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 *); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 39 | static int qla24xx_post_gpdb_work(struct scsi_qla_host *, fc_port_t *, u8); |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 40 | 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] | 41 | static void qla24xx_handle_plogi_done_event(struct scsi_qla_host *, |
| 42 | struct event_arg *); |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 43 | static void qla24xx_handle_prli_done_event(struct scsi_qla_host *, |
| 44 | struct event_arg *); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 45 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 46 | /* SRB Extensions ---------------------------------------------------------- */ |
| 47 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 48 | void |
| 49 | qla2x00_sp_timeout(unsigned long __data) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 50 | { |
| 51 | srb_t *sp = (srb_t *)__data; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 52 | struct srb_iocb *iocb; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 53 | scsi_qla_host_t *vha = sp->vha; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 54 | struct req_que *req; |
| 55 | unsigned long flags; |
| 56 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 57 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 58 | req = vha->hw->req_q_map[0]; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 59 | req->outstanding_cmds[sp->handle] = NULL; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 60 | iocb = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 61 | iocb->timeout(sp); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 62 | sp->free(sp); |
| 63 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 66 | void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 67 | qla2x00_sp_free(void *ptr) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 68 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 69 | srb_t *sp = ptr; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 70 | struct srb_iocb *iocb = &sp->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 71 | |
Chad Dupuis | 4d97cc5 | 2010-10-15 11:27:41 -0700 | [diff] [blame] | 72 | del_timer(&iocb->timer); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 73 | qla2x00_rel_sp(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 76 | /* Asynchronous Login/Logout Routines -------------------------------------- */ |
| 77 | |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 78 | unsigned long |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 79 | qla2x00_get_async_timeout(struct scsi_qla_host *vha) |
| 80 | { |
| 81 | unsigned long tmo; |
| 82 | struct qla_hw_data *ha = vha->hw; |
| 83 | |
| 84 | /* Firmware should use switch negotiated r_a_tov for timeout. */ |
| 85 | tmo = ha->r_a_tov / 10 * 2; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 86 | if (IS_QLAFX00(ha)) { |
| 87 | tmo = FX00_DEF_RATOV * 2; |
| 88 | } else if (!IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 89 | /* |
| 90 | * Except for earlier ISPs where the timeout is seeded from the |
| 91 | * initialization control block. |
| 92 | */ |
| 93 | tmo = ha->login_timeout; |
| 94 | } |
| 95 | return tmo; |
| 96 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 97 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 98 | void |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 99 | qla2x00_async_iocb_timeout(void *data) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 100 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 101 | srb_t *sp = data; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 102 | fc_port_t *fcport = sp->fcport; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 103 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 104 | struct event_arg ea; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 105 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 106 | ql_dbg(ql_dbg_disc, fcport->vha, 0x2071, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 107 | "Async-%s timeout - hdl=%x portid=%06x %8phC.\n", |
| 108 | sp->name, sp->handle, fcport->d_id.b24, fcport->port_name); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 109 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 110 | fcport->flags &= ~FCF_ASYNC_SENT; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 111 | |
| 112 | switch (sp->type) { |
| 113 | case SRB_LOGIN_CMD: |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 114 | /* Retry as needed. */ |
| 115 | lio->u.logio.data[0] = MBS_COMMAND_ERROR; |
| 116 | lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? |
| 117 | QLA_LOGIO_LOGIN_RETRIED : 0; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 118 | memset(&ea, 0, sizeof(ea)); |
| 119 | ea.event = FCME_PLOGI_DONE; |
| 120 | ea.fcport = sp->fcport; |
| 121 | ea.data[0] = lio->u.logio.data[0]; |
| 122 | ea.data[1] = lio->u.logio.data[1]; |
| 123 | ea.sp = sp; |
| 124 | qla24xx_handle_plogi_done_event(fcport->vha, &ea); |
| 125 | break; |
| 126 | case SRB_LOGOUT_CMD: |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 127 | qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 128 | break; |
| 129 | case SRB_CT_PTHRU_CMD: |
| 130 | case SRB_MB_IOCB: |
| 131 | case SRB_NACK_PLOGI: |
| 132 | case SRB_NACK_PRLI: |
| 133 | case SRB_NACK_LOGO: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 134 | sp->done(sp, QLA_FUNCTION_TIMEOUT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 135 | break; |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 136 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 139 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 140 | qla2x00_async_login_sp_done(void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 141 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 142 | srb_t *sp = ptr; |
| 143 | struct scsi_qla_host *vha = sp->vha; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 144 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 145 | struct event_arg ea; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 146 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 147 | ql_dbg(ql_dbg_disc, vha, 0x20dd, |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 148 | "%s %8phC res %d \n", __func__, sp->fcport->port_name, res); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 149 | |
| 150 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
| 151 | if (!test_bit(UNLOADING, &vha->dpc_flags)) { |
| 152 | memset(&ea, 0, sizeof(ea)); |
| 153 | ea.event = FCME_PLOGI_DONE; |
| 154 | ea.fcport = sp->fcport; |
| 155 | ea.data[0] = lio->u.logio.data[0]; |
| 156 | ea.data[1] = lio->u.logio.data[1]; |
| 157 | ea.iop[0] = lio->u.logio.iop[0]; |
| 158 | ea.iop[1] = lio->u.logio.iop[1]; |
| 159 | ea.sp = sp; |
| 160 | qla2x00_fcport_event_handler(vha, &ea); |
| 161 | } |
| 162 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 163 | sp->free(sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 166 | int |
| 167 | qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 168 | uint16_t *data) |
| 169 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 170 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 171 | struct srb_iocb *lio; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 172 | int rval = QLA_FUNCTION_FAILED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 173 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 174 | if (!vha->flags.online) |
| 175 | goto done; |
| 176 | |
| 177 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
| 178 | (fcport->fw_login_state == DSC_LS_PLOGI_COMP) || |
| 179 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 180 | goto done; |
| 181 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 182 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 183 | if (!sp) |
| 184 | goto done; |
| 185 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 186 | fcport->flags |= FCF_ASYNC_SENT; |
| 187 | fcport->logout_completed = 0; |
| 188 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 189 | sp->type = SRB_LOGIN_CMD; |
| 190 | sp->name = "login"; |
| 191 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 192 | |
| 193 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 194 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 195 | sp->done = qla2x00_async_login_sp_done; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 196 | lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 197 | |
| 198 | if (fcport->fc4f_nvme) |
| 199 | lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI; |
| 200 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 201 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 202 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 203 | rval = qla2x00_start_sp(sp); |
Chad Dupuis | 080c951 | 2016-01-27 12:03:37 -0500 | [diff] [blame] | 204 | if (rval != QLA_SUCCESS) { |
| 205 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 206 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 207 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 208 | goto done_free_sp; |
Chad Dupuis | 080c951 | 2016-01-27 12:03:37 -0500 | [diff] [blame] | 209 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 210 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 211 | ql_dbg(ql_dbg_disc, vha, 0x2072, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 212 | "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x " |
| 213 | "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 214 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 215 | fcport->login_retry); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 216 | return rval; |
| 217 | |
| 218 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 219 | sp->free(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 220 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 221 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 222 | return rval; |
| 223 | } |
| 224 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 225 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 226 | qla2x00_async_logout_sp_done(void *ptr, int res) |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 227 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 228 | srb_t *sp = ptr; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 229 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 230 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 231 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 232 | if (!test_bit(UNLOADING, &sp->vha->dpc_flags)) |
| 233 | qla2x00_post_async_logout_done_work(sp->vha, sp->fcport, |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 234 | lio->u.logio.data); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 235 | sp->free(sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 238 | int |
| 239 | qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 240 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 241 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 242 | struct srb_iocb *lio; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 243 | int rval; |
| 244 | |
| 245 | rval = QLA_FUNCTION_FAILED; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 246 | fcport->flags |= FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 247 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 248 | if (!sp) |
| 249 | goto done; |
| 250 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 251 | sp->type = SRB_LOGOUT_CMD; |
| 252 | sp->name = "logout"; |
| 253 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 254 | |
| 255 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 256 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 257 | sp->done = qla2x00_async_logout_sp_done; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 258 | rval = qla2x00_start_sp(sp); |
| 259 | if (rval != QLA_SUCCESS) |
| 260 | goto done_free_sp; |
| 261 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 262 | ql_dbg(ql_dbg_disc, vha, 0x2070, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 263 | "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] | 264 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 265 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 266 | fcport->port_name); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 267 | return rval; |
| 268 | |
| 269 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 270 | sp->free(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 271 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 272 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 273 | return rval; |
| 274 | } |
| 275 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 276 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 277 | qla2x00_async_adisc_sp_done(void *ptr, int res) |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 278 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 279 | srb_t *sp = ptr; |
| 280 | struct scsi_qla_host *vha = sp->vha; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 281 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 282 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 283 | if (!test_bit(UNLOADING, &vha->dpc_flags)) |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 284 | qla2x00_post_async_adisc_done_work(sp->vha, sp->fcport, |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 285 | lio->u.logio.data); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 286 | sp->free(sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | int |
| 290 | qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 291 | uint16_t *data) |
| 292 | { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 293 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 294 | struct srb_iocb *lio; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 295 | int rval; |
| 296 | |
| 297 | rval = QLA_FUNCTION_FAILED; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 298 | fcport->flags |= FCF_ASYNC_SENT; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 299 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 300 | if (!sp) |
| 301 | goto done; |
| 302 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 303 | sp->type = SRB_ADISC_CMD; |
| 304 | sp->name = "adisc"; |
| 305 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 306 | |
| 307 | lio = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 308 | lio->timeout = qla2x00_async_iocb_timeout; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 309 | sp->done = qla2x00_async_adisc_sp_done; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 310 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 311 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 312 | rval = qla2x00_start_sp(sp); |
| 313 | if (rval != QLA_SUCCESS) |
| 314 | goto done_free_sp; |
| 315 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 316 | ql_dbg(ql_dbg_disc, vha, 0x206f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 317 | "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n", |
| 318 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 319 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 320 | return rval; |
| 321 | |
| 322 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 323 | sp->free(sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 324 | done: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 325 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 326 | return rval; |
| 327 | } |
| 328 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 329 | static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha, |
| 330 | struct event_arg *ea) |
| 331 | { |
| 332 | fc_port_t *fcport, *conflict_fcport; |
| 333 | struct get_name_list_extended *e; |
| 334 | u16 i, n, found = 0, loop_id; |
| 335 | port_id_t id; |
| 336 | u64 wwn; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 337 | u8 opt = 0, current_login_state; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 338 | |
| 339 | fcport = ea->fcport; |
| 340 | |
| 341 | if (ea->rc) { /* rval */ |
| 342 | if (fcport->login_retry == 0) { |
| 343 | fcport->login_retry = vha->hw->login_retry_count; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 344 | ql_dbg(ql_dbg_disc, vha, 0x20de, |
| 345 | "GNL failed Port login retry %8phN, retry cnt=%d.\n", |
| 346 | fcport->port_name, fcport->login_retry); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 347 | } |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | if (fcport->last_rscn_gen != fcport->rscn_gen) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 352 | ql_dbg(ql_dbg_disc, vha, 0x20df, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 353 | "%s %8phC rscn gen changed rscn %d|%d \n", |
| 354 | __func__, fcport->port_name, |
| 355 | fcport->last_rscn_gen, fcport->rscn_gen); |
| 356 | qla24xx_post_gidpn_work(vha, fcport); |
| 357 | return; |
| 358 | } else if (fcport->last_login_gen != fcport->login_gen) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 359 | ql_dbg(ql_dbg_disc, vha, 0x20e0, |
| 360 | "%s %8phC login gen changed login %d|%d\n", |
| 361 | __func__, fcport->port_name, |
| 362 | fcport->last_login_gen, fcport->login_gen); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 363 | return; |
| 364 | } |
| 365 | |
| 366 | n = ea->data[0] / sizeof(struct get_name_list_extended); |
| 367 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 368 | ql_dbg(ql_dbg_disc, vha, 0x20e1, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 369 | "%s %d %8phC n %d %02x%02x%02x lid %d \n", |
| 370 | __func__, __LINE__, fcport->port_name, n, |
| 371 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 372 | fcport->d_id.b.al_pa, fcport->loop_id); |
| 373 | |
| 374 | for (i = 0; i < n; i++) { |
| 375 | e = &vha->gnl.l[i]; |
| 376 | wwn = wwn_to_u64(e->port_name); |
| 377 | |
| 378 | if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE)) |
| 379 | continue; |
| 380 | |
| 381 | found = 1; |
| 382 | id.b.domain = e->port_id[2]; |
| 383 | id.b.area = e->port_id[1]; |
| 384 | id.b.al_pa = e->port_id[0]; |
| 385 | id.b.rsvd_1 = 0; |
| 386 | |
| 387 | loop_id = le16_to_cpu(e->nport_handle); |
| 388 | loop_id = (loop_id & 0x7fff); |
| 389 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 390 | ql_dbg(ql_dbg_disc, vha, 0x20e2, |
| 391 | "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n", |
| 392 | __func__, fcport->port_name, |
| 393 | e->current_login_state, fcport->fw_login_state, |
| 394 | id.b.domain, id.b.area, id.b.al_pa, |
| 395 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 396 | fcport->d_id.b.al_pa, loop_id, fcport->loop_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 397 | |
| 398 | if ((id.b24 != fcport->d_id.b24) || |
| 399 | ((fcport->loop_id != FC_NO_LOOP_ID) && |
| 400 | (fcport->loop_id != loop_id))) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 401 | ql_dbg(ql_dbg_disc, vha, 0x20e3, |
| 402 | "%s %d %8phC post del sess\n", |
| 403 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 404 | qlt_schedule_sess_for_deletion(fcport, 1); |
| 405 | return; |
| 406 | } |
| 407 | |
| 408 | fcport->loop_id = loop_id; |
| 409 | |
| 410 | wwn = wwn_to_u64(fcport->port_name); |
| 411 | qlt_find_sess_invalidate_other(vha, wwn, |
| 412 | id, loop_id, &conflict_fcport); |
| 413 | |
| 414 | if (conflict_fcport) { |
| 415 | /* |
| 416 | * Another share fcport share the same loop_id & |
| 417 | * nport id. Conflict fcport needs to finish |
| 418 | * cleanup before this fcport can proceed to login. |
| 419 | */ |
| 420 | conflict_fcport->conflict = fcport; |
| 421 | fcport->login_pause = 1; |
| 422 | } |
| 423 | |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 424 | if (fcport->fc4f_nvme) |
| 425 | current_login_state = e->current_login_state >> 4; |
| 426 | else |
| 427 | current_login_state = e->current_login_state & 0xf; |
| 428 | |
| 429 | switch (current_login_state) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 430 | case DSC_LS_PRLI_COMP: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 431 | ql_dbg(ql_dbg_disc, vha, 0x20e4, |
| 432 | "%s %d %8phC post gpdb\n", |
| 433 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 434 | opt = PDO_FORCE_ADISC; |
| 435 | qla24xx_post_gpdb_work(vha, fcport, opt); |
| 436 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 437 | case DSC_LS_PORT_UNAVAIL: |
| 438 | default: |
| 439 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 440 | qla2x00_find_new_loop_id(vha, fcport); |
| 441 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 442 | } |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 443 | ql_dbg(ql_dbg_disc, vha, 0x20e5, |
| 444 | "%s %d %8phC\n", |
| 445 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 446 | qla24xx_fcport_handle_login(vha, fcport); |
| 447 | break; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | if (!found) { |
| 452 | /* fw has no record of this port */ |
| 453 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 454 | qla2x00_find_new_loop_id(vha, fcport); |
| 455 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 456 | } else { |
| 457 | for (i = 0; i < n; i++) { |
| 458 | e = &vha->gnl.l[i]; |
| 459 | id.b.domain = e->port_id[0]; |
| 460 | id.b.area = e->port_id[1]; |
| 461 | id.b.al_pa = e->port_id[2]; |
| 462 | id.b.rsvd_1 = 0; |
| 463 | loop_id = le16_to_cpu(e->nport_handle); |
| 464 | |
| 465 | if (fcport->d_id.b24 == id.b24) { |
| 466 | conflict_fcport = |
| 467 | qla2x00_find_fcport_by_wwpn(vha, |
| 468 | e->port_name, 0); |
| 469 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 470 | ql_dbg(ql_dbg_disc, vha, 0x20e6, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 471 | "%s %d %8phC post del sess\n", |
| 472 | __func__, __LINE__, |
| 473 | conflict_fcport->port_name); |
| 474 | qlt_schedule_sess_for_deletion |
| 475 | (conflict_fcport, 1); |
| 476 | } |
| 477 | |
| 478 | if (fcport->loop_id == loop_id) { |
| 479 | /* FW already picked this loop id for another fcport */ |
| 480 | qla2x00_find_new_loop_id(vha, fcport); |
| 481 | } |
| 482 | } |
| 483 | } |
| 484 | qla24xx_fcport_handle_login(vha, fcport); |
| 485 | } |
| 486 | } /* gnl_event */ |
| 487 | |
| 488 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 489 | qla24xx_async_gnl_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 490 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 491 | struct srb *sp = s; |
| 492 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 493 | unsigned long flags; |
| 494 | struct fc_port *fcport = NULL, *tf; |
| 495 | u16 i, n = 0, loop_id; |
| 496 | struct event_arg ea; |
| 497 | struct get_name_list_extended *e; |
| 498 | u64 wwn; |
| 499 | struct list_head h; |
| 500 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 501 | ql_dbg(ql_dbg_disc, vha, 0x20e7, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 502 | "Async done-%s res %x mb[1]=%x mb[2]=%x \n", |
| 503 | sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1], |
| 504 | sp->u.iocb_cmd.u.mbx.in_mb[2]); |
| 505 | |
| 506 | memset(&ea, 0, sizeof(ea)); |
| 507 | ea.sp = sp; |
| 508 | ea.rc = res; |
| 509 | ea.event = FCME_GNL_DONE; |
| 510 | |
| 511 | if (sp->u.iocb_cmd.u.mbx.in_mb[1] >= |
| 512 | sizeof(struct get_name_list_extended)) { |
| 513 | n = sp->u.iocb_cmd.u.mbx.in_mb[1] / |
| 514 | sizeof(struct get_name_list_extended); |
| 515 | ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */ |
| 516 | } |
| 517 | |
| 518 | for (i = 0; i < n; i++) { |
| 519 | e = &vha->gnl.l[i]; |
| 520 | loop_id = le16_to_cpu(e->nport_handle); |
| 521 | /* mask out reserve bit */ |
| 522 | loop_id = (loop_id & 0x7fff); |
| 523 | set_bit(loop_id, vha->hw->loop_id_map); |
| 524 | wwn = wwn_to_u64(e->port_name); |
| 525 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 526 | ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 527 | "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n", |
| 528 | __func__, (void *)&wwn, e->port_id[2], e->port_id[1], |
| 529 | e->port_id[0], e->current_login_state, e->last_login_state, |
| 530 | (loop_id & 0x7fff)); |
| 531 | } |
| 532 | |
| 533 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 534 | vha->gnl.sent = 0; |
| 535 | |
| 536 | INIT_LIST_HEAD(&h); |
| 537 | fcport = tf = NULL; |
| 538 | if (!list_empty(&vha->gnl.fcports)) |
| 539 | list_splice_init(&vha->gnl.fcports, &h); |
| 540 | |
| 541 | list_for_each_entry_safe(fcport, tf, &h, gnl_entry) { |
| 542 | list_del_init(&fcport->gnl_entry); |
| 543 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 544 | ea.fcport = fcport; |
| 545 | |
| 546 | qla2x00_fcport_event_handler(vha, &ea); |
| 547 | } |
| 548 | |
| 549 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 550 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 551 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 555 | { |
| 556 | srb_t *sp; |
| 557 | struct srb_iocb *mbx; |
| 558 | int rval = QLA_FUNCTION_FAILED; |
| 559 | unsigned long flags; |
| 560 | u16 *mb; |
| 561 | |
| 562 | if (!vha->flags.online) |
| 563 | goto done; |
| 564 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 565 | ql_dbg(ql_dbg_disc, vha, 0x20d9, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 566 | "Async-gnlist WWPN %8phC \n", fcport->port_name); |
| 567 | |
| 568 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 569 | fcport->flags |= FCF_ASYNC_SENT; |
| 570 | fcport->disc_state = DSC_GNL; |
| 571 | fcport->last_rscn_gen = fcport->rscn_gen; |
| 572 | fcport->last_login_gen = fcport->login_gen; |
| 573 | |
| 574 | list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports); |
| 575 | if (vha->gnl.sent) { |
| 576 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 577 | rval = QLA_SUCCESS; |
| 578 | goto done; |
| 579 | } |
| 580 | vha->gnl.sent = 1; |
| 581 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 582 | |
| 583 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 584 | if (!sp) |
| 585 | goto done; |
| 586 | sp->type = SRB_MB_IOCB; |
| 587 | sp->name = "gnlist"; |
| 588 | sp->gen1 = fcport->rscn_gen; |
| 589 | sp->gen2 = fcport->login_gen; |
| 590 | |
| 591 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2); |
| 592 | |
| 593 | mb = sp->u.iocb_cmd.u.mbx.out_mb; |
| 594 | mb[0] = MBC_PORT_NODE_NAME_LIST; |
| 595 | mb[1] = BIT_2 | BIT_3; |
| 596 | mb[2] = MSW(vha->gnl.ldma); |
| 597 | mb[3] = LSW(vha->gnl.ldma); |
| 598 | mb[6] = MSW(MSD(vha->gnl.ldma)); |
| 599 | mb[7] = LSW(MSD(vha->gnl.ldma)); |
| 600 | mb[8] = vha->gnl.size; |
| 601 | mb[9] = vha->vp_idx; |
| 602 | |
| 603 | mbx = &sp->u.iocb_cmd; |
| 604 | mbx->timeout = qla2x00_async_iocb_timeout; |
| 605 | |
| 606 | sp->done = qla24xx_async_gnl_sp_done; |
| 607 | |
| 608 | rval = qla2x00_start_sp(sp); |
| 609 | if (rval != QLA_SUCCESS) |
| 610 | goto done_free_sp; |
| 611 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 612 | ql_dbg(ql_dbg_disc, vha, 0x20da, |
| 613 | "Async-%s - OUT WWPN %8phC hndl %x\n", |
| 614 | sp->name, fcport->port_name, sp->handle); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 615 | |
| 616 | return rval; |
| 617 | |
| 618 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 619 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 620 | done: |
| 621 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 622 | return rval; |
| 623 | } |
| 624 | |
| 625 | int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 626 | { |
| 627 | struct qla_work_evt *e; |
| 628 | |
| 629 | e = qla2x00_alloc_work(vha, QLA_EVT_GNL); |
| 630 | if (!e) |
| 631 | return QLA_FUNCTION_FAILED; |
| 632 | |
| 633 | e->u.fcport.fcport = fcport; |
| 634 | return qla2x00_post_work(vha, e); |
| 635 | } |
| 636 | |
| 637 | static |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 638 | void qla24xx_async_gpdb_sp_done(void *s, int res) |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 639 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 640 | struct srb *sp = s; |
| 641 | struct scsi_qla_host *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 642 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 643 | struct port_database_24xx *pd; |
| 644 | fc_port_t *fcport = sp->fcport; |
| 645 | u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb; |
| 646 | int rval = QLA_SUCCESS; |
| 647 | struct event_arg ea; |
| 648 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 649 | ql_dbg(ql_dbg_disc, vha, 0x20db, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 650 | "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n", |
| 651 | sp->name, res, fcport->port_name, mb[1], mb[2]); |
| 652 | |
| 653 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 654 | |
| 655 | if (res) { |
| 656 | rval = res; |
| 657 | goto gpd_error_out; |
| 658 | } |
| 659 | |
| 660 | pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in; |
| 661 | |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 662 | rval = __qla24xx_parse_gpdb(vha, fcport, pd); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 663 | |
| 664 | gpd_error_out: |
| 665 | memset(&ea, 0, sizeof(ea)); |
| 666 | ea.event = FCME_GPDB_DONE; |
| 667 | ea.rc = rval; |
| 668 | ea.fcport = fcport; |
| 669 | ea.sp = sp; |
| 670 | |
| 671 | qla2x00_fcport_event_handler(vha, &ea); |
| 672 | |
| 673 | dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in, |
| 674 | sp->u.iocb_cmd.u.mbx.in_dma); |
| 675 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 676 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 677 | } |
| 678 | |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 679 | static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 680 | { |
| 681 | struct qla_work_evt *e; |
| 682 | |
| 683 | e = qla2x00_alloc_work(vha, QLA_EVT_PRLI); |
| 684 | if (!e) |
| 685 | return QLA_FUNCTION_FAILED; |
| 686 | |
| 687 | e->u.fcport.fcport = fcport; |
| 688 | |
| 689 | return qla2x00_post_work(vha, e); |
| 690 | } |
| 691 | |
| 692 | static void |
| 693 | qla2x00_async_prli_sp_done(void *ptr, int res) |
| 694 | { |
| 695 | srb_t *sp = ptr; |
| 696 | struct scsi_qla_host *vha = sp->vha; |
| 697 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
| 698 | struct event_arg ea; |
| 699 | |
| 700 | ql_dbg(ql_dbg_disc, vha, 0x2129, |
| 701 | "%s %8phC res %d \n", __func__, |
| 702 | sp->fcport->port_name, res); |
| 703 | |
| 704 | sp->fcport->flags &= ~FCF_ASYNC_SENT; |
| 705 | |
| 706 | if (!test_bit(UNLOADING, &vha->dpc_flags)) { |
| 707 | memset(&ea, 0, sizeof(ea)); |
| 708 | ea.event = FCME_PRLI_DONE; |
| 709 | ea.fcport = sp->fcport; |
| 710 | ea.data[0] = lio->u.logio.data[0]; |
| 711 | ea.data[1] = lio->u.logio.data[1]; |
| 712 | ea.iop[0] = lio->u.logio.iop[0]; |
| 713 | ea.iop[1] = lio->u.logio.iop[1]; |
| 714 | ea.sp = sp; |
| 715 | |
| 716 | qla2x00_fcport_event_handler(vha, &ea); |
| 717 | } |
| 718 | |
| 719 | sp->free(sp); |
| 720 | } |
| 721 | |
| 722 | int |
| 723 | qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 724 | { |
| 725 | srb_t *sp; |
| 726 | struct srb_iocb *lio; |
| 727 | int rval = QLA_FUNCTION_FAILED; |
| 728 | |
| 729 | if (!vha->flags.online) |
| 730 | return rval; |
| 731 | |
| 732 | if (fcport->fw_login_state == DSC_LS_PLOGI_PEND || |
| 733 | fcport->fw_login_state == DSC_LS_PLOGI_COMP || |
| 734 | fcport->fw_login_state == DSC_LS_PRLI_PEND) |
| 735 | return rval; |
| 736 | |
| 737 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 738 | if (!sp) |
| 739 | return rval; |
| 740 | |
| 741 | fcport->flags |= FCF_ASYNC_SENT; |
| 742 | fcport->logout_completed = 0; |
| 743 | |
| 744 | sp->type = SRB_PRLI_CMD; |
| 745 | sp->name = "prli"; |
| 746 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 747 | |
| 748 | lio = &sp->u.iocb_cmd; |
| 749 | lio->timeout = qla2x00_async_iocb_timeout; |
| 750 | sp->done = qla2x00_async_prli_sp_done; |
| 751 | lio->u.logio.flags = 0; |
| 752 | |
| 753 | if (fcport->fc4f_nvme) |
| 754 | lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI; |
| 755 | |
| 756 | rval = qla2x00_start_sp(sp); |
| 757 | if (rval != QLA_SUCCESS) { |
| 758 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 759 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 760 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 761 | goto done_free_sp; |
| 762 | } |
| 763 | |
| 764 | ql_dbg(ql_dbg_disc, vha, 0x211b, |
| 765 | "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n", |
| 766 | fcport->port_name, sp->handle, fcport->loop_id, |
| 767 | fcport->d_id.b24, fcport->login_retry); |
| 768 | |
| 769 | return rval; |
| 770 | |
| 771 | done_free_sp: |
| 772 | sp->free(sp); |
| 773 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 774 | return rval; |
| 775 | } |
| 776 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 777 | static int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 778 | u8 opt) |
| 779 | { |
| 780 | struct qla_work_evt *e; |
| 781 | |
| 782 | e = qla2x00_alloc_work(vha, QLA_EVT_GPDB); |
| 783 | if (!e) |
| 784 | return QLA_FUNCTION_FAILED; |
| 785 | |
| 786 | e->u.fcport.fcport = fcport; |
| 787 | e->u.fcport.opt = opt; |
| 788 | return qla2x00_post_work(vha, e); |
| 789 | } |
| 790 | |
| 791 | int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt) |
| 792 | { |
| 793 | srb_t *sp; |
| 794 | struct srb_iocb *mbx; |
| 795 | int rval = QLA_FUNCTION_FAILED; |
| 796 | u16 *mb; |
| 797 | dma_addr_t pd_dma; |
| 798 | struct port_database_24xx *pd; |
| 799 | struct qla_hw_data *ha = vha->hw; |
| 800 | |
| 801 | if (!vha->flags.online) |
| 802 | goto done; |
| 803 | |
| 804 | fcport->flags |= FCF_ASYNC_SENT; |
| 805 | fcport->disc_state = DSC_GPDB; |
| 806 | |
| 807 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 808 | if (!sp) |
| 809 | goto done; |
| 810 | |
Joe Carnuccio | e0824e6 | 2017-08-23 15:05:08 -0700 | [diff] [blame] | 811 | sp->type = SRB_MB_IOCB; |
| 812 | sp->name = "gpdb"; |
| 813 | sp->gen1 = fcport->rscn_gen; |
| 814 | sp->gen2 = fcport->login_gen; |
| 815 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2); |
| 816 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 817 | pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma); |
| 818 | if (pd == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 819 | ql_log(ql_log_warn, vha, 0xd043, |
| 820 | "Failed to allocate port database structure.\n"); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 821 | goto done_free_sp; |
| 822 | } |
| 823 | memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE)); |
| 824 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 825 | mb = sp->u.iocb_cmd.u.mbx.out_mb; |
| 826 | mb[0] = MBC_GET_PORT_DATABASE; |
| 827 | mb[1] = fcport->loop_id; |
| 828 | mb[2] = MSW(pd_dma); |
| 829 | mb[3] = LSW(pd_dma); |
| 830 | mb[6] = MSW(MSD(pd_dma)); |
| 831 | mb[7] = LSW(MSD(pd_dma)); |
| 832 | mb[9] = vha->vp_idx; |
| 833 | mb[10] = opt; |
| 834 | |
| 835 | mbx = &sp->u.iocb_cmd; |
| 836 | mbx->timeout = qla2x00_async_iocb_timeout; |
| 837 | mbx->u.mbx.in = (void *)pd; |
| 838 | mbx->u.mbx.in_dma = pd_dma; |
| 839 | |
| 840 | sp->done = qla24xx_async_gpdb_sp_done; |
| 841 | |
| 842 | rval = qla2x00_start_sp(sp); |
| 843 | if (rval != QLA_SUCCESS) |
| 844 | goto done_free_sp; |
| 845 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 846 | ql_dbg(ql_dbg_disc, vha, 0x20dc, |
| 847 | "Async-%s %8phC hndl %x opt %x\n", |
| 848 | sp->name, fcport->port_name, sp->handle, opt); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 849 | |
| 850 | return rval; |
| 851 | |
| 852 | done_free_sp: |
| 853 | if (pd) |
| 854 | dma_pool_free(ha->s_dma_pool, pd, pd_dma); |
| 855 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 856 | sp->free(sp); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 857 | done: |
| 858 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 859 | qla24xx_post_gpdb_work(vha, fcport, opt); |
| 860 | return rval; |
| 861 | } |
| 862 | |
| 863 | static |
| 864 | void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea) |
| 865 | { |
| 866 | int rval = ea->rc; |
| 867 | fc_port_t *fcport = ea->fcport; |
| 868 | unsigned long flags; |
| 869 | |
| 870 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 871 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 872 | ql_dbg(ql_dbg_disc, vha, 0x20d2, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 873 | "%s %8phC DS %d LS %d rval %d\n", __func__, fcport->port_name, |
| 874 | fcport->disc_state, fcport->fw_login_state, rval); |
| 875 | |
| 876 | if (ea->sp->gen2 != fcport->login_gen) { |
| 877 | /* target side must have changed it. */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 878 | ql_dbg(ql_dbg_disc, vha, 0x20d3, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 879 | "%s %8phC generation changed rscn %d|%d login %d|%d \n", |
| 880 | __func__, fcport->port_name, fcport->last_rscn_gen, |
| 881 | fcport->rscn_gen, fcport->last_login_gen, |
| 882 | fcport->login_gen); |
| 883 | return; |
| 884 | } else if (ea->sp->gen1 != fcport->rscn_gen) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 885 | 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] | 886 | __func__, __LINE__, fcport->port_name); |
| 887 | qla24xx_post_gidpn_work(vha, fcport); |
| 888 | return; |
| 889 | } |
| 890 | |
| 891 | if (rval != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 892 | 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] | 893 | __func__, __LINE__, fcport->port_name); |
| 894 | qlt_schedule_sess_for_deletion_lock(fcport); |
| 895 | return; |
| 896 | } |
| 897 | |
| 898 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 899 | ea->fcport->login_gen++; |
| 900 | ea->fcport->deleted = 0; |
| 901 | ea->fcport->logout_on_delete = 1; |
| 902 | |
| 903 | if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) { |
| 904 | vha->fcport_count++; |
| 905 | ea->fcport->login_succ = 1; |
| 906 | |
| 907 | if (!IS_IIDMA_CAPABLE(vha->hw) || |
| 908 | !vha->hw->flags.gpsc_supported) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 909 | ql_dbg(ql_dbg_disc, vha, 0x20d6, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 910 | "%s %d %8phC post upd_fcport fcp_cnt %d\n", |
| 911 | __func__, __LINE__, fcport->port_name, |
| 912 | vha->fcport_count); |
| 913 | |
| 914 | qla24xx_post_upd_fcport_work(vha, fcport); |
| 915 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 916 | ql_dbg(ql_dbg_disc, vha, 0x20d7, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 917 | "%s %d %8phC post gpsc fcp_cnt %d\n", |
| 918 | __func__, __LINE__, fcport->port_name, |
| 919 | vha->fcport_count); |
| 920 | |
| 921 | qla24xx_post_gpsc_work(vha, fcport); |
| 922 | } |
| 923 | } |
| 924 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 925 | } /* gpdb event */ |
| 926 | |
| 927 | int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 928 | { |
| 929 | if (fcport->login_retry == 0) |
| 930 | return 0; |
| 931 | |
| 932 | if (fcport->scan_state != QLA_FCPORT_FOUND) |
| 933 | return 0; |
| 934 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 935 | ql_dbg(ql_dbg_disc, vha, 0x20d8, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 936 | "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d|%d retry %d lid %d\n", |
| 937 | __func__, fcport->port_name, fcport->disc_state, |
| 938 | fcport->fw_login_state, fcport->login_pause, fcport->flags, |
| 939 | fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen, |
| 940 | fcport->last_login_gen, fcport->login_gen, fcport->login_retry, |
| 941 | fcport->loop_id); |
| 942 | |
| 943 | fcport->login_retry--; |
| 944 | |
| 945 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 946 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 947 | return 0; |
| 948 | |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 949 | if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) { |
| 950 | if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) |
| 951 | return 0; |
| 952 | } |
| 953 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 954 | /* for pure Target Mode. Login will not be initiated */ |
| 955 | if (vha->host->active_mode == MODE_TARGET) |
| 956 | return 0; |
| 957 | |
| 958 | if (fcport->flags & FCF_ASYNC_SENT) { |
| 959 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 960 | return 0; |
| 961 | } |
| 962 | |
| 963 | switch (fcport->disc_state) { |
| 964 | case DSC_DELETED: |
| 965 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 966 | ql_dbg(ql_dbg_disc, vha, 0x20bd, |
| 967 | "%s %d %8phC post gnl\n", |
| 968 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 969 | qla24xx_async_gnl(vha, fcport); |
| 970 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 971 | ql_dbg(ql_dbg_disc, vha, 0x20bf, |
| 972 | "%s %d %8phC post login\n", |
| 973 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 974 | fcport->disc_state = DSC_LOGIN_PEND; |
| 975 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 976 | } |
| 977 | break; |
| 978 | |
| 979 | case DSC_GNL: |
| 980 | if (fcport->login_pause) { |
| 981 | fcport->last_rscn_gen = fcport->rscn_gen; |
| 982 | fcport->last_login_gen = fcport->login_gen; |
| 983 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 984 | break; |
| 985 | } |
| 986 | |
| 987 | if (fcport->flags & FCF_FCP2_DEVICE) { |
| 988 | u8 opt = PDO_FORCE_ADISC; |
| 989 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 990 | ql_dbg(ql_dbg_disc, vha, 0x20c9, |
| 991 | "%s %d %8phC post gpdb\n", |
| 992 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 993 | |
| 994 | fcport->disc_state = DSC_GPDB; |
| 995 | qla24xx_post_gpdb_work(vha, fcport, opt); |
| 996 | } else { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 997 | ql_dbg(ql_dbg_disc, vha, 0x20cf, |
| 998 | "%s %d %8phC post login\n", |
| 999 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1000 | fcport->disc_state = DSC_LOGIN_PEND; |
| 1001 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 1002 | } |
| 1003 | |
| 1004 | break; |
| 1005 | |
| 1006 | case DSC_LOGIN_FAILED: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1007 | ql_dbg(ql_dbg_disc, vha, 0x20d0, |
| 1008 | "%s %d %8phC post gidpn\n", |
| 1009 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1010 | |
| 1011 | qla24xx_post_gidpn_work(vha, fcport); |
| 1012 | break; |
| 1013 | |
| 1014 | case DSC_LOGIN_COMPLETE: |
| 1015 | /* recheck login state */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1016 | ql_dbg(ql_dbg_disc, vha, 0x20d1, |
| 1017 | "%s %d %8phC post gpdb\n", |
| 1018 | __func__, __LINE__, fcport->port_name); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1019 | |
| 1020 | qla24xx_post_gpdb_work(vha, fcport, PDO_FORCE_ADISC); |
| 1021 | break; |
| 1022 | |
| 1023 | default: |
| 1024 | break; |
| 1025 | } |
| 1026 | |
| 1027 | return 0; |
| 1028 | } |
| 1029 | |
| 1030 | static |
| 1031 | void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea) |
| 1032 | { |
| 1033 | fcport->rscn_gen++; |
| 1034 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1035 | ql_dbg(ql_dbg_disc, fcport->vha, 0x210c, |
| 1036 | "%s %8phC DS %d LS %d\n", |
| 1037 | __func__, fcport->port_name, fcport->disc_state, |
| 1038 | fcport->fw_login_state); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1039 | |
| 1040 | if (fcport->flags & FCF_ASYNC_SENT) |
| 1041 | return; |
| 1042 | |
| 1043 | switch (fcport->disc_state) { |
| 1044 | case DSC_DELETED: |
| 1045 | case DSC_LOGIN_COMPLETE: |
| 1046 | qla24xx_post_gidpn_work(fcport->vha, fcport); |
| 1047 | break; |
| 1048 | |
| 1049 | default: |
| 1050 | break; |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id, |
| 1055 | u8 *port_name, void *pla) |
| 1056 | { |
| 1057 | struct qla_work_evt *e; |
| 1058 | e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS); |
| 1059 | if (!e) |
| 1060 | return QLA_FUNCTION_FAILED; |
| 1061 | |
| 1062 | e->u.new_sess.id = *id; |
| 1063 | e->u.new_sess.pla = pla; |
| 1064 | memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE); |
| 1065 | |
| 1066 | return qla2x00_post_work(vha, e); |
| 1067 | } |
| 1068 | |
| 1069 | static |
| 1070 | int qla24xx_handle_delete_done_event(scsi_qla_host_t *vha, |
| 1071 | struct event_arg *ea) |
| 1072 | { |
| 1073 | fc_port_t *fcport = ea->fcport; |
| 1074 | |
| 1075 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1076 | return 0; |
| 1077 | |
| 1078 | switch (vha->host->active_mode) { |
| 1079 | case MODE_INITIATOR: |
| 1080 | case MODE_DUAL: |
| 1081 | if (fcport->scan_state == QLA_FCPORT_FOUND) |
| 1082 | qla24xx_fcport_handle_login(vha, fcport); |
| 1083 | break; |
| 1084 | |
| 1085 | case MODE_TARGET: |
| 1086 | default: |
| 1087 | /* no-op */ |
| 1088 | break; |
| 1089 | } |
| 1090 | |
| 1091 | return 0; |
| 1092 | } |
| 1093 | |
| 1094 | static |
| 1095 | void qla24xx_handle_relogin_event(scsi_qla_host_t *vha, |
| 1096 | struct event_arg *ea) |
| 1097 | { |
| 1098 | fc_port_t *fcport = ea->fcport; |
| 1099 | |
| 1100 | if (fcport->scan_state != QLA_FCPORT_FOUND) { |
| 1101 | fcport->login_retry++; |
| 1102 | return; |
| 1103 | } |
| 1104 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1105 | ql_dbg(ql_dbg_disc, vha, 0x2102, |
| 1106 | "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n", |
| 1107 | __func__, fcport->port_name, fcport->disc_state, |
| 1108 | fcport->fw_login_state, fcport->login_pause, |
| 1109 | fcport->deleted, fcport->conflict, |
| 1110 | fcport->last_rscn_gen, fcport->rscn_gen, |
| 1111 | fcport->last_login_gen, fcport->login_gen, |
| 1112 | fcport->flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1113 | |
| 1114 | if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1115 | (fcport->fw_login_state == DSC_LS_PRLI_PEND)) |
| 1116 | return; |
| 1117 | |
Quinn Tran | 5b33469 | 2017-03-15 09:48:48 -0700 | [diff] [blame] | 1118 | if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) { |
| 1119 | if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) |
| 1120 | return; |
| 1121 | } |
| 1122 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1123 | if (fcport->flags & FCF_ASYNC_SENT) { |
| 1124 | fcport->login_retry++; |
| 1125 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1126 | return; |
| 1127 | } |
| 1128 | |
| 1129 | if (fcport->disc_state == DSC_DELETE_PEND) { |
| 1130 | fcport->login_retry++; |
| 1131 | return; |
| 1132 | } |
| 1133 | |
| 1134 | if (fcport->last_rscn_gen != fcport->rscn_gen) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1135 | 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] | 1136 | __func__, __LINE__, fcport->port_name); |
| 1137 | |
| 1138 | qla24xx_async_gidpn(vha, fcport); |
| 1139 | return; |
| 1140 | } |
| 1141 | |
| 1142 | qla24xx_fcport_handle_login(vha, fcport); |
| 1143 | } |
| 1144 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1145 | 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] | 1146 | { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1147 | fc_port_t *fcport, *f, *tf; |
| 1148 | uint32_t id = 0, mask, rid; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1149 | int rc; |
| 1150 | |
| 1151 | switch (ea->event) { |
| 1152 | case FCME_RELOGIN: |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 1153 | case FCME_RSCN: |
| 1154 | case FCME_GIDPN_DONE: |
| 1155 | case FCME_GPSC_DONE: |
| 1156 | case FCME_GPNID_DONE: |
| 1157 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) || |
| 1158 | test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags)) |
| 1159 | return; |
| 1160 | break; |
| 1161 | default: |
| 1162 | break; |
| 1163 | } |
| 1164 | |
| 1165 | switch (ea->event) { |
| 1166 | case FCME_RELOGIN: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1167 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1168 | return; |
| 1169 | |
| 1170 | qla24xx_handle_relogin_event(vha, ea); |
| 1171 | break; |
| 1172 | case FCME_RSCN: |
| 1173 | if (test_bit(UNLOADING, &vha->dpc_flags)) |
| 1174 | return; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1175 | switch (ea->id.b.rsvd_1) { |
| 1176 | case RSCN_PORT_ADDR: |
| 1177 | fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1); |
| 1178 | if (!fcport) { |
| 1179 | /* cable moved */ |
| 1180 | rc = qla24xx_post_gpnid_work(vha, &ea->id); |
| 1181 | if (rc) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1182 | ql_log(ql_log_warn, vha, 0xd044, |
| 1183 | "RSCN GPNID work failed %02x%02x%02x\n", |
| 1184 | ea->id.b.domain, ea->id.b.area, |
| 1185 | ea->id.b.al_pa); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1186 | } |
| 1187 | } else { |
| 1188 | ea->fcport = fcport; |
| 1189 | qla24xx_handle_rscn_event(fcport, ea); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1190 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1191 | break; |
| 1192 | case RSCN_AREA_ADDR: |
| 1193 | case RSCN_DOM_ADDR: |
| 1194 | if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) { |
| 1195 | mask = 0xffff00; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1196 | ql_dbg(ql_dbg_async, vha, 0x5044, |
| 1197 | "RSCN: Area 0x%06x was affected\n", |
| 1198 | ea->id.b24); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1199 | } else { |
| 1200 | mask = 0xff0000; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1201 | ql_dbg(ql_dbg_async, vha, 0x507a, |
| 1202 | "RSCN: Domain 0x%06x was affected\n", |
| 1203 | ea->id.b24); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | rid = ea->id.b24 & mask; |
| 1207 | list_for_each_entry_safe(f, tf, &vha->vp_fcports, |
| 1208 | list) { |
| 1209 | id = f->d_id.b24 & mask; |
| 1210 | if (rid == id) { |
| 1211 | ea->fcport = f; |
| 1212 | qla24xx_handle_rscn_event(f, ea); |
| 1213 | } |
| 1214 | } |
| 1215 | break; |
| 1216 | case RSCN_FAB_ADDR: |
| 1217 | default: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1218 | ql_log(ql_log_warn, vha, 0xd045, |
| 1219 | "RSCN: Fabric was affected. Addr format %d\n", |
| 1220 | ea->id.b.rsvd_1); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 1221 | qla2x00_mark_all_devices_lost(vha, 1); |
| 1222 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 1223 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1224 | } |
| 1225 | break; |
| 1226 | case FCME_GIDPN_DONE: |
| 1227 | qla24xx_handle_gidpn_event(vha, ea); |
| 1228 | break; |
| 1229 | case FCME_GNL_DONE: |
| 1230 | qla24xx_handle_gnl_done_event(vha, ea); |
| 1231 | break; |
| 1232 | case FCME_GPSC_DONE: |
| 1233 | qla24xx_post_upd_fcport_work(vha, ea->fcport); |
| 1234 | break; |
| 1235 | case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */ |
| 1236 | qla24xx_handle_plogi_done_event(vha, ea); |
| 1237 | break; |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1238 | case FCME_PRLI_DONE: |
| 1239 | qla24xx_handle_prli_done_event(vha, ea); |
| 1240 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1241 | case FCME_GPDB_DONE: |
| 1242 | qla24xx_handle_gpdb_event(vha, ea); |
| 1243 | break; |
| 1244 | case FCME_GPNID_DONE: |
| 1245 | qla24xx_handle_gpnid_event(vha, ea); |
| 1246 | break; |
Duane Grigsby | d3bae93 | 2017-06-21 13:48:44 -0700 | [diff] [blame] | 1247 | case FCME_GFFID_DONE: |
| 1248 | qla24xx_handle_gffid_event(vha, ea); |
| 1249 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1250 | case FCME_DELETE_DONE: |
| 1251 | qla24xx_handle_delete_done_event(vha, ea); |
| 1252 | break; |
| 1253 | default: |
| 1254 | BUG_ON(1); |
| 1255 | break; |
| 1256 | } |
| 1257 | } |
| 1258 | |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1259 | static void |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1260 | qla2x00_tmf_iocb_timeout(void *data) |
| 1261 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1262 | srb_t *sp = data; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1263 | struct srb_iocb *tmf = &sp->u.iocb_cmd; |
| 1264 | |
| 1265 | tmf->u.tmf.comp_status = CS_TIMEOUT; |
| 1266 | complete(&tmf->u.tmf.comp); |
| 1267 | } |
| 1268 | |
| 1269 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1270 | qla2x00_tmf_sp_done(void *ptr, int res) |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1271 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1272 | srb_t *sp = ptr; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1273 | struct srb_iocb *tmf = &sp->u.iocb_cmd; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1274 | |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1275 | complete(&tmf->u.tmf.comp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | int |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1279 | 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] | 1280 | uint32_t tag) |
| 1281 | { |
| 1282 | struct scsi_qla_host *vha = fcport->vha; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1283 | struct srb_iocb *tm_iocb; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1284 | srb_t *sp; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1285 | int rval = QLA_FUNCTION_FAILED; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1286 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1287 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1288 | if (!sp) |
| 1289 | goto done; |
| 1290 | |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1291 | tm_iocb = &sp->u.iocb_cmd; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1292 | sp->type = SRB_TM_CMD; |
| 1293 | sp->name = "tmf"; |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1294 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); |
| 1295 | tm_iocb->u.tmf.flags = flags; |
| 1296 | tm_iocb->u.tmf.lun = lun; |
| 1297 | tm_iocb->u.tmf.data = tag; |
| 1298 | sp->done = qla2x00_tmf_sp_done; |
| 1299 | tm_iocb->timeout = qla2x00_tmf_iocb_timeout; |
| 1300 | init_completion(&tm_iocb->u.tmf.comp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1301 | |
| 1302 | rval = qla2x00_start_sp(sp); |
| 1303 | if (rval != QLA_SUCCESS) |
| 1304 | goto done_free_sp; |
| 1305 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1306 | ql_dbg(ql_dbg_taskm, vha, 0x802f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1307 | "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n", |
| 1308 | sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 1309 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Armen Baloyan | faef62d | 2014-02-26 04:15:17 -0500 | [diff] [blame] | 1310 | |
| 1311 | wait_for_completion(&tm_iocb->u.tmf.comp); |
| 1312 | |
| 1313 | rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ? |
| 1314 | QLA_SUCCESS : QLA_FUNCTION_FAILED; |
| 1315 | |
| 1316 | if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) { |
| 1317 | ql_dbg(ql_dbg_taskm, vha, 0x8030, |
| 1318 | "TM IOCB failed (%x).\n", rval); |
| 1319 | } |
| 1320 | |
| 1321 | if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) { |
| 1322 | flags = tm_iocb->u.tmf.flags; |
| 1323 | lun = (uint16_t)tm_iocb->u.tmf.lun; |
| 1324 | |
| 1325 | /* Issue Marker IOCB */ |
| 1326 | qla2x00_marker(vha, vha->hw->req_q_map[0], |
| 1327 | vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun, |
| 1328 | flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID); |
| 1329 | } |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1330 | |
| 1331 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1332 | sp->free(sp); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1333 | done: |
| 1334 | return rval; |
| 1335 | } |
| 1336 | |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1337 | static void |
| 1338 | qla24xx_abort_iocb_timeout(void *data) |
| 1339 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1340 | srb_t *sp = data; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1341 | struct srb_iocb *abt = &sp->u.iocb_cmd; |
| 1342 | |
| 1343 | abt->u.abt.comp_status = CS_TIMEOUT; |
| 1344 | complete(&abt->u.abt.comp); |
| 1345 | } |
| 1346 | |
| 1347 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1348 | qla24xx_abort_sp_done(void *ptr, int res) |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1349 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1350 | srb_t *sp = ptr; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1351 | struct srb_iocb *abt = &sp->u.iocb_cmd; |
| 1352 | |
| 1353 | complete(&abt->u.abt.comp); |
| 1354 | } |
| 1355 | |
Quinn Tran | 15f30a5 | 2017-03-15 09:48:52 -0700 | [diff] [blame] | 1356 | int |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1357 | qla24xx_async_abort_cmd(srb_t *cmd_sp) |
| 1358 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1359 | scsi_qla_host_t *vha = cmd_sp->vha; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1360 | fc_port_t *fcport = cmd_sp->fcport; |
| 1361 | struct srb_iocb *abt_iocb; |
| 1362 | srb_t *sp; |
| 1363 | int rval = QLA_FUNCTION_FAILED; |
| 1364 | |
| 1365 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 1366 | if (!sp) |
| 1367 | goto done; |
| 1368 | |
| 1369 | abt_iocb = &sp->u.iocb_cmd; |
| 1370 | sp->type = SRB_ABT_CMD; |
| 1371 | sp->name = "abort"; |
| 1372 | qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)); |
| 1373 | abt_iocb->u.abt.cmd_hndl = cmd_sp->handle; |
| 1374 | sp->done = qla24xx_abort_sp_done; |
| 1375 | abt_iocb->timeout = qla24xx_abort_iocb_timeout; |
| 1376 | init_completion(&abt_iocb->u.abt.comp); |
| 1377 | |
| 1378 | rval = qla2x00_start_sp(sp); |
| 1379 | if (rval != QLA_SUCCESS) |
| 1380 | goto done_free_sp; |
| 1381 | |
| 1382 | ql_dbg(ql_dbg_async, vha, 0x507c, |
| 1383 | "Abort command issued - hdl=%x, target_id=%x\n", |
| 1384 | cmd_sp->handle, fcport->tgt_id); |
| 1385 | |
| 1386 | wait_for_completion(&abt_iocb->u.abt.comp); |
| 1387 | |
| 1388 | rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ? |
| 1389 | QLA_SUCCESS : QLA_FUNCTION_FAILED; |
| 1390 | |
| 1391 | done_free_sp: |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1392 | sp->free(sp); |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 1393 | done: |
| 1394 | return rval; |
| 1395 | } |
| 1396 | |
| 1397 | int |
| 1398 | qla24xx_async_abort_command(srb_t *sp) |
| 1399 | { |
| 1400 | unsigned long flags = 0; |
| 1401 | |
| 1402 | uint32_t handle; |
| 1403 | fc_port_t *fcport = sp->fcport; |
| 1404 | struct scsi_qla_host *vha = fcport->vha; |
| 1405 | struct qla_hw_data *ha = vha->hw; |
| 1406 | struct req_que *req = vha->req; |
| 1407 | |
| 1408 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1409 | for (handle = 1; handle < req->num_outstanding_cmds; handle++) { |
| 1410 | if (req->outstanding_cmds[handle] == sp) |
| 1411 | break; |
| 1412 | } |
| 1413 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1414 | if (handle == req->num_outstanding_cmds) { |
| 1415 | /* Command not found. */ |
| 1416 | return QLA_FUNCTION_FAILED; |
| 1417 | } |
| 1418 | if (sp->type == SRB_FXIOCB_DCMD) |
| 1419 | return qlafx00_fx_disc(vha, &vha->hw->mr.fcport, |
| 1420 | FXDISC_ABORT_IOCTL); |
| 1421 | |
| 1422 | return qla24xx_async_abort_cmd(sp); |
| 1423 | } |
| 1424 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1425 | static void |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1426 | qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea) |
| 1427 | { |
| 1428 | switch (ea->data[0]) { |
| 1429 | case MBS_COMMAND_COMPLETE: |
| 1430 | ql_dbg(ql_dbg_disc, vha, 0x2118, |
| 1431 | "%s %d %8phC post gpdb\n", |
| 1432 | __func__, __LINE__, ea->fcport->port_name); |
| 1433 | |
| 1434 | ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset; |
| 1435 | ea->fcport->logout_on_delete = 1; |
| 1436 | qla24xx_post_gpdb_work(vha, ea->fcport, 0); |
| 1437 | break; |
| 1438 | default: |
| 1439 | ql_dbg(ql_dbg_disc, vha, 0x2119, |
| 1440 | "%s %d %8phC unhandle event of %x\n", |
| 1441 | __func__, __LINE__, ea->fcport->port_name, ea->data[0]); |
| 1442 | break; |
| 1443 | } |
| 1444 | } |
| 1445 | |
| 1446 | static void |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1447 | 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] | 1448 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1449 | port_id_t cid; /* conflict Nport id */ |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1450 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1451 | switch (ea->data[0]) { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1452 | case MBS_COMMAND_COMPLETE: |
Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 1453 | /* |
| 1454 | * Driver must validate login state - If PRLI not complete, |
| 1455 | * force a relogin attempt via implicit LOGO, PLOGI, and PRLI |
| 1456 | * requests. |
| 1457 | */ |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 1458 | if (ea->fcport->fc4f_nvme) { |
| 1459 | ql_dbg(ql_dbg_disc, vha, 0x2117, |
| 1460 | "%s %d %8phC post prli\n", |
| 1461 | __func__, __LINE__, ea->fcport->port_name); |
| 1462 | qla24xx_post_prli_work(vha, ea->fcport); |
| 1463 | } else { |
| 1464 | ql_dbg(ql_dbg_disc, vha, 0x20ea, |
| 1465 | "%s %d %8phC post gpdb\n", |
| 1466 | __func__, __LINE__, ea->fcport->port_name); |
| 1467 | ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset; |
| 1468 | ea->fcport->logout_on_delete = 1; |
| 1469 | qla24xx_post_gpdb_work(vha, ea->fcport, 0); |
| 1470 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1471 | break; |
| 1472 | case MBS_COMMAND_ERROR: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1473 | 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] | 1474 | __func__, __LINE__, ea->fcport->port_name, ea->data[1]); |
| 1475 | |
| 1476 | ea->fcport->flags &= ~FCF_ASYNC_SENT; |
| 1477 | ea->fcport->disc_state = DSC_LOGIN_FAILED; |
| 1478 | if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1479 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1480 | else |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1481 | qla2x00_mark_device_lost(vha, ea->fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1482 | break; |
| 1483 | case MBS_LOOP_ID_USED: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1484 | /* data[1] = IO PARAM 1 = nport ID */ |
| 1485 | cid.b.domain = (ea->iop[1] >> 16) & 0xff; |
| 1486 | cid.b.area = (ea->iop[1] >> 8) & 0xff; |
| 1487 | cid.b.al_pa = ea->iop[1] & 0xff; |
| 1488 | cid.b.rsvd_1 = 0; |
| 1489 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1490 | ql_dbg(ql_dbg_disc, vha, 0x20ec, |
| 1491 | "%s %d %8phC LoopID 0x%x in use post gnl\n", |
| 1492 | __func__, __LINE__, ea->fcport->port_name, |
| 1493 | ea->fcport->loop_id); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1494 | |
| 1495 | if (IS_SW_RESV_ADDR(cid)) { |
| 1496 | set_bit(ea->fcport->loop_id, vha->hw->loop_id_map); |
| 1497 | ea->fcport->loop_id = FC_NO_LOOP_ID; |
| 1498 | } else { |
| 1499 | qla2x00_clear_loop_id(ea->fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1500 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1501 | qla24xx_post_gnl_work(vha, ea->fcport); |
| 1502 | break; |
| 1503 | case MBS_PORT_ID_USED: |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 1504 | ql_dbg(ql_dbg_disc, vha, 0x20ed, |
| 1505 | "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n", |
| 1506 | __func__, __LINE__, ea->fcport->port_name, |
| 1507 | ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area, |
| 1508 | ea->fcport->d_id.b.al_pa); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1509 | |
| 1510 | qla2x00_clear_loop_id(ea->fcport); |
| 1511 | qla24xx_post_gidpn_work(vha, ea->fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1512 | break; |
| 1513 | } |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1514 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1517 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1518 | qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 1519 | uint16_t *data) |
| 1520 | { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1521 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 1522 | qlt_logo_completion_handler(fcport, data[0]); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 1523 | fcport->login_gen++; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1524 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1527 | void |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1528 | qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 1529 | uint16_t *data) |
| 1530 | { |
| 1531 | if (data[0] == MBS_COMMAND_COMPLETE) { |
| 1532 | qla2x00_update_fcport(vha, fcport); |
| 1533 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1534 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | /* Retry login. */ |
| 1538 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 1539 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 1540 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 1541 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 1542 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1543 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1544 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | /****************************************************************************/ |
| 1548 | /* QLogic ISP2x00 Hardware Support Functions. */ |
| 1549 | /****************************************************************************/ |
| 1550 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 1551 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1552 | qla83xx_nic_core_fw_load(scsi_qla_host_t *vha) |
| 1553 | { |
| 1554 | int rval = QLA_SUCCESS; |
| 1555 | struct qla_hw_data *ha = vha->hw; |
| 1556 | uint32_t idc_major_ver, idc_minor_ver; |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 1557 | uint16_t config[4]; |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1558 | |
| 1559 | qla83xx_idc_lock(vha, 0); |
| 1560 | |
| 1561 | /* SV: TODO: Assign initialization timeout from |
| 1562 | * flash-info / other param |
| 1563 | */ |
| 1564 | ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT; |
| 1565 | ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT; |
| 1566 | |
| 1567 | /* Set our fcoe function presence */ |
| 1568 | if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) { |
| 1569 | ql_dbg(ql_dbg_p3p, vha, 0xb077, |
| 1570 | "Error while setting DRV-Presence.\n"); |
| 1571 | rval = QLA_FUNCTION_FAILED; |
| 1572 | goto exit; |
| 1573 | } |
| 1574 | |
| 1575 | /* Decide the reset ownership */ |
| 1576 | qla83xx_reset_ownership(vha); |
| 1577 | |
| 1578 | /* |
| 1579 | * On first protocol driver load: |
| 1580 | * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery |
| 1581 | * register. |
| 1582 | * Others: Check compatibility with current IDC Major version. |
| 1583 | */ |
| 1584 | qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver); |
| 1585 | if (ha->flags.nic_core_reset_owner) { |
| 1586 | /* Set IDC Major version */ |
| 1587 | idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION; |
| 1588 | qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver); |
| 1589 | |
| 1590 | /* Clearing IDC-Lock-Recovery register */ |
| 1591 | qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0); |
| 1592 | } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) { |
| 1593 | /* |
| 1594 | * Clear further IDC participation if we are not compatible with |
| 1595 | * the current IDC Major Version. |
| 1596 | */ |
| 1597 | ql_log(ql_log_warn, vha, 0xb07d, |
| 1598 | "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n", |
| 1599 | idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION); |
| 1600 | __qla83xx_clear_drv_presence(vha); |
| 1601 | rval = QLA_FUNCTION_FAILED; |
| 1602 | goto exit; |
| 1603 | } |
| 1604 | /* Each function sets its supported Minor version. */ |
| 1605 | qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver); |
| 1606 | idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2)); |
| 1607 | qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver); |
| 1608 | |
Saurav Kashyap | 711aa7f | 2012-08-22 14:21:15 -0400 | [diff] [blame] | 1609 | if (ha->flags.nic_core_reset_owner) { |
| 1610 | memset(config, 0, sizeof(config)); |
| 1611 | if (!qla81xx_get_port_config(vha, config)) |
| 1612 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 1613 | QLA8XXX_DEV_READY); |
| 1614 | } |
| 1615 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1616 | rval = qla83xx_idc_state_handler(vha); |
| 1617 | |
| 1618 | exit: |
| 1619 | qla83xx_idc_unlock(vha, 0); |
| 1620 | |
| 1621 | return rval; |
| 1622 | } |
| 1623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | /* |
| 1625 | * qla2x00_initialize_adapter |
| 1626 | * Initialize board. |
| 1627 | * |
| 1628 | * Input: |
| 1629 | * ha = adapter block pointer. |
| 1630 | * |
| 1631 | * Returns: |
| 1632 | * 0 = success |
| 1633 | */ |
| 1634 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1635 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | { |
| 1637 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1638 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1639 | struct req_que *req = ha->req_q_map[0]; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1640 | |
Joe Carnuccio | fc90ada | 2016-07-06 11:14:23 -0400 | [diff] [blame] | 1641 | memset(&vha->qla_stats, 0, sizeof(vha->qla_stats)); |
| 1642 | memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat)); |
| 1643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | /* Clear adapter flags. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1645 | vha->flags.online = 0; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1646 | ha->flags.chip_reset_done = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1647 | vha->flags.reset_active = 0; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1648 | ha->flags.pci_channel_io_perm_failure = 0; |
| 1649 | ha->flags.eeh_busy = 0; |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 1650 | vha->qla_stats.jiffies_at_last_reset = get_jiffies_64(); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1651 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 1652 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 1653 | vha->device_flags = DFLG_NO_CABLE; |
| 1654 | vha->dpc_flags = 0; |
| 1655 | vha->flags.management_server_logged_in = 0; |
| 1656 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | ha->isp_abort_cnt = 0; |
| 1658 | ha->beacon_blink_led = 0; |
| 1659 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1660 | set_bit(0, ha->req_qid_map); |
| 1661 | set_bit(0, ha->rsp_qid_map); |
| 1662 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1663 | ql_dbg(ql_dbg_init, vha, 0x0040, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1664 | "Configuring PCI space...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1665 | rval = ha->isp_ops->pci_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1667 | ql_log(ql_log_warn, vha, 0x0044, |
| 1668 | "Unable to configure PCI space.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | return (rval); |
| 1670 | } |
| 1671 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1672 | ha->isp_ops->reset_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1674 | rval = qla2xxx_get_flash_info(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 1675 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1676 | ql_log(ql_log_fatal, vha, 0x004f, |
| 1677 | "Unable to validate FLASH data.\n"); |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 1678 | return rval; |
| 1679 | } |
| 1680 | |
| 1681 | if (IS_QLA8044(ha)) { |
| 1682 | qla8044_read_reset_template(vha); |
| 1683 | |
| 1684 | /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0. |
| 1685 | * If DONRESET_BIT0 is set, drivers should not set dev_state |
| 1686 | * to NEED_RESET. But if NEED_RESET is set, drivers should |
| 1687 | * should honor the reset. */ |
| 1688 | if (ql2xdontresethba == 1) |
| 1689 | qla8044_set_idc_dontreset(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1692 | ha->isp_ops->get_flash_version(vha, req->ring); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1693 | ql_dbg(ql_dbg_init, vha, 0x0061, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1694 | "Configure NVRAM parameters...\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1695 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1696 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 1698 | if (ha->flags.disable_serdes) { |
| 1699 | /* Mask HBA via NVRAM settings? */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1700 | ql_log(ql_log_info, vha, 0x0077, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 1701 | "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name); |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 1702 | return QLA_FUNCTION_FAILED; |
| 1703 | } |
| 1704 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 1705 | ql_dbg(ql_dbg_init, vha, 0x0078, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1706 | "Verifying loaded RISC code...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1708 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { |
| 1709 | rval = ha->isp_ops->chip_diag(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 1710 | if (rval) |
| 1711 | return (rval); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1712 | rval = qla2x00_setup_chip(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 1713 | if (rval) |
| 1714 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1716 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1717 | if (IS_QLA84XX(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1718 | ha->cs84xx = qla84xx_get_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1719 | if (!ha->cs84xx) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1720 | ql_log(ql_log_warn, vha, 0x00d0, |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1721 | "Unable to configure ISP84XX.\n"); |
| 1722 | return QLA_FUNCTION_FAILED; |
| 1723 | } |
| 1724 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1725 | |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 1726 | if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 1727 | rval = qla2x00_init_rings(vha); |
| 1728 | |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 1729 | ha->flags.chip_reset_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1731 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 1732 | /* Issue verify 84xx FW IOCB to complete 84xx initialization */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1733 | rval = qla84xx_init_chip(vha); |
| 1734 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1735 | ql_log(ql_log_warn, vha, 0x00d4, |
| 1736 | "Unable to initialize ISP84XX.\n"); |
Bart Van Assche | 8d2b21d | 2015-06-04 15:58:09 -0700 | [diff] [blame] | 1737 | qla84xx_put_chip(vha); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1738 | } |
| 1739 | } |
| 1740 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 1741 | /* Load the NIC Core f/w if we are the first protocol driver. */ |
| 1742 | if (IS_QLA8031(ha)) { |
| 1743 | rval = qla83xx_nic_core_fw_load(vha); |
| 1744 | if (rval) |
| 1745 | ql_log(ql_log_warn, vha, 0x0124, |
| 1746 | "Error in initializing NIC Core f/w.\n"); |
| 1747 | } |
| 1748 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 1749 | if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) |
| 1750 | qla24xx_read_fcp_prio_cfg(vha); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 1751 | |
Joe Carnuccio | c46e65c | 2013-08-27 01:37:35 -0400 | [diff] [blame] | 1752 | if (IS_P3P_TYPE(ha)) |
| 1753 | qla82xx_set_driver_version(vha, QLA2XXX_VERSION); |
| 1754 | else |
| 1755 | qla25xx_set_driver_version(vha, QLA2XXX_VERSION); |
| 1756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | return (rval); |
| 1758 | } |
| 1759 | |
| 1760 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1761 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | * @ha: HA context |
| 1763 | * |
| 1764 | * Returns 0 on success. |
| 1765 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1766 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1767 | qla2100_pci_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1769 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1770 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1771 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1772 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 1775 | pci_try_set_mwi(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1778 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 1780 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1781 | pci_disable_rom(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1783 | /* Get PCI bus information. */ |
| 1784 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1785 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1786 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1787 | |
| 1788 | return QLA_SUCCESS; |
| 1789 | } |
| 1790 | |
| 1791 | /** |
| 1792 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
| 1793 | * @ha: HA context |
| 1794 | * |
| 1795 | * Returns 0 on success. |
| 1796 | */ |
| 1797 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1798 | qla2300_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1799 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1800 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1801 | unsigned long flags = 0; |
| 1802 | uint32_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1803 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1804 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1805 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1806 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 1807 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1808 | |
| 1809 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1810 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1811 | |
| 1812 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1813 | w &= ~PCI_COMMAND_INTX_DISABLE; |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1814 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1815 | |
| 1816 | /* |
| 1817 | * If this is a 2300 card and not 2312, reset the |
| 1818 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 1819 | * the 2310 also reports itself as a 2300 so we need to get the |
| 1820 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 1821 | * not a 2310. |
| 1822 | */ |
| 1823 | if (IS_QLA2300(ha)) { |
| 1824 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1825 | |
| 1826 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1827 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1828 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1829 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1830 | break; |
| 1831 | |
| 1832 | udelay(10); |
| 1833 | } |
| 1834 | |
| 1835 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1836 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 1837 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1838 | |
| 1839 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1840 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1841 | |
| 1842 | if (ha->fb_rev == FPM_2300) |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1843 | pci_clear_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1844 | |
| 1845 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1846 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 1847 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1848 | |
| 1849 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1850 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1851 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1852 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1853 | break; |
| 1854 | |
| 1855 | udelay(10); |
| 1856 | } |
| 1857 | |
| 1858 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1859 | } |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1860 | |
| 1861 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 1862 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1863 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1864 | |
| 1865 | /* Get PCI bus information. */ |
| 1866 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1867 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1868 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1869 | |
| 1870 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1874 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. |
| 1875 | * @ha: HA context |
| 1876 | * |
| 1877 | * Returns 0 on success. |
| 1878 | */ |
| 1879 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1880 | qla24xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1881 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1882 | uint16_t w; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1883 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1884 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1885 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1886 | |
| 1887 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 1888 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1889 | |
| 1890 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 1891 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1892 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 1893 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 1894 | |
| 1895 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 1896 | |
| 1897 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 1898 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
| 1899 | pcix_set_mmrbc(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1900 | |
| 1901 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 1902 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 1903 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1904 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1905 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1906 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 1907 | ha->chip_revision = ha->pdev->revision; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 1908 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1909 | /* Get PCI bus information. */ |
| 1910 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1911 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); |
| 1912 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1913 | |
| 1914 | return QLA_SUCCESS; |
| 1915 | } |
| 1916 | |
| 1917 | /** |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1918 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. |
| 1919 | * @ha: HA context |
| 1920 | * |
| 1921 | * Returns 0 on success. |
| 1922 | */ |
| 1923 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1924 | qla25xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1925 | { |
| 1926 | uint16_t w; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1927 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1928 | |
| 1929 | pci_set_master(ha->pdev); |
| 1930 | pci_try_set_mwi(ha->pdev); |
| 1931 | |
| 1932 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 1933 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 1934 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 1935 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 1936 | |
| 1937 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Jon Mason | e67f132 | 2012-07-10 14:57:56 -0700 | [diff] [blame] | 1938 | if (pci_is_pcie(ha->pdev)) |
Chad Dupuis | 5ffd3a5 | 2012-08-22 14:21:26 -0400 | [diff] [blame] | 1939 | pcie_set_readrq(ha->pdev, 4096); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1940 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 1941 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 1942 | |
| 1943 | ha->chip_revision = ha->pdev->revision; |
| 1944 | |
| 1945 | return QLA_SUCCESS; |
| 1946 | } |
| 1947 | |
| 1948 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | * qla2x00_isp_firmware() - Choose firmware image. |
| 1950 | * @ha: HA context |
| 1951 | * |
| 1952 | * Returns 0 on success. |
| 1953 | */ |
| 1954 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1955 | qla2x00_isp_firmware(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | { |
| 1957 | int rval; |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 1958 | uint16_t loop_id, topo, sw_cap; |
| 1959 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1960 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | |
| 1962 | /* Assume loading risc code */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1963 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | |
| 1965 | if (ha->flags.disable_risc_code_load) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1966 | ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | |
| 1968 | /* Verify checksum of loaded RISC code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1969 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 1970 | if (rval == QLA_SUCCESS) { |
| 1971 | /* And, verify we are not in ROM code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1972 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 1973 | &area, &domain, &topo, &sw_cap); |
| 1974 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1977 | if (rval) |
| 1978 | ql_dbg(ql_dbg_init, vha, 0x007a, |
| 1979 | "**** Load RISC code ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | |
| 1981 | return (rval); |
| 1982 | } |
| 1983 | |
| 1984 | /** |
| 1985 | * qla2x00_reset_chip() - Reset ISP chip. |
| 1986 | * @ha: HA context |
| 1987 | * |
| 1988 | * Returns 0 on success. |
| 1989 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1990 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1991 | qla2x00_reset_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | { |
| 1993 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1994 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1995 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | uint32_t cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | uint16_t cmd; |
| 1998 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1999 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 2000 | return; |
| 2001 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2002 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | |
| 2004 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2005 | |
| 2006 | /* Turn off master enable */ |
| 2007 | cmd = 0; |
| 2008 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 2009 | cmd &= ~PCI_COMMAND_MASTER; |
| 2010 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 2011 | |
| 2012 | if (!IS_QLA2100(ha)) { |
| 2013 | /* Pause RISC. */ |
| 2014 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 2015 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2016 | for (cnt = 0; cnt < 30000; cnt++) { |
| 2017 | if ((RD_REG_WORD(®->hccr) & |
| 2018 | HCCR_RISC_PAUSE) != 0) |
| 2019 | break; |
| 2020 | udelay(100); |
| 2021 | } |
| 2022 | } else { |
| 2023 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2024 | udelay(10); |
| 2025 | } |
| 2026 | |
| 2027 | /* Select FPM registers. */ |
| 2028 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 2029 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 2030 | |
| 2031 | /* FPM Soft Reset. */ |
| 2032 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 2033 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 2034 | |
| 2035 | /* Toggle Fpm Reset. */ |
| 2036 | if (!IS_QLA2200(ha)) { |
| 2037 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 2038 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 2039 | } |
| 2040 | |
| 2041 | /* Select frame buffer registers. */ |
| 2042 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 2043 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 2044 | |
| 2045 | /* Reset frame buffer FIFOs. */ |
| 2046 | if (IS_QLA2200(ha)) { |
| 2047 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 2048 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 2049 | } else { |
| 2050 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 2051 | |
| 2052 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 2053 | for (cnt = 0; cnt < 3000; cnt++) { |
| 2054 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 2055 | break; |
| 2056 | udelay(100); |
| 2057 | } |
| 2058 | } |
| 2059 | |
| 2060 | /* Select RISC module registers. */ |
| 2061 | WRT_REG_WORD(®->ctrl_status, 0); |
| 2062 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 2063 | |
| 2064 | /* Reset RISC processor. */ |
| 2065 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 2066 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2067 | |
| 2068 | /* Release RISC processor. */ |
| 2069 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 2070 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2071 | } |
| 2072 | |
| 2073 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 2074 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 2075 | |
| 2076 | /* Reset ISP chip. */ |
| 2077 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 2078 | |
| 2079 | /* Wait for RISC to recover from reset. */ |
| 2080 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2081 | /* |
| 2082 | * It is necessary to for a delay here since the card doesn't |
| 2083 | * respond to PCI reads during a reset. On some architectures |
| 2084 | * this will result in an MCA. |
| 2085 | */ |
| 2086 | udelay(20); |
| 2087 | for (cnt = 30000; cnt; cnt--) { |
| 2088 | if ((RD_REG_WORD(®->ctrl_status) & |
| 2089 | CSR_ISP_SOFT_RESET) == 0) |
| 2090 | break; |
| 2091 | udelay(100); |
| 2092 | } |
| 2093 | } else |
| 2094 | udelay(10); |
| 2095 | |
| 2096 | /* Reset RISC processor. */ |
| 2097 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 2098 | |
| 2099 | WRT_REG_WORD(®->semaphore, 0); |
| 2100 | |
| 2101 | /* Release RISC processor. */ |
| 2102 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 2103 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2104 | |
| 2105 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2106 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 2107 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | |
| 2110 | udelay(100); |
| 2111 | } |
| 2112 | } else |
| 2113 | udelay(100); |
| 2114 | |
| 2115 | /* Turn on master enable */ |
| 2116 | cmd |= PCI_COMMAND_MASTER; |
| 2117 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 2118 | |
| 2119 | /* Disable RISC pause on FPM parity error. */ |
| 2120 | if (!IS_QLA2100(ha)) { |
| 2121 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 2122 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 2123 | } |
| 2124 | |
| 2125 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2126 | } |
| 2127 | |
| 2128 | /** |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2129 | * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. |
| 2130 | * |
| 2131 | * Returns 0 on success. |
| 2132 | */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 2133 | static int |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2134 | qla81xx_reset_mpi(scsi_qla_host_t *vha) |
| 2135 | { |
| 2136 | uint16_t mb[4] = {0x1010, 0, 1, 0}; |
| 2137 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2138 | if (!IS_QLA81XX(vha->hw)) |
| 2139 | return QLA_SUCCESS; |
| 2140 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2141 | return qla81xx_write_mpi_register(vha, mb); |
| 2142 | } |
| 2143 | |
| 2144 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2145 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2146 | * @ha: HA context |
| 2147 | * |
| 2148 | * Returns 0 on success. |
| 2149 | */ |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2150 | static inline int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2151 | qla24xx_reset_risc(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2152 | { |
| 2153 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2154 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2155 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2156 | uint32_t cnt; |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2157 | uint16_t wd; |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2158 | static int abts_cnt; /* ISP abort retry counts */ |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2159 | int rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2160 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2161 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2162 | |
| 2163 | /* Reset RISC. */ |
| 2164 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
| 2165 | for (cnt = 0; cnt < 30000; cnt++) { |
| 2166 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) |
| 2167 | break; |
| 2168 | |
| 2169 | udelay(10); |
| 2170 | } |
| 2171 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2172 | if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE)) |
| 2173 | set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags); |
| 2174 | |
| 2175 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e, |
| 2176 | "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n", |
| 2177 | RD_REG_DWORD(®->hccr), |
| 2178 | RD_REG_DWORD(®->ctrl_status), |
| 2179 | (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE)); |
| 2180 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2181 | WRT_REG_DWORD(®->ctrl_status, |
| 2182 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2183 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2184 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2185 | udelay(100); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2186 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2187 | /* Wait for firmware to complete NVRAM accesses. */ |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2188 | RD_REG_WORD(®->mailbox0); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2189 | for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 && |
| 2190 | rval == QLA_SUCCESS; cnt--) { |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2191 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2192 | if (cnt) |
| 2193 | udelay(5); |
| 2194 | else |
| 2195 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2196 | } |
| 2197 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2198 | if (rval == QLA_SUCCESS) |
| 2199 | set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags); |
| 2200 | |
| 2201 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f, |
| 2202 | "HCCR: 0x%x, MailBox0 Status 0x%x\n", |
| 2203 | RD_REG_DWORD(®->hccr), |
| 2204 | RD_REG_DWORD(®->mailbox0)); |
| 2205 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 2206 | /* Wait for soft-reset to complete. */ |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2207 | RD_REG_DWORD(®->ctrl_status); |
Quinn Tran | 200ffb1 | 2016-12-23 18:06:12 -0800 | [diff] [blame] | 2208 | for (cnt = 0; cnt < 60; cnt++) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2209 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2210 | if ((RD_REG_DWORD(®->ctrl_status) & |
| 2211 | CSRX_ISP_SOFT_RESET) == 0) |
| 2212 | break; |
| 2213 | |
| 2214 | udelay(5); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2215 | } |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2216 | if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET)) |
| 2217 | set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags); |
| 2218 | |
| 2219 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d, |
| 2220 | "HCCR: 0x%x, Soft Reset status: 0x%x\n", |
| 2221 | RD_REG_DWORD(®->hccr), |
| 2222 | RD_REG_DWORD(®->ctrl_status)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2223 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 2224 | /* If required, do an MPI FW reset now */ |
| 2225 | if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { |
| 2226 | if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { |
| 2227 | if (++abts_cnt < 5) { |
| 2228 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 2229 | set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); |
| 2230 | } else { |
| 2231 | /* |
| 2232 | * We exhausted the ISP abort retries. We have to |
| 2233 | * set the board offline. |
| 2234 | */ |
| 2235 | abts_cnt = 0; |
| 2236 | vha->flags.online = 0; |
| 2237 | } |
| 2238 | } |
| 2239 | } |
| 2240 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2241 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 2242 | RD_REG_DWORD(®->hccr); |
| 2243 | |
| 2244 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 2245 | RD_REG_DWORD(®->hccr); |
| 2246 | |
| 2247 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); |
| 2248 | RD_REG_DWORD(®->hccr); |
| 2249 | |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2250 | RD_REG_WORD(®->mailbox0); |
Quinn Tran | 200ffb1 | 2016-12-23 18:06:12 -0800 | [diff] [blame] | 2251 | for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 && |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2252 | rval == QLA_SUCCESS; cnt--) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2253 | barrier(); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2254 | if (cnt) |
| 2255 | udelay(5); |
| 2256 | else |
| 2257 | rval = QLA_FUNCTION_TIMEOUT; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2258 | } |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2259 | if (rval == QLA_SUCCESS) |
| 2260 | set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags); |
| 2261 | |
| 2262 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e, |
| 2263 | "Host Risc 0x%x, mailbox0 0x%x\n", |
| 2264 | RD_REG_DWORD(®->hccr), |
| 2265 | RD_REG_WORD(®->mailbox0)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2266 | |
| 2267 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 2268 | |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2269 | ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f, |
| 2270 | "Driver in %s mode\n", |
| 2271 | IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling"); |
| 2272 | |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 2273 | if (IS_NOPOLLING_TYPE(ha)) |
| 2274 | ha->isp_ops->enable_intrs(ha); |
Himanshu Madhani | d14e72f | 2015-04-09 15:00:03 -0400 | [diff] [blame] | 2275 | |
| 2276 | return rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2277 | } |
| 2278 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2279 | static void |
| 2280 | qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data) |
| 2281 | { |
| 2282 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 2283 | |
| 2284 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 2285 | *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET); |
| 2286 | |
| 2287 | } |
| 2288 | |
| 2289 | static void |
| 2290 | qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data) |
| 2291 | { |
| 2292 | struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24; |
| 2293 | |
| 2294 | WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET); |
| 2295 | WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data); |
| 2296 | } |
| 2297 | |
| 2298 | static void |
| 2299 | qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha) |
| 2300 | { |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2301 | uint32_t wd32 = 0; |
| 2302 | uint delta_msec = 100; |
| 2303 | uint elapsed_msec = 0; |
| 2304 | uint timeout_msec; |
| 2305 | ulong n; |
| 2306 | |
Joe Carnuccio | cc79076 | 2015-08-04 13:37:53 -0400 | [diff] [blame] | 2307 | if (vha->hw->pdev->subsystem_device != 0x0175 && |
| 2308 | vha->hw->pdev->subsystem_device != 0x0240) |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2309 | return; |
| 2310 | |
Joe Carnuccio | 8dd7e3a | 2015-08-04 13:37:54 -0400 | [diff] [blame] | 2311 | WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE); |
| 2312 | udelay(100); |
| 2313 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2314 | attempt: |
| 2315 | timeout_msec = TIMEOUT_SEMAPHORE; |
| 2316 | n = timeout_msec / delta_msec; |
| 2317 | while (n--) { |
| 2318 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET); |
| 2319 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 2320 | if (wd32 & RISC_SEMAPHORE) |
| 2321 | break; |
| 2322 | msleep(delta_msec); |
| 2323 | elapsed_msec += delta_msec; |
| 2324 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 2325 | goto force; |
| 2326 | } |
| 2327 | |
| 2328 | if (!(wd32 & RISC_SEMAPHORE)) |
| 2329 | goto force; |
| 2330 | |
| 2331 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 2332 | goto acquired; |
| 2333 | |
| 2334 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR); |
| 2335 | timeout_msec = TIMEOUT_SEMAPHORE_FORCE; |
| 2336 | n = timeout_msec / delta_msec; |
| 2337 | while (n--) { |
| 2338 | qla25xx_read_risc_sema_reg(vha, &wd32); |
| 2339 | if (!(wd32 & RISC_SEMAPHORE_FORCE)) |
| 2340 | break; |
| 2341 | msleep(delta_msec); |
| 2342 | elapsed_msec += delta_msec; |
| 2343 | if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED) |
| 2344 | goto force; |
| 2345 | } |
| 2346 | |
| 2347 | if (wd32 & RISC_SEMAPHORE_FORCE) |
| 2348 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR); |
| 2349 | |
| 2350 | goto attempt; |
| 2351 | |
| 2352 | force: |
| 2353 | qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET); |
| 2354 | |
| 2355 | acquired: |
| 2356 | return; |
| 2357 | } |
| 2358 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2359 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2360 | * qla24xx_reset_chip() - Reset ISP24xx chip. |
| 2361 | * @ha: HA context |
| 2362 | * |
| 2363 | * Returns 0 on success. |
| 2364 | */ |
| 2365 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2366 | qla24xx_reset_chip(scsi_qla_host_t *vha) |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2367 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2368 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 2369 | |
| 2370 | if (pci_channel_offline(ha->pdev) && |
| 2371 | ha->flags.pci_channel_io_perm_failure) { |
| 2372 | return; |
| 2373 | } |
| 2374 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 2375 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2376 | |
Joe Carnuccio | 4ea2c9c | 2012-11-21 02:40:37 -0500 | [diff] [blame] | 2377 | qla25xx_manipulate_risc_semaphore(vha); |
| 2378 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2379 | /* Perform RISC reset. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2380 | qla24xx_reset_risc(vha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | * qla2x00_chip_diag() - Test chip for proper operation. |
| 2385 | * @ha: HA context |
| 2386 | * |
| 2387 | * Returns 0 on success. |
| 2388 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2389 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2390 | qla2x00_chip_diag(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | { |
| 2392 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2393 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2394 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | unsigned long flags = 0; |
| 2396 | uint16_t data; |
| 2397 | uint32_t cnt; |
| 2398 | uint16_t mb[5]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2399 | struct req_que *req = ha->req_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | |
| 2401 | /* Assume a failed state */ |
| 2402 | rval = QLA_FUNCTION_FAILED; |
| 2403 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2404 | ql_dbg(ql_dbg_init, vha, 0x007b, |
| 2405 | "Testing device at %lx.\n", (u_long)®->flash_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | |
| 2407 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2408 | |
| 2409 | /* Reset ISP chip. */ |
| 2410 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 2411 | |
| 2412 | /* |
| 2413 | * We need to have a delay here since the card will not respond while |
| 2414 | * in reset causing an MCA on some architectures. |
| 2415 | */ |
| 2416 | udelay(20); |
| 2417 | data = qla2x00_debounce_register(®->ctrl_status); |
| 2418 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 2419 | udelay(5); |
| 2420 | data = RD_REG_WORD(®->ctrl_status); |
| 2421 | barrier(); |
| 2422 | } |
| 2423 | |
| 2424 | if (!cnt) |
| 2425 | goto chip_diag_failed; |
| 2426 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2427 | ql_dbg(ql_dbg_init, vha, 0x007c, |
| 2428 | "Reset register cleared by chip reset.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | |
| 2430 | /* Reset RISC processor. */ |
| 2431 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 2432 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 2433 | |
| 2434 | /* Workaround for QLA2312 PCI parity error */ |
| 2435 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 2436 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 2437 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 2438 | udelay(5); |
| 2439 | data = RD_MAILBOX_REG(ha, reg, 0); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2440 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | } |
| 2442 | } else |
| 2443 | udelay(10); |
| 2444 | |
| 2445 | if (!cnt) |
| 2446 | goto chip_diag_failed; |
| 2447 | |
| 2448 | /* Check product ID of chip */ |
Milan P Gandhi | 5a68a1c | 2017-03-31 14:37:04 -0700 | [diff] [blame] | 2449 | 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] | 2450 | |
| 2451 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 2452 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 2453 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 2454 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 2455 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 2456 | mb[3] != PROD_ID_3) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2457 | ql_log(ql_log_warn, vha, 0x0062, |
| 2458 | "Wrong product ID = 0x%x,0x%x,0x%x.\n", |
| 2459 | mb[1], mb[2], mb[3]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | |
| 2461 | goto chip_diag_failed; |
| 2462 | } |
| 2463 | ha->product_id[0] = mb[1]; |
| 2464 | ha->product_id[1] = mb[2]; |
| 2465 | ha->product_id[2] = mb[3]; |
| 2466 | ha->product_id[3] = mb[4]; |
| 2467 | |
| 2468 | /* Adjust fw RISC transfer size */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2469 | if (req->length > 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 2471 | else |
| 2472 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2473 | req->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | |
| 2475 | if (IS_QLA2200(ha) && |
| 2476 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 2477 | /* Limit firmware transfer size with a 2200A */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2478 | ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 2480 | ha->device_type |= DT_ISP2200A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | ha->fw_transfer_size = 128; |
| 2482 | } |
| 2483 | |
| 2484 | /* Wrap Incoming Mailboxes Test. */ |
| 2485 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2486 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2487 | ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2488 | rval = qla2x00_mbx_reg_test(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2489 | if (rval) |
| 2490 | ql_log(ql_log_warn, vha, 0x0080, |
| 2491 | "Failed mailbox send register test.\n"); |
| 2492 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | /* Flag a successful rval */ |
| 2494 | rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2495 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2496 | |
| 2497 | chip_diag_failed: |
| 2498 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2499 | ql_log(ql_log_info, vha, 0x0081, |
| 2500 | "Chip diagnostics **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | |
| 2502 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2503 | |
| 2504 | return (rval); |
| 2505 | } |
| 2506 | |
| 2507 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2508 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. |
| 2509 | * @ha: HA context |
| 2510 | * |
| 2511 | * Returns 0 on success. |
| 2512 | */ |
| 2513 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2514 | qla24xx_chip_diag(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2515 | { |
| 2516 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2517 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2518 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2519 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2520 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2521 | return QLA_SUCCESS; |
| 2522 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2523 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2524 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2525 | rval = qla2x00_mbx_reg_test(vha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2526 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2527 | ql_log(ql_log_warn, vha, 0x0082, |
| 2528 | "Failed mailbox send register test.\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2529 | } else { |
| 2530 | /* Flag a successful rval */ |
| 2531 | rval = QLA_SUCCESS; |
| 2532 | } |
| 2533 | |
| 2534 | return rval; |
| 2535 | } |
| 2536 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2537 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2538 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2539 | { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2540 | int rval; |
| 2541 | 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] | 2542 | eft_size, fce_size, mq_size; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2543 | dma_addr_t tc_dma; |
| 2544 | void *tc; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2545 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2546 | struct req_que *req = ha->req_q_map[0]; |
| 2547 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2548 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2549 | if (ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2550 | ql_dbg(ql_dbg_init, vha, 0x00bd, |
| 2551 | "Firmware dump already allocated.\n"); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2552 | return; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2553 | } |
| 2554 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2555 | ha->fw_dumped = 0; |
Hiral Patel | 61f098d | 2014-04-11 16:54:21 -0400 | [diff] [blame] | 2556 | ha->fw_dump_cap_flags = 0; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2557 | dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0; |
| 2558 | req_q_size = rsp_q_size = 0; |
| 2559 | |
| 2560 | if (IS_QLA27XX(ha)) |
| 2561 | goto try_fce; |
| 2562 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2563 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2564 | fixed_size = sizeof(struct qla2100_fw_dump); |
| 2565 | } else if (IS_QLA23XX(ha)) { |
| 2566 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
| 2567 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * |
| 2568 | sizeof(uint16_t); |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2569 | } else if (IS_FWI2_CAPABLE(ha)) { |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 2570 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2571 | fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem); |
| 2572 | else if (IS_QLA81XX(ha)) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 2573 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); |
| 2574 | else if (IS_QLA25XX(ha)) |
| 2575 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); |
| 2576 | else |
| 2577 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2578 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2579 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
| 2580 | sizeof(uint32_t); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 2581 | if (ha->mqenable) { |
Himanshu Madhani | b20f02e | 2015-06-10 11:05:18 -0400 | [diff] [blame] | 2582 | if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha)) |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 2583 | mq_size = sizeof(struct qla2xxx_mq_chain); |
Giridhar Malavali | 050c9bb | 2012-02-09 11:15:33 -0800 | [diff] [blame] | 2584 | /* |
| 2585 | * Allocate maximum buffer size for all queues. |
| 2586 | * Resizing must be done at end-of-dump processing. |
| 2587 | */ |
| 2588 | mq_size += ha->max_req_queues * |
| 2589 | (req->length * sizeof(request_t)); |
| 2590 | mq_size += ha->max_rsp_queues * |
| 2591 | (rsp->length * sizeof(response_t)); |
| 2592 | } |
Arun Easi | 00876ae | 2013-03-25 02:21:37 -0400 | [diff] [blame] | 2593 | if (ha->tgt.atio_ring) |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 2594 | mq_size += ha->tgt.atio_q_length * sizeof(request_t); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2595 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2596 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) && |
| 2597 | !IS_QLA27XX(ha)) |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2598 | goto try_eft; |
| 2599 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2600 | try_fce: |
| 2601 | if (ha->fce) |
| 2602 | dma_free_coherent(&ha->pdev->dev, |
| 2603 | FCE_SIZE, ha->fce, ha->fce_dma); |
| 2604 | |
| 2605 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Joe Perches | 0ea85b5 | 2014-06-15 13:37:51 -0700 | [diff] [blame] | 2606 | tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, |
| 2607 | GFP_KERNEL); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2608 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2609 | ql_log(ql_log_warn, vha, 0x00be, |
| 2610 | "Unable to allocate (%d KB) for FCE.\n", |
| 2611 | FCE_SIZE / 1024); |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 2612 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2613 | } |
| 2614 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2615 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2616 | ha->fce_mb, &ha->fce_bufs); |
| 2617 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2618 | ql_log(ql_log_warn, vha, 0x00bf, |
| 2619 | "Unable to initialize FCE (%d).\n", rval); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2620 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, |
| 2621 | tc_dma); |
| 2622 | ha->flags.fce_enabled = 0; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 2623 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2624 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2625 | ql_dbg(ql_dbg_init, vha, 0x00c0, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2626 | "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2627 | |
Giridhar Malavali | 7d9dade | 2009-03-24 09:07:58 -0700 | [diff] [blame] | 2628 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2629 | ha->flags.fce_enabled = 1; |
| 2630 | ha->fce_dma = tc_dma; |
| 2631 | ha->fce = tc; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2632 | |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 2633 | try_eft: |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2634 | if (ha->eft) |
| 2635 | dma_free_coherent(&ha->pdev->dev, |
| 2636 | EFT_SIZE, ha->eft, ha->eft_dma); |
| 2637 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2638 | /* Allocate memory for Extended Trace Buffer. */ |
Joe Perches | 0ea85b5 | 2014-06-15 13:37:51 -0700 | [diff] [blame] | 2639 | tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, |
| 2640 | GFP_KERNEL); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2641 | if (!tc) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2642 | ql_log(ql_log_warn, vha, 0x00c1, |
| 2643 | "Unable to allocate (%d KB) for EFT.\n", |
| 2644 | EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2645 | goto cont_alloc; |
| 2646 | } |
| 2647 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2648 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2649 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2650 | ql_log(ql_log_warn, vha, 0x00c2, |
| 2651 | "Unable to initialize EFT (%d).\n", rval); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2652 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, |
| 2653 | tc_dma); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2654 | goto cont_alloc; |
| 2655 | } |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2656 | ql_dbg(ql_dbg_init, vha, 0x00c3, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2657 | "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2658 | |
| 2659 | eft_size = EFT_SIZE; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 2660 | ha->eft_dma = tc_dma; |
| 2661 | ha->eft = tc; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2662 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2663 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2664 | cont_alloc: |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2665 | if (IS_QLA27XX(ha)) { |
| 2666 | if (!ha->fw_dump_template) { |
| 2667 | ql_log(ql_log_warn, vha, 0x00ba, |
| 2668 | "Failed missing fwdump template\n"); |
| 2669 | return; |
| 2670 | } |
| 2671 | dump_size = qla27xx_fwdt_calculate_dump_size(vha); |
| 2672 | ql_dbg(ql_dbg_init, vha, 0x00fa, |
| 2673 | "-> allocating fwdump (%x bytes)...\n", dump_size); |
| 2674 | goto allocate; |
| 2675 | } |
| 2676 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2677 | req_q_size = req->length * sizeof(request_t); |
| 2678 | rsp_q_size = rsp->length * sizeof(response_t); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2679 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 2680 | 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] | 2681 | ha->chain_offset = dump_size; |
| 2682 | dump_size += mq_size + fce_size; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2683 | |
Quinn Tran | b945e77 | 2017-06-13 20:47:29 -0700 | [diff] [blame] | 2684 | if (ha->exchoffld_buf) |
| 2685 | dump_size += sizeof(struct qla2xxx_offld_chain) + |
| 2686 | ha->exchoffld_size; |
| 2687 | if (ha->exlogin_buf) |
| 2688 | dump_size += sizeof(struct qla2xxx_offld_chain) + |
| 2689 | ha->exlogin_size; |
| 2690 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2691 | allocate: |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 2692 | ha->fw_dump = vmalloc(dump_size); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2693 | if (!ha->fw_dump) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2694 | ql_log(ql_log_warn, vha, 0x00c4, |
| 2695 | "Unable to allocate (%d KB) for firmware dump.\n", |
| 2696 | dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2697 | |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 2698 | if (ha->fce) { |
| 2699 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, |
| 2700 | ha->fce_dma); |
| 2701 | ha->fce = NULL; |
| 2702 | ha->fce_dma = 0; |
| 2703 | } |
| 2704 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2705 | if (ha->eft) { |
| 2706 | dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, |
| 2707 | ha->eft_dma); |
| 2708 | ha->eft = NULL; |
| 2709 | ha->eft_dma = 0; |
| 2710 | } |
| 2711 | return; |
| 2712 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2713 | ha->fw_dump_len = dump_size; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 2714 | ql_dbg(ql_dbg_init, vha, 0x00c5, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2715 | "Allocated (%d KB) for firmware dump.\n", dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2716 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2717 | if (IS_QLA27XX(ha)) |
| 2718 | return; |
| 2719 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2720 | ha->fw_dump->signature[0] = 'Q'; |
| 2721 | ha->fw_dump->signature[1] = 'L'; |
| 2722 | ha->fw_dump->signature[2] = 'G'; |
| 2723 | ha->fw_dump->signature[3] = 'C'; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2724 | ha->fw_dump->version = htonl(1); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 2725 | |
| 2726 | ha->fw_dump->fixed_size = htonl(fixed_size); |
| 2727 | ha->fw_dump->mem_size = htonl(mem_size); |
| 2728 | ha->fw_dump->req_q_size = htonl(req_q_size); |
| 2729 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); |
| 2730 | |
| 2731 | ha->fw_dump->eft_size = htonl(eft_size); |
| 2732 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); |
| 2733 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); |
| 2734 | |
| 2735 | ha->fw_dump->header_size = |
| 2736 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2739 | static int |
| 2740 | qla81xx_mpi_sync(scsi_qla_host_t *vha) |
| 2741 | { |
| 2742 | #define MPS_MASK 0xe0 |
| 2743 | int rval; |
| 2744 | uint16_t dc; |
| 2745 | uint32_t dw; |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2746 | |
| 2747 | if (!IS_QLA81XX(vha->hw)) |
| 2748 | return QLA_SUCCESS; |
| 2749 | |
| 2750 | rval = qla2x00_write_ram_word(vha, 0x7c00, 1); |
| 2751 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2752 | ql_log(ql_log_warn, vha, 0x0105, |
| 2753 | "Unable to acquire semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2754 | goto done; |
| 2755 | } |
| 2756 | |
| 2757 | pci_read_config_word(vha->hw->pdev, 0x54, &dc); |
| 2758 | rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); |
| 2759 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2760 | ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2761 | goto done_release; |
| 2762 | } |
| 2763 | |
| 2764 | dc &= MPS_MASK; |
| 2765 | if (dc == (dw & MPS_MASK)) |
| 2766 | goto done_release; |
| 2767 | |
| 2768 | dw &= ~MPS_MASK; |
| 2769 | dw |= dc; |
| 2770 | rval = qla2x00_write_ram_word(vha, 0x7a15, dw); |
| 2771 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2772 | ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | done_release: |
| 2776 | rval = qla2x00_write_ram_word(vha, 0x7c00, 0); |
| 2777 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2778 | ql_log(ql_log_warn, vha, 0x006d, |
| 2779 | "Unable to release semaphore.\n"); |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 2780 | } |
| 2781 | |
| 2782 | done: |
| 2783 | return rval; |
| 2784 | } |
| 2785 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2786 | int |
| 2787 | qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req) |
| 2788 | { |
| 2789 | /* Don't try to reallocate the array */ |
| 2790 | if (req->outstanding_cmds) |
| 2791 | return QLA_SUCCESS; |
| 2792 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 2793 | if (!IS_FWI2_CAPABLE(ha)) |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2794 | req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS; |
| 2795 | else { |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 2796 | if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count) |
| 2797 | req->num_outstanding_cmds = ha->cur_fw_xcb_count; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2798 | else |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 2799 | req->num_outstanding_cmds = ha->cur_fw_iocb_count; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2800 | } |
| 2801 | |
| 2802 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 2803 | req->num_outstanding_cmds, GFP_KERNEL); |
| 2804 | |
| 2805 | if (!req->outstanding_cmds) { |
| 2806 | /* |
| 2807 | * Try to allocate a minimal size just so we can get through |
| 2808 | * initialization. |
| 2809 | */ |
| 2810 | req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS; |
| 2811 | req->outstanding_cmds = kzalloc(sizeof(srb_t *) * |
| 2812 | req->num_outstanding_cmds, GFP_KERNEL); |
| 2813 | |
| 2814 | if (!req->outstanding_cmds) { |
| 2815 | ql_log(ql_log_fatal, NULL, 0x0126, |
| 2816 | "Failed to allocate memory for " |
| 2817 | "outstanding_cmds for req_que %p.\n", req); |
| 2818 | req->num_outstanding_cmds = 0; |
| 2819 | return QLA_FUNCTION_FAILED; |
| 2820 | } |
| 2821 | } |
| 2822 | |
| 2823 | return QLA_SUCCESS; |
| 2824 | } |
| 2825 | |
Quinn Tran | e4e3a2c | 2017-08-23 15:05:07 -0700 | [diff] [blame] | 2826 | #define PRINT_FIELD(_field, _flag, _str) { \ |
| 2827 | if (a0->_field & _flag) {\ |
| 2828 | if (p) {\ |
| 2829 | strcat(ptr, "|");\ |
| 2830 | ptr++;\ |
| 2831 | leftover--;\ |
| 2832 | } \ |
| 2833 | len = snprintf(ptr, leftover, "%s", _str); \ |
| 2834 | p = 1;\ |
| 2835 | leftover -= len;\ |
| 2836 | ptr += len; \ |
| 2837 | } \ |
| 2838 | } |
| 2839 | |
| 2840 | static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha) |
| 2841 | { |
| 2842 | #define STR_LEN 64 |
| 2843 | struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data; |
| 2844 | u8 str[STR_LEN], *ptr, p; |
| 2845 | int leftover, len; |
| 2846 | |
| 2847 | memset(str, 0, STR_LEN); |
| 2848 | snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name); |
| 2849 | ql_dbg(ql_dbg_init, vha, 0x015a, |
| 2850 | "SFP MFG Name: %s\n", str); |
| 2851 | |
| 2852 | memset(str, 0, STR_LEN); |
| 2853 | snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn); |
| 2854 | ql_dbg(ql_dbg_init, vha, 0x015c, |
| 2855 | "SFP Part Name: %s\n", str); |
| 2856 | |
| 2857 | /* media */ |
| 2858 | memset(str, 0, STR_LEN); |
| 2859 | ptr = str; |
| 2860 | leftover = STR_LEN; |
| 2861 | p = len = 0; |
| 2862 | PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX"); |
| 2863 | PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair"); |
| 2864 | PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax"); |
| 2865 | PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax"); |
| 2866 | PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um"); |
| 2867 | PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um"); |
| 2868 | PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode"); |
| 2869 | ql_dbg(ql_dbg_init, vha, 0x0160, |
| 2870 | "SFP Media: %s\n", str); |
| 2871 | |
| 2872 | /* link length */ |
| 2873 | memset(str, 0, STR_LEN); |
| 2874 | ptr = str; |
| 2875 | leftover = STR_LEN; |
| 2876 | p = len = 0; |
| 2877 | PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long"); |
| 2878 | PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short"); |
| 2879 | PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate"); |
| 2880 | PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long"); |
| 2881 | PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium"); |
| 2882 | ql_dbg(ql_dbg_init, vha, 0x0196, |
| 2883 | "SFP Link Length: %s\n", str); |
| 2884 | |
| 2885 | memset(str, 0, STR_LEN); |
| 2886 | ptr = str; |
| 2887 | leftover = STR_LEN; |
| 2888 | p = len = 0; |
| 2889 | PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)"); |
| 2890 | PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)"); |
| 2891 | PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)"); |
| 2892 | PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)"); |
| 2893 | PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)"); |
| 2894 | ql_dbg(ql_dbg_init, vha, 0x016e, |
| 2895 | "SFP FC Link Tech: %s\n", str); |
| 2896 | |
| 2897 | if (a0->length_km) |
| 2898 | ql_dbg(ql_dbg_init, vha, 0x016f, |
| 2899 | "SFP Distant: %d km\n", a0->length_km); |
| 2900 | if (a0->length_100m) |
| 2901 | ql_dbg(ql_dbg_init, vha, 0x0170, |
| 2902 | "SFP Distant: %d m\n", a0->length_100m*100); |
| 2903 | if (a0->length_50um_10m) |
| 2904 | ql_dbg(ql_dbg_init, vha, 0x0189, |
| 2905 | "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10); |
| 2906 | if (a0->length_62um_10m) |
| 2907 | ql_dbg(ql_dbg_init, vha, 0x018a, |
| 2908 | "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10); |
| 2909 | if (a0->length_om4_10m) |
| 2910 | ql_dbg(ql_dbg_init, vha, 0x0194, |
| 2911 | "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10); |
| 2912 | if (a0->length_om3_10m) |
| 2913 | ql_dbg(ql_dbg_init, vha, 0x0195, |
| 2914 | "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10); |
| 2915 | } |
| 2916 | |
| 2917 | |
| 2918 | /* |
| 2919 | * Return Code: |
| 2920 | * QLA_SUCCESS: no action |
| 2921 | * QLA_INTERFACE_ERROR: SFP is not there. |
| 2922 | * QLA_FUNCTION_FAILED: detected New SFP |
| 2923 | */ |
| 2924 | int |
| 2925 | qla24xx_detect_sfp(scsi_qla_host_t *vha) |
| 2926 | { |
| 2927 | int rc = QLA_SUCCESS; |
| 2928 | struct sff_8247_a0 *a; |
| 2929 | struct qla_hw_data *ha = vha->hw; |
| 2930 | |
| 2931 | if (!AUTO_DETECT_SFP_SUPPORT(vha)) |
| 2932 | goto out; |
| 2933 | |
| 2934 | rc = qla2x00_read_sfp_dev(vha, NULL, 0); |
| 2935 | if (rc) |
| 2936 | goto out; |
| 2937 | |
| 2938 | a = (struct sff_8247_a0 *)vha->hw->sfp_data; |
| 2939 | qla2xxx_print_sfp_info(vha); |
| 2940 | |
| 2941 | if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) { |
| 2942 | /* long range */ |
| 2943 | ha->flags.detected_lr_sfp = 1; |
| 2944 | |
| 2945 | if (a->length_km > 5 || a->length_100m > 50) |
| 2946 | ha->long_range_distance = LR_DISTANCE_10K; |
| 2947 | else |
| 2948 | ha->long_range_distance = LR_DISTANCE_5K; |
| 2949 | |
| 2950 | if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting) |
| 2951 | ql_dbg(ql_dbg_async, vha, 0x507b, |
| 2952 | "Detected Long Range SFP.\n"); |
| 2953 | } else { |
| 2954 | /* short range */ |
| 2955 | ha->flags.detected_lr_sfp = 0; |
| 2956 | if (ha->flags.using_lr_setting) |
| 2957 | ql_dbg(ql_dbg_async, vha, 0x5084, |
| 2958 | "Detected Short Range SFP.\n"); |
| 2959 | } |
| 2960 | |
| 2961 | if (!vha->flags.init_done) |
| 2962 | rc = QLA_SUCCESS; |
| 2963 | out: |
| 2964 | return rc; |
| 2965 | } |
| 2966 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2967 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | * qla2x00_setup_chip() - Load and start RISC firmware. |
| 2969 | * @ha: HA context |
| 2970 | * |
| 2971 | * Returns 0 on success. |
| 2972 | */ |
| 2973 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2974 | qla2x00_setup_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2976 | int rval; |
| 2977 | uint32_t srisc_address = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2978 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 2979 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 2980 | unsigned long flags; |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 2981 | uint16_t fw_major_version; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 2982 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2983 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2984 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 2985 | if (rval == QLA_SUCCESS) { |
| 2986 | qla2x00_stop_firmware(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2987 | goto enable_82xx_npiv; |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 2988 | } else |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 2989 | goto failed; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2990 | } |
| 2991 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 2992 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 2993 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 2994 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2995 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 2996 | RD_REG_WORD(®->hccr); |
| 2997 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2998 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 3000 | qla81xx_mpi_sync(vha); |
| 3001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | /* Load firmware sequences */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3003 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3004 | if (rval == QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3005 | ql_dbg(ql_dbg_init, vha, 0x00c9, |
| 3006 | "Verifying Checksum of loaded RISC code.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3008 | rval = qla2x00_verify_checksum(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | if (rval == QLA_SUCCESS) { |
| 3010 | /* Start firmware execution. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3011 | ql_dbg(ql_dbg_init, vha, 0x00ca, |
| 3012 | "Starting firmware.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | |
Himanshu Madhani | b0d6cab | 2015-12-17 14:56:56 -0500 | [diff] [blame] | 3014 | if (ql2xexlogins) |
| 3015 | ha->flags.exlogins_enabled = 1; |
| 3016 | |
Quinn Tran | 99e1b68 | 2017-06-02 09:12:03 -0700 | [diff] [blame] | 3017 | if (qla_is_exch_offld_enabled(vha)) |
Himanshu Madhani | 2f56a7f | 2015-12-17 14:56:57 -0500 | [diff] [blame] | 3018 | ha->flags.exchoffld_enabled = 1; |
| 3019 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3020 | rval = qla2x00_execute_fw(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | /* Retrieve firmware information. */ |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 3022 | if (rval == QLA_SUCCESS) { |
Quinn Tran | e4e3a2c | 2017-08-23 15:05:07 -0700 | [diff] [blame] | 3023 | qla24xx_detect_sfp(vha); |
| 3024 | |
Himanshu Madhani | b0d6cab | 2015-12-17 14:56:56 -0500 | [diff] [blame] | 3025 | rval = qla2x00_set_exlogins_buffer(vha); |
| 3026 | if (rval != QLA_SUCCESS) |
| 3027 | goto failed; |
| 3028 | |
Himanshu Madhani | 2f56a7f | 2015-12-17 14:56:57 -0500 | [diff] [blame] | 3029 | rval = qla2x00_set_exchoffld_buffer(vha); |
| 3030 | if (rval != QLA_SUCCESS) |
| 3031 | goto failed; |
| 3032 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3033 | enable_82xx_npiv: |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 3034 | fw_major_version = ha->fw_major_version; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 3035 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 3036 | qla82xx_check_md_needed(vha); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3037 | else |
| 3038 | rval = qla2x00_get_fw_version(vha); |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 3039 | if (rval != QLA_SUCCESS) |
| 3040 | goto failed; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3041 | ha->flags.npiv_supported = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3042 | if (IS_QLA2XXX_MIDTYPE(ha) && |
Mike Hernandez | 946fb89 | 2008-08-13 21:36:59 -0700 | [diff] [blame] | 3043 | (ha->fw_attributes & BIT_2)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3044 | ha->flags.npiv_supported = 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 3045 | if ((!ha->max_npiv_vports) || |
| 3046 | ((ha->max_npiv_vports + 1) % |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 3047 | MIN_MULTI_ID_FABRIC)) |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 3048 | ha->max_npiv_vports = |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 3049 | MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 3050 | } |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3051 | qla2x00_get_resource_cnts(vha); |
Andrew Vasquez | d743de6 | 2009-03-24 09:08:15 -0700 | [diff] [blame] | 3052 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3053 | /* |
| 3054 | * Allocate the array of outstanding commands |
| 3055 | * now that we know the firmware resources. |
| 3056 | */ |
| 3057 | rval = qla2x00_alloc_outstanding_cmds(ha, |
| 3058 | vha->req); |
| 3059 | if (rval != QLA_SUCCESS) |
| 3060 | goto failed; |
| 3061 | |
Saurav Kashyap | be5ea3c | 2011-11-18 09:02:11 -0800 | [diff] [blame] | 3062 | if (!fw_major_version && ql2xallocfwdump |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 3063 | && !(IS_P3P_TYPE(ha))) |
Giridhar Malavali | 08de284 | 2011-08-16 11:31:44 -0700 | [diff] [blame] | 3064 | qla2x00_alloc_fw_dump(vha); |
Chad Dupuis | 3b6e5b9 | 2013-10-30 03:38:09 -0400 | [diff] [blame] | 3065 | } else { |
| 3066 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | } |
| 3068 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3069 | ql_log(ql_log_fatal, vha, 0x00cd, |
| 3070 | "ISP Firmware failed checksum.\n"); |
| 3071 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | } |
Andrew Vasquez | c74d88a | 2012-08-22 14:21:19 -0400 | [diff] [blame] | 3073 | } else |
| 3074 | goto failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 3076 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 3077 | /* Enable proper parity. */ |
| 3078 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3079 | if (IS_QLA2300(ha)) |
| 3080 | /* SRAM parity */ |
| 3081 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); |
| 3082 | else |
| 3083 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 3084 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); |
| 3085 | RD_REG_WORD(®->hccr); |
| 3086 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3087 | } |
| 3088 | |
Chad Dupuis | f3982d8 | 2014-09-25 05:16:57 -0400 | [diff] [blame] | 3089 | if (IS_QLA27XX(ha)) |
| 3090 | ha->flags.fac_supported = 1; |
| 3091 | else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 3092 | uint32_t size; |
| 3093 | |
| 3094 | rval = qla81xx_fac_get_sector_size(vha, &size); |
| 3095 | if (rval == QLA_SUCCESS) { |
| 3096 | ha->flags.fac_supported = 1; |
| 3097 | ha->fdt_block_size = size << 2; |
| 3098 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3099 | ql_log(ql_log_warn, vha, 0x00ce, |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 3100 | "Unsupported FAC firmware (%d.%02d.%02d).\n", |
| 3101 | ha->fw_major_version, ha->fw_minor_version, |
| 3102 | ha->fw_subminor_version); |
Joe Carnuccio | 1ca60e3 | 2014-02-26 04:15:02 -0500 | [diff] [blame] | 3103 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 3104 | if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3105 | ha->flags.fac_supported = 0; |
| 3106 | rval = QLA_SUCCESS; |
| 3107 | } |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 3108 | } |
| 3109 | } |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 3110 | failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3111 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3112 | ql_log(ql_log_fatal, vha, 0x00cf, |
| 3113 | "Setup chip ****FAILED****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | } |
| 3115 | |
| 3116 | return (rval); |
| 3117 | } |
| 3118 | |
| 3119 | /** |
| 3120 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
| 3121 | * @ha: HA context |
| 3122 | * |
| 3123 | * Beginning of request ring has initialization control block already built |
| 3124 | * by nvram config routine. |
| 3125 | * |
| 3126 | * Returns 0 on success. |
| 3127 | */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3128 | void |
| 3129 | qla2x00_init_response_q_entries(struct rsp_que *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 | { |
| 3131 | uint16_t cnt; |
| 3132 | response_t *pkt; |
| 3133 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3134 | rsp->ring_ptr = rsp->ring; |
| 3135 | rsp->ring_index = 0; |
| 3136 | rsp->status_srb = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3137 | pkt = rsp->ring_ptr; |
| 3138 | for (cnt = 0; cnt < rsp->length; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | pkt->signature = RESPONSE_PROCESSED; |
| 3140 | pkt++; |
| 3141 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3142 | } |
| 3143 | |
| 3144 | /** |
| 3145 | * qla2x00_update_fw_options() - Read and process firmware options. |
| 3146 | * @ha: HA context |
| 3147 | * |
| 3148 | * Returns 0 on success. |
| 3149 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3150 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3151 | qla2x00_update_fw_options(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | { |
| 3153 | uint16_t swing, emphasis, tx_sens, rx_sens; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3154 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | |
| 3156 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3157 | qla2x00_get_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | |
| 3159 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 3160 | return; |
| 3161 | |
| 3162 | /* Serial Link options. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3163 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115, |
| 3164 | "Serial link options.\n"); |
| 3165 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109, |
| 3166 | (uint8_t *)&ha->fw_seriallink_options, |
| 3167 | sizeof(ha->fw_seriallink_options)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | |
| 3169 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 3170 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 3171 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 3172 | |
| 3173 | /* 1G settings */ |
| 3174 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 3175 | emphasis = (ha->fw_seriallink_options[2] & |
| 3176 | (BIT_4 | BIT_3)) >> 3; |
| 3177 | tx_sens = ha->fw_seriallink_options[0] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3178 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | rx_sens = (ha->fw_seriallink_options[0] & |
| 3180 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 3181 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 3182 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 3183 | if (rx_sens == 0x0) |
| 3184 | rx_sens = 0x3; |
| 3185 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 3186 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 3187 | ha->fw_options[10] |= BIT_5 | |
| 3188 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 3189 | (tx_sens & (BIT_1 | BIT_0)); |
| 3190 | |
| 3191 | /* 2G settings */ |
| 3192 | swing = (ha->fw_seriallink_options[2] & |
| 3193 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 3194 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 3195 | tx_sens = ha->fw_seriallink_options[1] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3196 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 | rx_sens = (ha->fw_seriallink_options[1] & |
| 3198 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 3199 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 3200 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 3201 | if (rx_sens == 0x0) |
| 3202 | rx_sens = 0x3; |
| 3203 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 3204 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 3205 | ha->fw_options[11] |= BIT_5 | |
| 3206 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 3207 | (tx_sens & (BIT_1 | BIT_0)); |
| 3208 | } |
| 3209 | |
| 3210 | /* FCP2 options. */ |
| 3211 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 3212 | ha->fw_options[3] |= BIT_13; |
| 3213 | |
| 3214 | /* LED scheme. */ |
| 3215 | if (ha->flags.enable_led_scheme) |
| 3216 | ha->fw_options[2] |= BIT_12; |
| 3217 | |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 3218 | /* Detect ISP6312. */ |
| 3219 | if (IS_QLA6312(ha)) |
| 3220 | ha->fw_options[2] |= BIT_13; |
| 3221 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 3222 | /* Set Retry FLOGI in case of P2P connection */ |
| 3223 | if (ha->operating_mode == P2P) { |
| 3224 | ha->fw_options[2] |= BIT_3; |
| 3225 | ql_dbg(ql_dbg_disc, vha, 0x2100, |
| 3226 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 3227 | __func__, ha->fw_options[2]); |
| 3228 | } |
| 3229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | /* Update firmware options. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3231 | qla2x00_set_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | } |
| 3233 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3234 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3235 | qla24xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3236 | { |
| 3237 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3238 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3239 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 3240 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3241 | return; |
| 3242 | |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 3243 | /* Hold status IOCBs until ABTS response received. */ |
| 3244 | if (ql2xfwholdabts) |
| 3245 | ha->fw_options[3] |= BIT_12; |
| 3246 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 3247 | /* Set Retry FLOGI in case of P2P connection */ |
| 3248 | if (ha->operating_mode == P2P) { |
| 3249 | ha->fw_options[2] |= BIT_3; |
| 3250 | ql_dbg(ql_dbg_disc, vha, 0x2101, |
| 3251 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 3252 | __func__, ha->fw_options[2]); |
| 3253 | } |
| 3254 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 3255 | /* Move PUREX, ABTS RX & RIDA to ATIOQ */ |
Quinn Tran | 3c4810f | 2017-06-02 09:11:53 -0700 | [diff] [blame] | 3256 | if (ql2xmvasynctoatio && |
| 3257 | (IS_QLA83XX(ha) || IS_QLA27XX(ha))) { |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 3258 | if (qla_tgt_mode_enabled(vha) || |
| 3259 | qla_dual_mode_enabled(vha)) |
| 3260 | ha->fw_options[2] |= BIT_11; |
| 3261 | else |
| 3262 | ha->fw_options[2] &= ~BIT_11; |
| 3263 | } |
| 3264 | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 3265 | if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
| 3266 | /* |
| 3267 | * Tell FW to track each exchange to prevent |
| 3268 | * driver from using stale exchange. |
| 3269 | */ |
| 3270 | if (qla_tgt_mode_enabled(vha) || |
| 3271 | qla_dual_mode_enabled(vha)) |
| 3272 | ha->fw_options[2] |= BIT_4; |
| 3273 | else |
| 3274 | ha->fw_options[2] &= ~BIT_4; |
| 3275 | } |
| 3276 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3277 | ql_dbg(ql_dbg_init, vha, 0x00e8, |
| 3278 | "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n", |
| 3279 | __func__, ha->fw_options[1], ha->fw_options[2], |
| 3280 | ha->fw_options[3], vha->host->active_mode); |
Quinn Tran | 3c4810f | 2017-06-02 09:11:53 -0700 | [diff] [blame] | 3281 | |
| 3282 | if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3]) |
| 3283 | qla2x00_set_fw_options(vha, ha->fw_options); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 3284 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3285 | /* Update Serial Link options. */ |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 3286 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3287 | return; |
| 3288 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3289 | rval = qla2x00_set_serdes_params(vha, |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 3290 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
| 3291 | le16_to_cpu(ha->fw_seriallink_options24[2]), |
| 3292 | le16_to_cpu(ha->fw_seriallink_options24[3])); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3293 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3294 | ql_log(ql_log_warn, vha, 0x0104, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3295 | "Unable to update Serial Link options (%x).\n", rval); |
| 3296 | } |
| 3297 | } |
| 3298 | |
| 3299 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3300 | qla2x00_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3301 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3302 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 3303 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3304 | struct req_que *req = ha->req_q_map[0]; |
| 3305 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3306 | |
| 3307 | /* Setup ring parameters in initialization control block. */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3308 | ha->init_cb->request_q_outpointer = cpu_to_le16(0); |
| 3309 | ha->init_cb->response_q_inpointer = cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3310 | ha->init_cb->request_q_length = cpu_to_le16(req->length); |
| 3311 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); |
| 3312 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 3313 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 3314 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 3315 | 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] | 3316 | |
| 3317 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 3318 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 3319 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 3320 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 3321 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 3322 | } |
| 3323 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3324 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3325 | qla24xx_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3326 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3327 | struct qla_hw_data *ha = vha->hw; |
Bart Van Assche | 118e2ef | 2015-07-09 07:24:27 -0700 | [diff] [blame] | 3328 | device_reg_t *reg = ISP_QUE_REG(ha, 0); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3329 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
| 3330 | struct qla_msix_entry *msix; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3331 | struct init_cb_24xx *icb; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3332 | uint16_t rid = 0; |
| 3333 | struct req_que *req = ha->req_q_map[0]; |
| 3334 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3335 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3336 | /* Setup ring parameters in initialization control block. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3337 | icb = (struct init_cb_24xx *)ha->init_cb; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3338 | icb->request_q_outpointer = cpu_to_le16(0); |
| 3339 | icb->response_q_inpointer = cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3340 | icb->request_q_length = cpu_to_le16(req->length); |
| 3341 | icb->response_q_length = cpu_to_le16(rsp->length); |
| 3342 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 3343 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 3344 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 3345 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3346 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3347 | /* Setup ATIO queue dma pointers for target mode */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3348 | icb->atio_q_inpointer = cpu_to_le16(0); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3349 | icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length); |
| 3350 | icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma)); |
| 3351 | icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma)); |
| 3352 | |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3353 | if (IS_SHADOW_REG_CAPABLE(ha)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3354 | icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29); |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3355 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 3356 | if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3357 | icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS); |
| 3358 | icb->rid = cpu_to_le16(rid); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3359 | if (ha->flags.msix_enabled) { |
| 3360 | msix = &ha->msix_entries[1]; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3361 | ql_dbg(ql_dbg_init, vha, 0x0019, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3362 | "Registering vector 0x%x for base que.\n", |
| 3363 | msix->entry); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3364 | icb->msix = cpu_to_le16(msix->entry); |
| 3365 | } |
| 3366 | /* Use alternate PCI bus number */ |
| 3367 | if (MSB(rid)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3368 | icb->firmware_options_2 |= cpu_to_le32(BIT_19); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3369 | /* Use alternate PCI devfn */ |
| 3370 | if (LSB(rid)) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3371 | icb->firmware_options_2 |= cpu_to_le32(BIT_18); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3372 | |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3373 | /* Use Disable MSIX Handshake mode for capable adapters */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3374 | if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) && |
| 3375 | (ha->flags.msix_enabled)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3376 | icb->firmware_options_2 &= cpu_to_le32(~BIT_22); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3377 | ha->flags.disable_msix_handshake = 1; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3378 | ql_dbg(ql_dbg_init, vha, 0x00fe, |
| 3379 | "MSIX Handshake Disable Mode turned on.\n"); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3380 | } else { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3381 | icb->firmware_options_2 |= cpu_to_le32(BIT_22); |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 3382 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3383 | icb->firmware_options_2 |= cpu_to_le32(BIT_23); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3384 | |
| 3385 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); |
| 3386 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); |
| 3387 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); |
| 3388 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); |
| 3389 | } else { |
| 3390 | WRT_REG_DWORD(®->isp24.req_q_in, 0); |
| 3391 | WRT_REG_DWORD(®->isp24.req_q_out, 0); |
| 3392 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); |
| 3393 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); |
| 3394 | } |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 3395 | qlt_24xx_config_rings(vha); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3396 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3397 | /* PCI posting */ |
| 3398 | RD_REG_DWORD(&ioreg->hccr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3399 | } |
| 3400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | /** |
| 3402 | * qla2x00_init_rings() - Initializes firmware. |
| 3403 | * @ha: HA context |
| 3404 | * |
| 3405 | * Beginning of request ring has initialization control block already built |
| 3406 | * by nvram config routine. |
| 3407 | * |
| 3408 | * Returns 0 on success. |
| 3409 | */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3410 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3411 | qla2x00_init_rings(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | { |
| 3413 | int rval; |
| 3414 | unsigned long flags = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3415 | int cnt, que; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3416 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3417 | struct req_que *req; |
| 3418 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3419 | struct mid_init_cb_24xx *mid_init_cb = |
| 3420 | (struct mid_init_cb_24xx *) ha->init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | |
| 3422 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3423 | |
| 3424 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3425 | for (que = 0; que < ha->max_req_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3426 | req = ha->req_q_map[que]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 3427 | if (!req || !test_bit(que, ha->req_qid_map)) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3428 | continue; |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3429 | req->out_ptr = (void *)(req->ring + req->length); |
| 3430 | *req->out_ptr = 0; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3431 | for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3432 | req->outstanding_cmds[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3433 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3434 | req->current_outstanding_cmd = 1; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3435 | |
| 3436 | /* Initialize firmware. */ |
| 3437 | req->ring_ptr = req->ring; |
| 3438 | req->ring_index = 0; |
| 3439 | req->cnt = req->length; |
| 3440 | } |
| 3441 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 3442 | for (que = 0; que < ha->max_rsp_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3443 | rsp = ha->rsp_q_map[que]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 3444 | if (!rsp || !test_bit(que, ha->rsp_qid_map)) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3445 | continue; |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3446 | rsp->in_ptr = (void *)(rsp->ring + rsp->length); |
| 3447 | *rsp->in_ptr = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3448 | /* Initialize response queue entries */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3449 | if (IS_QLAFX00(ha)) |
| 3450 | qlafx00_init_response_q_entries(rsp); |
| 3451 | else |
| 3452 | qla2x00_init_response_q_entries(rsp); |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3453 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3455 | ha->tgt.atio_ring_ptr = ha->tgt.atio_ring; |
| 3456 | ha->tgt.atio_ring_index = 0; |
| 3457 | /* Initialize ATIO queue entries */ |
| 3458 | qlt_init_atio_q_entries(vha); |
| 3459 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3460 | ha->isp_ops->config_rings(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3461 | |
| 3462 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3463 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3464 | ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n"); |
| 3465 | |
| 3466 | if (IS_QLAFX00(ha)) { |
| 3467 | rval = qlafx00_init_firmware(vha, ha->init_cb_size); |
| 3468 | goto next_check; |
| 3469 | } |
| 3470 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3471 | /* Update any ISP specific firmware options before initialization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3472 | ha->isp_ops->update_fw_options(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3474 | if (ha->flags.npiv_supported) { |
Saurav Kashyap | 45980cc | 2012-08-22 14:21:21 -0400 | [diff] [blame] | 3475 | if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha)) |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3476 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 3477 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 3478 | } |
| 3479 | |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3480 | if (IS_FWI2_CAPABLE(ha)) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3481 | mid_init_cb->options = cpu_to_le16(BIT_1); |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3482 | mid_init_cb->init_cb.execution_throttle = |
Quinn Tran | 03e8c68 | 2015-12-17 14:56:59 -0500 | [diff] [blame] | 3483 | cpu_to_le16(ha->cur_fw_xcb_count); |
Joe Carnuccio | 40f3862 | 2016-07-06 11:14:28 -0400 | [diff] [blame] | 3484 | ha->flags.dport_enabled = |
| 3485 | (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0; |
| 3486 | ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n", |
| 3487 | (ha->flags.dport_enabled) ? "enabled" : "disabled"); |
| 3488 | /* FA-WWPN Status */ |
Himanshu Madhani | 2486c62 | 2014-09-25 05:17:00 -0400 | [diff] [blame] | 3489 | ha->flags.fawwpn_enabled = |
Joe Carnuccio | 40f3862 | 2016-07-06 11:14:28 -0400 | [diff] [blame] | 3490 | (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 3491 | ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n", |
Himanshu Madhani | 2486c62 | 2014-09-25 05:17:00 -0400 | [diff] [blame] | 3492 | (ha->flags.fawwpn_enabled) ? "enabled" : "disabled"); |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 3493 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3494 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3495 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3496 | next_check: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3497 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3498 | ql_log(ql_log_fatal, vha, 0x00d2, |
| 3499 | "Init Firmware **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3501 | ql_dbg(ql_dbg_init, vha, 0x00d3, |
| 3502 | "Init Firmware -- success.\n"); |
Quinn Tran | 4b60c82 | 2017-06-13 20:47:21 -0700 | [diff] [blame] | 3503 | QLA_FW_STARTED(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | } |
| 3505 | |
| 3506 | return (rval); |
| 3507 | } |
| 3508 | |
| 3509 | /** |
| 3510 | * qla2x00_fw_ready() - Waits for firmware ready. |
| 3511 | * @ha: HA context |
| 3512 | * |
| 3513 | * Returns 0 on success. |
| 3514 | */ |
| 3515 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3516 | qla2x00_fw_ready(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | { |
| 3518 | int rval; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3519 | unsigned long wtime, mtime, cs84xx_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3520 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 3521 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
Joe Carnuccio | b5a340d | 2014-09-25 05:16:48 -0400 | [diff] [blame] | 3522 | uint16_t state[6]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3523 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3525 | if (IS_QLAFX00(vha->hw)) |
| 3526 | return qlafx00_fw_ready(vha); |
| 3527 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | rval = QLA_SUCCESS; |
| 3529 | |
Chad Dupuis | 33461491 | 2015-04-09 14:59:57 -0400 | [diff] [blame] | 3530 | /* Time to wait for loop down */ |
| 3531 | if (IS_P3P_TYPE(ha)) |
| 3532 | min_wait = 30; |
| 3533 | else |
| 3534 | min_wait = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | |
| 3536 | /* |
| 3537 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 3538 | * our own processing. |
| 3539 | */ |
| 3540 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 3541 | wait_time = min_wait; |
| 3542 | } |
| 3543 | |
| 3544 | /* Min wait time if loop down */ |
| 3545 | mtime = jiffies + (min_wait * HZ); |
| 3546 | |
| 3547 | /* wait time before firmware ready */ |
| 3548 | wtime = jiffies + (wait_time * HZ); |
| 3549 | |
| 3550 | /* Wait for ISP to finish LIP */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3551 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3552 | ql_log(ql_log_info, vha, 0x801e, |
| 3553 | "Waiting for LIP to complete.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3554 | |
| 3555 | do { |
Andrew Vasquez | 5b93903 | 2012-11-21 02:40:26 -0500 | [diff] [blame] | 3556 | memset(state, -1, sizeof(state)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3557 | rval = qla2x00_get_firmware_state(vha, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3558 | if (rval == QLA_SUCCESS) { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3559 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3560 | vha->device_flags &= ~DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3562 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3563 | ql_dbg(ql_dbg_taskm, vha, 0x801f, |
| 3564 | "fw_state=%x 84xx=%x.\n", state[0], |
| 3565 | state[2]); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3566 | if ((state[2] & FSTATE_LOGGED_IN) && |
| 3567 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3568 | ql_dbg(ql_dbg_taskm, vha, 0x8028, |
| 3569 | "Sending verify iocb.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3570 | |
| 3571 | cs84xx_time = jiffies; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3572 | rval = qla84xx_init_chip(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3573 | if (rval != QLA_SUCCESS) { |
| 3574 | ql_log(ql_log_warn, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3575 | vha, 0x8007, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3576 | "Init chip failed.\n"); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3577 | break; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3578 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3579 | |
| 3580 | /* Add time taken to initialize. */ |
| 3581 | cs84xx_time = jiffies - cs84xx_time; |
| 3582 | wtime += cs84xx_time; |
| 3583 | mtime += cs84xx_time; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3584 | ql_dbg(ql_dbg_taskm, vha, 0x8008, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3585 | "Increasing wait time by %ld. " |
| 3586 | "New time %ld.\n", cs84xx_time, |
| 3587 | wtime); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3588 | } |
| 3589 | } else if (state[0] == FSTATE_READY) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3590 | ql_dbg(ql_dbg_taskm, vha, 0x8037, |
| 3591 | "F/W Ready - OK.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3593 | qla2x00_get_retry_cnt(vha, &ha->retry_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3594 | &ha->login_timeout, &ha->r_a_tov); |
| 3595 | |
| 3596 | rval = QLA_SUCCESS; |
| 3597 | break; |
| 3598 | } |
| 3599 | |
| 3600 | rval = QLA_FUNCTION_FAILED; |
| 3601 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3602 | if (atomic_read(&vha->loop_down_timer) && |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 3603 | state[0] != FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | /* Loop down. Timeout on min_wait for states |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3605 | * other than Wait for Login. |
| 3606 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 | if (time_after_eq(jiffies, mtime)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3608 | ql_log(ql_log_info, vha, 0x8038, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | "Cable is unplugged...\n"); |
| 3610 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3611 | vha->device_flags |= DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | break; |
| 3613 | } |
| 3614 | } |
| 3615 | } else { |
| 3616 | /* Mailbox cmd failed. Timeout on min_wait. */ |
Santosh Vernekar | cdbb0a4f | 2010-05-28 15:08:25 -0700 | [diff] [blame] | 3617 | if (time_after_eq(jiffies, mtime) || |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 3618 | ha->flags.isp82xx_fw_hung) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | break; |
| 3620 | } |
| 3621 | |
| 3622 | if (time_after_eq(jiffies, wtime)) |
| 3623 | break; |
| 3624 | |
| 3625 | /* Delay for a while */ |
| 3626 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3627 | } while (1); |
| 3628 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3629 | ql_dbg(ql_dbg_taskm, vha, 0x803a, |
Joe Carnuccio | b5a340d | 2014-09-25 05:16:48 -0400 | [diff] [blame] | 3630 | "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0], |
| 3631 | state[1], state[2], state[3], state[4], state[5], jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 3633 | if (rval && !(vha->device_flags & DFLG_NO_CABLE)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3634 | ql_log(ql_log_warn, vha, 0x803b, |
| 3635 | "Firmware ready **** FAILED ****.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | } |
| 3637 | |
| 3638 | return (rval); |
| 3639 | } |
| 3640 | |
| 3641 | /* |
| 3642 | * qla2x00_configure_hba |
| 3643 | * Setup adapter context. |
| 3644 | * |
| 3645 | * Input: |
| 3646 | * ha = adapter state pointer. |
| 3647 | * |
| 3648 | * Returns: |
| 3649 | * 0 = success |
| 3650 | * |
| 3651 | * Context: |
| 3652 | * Kernel context. |
| 3653 | */ |
| 3654 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3655 | qla2x00_configure_hba(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3656 | { |
| 3657 | int rval; |
| 3658 | uint16_t loop_id; |
| 3659 | uint16_t topo; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3660 | uint16_t sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3661 | uint8_t al_pa; |
| 3662 | uint8_t area; |
| 3663 | uint8_t domain; |
| 3664 | char connect_type[22]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3665 | struct qla_hw_data *ha = vha->hw; |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 3666 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 3667 | port_id_t id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | |
| 3669 | /* Get host addresses. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3670 | rval = qla2x00_get_adapter_id(vha, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3671 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3672 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3673 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3674 | IS_CNA_CAPABLE(ha) || |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3675 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3676 | ql_dbg(ql_dbg_disc, vha, 0x2008, |
| 3677 | "Loop is in a transition state.\n"); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3678 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3679 | ql_log(ql_log_warn, vha, 0x2009, |
| 3680 | "Unable to get host loop ID.\n"); |
Joe Carnuccio | 61e1b26 | 2013-02-08 01:57:48 -0500 | [diff] [blame] | 3681 | if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) && |
| 3682 | (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) { |
| 3683 | ql_log(ql_log_warn, vha, 0x1151, |
| 3684 | "Doing link init.\n"); |
| 3685 | if (qla24xx_link_initialize(vha) == QLA_SUCCESS) |
| 3686 | return rval; |
| 3687 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3688 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 3689 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | return (rval); |
| 3691 | } |
| 3692 | |
| 3693 | if (topo == 4) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3694 | ql_log(ql_log_info, vha, 0x200a, |
| 3695 | "Cannot get topology - retrying.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | return (QLA_FUNCTION_FAILED); |
| 3697 | } |
| 3698 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3699 | vha->loop_id = loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3700 | |
| 3701 | /* initialize */ |
| 3702 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 3703 | ha->operating_mode = LOOP; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3704 | ha->switch_cap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3705 | |
| 3706 | switch (topo) { |
| 3707 | case 0: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3708 | ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | ha->current_topology = ISP_CFG_NL; |
| 3710 | strcpy(connect_type, "(Loop)"); |
| 3711 | break; |
| 3712 | |
| 3713 | case 1: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3714 | ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n"); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3715 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 | ha->current_topology = ISP_CFG_FL; |
| 3717 | strcpy(connect_type, "(FL_Port)"); |
| 3718 | break; |
| 3719 | |
| 3720 | case 2: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3721 | 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] | 3722 | ha->operating_mode = P2P; |
| 3723 | ha->current_topology = ISP_CFG_N; |
| 3724 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 3725 | break; |
| 3726 | |
| 3727 | case 3: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3728 | 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] | 3729 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | ha->operating_mode = P2P; |
| 3731 | ha->current_topology = ISP_CFG_F; |
| 3732 | strcpy(connect_type, "(F_Port)"); |
| 3733 | break; |
| 3734 | |
| 3735 | default: |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3736 | ql_dbg(ql_dbg_disc, vha, 0x200f, |
| 3737 | "HBA in unknown topology %x, using NL.\n", topo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | ha->current_topology = ISP_CFG_NL; |
| 3739 | strcpy(connect_type, "(Loop)"); |
| 3740 | break; |
| 3741 | } |
| 3742 | |
| 3743 | /* Save Host port and loop ID. */ |
| 3744 | /* byte order - Big Endian */ |
Quinn Tran | 482c9dc | 2017-03-15 09:48:54 -0700 | [diff] [blame] | 3745 | id.b.domain = domain; |
| 3746 | id.b.area = area; |
| 3747 | id.b.al_pa = al_pa; |
| 3748 | id.b.rsvd_1 = 0; |
| 3749 | qlt_update_host_map(vha, id); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3750 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3751 | if (!vha->flags.init_done) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3752 | ql_log(ql_log_info, vha, 0x2010, |
| 3753 | "Topology - %s, Host Loop address 0x%x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3754 | connect_type, vha->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3756 | return(rval); |
| 3757 | } |
| 3758 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3759 | inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3760 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, |
| 3761 | char *def) |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3762 | { |
| 3763 | char *st, *en; |
| 3764 | uint16_t index; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3765 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ab67114 | 2009-08-25 11:36:17 -0700 | [diff] [blame] | 3766 | int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 3767 | !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3768 | |
| 3769 | if (memcmp(model, BINZERO, len) != 0) { |
| 3770 | strncpy(ha->model_number, model, len); |
| 3771 | st = en = ha->model_number; |
| 3772 | en += len - 1; |
| 3773 | while (en > st) { |
| 3774 | if (*en != 0x20 && *en != 0x00) |
| 3775 | break; |
| 3776 | *en-- = '\0'; |
| 3777 | } |
| 3778 | |
| 3779 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 3780 | if (use_tbl && |
| 3781 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3782 | index < QLA_MODEL_NAMES) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3783 | strncpy(ha->model_desc, |
| 3784 | qla2x00_model_name[index * 2 + 1], |
| 3785 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3786 | } else { |
| 3787 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 3788 | if (use_tbl && |
| 3789 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3790 | index < QLA_MODEL_NAMES) { |
| 3791 | strcpy(ha->model_number, |
| 3792 | qla2x00_model_name[index * 2]); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3793 | strncpy(ha->model_desc, |
| 3794 | qla2x00_model_name[index * 2 + 1], |
| 3795 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3796 | } else { |
| 3797 | strcpy(ha->model_number, def); |
| 3798 | } |
| 3799 | } |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3800 | if (IS_FWI2_CAPABLE(ha)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3801 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 3802 | sizeof(ha->model_desc)); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3803 | } |
| 3804 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3805 | /* On sparc systems, obtain port and node WWN from firmware |
| 3806 | * properties. |
| 3807 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3808 | 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] | 3809 | { |
| 3810 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3811 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3812 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 3813 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 3814 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3815 | int len; |
| 3816 | |
| 3817 | val = of_get_property(dp, "port-wwn", &len); |
| 3818 | if (val && len >= WWN_SIZE) |
| 3819 | memcpy(nv->port_name, val, WWN_SIZE); |
| 3820 | |
| 3821 | val = of_get_property(dp, "node-wwn", &len); |
| 3822 | if (val && len >= WWN_SIZE) |
| 3823 | memcpy(nv->node_name, val, WWN_SIZE); |
| 3824 | #endif |
| 3825 | } |
| 3826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3827 | /* |
| 3828 | * NVRAM configuration for ISP 2xxx |
| 3829 | * |
| 3830 | * Input: |
| 3831 | * ha = adapter block pointer. |
| 3832 | * |
| 3833 | * Output: |
| 3834 | * initialization control block in response_ring |
| 3835 | * host adapters parameters in host adapter block |
| 3836 | * |
| 3837 | * Returns: |
| 3838 | * 0 = success. |
| 3839 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3840 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3841 | qla2x00_nvram_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3842 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3843 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3844 | uint8_t chksum = 0; |
| 3845 | uint16_t cnt; |
| 3846 | uint8_t *dptr1, *dptr2; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3847 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3848 | init_cb_t *icb = ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 3849 | nvram_t *nv = ha->nvram; |
| 3850 | uint8_t *ptr = ha->nvram; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 3851 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3852 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3853 | rval = QLA_SUCCESS; |
| 3854 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | /* Determine NVRAM starting address. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3856 | ha->nvram_size = sizeof(nvram_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3857 | ha->nvram_base = 0; |
| 3858 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 3859 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 3860 | ha->nvram_base = 0x80; |
| 3861 | |
| 3862 | /* Get NVRAM data and calculate checksum. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3863 | 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] | 3864 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
| 3865 | chksum += *ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3867 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f, |
| 3868 | "Contents of NVRAM.\n"); |
| 3869 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110, |
| 3870 | (uint8_t *)nv, ha->nvram_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3871 | |
| 3872 | /* Bad NVRAM data, set defaults parameters. */ |
| 3873 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 3874 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 3875 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3876 | ql_log(ql_log_warn, vha, 0x0064, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 3877 | "Inconsistent NVRAM " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3878 | "detected: checksum=0x%x id=%c version=0x%x.\n", |
| 3879 | chksum, nv->id[0], nv->nvram_version); |
| 3880 | ql_log(ql_log_warn, vha, 0x0065, |
| 3881 | "Falling back to " |
| 3882 | "functioning (yet invalid -- WWPN) defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3883 | |
| 3884 | /* |
| 3885 | * Set default initialization control block. |
| 3886 | */ |
| 3887 | memset(nv, 0, ha->nvram_size); |
| 3888 | nv->parameter_block_version = ICB_VERSION; |
| 3889 | |
| 3890 | if (IS_QLA23XX(ha)) { |
| 3891 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 3892 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 3893 | nv->add_firmware_options[0] = BIT_5; |
| 3894 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3895 | nv->frame_payload_size = 2048; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3896 | nv->special_options[1] = BIT_7; |
| 3897 | } else if (IS_QLA2200(ha)) { |
| 3898 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 3899 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 3900 | nv->add_firmware_options[0] = BIT_5; |
| 3901 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3902 | nv->frame_payload_size = 1024; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3903 | } else if (IS_QLA2100(ha)) { |
| 3904 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 3905 | nv->firmware_options[1] = BIT_5; |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3906 | nv->frame_payload_size = 1024; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3907 | } |
| 3908 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3909 | nv->max_iocb_allocation = cpu_to_le16(256); |
| 3910 | nv->execution_throttle = cpu_to_le16(16); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3911 | nv->retry_count = 8; |
| 3912 | nv->retry_delay = 1; |
| 3913 | |
| 3914 | nv->port_name[0] = 33; |
| 3915 | nv->port_name[3] = 224; |
| 3916 | nv->port_name[4] = 139; |
| 3917 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3918 | qla2xxx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3919 | |
| 3920 | nv->login_timeout = 4; |
| 3921 | |
| 3922 | /* |
| 3923 | * Set default host adapter parameters |
| 3924 | */ |
| 3925 | nv->host_p[1] = BIT_2; |
| 3926 | nv->reset_delay = 5; |
| 3927 | nv->port_down_retry_count = 8; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3928 | nv->max_luns_per_target = cpu_to_le16(8); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3929 | nv->link_down_timeout = 60; |
| 3930 | |
| 3931 | rval = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 | } |
| 3933 | |
| 3934 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 3935 | /* |
| 3936 | * The SN2 does not provide BIOS emulation which means you can't change |
| 3937 | * potentially bogus BIOS settings. Force the use of default settings |
| 3938 | * for link rate and frame size. Hope that the rest of the settings |
| 3939 | * are valid. |
| 3940 | */ |
| 3941 | if (ia64_platform_is("sn2")) { |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 3942 | nv->frame_payload_size = 2048; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | if (IS_QLA23XX(ha)) |
| 3944 | nv->special_options[1] = BIT_7; |
| 3945 | } |
| 3946 | #endif |
| 3947 | |
| 3948 | /* Reset Initialization control block */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3949 | memset(icb, 0, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3950 | |
| 3951 | /* |
| 3952 | * Setup driver NVRAM options. |
| 3953 | */ |
| 3954 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 3955 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 3956 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 3957 | nv->firmware_options[1] &= ~BIT_4; |
| 3958 | |
| 3959 | if (IS_QLA23XX(ha)) { |
| 3960 | nv->firmware_options[0] |= BIT_2; |
| 3961 | nv->firmware_options[0] &= ~BIT_3; |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 3962 | nv->special_options[0] &= ~BIT_6; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3963 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3964 | |
| 3965 | if (IS_QLA2300(ha)) { |
| 3966 | if (ha->fb_rev == FPM_2310) { |
| 3967 | strcpy(ha->model_number, "QLA2310"); |
| 3968 | } else { |
| 3969 | strcpy(ha->model_number, "QLA2300"); |
| 3970 | } |
| 3971 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3972 | qla2x00_set_model_info(vha, nv->model_number, |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3973 | sizeof(nv->model_number), "QLA23xx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3974 | } |
| 3975 | } else if (IS_QLA2200(ha)) { |
| 3976 | nv->firmware_options[0] |= BIT_2; |
| 3977 | /* |
| 3978 | * 'Point-to-point preferred, else loop' is not a safe |
| 3979 | * connection mode setting. |
| 3980 | */ |
| 3981 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 3982 | (BIT_5 | BIT_4)) { |
| 3983 | /* Force 'loop preferred, else point-to-point'. */ |
| 3984 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 3985 | nv->add_firmware_options[0] |= BIT_5; |
| 3986 | } |
| 3987 | strcpy(ha->model_number, "QLA22xx"); |
| 3988 | } else /*if (IS_QLA2100(ha))*/ { |
| 3989 | strcpy(ha->model_number, "QLA2100"); |
| 3990 | } |
| 3991 | |
| 3992 | /* |
| 3993 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 3994 | */ |
| 3995 | dptr1 = (uint8_t *)icb; |
| 3996 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 3997 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 3998 | while (cnt--) |
| 3999 | *dptr1++ = *dptr2++; |
| 4000 | |
| 4001 | /* Copy 2nd half. */ |
| 4002 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 4003 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 4004 | while (cnt--) |
| 4005 | *dptr1++ = *dptr2++; |
| 4006 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 4007 | /* Use alternate WWN? */ |
| 4008 | if (nv->host_p[1] & BIT_7) { |
| 4009 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 4010 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 4011 | } |
| 4012 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | /* Prepare nodename */ |
| 4014 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 4015 | /* |
| 4016 | * Firmware will apply the following mask if the nodename was |
| 4017 | * not provided. |
| 4018 | */ |
| 4019 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 4020 | icb->node_name[0] &= 0xF0; |
| 4021 | } |
| 4022 | |
| 4023 | /* |
| 4024 | * Set host adapter parameters. |
| 4025 | */ |
Saurav Kashyap | 3ce8866 | 2011-07-14 12:00:12 -0700 | [diff] [blame] | 4026 | |
| 4027 | /* |
| 4028 | * BIT_7 in the host-parameters section allows for modification to |
| 4029 | * internal driver logging. |
| 4030 | */ |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 4031 | if (nv->host_p[0] & BIT_7) |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 4032 | ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 4034 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 4035 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 4036 | ha->flags.disable_risc_code_load = 0; |
| 4037 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 4038 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 4039 | 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] | 4040 | 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] | 4041 | ha->flags.disable_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | |
| 4043 | ha->operating_mode = |
| 4044 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 4045 | |
| 4046 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 4047 | sizeof(ha->fw_seriallink_options)); |
| 4048 | |
| 4049 | /* save HBA serial number */ |
| 4050 | ha->serial0 = icb->port_name[5]; |
| 4051 | ha->serial1 = icb->port_name[6]; |
| 4052 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4053 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 4054 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4055 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4056 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4057 | |
| 4058 | ha->retry_count = nv->retry_count; |
| 4059 | |
| 4060 | /* Set minimum login_timeout to 4 seconds. */ |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 4061 | if (nv->login_timeout != ql2xlogintimeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4062 | nv->login_timeout = ql2xlogintimeout; |
| 4063 | if (nv->login_timeout < 4) |
| 4064 | nv->login_timeout = 4; |
| 4065 | ha->login_timeout = nv->login_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 4067 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 4068 | ha->r_a_tov = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4070 | ha->loop_reset_delay = nv->reset_delay; |
| 4071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | /* Link Down Timeout = 0: |
| 4073 | * |
| 4074 | * When Port Down timer expires we will start returning |
| 4075 | * I/O's to OS with "DID_NO_CONNECT". |
| 4076 | * |
| 4077 | * Link Down Timeout != 0: |
| 4078 | * |
| 4079 | * The driver waits for the link to come up after link down |
| 4080 | * before returning I/Os to OS with "DID_NO_CONNECT". |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4081 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4082 | if (nv->link_down_timeout == 0) { |
| 4083 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 4084 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | } else { |
| 4086 | ha->link_down_timeout = nv->link_down_timeout; |
| 4087 | ha->loop_down_abort_time = |
| 4088 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4089 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | /* |
| 4092 | * Need enough time to try and get the port back. |
| 4093 | */ |
| 4094 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 4095 | if (qlport_down_retry) |
| 4096 | ha->port_down_retry_count = qlport_down_retry; |
| 4097 | /* Set login_retry_count */ |
| 4098 | ha->login_retry_count = nv->retry_count; |
| 4099 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 4100 | ha->port_down_retry_count > 3) |
| 4101 | ha->login_retry_count = ha->port_down_retry_count; |
| 4102 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 4103 | ha->login_retry_count = ha->port_down_retry_count; |
| 4104 | if (ql2xloginretrycount) |
| 4105 | ha->login_retry_count = ql2xloginretrycount; |
| 4106 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4107 | icb->lun_enables = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4108 | icb->command_resource_count = 0; |
| 4109 | icb->immediate_notify_resource_count = 0; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 4110 | icb->timeout = cpu_to_le16(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4111 | |
| 4112 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 4113 | /* Enable RIO */ |
| 4114 | icb->firmware_options[0] &= ~BIT_3; |
| 4115 | icb->add_firmware_options[0] &= |
| 4116 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 4117 | icb->add_firmware_options[0] |= BIT_2; |
| 4118 | icb->response_accumulation_timer = 3; |
| 4119 | icb->interrupt_delay_timer = 5; |
| 4120 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4121 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | } else { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4123 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4124 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4125 | ha->zio_mode = icb->add_firmware_options[0] & |
| 4126 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 4127 | ha->zio_timer = icb->interrupt_delay_timer ? |
| 4128 | icb->interrupt_delay_timer: 2; |
| 4129 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | icb->add_firmware_options[0] &= |
| 4131 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4132 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4133 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 4134 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 4135 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4136 | ql_log(ql_log_info, vha, 0x0068, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4137 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 4138 | ha->zio_mode, ha->zio_timer * 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4140 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
| 4141 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4142 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4143 | } |
| 4144 | } |
| 4145 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4146 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4147 | ql_log(ql_log_warn, vha, 0x0069, |
| 4148 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4149 | } |
| 4150 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4151 | } |
| 4152 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4153 | static void |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4154 | qla2x00_rport_del(void *data) |
| 4155 | { |
| 4156 | fc_port_t *fcport = data; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4157 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4158 | unsigned long flags; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4159 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4160 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 4161 | rport = fcport->drport ? fcport->drport: fcport->rport; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4162 | fcport->drport = NULL; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4163 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4164 | if (rport) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4165 | ql_dbg(ql_dbg_disc, fcport->vha, 0x210b, |
| 4166 | "%s %8phN. rport %p roles %x\n", |
| 4167 | __func__, fcport->port_name, rport, |
| 4168 | rport->roles); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4169 | |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4170 | fc_remote_port_delete(rport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4171 | } |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4172 | } |
| 4173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | /** |
| 4175 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
| 4176 | * @ha: HA context |
| 4177 | * @flags: allocation flags |
| 4178 | * |
| 4179 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 4180 | */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 4181 | fc_port_t * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4182 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | { |
| 4184 | fc_port_t *fcport; |
| 4185 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 4186 | fcport = kzalloc(sizeof(fc_port_t), flags); |
| 4187 | if (!fcport) |
| 4188 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | |
| 4190 | /* Setup fcport template structure. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4191 | fcport->vha = vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4192 | fcport->port_type = FCT_UNKNOWN; |
| 4193 | fcport->loop_id = FC_NO_LOOP_ID; |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 4194 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 4195 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4196 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4197 | fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev, |
| 4198 | sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma, |
Quinn Tran | 6cb3216 | 2017-02-13 12:18:29 -0800 | [diff] [blame] | 4199 | flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4200 | fcport->disc_state = DSC_DELETED; |
| 4201 | fcport->fw_login_state = DSC_LS_PORT_UNAVAIL; |
| 4202 | fcport->deleted = QLA_SESS_DELETED; |
| 4203 | fcport->login_retry = vha->hw->login_retry_count; |
| 4204 | fcport->login_retry = 5; |
| 4205 | fcport->logout_on_delete = 1; |
| 4206 | |
| 4207 | if (!fcport->ct_desc.ct_sns) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4208 | ql_log(ql_log_warn, vha, 0xd049, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4209 | "Failed to allocate ct_sns request.\n"); |
| 4210 | kfree(fcport); |
| 4211 | fcport = NULL; |
| 4212 | } |
| 4213 | INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn); |
| 4214 | INIT_LIST_HEAD(&fcport->gnl_entry); |
| 4215 | INIT_LIST_HEAD(&fcport->list); |
| 4216 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 4217 | return fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 | } |
| 4219 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4220 | void |
| 4221 | qla2x00_free_fcport(fc_port_t *fcport) |
| 4222 | { |
| 4223 | if (fcport->ct_desc.ct_sns) { |
| 4224 | dma_free_coherent(&fcport->vha->hw->pdev->dev, |
| 4225 | sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns, |
| 4226 | fcport->ct_desc.ct_sns_dma); |
| 4227 | |
| 4228 | fcport->ct_desc.ct_sns = NULL; |
| 4229 | } |
| 4230 | kfree(fcport); |
| 4231 | } |
| 4232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | /* |
| 4234 | * qla2x00_configure_loop |
| 4235 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 4236 | * |
| 4237 | * Input: |
| 4238 | * ha = adapter block pointer. |
| 4239 | * |
| 4240 | * Returns: |
| 4241 | * 0 = success. |
| 4242 | * 1 = error. |
| 4243 | * 2 = database was full and device was not configured. |
| 4244 | */ |
| 4245 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4246 | qla2x00_configure_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | { |
| 4248 | int rval; |
| 4249 | unsigned long flags, save_flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4250 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4251 | rval = QLA_SUCCESS; |
| 4252 | |
| 4253 | /* Get Initiator ID */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4254 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { |
| 4255 | rval = qla2x00_configure_hba(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4257 | ql_dbg(ql_dbg_disc, vha, 0x2013, |
| 4258 | "Unable to configure HBA.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | return (rval); |
| 4260 | } |
| 4261 | } |
| 4262 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4263 | save_flags = flags = vha->dpc_flags; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4264 | ql_dbg(ql_dbg_disc, vha, 0x2014, |
| 4265 | "Configure loop -- dpc flags = 0x%lx.\n", flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4266 | |
| 4267 | /* |
| 4268 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 4269 | * both at the same time. |
| 4270 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4271 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 4272 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4273 | |
Michael Hernandez | 3064ff3 | 2009-12-15 21:29:44 -0800 | [diff] [blame] | 4274 | qla2x00_get_data_rate(vha); |
| 4275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | /* Determine what we need to do */ |
| 4277 | if (ha->current_topology == ISP_CFG_FL && |
| 4278 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 4279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4280 | set_bit(RSCN_UPDATE, &flags); |
| 4281 | |
| 4282 | } else if (ha->current_topology == ISP_CFG_F && |
| 4283 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 4284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | set_bit(RSCN_UPDATE, &flags); |
| 4286 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 4287 | |
Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 4288 | } else if (ha->current_topology == ISP_CFG_N) { |
| 4289 | clear_bit(RSCN_UPDATE, &flags); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4290 | } else if (ha->current_topology == ISP_CFG_NL) { |
| 4291 | clear_bit(RSCN_UPDATE, &flags); |
| 4292 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4293 | } else if (!vha->flags.online || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4294 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4295 | set_bit(RSCN_UPDATE, &flags); |
| 4296 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 4297 | } |
| 4298 | |
| 4299 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4300 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
| 4301 | ql_dbg(ql_dbg_disc, vha, 0x2015, |
| 4302 | "Loop resync needed, failing.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | rval = QLA_FUNCTION_FAILED; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4304 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4305 | rval = qla2x00_configure_local_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4306 | } |
| 4307 | |
| 4308 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4309 | if (LOOP_TRANSITION(vha)) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4310 | ql_dbg(ql_dbg_disc, vha, 0x2099, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4311 | "Needs RSCN update and loop transition.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | rval = QLA_FUNCTION_FAILED; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4313 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4314 | else |
| 4315 | rval = qla2x00_configure_fabric(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | } |
| 4317 | |
| 4318 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4319 | if (atomic_read(&vha->loop_down_timer) || |
| 4320 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | rval = QLA_FUNCTION_FAILED; |
| 4322 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4323 | atomic_set(&vha->loop_state, LOOP_READY); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4324 | ql_dbg(ql_dbg_disc, vha, 0x2069, |
| 4325 | "LOOP READY.\n"); |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 4326 | ha->flags.fw_init_done = 1; |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 4327 | |
| 4328 | /* |
| 4329 | * Process any ATIO queue entries that came in |
| 4330 | * while we weren't online. |
| 4331 | */ |
Quinn Tran | ead0385 | 2017-01-19 22:28:01 -0800 | [diff] [blame] | 4332 | if (qla_tgt_mode_enabled(vha) || |
| 4333 | qla_dual_mode_enabled(vha)) { |
Dilip Kumar Uppugandla | 3bb67df | 2015-12-17 14:57:11 -0500 | [diff] [blame] | 4334 | if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) { |
| 4335 | spin_lock_irqsave(&ha->tgt.atio_lock, |
| 4336 | flags); |
| 4337 | qlt_24xx_process_atio_queue(vha, 0); |
| 4338 | spin_unlock_irqrestore( |
| 4339 | &ha->tgt.atio_lock, flags); |
| 4340 | } else { |
| 4341 | spin_lock_irqsave(&ha->hardware_lock, |
| 4342 | flags); |
| 4343 | qlt_24xx_process_atio_queue(vha, 1); |
| 4344 | spin_unlock_irqrestore( |
| 4345 | &ha->hardware_lock, flags); |
| 4346 | } |
| 4347 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | } |
| 4349 | } |
| 4350 | |
| 4351 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4352 | ql_dbg(ql_dbg_disc, vha, 0x206a, |
| 4353 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4354 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4355 | ql_dbg(ql_dbg_disc, vha, 0x206b, |
| 4356 | "%s: exiting normally.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4357 | } |
| 4358 | |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 4359 | /* Restore state if a resync event occurred during processing */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4360 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4361 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4362 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 4363 | if (test_bit(RSCN_UPDATE, &save_flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4364 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 4365 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4366 | } |
| 4367 | |
| 4368 | return (rval); |
| 4369 | } |
| 4370 | |
| 4371 | |
| 4372 | |
| 4373 | /* |
| 4374 | * qla2x00_configure_local_loop |
| 4375 | * Updates Fibre Channel Device Database with local loop devices. |
| 4376 | * |
| 4377 | * Input: |
| 4378 | * ha = adapter block pointer. |
| 4379 | * |
| 4380 | * Returns: |
| 4381 | * 0 = success. |
| 4382 | */ |
| 4383 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4384 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | { |
| 4386 | int rval, rval2; |
| 4387 | int found_devs; |
| 4388 | int found; |
| 4389 | fc_port_t *fcport, *new_fcport; |
| 4390 | |
| 4391 | uint16_t index; |
| 4392 | uint16_t entries; |
| 4393 | char *id_iter; |
| 4394 | uint16_t loop_id; |
| 4395 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4396 | struct qla_hw_data *ha = vha->hw; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4397 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4398 | |
| 4399 | found_devs = 0; |
| 4400 | new_fcport = NULL; |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4401 | entries = MAX_FIBRE_DEVICES_LOOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | /* Get list of logged in devices. */ |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4404 | memset(ha->gid_list, 0, qla2x00_gid_list_size(ha)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4405 | 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] | 4406 | &entries); |
| 4407 | if (rval != QLA_SUCCESS) |
| 4408 | goto cleanup_allocation; |
| 4409 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4410 | ql_dbg(ql_dbg_disc, vha, 0x2011, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4411 | "Entries in ID list (%d).\n", entries); |
| 4412 | ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075, |
| 4413 | (uint8_t *)ha->gid_list, |
| 4414 | entries * sizeof(struct gid_list_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | |
| 4416 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4417 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | if (new_fcport == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4419 | ql_log(ql_log_warn, vha, 0x2012, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4420 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 4422 | goto cleanup_allocation; |
| 4423 | } |
| 4424 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 4425 | |
| 4426 | /* |
| 4427 | * Mark local devices that were present with FCF_DEVICE_LOST for now. |
| 4428 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4429 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4430 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
| 4431 | fcport->port_type != FCT_BROADCAST && |
| 4432 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 4433 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4434 | ql_dbg(ql_dbg_disc, vha, 0x2096, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4435 | "Marking port lost loop_id=0x%04x.\n", |
| 4436 | fcport->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4437 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4438 | qla2x00_mark_device_lost(vha, fcport, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | } |
| 4440 | } |
| 4441 | |
| 4442 | /* Add devices to port list. */ |
| 4443 | id_iter = (char *)ha->gid_list; |
| 4444 | for (index = 0; index < entries; index++) { |
| 4445 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 4446 | area = ((struct gid_list_info *)id_iter)->area; |
| 4447 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4448 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4449 | loop_id = (uint16_t) |
| 4450 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4451 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4452 | loop_id = le16_to_cpu( |
| 4453 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4454 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4455 | |
| 4456 | /* Bypass reserved domain fields. */ |
| 4457 | if ((domain & 0xf0) == 0xf0) |
| 4458 | continue; |
| 4459 | |
| 4460 | /* Bypass if not same domain and area of adapter. */ |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 4461 | if (area && domain && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4462 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | continue; |
| 4464 | |
| 4465 | /* Bypass invalid local loop ID. */ |
| 4466 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 4467 | continue; |
| 4468 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4469 | memset(new_fcport->port_name, 0, WWN_SIZE); |
Arun Easi | 370d550 | 2012-08-22 14:21:10 -0400 | [diff] [blame] | 4470 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | /* Fill in member data. */ |
| 4472 | new_fcport->d_id.b.domain = domain; |
| 4473 | new_fcport->d_id.b.area = area; |
| 4474 | new_fcport->d_id.b.al_pa = al_pa; |
| 4475 | new_fcport->loop_id = loop_id; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4476 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4477 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | if (rval2 != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4479 | ql_dbg(ql_dbg_disc, vha, 0x2097, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4480 | "Failed to retrieve fcport information " |
| 4481 | "-- get_port_database=%x, loop_id=0x%04x.\n", |
| 4482 | rval2, new_fcport->loop_id); |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4483 | ql_dbg(ql_dbg_disc, vha, 0x2105, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4484 | "Scheduling resync.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4485 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4486 | continue; |
| 4487 | } |
| 4488 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4489 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | /* Check for matching device in port list. */ |
| 4491 | found = 0; |
| 4492 | fcport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4493 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 4495 | WWN_SIZE)) |
| 4496 | continue; |
| 4497 | |
Shyam Sundar | ddb9b12 | 2009-03-24 09:08:10 -0700 | [diff] [blame] | 4498 | fcport->flags &= ~FCF_FABRIC_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | fcport->loop_id = new_fcport->loop_id; |
| 4500 | fcport->port_type = new_fcport->port_type; |
| 4501 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 4502 | memcpy(fcport->node_name, new_fcport->node_name, |
| 4503 | WWN_SIZE); |
| 4504 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4505 | if (!fcport->login_succ) { |
| 4506 | vha->fcport_count++; |
| 4507 | fcport->login_succ = 1; |
| 4508 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 4509 | } |
| 4510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | found++; |
| 4512 | break; |
| 4513 | } |
| 4514 | |
| 4515 | if (!found) { |
| 4516 | /* New device, add to fcports list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4517 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4518 | |
| 4519 | /* Allocate a new replacement fcport. */ |
| 4520 | fcport = new_fcport; |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4521 | if (!fcport->login_succ) { |
| 4522 | vha->fcport_count++; |
| 4523 | fcport->login_succ = 1; |
| 4524 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 4525 | } |
| 4526 | |
| 4527 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4528 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4529 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4531 | if (new_fcport == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4532 | ql_log(ql_log_warn, vha, 0xd031, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4533 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4534 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 4535 | goto cleanup_allocation; |
| 4536 | } |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4537 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4538 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 4539 | } |
| 4540 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4541 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 4542 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4543 | /* Base iIDMA settings on HBA port speed. */ |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 4544 | fcport->fp_speed = ha->link_data_rate; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4545 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4546 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4547 | |
| 4548 | found_devs++; |
| 4549 | } |
| 4550 | |
| 4551 | cleanup_allocation: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 4552 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4553 | |
| 4554 | if (rval != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4555 | ql_dbg(ql_dbg_disc, vha, 0x2098, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4556 | "Configure local loop error exit: rval=%x.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | } |
| 4558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | return (rval); |
| 4560 | } |
| 4561 | |
| 4562 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4563 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4564 | { |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4565 | int rval; |
Quinn Tran | 93f2bd6 | 2014-09-25 05:16:53 -0400 | [diff] [blame] | 4566 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4567 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4568 | |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 4569 | if (!IS_IIDMA_CAPABLE(ha)) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4570 | return; |
| 4571 | |
Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 4572 | if (atomic_read(&fcport->state) != FCS_ONLINE) |
| 4573 | return; |
| 4574 | |
Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 4575 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
| 4576 | fcport->fp_speed > ha->link_data_rate) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4577 | return; |
| 4578 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4579 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 4580 | mb); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4581 | if (rval != QLA_SUCCESS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4582 | ql_dbg(ql_dbg_disc, vha, 0x2004, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 4583 | "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n", |
| 4584 | fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4585 | } else { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4586 | ql_dbg(ql_dbg_disc, vha, 0x2005, |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 4587 | "iIDMA adjusted to %s GB/s on %8phN.\n", |
Joe Carnuccio | d0297c9 | 2012-11-21 02:40:40 -0500 | [diff] [blame] | 4588 | qla2x00_get_link_speed_str(ha, fcport->fp_speed), |
Oleksandr Khoshaba | 7b833558 | 2013-08-27 01:37:27 -0400 | [diff] [blame] | 4589 | fcport->port_name); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4590 | } |
| 4591 | } |
| 4592 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4593 | /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/ |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4594 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4595 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4596 | { |
| 4597 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 4598 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4599 | unsigned long flags; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4600 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 4601 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
| 4602 | rport_ids.port_name = wwn_to_u64(fcport->port_name); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4603 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 4604 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 4605 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4606 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4607 | if (!rport) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4608 | ql_log(ql_log_warn, vha, 0x2006, |
| 4609 | "Unable to allocate fc remote port.\n"); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4610 | return; |
| 4611 | } |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 4612 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4613 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 4614 | *((fc_port_t **)rport->dd_data) = fcport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 4615 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 4616 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 4617 | rport->supported_classes = fcport->supported_classes; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4618 | |
| 4619 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4620 | if (fcport->port_type == FCT_INITIATOR) |
| 4621 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 4622 | if (fcport->port_type == FCT_TARGET) |
| 4623 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4624 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4625 | ql_dbg(ql_dbg_disc, vha, 0x20ee, |
| 4626 | "%s %8phN. rport %p is %s mode\n", |
| 4627 | __func__, fcport->port_name, rport, |
| 4628 | (fcport->port_type == FCT_TARGET) ? "tgt" : "ini"); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4629 | |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 4630 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 4631 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4632 | |
| 4633 | /* |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4634 | * qla2x00_update_fcport |
| 4635 | * Updates device on list. |
| 4636 | * |
| 4637 | * Input: |
| 4638 | * ha = adapter block pointer. |
| 4639 | * fcport = port structure pointer. |
| 4640 | * |
| 4641 | * Return: |
| 4642 | * 0 - Success |
| 4643 | * BIT_0 - error |
| 4644 | * |
| 4645 | * Context: |
| 4646 | * Kernel context. |
| 4647 | */ |
| 4648 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4649 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4650 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4651 | fcport->vha = vha; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4652 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4653 | if (IS_SW_RESV_ADDR(fcport->d_id)) |
| 4654 | return; |
| 4655 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4656 | ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n", |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4657 | __func__, fcport->port_name); |
| 4658 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4659 | if (IS_QLAFX00(vha->hw)) { |
| 4660 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4661 | goto reg_port; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 4662 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4663 | fcport->login_retry = 0; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 4664 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4665 | fcport->disc_state = DSC_LOGIN_COMPLETE; |
| 4666 | fcport->deleted = 0; |
| 4667 | fcport->logout_on_delete = 1; |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4668 | |
Duane Grigsby | e84067d | 2017-06-21 13:48:43 -0700 | [diff] [blame] | 4669 | if (fcport->fc4f_nvme) { |
| 4670 | qla_nvme_register_remote(vha, fcport); |
| 4671 | return; |
| 4672 | } |
| 4673 | |
Joe Carnuccio | 1f93da52 | 2012-11-21 02:40:38 -0500 | [diff] [blame] | 4674 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4675 | qla2x00_iidma_fcport(vha, fcport); |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 4676 | qla24xx_update_fcport_fcp_prio(vha, fcport); |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4677 | |
| 4678 | reg_port: |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4679 | switch (vha->host->active_mode) { |
| 4680 | case MODE_INITIATOR: |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4681 | qla2x00_reg_remote_port(vha, fcport); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4682 | break; |
| 4683 | case MODE_TARGET: |
| 4684 | if (!vha->vha_tgt.qla_tgt->tgt_stop && |
| 4685 | !vha->vha_tgt.qla_tgt->tgt_stopped) |
| 4686 | qlt_fc_port_added(vha, fcport); |
| 4687 | break; |
| 4688 | case MODE_DUAL: |
| 4689 | qla2x00_reg_remote_port(vha, fcport); |
| 4690 | if (!vha->vha_tgt.qla_tgt->tgt_stop && |
| 4691 | !vha->vha_tgt.qla_tgt->tgt_stopped) |
| 4692 | qlt_fc_port_added(vha, fcport); |
| 4693 | break; |
| 4694 | default: |
| 4695 | break; |
Alexei Potashnik | d20ed91 | 2015-07-14 16:00:47 -0400 | [diff] [blame] | 4696 | } |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 4697 | } |
| 4698 | |
| 4699 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | * qla2x00_configure_fabric |
| 4701 | * Setup SNS devices with loop ID's. |
| 4702 | * |
| 4703 | * Input: |
| 4704 | * ha = adapter block pointer. |
| 4705 | * |
| 4706 | * Returns: |
| 4707 | * 0 = success. |
| 4708 | * BIT_0 = error |
| 4709 | */ |
| 4710 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4711 | qla2x00_configure_fabric(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4712 | { |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 4713 | int rval; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4714 | fc_port_t *fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4715 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4716 | uint16_t loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4717 | LIST_HEAD(new_fcports); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4718 | struct qla_hw_data *ha = vha->hw; |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4719 | int discovery_gen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4720 | |
| 4721 | /* If FL port exists, then SNS is present */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 4722 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4723 | loop_id = NPH_F_PORT; |
| 4724 | else |
| 4725 | loop_id = SNS_FL_PORT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4726 | 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] | 4727 | if (rval != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4728 | ql_dbg(ql_dbg_disc, vha, 0x20a0, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4729 | "MBX_GET_PORT_NAME failed, No FL Port.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4730 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4731 | vha->device_flags &= ~SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4732 | return (QLA_SUCCESS); |
| 4733 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4734 | vha->device_flags |= SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4735 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 4736 | |
| 4737 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) { |
| 4738 | rval = qla2x00_send_change_request(vha, 0x3, 0); |
| 4739 | if (rval != QLA_SUCCESS) |
| 4740 | ql_log(ql_log_warn, vha, 0x121, |
| 4741 | "Failed to enable receiving of RSCN requests: 0x%x.\n", |
| 4742 | rval); |
| 4743 | } |
| 4744 | |
| 4745 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4746 | do { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4747 | qla2x00_mgmt_svr_login(vha); |
| 4748 | |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 4749 | /* FDMI support. */ |
| 4750 | if (ql2xfdmienable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4751 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) |
| 4752 | qla2x00_fdmi_register(vha); |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 4753 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4754 | /* Ensure we are logged into the SNS. */ |
Joe Carnuccio | a14c771 | 2017-08-23 15:05:12 -0700 | [diff] [blame^] | 4755 | loop_id = NPH_SNS_LID(ha); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4756 | rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, |
| 4757 | 0xfc, mb, BIT_1|BIT_0); |
Joe Carnuccio | a14c771 | 2017-08-23 15:05:12 -0700 | [diff] [blame^] | 4758 | if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
| 4759 | ql_dbg(ql_dbg_disc, vha, 0x20a1, |
| 4760 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n", |
| 4761 | 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] | 4762 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Joe Carnuccio | e452ceb | 2013-02-08 01:57:56 -0500 | [diff] [blame] | 4763 | return rval; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 4764 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4765 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { |
| 4766 | if (qla2x00_rft_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4767 | /* EMPTY */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4768 | ql_dbg(ql_dbg_disc, vha, 0x20a2, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4769 | "Register FC-4 TYPE failed.\n"); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 4770 | if (test_bit(LOOP_RESYNC_NEEDED, |
| 4771 | &vha->dpc_flags)) |
| 4772 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | } |
Duane Grigsby | d3bae93 | 2017-06-21 13:48:44 -0700 | [diff] [blame] | 4774 | if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4775 | /* EMPTY */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4776 | ql_dbg(ql_dbg_disc, vha, 0x209a, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4777 | "Register FC-4 Features failed.\n"); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 4778 | if (test_bit(LOOP_RESYNC_NEEDED, |
| 4779 | &vha->dpc_flags)) |
| 4780 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4781 | } |
Duane Grigsby | d3bae93 | 2017-06-21 13:48:44 -0700 | [diff] [blame] | 4782 | if (vha->flags.nvme_enabled) { |
| 4783 | if (qla2x00_rff_id(vha, FC_TYPE_NVME)) { |
| 4784 | ql_dbg(ql_dbg_disc, vha, 0x2049, |
| 4785 | "Register NVME FC Type Features failed.\n"); |
| 4786 | } |
| 4787 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4788 | if (qla2x00_rnn_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4789 | /* EMPTY */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4790 | ql_dbg(ql_dbg_disc, vha, 0x2104, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4791 | "Register Node Name failed.\n"); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 4792 | if (test_bit(LOOP_RESYNC_NEEDED, |
| 4793 | &vha->dpc_flags)) |
| 4794 | break; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4795 | } else if (qla2x00_rsnn_nn(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | /* EMPTY */ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4797 | ql_dbg(ql_dbg_disc, vha, 0x209b, |
Colin Ian King | 0bf0efa | 2017-06-30 14:47:41 +0100 | [diff] [blame] | 4798 | "Register Symbolic Node Name failed.\n"); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 4799 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 4800 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4801 | } |
| 4802 | } |
| 4803 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 4804 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 4805 | fcport->scan_state = QLA_FCPORT_SCAN; |
| 4806 | } |
| 4807 | |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 4808 | /* Mark the time right before querying FW for connected ports. |
| 4809 | * This process is long, asynchronous and by the time it's done, |
| 4810 | * collected information might not be accurate anymore. E.g. |
| 4811 | * disconnected port might have re-connected and a brand new |
| 4812 | * session has been created. In this case session's generation |
| 4813 | * will be newer than discovery_gen. */ |
| 4814 | qlt_do_generation_tick(vha, &discovery_gen); |
| 4815 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4816 | rval = qla2x00_find_all_fabric_devs(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4817 | if (rval != QLA_SUCCESS) |
| 4818 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4819 | } while (0); |
| 4820 | |
Duane Grigsby | e84067d | 2017-06-21 13:48:43 -0700 | [diff] [blame] | 4821 | if (!vha->nvme_local_port && vha->flags.nvme_enabled) |
| 4822 | qla_nvme_register_hba(vha); |
| 4823 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4824 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4825 | ql_dbg(ql_dbg_disc, vha, 0x2068, |
| 4826 | "Configure fabric error exit rval=%d.\n", rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4827 | |
| 4828 | return (rval); |
| 4829 | } |
| 4830 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4831 | /* |
| 4832 | * qla2x00_find_all_fabric_devs |
| 4833 | * |
| 4834 | * Input: |
| 4835 | * ha = adapter block pointer. |
| 4836 | * dev = database device entry pointer. |
| 4837 | * |
| 4838 | * Returns: |
| 4839 | * 0 = success. |
| 4840 | * |
| 4841 | * Context: |
| 4842 | * Kernel context. |
| 4843 | */ |
| 4844 | static int |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4845 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4846 | { |
| 4847 | int rval; |
| 4848 | uint16_t loop_id; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4849 | fc_port_t *fcport, *new_fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | int found; |
| 4851 | |
| 4852 | sw_info_t *swl; |
| 4853 | int swl_idx; |
| 4854 | int first_dev, last_dev; |
Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 4855 | port_id_t wrap = {}, nxt_d_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4856 | struct qla_hw_data *ha = vha->hw; |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 4857 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4858 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | |
| 4860 | rval = QLA_SUCCESS; |
| 4861 | |
| 4862 | /* Try GID_PT to get device list, else GAN. */ |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 4863 | if (!ha->swl) |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4864 | ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t), |
Andrew Vasquez | 7a67735 | 2012-02-09 11:15:56 -0800 | [diff] [blame] | 4865 | GFP_KERNEL); |
| 4866 | swl = ha->swl; |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 4867 | if (!swl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | /*EMPTY*/ |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4869 | ql_dbg(ql_dbg_disc, vha, 0x209c, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4870 | "GID_PT allocations failed, fallback on GA_NXT.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | } else { |
Chad Dupuis | 642ef98 | 2012-02-09 11:15:57 -0800 | [diff] [blame] | 4872 | memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4873 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4874 | swl = NULL; |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 4875 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 4876 | return rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4877 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4878 | swl = NULL; |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 4879 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 4880 | return rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4881 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4882 | swl = NULL; |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 4883 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 4884 | return rval; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 4885 | } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) { |
| 4886 | swl = NULL; |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 4887 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 4888 | return rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4889 | } |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 4890 | |
| 4891 | /* If other queries succeeded probe for FC-4 type */ |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 4892 | if (swl) { |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 4893 | qla2x00_gff_id(vha, swl); |
Quinn Tran | b98ae0d | 2017-06-02 09:12:00 -0700 | [diff] [blame] | 4894 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 4895 | return rval; |
| 4896 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4897 | } |
| 4898 | swl_idx = 0; |
| 4899 | |
| 4900 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4901 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4902 | if (new_fcport == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4903 | ql_log(ql_log_warn, vha, 0x209d, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4904 | "Failed to allocate memory for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | return (QLA_MEMORY_ALLOC_FAILED); |
| 4906 | } |
| 4907 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4908 | /* Set start port ID scan at adapter ID. */ |
| 4909 | first_dev = 1; |
| 4910 | last_dev = 0; |
| 4911 | |
| 4912 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4913 | loop_id = ha->min_external_loopid; |
| 4914 | for (; loop_id <= ha->max_loop_id; loop_id++) { |
| 4915 | if (qla2x00_is_reserved_id(vha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | continue; |
| 4917 | |
Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 4918 | if (ha->current_topology == ISP_CFG_FL && |
| 4919 | (atomic_read(&vha->loop_down_timer) || |
| 4920 | LOOP_TRANSITION(vha))) { |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 4921 | atomic_set(&vha->loop_down_timer, 0); |
| 4922 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4923 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4924 | break; |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 4925 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | |
| 4927 | if (swl != NULL) { |
| 4928 | if (last_dev) { |
| 4929 | wrap.b24 = new_fcport->d_id.b24; |
| 4930 | } else { |
| 4931 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 4932 | memcpy(new_fcport->node_name, |
| 4933 | swl[swl_idx].node_name, WWN_SIZE); |
| 4934 | memcpy(new_fcport->port_name, |
| 4935 | swl[swl_idx].port_name, WWN_SIZE); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 4936 | memcpy(new_fcport->fabric_port_name, |
| 4937 | swl[swl_idx].fabric_port_name, WWN_SIZE); |
| 4938 | new_fcport->fp_speed = swl[swl_idx].fp_speed; |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 4939 | new_fcport->fc4_type = swl[swl_idx].fc4_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4940 | |
Duane Grigsby | a5d42f4 | 2017-06-21 13:48:41 -0700 | [diff] [blame] | 4941 | new_fcport->nvme_flag = 0; |
| 4942 | if (vha->flags.nvme_enabled && |
| 4943 | swl[swl_idx].fc4f_nvme) { |
| 4944 | new_fcport->fc4f_nvme = |
| 4945 | swl[swl_idx].fc4f_nvme; |
| 4946 | ql_log(ql_log_info, vha, 0x2131, |
| 4947 | "FOUND: NVME port %8phC as FC Type 28h\n", |
| 4948 | new_fcport->port_name); |
| 4949 | } |
| 4950 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4951 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 4952 | last_dev = 1; |
| 4953 | } |
| 4954 | swl_idx++; |
| 4955 | } |
| 4956 | } else { |
| 4957 | /* Send GA_NXT to the switch */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4958 | rval = qla2x00_ga_nxt(vha, new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4959 | if (rval != QLA_SUCCESS) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4960 | ql_log(ql_log_warn, vha, 0x209e, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4961 | "SNS scan failed -- assuming " |
| 4962 | "zero-entry result.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4963 | rval = QLA_SUCCESS; |
| 4964 | break; |
| 4965 | } |
| 4966 | } |
| 4967 | |
| 4968 | /* If wrap on switch device list, exit. */ |
| 4969 | if (first_dev) { |
| 4970 | wrap.b24 = new_fcport->d_id.b24; |
| 4971 | first_dev = 0; |
| 4972 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 4973 | ql_dbg(ql_dbg_disc, vha, 0x209f, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 4974 | "Device wrap (%02x%02x%02x).\n", |
| 4975 | new_fcport->d_id.b.domain, |
| 4976 | new_fcport->d_id.b.area, |
| 4977 | new_fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4978 | break; |
| 4979 | } |
| 4980 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4981 | /* Bypass if same physical adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4982 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4983 | continue; |
| 4984 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4985 | /* Bypass virtual ports of the same host. */ |
Chad Dupuis | bb4cf5b | 2013-02-08 01:58:01 -0500 | [diff] [blame] | 4986 | if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24)) |
| 4987 | continue; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4988 | |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 4989 | /* Bypass if same domain and area of adapter. */ |
| 4990 | if (((new_fcport->d_id.b24 & 0xffff00) == |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4991 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 4992 | ISP_CFG_FL) |
| 4993 | continue; |
| 4994 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4995 | /* Bypass reserved domain fields. */ |
| 4996 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 4997 | continue; |
| 4998 | |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 4999 | /* Bypass ports whose FCP-4 type is not FCP_SCSI */ |
Chad Dupuis | 4da26e1 | 2010-10-15 11:27:40 -0700 | [diff] [blame] | 5000 | if (ql2xgffidenable && |
| 5001 | (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && |
| 5002 | new_fcport->fc4_type != FC4_TYPE_UNKNOWN)) |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 5003 | continue; |
| 5004 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5005 | spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags); |
| 5006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5007 | /* Locate matching device in database. */ |
| 5008 | found = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5009 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5010 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 5011 | WWN_SIZE)) |
| 5012 | continue; |
| 5013 | |
Joe Carnuccio | 827210b | 2013-02-08 01:57:57 -0500 | [diff] [blame] | 5014 | fcport->scan_state = QLA_FCPORT_FOUND; |
Arun Easi | b3b02e6 | 2012-02-09 11:15:39 -0800 | [diff] [blame] | 5015 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5016 | found++; |
| 5017 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 5018 | /* Update port state. */ |
| 5019 | memcpy(fcport->fabric_port_name, |
| 5020 | new_fcport->fabric_port_name, WWN_SIZE); |
| 5021 | fcport->fp_speed = new_fcport->fp_speed; |
| 5022 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5023 | /* |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 5024 | * If address the same and state FCS_ONLINE |
| 5025 | * (or in target mode), nothing changed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5026 | */ |
| 5027 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 5028 | (atomic_read(&fcport->state) == FCS_ONLINE || |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5029 | (vha->host->active_mode == MODE_TARGET))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5030 | break; |
| 5031 | } |
| 5032 | |
| 5033 | /* |
| 5034 | * If device was not a fabric device before. |
| 5035 | */ |
| 5036 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 5037 | fcport->d_id.b24 = new_fcport->d_id.b24; |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5038 | qla2x00_clear_loop_id(fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5039 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 5040 | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5041 | break; |
| 5042 | } |
| 5043 | |
| 5044 | /* |
| 5045 | * Port ID changed or device was marked to be updated; |
| 5046 | * Log it out if still logged in and mark it for |
| 5047 | * relogin later. |
| 5048 | */ |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5049 | if (qla_tgt_mode_enabled(base_vha)) { |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 5050 | ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080, |
| 5051 | "port changed FC ID, %8phC" |
| 5052 | " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n", |
| 5053 | fcport->port_name, |
| 5054 | fcport->d_id.b.domain, |
| 5055 | fcport->d_id.b.area, |
| 5056 | fcport->d_id.b.al_pa, |
| 5057 | fcport->loop_id, |
| 5058 | new_fcport->d_id.b.domain, |
| 5059 | new_fcport->d_id.b.area, |
| 5060 | new_fcport->d_id.b.al_pa); |
| 5061 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 5062 | break; |
| 5063 | } |
| 5064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5065 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 5066 | fcport->flags |= FCF_LOGIN_NEEDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5067 | break; |
| 5068 | } |
| 5069 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5070 | if (found) { |
| 5071 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5072 | continue; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5073 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5074 | /* If device was not in our fcports list, then add it. */ |
Roland Dreier | b2032fd | 2015-07-14 16:00:42 -0400 | [diff] [blame] | 5075 | new_fcport->scan_state = QLA_FCPORT_FOUND; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5076 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
| 5077 | |
| 5078 | spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags); |
| 5079 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5080 | |
| 5081 | /* Allocate a new replacement fcport. */ |
| 5082 | nxt_d_id.b24 = new_fcport->d_id.b24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5083 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5084 | if (new_fcport == NULL) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5085 | ql_log(ql_log_warn, vha, 0xd032, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5086 | "Memory allocation failed for fcport.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5087 | return (QLA_MEMORY_ALLOC_FAILED); |
| 5088 | } |
| 5089 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 5090 | new_fcport->d_id.b24 = nxt_d_id.b24; |
| 5091 | } |
| 5092 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5093 | qla2x00_free_fcport(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5094 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5095 | /* |
| 5096 | * Logout all previous fabric dev marked lost, except FCP2 devices. |
| 5097 | */ |
| 5098 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 5099 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
| 5100 | break; |
| 5101 | |
| 5102 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 5103 | (fcport->flags & FCF_LOGIN_NEEDED) == 0) |
| 5104 | continue; |
| 5105 | |
| 5106 | if (fcport->scan_state == QLA_FCPORT_SCAN) { |
| 5107 | if ((qla_dual_mode_enabled(vha) || |
| 5108 | qla_ini_mode_enabled(vha)) && |
| 5109 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 5110 | qla2x00_mark_device_lost(vha, fcport, |
| 5111 | ql2xplogiabsentdevice, 0); |
| 5112 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 5113 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
| 5114 | fcport->port_type != FCT_INITIATOR && |
| 5115 | fcport->port_type != FCT_BROADCAST) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 5116 | ql_dbg(ql_dbg_disc, vha, 0x20f0, |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5117 | "%s %d %8phC post del sess\n", |
| 5118 | __func__, __LINE__, |
| 5119 | fcport->port_name); |
| 5120 | |
| 5121 | qlt_schedule_sess_for_deletion_lock |
| 5122 | (fcport); |
| 5123 | continue; |
| 5124 | } |
| 5125 | } |
| 5126 | } |
| 5127 | |
| 5128 | if (fcport->scan_state == QLA_FCPORT_FOUND) |
| 5129 | qla24xx_fcport_handle_login(vha, fcport); |
| 5130 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5131 | return (rval); |
| 5132 | } |
| 5133 | |
| 5134 | /* |
| 5135 | * qla2x00_find_new_loop_id |
| 5136 | * Scan through our port list and find a new usable loop ID. |
| 5137 | * |
| 5138 | * Input: |
| 5139 | * ha: adapter state pointer. |
| 5140 | * dev: port structure pointer. |
| 5141 | * |
| 5142 | * Returns: |
| 5143 | * qla2x00 local function return status code. |
| 5144 | * |
| 5145 | * Context: |
| 5146 | * Kernel context. |
| 5147 | */ |
Joe Carnuccio | 03bcfb5 | 2011-03-30 11:46:27 -0700 | [diff] [blame] | 5148 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5149 | 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] | 5150 | { |
| 5151 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5152 | struct qla_hw_data *ha = vha->hw; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5153 | unsigned long flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5154 | |
| 5155 | rval = QLA_SUCCESS; |
| 5156 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5157 | spin_lock_irqsave(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5158 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5159 | dev->loop_id = find_first_zero_bit(ha->loop_id_map, |
| 5160 | LOOPID_MAP_SIZE); |
| 5161 | if (dev->loop_id >= LOOPID_MAP_SIZE || |
| 5162 | qla2x00_is_reserved_id(vha, dev->loop_id)) { |
| 5163 | dev->loop_id = FC_NO_LOOP_ID; |
| 5164 | rval = QLA_FUNCTION_FAILED; |
| 5165 | } else |
| 5166 | set_bit(dev->loop_id, ha->loop_id_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5167 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5168 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5169 | |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5170 | if (rval == QLA_SUCCESS) |
| 5171 | ql_dbg(ql_dbg_disc, dev->vha, 0x2086, |
| 5172 | "Assigning new loopid=%x, portid=%x.\n", |
| 5173 | dev->loop_id, dev->d_id.b24); |
| 5174 | else |
| 5175 | ql_log(ql_log_warn, dev->vha, 0x2087, |
| 5176 | "No loop_id's available, portid=%x.\n", |
| 5177 | dev->d_id.b24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5178 | |
| 5179 | return (rval); |
| 5180 | } |
| 5181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5182 | |
| 5183 | /* |
| 5184 | * qla2x00_fabric_login |
| 5185 | * Issue fabric login command. |
| 5186 | * |
| 5187 | * Input: |
| 5188 | * ha = adapter block pointer. |
| 5189 | * device = pointer to FC device type structure. |
| 5190 | * |
| 5191 | * Returns: |
| 5192 | * 0 - Login successfully |
| 5193 | * 1 - Login failed |
| 5194 | * 2 - Initiator device |
| 5195 | * 3 - Fatal error |
| 5196 | */ |
| 5197 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5198 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5199 | uint16_t *next_loopid) |
| 5200 | { |
| 5201 | int rval; |
| 5202 | int retry; |
| 5203 | uint16_t tmp_loopid; |
| 5204 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5205 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5206 | |
| 5207 | retry = 0; |
| 5208 | tmp_loopid = 0; |
| 5209 | |
| 5210 | for (;;) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5211 | ql_dbg(ql_dbg_disc, vha, 0x2000, |
| 5212 | "Trying Fabric Login w/loop id 0x%04x for port " |
| 5213 | "%02x%02x%02x.\n", |
| 5214 | fcport->loop_id, fcport->d_id.b.domain, |
| 5215 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5216 | |
| 5217 | /* Login fcport on switch. */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5218 | rval = ha->isp_ops->fabric_login(vha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5219 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 5220 | fcport->d_id.b.al_pa, mb, BIT_0); |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 5221 | if (rval != QLA_SUCCESS) { |
| 5222 | return rval; |
| 5223 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5224 | if (mb[0] == MBS_PORT_ID_USED) { |
| 5225 | /* |
| 5226 | * Device has another loop ID. The firmware team |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 5227 | * recommends the driver perform an implicit login with |
| 5228 | * the specified ID again. The ID we just used is save |
| 5229 | * here so we return with an ID that can be tried by |
| 5230 | * the next login. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5231 | */ |
| 5232 | retry++; |
| 5233 | tmp_loopid = fcport->loop_id; |
| 5234 | fcport->loop_id = mb[1]; |
| 5235 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5236 | ql_dbg(ql_dbg_disc, vha, 0x2001, |
| 5237 | "Fabric Login: port in use - next loop " |
| 5238 | "id=0x%04x, port id= %02x%02x%02x.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5239 | fcport->loop_id, fcport->d_id.b.domain, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5240 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5241 | |
| 5242 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 5243 | /* |
| 5244 | * Login succeeded. |
| 5245 | */ |
| 5246 | if (retry) { |
| 5247 | /* A retry occurred before. */ |
| 5248 | *next_loopid = tmp_loopid; |
| 5249 | } else { |
| 5250 | /* |
| 5251 | * No retry occurred before. Just increment the |
| 5252 | * ID value for next login. |
| 5253 | */ |
| 5254 | *next_loopid = (fcport->loop_id + 1); |
| 5255 | } |
| 5256 | |
| 5257 | if (mb[1] & BIT_0) { |
| 5258 | fcport->port_type = FCT_INITIATOR; |
| 5259 | } else { |
| 5260 | fcport->port_type = FCT_TARGET; |
| 5261 | if (mb[1] & BIT_1) { |
Santosh Vernekar | 8474f3a | 2009-08-25 11:36:16 -0700 | [diff] [blame] | 5262 | fcport->flags |= FCF_FCP2_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5263 | } |
| 5264 | } |
| 5265 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 5266 | if (mb[10] & BIT_0) |
| 5267 | fcport->supported_classes |= FC_COS_CLASS2; |
| 5268 | if (mb[10] & BIT_1) |
| 5269 | fcport->supported_classes |= FC_COS_CLASS3; |
| 5270 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 5271 | if (IS_FWI2_CAPABLE(ha)) { |
| 5272 | if (mb[10] & BIT_7) |
| 5273 | fcport->flags |= |
| 5274 | FCF_CONF_COMP_SUPPORTED; |
| 5275 | } |
| 5276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5277 | rval = QLA_SUCCESS; |
| 5278 | break; |
| 5279 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 5280 | /* |
| 5281 | * Loop ID already used, try next loop ID. |
| 5282 | */ |
| 5283 | fcport->loop_id++; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5284 | rval = qla2x00_find_new_loop_id(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5285 | if (rval != QLA_SUCCESS) { |
| 5286 | /* Ran out of loop IDs to use */ |
| 5287 | break; |
| 5288 | } |
| 5289 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 5290 | /* |
| 5291 | * Firmware possibly timed out during login. If NO |
| 5292 | * retries are left to do then the device is declared |
| 5293 | * dead. |
| 5294 | */ |
| 5295 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5296 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 5297 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 5298 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5299 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5300 | |
| 5301 | rval = 1; |
| 5302 | break; |
| 5303 | } else { |
| 5304 | /* |
| 5305 | * unrecoverable / not handled error |
| 5306 | */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5307 | ql_dbg(ql_dbg_disc, vha, 0x2002, |
| 5308 | "Failed=%x port_id=%02x%02x%02x loop_id=%x " |
| 5309 | "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain, |
| 5310 | fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 5311 | fcport->loop_id, jiffies); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5312 | |
| 5313 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5314 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 5315 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 5316 | fcport->d_id.b.al_pa); |
Chad Dupuis | 5f16b33 | 2012-08-22 14:21:00 -0400 | [diff] [blame] | 5317 | qla2x00_clear_loop_id(fcport); |
Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 5318 | fcport->login_retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5319 | |
| 5320 | rval = 3; |
| 5321 | break; |
| 5322 | } |
| 5323 | } |
| 5324 | |
| 5325 | return (rval); |
| 5326 | } |
| 5327 | |
| 5328 | /* |
| 5329 | * qla2x00_local_device_login |
| 5330 | * Issue local device login command. |
| 5331 | * |
| 5332 | * Input: |
| 5333 | * ha = adapter block pointer. |
| 5334 | * loop_id = loop id of device to login to. |
| 5335 | * |
| 5336 | * Returns (Where's the #define!!!!): |
| 5337 | * 0 - Login successfully |
| 5338 | * 1 - Login failed |
| 5339 | * 3 - Fatal error |
| 5340 | */ |
| 5341 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5342 | 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] | 5343 | { |
| 5344 | int rval; |
| 5345 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 5346 | |
| 5347 | memset(mb, 0, sizeof(mb)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5348 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5349 | if (rval == QLA_SUCCESS) { |
| 5350 | /* Interrogate mailbox registers for any errors */ |
| 5351 | if (mb[0] == MBS_COMMAND_ERROR) |
| 5352 | rval = 1; |
| 5353 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 5354 | /* device not in PCB table */ |
| 5355 | rval = 3; |
| 5356 | } |
| 5357 | |
| 5358 | return (rval); |
| 5359 | } |
| 5360 | |
| 5361 | /* |
| 5362 | * qla2x00_loop_resync |
| 5363 | * Resync with fibre channel devices. |
| 5364 | * |
| 5365 | * Input: |
| 5366 | * ha = adapter block pointer. |
| 5367 | * |
| 5368 | * Returns: |
| 5369 | * 0 = success |
| 5370 | */ |
| 5371 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5372 | qla2x00_loop_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5373 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5374 | int rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5375 | uint32_t wait_time; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5376 | struct req_que *req; |
| 5377 | struct rsp_que *rsp; |
| 5378 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 5379 | req = vha->req; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5380 | rsp = req->rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5381 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5382 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5383 | if (vha->flags.online) { |
| 5384 | if (!(rval = qla2x00_fw_ready(vha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5385 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 5386 | wait_time = 256; |
| 5387 | do { |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5388 | if (!IS_QLAFX00(vha->hw)) { |
| 5389 | /* |
| 5390 | * Issue a marker after FW becomes |
| 5391 | * ready. |
| 5392 | */ |
| 5393 | qla2x00_marker(vha, req, rsp, 0, 0, |
| 5394 | MK_SYNC_ALL); |
| 5395 | vha->marker_needed = 0; |
| 5396 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5397 | |
| 5398 | /* Remap devices on Loop. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5399 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5400 | |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 5401 | if (IS_QLAFX00(vha->hw)) |
| 5402 | qlafx00_configure_devices(vha); |
| 5403 | else |
| 5404 | qla2x00_configure_loop(vha); |
| 5405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5406 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5407 | } while (!atomic_read(&vha->loop_down_timer) && |
| 5408 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 5409 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 5410 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5411 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5412 | } |
| 5413 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5414 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5415 | return (QLA_FUNCTION_FAILED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5416 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5417 | if (rval) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5418 | ql_dbg(ql_dbg_disc, vha, 0x206c, |
| 5419 | "%s *** FAILED ***.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5420 | |
| 5421 | return (rval); |
| 5422 | } |
| 5423 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5424 | /* |
| 5425 | * qla2x00_perform_loop_resync |
| 5426 | * Description: This function will set the appropriate flags and call |
| 5427 | * qla2x00_loop_resync. If successful loop will be resynced |
| 5428 | * Arguments : scsi_qla_host_t pointer |
| 5429 | * returm : Success or Failure |
| 5430 | */ |
| 5431 | |
| 5432 | int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) |
| 5433 | { |
| 5434 | int32_t rval = 0; |
| 5435 | |
| 5436 | if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { |
| 5437 | /*Configure the flags so that resync happens properly*/ |
| 5438 | atomic_set(&ha->loop_down_timer, 0); |
| 5439 | if (!(ha->device_flags & DFLG_NO_CABLE)) { |
| 5440 | atomic_set(&ha->loop_state, LOOP_UP); |
| 5441 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 5442 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); |
| 5443 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 5444 | |
| 5445 | rval = qla2x00_loop_resync(ha); |
| 5446 | } else |
| 5447 | atomic_set(&ha->loop_state, LOOP_DEAD); |
| 5448 | |
| 5449 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); |
| 5450 | } |
| 5451 | |
| 5452 | return rval; |
| 5453 | } |
| 5454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5455 | void |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 5456 | qla2x00_update_fcports(scsi_qla_host_t *base_vha) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5457 | { |
| 5458 | fc_port_t *fcport; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5459 | struct scsi_qla_host *vha; |
| 5460 | struct qla_hw_data *ha = base_vha->hw; |
| 5461 | unsigned long flags; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5462 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5463 | spin_lock_irqsave(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5464 | /* Go with deferred removal of rport references. */ |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5465 | list_for_each_entry(vha, &base_vha->hw->vp_list, list) { |
| 5466 | atomic_inc(&vha->vref_count); |
| 5467 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Dan Carpenter | 8ae598d | 2010-12-21 16:00:15 -0800 | [diff] [blame] | 5468 | if (fcport->drport && |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5469 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) { |
| 5470 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 5471 | qla2x00_rport_del(fcport); |
Alexei Potashnik | df67327 | 2015-07-14 16:00:46 -0400 | [diff] [blame] | 5472 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5473 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5474 | } |
| 5475 | } |
| 5476 | atomic_dec(&vha->vref_count); |
Joe Carnuccio | c4a9b53 | 2017-03-15 09:48:43 -0700 | [diff] [blame] | 5477 | wake_up(&vha->vref_waitq); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5478 | } |
| 5479 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 5480 | } |
| 5481 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5482 | /* Assumes idc_lock always held on entry */ |
| 5483 | void |
| 5484 | qla83xx_reset_ownership(scsi_qla_host_t *vha) |
| 5485 | { |
| 5486 | struct qla_hw_data *ha = vha->hw; |
| 5487 | uint32_t drv_presence, drv_presence_mask; |
| 5488 | uint32_t dev_part_info1, dev_part_info2, class_type; |
| 5489 | uint32_t class_type_mask = 0x3; |
| 5490 | uint16_t fcoe_other_function = 0xffff, i; |
| 5491 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5492 | if (IS_QLA8044(ha)) { |
| 5493 | drv_presence = qla8044_rd_direct(vha, |
| 5494 | QLA8044_CRB_DRV_ACTIVE_INDEX); |
| 5495 | dev_part_info1 = qla8044_rd_direct(vha, |
| 5496 | QLA8044_CRB_DEV_PART_INFO_INDEX); |
| 5497 | dev_part_info2 = qla8044_rd_direct(vha, |
| 5498 | QLA8044_CRB_DEV_PART_INFO2); |
| 5499 | } else { |
| 5500 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 5501 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1); |
| 5502 | qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2); |
| 5503 | } |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5504 | for (i = 0; i < 8; i++) { |
| 5505 | class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask); |
| 5506 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 5507 | (i != ha->portnum)) { |
| 5508 | fcoe_other_function = i; |
| 5509 | break; |
| 5510 | } |
| 5511 | } |
| 5512 | if (fcoe_other_function == 0xffff) { |
| 5513 | for (i = 0; i < 8; i++) { |
| 5514 | class_type = ((dev_part_info2 >> (i * 4)) & |
| 5515 | class_type_mask); |
| 5516 | if ((class_type == QLA83XX_CLASS_TYPE_FCOE) && |
| 5517 | ((i + 8) != ha->portnum)) { |
| 5518 | fcoe_other_function = i + 8; |
| 5519 | break; |
| 5520 | } |
| 5521 | } |
| 5522 | } |
| 5523 | /* |
| 5524 | * Prepare drv-presence mask based on fcoe functions present. |
| 5525 | * However consider only valid physical fcoe function numbers (0-15). |
| 5526 | */ |
| 5527 | drv_presence_mask = ~((1 << (ha->portnum)) | |
| 5528 | ((fcoe_other_function == 0xffff) ? |
| 5529 | 0 : (1 << (fcoe_other_function)))); |
| 5530 | |
| 5531 | /* We are the reset owner iff: |
| 5532 | * - No other protocol drivers present. |
| 5533 | * - This is the lowest among fcoe functions. */ |
| 5534 | if (!(drv_presence & drv_presence_mask) && |
| 5535 | (ha->portnum < fcoe_other_function)) { |
| 5536 | ql_dbg(ql_dbg_p3p, vha, 0xb07f, |
| 5537 | "This host is Reset owner.\n"); |
| 5538 | ha->flags.nic_core_reset_owner = 1; |
| 5539 | } |
| 5540 | } |
| 5541 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5542 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5543 | __qla83xx_set_drv_ack(scsi_qla_host_t *vha) |
| 5544 | { |
| 5545 | int rval = QLA_SUCCESS; |
| 5546 | struct qla_hw_data *ha = vha->hw; |
| 5547 | uint32_t drv_ack; |
| 5548 | |
| 5549 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 5550 | if (rval == QLA_SUCCESS) { |
| 5551 | drv_ack |= (1 << ha->portnum); |
| 5552 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 5553 | } |
| 5554 | |
| 5555 | return rval; |
| 5556 | } |
| 5557 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5558 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5559 | __qla83xx_clear_drv_ack(scsi_qla_host_t *vha) |
| 5560 | { |
| 5561 | int rval = QLA_SUCCESS; |
| 5562 | struct qla_hw_data *ha = vha->hw; |
| 5563 | uint32_t drv_ack; |
| 5564 | |
| 5565 | rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack); |
| 5566 | if (rval == QLA_SUCCESS) { |
| 5567 | drv_ack &= ~(1 << ha->portnum); |
| 5568 | rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack); |
| 5569 | } |
| 5570 | |
| 5571 | return rval; |
| 5572 | } |
| 5573 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5574 | static const char * |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5575 | qla83xx_dev_state_to_string(uint32_t dev_state) |
| 5576 | { |
| 5577 | switch (dev_state) { |
| 5578 | case QLA8XXX_DEV_COLD: |
| 5579 | return "COLD/RE-INIT"; |
| 5580 | case QLA8XXX_DEV_INITIALIZING: |
| 5581 | return "INITIALIZING"; |
| 5582 | case QLA8XXX_DEV_READY: |
| 5583 | return "READY"; |
| 5584 | case QLA8XXX_DEV_NEED_RESET: |
| 5585 | return "NEED RESET"; |
| 5586 | case QLA8XXX_DEV_NEED_QUIESCENT: |
| 5587 | return "NEED QUIESCENT"; |
| 5588 | case QLA8XXX_DEV_FAILED: |
| 5589 | return "FAILED"; |
| 5590 | case QLA8XXX_DEV_QUIESCENT: |
| 5591 | return "QUIESCENT"; |
| 5592 | default: |
| 5593 | return "Unknown"; |
| 5594 | } |
| 5595 | } |
| 5596 | |
| 5597 | /* Assumes idc-lock always held on entry */ |
| 5598 | void |
| 5599 | qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type) |
| 5600 | { |
| 5601 | struct qla_hw_data *ha = vha->hw; |
| 5602 | uint32_t idc_audit_reg = 0, duration_secs = 0; |
| 5603 | |
| 5604 | switch (audit_type) { |
| 5605 | case IDC_AUDIT_TIMESTAMP: |
| 5606 | ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000); |
| 5607 | idc_audit_reg = (ha->portnum) | |
| 5608 | (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8); |
| 5609 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 5610 | break; |
| 5611 | |
| 5612 | case IDC_AUDIT_COMPLETION: |
| 5613 | duration_secs = ((jiffies_to_msecs(jiffies) - |
| 5614 | jiffies_to_msecs(ha->idc_audit_ts)) / 1000); |
| 5615 | idc_audit_reg = (ha->portnum) | |
| 5616 | (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8); |
| 5617 | qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg); |
| 5618 | break; |
| 5619 | |
| 5620 | default: |
| 5621 | ql_log(ql_log_warn, vha, 0xb078, |
| 5622 | "Invalid audit type specified.\n"); |
| 5623 | break; |
| 5624 | } |
| 5625 | } |
| 5626 | |
| 5627 | /* Assumes idc_lock always held on entry */ |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5628 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5629 | qla83xx_initiating_reset(scsi_qla_host_t *vha) |
| 5630 | { |
| 5631 | struct qla_hw_data *ha = vha->hw; |
| 5632 | uint32_t idc_control, dev_state; |
| 5633 | |
| 5634 | __qla83xx_get_idc_control(vha, &idc_control); |
| 5635 | if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) { |
| 5636 | ql_log(ql_log_info, vha, 0xb080, |
| 5637 | "NIC Core reset has been disabled. idc-control=0x%x\n", |
| 5638 | idc_control); |
| 5639 | return QLA_FUNCTION_FAILED; |
| 5640 | } |
| 5641 | |
| 5642 | /* Set NEED-RESET iff in READY state and we are the reset-owner */ |
| 5643 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 5644 | if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) { |
| 5645 | qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, |
| 5646 | QLA8XXX_DEV_NEED_RESET); |
| 5647 | ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n"); |
| 5648 | qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP); |
| 5649 | } else { |
| 5650 | const char *state = qla83xx_dev_state_to_string(dev_state); |
| 5651 | ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state); |
| 5652 | |
| 5653 | /* SV: XXX: Is timeout required here? */ |
| 5654 | /* Wait for IDC state change READY -> NEED_RESET */ |
| 5655 | while (dev_state == QLA8XXX_DEV_READY) { |
| 5656 | qla83xx_idc_unlock(vha, 0); |
| 5657 | msleep(200); |
| 5658 | qla83xx_idc_lock(vha, 0); |
| 5659 | qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state); |
| 5660 | } |
| 5661 | } |
| 5662 | |
| 5663 | /* Send IDC ack by writing to drv-ack register */ |
| 5664 | __qla83xx_set_drv_ack(vha); |
| 5665 | |
| 5666 | return QLA_SUCCESS; |
| 5667 | } |
| 5668 | |
| 5669 | int |
| 5670 | __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control) |
| 5671 | { |
| 5672 | return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 5673 | } |
| 5674 | |
| 5675 | int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5676 | __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control) |
| 5677 | { |
| 5678 | return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control); |
| 5679 | } |
| 5680 | |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 5681 | static int |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 5682 | qla83xx_check_driver_presence(scsi_qla_host_t *vha) |
| 5683 | { |
| 5684 | uint32_t drv_presence = 0; |
| 5685 | struct qla_hw_data *ha = vha->hw; |
| 5686 | |
| 5687 | qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence); |
| 5688 | if (drv_presence & (1 << ha->portnum)) |
| 5689 | return QLA_SUCCESS; |
| 5690 | else |
| 5691 | return QLA_TEST_FAILED; |
| 5692 | } |
| 5693 | |
| 5694 | int |
| 5695 | qla83xx_nic_core_reset(scsi_qla_host_t *vha) |
| 5696 | { |
| 5697 | int rval = QLA_SUCCESS; |
| 5698 | struct qla_hw_data *ha = vha->hw; |
| 5699 | |
| 5700 | ql_dbg(ql_dbg_p3p, vha, 0xb058, |
| 5701 | "Entered %s().\n", __func__); |
| 5702 | |
| 5703 | if (vha->device_flags & DFLG_DEV_FAILED) { |
| 5704 | ql_log(ql_log_warn, vha, 0xb059, |
| 5705 | "Device in unrecoverable FAILED state.\n"); |
| 5706 | return QLA_FUNCTION_FAILED; |
| 5707 | } |
| 5708 | |
| 5709 | qla83xx_idc_lock(vha, 0); |
| 5710 | |
| 5711 | if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) { |
| 5712 | ql_log(ql_log_warn, vha, 0xb05a, |
| 5713 | "Function=0x%x has been removed from IDC participation.\n", |
| 5714 | ha->portnum); |
| 5715 | rval = QLA_FUNCTION_FAILED; |
| 5716 | goto exit; |
| 5717 | } |
| 5718 | |
| 5719 | qla83xx_reset_ownership(vha); |
| 5720 | |
| 5721 | rval = qla83xx_initiating_reset(vha); |
| 5722 | |
| 5723 | /* |
| 5724 | * Perform reset if we are the reset-owner, |
| 5725 | * else wait till IDC state changes to READY/FAILED. |
| 5726 | */ |
| 5727 | if (rval == QLA_SUCCESS) { |
| 5728 | rval = qla83xx_idc_state_handler(vha); |
| 5729 | |
| 5730 | if (rval == QLA_SUCCESS) |
| 5731 | ha->flags.nic_core_hung = 0; |
| 5732 | __qla83xx_clear_drv_ack(vha); |
| 5733 | } |
| 5734 | |
| 5735 | exit: |
| 5736 | qla83xx_idc_unlock(vha, 0); |
| 5737 | |
| 5738 | ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__); |
| 5739 | |
| 5740 | return rval; |
| 5741 | } |
| 5742 | |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 5743 | int |
| 5744 | qla2xxx_mctp_dump(scsi_qla_host_t *vha) |
| 5745 | { |
| 5746 | struct qla_hw_data *ha = vha->hw; |
| 5747 | int rval = QLA_FUNCTION_FAILED; |
| 5748 | |
| 5749 | if (!IS_MCTP_CAPABLE(ha)) { |
| 5750 | /* This message can be removed from the final version */ |
| 5751 | ql_log(ql_log_info, vha, 0x506d, |
| 5752 | "This board is not MCTP capable\n"); |
| 5753 | return rval; |
| 5754 | } |
| 5755 | |
| 5756 | if (!ha->mctp_dump) { |
| 5757 | ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev, |
| 5758 | MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL); |
| 5759 | |
| 5760 | if (!ha->mctp_dump) { |
| 5761 | ql_log(ql_log_warn, vha, 0x506e, |
| 5762 | "Failed to allocate memory for mctp dump\n"); |
| 5763 | return rval; |
| 5764 | } |
| 5765 | } |
| 5766 | |
| 5767 | #define MCTP_DUMP_STR_ADDR 0x00000000 |
| 5768 | rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma, |
| 5769 | MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4); |
| 5770 | if (rval != QLA_SUCCESS) { |
| 5771 | ql_log(ql_log_warn, vha, 0x506f, |
| 5772 | "Failed to capture mctp dump\n"); |
| 5773 | } else { |
| 5774 | ql_log(ql_log_info, vha, 0x5070, |
| 5775 | "Mctp dump capture for host (%ld/%p).\n", |
| 5776 | vha->host_no, ha->mctp_dump); |
| 5777 | ha->mctp_dumped = 1; |
| 5778 | } |
| 5779 | |
Saurav Kashyap | 409ee0f | 2012-08-22 14:21:29 -0400 | [diff] [blame] | 5780 | if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) { |
Saurav Kashyap | 8117877 | 2012-08-22 14:21:04 -0400 | [diff] [blame] | 5781 | ha->flags.nic_core_reset_hdlr_active = 1; |
| 5782 | rval = qla83xx_restart_nic_firmware(vha); |
| 5783 | if (rval) |
| 5784 | /* NIC Core reset failed. */ |
| 5785 | ql_log(ql_log_warn, vha, 0x5071, |
| 5786 | "Failed to restart nic firmware\n"); |
| 5787 | else |
| 5788 | ql_dbg(ql_dbg_p3p, vha, 0xb084, |
| 5789 | "Restarted NIC firmware successfully.\n"); |
| 5790 | ha->flags.nic_core_reset_hdlr_active = 0; |
| 5791 | } |
| 5792 | |
| 5793 | return rval; |
| 5794 | |
| 5795 | } |
| 5796 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5797 | /* |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5798 | * qla2x00_quiesce_io |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5799 | * Description: This function will block the new I/Os |
| 5800 | * Its not aborting any I/Os as context |
| 5801 | * is not destroyed during quiescence |
| 5802 | * Arguments: scsi_qla_host_t |
| 5803 | * return : void |
| 5804 | */ |
| 5805 | void |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5806 | qla2x00_quiesce_io(scsi_qla_host_t *vha) |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5807 | { |
| 5808 | struct qla_hw_data *ha = vha->hw; |
| 5809 | struct scsi_qla_host *vp; |
| 5810 | |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5811 | ql_dbg(ql_dbg_dpc, vha, 0x401d, |
| 5812 | "Quiescing I/O - ha=%p.\n", ha); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5813 | |
| 5814 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 5815 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 5816 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 5817 | qla2x00_mark_all_devices_lost(vha, 0); |
| 5818 | list_for_each_entry(vp, &ha->vp_list, list) |
Chad Dupuis | 8fcd6b8 | 2012-08-22 14:21:06 -0400 | [diff] [blame] | 5819 | qla2x00_mark_all_devices_lost(vp, 0); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5820 | } else { |
| 5821 | if (!atomic_read(&vha->loop_down_timer)) |
| 5822 | atomic_set(&vha->loop_down_timer, |
| 5823 | LOOP_DOWN_TIME); |
| 5824 | } |
| 5825 | /* Wait for pending cmds to complete */ |
| 5826 | qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST); |
| 5827 | } |
| 5828 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5829 | void |
| 5830 | qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) |
| 5831 | { |
| 5832 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5833 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5834 | unsigned long flags; |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 5835 | fc_port_t *fcport; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 5836 | u16 i; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5837 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 5838 | /* For ISP82XX, driver waits for completion of the commands. |
| 5839 | * online flag should be set. |
| 5840 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5841 | if (!(IS_P3P_TYPE(ha))) |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 5842 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5843 | ha->flags.chip_reset_done = 0; |
| 5844 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 5845 | vha->qla_stats.total_isp_aborts++; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5846 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5847 | ql_log(ql_log_info, vha, 0x00af, |
| 5848 | "Performing ISP error recovery - ha=%p.\n", ha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5849 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 5850 | /* For ISP82XX, reset_chip is just disabling interrupts. |
| 5851 | * Driver waits for the completion of the commands. |
| 5852 | * the interrupts need to be enabled. |
| 5853 | */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5854 | if (!(IS_P3P_TYPE(ha))) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5855 | ha->isp_ops->reset_chip(vha); |
| 5856 | |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 5857 | ha->flags.n2n_ae = 0; |
| 5858 | ha->flags.lip_ae = 0; |
| 5859 | ha->current_topology = 0; |
| 5860 | ha->flags.fw_started = 0; |
| 5861 | ha->flags.fw_init_done = 0; |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 5862 | ha->base_qpair->chip_reset++; |
| 5863 | for (i = 0; i < ha->max_qpairs; i++) { |
| 5864 | if (ha->queue_pair_map[i]) |
| 5865 | ha->queue_pair_map[i]->chip_reset = |
| 5866 | ha->base_qpair->chip_reset; |
| 5867 | } |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 5868 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5869 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 5870 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 5871 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 5872 | qla2x00_mark_all_devices_lost(vha, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5873 | |
| 5874 | spin_lock_irqsave(&ha->vport_slock, flags); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 5875 | list_for_each_entry(vp, &ha->vp_list, list) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5876 | atomic_inc(&vp->vref_count); |
| 5877 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5878 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5879 | qla2x00_mark_all_devices_lost(vp, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5880 | |
| 5881 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5882 | atomic_dec(&vp->vref_count); |
| 5883 | } |
| 5884 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5885 | } else { |
| 5886 | if (!atomic_read(&vha->loop_down_timer)) |
| 5887 | atomic_set(&vha->loop_down_timer, |
| 5888 | LOOP_DOWN_TIME); |
| 5889 | } |
| 5890 | |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 5891 | /* Clear all async request states across all VPs. */ |
| 5892 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 5893 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 5894 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5895 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 5896 | atomic_inc(&vp->vref_count); |
| 5897 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5898 | |
| 5899 | list_for_each_entry(fcport, &vp->vp_fcports, list) |
| 5900 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 5901 | |
| 5902 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5903 | atomic_dec(&vp->vref_count); |
| 5904 | } |
| 5905 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5906 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 5907 | if (!ha->flags.eeh_busy) { |
| 5908 | /* Make sure for ISP 82XX IO DMA is complete */ |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 5909 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 5910 | qla82xx_chip_reset_cleanup(vha); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5911 | ql_log(ql_log_info, vha, 0x00b4, |
| 5912 | "Done chip reset cleanup.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5913 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 5914 | /* Done waiting for pending commands. |
| 5915 | * Reset the online flag. |
| 5916 | */ |
| 5917 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5918 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5919 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 5920 | /* Requeue all commands in outstanding command list. */ |
| 5921 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); |
| 5922 | } |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 5923 | /* memory barrier */ |
| 5924 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5925 | } |
| 5926 | |
| 5927 | /* |
| 5928 | * qla2x00_abort_isp |
| 5929 | * Resets ISP and aborts all outstanding commands. |
| 5930 | * |
| 5931 | * Input: |
| 5932 | * ha = adapter block pointer. |
| 5933 | * |
| 5934 | * Returns: |
| 5935 | * 0 = success |
| 5936 | */ |
| 5937 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5938 | qla2x00_abort_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5939 | { |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 5940 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5941 | uint8_t status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5942 | struct qla_hw_data *ha = vha->hw; |
| 5943 | struct scsi_qla_host *vp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5944 | struct req_que *req = ha->req_q_map[0]; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5945 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5946 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5947 | if (vha->flags.online) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5948 | qla2x00_abort_isp_cleanup(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5949 | |
Santosh Vernekar | a6171297 | 2012-08-22 14:21:13 -0400 | [diff] [blame] | 5950 | if (IS_QLA8031(ha)) { |
| 5951 | ql_dbg(ql_dbg_p3p, vha, 0xb05c, |
| 5952 | "Clearing fcoe driver presence.\n"); |
| 5953 | if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS) |
| 5954 | ql_dbg(ql_dbg_p3p, vha, 0xb073, |
| 5955 | "Error while clearing DRV-Presence.\n"); |
| 5956 | } |
| 5957 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 5958 | if (unlikely(pci_channel_offline(ha->pdev) && |
| 5959 | ha->flags.pci_channel_io_perm_failure)) { |
| 5960 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5961 | status = 0; |
| 5962 | return status; |
| 5963 | } |
| 5964 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5965 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 5966 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5967 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5968 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5969 | if (!qla2x00_restart_isp(vha)) { |
| 5970 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5971 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5972 | if (!atomic_read(&vha->loop_down_timer)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5973 | /* |
| 5974 | * Issue marker command only when we are going |
| 5975 | * to start the I/O . |
| 5976 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5977 | vha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5978 | } |
| 5979 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5980 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5981 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 5982 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5983 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 5984 | ha->isp_abort_cnt = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5985 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 5986 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 5987 | if (IS_QLA81XX(ha) || IS_QLA8031(ha)) |
| 5988 | qla2x00_get_fw_version(vha); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 5989 | if (ha->fce) { |
| 5990 | ha->flags.fce_enabled = 1; |
| 5991 | memset(ha->fce, 0, |
| 5992 | fce_calc_size(ha->fce_bufs)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5993 | rval = qla2x00_enable_fce_trace(vha, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 5994 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 5995 | &ha->fce_bufs); |
| 5996 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 5997 | ql_log(ql_log_warn, vha, 0x8033, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 5998 | "Unable to reinitialize FCE " |
| 5999 | "(%d).\n", rval); |
| 6000 | ha->flags.fce_enabled = 0; |
| 6001 | } |
| 6002 | } |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 6003 | |
| 6004 | if (ha->eft) { |
| 6005 | memset(ha->eft, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6006 | rval = qla2x00_enable_eft_trace(vha, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 6007 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 6008 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6009 | ql_log(ql_log_warn, vha, 0x8034, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 6010 | "Unable to reinitialize EFT " |
| 6011 | "(%d).\n", rval); |
| 6012 | } |
| 6013 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6014 | } else { /* failed the ISP abort */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6015 | vha->flags.online = 1; |
| 6016 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6017 | if (ha->isp_abort_cnt == 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6018 | ql_log(ql_log_fatal, vha, 0x8035, |
| 6019 | "ISP error recover failed - " |
| 6020 | "board disabled.\n"); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 6021 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6022 | * The next call disables the board |
| 6023 | * completely. |
| 6024 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6025 | ha->isp_ops->reset_adapter(vha); |
| 6026 | vha->flags.online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6027 | clear_bit(ISP_ABORT_RETRY, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6028 | &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6029 | status = 0; |
| 6030 | } else { /* schedule another ISP abort */ |
| 6031 | ha->isp_abort_cnt--; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6032 | ql_dbg(ql_dbg_taskm, vha, 0x8020, |
| 6033 | "ISP abort - retry remaining %d.\n", |
| 6034 | ha->isp_abort_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6035 | status = 1; |
| 6036 | } |
| 6037 | } else { |
| 6038 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6039 | ql_dbg(ql_dbg_taskm, vha, 0x8021, |
| 6040 | "ISP error recovery - retrying (%d) " |
| 6041 | "more times.\n", ha->isp_abort_cnt); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6042 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6043 | status = 1; |
| 6044 | } |
| 6045 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 6046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6047 | } |
| 6048 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6049 | if (!status) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6050 | ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__); |
Quinn Tran | 1608cc4 | 2017-08-23 15:05:03 -0700 | [diff] [blame] | 6051 | qla2x00_configure_hba(vha); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6052 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6053 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 6054 | if (vp->vp_idx) { |
| 6055 | atomic_inc(&vp->vref_count); |
| 6056 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6057 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6058 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6059 | |
| 6060 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 6061 | atomic_dec(&vp->vref_count); |
| 6062 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6063 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 6064 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 6065 | |
Santosh Vernekar | 7d613ac | 2012-08-22 14:21:03 -0400 | [diff] [blame] | 6066 | if (IS_QLA8031(ha)) { |
| 6067 | ql_dbg(ql_dbg_p3p, vha, 0xb05d, |
| 6068 | "Setting back fcoe driver presence.\n"); |
| 6069 | if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS) |
| 6070 | ql_dbg(ql_dbg_p3p, vha, 0xb074, |
| 6071 | "Error while setting DRV-Presence.\n"); |
| 6072 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6073 | } else { |
Joe Perches | d8424f6 | 2011-11-18 09:03:06 -0800 | [diff] [blame] | 6074 | ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n", |
| 6075 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6076 | } |
| 6077 | |
| 6078 | return(status); |
| 6079 | } |
| 6080 | |
| 6081 | /* |
| 6082 | * qla2x00_restart_isp |
| 6083 | * restarts the ISP after a reset |
| 6084 | * |
| 6085 | * Input: |
| 6086 | * ha = adapter block pointer. |
| 6087 | * |
| 6088 | * Returns: |
| 6089 | * 0 = success |
| 6090 | */ |
| 6091 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6092 | qla2x00_restart_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6093 | { |
Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 6094 | int status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6095 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6096 | struct req_que *req = ha->req_q_map[0]; |
| 6097 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6098 | |
| 6099 | /* If firmware needs to be loaded */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6100 | if (qla2x00_isp_firmware(vha)) { |
| 6101 | vha->flags.online = 0; |
| 6102 | status = ha->isp_ops->chip_diag(vha); |
| 6103 | if (!status) |
| 6104 | status = qla2x00_setup_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6105 | } |
| 6106 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6107 | if (!status && !(status = qla2x00_init_rings(vha))) { |
| 6108 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 6109 | ha->flags.chip_reset_done = 1; |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 6110 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6111 | /* Initialize the queues in use */ |
| 6112 | qla25xx_init_queues(ha); |
| 6113 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6114 | status = qla2x00_fw_ready(vha); |
| 6115 | if (!status) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6116 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6117 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 6118 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6119 | } |
| 6120 | |
| 6121 | /* if no cable then assume it's good */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6122 | if ((vha->device_flags & DFLG_NO_CABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6123 | status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6124 | } |
| 6125 | return (status); |
| 6126 | } |
| 6127 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6128 | static int |
| 6129 | qla25xx_init_queues(struct qla_hw_data *ha) |
| 6130 | { |
| 6131 | struct rsp_que *rsp = NULL; |
| 6132 | struct req_que *req = NULL; |
| 6133 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
| 6134 | int ret = -1; |
| 6135 | int i; |
| 6136 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 6137 | for (i = 1; i < ha->max_rsp_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6138 | rsp = ha->rsp_q_map[i]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 6139 | if (rsp && test_bit(i, ha->rsp_qid_map)) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6140 | rsp->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 6141 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6142 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6143 | ql_dbg(ql_dbg_init, base_vha, 0x00ff, |
| 6144 | "%s Rsp que: %d init failed.\n", |
| 6145 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6146 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6147 | ql_dbg(ql_dbg_init, base_vha, 0x0100, |
| 6148 | "%s Rsp que: %d inited.\n", |
| 6149 | __func__, rsp->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6150 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 6151 | } |
| 6152 | for (i = 1; i < ha->max_req_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6153 | req = ha->req_q_map[i]; |
Quinn Tran | cb43285 | 2016-02-04 11:45:16 -0500 | [diff] [blame] | 6154 | if (req && test_bit(i, ha->req_qid_map)) { |
| 6155 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6156 | req->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 6157 | ret = qla25xx_init_req_que(base_vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6158 | if (ret != QLA_SUCCESS) |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6159 | ql_dbg(ql_dbg_init, base_vha, 0x0101, |
| 6160 | "%s Req que: %d init failed.\n", |
| 6161 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6162 | else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6163 | ql_dbg(ql_dbg_init, base_vha, 0x0102, |
| 6164 | "%s Req que: %d inited.\n", |
| 6165 | __func__, req->id); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6166 | } |
| 6167 | } |
| 6168 | return ret; |
| 6169 | } |
| 6170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6171 | /* |
| 6172 | * qla2x00_reset_adapter |
| 6173 | * Reset adapter. |
| 6174 | * |
| 6175 | * Input: |
| 6176 | * ha = adapter block pointer. |
| 6177 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 6178 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6179 | qla2x00_reset_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6180 | { |
| 6181 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6182 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 6183 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6184 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6185 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 6186 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6188 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6189 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 6190 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 6191 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 6192 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 6193 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 6194 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6195 | |
| 6196 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6197 | qla24xx_reset_adapter(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6198 | { |
| 6199 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6200 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6201 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 6202 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 6203 | if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 6204 | return; |
| 6205 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6206 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 6207 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6208 | |
| 6209 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 6210 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 6211 | RD_REG_DWORD(®->hccr); |
| 6212 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 6213 | RD_REG_DWORD(®->hccr); |
| 6214 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 09ff36d | 2009-01-22 09:45:30 -0800 | [diff] [blame] | 6215 | |
| 6216 | if (IS_NOPOLLING_TYPE(ha)) |
| 6217 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6218 | } |
| 6219 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6220 | /* On sparc systems, obtain port and node WWN from firmware |
| 6221 | * properties. |
| 6222 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6223 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, |
| 6224 | struct nvram_24xx *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6225 | { |
| 6226 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6227 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6228 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 6229 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 6230 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6231 | int len; |
| 6232 | |
| 6233 | val = of_get_property(dp, "port-wwn", &len); |
| 6234 | if (val && len >= WWN_SIZE) |
| 6235 | memcpy(nv->port_name, val, WWN_SIZE); |
| 6236 | |
| 6237 | val = of_get_property(dp, "node-wwn", &len); |
| 6238 | if (val && len >= WWN_SIZE) |
| 6239 | memcpy(nv->node_name, val, WWN_SIZE); |
| 6240 | #endif |
| 6241 | } |
| 6242 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6243 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6244 | qla24xx_nvram_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6245 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6246 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6247 | struct init_cb_24xx *icb; |
| 6248 | struct nvram_24xx *nv; |
| 6249 | uint32_t *dptr; |
| 6250 | uint8_t *dptr1, *dptr2; |
| 6251 | uint32_t chksum; |
| 6252 | uint16_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6253 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6254 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6255 | rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6256 | icb = (struct init_cb_24xx *)ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 6257 | nv = ha->nvram; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6258 | |
| 6259 | /* Determine NVRAM starting address. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6260 | if (ha->port_no == 0) { |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 6261 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; |
| 6262 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; |
| 6263 | } else { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6264 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 6265 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
| 6266 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6267 | |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 6268 | ha->nvram_size = sizeof(struct nvram_24xx); |
| 6269 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6270 | |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 6271 | /* Get VPD data into cache */ |
| 6272 | ha->vpd = ha->nvram + VPD_OFFSET; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6273 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 6274 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
| 6275 | |
| 6276 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6277 | dptr = (uint32_t *)nv; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6278 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6279 | ha->nvram_size); |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6280 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) |
| 6281 | chksum += le32_to_cpu(*dptr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6282 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6283 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a, |
| 6284 | "Contents of NVRAM\n"); |
| 6285 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d, |
| 6286 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6287 | |
| 6288 | /* Bad NVRAM data, set defaults parameters. */ |
| 6289 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 6290 | || nv->id[3] != ' ' || |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6291 | nv->nvram_version < cpu_to_le16(ICB_VERSION)) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6292 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6293 | ql_log(ql_log_warn, vha, 0x006b, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 6294 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6295 | "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version); |
| 6296 | ql_log(ql_log_warn, vha, 0x006c, |
| 6297 | "Falling back to functioning (yet invalid -- WWPN) " |
| 6298 | "defaults.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6299 | |
| 6300 | /* |
| 6301 | * Set default initialization control block. |
| 6302 | */ |
| 6303 | memset(nv, 0, ha->nvram_size); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6304 | nv->nvram_version = cpu_to_le16(ICB_VERSION); |
| 6305 | nv->version = cpu_to_le16(ICB_VERSION); |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 6306 | nv->frame_payload_size = 2048; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6307 | nv->execution_throttle = cpu_to_le16(0xFFFF); |
| 6308 | nv->exchange_count = cpu_to_le16(0); |
| 6309 | nv->hard_address = cpu_to_le16(124); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6310 | nv->port_name[0] = 0x21; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6311 | nv->port_name[1] = 0x00 + ha->port_no + 1; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6312 | nv->port_name[2] = 0x00; |
| 6313 | nv->port_name[3] = 0xe0; |
| 6314 | nv->port_name[4] = 0x8b; |
| 6315 | nv->port_name[5] = 0x1c; |
| 6316 | nv->port_name[6] = 0x55; |
| 6317 | nv->port_name[7] = 0x86; |
| 6318 | nv->node_name[0] = 0x20; |
| 6319 | nv->node_name[1] = 0x00; |
| 6320 | nv->node_name[2] = 0x00; |
| 6321 | nv->node_name[3] = 0xe0; |
| 6322 | nv->node_name[4] = 0x8b; |
| 6323 | nv->node_name[5] = 0x1c; |
| 6324 | nv->node_name[6] = 0x55; |
| 6325 | nv->node_name[7] = 0x86; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6326 | qla24xx_nvram_wwn_from_ofw(vha, nv); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6327 | nv->login_retry_count = cpu_to_le16(8); |
| 6328 | nv->interrupt_delay_timer = cpu_to_le16(0); |
| 6329 | nv->login_timeout = cpu_to_le16(0); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6330 | nv->firmware_options_1 = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6331 | cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 6332 | nv->firmware_options_2 = cpu_to_le32(2 << 4); |
| 6333 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 6334 | nv->firmware_options_3 = cpu_to_le32(2 << 13); |
| 6335 | nv->host_p = cpu_to_le32(BIT_11|BIT_10); |
| 6336 | nv->efi_parameters = cpu_to_le32(0); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6337 | nv->reset_delay = 5; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6338 | nv->max_luns_per_target = cpu_to_le16(128); |
| 6339 | nv->port_down_retry_count = cpu_to_le16(30); |
| 6340 | nv->link_down_timeout = cpu_to_le16(30); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6341 | |
| 6342 | rval = 1; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6343 | } |
| 6344 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 6345 | if (qla_tgt_mode_enabled(vha)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6346 | /* Don't enable full login after initial LIP */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6347 | nv->firmware_options_1 &= cpu_to_le32(~BIT_13); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6348 | /* Don't enable LIP full login for initiator */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6349 | nv->host_p &= cpu_to_le32(~BIT_10); |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6350 | } |
| 6351 | |
| 6352 | qlt_24xx_config_nvram_stage1(vha, nv); |
| 6353 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6354 | /* Reset Initialization control block */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6355 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6356 | |
| 6357 | /* Copy 1st segment. */ |
| 6358 | dptr1 = (uint8_t *)icb; |
| 6359 | dptr2 = (uint8_t *)&nv->version; |
| 6360 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 6361 | while (cnt--) |
| 6362 | *dptr1++ = *dptr2++; |
| 6363 | |
| 6364 | icb->login_retry_count = nv->login_retry_count; |
Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 6365 | icb->link_down_on_nos = nv->link_down_on_nos; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6366 | |
| 6367 | /* Copy 2nd segment. */ |
| 6368 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 6369 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 6370 | cnt = (uint8_t *)&icb->reserved_3 - |
| 6371 | (uint8_t *)&icb->interrupt_delay_timer; |
| 6372 | while (cnt--) |
| 6373 | *dptr1++ = *dptr2++; |
| 6374 | |
| 6375 | /* |
| 6376 | * Setup driver NVRAM options. |
| 6377 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6378 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 6379 | "QLA2462"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6380 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6381 | qlt_24xx_config_nvram_stage2(vha, icb); |
| 6382 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6383 | if (nv->host_p & cpu_to_le32(BIT_15)) { |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 6384 | /* Use alternate WWN? */ |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 6385 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 6386 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 6387 | } |
| 6388 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6389 | /* Prepare nodename */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6390 | if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6391 | /* |
| 6392 | * Firmware will apply the following mask if the nodename was |
| 6393 | * not provided. |
| 6394 | */ |
| 6395 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 6396 | icb->node_name[0] &= 0xF0; |
| 6397 | } |
| 6398 | |
| 6399 | /* Set host adapter parameters. */ |
| 6400 | ha->flags.disable_risc_code_load = 0; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 6401 | ha->flags.enable_lip_reset = 0; |
| 6402 | ha->flags.enable_lip_full_login = |
| 6403 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 6404 | ha->flags.enable_target_reset = |
| 6405 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6406 | ha->flags.enable_led_scheme = 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 6407 | 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] | 6408 | |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 6409 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 6410 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6411 | |
| 6412 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, |
| 6413 | sizeof(ha->fw_seriallink_options24)); |
| 6414 | |
| 6415 | /* save HBA serial number */ |
| 6416 | ha->serial0 = icb->port_name[5]; |
| 6417 | ha->serial1 = icb->port_name[6]; |
| 6418 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6419 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 6420 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6421 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6422 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 6423 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6424 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 6425 | |
| 6426 | /* Set minimum login_timeout to 4 seconds. */ |
| 6427 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 6428 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 6429 | if (le16_to_cpu(nv->login_timeout) < 4) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6430 | nv->login_timeout = cpu_to_le16(4); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6431 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6432 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 6433 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 6434 | ha->r_a_tov = 100; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6435 | |
| 6436 | ha->loop_reset_delay = nv->reset_delay; |
| 6437 | |
| 6438 | /* Link Down Timeout = 0: |
| 6439 | * |
| 6440 | * When Port Down timer expires we will start returning |
| 6441 | * I/O's to OS with "DID_NO_CONNECT". |
| 6442 | * |
| 6443 | * Link Down Timeout != 0: |
| 6444 | * |
| 6445 | * The driver waits for the link to come up after link down |
| 6446 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 6447 | */ |
| 6448 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 6449 | ha->loop_down_abort_time = |
| 6450 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 6451 | } else { |
| 6452 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 6453 | ha->loop_down_abort_time = |
| 6454 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 6455 | } |
| 6456 | |
| 6457 | /* Need enough time to try and get the port back. */ |
| 6458 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 6459 | if (qlport_down_retry) |
| 6460 | ha->port_down_retry_count = qlport_down_retry; |
| 6461 | |
| 6462 | /* Set login_retry_count */ |
| 6463 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 6464 | if (ha->port_down_retry_count == |
| 6465 | le16_to_cpu(nv->port_down_retry_count) && |
| 6466 | ha->port_down_retry_count > 3) |
| 6467 | ha->login_retry_count = ha->port_down_retry_count; |
| 6468 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 6469 | ha->login_retry_count = ha->port_down_retry_count; |
| 6470 | if (ql2xloginretrycount) |
| 6471 | ha->login_retry_count = ql2xloginretrycount; |
| 6472 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6473 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6474 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6475 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 6476 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 6477 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 6478 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 6479 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 6480 | icb->firmware_options_2 &= cpu_to_le32( |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6481 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6482 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6483 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 6484 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 6485 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6486 | ql_log(ql_log_info, vha, 0x006f, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6487 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 6488 | ha->zio_mode, ha->zio_timer * 100); |
| 6489 | |
| 6490 | icb->firmware_options_2 |= cpu_to_le32( |
| 6491 | (uint32_t)ha->zio_mode); |
| 6492 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6493 | vha->flags.process_response_queue = 1; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 6494 | } |
| 6495 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6496 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6497 | ql_log(ql_log_warn, vha, 0x0070, |
| 6498 | "NVRAM configuration failed.\n"); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 6499 | } |
| 6500 | return (rval); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6501 | } |
| 6502 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6503 | uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha) |
| 6504 | { |
| 6505 | struct qla27xx_image_status pri_image_status, sec_image_status; |
| 6506 | uint8_t valid_pri_image, valid_sec_image; |
| 6507 | uint32_t *wptr; |
| 6508 | uint32_t cnt, chksum, size; |
| 6509 | struct qla_hw_data *ha = vha->hw; |
| 6510 | |
| 6511 | valid_pri_image = valid_sec_image = 1; |
| 6512 | ha->active_image = 0; |
| 6513 | size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t); |
| 6514 | |
| 6515 | if (!ha->flt_region_img_status_pri) { |
| 6516 | valid_pri_image = 0; |
| 6517 | goto check_sec_image; |
| 6518 | } |
| 6519 | |
| 6520 | qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status), |
| 6521 | ha->flt_region_img_status_pri, size); |
| 6522 | |
| 6523 | if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) { |
| 6524 | ql_dbg(ql_dbg_init, vha, 0x018b, |
| 6525 | "Primary image signature (0x%x) not valid\n", |
| 6526 | pri_image_status.signature); |
| 6527 | valid_pri_image = 0; |
| 6528 | goto check_sec_image; |
| 6529 | } |
| 6530 | |
| 6531 | wptr = (uint32_t *)(&pri_image_status); |
| 6532 | cnt = size; |
| 6533 | |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6534 | for (chksum = 0; cnt--; wptr++) |
| 6535 | chksum += le32_to_cpu(*wptr); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 6536 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6537 | if (chksum) { |
| 6538 | ql_dbg(ql_dbg_init, vha, 0x018c, |
| 6539 | "Checksum validation failed for primary image (0x%x)\n", |
| 6540 | chksum); |
| 6541 | valid_pri_image = 0; |
| 6542 | } |
| 6543 | |
| 6544 | check_sec_image: |
| 6545 | if (!ha->flt_region_img_status_sec) { |
| 6546 | valid_sec_image = 0; |
| 6547 | goto check_valid_image; |
| 6548 | } |
| 6549 | |
| 6550 | qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status), |
| 6551 | ha->flt_region_img_status_sec, size); |
| 6552 | |
| 6553 | if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) { |
| 6554 | ql_dbg(ql_dbg_init, vha, 0x018d, |
| 6555 | "Secondary image signature(0x%x) not valid\n", |
| 6556 | sec_image_status.signature); |
| 6557 | valid_sec_image = 0; |
| 6558 | goto check_valid_image; |
| 6559 | } |
| 6560 | |
| 6561 | wptr = (uint32_t *)(&sec_image_status); |
| 6562 | cnt = size; |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 6563 | for (chksum = 0; cnt--; wptr++) |
| 6564 | chksum += le32_to_cpu(*wptr); |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6565 | if (chksum) { |
| 6566 | ql_dbg(ql_dbg_init, vha, 0x018e, |
| 6567 | "Checksum validation failed for secondary image (0x%x)\n", |
| 6568 | chksum); |
| 6569 | valid_sec_image = 0; |
| 6570 | } |
| 6571 | |
| 6572 | check_valid_image: |
| 6573 | if (valid_pri_image && (pri_image_status.image_status_mask & 0x1)) |
| 6574 | ha->active_image = QLA27XX_PRIMARY_IMAGE; |
| 6575 | if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) { |
| 6576 | if (!ha->active_image || |
| 6577 | pri_image_status.generation_number < |
| 6578 | sec_image_status.generation_number) |
| 6579 | ha->active_image = QLA27XX_SECONDARY_IMAGE; |
| 6580 | } |
| 6581 | |
| 6582 | ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n", |
| 6583 | ha->active_image == 0 ? "default bootld and fw" : |
| 6584 | ha->active_image == 1 ? "primary" : |
| 6585 | ha->active_image == 2 ? "secondary" : |
| 6586 | "Invalid"); |
| 6587 | |
| 6588 | return ha->active_image; |
| 6589 | } |
| 6590 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 6591 | static int |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 6592 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, |
| 6593 | uint32_t faddr) |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6594 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6595 | int rval = QLA_SUCCESS; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6596 | int segments, fragment; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6597 | uint32_t *dcode, dlen; |
| 6598 | uint32_t risc_addr; |
| 6599 | uint32_t risc_size; |
| 6600 | uint32_t i; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6601 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6602 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6603 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6604 | ql_dbg(ql_dbg_init, vha, 0x008b, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6605 | "FW: Loading firmware from flash (%x).\n", faddr); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6606 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6607 | rval = QLA_SUCCESS; |
| 6608 | |
| 6609 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6610 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6611 | *srisc_addr = 0; |
| 6612 | |
Sawan Chandak | 4243c11 | 2016-01-27 12:03:31 -0500 | [diff] [blame] | 6613 | if (IS_QLA27XX(ha) && |
| 6614 | qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE) |
| 6615 | faddr = ha->flt_region_fw_sec; |
| 6616 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6617 | /* Validate firmware image by checking version. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6618 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6619 | for (i = 0; i < 4; i++) |
| 6620 | dcode[i] = be32_to_cpu(dcode[i]); |
| 6621 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 6622 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 6623 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 6624 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6625 | ql_log(ql_log_fatal, vha, 0x008c, |
| 6626 | "Unable to verify the integrity of flash firmware " |
| 6627 | "image.\n"); |
| 6628 | ql_log(ql_log_fatal, vha, 0x008d, |
| 6629 | "Firmware data: %08x %08x %08x %08x.\n", |
| 6630 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6631 | |
| 6632 | return QLA_FUNCTION_FAILED; |
| 6633 | } |
| 6634 | |
| 6635 | while (segments && rval == QLA_SUCCESS) { |
| 6636 | /* Read segment's load information. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6637 | qla24xx_read_flash_data(vha, dcode, faddr, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6638 | |
| 6639 | risc_addr = be32_to_cpu(dcode[2]); |
| 6640 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 6641 | risc_size = be32_to_cpu(dcode[3]); |
| 6642 | |
| 6643 | fragment = 0; |
| 6644 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 6645 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 6646 | if (dlen > risc_size) |
| 6647 | dlen = risc_size; |
| 6648 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6649 | ql_dbg(ql_dbg_init, vha, 0x008e, |
| 6650 | "Loading risc segment@ risc addr %x " |
| 6651 | "number of dwords 0x%x offset 0x%x.\n", |
| 6652 | risc_addr, dlen, faddr); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6653 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6654 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6655 | for (i = 0; i < dlen; i++) |
| 6656 | dcode[i] = swab32(dcode[i]); |
| 6657 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6658 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6659 | dlen); |
| 6660 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6661 | ql_log(ql_log_fatal, vha, 0x008f, |
| 6662 | "Failed to load segment %d of firmware.\n", |
| 6663 | fragment); |
Chad Dupuis | f261f7a | 2014-09-25 05:17:03 -0400 | [diff] [blame] | 6664 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6665 | } |
| 6666 | |
| 6667 | faddr += dlen; |
| 6668 | risc_addr += dlen; |
| 6669 | risc_size -= dlen; |
| 6670 | fragment++; |
| 6671 | } |
| 6672 | |
| 6673 | /* Next segment. */ |
| 6674 | segments--; |
| 6675 | } |
| 6676 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6677 | if (!IS_QLA27XX(ha)) |
| 6678 | return rval; |
| 6679 | |
| 6680 | if (ha->fw_dump_template) |
| 6681 | vfree(ha->fw_dump_template); |
| 6682 | ha->fw_dump_template = NULL; |
| 6683 | ha->fw_dump_template_len = 0; |
| 6684 | |
| 6685 | ql_dbg(ql_dbg_init, vha, 0x0161, |
| 6686 | "Loading fwdump template from %x\n", faddr); |
| 6687 | qla24xx_read_flash_data(vha, dcode, faddr, 7); |
| 6688 | risc_size = be32_to_cpu(dcode[2]); |
| 6689 | ql_dbg(ql_dbg_init, vha, 0x0162, |
| 6690 | "-> array size %x dwords\n", risc_size); |
| 6691 | if (risc_size == 0 || risc_size == ~0) |
| 6692 | goto default_template; |
| 6693 | |
| 6694 | dlen = (risc_size - 8) * sizeof(*dcode); |
| 6695 | ql_dbg(ql_dbg_init, vha, 0x0163, |
| 6696 | "-> template allocating %x bytes...\n", dlen); |
| 6697 | ha->fw_dump_template = vmalloc(dlen); |
| 6698 | if (!ha->fw_dump_template) { |
| 6699 | ql_log(ql_log_warn, vha, 0x0164, |
| 6700 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 6701 | goto default_template; |
| 6702 | } |
| 6703 | |
| 6704 | faddr += 7; |
| 6705 | risc_size -= 8; |
| 6706 | dcode = ha->fw_dump_template; |
| 6707 | qla24xx_read_flash_data(vha, dcode, faddr, risc_size); |
| 6708 | for (i = 0; i < risc_size; i++) |
| 6709 | dcode[i] = le32_to_cpu(dcode[i]); |
| 6710 | |
| 6711 | if (!qla27xx_fwdt_template_valid(dcode)) { |
| 6712 | ql_log(ql_log_warn, vha, 0x0165, |
| 6713 | "Failed fwdump template validate\n"); |
| 6714 | goto default_template; |
| 6715 | } |
| 6716 | |
| 6717 | dlen = qla27xx_fwdt_template_size(dcode); |
| 6718 | ql_dbg(ql_dbg_init, vha, 0x0166, |
| 6719 | "-> template size %x bytes\n", dlen); |
| 6720 | if (dlen > risc_size * sizeof(*dcode)) { |
| 6721 | ql_log(ql_log_warn, vha, 0x0167, |
Himanshu Madhani | 4fae52b | 2017-06-06 13:55:23 -0700 | [diff] [blame] | 6722 | "Failed fwdump template exceeds array by %zx bytes\n", |
Joe Carnuccio | 383a298 | 2017-06-02 09:11:55 -0700 | [diff] [blame] | 6723 | (size_t)(dlen - risc_size * sizeof(*dcode))); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6724 | goto default_template; |
| 6725 | } |
| 6726 | ha->fw_dump_template_len = dlen; |
| 6727 | return rval; |
| 6728 | |
| 6729 | default_template: |
| 6730 | ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n"); |
| 6731 | if (ha->fw_dump_template) |
| 6732 | vfree(ha->fw_dump_template); |
| 6733 | ha->fw_dump_template = NULL; |
| 6734 | ha->fw_dump_template_len = 0; |
| 6735 | |
| 6736 | dlen = qla27xx_fwdt_template_default_size(); |
| 6737 | ql_dbg(ql_dbg_init, vha, 0x0169, |
| 6738 | "-> template allocating %x bytes...\n", dlen); |
| 6739 | ha->fw_dump_template = vmalloc(dlen); |
| 6740 | if (!ha->fw_dump_template) { |
| 6741 | ql_log(ql_log_warn, vha, 0x016a, |
| 6742 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 6743 | goto failed_template; |
| 6744 | } |
| 6745 | |
| 6746 | dcode = ha->fw_dump_template; |
| 6747 | risc_size = dlen / sizeof(*dcode); |
| 6748 | memcpy(dcode, qla27xx_fwdt_template_default(), dlen); |
| 6749 | for (i = 0; i < risc_size; i++) |
| 6750 | dcode[i] = be32_to_cpu(dcode[i]); |
| 6751 | |
| 6752 | if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) { |
| 6753 | ql_log(ql_log_warn, vha, 0x016b, |
| 6754 | "Failed fwdump template validate\n"); |
| 6755 | goto failed_template; |
| 6756 | } |
| 6757 | |
| 6758 | dlen = qla27xx_fwdt_template_size(ha->fw_dump_template); |
| 6759 | ql_dbg(ql_dbg_init, vha, 0x016c, |
| 6760 | "-> template size %x bytes\n", dlen); |
| 6761 | ha->fw_dump_template_len = dlen; |
| 6762 | return rval; |
| 6763 | |
| 6764 | failed_template: |
| 6765 | ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n"); |
| 6766 | if (ha->fw_dump_template) |
| 6767 | vfree(ha->fw_dump_template); |
| 6768 | ha->fw_dump_template = NULL; |
| 6769 | ha->fw_dump_template_len = 0; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6770 | return rval; |
| 6771 | } |
| 6772 | |
Giridhar Malavali | e9454a8 | 2013-02-08 01:57:47 -0500 | [diff] [blame] | 6773 | #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/" |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6774 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6775 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6776 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6777 | { |
| 6778 | int rval; |
| 6779 | int i, fragment; |
| 6780 | uint16_t *wcode, *fwcode; |
| 6781 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; |
| 6782 | struct fw_blob *blob; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6783 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6784 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6785 | |
| 6786 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6787 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6788 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6789 | ql_log(ql_log_info, vha, 0x0083, |
Yannick Guerrini | 94bcf83 | 2015-02-26 22:49:34 +0100 | [diff] [blame] | 6790 | "Firmware image unavailable.\n"); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6791 | ql_log(ql_log_info, vha, 0x0084, |
| 6792 | "Firmware images can be retrieved from: "QLA_FW_URL ".\n"); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6793 | return QLA_FUNCTION_FAILED; |
| 6794 | } |
| 6795 | |
| 6796 | rval = QLA_SUCCESS; |
| 6797 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6798 | wcode = (uint16_t *)req->ring; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6799 | *srisc_addr = 0; |
| 6800 | fwcode = (uint16_t *)blob->fw->data; |
| 6801 | fwclen = 0; |
| 6802 | |
| 6803 | /* Validate firmware image by checking version. */ |
| 6804 | if (blob->fw->size < 8 * sizeof(uint16_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6805 | ql_log(ql_log_fatal, vha, 0x0085, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 6806 | "Unable to verify integrity of firmware image (%zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6807 | blob->fw->size); |
| 6808 | goto fail_fw_integrity; |
| 6809 | } |
| 6810 | for (i = 0; i < 4; i++) |
| 6811 | wcode[i] = be16_to_cpu(fwcode[i + 4]); |
| 6812 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && |
| 6813 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && |
| 6814 | wcode[2] == 0 && wcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6815 | ql_log(ql_log_fatal, vha, 0x0086, |
| 6816 | "Unable to verify integrity of firmware image.\n"); |
| 6817 | ql_log(ql_log_fatal, vha, 0x0087, |
| 6818 | "Firmware data: %04x %04x %04x %04x.\n", |
| 6819 | wcode[0], wcode[1], wcode[2], wcode[3]); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6820 | goto fail_fw_integrity; |
| 6821 | } |
| 6822 | |
| 6823 | seg = blob->segs; |
| 6824 | while (*seg && rval == QLA_SUCCESS) { |
| 6825 | risc_addr = *seg; |
| 6826 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; |
| 6827 | risc_size = be16_to_cpu(fwcode[3]); |
| 6828 | |
| 6829 | /* Validate firmware image size. */ |
| 6830 | fwclen += risc_size * sizeof(uint16_t); |
| 6831 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6832 | ql_log(ql_log_fatal, vha, 0x0088, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6833 | "Unable to verify integrity of firmware image " |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 6834 | "(%zd).\n", blob->fw->size); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6835 | goto fail_fw_integrity; |
| 6836 | } |
| 6837 | |
| 6838 | fragment = 0; |
| 6839 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 6840 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); |
| 6841 | if (wlen > risc_size) |
| 6842 | wlen = risc_size; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6843 | ql_dbg(ql_dbg_init, vha, 0x0089, |
| 6844 | "Loading risc segment@ risc addr %x number of " |
| 6845 | "words 0x%x.\n", risc_addr, wlen); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6846 | |
| 6847 | for (i = 0; i < wlen; i++) |
| 6848 | wcode[i] = swab16(fwcode[i]); |
| 6849 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6850 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6851 | wlen); |
| 6852 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6853 | ql_log(ql_log_fatal, vha, 0x008a, |
| 6854 | "Failed to load segment %d of firmware.\n", |
| 6855 | fragment); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6856 | break; |
| 6857 | } |
| 6858 | |
| 6859 | fwcode += wlen; |
| 6860 | risc_addr += wlen; |
| 6861 | risc_size -= wlen; |
| 6862 | fragment++; |
| 6863 | } |
| 6864 | |
| 6865 | /* Next segment. */ |
| 6866 | seg++; |
| 6867 | } |
| 6868 | return rval; |
| 6869 | |
| 6870 | fail_fw_integrity: |
| 6871 | return QLA_FUNCTION_FAILED; |
| 6872 | } |
| 6873 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6874 | static int |
| 6875 | 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] | 6876 | { |
| 6877 | int rval; |
| 6878 | int segments, fragment; |
| 6879 | uint32_t *dcode, dlen; |
| 6880 | uint32_t risc_addr; |
| 6881 | uint32_t risc_size; |
| 6882 | uint32_t i; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6883 | struct fw_blob *blob; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6884 | const uint32_t *fwcode; |
| 6885 | uint32_t fwclen; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6886 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6887 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6888 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6889 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 6890 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6891 | if (!blob) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6892 | ql_log(ql_log_warn, vha, 0x0090, |
Yannick Guerrini | 94bcf83 | 2015-02-26 22:49:34 +0100 | [diff] [blame] | 6893 | "Firmware image unavailable.\n"); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6894 | ql_log(ql_log_warn, vha, 0x0091, |
| 6895 | "Firmware images can be retrieved from: " |
| 6896 | QLA_FW_URL ".\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 6897 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6898 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6899 | } |
| 6900 | |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 6901 | ql_dbg(ql_dbg_init, vha, 0x0092, |
| 6902 | "FW: Loading via request-firmware.\n"); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 6903 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6904 | rval = QLA_SUCCESS; |
| 6905 | |
| 6906 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6907 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6908 | *srisc_addr = 0; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6909 | fwcode = (uint32_t *)blob->fw->data; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6910 | fwclen = 0; |
| 6911 | |
| 6912 | /* Validate firmware image by checking version. */ |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6913 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6914 | ql_log(ql_log_fatal, vha, 0x0093, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 6915 | "Unable to verify integrity of firmware image (%zd).\n", |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6916 | blob->fw->size); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6917 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6918 | } |
| 6919 | for (i = 0; i < 4; i++) |
| 6920 | dcode[i] = be32_to_cpu(fwcode[i + 4]); |
| 6921 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 6922 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 6923 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 6924 | dcode[3] == 0)) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6925 | ql_log(ql_log_fatal, vha, 0x0094, |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 6926 | "Unable to verify integrity of firmware image (%zd).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6927 | blob->fw->size); |
| 6928 | ql_log(ql_log_fatal, vha, 0x0095, |
| 6929 | "Firmware data: %08x %08x %08x %08x.\n", |
| 6930 | dcode[0], dcode[1], dcode[2], dcode[3]); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6931 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6932 | } |
| 6933 | |
| 6934 | while (segments && rval == QLA_SUCCESS) { |
| 6935 | risc_addr = be32_to_cpu(fwcode[2]); |
| 6936 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 6937 | risc_size = be32_to_cpu(fwcode[3]); |
| 6938 | |
| 6939 | /* Validate firmware image size. */ |
| 6940 | fwclen += risc_size * sizeof(uint32_t); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6941 | if (blob->fw->size < fwclen) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6942 | ql_log(ql_log_fatal, vha, 0x0096, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 6943 | "Unable to verify integrity of firmware image " |
Alexey Dobriyan | 5b5e092 | 2017-02-27 14:30:02 -0800 | [diff] [blame] | 6944 | "(%zd).\n", blob->fw->size); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6945 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6946 | } |
| 6947 | |
| 6948 | fragment = 0; |
| 6949 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 6950 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 6951 | if (dlen > risc_size) |
| 6952 | dlen = risc_size; |
| 6953 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6954 | ql_dbg(ql_dbg_init, vha, 0x0097, |
| 6955 | "Loading risc segment@ risc addr %x " |
| 6956 | "number of dwords 0x%x.\n", risc_addr, dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6957 | |
| 6958 | for (i = 0; i < dlen; i++) |
| 6959 | dcode[i] = swab32(fwcode[i]); |
| 6960 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 6961 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 6962 | dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6963 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 6964 | ql_log(ql_log_fatal, vha, 0x0098, |
| 6965 | "Failed to load segment %d of firmware.\n", |
| 6966 | fragment); |
Chad Dupuis | f261f7a | 2014-09-25 05:17:03 -0400 | [diff] [blame] | 6967 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 6968 | } |
| 6969 | |
| 6970 | fwcode += dlen; |
| 6971 | risc_addr += dlen; |
| 6972 | risc_size -= dlen; |
| 6973 | fragment++; |
| 6974 | } |
| 6975 | |
| 6976 | /* Next segment. */ |
| 6977 | segments--; |
| 6978 | } |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6979 | |
| 6980 | if (!IS_QLA27XX(ha)) |
| 6981 | return rval; |
| 6982 | |
| 6983 | if (ha->fw_dump_template) |
| 6984 | vfree(ha->fw_dump_template); |
| 6985 | ha->fw_dump_template = NULL; |
| 6986 | ha->fw_dump_template_len = 0; |
| 6987 | |
| 6988 | ql_dbg(ql_dbg_init, vha, 0x171, |
Chad Dupuis | 97ea702 | 2014-03-13 14:16:40 -0400 | [diff] [blame] | 6989 | "Loading fwdump template from %x\n", |
| 6990 | (uint32_t)((void *)fwcode - (void *)blob->fw->data)); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 6991 | risc_size = be32_to_cpu(fwcode[2]); |
| 6992 | ql_dbg(ql_dbg_init, vha, 0x172, |
| 6993 | "-> array size %x dwords\n", risc_size); |
| 6994 | if (risc_size == 0 || risc_size == ~0) |
| 6995 | goto default_template; |
| 6996 | |
| 6997 | dlen = (risc_size - 8) * sizeof(*fwcode); |
| 6998 | ql_dbg(ql_dbg_init, vha, 0x0173, |
| 6999 | "-> template allocating %x bytes...\n", dlen); |
| 7000 | ha->fw_dump_template = vmalloc(dlen); |
| 7001 | if (!ha->fw_dump_template) { |
| 7002 | ql_log(ql_log_warn, vha, 0x0174, |
| 7003 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 7004 | goto default_template; |
| 7005 | } |
| 7006 | |
| 7007 | fwcode += 7; |
| 7008 | risc_size -= 8; |
| 7009 | dcode = ha->fw_dump_template; |
| 7010 | for (i = 0; i < risc_size; i++) |
| 7011 | dcode[i] = le32_to_cpu(fwcode[i]); |
| 7012 | |
| 7013 | if (!qla27xx_fwdt_template_valid(dcode)) { |
| 7014 | ql_log(ql_log_warn, vha, 0x0175, |
| 7015 | "Failed fwdump template validate\n"); |
| 7016 | goto default_template; |
| 7017 | } |
| 7018 | |
| 7019 | dlen = qla27xx_fwdt_template_size(dcode); |
| 7020 | ql_dbg(ql_dbg_init, vha, 0x0176, |
| 7021 | "-> template size %x bytes\n", dlen); |
| 7022 | if (dlen > risc_size * sizeof(*fwcode)) { |
| 7023 | ql_log(ql_log_warn, vha, 0x0177, |
Himanshu Madhani | 4fae52b | 2017-06-06 13:55:23 -0700 | [diff] [blame] | 7024 | "Failed fwdump template exceeds array by %zx bytes\n", |
Joe Carnuccio | 383a298 | 2017-06-02 09:11:55 -0700 | [diff] [blame] | 7025 | (size_t)(dlen - risc_size * sizeof(*fwcode))); |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7026 | goto default_template; |
| 7027 | } |
| 7028 | ha->fw_dump_template_len = dlen; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7029 | return rval; |
| 7030 | |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7031 | default_template: |
| 7032 | ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n"); |
| 7033 | if (ha->fw_dump_template) |
| 7034 | vfree(ha->fw_dump_template); |
| 7035 | ha->fw_dump_template = NULL; |
| 7036 | ha->fw_dump_template_len = 0; |
| 7037 | |
| 7038 | dlen = qla27xx_fwdt_template_default_size(); |
| 7039 | ql_dbg(ql_dbg_init, vha, 0x0179, |
| 7040 | "-> template allocating %x bytes...\n", dlen); |
| 7041 | ha->fw_dump_template = vmalloc(dlen); |
| 7042 | if (!ha->fw_dump_template) { |
| 7043 | ql_log(ql_log_warn, vha, 0x017a, |
| 7044 | "Failed fwdump template allocate %x bytes.\n", risc_size); |
| 7045 | goto failed_template; |
| 7046 | } |
| 7047 | |
| 7048 | dcode = ha->fw_dump_template; |
| 7049 | risc_size = dlen / sizeof(*fwcode); |
| 7050 | fwcode = qla27xx_fwdt_template_default(); |
| 7051 | for (i = 0; i < risc_size; i++) |
| 7052 | dcode[i] = be32_to_cpu(fwcode[i]); |
| 7053 | |
| 7054 | if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) { |
| 7055 | ql_log(ql_log_warn, vha, 0x017b, |
| 7056 | "Failed fwdump template validate\n"); |
| 7057 | goto failed_template; |
| 7058 | } |
| 7059 | |
| 7060 | dlen = qla27xx_fwdt_template_size(ha->fw_dump_template); |
| 7061 | ql_dbg(ql_dbg_init, vha, 0x017c, |
| 7062 | "-> template size %x bytes\n", dlen); |
| 7063 | ha->fw_dump_template_len = dlen; |
| 7064 | return rval; |
| 7065 | |
| 7066 | failed_template: |
| 7067 | ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n"); |
| 7068 | if (ha->fw_dump_template) |
| 7069 | vfree(ha->fw_dump_template); |
| 7070 | ha->fw_dump_template = NULL; |
| 7071 | ha->fw_dump_template_len = 0; |
| 7072 | return rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 7073 | } |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7074 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7075 | int |
| 7076 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 7077 | { |
| 7078 | int rval; |
| 7079 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 7080 | if (ql2xfwloadbin == 1) |
| 7081 | return qla81xx_load_risc(vha, srisc_addr); |
| 7082 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7083 | /* |
| 7084 | * FW Load priority: |
| 7085 | * 1) Firmware via request-firmware interface (.bin file). |
| 7086 | * 2) Firmware residing in flash. |
| 7087 | */ |
| 7088 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 7089 | if (rval == QLA_SUCCESS) |
| 7090 | return rval; |
| 7091 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7092 | return qla24xx_load_risc_flash(vha, srisc_addr, |
| 7093 | vha->hw->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7094 | } |
| 7095 | |
| 7096 | int |
| 7097 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 7098 | { |
| 7099 | int rval; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7100 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7101 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 7102 | if (ql2xfwloadbin == 2) |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7103 | goto try_blob_fw; |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 7104 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7105 | /* |
| 7106 | * FW Load priority: |
| 7107 | * 1) Firmware residing in flash. |
| 7108 | * 2) Firmware via request-firmware interface (.bin file). |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7109 | * 3) Golden-Firmware residing in flash -- limited operation. |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7110 | */ |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7111 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7112 | if (rval == QLA_SUCCESS) |
| 7113 | return rval; |
| 7114 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7115 | try_blob_fw: |
| 7116 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 7117 | if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw) |
| 7118 | return rval; |
| 7119 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7120 | ql_log(ql_log_info, vha, 0x0099, |
| 7121 | "Attempting to fallback to golden firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7122 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); |
| 7123 | if (rval != QLA_SUCCESS) |
| 7124 | return rval; |
| 7125 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7126 | ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n"); |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7127 | ha->flags.running_gold_fw = 1; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 7128 | return rval; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 7129 | } |
| 7130 | |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7131 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7132 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7133 | { |
| 7134 | int ret, retries; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7135 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7136 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 7137 | if (ha->flags.pci_channel_io_perm_failure) |
| 7138 | return; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 7139 | if (!IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7140 | return; |
Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 7141 | if (!ha->fw_major_version) |
| 7142 | return; |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 7143 | if (!ha->flags.fw_started) |
| 7144 | return; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7145 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7146 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 7147 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
Andrew Vasquez | b469a7c | 2009-04-06 22:33:48 -0700 | [diff] [blame] | 7148 | ret != QLA_INVALID_COMMAND && retries ; retries--) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7149 | ha->isp_ops->reset_chip(vha); |
| 7150 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7151 | continue; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7152 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7153 | continue; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7154 | ql_log(ql_log_info, vha, 0x8015, |
| 7155 | "Attempting retry of stop-firmware command.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7156 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7157 | } |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 7158 | |
Quinn Tran | 4b60c82 | 2017-06-13 20:47:21 -0700 | [diff] [blame] | 7159 | QLA_FW_STOPPED(ha); |
Quinn Tran | ec7193e | 2017-03-15 09:48:55 -0700 | [diff] [blame] | 7160 | ha->flags.fw_init_done = 0; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 7161 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7162 | |
| 7163 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7164 | qla24xx_configure_vhba(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7165 | { |
| 7166 | int rval = QLA_SUCCESS; |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 7167 | int rval2; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7168 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7169 | struct qla_hw_data *ha = vha->hw; |
| 7170 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 7171 | struct req_que *req; |
| 7172 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7173 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7174 | if (!vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7175 | return -EINVAL; |
| 7176 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7177 | rval = qla2x00_fw_ready(base_vha); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7178 | if (vha->qpair) |
| 7179 | req = vha->qpair->req; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 7180 | else |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7181 | req = ha->req_q_map[0]; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 7182 | rsp = req->rsp; |
| 7183 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7184 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7185 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 7186 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7187 | } |
| 7188 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7189 | vha->flags.management_server_logged_in = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7190 | |
| 7191 | /* Login to SNS first */ |
Chad Dupuis | 0b91d11 | 2012-02-09 11:15:42 -0800 | [diff] [blame] | 7192 | rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, |
| 7193 | BIT_1); |
| 7194 | if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) { |
| 7195 | if (rval2 == QLA_MEMORY_ALLOC_FAILED) |
| 7196 | ql_dbg(ql_dbg_init, vha, 0x0120, |
| 7197 | "Failed SNS login: loop_id=%x, rval2=%d\n", |
| 7198 | NPH_SNS, rval2); |
| 7199 | else |
| 7200 | ql_dbg(ql_dbg_init, vha, 0x0103, |
| 7201 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 7202 | "mb[2]=%x mb[6]=%x mb[7]=%x.\n", |
| 7203 | NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7204 | return (QLA_FUNCTION_FAILED); |
| 7205 | } |
| 7206 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7207 | atomic_set(&vha->loop_down_timer, 0); |
| 7208 | atomic_set(&vha->loop_state, LOOP_UP); |
| 7209 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 7210 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 7211 | rval = qla2x00_loop_resync(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 7212 | |
| 7213 | return rval; |
| 7214 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7215 | |
| 7216 | /* 84XX Support **************************************************************/ |
| 7217 | |
| 7218 | static LIST_HEAD(qla_cs84xx_list); |
| 7219 | static DEFINE_MUTEX(qla_cs84xx_mutex); |
| 7220 | |
| 7221 | static struct qla_chip_state_84xx * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7222 | qla84xx_get_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7223 | { |
| 7224 | struct qla_chip_state_84xx *cs84xx; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7225 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7226 | |
| 7227 | mutex_lock(&qla_cs84xx_mutex); |
| 7228 | |
| 7229 | /* Find any shared 84xx chip. */ |
| 7230 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { |
| 7231 | if (cs84xx->bus == ha->pdev->bus) { |
| 7232 | kref_get(&cs84xx->kref); |
| 7233 | goto done; |
| 7234 | } |
| 7235 | } |
| 7236 | |
| 7237 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); |
| 7238 | if (!cs84xx) |
| 7239 | goto done; |
| 7240 | |
| 7241 | kref_init(&cs84xx->kref); |
| 7242 | spin_lock_init(&cs84xx->access_lock); |
| 7243 | mutex_init(&cs84xx->fw_update_mutex); |
| 7244 | cs84xx->bus = ha->pdev->bus; |
| 7245 | |
| 7246 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); |
| 7247 | done: |
| 7248 | mutex_unlock(&qla_cs84xx_mutex); |
| 7249 | return cs84xx; |
| 7250 | } |
| 7251 | |
| 7252 | static void |
| 7253 | __qla84xx_chip_release(struct kref *kref) |
| 7254 | { |
| 7255 | struct qla_chip_state_84xx *cs84xx = |
| 7256 | container_of(kref, struct qla_chip_state_84xx, kref); |
| 7257 | |
| 7258 | mutex_lock(&qla_cs84xx_mutex); |
| 7259 | list_del(&cs84xx->list); |
| 7260 | mutex_unlock(&qla_cs84xx_mutex); |
| 7261 | kfree(cs84xx); |
| 7262 | } |
| 7263 | |
| 7264 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7265 | qla84xx_put_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7266 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7267 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7268 | if (ha->cs84xx) |
| 7269 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); |
| 7270 | } |
| 7271 | |
| 7272 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7273 | qla84xx_init_chip(scsi_qla_host_t *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7274 | { |
| 7275 | int rval; |
| 7276 | uint16_t status[2]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7277 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7278 | |
| 7279 | mutex_lock(&ha->cs84xx->fw_update_mutex); |
| 7280 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 7281 | rval = qla84xx_verify_chip(vha, status); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 7282 | |
| 7283 | mutex_unlock(&ha->cs84xx->fw_update_mutex); |
| 7284 | |
| 7285 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: |
| 7286 | QLA_SUCCESS; |
| 7287 | } |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7288 | |
| 7289 | /* 81XX Support **************************************************************/ |
| 7290 | |
| 7291 | int |
| 7292 | qla81xx_nvram_config(scsi_qla_host_t *vha) |
| 7293 | { |
| 7294 | int rval; |
| 7295 | struct init_cb_81xx *icb; |
| 7296 | struct nvram_81xx *nv; |
| 7297 | uint32_t *dptr; |
| 7298 | uint8_t *dptr1, *dptr2; |
| 7299 | uint32_t chksum; |
| 7300 | uint16_t cnt; |
| 7301 | struct qla_hw_data *ha = vha->hw; |
| 7302 | |
| 7303 | rval = QLA_SUCCESS; |
| 7304 | icb = (struct init_cb_81xx *)ha->init_cb; |
| 7305 | nv = ha->nvram; |
| 7306 | |
| 7307 | /* Determine NVRAM starting address. */ |
| 7308 | ha->nvram_size = sizeof(struct nvram_81xx); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7309 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 7310 | if (IS_P3P_TYPE(ha) || IS_QLA8031(ha)) |
| 7311 | ha->vpd_size = FA_VPD_SIZE_82XX; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7312 | |
| 7313 | /* Get VPD data into cache */ |
| 7314 | ha->vpd = ha->nvram + VPD_OFFSET; |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 7315 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
| 7316 | ha->vpd_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7317 | |
| 7318 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 7319 | 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] | 7320 | ha->nvram_size); |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 7321 | dptr = (uint32_t *)nv; |
Joe Carnuccio | da08ef5 | 2016-01-27 12:03:34 -0500 | [diff] [blame] | 7322 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++) |
| 7323 | chksum += le32_to_cpu(*dptr); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7324 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7325 | ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111, |
| 7326 | "Contents of NVRAM:\n"); |
| 7327 | ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112, |
| 7328 | (uint8_t *)nv, ha->nvram_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7329 | |
| 7330 | /* Bad NVRAM data, set defaults parameters. */ |
| 7331 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 7332 | || nv->id[3] != ' ' || |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7333 | nv->nvram_version < cpu_to_le16(ICB_VERSION)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7334 | /* Reset NVRAM data. */ |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7335 | ql_log(ql_log_info, vha, 0x0073, |
Raul Porcel | 9e33652 | 2012-05-15 14:34:08 -0400 | [diff] [blame] | 7336 | "Inconsistent NVRAM detected: checksum=0x%x id=%c " |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7337 | "version=0x%x.\n", chksum, nv->id[0], |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7338 | le16_to_cpu(nv->nvram_version)); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7339 | ql_log(ql_log_info, vha, 0x0074, |
| 7340 | "Falling back to functioning (yet invalid -- WWPN) " |
| 7341 | "defaults.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7342 | |
| 7343 | /* |
| 7344 | * Set default initialization control block. |
| 7345 | */ |
| 7346 | memset(nv, 0, ha->nvram_size); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7347 | nv->nvram_version = cpu_to_le16(ICB_VERSION); |
| 7348 | nv->version = cpu_to_le16(ICB_VERSION); |
Joe Carnuccio | 98aee70 | 2014-09-25 05:16:38 -0400 | [diff] [blame] | 7349 | nv->frame_payload_size = 2048; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7350 | nv->execution_throttle = cpu_to_le16(0xFFFF); |
| 7351 | nv->exchange_count = cpu_to_le16(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7352 | nv->port_name[0] = 0x21; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7353 | nv->port_name[1] = 0x00 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7354 | nv->port_name[2] = 0x00; |
| 7355 | nv->port_name[3] = 0xe0; |
| 7356 | nv->port_name[4] = 0x8b; |
| 7357 | nv->port_name[5] = 0x1c; |
| 7358 | nv->port_name[6] = 0x55; |
| 7359 | nv->port_name[7] = 0x86; |
| 7360 | nv->node_name[0] = 0x20; |
| 7361 | nv->node_name[1] = 0x00; |
| 7362 | nv->node_name[2] = 0x00; |
| 7363 | nv->node_name[3] = 0xe0; |
| 7364 | nv->node_name[4] = 0x8b; |
| 7365 | nv->node_name[5] = 0x1c; |
| 7366 | nv->node_name[6] = 0x55; |
| 7367 | nv->node_name[7] = 0x86; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7368 | nv->login_retry_count = cpu_to_le16(8); |
| 7369 | nv->interrupt_delay_timer = cpu_to_le16(0); |
| 7370 | nv->login_timeout = cpu_to_le16(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7371 | nv->firmware_options_1 = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7372 | cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 7373 | nv->firmware_options_2 = cpu_to_le32(2 << 4); |
| 7374 | nv->firmware_options_2 |= cpu_to_le32(BIT_12); |
| 7375 | nv->firmware_options_3 = cpu_to_le32(2 << 13); |
| 7376 | nv->host_p = cpu_to_le32(BIT_11|BIT_10); |
| 7377 | nv->efi_parameters = cpu_to_le32(0); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7378 | nv->reset_delay = 5; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7379 | nv->max_luns_per_target = cpu_to_le16(128); |
| 7380 | nv->port_down_retry_count = cpu_to_le16(30); |
| 7381 | nv->link_down_timeout = cpu_to_le16(180); |
Andrew Vasquez | eeebcc9 | 2009-06-03 09:55:24 -0700 | [diff] [blame] | 7382 | nv->enode_mac[0] = 0x00; |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7383 | nv->enode_mac[1] = 0xC0; |
| 7384 | nv->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7385 | nv->enode_mac[3] = 0x04; |
| 7386 | nv->enode_mac[4] = 0x05; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7387 | nv->enode_mac[5] = 0x06 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7388 | |
| 7389 | rval = 1; |
| 7390 | } |
| 7391 | |
Arun Easi | 9e522cd | 2012-08-22 14:21:31 -0400 | [diff] [blame] | 7392 | if (IS_T10_PI_CAPABLE(ha)) |
| 7393 | nv->frame_payload_size &= ~7; |
| 7394 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7395 | qlt_81xx_config_nvram_stage1(vha, nv); |
| 7396 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7397 | /* Reset Initialization control block */ |
Andrew Vasquez | 773120e | 2011-05-10 11:30:14 -0700 | [diff] [blame] | 7398 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7399 | |
| 7400 | /* Copy 1st segment. */ |
| 7401 | dptr1 = (uint8_t *)icb; |
| 7402 | dptr2 = (uint8_t *)&nv->version; |
| 7403 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 7404 | while (cnt--) |
| 7405 | *dptr1++ = *dptr2++; |
| 7406 | |
| 7407 | icb->login_retry_count = nv->login_retry_count; |
| 7408 | |
| 7409 | /* Copy 2nd segment. */ |
| 7410 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 7411 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 7412 | cnt = (uint8_t *)&icb->reserved_5 - |
| 7413 | (uint8_t *)&icb->interrupt_delay_timer; |
| 7414 | while (cnt--) |
| 7415 | *dptr1++ = *dptr2++; |
| 7416 | |
| 7417 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); |
| 7418 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ |
| 7419 | 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] | 7420 | icb->enode_mac[0] = 0x00; |
| 7421 | icb->enode_mac[1] = 0xC0; |
| 7422 | icb->enode_mac[2] = 0xDD; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7423 | icb->enode_mac[3] = 0x04; |
| 7424 | icb->enode_mac[4] = 0x05; |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7425 | icb->enode_mac[5] = 0x06 + ha->port_no + 1; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7426 | } |
| 7427 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 7428 | /* Use extended-initialization control block. */ |
| 7429 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); |
| 7430 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7431 | /* |
| 7432 | * Setup driver NVRAM options. |
| 7433 | */ |
| 7434 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7435 | "QLE8XXX"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7436 | |
Arun Easi | aa230bc | 2013-01-30 03:34:39 -0500 | [diff] [blame] | 7437 | qlt_81xx_config_nvram_stage2(vha, icb); |
| 7438 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7439 | /* Use alternate WWN? */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7440 | if (nv->host_p & cpu_to_le32(BIT_15)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7441 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 7442 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 7443 | } |
| 7444 | |
| 7445 | /* Prepare nodename */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7446 | if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7447 | /* |
| 7448 | * Firmware will apply the following mask if the nodename was |
| 7449 | * not provided. |
| 7450 | */ |
| 7451 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 7452 | icb->node_name[0] &= 0xF0; |
| 7453 | } |
| 7454 | |
| 7455 | /* Set host adapter parameters. */ |
| 7456 | ha->flags.disable_risc_code_load = 0; |
| 7457 | ha->flags.enable_lip_reset = 0; |
| 7458 | ha->flags.enable_lip_full_login = |
| 7459 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 7460 | ha->flags.enable_target_reset = |
| 7461 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
| 7462 | ha->flags.enable_led_scheme = 0; |
| 7463 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
| 7464 | |
| 7465 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 7466 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 7467 | |
| 7468 | /* save HBA serial number */ |
| 7469 | ha->serial0 = icb->port_name[5]; |
| 7470 | ha->serial1 = icb->port_name[6]; |
| 7471 | ha->serial2 = icb->port_name[7]; |
| 7472 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 7473 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
| 7474 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7475 | icb->execution_throttle = cpu_to_le16(0xFFFF); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7476 | |
| 7477 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 7478 | |
| 7479 | /* Set minimum login_timeout to 4 seconds. */ |
| 7480 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 7481 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 7482 | if (le16_to_cpu(nv->login_timeout) < 4) |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7483 | nv->login_timeout = cpu_to_le16(4); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7484 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7485 | |
| 7486 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 7487 | ha->r_a_tov = 100; |
| 7488 | |
| 7489 | ha->loop_reset_delay = nv->reset_delay; |
| 7490 | |
| 7491 | /* Link Down Timeout = 0: |
| 7492 | * |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 7493 | * When Port Down timer expires we will start returning |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7494 | * I/O's to OS with "DID_NO_CONNECT". |
| 7495 | * |
| 7496 | * Link Down Timeout != 0: |
| 7497 | * |
| 7498 | * The driver waits for the link to come up after link down |
| 7499 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 7500 | */ |
| 7501 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 7502 | ha->loop_down_abort_time = |
| 7503 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 7504 | } else { |
| 7505 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 7506 | ha->loop_down_abort_time = |
| 7507 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 7508 | } |
| 7509 | |
| 7510 | /* Need enough time to try and get the port back. */ |
| 7511 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 7512 | if (qlport_down_retry) |
| 7513 | ha->port_down_retry_count = qlport_down_retry; |
| 7514 | |
| 7515 | /* Set login_retry_count */ |
| 7516 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 7517 | if (ha->port_down_retry_count == |
| 7518 | le16_to_cpu(nv->port_down_retry_count) && |
| 7519 | ha->port_down_retry_count > 3) |
| 7520 | ha->login_retry_count = ha->port_down_retry_count; |
| 7521 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 7522 | ha->login_retry_count = ha->port_down_retry_count; |
| 7523 | if (ql2xloginretrycount) |
| 7524 | ha->login_retry_count = ql2xloginretrycount; |
| 7525 | |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7526 | /* if not running MSI-X we need handshaking on interrupts */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 7527 | 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] | 7528 | icb->firmware_options_2 |= cpu_to_le32(BIT_22); |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 7529 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7530 | /* Enable ZIO. */ |
| 7531 | if (!vha->flags.init_done) { |
| 7532 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 7533 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 7534 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 7535 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 7536 | } |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 7537 | icb->firmware_options_2 &= cpu_to_le32( |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7538 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
| 7539 | vha->flags.process_response_queue = 0; |
| 7540 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
| 7541 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 7542 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7543 | ql_log(ql_log_info, vha, 0x0075, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7544 | "ZIO mode %d enabled; timer delay (%d us).\n", |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7545 | ha->zio_mode, |
| 7546 | ha->zio_timer * 100); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7547 | |
| 7548 | icb->firmware_options_2 |= cpu_to_le32( |
| 7549 | (uint32_t)ha->zio_mode); |
| 7550 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
| 7551 | vha->flags.process_response_queue = 1; |
| 7552 | } |
| 7553 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7554 | /* enable RIDA Format2 */ |
| 7555 | if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) |
| 7556 | icb->firmware_options_3 |= BIT_0; |
| 7557 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7558 | if (rval) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7559 | ql_log(ql_log_warn, vha, 0x0076, |
| 7560 | "NVRAM configuration failed.\n"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7561 | } |
| 7562 | return (rval); |
| 7563 | } |
| 7564 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7565 | int |
| 7566 | qla82xx_restart_isp(scsi_qla_host_t *vha) |
| 7567 | { |
| 7568 | int status, rval; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7569 | struct qla_hw_data *ha = vha->hw; |
| 7570 | struct req_que *req = ha->req_q_map[0]; |
| 7571 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
| 7572 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7573 | unsigned long flags; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7574 | |
| 7575 | status = qla2x00_init_rings(vha); |
| 7576 | if (!status) { |
| 7577 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 7578 | ha->flags.chip_reset_done = 1; |
| 7579 | |
| 7580 | status = qla2x00_fw_ready(vha); |
| 7581 | if (!status) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7582 | /* Issue a marker after FW becomes ready. */ |
| 7583 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7584 | vha->flags.online = 1; |
Chad Dupuis | 7108b76 | 2014-04-11 16:54:45 -0400 | [diff] [blame] | 7585 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7586 | } |
| 7587 | |
| 7588 | /* if no cable then assume it's good */ |
| 7589 | if ((vha->device_flags & DFLG_NO_CABLE)) |
| 7590 | status = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7591 | } |
| 7592 | |
| 7593 | if (!status) { |
| 7594 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 7595 | |
| 7596 | if (!atomic_read(&vha->loop_down_timer)) { |
| 7597 | /* |
| 7598 | * Issue marker command only when we are going |
| 7599 | * to start the I/O . |
| 7600 | */ |
| 7601 | vha->marker_needed = 1; |
| 7602 | } |
| 7603 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7604 | ha->isp_ops->enable_intrs(ha); |
| 7605 | |
| 7606 | ha->isp_abort_cnt = 0; |
| 7607 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 7608 | |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 7609 | /* Update the firmware version */ |
Giridhar Malavali | 3173167 | 2011-08-16 11:31:54 -0700 | [diff] [blame] | 7610 | status = qla82xx_check_md_needed(vha); |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 7611 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7612 | if (ha->fce) { |
| 7613 | ha->flags.fce_enabled = 1; |
| 7614 | memset(ha->fce, 0, |
| 7615 | fce_calc_size(ha->fce_bufs)); |
| 7616 | rval = qla2x00_enable_fce_trace(vha, |
| 7617 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 7618 | &ha->fce_bufs); |
| 7619 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7620 | ql_log(ql_log_warn, vha, 0x8001, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7621 | "Unable to reinitialize FCE (%d).\n", |
| 7622 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7623 | ha->flags.fce_enabled = 0; |
| 7624 | } |
| 7625 | } |
| 7626 | |
| 7627 | if (ha->eft) { |
| 7628 | memset(ha->eft, 0, EFT_SIZE); |
| 7629 | rval = qla2x00_enable_eft_trace(vha, |
| 7630 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 7631 | if (rval) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7632 | ql_log(ql_log_warn, vha, 0x8010, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7633 | "Unable to reinitialize EFT (%d).\n", |
| 7634 | rval); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7635 | } |
| 7636 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7637 | } |
| 7638 | |
| 7639 | if (!status) { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7640 | ql_dbg(ql_dbg_taskm, vha, 0x8011, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7641 | "qla82xx_restart_isp succeeded.\n"); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7642 | |
| 7643 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 7644 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 7645 | if (vp->vp_idx) { |
| 7646 | atomic_inc(&vp->vref_count); |
| 7647 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 7648 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7649 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7650 | |
| 7651 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 7652 | atomic_dec(&vp->vref_count); |
| 7653 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7654 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 7655 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 7656 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7657 | } else { |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7658 | ql_log(ql_log_warn, vha, 0x8016, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7659 | "qla82xx_restart_isp **** FAILED ****.\n"); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 7660 | } |
| 7661 | |
| 7662 | return status; |
| 7663 | } |
| 7664 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7665 | void |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7666 | qla81xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7667 | { |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7668 | struct qla_hw_data *ha = vha->hw; |
| 7669 | |
Himanshu Madhani | f198caf | 2016-01-27 12:03:30 -0500 | [diff] [blame] | 7670 | /* Hold status IOCBs until ABTS response received. */ |
| 7671 | if (ql2xfwholdabts) |
| 7672 | ha->fw_options[3] |= BIT_12; |
| 7673 | |
Giridhar Malavali | 088d09d | 2016-07-06 11:14:20 -0400 | [diff] [blame] | 7674 | /* Set Retry FLOGI in case of P2P connection */ |
| 7675 | if (ha->operating_mode == P2P) { |
| 7676 | ha->fw_options[2] |= BIT_3; |
| 7677 | ql_dbg(ql_dbg_disc, vha, 0x2103, |
| 7678 | "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n", |
| 7679 | __func__, ha->fw_options[2]); |
| 7680 | } |
| 7681 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7682 | /* Move PUREX, ABTS RX & RIDA to ATIOQ */ |
| 7683 | if (ql2xmvasynctoatio) { |
| 7684 | if (qla_tgt_mode_enabled(vha) || |
| 7685 | qla_dual_mode_enabled(vha)) |
| 7686 | ha->fw_options[2] |= BIT_11; |
| 7687 | else |
| 7688 | ha->fw_options[2] &= ~BIT_11; |
| 7689 | } |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7690 | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 7691 | if (qla_tgt_mode_enabled(vha) || |
Quinn Tran | 2da5273 | 2017-06-02 09:12:05 -0700 | [diff] [blame] | 7692 | qla_dual_mode_enabled(vha)) { |
| 7693 | /* FW auto send SCSI status during */ |
| 7694 | ha->fw_options[1] |= BIT_8; |
| 7695 | ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8; |
| 7696 | |
| 7697 | /* FW perform Exchange validation */ |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 7698 | ha->fw_options[2] |= BIT_4; |
Quinn Tran | 2da5273 | 2017-06-02 09:12:05 -0700 | [diff] [blame] | 7699 | } else { |
| 7700 | ha->fw_options[1] &= ~BIT_8; |
| 7701 | ha->fw_options[10] &= 0x00ff; |
| 7702 | |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 7703 | ha->fw_options[2] &= ~BIT_4; |
Quinn Tran | 2da5273 | 2017-06-02 09:12:05 -0700 | [diff] [blame] | 7704 | } |
Quinn Tran | f7e761f | 2017-06-02 09:12:02 -0700 | [diff] [blame] | 7705 | |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7706 | if (ql2xetsenable) { |
| 7707 | /* Enable ETS Burst. */ |
| 7708 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
| 7709 | ha->fw_options[2] |= BIT_9; |
| 7710 | } |
| 7711 | |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7712 | ql_dbg(ql_dbg_init, vha, 0x00e9, |
| 7713 | "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n", |
| 7714 | __func__, ha->fw_options[1], ha->fw_options[2], |
| 7715 | ha->fw_options[3], vha->host->active_mode); |
Quinn Tran | 41dc529 | 2017-01-19 22:28:03 -0800 | [diff] [blame] | 7716 | |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 7717 | qla2x00_set_fw_options(vha, ha->fw_options); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 7718 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7719 | |
| 7720 | /* |
| 7721 | * qla24xx_get_fcp_prio |
| 7722 | * Gets the fcp cmd priority value for the logged in port. |
| 7723 | * Looks for a match of the port descriptors within |
| 7724 | * each of the fcp prio config entries. If a match is found, |
| 7725 | * the tag (priority) value is returned. |
| 7726 | * |
| 7727 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7728 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7729 | * fcport = port structure pointer. |
| 7730 | * |
| 7731 | * Return: |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 7732 | * non-zero (if found) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7733 | * -1 (if not found) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7734 | * |
| 7735 | * Context: |
| 7736 | * Kernel context |
| 7737 | */ |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7738 | static int |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7739 | qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 7740 | { |
| 7741 | int i, entries; |
| 7742 | uint8_t pid_match, wwn_match; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7743 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7744 | uint32_t pid1, pid2; |
| 7745 | uint64_t wwn1, wwn2; |
| 7746 | struct qla_fcp_prio_entry *pri_entry; |
| 7747 | struct qla_hw_data *ha = vha->hw; |
| 7748 | |
| 7749 | if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7750 | return -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7751 | |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7752 | priority = -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7753 | entries = ha->fcp_prio_cfg->num_entries; |
| 7754 | pri_entry = &ha->fcp_prio_cfg->entry[0]; |
| 7755 | |
| 7756 | for (i = 0; i < entries; i++) { |
| 7757 | pid_match = wwn_match = 0; |
| 7758 | |
| 7759 | if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { |
| 7760 | pri_entry++; |
| 7761 | continue; |
| 7762 | } |
| 7763 | |
| 7764 | /* check source pid for a match */ |
| 7765 | if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { |
| 7766 | pid1 = pri_entry->src_pid & INVALID_PORT_ID; |
| 7767 | pid2 = vha->d_id.b24 & INVALID_PORT_ID; |
| 7768 | if (pid1 == INVALID_PORT_ID) |
| 7769 | pid_match++; |
| 7770 | else if (pid1 == pid2) |
| 7771 | pid_match++; |
| 7772 | } |
| 7773 | |
| 7774 | /* check destination pid for a match */ |
| 7775 | if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { |
| 7776 | pid1 = pri_entry->dst_pid & INVALID_PORT_ID; |
| 7777 | pid2 = fcport->d_id.b24 & INVALID_PORT_ID; |
| 7778 | if (pid1 == INVALID_PORT_ID) |
| 7779 | pid_match++; |
| 7780 | else if (pid1 == pid2) |
| 7781 | pid_match++; |
| 7782 | } |
| 7783 | |
| 7784 | /* check source WWN for a match */ |
| 7785 | if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { |
| 7786 | wwn1 = wwn_to_u64(vha->port_name); |
| 7787 | wwn2 = wwn_to_u64(pri_entry->src_wwpn); |
| 7788 | if (wwn2 == (uint64_t)-1) |
| 7789 | wwn_match++; |
| 7790 | else if (wwn1 == wwn2) |
| 7791 | wwn_match++; |
| 7792 | } |
| 7793 | |
| 7794 | /* check destination WWN for a match */ |
| 7795 | if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { |
| 7796 | wwn1 = wwn_to_u64(fcport->port_name); |
| 7797 | wwn2 = wwn_to_u64(pri_entry->dst_wwpn); |
| 7798 | if (wwn2 == (uint64_t)-1) |
| 7799 | wwn_match++; |
| 7800 | else if (wwn1 == wwn2) |
| 7801 | wwn_match++; |
| 7802 | } |
| 7803 | |
| 7804 | if (pid_match == 2 || wwn_match == 2) { |
| 7805 | /* Found a matching entry */ |
| 7806 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) |
| 7807 | priority = pri_entry->tag; |
| 7808 | break; |
| 7809 | } |
| 7810 | |
| 7811 | pri_entry++; |
| 7812 | } |
| 7813 | |
| 7814 | return priority; |
| 7815 | } |
| 7816 | |
| 7817 | /* |
| 7818 | * qla24xx_update_fcport_fcp_prio |
| 7819 | * Activates fcp priority for the logged in fc port |
| 7820 | * |
| 7821 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7822 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7823 | * fcp = port structure pointer. |
| 7824 | * |
| 7825 | * Return: |
| 7826 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 7827 | * |
| 7828 | * Context: |
| 7829 | * Kernel context. |
| 7830 | */ |
| 7831 | int |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7832 | 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] | 7833 | { |
| 7834 | int ret; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7835 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7836 | uint16_t mb[5]; |
| 7837 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7838 | if (fcport->port_type != FCT_TARGET || |
| 7839 | fcport->loop_id == FC_NO_LOOP_ID) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7840 | return QLA_FUNCTION_FAILED; |
| 7841 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7842 | priority = qla24xx_get_fcp_prio(vha, fcport); |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 7843 | if (priority < 0) |
| 7844 | return QLA_FUNCTION_FAILED; |
| 7845 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 7846 | if (IS_P3P_TYPE(vha->hw)) { |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 7847 | fcport->fcp_prio = priority & 0xf; |
| 7848 | return QLA_SUCCESS; |
| 7849 | } |
| 7850 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 7851 | ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7852 | if (ret == QLA_SUCCESS) { |
| 7853 | if (fcport->fcp_prio != priority) |
| 7854 | ql_dbg(ql_dbg_user, vha, 0x709e, |
| 7855 | "Updated FCP_CMND priority - value=%d loop_id=%d " |
| 7856 | "port_id=%02x%02x%02x.\n", priority, |
| 7857 | fcport->loop_id, fcport->d_id.b.domain, |
| 7858 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 7859 | fcport->fcp_prio = priority & 0xf; |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7860 | } else |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 7861 | ql_dbg(ql_dbg_user, vha, 0x704f, |
Chad Dupuis | cfb0919 | 2011-11-18 09:03:07 -0800 | [diff] [blame] | 7862 | "Unable to update FCP_CMND priority - ret=0x%x for " |
| 7863 | "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id, |
| 7864 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 7865 | fcport->d_id.b.al_pa); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 7866 | return ret; |
| 7867 | } |
| 7868 | |
| 7869 | /* |
| 7870 | * qla24xx_update_all_fcp_prio |
| 7871 | * Activates fcp priority for all the logged in ports |
| 7872 | * |
| 7873 | * Input: |
| 7874 | * ha = adapter block pointer. |
| 7875 | * |
| 7876 | * Return: |
| 7877 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 7878 | * |
| 7879 | * Context: |
| 7880 | * Kernel context. |
| 7881 | */ |
| 7882 | int |
| 7883 | qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) |
| 7884 | { |
| 7885 | int ret; |
| 7886 | fc_port_t *fcport; |
| 7887 | |
| 7888 | ret = QLA_FUNCTION_FAILED; |
| 7889 | /* We need to set priority for all logged in ports */ |
| 7890 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 7891 | ret = qla24xx_update_fcport_fcp_prio(vha, fcport); |
| 7892 | |
| 7893 | return ret; |
| 7894 | } |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7895 | |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7896 | struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos, |
| 7897 | int vp_idx, bool startqp) |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7898 | { |
| 7899 | int rsp_id = 0; |
| 7900 | int req_id = 0; |
| 7901 | int i; |
| 7902 | struct qla_hw_data *ha = vha->hw; |
| 7903 | uint16_t qpair_id = 0; |
| 7904 | struct qla_qpair *qpair = NULL; |
| 7905 | struct qla_msix_entry *msix; |
| 7906 | |
| 7907 | if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) { |
| 7908 | ql_log(ql_log_warn, vha, 0x00181, |
| 7909 | "FW/Driver is not multi-queue capable.\n"); |
| 7910 | return NULL; |
| 7911 | } |
| 7912 | |
| 7913 | if (ql2xmqsupport) { |
| 7914 | qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL); |
| 7915 | if (qpair == NULL) { |
| 7916 | ql_log(ql_log_warn, vha, 0x0182, |
| 7917 | "Failed to allocate memory for queue pair.\n"); |
| 7918 | return NULL; |
| 7919 | } |
| 7920 | memset(qpair, 0, sizeof(struct qla_qpair)); |
| 7921 | |
| 7922 | qpair->hw = vha->hw; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 7923 | qpair->vha = vha; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7924 | qpair->qp_lock_ptr = &qpair->qp_lock; |
| 7925 | spin_lock_init(&qpair->qp_lock); |
Quinn Tran | af7bb38 | 2017-06-13 20:47:23 -0700 | [diff] [blame] | 7926 | qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7927 | |
| 7928 | /* Assign available que pair id */ |
| 7929 | mutex_lock(&ha->mq_lock); |
| 7930 | 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] | 7931 | if (ha->num_qpairs >= ha->max_qpairs) { |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7932 | mutex_unlock(&ha->mq_lock); |
| 7933 | ql_log(ql_log_warn, vha, 0x0183, |
| 7934 | "No resources to create additional q pair.\n"); |
| 7935 | goto fail_qid_map; |
| 7936 | } |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame] | 7937 | ha->num_qpairs++; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7938 | set_bit(qpair_id, ha->qpair_qid_map); |
| 7939 | ha->queue_pair_map[qpair_id] = qpair; |
| 7940 | qpair->id = qpair_id; |
| 7941 | qpair->vp_idx = vp_idx; |
himanshu.madhani@cavium.com | e6373f33 | 2017-08-23 15:04:57 -0700 | [diff] [blame] | 7942 | qpair->fw_started = ha->flags.fw_started; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 7943 | INIT_LIST_HEAD(&qpair->hints_list); |
Duane Grigsby | cf19c45 | 2017-08-23 15:04:58 -0700 | [diff] [blame] | 7944 | INIT_LIST_HEAD(&qpair->nvme_done_list); |
Quinn Tran | 7c3f8fd | 2017-06-13 20:47:22 -0700 | [diff] [blame] | 7945 | qpair->chip_reset = ha->base_qpair->chip_reset; |
| 7946 | qpair->enable_class_2 = ha->base_qpair->enable_class_2; |
| 7947 | qpair->enable_explicit_conf = |
| 7948 | ha->base_qpair->enable_explicit_conf; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7949 | |
| 7950 | for (i = 0; i < ha->msix_count; i++) { |
Quinn Tran | 093df73 | 2016-12-12 14:40:09 -0800 | [diff] [blame] | 7951 | msix = &ha->msix_entries[i]; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7952 | if (msix->in_use) |
| 7953 | continue; |
| 7954 | qpair->msix = msix; |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 7955 | ql_dbg(ql_dbg_multiq, vha, 0xc00f, |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7956 | "Vector %x selected for qpair\n", msix->vector); |
| 7957 | break; |
| 7958 | } |
| 7959 | if (!qpair->msix) { |
| 7960 | ql_log(ql_log_warn, vha, 0x0184, |
| 7961 | "Out of MSI-X vectors!.\n"); |
| 7962 | goto fail_msix; |
| 7963 | } |
| 7964 | |
| 7965 | qpair->msix->in_use = 1; |
| 7966 | list_add_tail(&qpair->qp_list_elem, &vha->qp_list); |
Quinn Tran | 8abfa9e | 2017-06-13 20:47:24 -0700 | [diff] [blame] | 7967 | qpair->pdev = ha->pdev; |
| 7968 | if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) |
| 7969 | qpair->reqq_start_iocbs = qla_83xx_start_iocbs; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7970 | |
| 7971 | mutex_unlock(&ha->mq_lock); |
| 7972 | |
| 7973 | /* Create response queue first */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7974 | rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7975 | if (!rsp_id) { |
| 7976 | ql_log(ql_log_warn, vha, 0x0185, |
| 7977 | "Failed to create response queue.\n"); |
| 7978 | goto fail_rsp; |
| 7979 | } |
| 7980 | |
| 7981 | qpair->rsp = ha->rsp_q_map[rsp_id]; |
| 7982 | |
| 7983 | /* Create request queue */ |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7984 | req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos, |
| 7985 | startqp); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7986 | if (!req_id) { |
| 7987 | ql_log(ql_log_warn, vha, 0x0186, |
| 7988 | "Failed to create request queue.\n"); |
| 7989 | goto fail_req; |
| 7990 | } |
| 7991 | |
| 7992 | qpair->req = ha->req_q_map[req_id]; |
| 7993 | qpair->rsp->req = qpair->req; |
Quinn Tran | 82de802 | 2017-06-13 20:47:17 -0700 | [diff] [blame] | 7994 | qpair->rsp->qpair = qpair; |
Quinn Tran | e326d22 | 2017-06-13 20:47:18 -0700 | [diff] [blame] | 7995 | /* init qpair to this cpu. Will adjust at run time. */ |
| 7996 | qla_cpu_update(qpair, smp_processor_id()); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 7997 | |
| 7998 | if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) { |
| 7999 | if (ha->fw_attributes & BIT_4) |
| 8000 | qpair->difdix_supported = 1; |
| 8001 | } |
| 8002 | |
| 8003 | qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep); |
| 8004 | if (!qpair->srb_mempool) { |
Quinn Tran | 83548fe | 2017-06-02 09:12:01 -0700 | [diff] [blame] | 8005 | ql_log(ql_log_warn, vha, 0xd036, |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8006 | "Failed to create srb mempool for qpair %d\n", |
| 8007 | qpair->id); |
| 8008 | goto fail_mempool; |
| 8009 | } |
| 8010 | |
| 8011 | /* Mark as online */ |
| 8012 | qpair->online = 1; |
| 8013 | |
| 8014 | if (!vha->flags.qpairs_available) |
| 8015 | vha->flags.qpairs_available = 1; |
| 8016 | |
| 8017 | ql_dbg(ql_dbg_multiq, vha, 0xc00d, |
| 8018 | "Request/Response queue pair created, id %d\n", |
| 8019 | qpair->id); |
| 8020 | ql_dbg(ql_dbg_init, vha, 0x0187, |
| 8021 | "Request/Response queue pair created, id %d\n", |
| 8022 | qpair->id); |
| 8023 | } |
| 8024 | return qpair; |
| 8025 | |
| 8026 | fail_mempool: |
| 8027 | fail_req: |
| 8028 | qla25xx_delete_rsp_que(vha, qpair->rsp); |
| 8029 | fail_rsp: |
| 8030 | mutex_lock(&ha->mq_lock); |
| 8031 | qpair->msix->in_use = 0; |
| 8032 | list_del(&qpair->qp_list_elem); |
| 8033 | if (list_empty(&vha->qp_list)) |
| 8034 | vha->flags.qpairs_available = 0; |
| 8035 | fail_msix: |
| 8036 | ha->queue_pair_map[qpair_id] = NULL; |
| 8037 | clear_bit(qpair_id, ha->qpair_qid_map); |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame] | 8038 | ha->num_qpairs--; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8039 | mutex_unlock(&ha->mq_lock); |
| 8040 | fail_qid_map: |
| 8041 | kfree(qpair); |
| 8042 | return NULL; |
| 8043 | } |
| 8044 | |
| 8045 | int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair) |
| 8046 | { |
Sawan Chandak | d65237c | 2017-06-13 20:47:19 -0700 | [diff] [blame] | 8047 | int ret = QLA_FUNCTION_FAILED; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8048 | struct qla_hw_data *ha = qpair->hw; |
| 8049 | |
Sawan Chandak | d65237c | 2017-06-13 20:47:19 -0700 | [diff] [blame] | 8050 | if (!vha->flags.qpairs_req_created && !vha->flags.qpairs_rsp_created) |
| 8051 | goto fail; |
| 8052 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8053 | qpair->delete_in_progress = 1; |
| 8054 | while (atomic_read(&qpair->ref_count)) |
| 8055 | msleep(500); |
| 8056 | |
| 8057 | ret = qla25xx_delete_req_que(vha, qpair->req); |
| 8058 | if (ret != QLA_SUCCESS) |
| 8059 | goto fail; |
| 8060 | ret = qla25xx_delete_rsp_que(vha, qpair->rsp); |
| 8061 | if (ret != QLA_SUCCESS) |
| 8062 | goto fail; |
| 8063 | |
| 8064 | mutex_lock(&ha->mq_lock); |
| 8065 | ha->queue_pair_map[qpair->id] = NULL; |
| 8066 | clear_bit(qpair->id, ha->qpair_qid_map); |
Sawan Chandak | b95b945 | 2017-05-24 18:06:20 -0700 | [diff] [blame] | 8067 | ha->num_qpairs--; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8068 | list_del(&qpair->qp_list_elem); |
Sawan Chandak | d65237c | 2017-06-13 20:47:19 -0700 | [diff] [blame] | 8069 | if (list_empty(&vha->qp_list)) { |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8070 | vha->flags.qpairs_available = 0; |
Sawan Chandak | d65237c | 2017-06-13 20:47:19 -0700 | [diff] [blame] | 8071 | vha->flags.qpairs_req_created = 0; |
| 8072 | vha->flags.qpairs_rsp_created = 0; |
| 8073 | } |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 8074 | mempool_destroy(qpair->srb_mempool); |
| 8075 | kfree(qpair); |
| 8076 | mutex_unlock(&ha->mq_lock); |
| 8077 | |
| 8078 | return QLA_SUCCESS; |
| 8079 | fail: |
| 8080 | return ret; |
| 8081 | } |