blob: d00e0129c51b7e4a6117e6fb33a166651ba91744 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Armen Baloyanbd21eaf2014-04-11 16:54:24 -04003 * Copyright (c) 2003-2014 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
Anirban Chakraborty73208df2008-12-09 16:45:39 -08008#include "qla_gbl.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Andrew Vasquez0107109e2005-07-06 10:31:37 -070012#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#include "qla_devtbl.h"
15
David Miller4e08df32007-04-16 12:37:43 -070016#ifdef CONFIG_SPARC
17#include <asm/prom.h>
David Miller4e08df32007-04-16 12:37:43 -070018#endif
19
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040020#include <target/target_core_base.h>
21#include "qla_target.h"
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023/*
24* QLogic ISP2x00 Hardware Support Function Prototypes.
25*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070026static int qla2x00_isp_firmware(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027static int qla2x00_setup_chip(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028static int qla2x00_fw_ready(scsi_qla_host_t *);
29static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static int qla2x00_configure_loop(scsi_qla_host_t *);
31static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032static int qla2x00_configure_fabric(scsi_qla_host_t *);
Quinn Tran726b8542017-01-19 22:28:00 -080033static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Harihara Kadayam4d4df192008-04-03 13:13:26 -070036static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
37static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080038static int qla25xx_init_queues(struct qla_hw_data *);
Quinn Tran726b8542017-01-19 22:28:00 -080039static int qla24xx_post_gpdb_work(struct scsi_qla_host *, fc_port_t *, u8);
Duane Grigsbya5d42f42017-06-21 13:48:41 -070040static int qla24xx_post_prli_work(struct scsi_qla_host*, fc_port_t *);
Quinn Tran726b8542017-01-19 22:28:00 -080041static void qla24xx_handle_plogi_done_event(struct scsi_qla_host *,
42 struct event_arg *);
Duane Grigsbya5d42f42017-06-21 13:48:41 -070043static void qla24xx_handle_prli_done_event(struct scsi_qla_host *,
44 struct event_arg *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070045
Andrew Vasquezac280b62009-08-20 11:06:05 -070046/* SRB Extensions ---------------------------------------------------------- */
47
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080048void
49qla2x00_sp_timeout(unsigned long __data)
Andrew Vasquezac280b62009-08-20 11:06:05 -070050{
51 srb_t *sp = (srb_t *)__data;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070052 struct srb_iocb *iocb;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080053 scsi_qla_host_t *vha = sp->vha;
Andrew Vasquezac280b62009-08-20 11:06:05 -070054 struct req_que *req;
55 unsigned long flags;
56
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080057 spin_lock_irqsave(&vha->hw->hardware_lock, flags);
58 req = vha->hw->req_q_map[0];
Andrew Vasquezac280b62009-08-20 11:06:05 -070059 req->outstanding_cmds[sp->handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080060 iocb = &sp->u.iocb_cmd;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070061 iocb->timeout(sp);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080062 sp->free(sp);
63 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -070064}
65
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080066void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080067qla2x00_sp_free(void *ptr)
Andrew Vasquezac280b62009-08-20 11:06:05 -070068{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080069 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080070 struct srb_iocb *iocb = &sp->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -070071
Chad Dupuis4d97cc52010-10-15 11:27:41 -070072 del_timer(&iocb->timer);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080073 qla2x00_rel_sp(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -070074}
75
Andrew Vasquezac280b62009-08-20 11:06:05 -070076/* Asynchronous Login/Logout Routines -------------------------------------- */
77
Saurav Kashyapa9b6f722012-08-22 14:21:01 -040078unsigned long
Andrew Vasquez5b914902010-05-28 15:08:30 -070079qla2x00_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 Malavali8ae6d9c2013-03-28 08:21:23 -040086 if (IS_QLAFX00(ha)) {
87 tmo = FX00_DEF_RATOV * 2;
88 } else if (!IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez5b914902010-05-28 15:08:30 -070089 /*
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 Vasquezac280b62009-08-20 11:06:05 -070097
Quinn Tran726b8542017-01-19 22:28:00 -080098void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080099qla2x00_async_iocb_timeout(void *data)
Andrew Vasquezac280b62009-08-20 11:06:05 -0700100{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800101 srb_t *sp = data;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700102 fc_port_t *fcport = sp->fcport;
Quinn Tran726b8542017-01-19 22:28:00 -0800103 struct srb_iocb *lio = &sp->u.iocb_cmd;
104 struct event_arg ea;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700105
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700106 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
Quinn Tran726b8542017-01-19 22:28:00 -0800107 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
108 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700109
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700110 fcport->flags &= ~FCF_ASYNC_SENT;
Quinn Tran726b8542017-01-19 22:28:00 -0800111
112 switch (sp->type) {
113 case SRB_LOGIN_CMD:
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700114 /* 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 Tran726b8542017-01-19 22:28:00 -0800118 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 Potashnika6ca8872015-07-14 16:00:44 -0400127 qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT);
Quinn Tran726b8542017-01-19 22:28:00 -0800128 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 Carnuccio25ff6af2017-01-19 22:28:04 -0800134 sp->done(sp, QLA_FUNCTION_TIMEOUT);
Quinn Tran726b8542017-01-19 22:28:00 -0800135 break;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700136 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700137}
138
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700139static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800140qla2x00_async_login_sp_done(void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700141{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800142 srb_t *sp = ptr;
143 struct scsi_qla_host *vha = sp->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800144 struct srb_iocb *lio = &sp->u.iocb_cmd;
Quinn Tran726b8542017-01-19 22:28:00 -0800145 struct event_arg ea;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700146
Quinn Tran83548fe2017-06-02 09:12:01 -0700147 ql_dbg(ql_dbg_disc, vha, 0x20dd,
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800148 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
Quinn Tran726b8542017-01-19 22:28:00 -0800149
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 Carnuccio25ff6af2017-01-19 22:28:04 -0800163 sp->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700164}
165
Andrew Vasquezac280b62009-08-20 11:06:05 -0700166int
167qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
168 uint16_t *data)
169{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700170 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700171 struct srb_iocb *lio;
Quinn Tran726b8542017-01-19 22:28:00 -0800172 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700173
Quinn Tran726b8542017-01-19 22:28:00 -0800174 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 Malavali9ba56b92012-02-09 11:15:36 -0800182 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700183 if (!sp)
184 goto done;
185
Quinn Tran726b8542017-01-19 22:28:00 -0800186 fcport->flags |= FCF_ASYNC_SENT;
187 fcport->logout_completed = 0;
188
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800189 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 Iyengar38222632010-05-04 15:01:29 -0700194 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800195 sp->done = qla2x00_async_login_sp_done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700196 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700197
198 if (fcport->fc4f_nvme)
199 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
200
Andrew Vasquezac280b62009-08-20 11:06:05 -0700201 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700202 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700203 rval = qla2x00_start_sp(sp);
Chad Dupuis080c9512016-01-27 12:03:37 -0500204 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 Vasquezac280b62009-08-20 11:06:05 -0700208 goto done_free_sp;
Chad Dupuis080c9512016-01-27 12:03:37 -0500209 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700210
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700211 ql_dbg(ql_dbg_disc, vha, 0x2072,
Quinn Tran726b8542017-01-19 22:28:00 -0800212 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
213 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800214 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
215 fcport->login_retry);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700216 return rval;
217
218done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800219 sp->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700220done:
Quinn Tran726b8542017-01-19 22:28:00 -0800221 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700222 return rval;
223}
224
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700225static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800226qla2x00_async_logout_sp_done(void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700227{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800228 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800229 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700230
Quinn Tran726b8542017-01-19 22:28:00 -0800231 sp->fcport->flags &= ~FCF_ASYNC_SENT;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800232 if (!test_bit(UNLOADING, &sp->vha->dpc_flags))
233 qla2x00_post_async_logout_done_work(sp->vha, sp->fcport,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800234 lio->u.logio.data);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800235 sp->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700236}
237
Andrew Vasquezac280b62009-08-20 11:06:05 -0700238int
239qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
240{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700241 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700242 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700243 int rval;
244
245 rval = QLA_FUNCTION_FAILED;
Quinn Tran726b8542017-01-19 22:28:00 -0800246 fcport->flags |= FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800247 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700248 if (!sp)
249 goto done;
250
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800251 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 Iyengar38222632010-05-04 15:01:29 -0700256 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800257 sp->done = qla2x00_async_logout_sp_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700258 rval = qla2x00_start_sp(sp);
259 if (rval != QLA_SUCCESS)
260 goto done_free_sp;
261
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700262 ql_dbg(ql_dbg_disc, vha, 0x2070,
Quinn Tran726b8542017-01-19 22:28:00 -0800263 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -0800264 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
Quinn Tran726b8542017-01-19 22:28:00 -0800265 fcport->d_id.b.area, fcport->d_id.b.al_pa,
266 fcport->port_name);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700267 return rval;
268
269done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800270 sp->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700271done:
Quinn Tran726b8542017-01-19 22:28:00 -0800272 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700273 return rval;
274}
275
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700276static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800277qla2x00_async_adisc_sp_done(void *ptr, int res)
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700278{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800279 srb_t *sp = ptr;
280 struct scsi_qla_host *vha = sp->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800281 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700282
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800283 if (!test_bit(UNLOADING, &vha->dpc_flags))
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800284 qla2x00_post_async_adisc_done_work(sp->vha, sp->fcport,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800285 lio->u.logio.data);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800286 sp->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700287}
288
289int
290qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
291 uint16_t *data)
292{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700293 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700294 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700295 int rval;
296
297 rval = QLA_FUNCTION_FAILED;
Quinn Tran726b8542017-01-19 22:28:00 -0800298 fcport->flags |= FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800299 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700300 if (!sp)
301 goto done;
302
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800303 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 Iyengar38222632010-05-04 15:01:29 -0700308 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800309 sp->done = qla2x00_async_adisc_sp_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700310 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700311 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700312 rval = qla2x00_start_sp(sp);
313 if (rval != QLA_SUCCESS)
314 goto done_free_sp;
315
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700316 ql_dbg(ql_dbg_disc, vha, 0x206f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800317 "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 Vasquez5ff1d582010-05-04 15:01:26 -0700320 return rval;
321
322done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800323 sp->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700324done:
Quinn Tran726b8542017-01-19 22:28:00 -0800325 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700326 return rval;
327}
328
Quinn Tran726b8542017-01-19 22:28:00 -0800329static 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 Grigsbya5d42f42017-06-21 13:48:41 -0700337 u8 opt = 0, current_login_state;
Quinn Tran726b8542017-01-19 22:28:00 -0800338
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 Tran83548fe2017-06-02 09:12:01 -0700344 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 Tran726b8542017-01-19 22:28:00 -0800347 }
348 return;
349 }
350
351 if (fcport->last_rscn_gen != fcport->rscn_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700352 ql_dbg(ql_dbg_disc, vha, 0x20df,
Quinn Tran726b8542017-01-19 22:28:00 -0800353 "%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 Tran83548fe2017-06-02 09:12:01 -0700359 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 Tran726b8542017-01-19 22:28:00 -0800363 return;
364 }
365
366 n = ea->data[0] / sizeof(struct get_name_list_extended);
367
Quinn Tran83548fe2017-06-02 09:12:01 -0700368 ql_dbg(ql_dbg_disc, vha, 0x20e1,
Quinn Tran726b8542017-01-19 22:28:00 -0800369 "%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 Tran83548fe2017-06-02 09:12:01 -0700390 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 Tran726b8542017-01-19 22:28:00 -0800397
398 if ((id.b24 != fcport->d_id.b24) ||
399 ((fcport->loop_id != FC_NO_LOOP_ID) &&
400 (fcport->loop_id != loop_id))) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700401 ql_dbg(ql_dbg_disc, vha, 0x20e3,
402 "%s %d %8phC post del sess\n",
403 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800404 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 Grigsbya5d42f42017-06-21 13:48:41 -0700424 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 Tran726b8542017-01-19 22:28:00 -0800430 case DSC_LS_PRLI_COMP:
Quinn Tran83548fe2017-06-02 09:12:01 -0700431 ql_dbg(ql_dbg_disc, vha, 0x20e4,
432 "%s %d %8phC post gpdb\n",
433 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800434 opt = PDO_FORCE_ADISC;
435 qla24xx_post_gpdb_work(vha, fcport, opt);
436 break;
Quinn Tran726b8542017-01-19 22:28:00 -0800437 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 Tran83548fe2017-06-02 09:12:01 -0700443 ql_dbg(ql_dbg_disc, vha, 0x20e5,
444 "%s %d %8phC\n",
445 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800446 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 Tran83548fe2017-06-02 09:12:01 -0700470 ql_dbg(ql_dbg_disc, vha, 0x20e6,
Quinn Tran726b8542017-01-19 22:28:00 -0800471 "%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
488static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800489qla24xx_async_gnl_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -0800490{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800491 struct srb *sp = s;
492 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -0800493 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 Tran83548fe2017-06-02 09:12:01 -0700501 ql_dbg(ql_dbg_disc, vha, 0x20e7,
Quinn Tran726b8542017-01-19 22:28:00 -0800502 "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 Tran83548fe2017-06-02 09:12:01 -0700526 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
Quinn Tran726b8542017-01-19 22:28:00 -0800527 "%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 Carnuccio25ff6af2017-01-19 22:28:04 -0800551 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800552}
553
554int 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 Tran83548fe2017-06-02 09:12:01 -0700565 ql_dbg(ql_dbg_disc, vha, 0x20d9,
Quinn Tran726b8542017-01-19 22:28:00 -0800566 "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 Tran83548fe2017-06-02 09:12:01 -0700612 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 Tran726b8542017-01-19 22:28:00 -0800615
616 return rval;
617
618done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800619 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800620done:
621 fcport->flags &= ~FCF_ASYNC_SENT;
622 return rval;
623}
624
625int 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
637static
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800638void qla24xx_async_gpdb_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -0800639{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800640 struct srb *sp = s;
641 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -0800642 struct qla_hw_data *ha = vha->hw;
Quinn Tran726b8542017-01-19 22:28:00 -0800643 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 Tran83548fe2017-06-02 09:12:01 -0700649 ql_dbg(ql_dbg_disc, vha, 0x20db,
Quinn Tran726b8542017-01-19 22:28:00 -0800650 "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 Tran15f30a52017-03-15 09:48:52 -0700662 rval = __qla24xx_parse_gpdb(vha, fcport, pd);
Quinn Tran726b8542017-01-19 22:28:00 -0800663
664gpd_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 Carnuccio25ff6af2017-01-19 22:28:04 -0800676 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800677}
678
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700679static 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
692static void
693qla2x00_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
722int
723qla24xx_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
771done_free_sp:
772 sp->free(sp);
773 fcport->flags &= ~FCF_ASYNC_SENT;
774 return rval;
775}
776
Quinn Tran726b8542017-01-19 22:28:00 -0800777static 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
791int 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 Carnuccioe0824e62017-08-23 15:05:08 -0700811 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 Tran726b8542017-01-19 22:28:00 -0800817 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
818 if (pd == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700819 ql_log(ql_log_warn, vha, 0xd043,
820 "Failed to allocate port database structure.\n");
Quinn Tran726b8542017-01-19 22:28:00 -0800821 goto done_free_sp;
822 }
823 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
824
Quinn Tran726b8542017-01-19 22:28:00 -0800825 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 Tran83548fe2017-06-02 09:12:01 -0700846 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 Tran726b8542017-01-19 22:28:00 -0800849
850 return rval;
851
852done_free_sp:
853 if (pd)
854 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
855
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800856 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800857done:
858 fcport->flags &= ~FCF_ASYNC_SENT;
859 qla24xx_post_gpdb_work(vha, fcport, opt);
860 return rval;
861}
862
863static
864void 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 Tran83548fe2017-06-02 09:12:01 -0700872 ql_dbg(ql_dbg_disc, vha, 0x20d2,
Quinn Tran726b8542017-01-19 22:28:00 -0800873 "%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 Tran83548fe2017-06-02 09:12:01 -0700878 ql_dbg(ql_dbg_disc, vha, 0x20d3,
Quinn Tran726b8542017-01-19 22:28:00 -0800879 "%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 Tran83548fe2017-06-02 09:12:01 -0700885 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
Quinn Tran726b8542017-01-19 22:28:00 -0800886 __func__, __LINE__, fcport->port_name);
887 qla24xx_post_gidpn_work(vha, fcport);
888 return;
889 }
890
891 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700892 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
Quinn Tran726b8542017-01-19 22:28:00 -0800893 __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 Tran83548fe2017-06-02 09:12:01 -0700909 ql_dbg(ql_dbg_disc, vha, 0x20d6,
Quinn Tran726b8542017-01-19 22:28:00 -0800910 "%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 Tran83548fe2017-06-02 09:12:01 -0700916 ql_dbg(ql_dbg_disc, vha, 0x20d7,
Quinn Tran726b8542017-01-19 22:28:00 -0800917 "%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
927int 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 Tran83548fe2017-06-02 09:12:01 -0700935 ql_dbg(ql_dbg_disc, vha, 0x20d8,
Quinn Tran726b8542017-01-19 22:28:00 -0800936 "%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 Tran726b8542017-01-19 22:28:00 -0800946 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
947 return 0;
948
Quinn Tran5b334692017-03-15 09:48:48 -0700949 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 Tran726b8542017-01-19 22:28:00 -0800954 /* 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 Tran83548fe2017-06-02 09:12:01 -0700966 ql_dbg(ql_dbg_disc, vha, 0x20bd,
967 "%s %d %8phC post gnl\n",
968 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800969 qla24xx_async_gnl(vha, fcport);
970 } else {
Quinn Tran83548fe2017-06-02 09:12:01 -0700971 ql_dbg(ql_dbg_disc, vha, 0x20bf,
972 "%s %d %8phC post login\n",
973 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800974 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 Tran83548fe2017-06-02 09:12:01 -0700990 ql_dbg(ql_dbg_disc, vha, 0x20c9,
991 "%s %d %8phC post gpdb\n",
992 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800993
994 fcport->disc_state = DSC_GPDB;
995 qla24xx_post_gpdb_work(vha, fcport, opt);
996 } else {
Quinn Tran83548fe2017-06-02 09:12:01 -0700997 ql_dbg(ql_dbg_disc, vha, 0x20cf,
998 "%s %d %8phC post login\n",
999 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -08001000 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 Tran83548fe2017-06-02 09:12:01 -07001007 ql_dbg(ql_dbg_disc, vha, 0x20d0,
1008 "%s %d %8phC post gidpn\n",
1009 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -08001010
1011 qla24xx_post_gidpn_work(vha, fcport);
1012 break;
1013
1014 case DSC_LOGIN_COMPLETE:
1015 /* recheck login state */
Quinn Tran83548fe2017-06-02 09:12:01 -07001016 ql_dbg(ql_dbg_disc, vha, 0x20d1,
1017 "%s %d %8phC post gpdb\n",
1018 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -08001019
1020 qla24xx_post_gpdb_work(vha, fcport, PDO_FORCE_ADISC);
1021 break;
1022
1023 default:
1024 break;
1025 }
1026
1027 return 0;
1028}
1029
1030static
1031void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea)
1032{
1033 fcport->rscn_gen++;
1034
Quinn Tran83548fe2017-06-02 09:12:01 -07001035 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 Tran726b8542017-01-19 22:28:00 -08001039
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
1054int 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
1069static
1070int 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
1094static
1095void 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 Tran83548fe2017-06-02 09:12:01 -07001105 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 Tran726b8542017-01-19 22:28:00 -08001113
1114 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
Quinn Tran726b8542017-01-19 22:28:00 -08001115 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1116 return;
1117
Quinn Tran5b334692017-03-15 09:48:48 -07001118 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 Tran726b8542017-01-19 22:28:00 -08001123 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 Tran83548fe2017-06-02 09:12:01 -07001135 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n",
Quinn Tran726b8542017-01-19 22:28:00 -08001136 __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 Tran41dc5292017-01-19 22:28:03 -08001145void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
Quinn Tran726b8542017-01-19 22:28:00 -08001146{
Quinn Tran41dc5292017-01-19 22:28:03 -08001147 fc_port_t *fcport, *f, *tf;
1148 uint32_t id = 0, mask, rid;
Quinn Tran726b8542017-01-19 22:28:00 -08001149 int rc;
1150
1151 switch (ea->event) {
1152 case FCME_RELOGIN:
Quinn Tranb98ae0d2017-06-02 09:12:00 -07001153 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 Tran726b8542017-01-19 22:28:00 -08001167 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 Tran41dc5292017-01-19 22:28:03 -08001175 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 Tran83548fe2017-06-02 09:12:01 -07001182 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 Tran41dc5292017-01-19 22:28:03 -08001186 }
1187 } else {
1188 ea->fcport = fcport;
1189 qla24xx_handle_rscn_event(fcport, ea);
Quinn Tran726b8542017-01-19 22:28:00 -08001190 }
Quinn Tran41dc5292017-01-19 22:28:03 -08001191 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 Tran83548fe2017-06-02 09:12:01 -07001196 ql_dbg(ql_dbg_async, vha, 0x5044,
1197 "RSCN: Area 0x%06x was affected\n",
1198 ea->id.b24);
Quinn Tran41dc5292017-01-19 22:28:03 -08001199 } else {
1200 mask = 0xff0000;
Quinn Tran83548fe2017-06-02 09:12:01 -07001201 ql_dbg(ql_dbg_async, vha, 0x507a,
1202 "RSCN: Domain 0x%06x was affected\n",
1203 ea->id.b24);
Quinn Tran41dc5292017-01-19 22:28:03 -08001204 }
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 Tran83548fe2017-06-02 09:12:01 -07001218 ql_log(ql_log_warn, vha, 0xd045,
1219 "RSCN: Fabric was affected. Addr format %d\n",
1220 ea->id.b.rsvd_1);
Quinn Tran41dc5292017-01-19 22:28:03 -08001221 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 Tran726b8542017-01-19 22:28:00 -08001224 }
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 Grigsbya5d42f42017-06-21 13:48:41 -07001238 case FCME_PRLI_DONE:
1239 qla24xx_handle_prli_done_event(vha, ea);
1240 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001241 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 Grigsbyd3bae932017-06-21 13:48:44 -07001247 case FCME_GFFID_DONE:
1248 qla24xx_handle_gffid_event(vha, ea);
1249 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001250 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 Iyengar38222632010-05-04 15:01:29 -07001259static void
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001260qla2x00_tmf_iocb_timeout(void *data)
1261{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001262 srb_t *sp = data;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001263 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
1269static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001270qla2x00_tmf_sp_done(void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001271{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001272 srb_t *sp = ptr;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001273 struct srb_iocb *tmf = &sp->u.iocb_cmd;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001274
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001275 complete(&tmf->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001276}
1277
1278int
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001279qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001280 uint32_t tag)
1281{
1282 struct scsi_qla_host *vha = fcport->vha;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001283 struct srb_iocb *tm_iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001284 srb_t *sp;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001285 int rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001286
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001287 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001288 if (!sp)
1289 goto done;
1290
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001291 tm_iocb = &sp->u.iocb_cmd;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001292 sp->type = SRB_TM_CMD;
1293 sp->name = "tmf";
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001294 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 Iyengar38222632010-05-04 15:01:29 -07001301
1302 rval = qla2x00_start_sp(sp);
1303 if (rval != QLA_SUCCESS)
1304 goto done_free_sp;
1305
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001306 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001307 "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 Baloyanfaef62d2014-02-26 04:15:17 -05001310
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 Iyengar38222632010-05-04 15:01:29 -07001330
1331done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001332 sp->free(sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001333done:
1334 return rval;
1335}
1336
Armen Baloyan4440e462014-02-26 04:15:18 -05001337static void
1338qla24xx_abort_iocb_timeout(void *data)
1339{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001340 srb_t *sp = data;
Armen Baloyan4440e462014-02-26 04:15:18 -05001341 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
1347static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001348qla24xx_abort_sp_done(void *ptr, int res)
Armen Baloyan4440e462014-02-26 04:15:18 -05001349{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001350 srb_t *sp = ptr;
Armen Baloyan4440e462014-02-26 04:15:18 -05001351 struct srb_iocb *abt = &sp->u.iocb_cmd;
1352
1353 complete(&abt->u.abt.comp);
1354}
1355
Quinn Tran15f30a52017-03-15 09:48:52 -07001356int
Armen Baloyan4440e462014-02-26 04:15:18 -05001357qla24xx_async_abort_cmd(srb_t *cmd_sp)
1358{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001359 scsi_qla_host_t *vha = cmd_sp->vha;
Armen Baloyan4440e462014-02-26 04:15:18 -05001360 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
1391done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001392 sp->free(sp);
Armen Baloyan4440e462014-02-26 04:15:18 -05001393done:
1394 return rval;
1395}
1396
1397int
1398qla24xx_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 Tran726b8542017-01-19 22:28:00 -08001425static void
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001426qla24xx_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
1446static void
Quinn Tran726b8542017-01-19 22:28:00 -08001447qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001448{
Quinn Tran726b8542017-01-19 22:28:00 -08001449 port_id_t cid; /* conflict Nport id */
Andrew Vasquezac280b62009-08-20 11:06:05 -07001450
Quinn Tran726b8542017-01-19 22:28:00 -08001451 switch (ea->data[0]) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07001452 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -07001453 /*
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 Grigsbya5d42f42017-06-21 13:48:41 -07001458 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 Vasquezac280b62009-08-20 11:06:05 -07001471 break;
1472 case MBS_COMMAND_ERROR:
Quinn Tran83548fe2017-06-02 09:12:01 -07001473 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
Quinn Tran726b8542017-01-19 22:28:00 -08001474 __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 Vasquezac280b62009-08-20 11:06:05 -07001479 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1480 else
Quinn Tran726b8542017-01-19 22:28:00 -08001481 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001482 break;
1483 case MBS_LOOP_ID_USED:
Quinn Tran726b8542017-01-19 22:28:00 -08001484 /* 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 Tran83548fe2017-06-02 09:12:01 -07001490 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 Tran726b8542017-01-19 22:28:00 -08001494
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 Vasquezac280b62009-08-20 11:06:05 -07001500 }
Quinn Tran726b8542017-01-19 22:28:00 -08001501 qla24xx_post_gnl_work(vha, ea->fcport);
1502 break;
1503 case MBS_PORT_ID_USED:
Quinn Tran83548fe2017-06-02 09:12:01 -07001504 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 Tran726b8542017-01-19 22:28:00 -08001509
1510 qla2x00_clear_loop_id(ea->fcport);
1511 qla24xx_post_gidpn_work(vha, ea->fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001512 break;
1513 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001514 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001515}
1516
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001517void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001518qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1519 uint16_t *data)
1520{
Quinn Tran726b8542017-01-19 22:28:00 -08001521 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Alexei Potashnika6ca8872015-07-14 16:00:44 -04001522 qlt_logo_completion_handler(fcport, data[0]);
Quinn Tran726b8542017-01-19 22:28:00 -08001523 fcport->login_gen++;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001524 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001525}
1526
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001527void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001528qla2x00_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 Iyengar49163922010-05-04 15:01:28 -07001534 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001535 }
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 Vasquez80d79442011-03-30 11:46:17 -07001542 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001543
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001544 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001545}
1546
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547/****************************************************************************/
1548/* QLogic ISP2x00 Hardware Support Functions. */
1549/****************************************************************************/
1550
Saurav Kashyapfa492632012-11-21 02:40:29 -05001551static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001552qla83xx_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 Kashyap711aa7f2012-08-22 14:21:15 -04001557 uint16_t config[4];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001558
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 Kashyap711aa7f2012-08-22 14:21:15 -04001609 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 Vernekar7d613ac2012-08-22 14:21:03 -04001616 rval = qla83xx_idc_state_handler(vha);
1617
1618exit:
1619 qla83xx_idc_unlock(vha, 0);
1620
1621 return rval;
1622}
1623
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624/*
1625* qla2x00_initialize_adapter
1626* Initialize board.
1627*
1628* Input:
1629* ha = adapter block pointer.
1630*
1631* Returns:
1632* 0 = success
1633*/
1634int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001635qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636{
1637 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001638 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001639 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001640
Joe Carnucciofc90ada2016-07-06 11:14:23 -04001641 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
1642 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
1643
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001645 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001646 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001647 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -08001648 ha->flags.pci_channel_io_perm_failure = 0;
1649 ha->flags.eeh_busy = 0;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -04001650 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001651 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 Torvalds1da177e2005-04-16 15:20:36 -07001657 ha->isp_abort_cnt = 0;
1658 ha->beacon_blink_led = 0;
1659
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001660 set_bit(0, ha->req_qid_map);
1661 set_bit(0, ha->rsp_qid_map);
1662
Chad Dupuiscfb09192011-11-18 09:03:07 -08001663 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001664 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001665 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001667 ql_log(ql_log_warn, vha, 0x0044,
1668 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 return (rval);
1670 }
1671
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001672 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001674 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001675 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001676 ql_log(ql_log_fatal, vha, 0x004f,
1677 "Unable to validate FLASH data.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001678 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 Vasquezc00d8992008-09-11 21:22:49 -07001690 }
1691
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001692 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001693 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001694 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001695
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001696 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001698 if (ha->flags.disable_serdes) {
1699 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001700 ql_log(ql_log_info, vha, 0x0077,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001701 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001702 return QLA_FUNCTION_FAILED;
1703 }
1704
Chad Dupuiscfb09192011-11-18 09:03:07 -08001705 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001706 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001708 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
1709 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001710 if (rval)
1711 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001712 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001713 if (rval)
1714 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07001716
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001717 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001718 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001719 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001720 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001721 "Unable to configure ISP84XX.\n");
1722 return QLA_FUNCTION_FAILED;
1723 }
1724 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001725
Quinn Tranead03852017-01-19 22:28:01 -08001726 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001727 rval = qla2x00_init_rings(vha);
1728
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001729 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001731 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001732 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001733 rval = qla84xx_init_chip(vha);
1734 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001735 ql_log(ql_log_warn, vha, 0x00d4,
1736 "Unable to initialize ISP84XX.\n");
Bart Van Assche8d2b21d2015-06-04 15:58:09 -07001737 qla84xx_put_chip(vha);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001738 }
1739 }
1740
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001741 /* 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 Iyengar2f0f3f42010-07-23 15:28:24 +05001749 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
1750 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -07001751
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04001752 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 Torvalds1da177e2005-04-16 15:20:36 -07001757 return (rval);
1758}
1759
1760/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001761 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 * @ha: HA context
1763 *
1764 * Returns 0 on success.
1765 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001766int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001767qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001769 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001770 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001771 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001772 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001775 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001778 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1780
Andrew Vasquez737faec2008-10-24 15:13:45 -07001781 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001783 /* Get PCI bus information. */
1784 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07001785 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001786 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 */
1797int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001798qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001799{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001800 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001801 unsigned long flags = 0;
1802 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001803 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001804 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001805
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001806 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001807 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001808
1809 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001810 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001811
1812 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1813 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -07001814 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001815
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 Vasquez3d716442005-07-06 10:30:26 -07001827 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001828 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07001829 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001830 break;
1831
1832 udelay(10);
1833 }
1834
1835 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001836 WRT_REG_WORD(&reg->ctrl_status, 0x20);
1837 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001838
1839 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001840 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001841
1842 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -07001843 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001844
1845 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001846 WRT_REG_WORD(&reg->ctrl_status, 0x0);
1847 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001848
1849 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001850 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001851 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07001852 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001853 break;
1854
1855 udelay(10);
1856 }
1857
1858 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1859 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001860
1861 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
1862
Andrew Vasquez737faec2008-10-24 15:13:45 -07001863 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001864
1865 /* Get PCI bus information. */
1866 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07001867 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001868 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1869
1870 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871}
1872
1873/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001874 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
1875 * @ha: HA context
1876 *
1877 * Returns 0 on success.
1878 */
1879int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001880qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001881{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001882 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001883 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001884 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001885 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001886
1887 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001888 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001889
1890 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001891 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001892 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 Vasquezf85ec182007-07-19 15:06:01 -07001898 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
1899 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001900
1901 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07001902 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04001903 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001904
Andrew Vasquez737faec2008-10-24 15:13:45 -07001905 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001906
Auke Kok44c10132007-06-08 15:46:36 -07001907 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001908
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001909 /* Get PCI bus information. */
1910 spin_lock_irqsave(&ha->hardware_lock, flags);
1911 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
1912 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1913
1914 return QLA_SUCCESS;
1915}
1916
1917/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001918 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
1919 * @ha: HA context
1920 *
1921 * Returns 0 on success.
1922 */
1923int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001924qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001925{
1926 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001927 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001928
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 Masone67f1322012-07-10 14:57:56 -07001938 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04001939 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001940
Andrew Vasquez737faec2008-10-24 15:13:45 -07001941 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001942
1943 ha->chip_revision = ha->pdev->revision;
1944
1945 return QLA_SUCCESS;
1946}
1947
1948/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 * qla2x00_isp_firmware() - Choose firmware image.
1950 * @ha: HA context
1951 *
1952 * Returns 0 on success.
1953 */
1954static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001955qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956{
1957 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001958 uint16_t loop_id, topo, sw_cap;
1959 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001960 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
1962 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001963 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964
1965 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001966 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967
1968 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001969 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001970 if (rval == QLA_SUCCESS) {
1971 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001972 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001973 &area, &domain, &topo, &sw_cap);
1974 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 }
1976
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001977 if (rval)
1978 ql_dbg(ql_dbg_init, vha, 0x007a,
1979 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980
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 Vasquezabbd8872005-07-06 10:30:05 -07001990void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001991qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992{
1993 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001994 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001995 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 uint16_t cmd;
1998
Andrew Vasquez85880802009-12-15 21:29:46 -08001999 if (unlikely(pci_channel_offline(ha->pdev)))
2000 return;
2001
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002002 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
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(&reg->hccr, HCCR_PAUSE_RISC);
2015 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2016 for (cnt = 0; cnt < 30000; cnt++) {
2017 if ((RD_REG_WORD(&reg->hccr) &
2018 HCCR_RISC_PAUSE) != 0)
2019 break;
2020 udelay(100);
2021 }
2022 } else {
2023 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2024 udelay(10);
2025 }
2026
2027 /* Select FPM registers. */
2028 WRT_REG_WORD(&reg->ctrl_status, 0x20);
2029 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2030
2031 /* FPM Soft Reset. */
2032 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
2033 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
2034
2035 /* Toggle Fpm Reset. */
2036 if (!IS_QLA2200(ha)) {
2037 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
2038 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
2039 }
2040
2041 /* Select frame buffer registers. */
2042 WRT_REG_WORD(&reg->ctrl_status, 0x10);
2043 RD_REG_WORD(&reg->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(&reg->ctrl_status, 0);
2062 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2063
2064 /* Reset RISC processor. */
2065 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2066 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2067
2068 /* Release RISC processor. */
2069 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2070 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2071 }
2072
2073 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
2074 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
2075
2076 /* Reset ISP chip. */
2077 WRT_REG_WORD(&reg->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(&reg->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(&reg->hccr, HCCR_RESET_RISC);
2098
2099 WRT_REG_WORD(&reg->semaphore, 0);
2100
2101 /* Release RISC processor. */
2102 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2103 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2104
2105 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2106 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -07002107 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109
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(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
2122 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2123 }
2124
2125 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2126}
2127
2128/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002129 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2130 *
2131 * Returns 0 on success.
2132 */
Saurav Kashyapfa492632012-11-21 02:40:29 -05002133static int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002134qla81xx_reset_mpi(scsi_qla_host_t *vha)
2135{
2136 uint16_t mb[4] = {0x1010, 0, 1, 0};
2137
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002138 if (!IS_QLA81XX(vha->hw))
2139 return QLA_SUCCESS;
2140
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002141 return qla81xx_write_mpi_register(vha, mb);
2142}
2143
2144/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002145 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002146 * @ha: HA context
2147 *
2148 * Returns 0 on success.
2149 */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002150static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002151qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002152{
2153 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002154 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002155 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Bart Van Assche52c82822015-07-09 07:23:26 -07002156 uint32_t cnt;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002157 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002158 static int abts_cnt; /* ISP abort retry counts */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002159 int rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002160
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002161 spin_lock_irqsave(&ha->hardware_lock, flags);
2162
2163 /* Reset RISC. */
2164 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2165 for (cnt = 0; cnt < 30000; cnt++) {
2166 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2167 break;
2168
2169 udelay(10);
2170 }
2171
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002172 if (!(RD_REG_DWORD(&reg->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(&reg->hccr),
2178 RD_REG_DWORD(&reg->ctrl_status),
2179 (RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE));
2180
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002181 WRT_REG_DWORD(&reg->ctrl_status,
2182 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002183 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002184
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002185 udelay(100);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002186
Andrew Vasquez88c26662005-07-08 17:59:26 -07002187 /* Wait for firmware to complete NVRAM accesses. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002188 RD_REG_WORD(&reg->mailbox0);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002189 for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
2190 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez88c26662005-07-08 17:59:26 -07002191 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002192 if (cnt)
2193 udelay(5);
2194 else
2195 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez88c26662005-07-08 17:59:26 -07002196 }
2197
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002198 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(&reg->hccr),
2204 RD_REG_DWORD(&reg->mailbox0));
2205
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002206 /* Wait for soft-reset to complete. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002207 RD_REG_DWORD(&reg->ctrl_status);
Quinn Tran200ffb12016-12-23 18:06:12 -08002208 for (cnt = 0; cnt < 60; cnt++) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002209 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002210 if ((RD_REG_DWORD(&reg->ctrl_status) &
2211 CSRX_ISP_SOFT_RESET) == 0)
2212 break;
2213
2214 udelay(5);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002215 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002216 if (!(RD_REG_DWORD(&reg->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(&reg->hccr),
2222 RD_REG_DWORD(&reg->ctrl_status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002223
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002224 /* 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 Vasquez0107109e2005-07-06 10:31:37 -07002241 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
2242 RD_REG_DWORD(&reg->hccr);
2243
2244 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
2245 RD_REG_DWORD(&reg->hccr);
2246
2247 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
2248 RD_REG_DWORD(&reg->hccr);
2249
Bart Van Assche52c82822015-07-09 07:23:26 -07002250 RD_REG_WORD(&reg->mailbox0);
Quinn Tran200ffb12016-12-23 18:06:12 -08002251 for (cnt = 60; RD_REG_WORD(&reg->mailbox0) != 0 &&
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002252 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002253 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002254 if (cnt)
2255 udelay(5);
2256 else
2257 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002258 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002259 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(&reg->hccr),
2265 RD_REG_WORD(&reg->mailbox0));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002266
2267 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002268
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002269 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 Vasquez124f85e2009-01-05 11:18:06 -08002273 if (IS_NOPOLLING_TYPE(ha))
2274 ha->isp_ops->enable_intrs(ha);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002275
2276 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002277}
2278
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002279static void
2280qla25xx_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(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2285 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2286
2287}
2288
2289static void
2290qla25xx_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(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2295 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2296}
2297
2298static void
2299qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2300{
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002301 uint32_t wd32 = 0;
2302 uint delta_msec = 100;
2303 uint elapsed_msec = 0;
2304 uint timeout_msec;
2305 ulong n;
2306
Joe Carnucciocc790762015-08-04 13:37:53 -04002307 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2308 vha->hw->pdev->subsystem_device != 0x0240)
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002309 return;
2310
Joe Carnuccio8dd7e3a2015-08-04 13:37:54 -04002311 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2312 udelay(100);
2313
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002314attempt:
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
2352force:
2353 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2354
2355acquired:
2356 return;
2357}
2358
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002359/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002360 * qla24xx_reset_chip() - Reset ISP24xx chip.
2361 * @ha: HA context
2362 *
2363 * Returns 0 on success.
2364 */
2365void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002366qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07002367{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002368 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08002369
2370 if (pci_channel_offline(ha->pdev) &&
2371 ha->flags.pci_channel_io_perm_failure) {
2372 return;
2373 }
2374
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002375 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002376
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002377 qla25xx_manipulate_risc_semaphore(vha);
2378
Andrew Vasquez88c26662005-07-08 17:59:26 -07002379 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002380 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002381}
2382
2383/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 * qla2x00_chip_diag() - Test chip for proper operation.
2385 * @ha: HA context
2386 *
2387 * Returns 0 on success.
2388 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002389int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002390qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391{
2392 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002393 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002394 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 unsigned long flags = 0;
2396 uint16_t data;
2397 uint32_t cnt;
2398 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002399 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400
2401 /* Assume a failed state */
2402 rval = QLA_FUNCTION_FAILED;
2403
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002404 ql_dbg(ql_dbg_init, vha, 0x007b,
2405 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
2407 spin_lock_irqsave(&ha->hardware_lock, flags);
2408
2409 /* Reset ISP chip. */
2410 WRT_REG_WORD(&reg->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(&reg->ctrl_status);
2418 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2419 udelay(5);
2420 data = RD_REG_WORD(&reg->ctrl_status);
2421 barrier();
2422 }
2423
2424 if (!cnt)
2425 goto chip_diag_failed;
2426
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002427 ql_dbg(ql_dbg_init, vha, 0x007c,
2428 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429
2430 /* Reset RISC processor. */
2431 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2432 WRT_REG_WORD(&reg->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 Vasquezfa2a1ce2005-07-06 10:32:07 -07002440 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 }
2442 } else
2443 udelay(10);
2444
2445 if (!cnt)
2446 goto chip_diag_failed;
2447
2448 /* Check product ID of chip */
Milan P Gandhi5a68a1c2017-03-31 14:37:04 -07002449 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
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 Kashyap7c3df132011-07-14 12:00:13 -07002457 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 Torvalds1da177e2005-04-16 15:20:36 -07002460
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 Chakraborty73208df2008-12-09 16:45:39 -08002469 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
2471 else
2472 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002473 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
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 Kashyap7c3df132011-07-14 12:00:13 -07002478 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002480 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 ha->fw_transfer_size = 128;
2482 }
2483
2484 /* Wrap Incoming Mailboxes Test. */
2485 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2486
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002487 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002488 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002489 if (rval)
2490 ql_log(ql_log_warn, vha, 0x0080,
2491 "Failed mailbox send register test.\n");
2492 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 /* Flag a successful rval */
2494 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 spin_lock_irqsave(&ha->hardware_lock, flags);
2496
2497chip_diag_failed:
2498 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002499 ql_log(ql_log_info, vha, 0x0081,
2500 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501
2502 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2503
2504 return (rval);
2505}
2506
2507/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002508 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2509 * @ha: HA context
2510 *
2511 * Returns 0 on success.
2512 */
2513int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002514qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002515{
2516 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002517 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002518 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002519
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002520 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07002521 return QLA_SUCCESS;
2522
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002523 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002524
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002525 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002526 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002527 ql_log(ql_log_warn, vha, 0x0082,
2528 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002529 } else {
2530 /* Flag a successful rval */
2531 rval = QLA_SUCCESS;
2532 }
2533
2534 return rval;
2535}
2536
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002537void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002538qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002539{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002540 int rval;
2541 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002542 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002543 dma_addr_t tc_dma;
2544 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002545 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002546 struct req_que *req = ha->req_q_map[0];
2547 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002548
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002549 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002550 ql_dbg(ql_dbg_init, vha, 0x00bd,
2551 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002552 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002553 }
2554
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002555 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04002556 ha->fw_dump_cap_flags = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002557 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 Vasqueza7a167b2006-06-23 16:10:29 -07002563 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 Vasqueze4289242007-07-19 15:05:56 -07002569 } else if (IS_FWI2_CAPABLE(ha)) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002570 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002571 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
2572 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002573 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 Dupuisf73cb692014-02-26 04:15:06 -05002578
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002579 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
2580 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002581 if (ha->mqenable) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002582 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002583 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002584 /*
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 Easi00876ae2013-03-25 02:21:37 -04002593 if (ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002594 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002595 /* Allocate memory for Fibre Channel Event Buffer. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05002596 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2597 !IS_QLA27XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002598 goto try_eft;
2599
Chad Dupuisf73cb692014-02-26 04:15:06 -05002600try_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 Perches0ea85b52014-06-15 13:37:51 -07002606 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
2607 GFP_KERNEL);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002608 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002609 ql_log(ql_log_warn, vha, 0x00be,
2610 "Unable to allocate (%d KB) for FCE.\n",
2611 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002612 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002613 }
2614
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002615 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002616 ha->fce_mb, &ha->fce_bufs);
2617 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002618 ql_log(ql_log_warn, vha, 0x00bf,
2619 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002620 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
2621 tc_dma);
2622 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002623 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002624 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002625 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002626 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002627
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07002628 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002629 ha->flags.fce_enabled = 1;
2630 ha->fce_dma = tc_dma;
2631 ha->fce = tc;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002632
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002633try_eft:
Chad Dupuisf73cb692014-02-26 04:15:06 -05002634 if (ha->eft)
2635 dma_free_coherent(&ha->pdev->dev,
2636 EFT_SIZE, ha->eft, ha->eft_dma);
2637
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002638 /* Allocate memory for Extended Trace Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07002639 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
2640 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002641 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002642 ql_log(ql_log_warn, vha, 0x00c1,
2643 "Unable to allocate (%d KB) for EFT.\n",
2644 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002645 goto cont_alloc;
2646 }
2647
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002648 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002649 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002650 ql_log(ql_log_warn, vha, 0x00c2,
2651 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002652 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
2653 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002654 goto cont_alloc;
2655 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002656 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002657 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002658
2659 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002660 ha->eft_dma = tc_dma;
2661 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002662 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05002663
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002664cont_alloc:
Chad Dupuisf73cb692014-02-26 04:15:06 -05002665 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 Chakraborty73208df2008-12-09 16:45:39 -08002677 req_q_size = req->length * sizeof(request_t);
2678 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002679 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002680 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08002681 ha->chain_offset = dump_size;
2682 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002683
Quinn Tranb945e772017-06-13 20:47:29 -07002684 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 Dupuisf73cb692014-02-26 04:15:06 -05002691allocate:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002692 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002693 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002694 ql_log(ql_log_warn, vha, 0x00c4,
2695 "Unable to allocate (%d KB) for firmware dump.\n",
2696 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002697
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002698 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 Vasqueza7a167b2006-06-23 16:10:29 -07002705 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 Dupuisf73cb692014-02-26 04:15:06 -05002713 ha->fw_dump_len = dump_size;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002714 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002715 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002716
Chad Dupuisf73cb692014-02-26 04:15:06 -05002717 if (IS_QLA27XX(ha))
2718 return;
2719
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002720 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 Asschead950362015-07-09 07:24:08 -07002724 ha->fw_dump->version = htonl(1);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002725
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 Vasquez0107109e2005-07-06 10:31:37 -07002737}
2738
Andrew Vasquez18e75552009-06-03 09:55:30 -07002739static int
2740qla81xx_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 Vasquez18e75552009-06-03 09:55:30 -07002746
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 Kashyap7c3df132011-07-14 12:00:13 -07002752 ql_log(ql_log_warn, vha, 0x0105,
2753 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002754 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 Kashyap7c3df132011-07-14 12:00:13 -07002760 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002761 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 Kashyap7c3df132011-07-14 12:00:13 -07002772 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002773 }
2774
2775done_release:
2776 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
2777 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002778 ql_log(ql_log_warn, vha, 0x006d,
2779 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002780 }
2781
2782done:
2783 return rval;
2784}
2785
Chad Dupuis8d93f552013-01-30 03:34:37 -05002786int
2787qla2x00_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 Hernandezd7459522016-12-12 14:40:07 -08002793 if (!IS_FWI2_CAPABLE(ha))
Chad Dupuis8d93f552013-01-30 03:34:37 -05002794 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
2795 else {
Quinn Tran03e8c682015-12-17 14:56:59 -05002796 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
2797 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002798 else
Quinn Tran03e8c682015-12-17 14:56:59 -05002799 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002800 }
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 Trane4e3a2c2017-08-23 15:05:07 -07002826#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
2840static 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 */
2924int
2925qla24xx_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;
2963out:
2964 return rc;
2965}
2966
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002967/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 * qla2x00_setup_chip() - Load and start RISC firmware.
2969 * @ha: HA context
2970 *
2971 * Returns 0 on success.
2972 */
2973static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002974qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002976 int rval;
2977 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002978 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08002979 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2980 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07002981 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08002982
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002983 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002984 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05002985 if (rval == QLA_SUCCESS) {
2986 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002987 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05002988 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07002989 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002990 }
2991
Andrew Vasquez3db06522008-01-31 12:33:49 -08002992 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(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
2996 RD_REG_WORD(&reg->hccr);
2997 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2998 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999
Andrew Vasquez18e75552009-06-03 09:55:30 -07003000 qla81xx_mpi_sync(vha);
3001
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003003 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003004 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003005 ql_dbg(ql_dbg_init, vha, 0x00c9,
3006 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003008 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 if (rval == QLA_SUCCESS) {
3010 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003011 ql_dbg(ql_dbg_init, vha, 0x00ca,
3012 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003014 if (ql2xexlogins)
3015 ha->flags.exlogins_enabled = 1;
3016
Quinn Tran99e1b682017-06-02 09:12:03 -07003017 if (qla_is_exch_offld_enabled(vha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003018 ha->flags.exchoffld_enabled = 1;
3019
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003020 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07003022 if (rval == QLA_SUCCESS) {
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003023 qla24xx_detect_sfp(vha);
3024
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003025 rval = qla2x00_set_exlogins_buffer(vha);
3026 if (rval != QLA_SUCCESS)
3027 goto failed;
3028
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003029 rval = qla2x00_set_exchoffld_buffer(vha);
3030 if (rval != QLA_SUCCESS)
3031 goto failed;
3032
Giridhar Malavalia9083012010-04-12 17:59:55 -07003033enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07003034 fw_major_version = ha->fw_major_version;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003035 if (IS_P3P_TYPE(ha))
Giridhar Malavali31731672011-08-16 11:31:54 -07003036 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003037 else
3038 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07003039 if (rval != QLA_SUCCESS)
3040 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003041 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003042 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07003043 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003044 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003045 if ((!ha->max_npiv_vports) ||
3046 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003047 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003048 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003049 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003050 }
Quinn Tran03e8c682015-12-17 14:56:59 -05003051 qla2x00_get_resource_cnts(vha);
Andrew Vasquezd743de62009-03-24 09:08:15 -07003052
Chad Dupuis8d93f552013-01-30 03:34:37 -05003053 /*
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 Kashyapbe5ea3c2011-11-18 09:02:11 -08003062 if (!fw_major_version && ql2xallocfwdump
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003063 && !(IS_P3P_TYPE(ha)))
Giridhar Malavali08de2842011-08-16 11:31:44 -07003064 qla2x00_alloc_fw_dump(vha);
Chad Dupuis3b6e5b92013-10-30 03:38:09 -04003065 } else {
3066 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 }
3068 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003069 ql_log(ql_log_fatal, vha, 0x00cd,
3070 "ISP Firmware failed checksum.\n");
3071 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04003073 } else
3074 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075
Andrew Vasquez3db06522008-01-31 12:33:49 -08003076 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(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
3082 else
3083 /* SRAM, Instruction RAM and GP RAM parity */
3084 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
3085 RD_REG_WORD(&reg->hccr);
3086 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3087 }
3088
Chad Dupuisf3982d82014-09-25 05:16:57 -04003089 if (IS_QLA27XX(ha))
3090 ha->flags.fac_supported = 1;
3091 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003092 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 Kashyap7c3df132011-07-14 12:00:13 -07003099 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003100 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3101 ha->fw_major_version, ha->fw_minor_version,
3102 ha->fw_subminor_version);
Joe Carnuccio1ca60e32014-02-26 04:15:02 -05003103
Chad Dupuisf73cb692014-02-26 04:15:06 -05003104 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003105 ha->flags.fac_supported = 0;
3106 rval = QLA_SUCCESS;
3107 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003108 }
3109 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07003110failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003112 ql_log(ql_log_fatal, vha, 0x00cf,
3113 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 }
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 Chakraborty73208df2008-12-09 16:45:39 -08003128void
3129qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130{
3131 uint16_t cnt;
3132 response_t *pkt;
3133
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003134 rsp->ring_ptr = rsp->ring;
3135 rsp->ring_index = 0;
3136 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003137 pkt = rsp->ring_ptr;
3138 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 pkt->signature = RESPONSE_PROCESSED;
3140 pkt++;
3141 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142}
3143
3144/**
3145 * qla2x00_update_fw_options() - Read and process firmware options.
3146 * @ha: HA context
3147 *
3148 * Returns 0 on success.
3149 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003150void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003151qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152{
3153 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003154 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155
3156 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003157 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158
3159 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3160 return;
3161
3162 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003163 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 Torvalds1da177e2005-04-16 15:20:36 -07003168
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 Vasquezfa2a1ce2005-07-06 10:32:07 -07003178 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 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 Vasquezfa2a1ce2005-07-06 10:32:07 -07003196 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 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.com48c02fd2006-03-09 14:27:18 -08003218 /* Detect ISP6312. */
3219 if (IS_QLA6312(ha))
3220 ha->fw_options[2] |= BIT_13;
3221
Giridhar Malavali088d09d2016-07-06 11:14:20 -04003222 /* 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 Torvalds1da177e2005-04-16 15:20:36 -07003230 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003231 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232}
3233
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003234void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003235qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003236{
3237 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003238 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003239
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003240 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07003241 return;
3242
Himanshu Madhanif198caf2016-01-27 12:03:30 -05003243 /* Hold status IOCBs until ABTS response received. */
3244 if (ql2xfwholdabts)
3245 ha->fw_options[3] |= BIT_12;
3246
Giridhar Malavali088d09d2016-07-06 11:14:20 -04003247 /* 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 Tran41dc5292017-01-19 22:28:03 -08003255 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
Quinn Tran3c4810f2017-06-02 09:11:53 -07003256 if (ql2xmvasynctoatio &&
3257 (IS_QLA83XX(ha) || IS_QLA27XX(ha))) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003258 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 Tranf7e761f2017-06-02 09:12:02 -07003265 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 Tran83548fe2017-06-02 09:12:01 -07003277 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 Tran3c4810f2017-06-02 09:11:53 -07003281
3282 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3283 qla2x00_set_fw_options(vha, ha->fw_options);
Quinn Tran41dc5292017-01-19 22:28:03 -08003284
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003285 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08003286 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003287 return;
3288
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003289 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08003290 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 Vasquez0107109e2005-07-06 10:31:37 -07003293 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003294 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003295 "Unable to update Serial Link options (%x).\n", rval);
3296 }
3297}
3298
3299void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003300qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003301{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003302 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003303 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003304 struct req_que *req = ha->req_q_map[0];
3305 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003306
3307 /* Setup ring parameters in initialization control block. */
Bart Van Asschead950362015-07-09 07:24:08 -07003308 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3309 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003310 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 Vasquezabbd8872005-07-06 10:30:05 -07003316
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 Vasquez0107109e2005-07-06 10:31:37 -07003324void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003325qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003326{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003327 struct qla_hw_data *ha = vha->hw;
Bart Van Assche118e2ef2015-07-09 07:24:27 -07003328 device_reg_t *reg = ISP_QUE_REG(ha, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003329 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3330 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003331 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003332 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 Vasquez0107109e2005-07-06 10:31:37 -07003335
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003336 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003337 icb = (struct init_cb_24xx *)ha->init_cb;
Bart Van Asschead950362015-07-09 07:24:08 -07003338 icb->request_q_outpointer = cpu_to_le16(0);
3339 icb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003340 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 Vasquez0107109e2005-07-06 10:31:37 -07003346
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003347 /* Setup ATIO queue dma pointers for target mode */
Bart Van Asschead950362015-07-09 07:24:08 -07003348 icb->atio_q_inpointer = cpu_to_le16(0);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003349 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 Carnuccio7c6300e2014-04-11 16:54:37 -04003353 if (IS_SHADOW_REG_CAPABLE(ha))
Bart Van Asschead950362015-07-09 07:24:08 -07003354 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003355
Chad Dupuisf73cb692014-02-26 04:15:06 -05003356 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003357 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3358 icb->rid = cpu_to_le16(rid);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003359 if (ha->flags.msix_enabled) {
3360 msix = &ha->msix_entries[1];
Quinn Tran83548fe2017-06-02 09:12:01 -07003361 ql_dbg(ql_dbg_init, vha, 0x0019,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003362 "Registering vector 0x%x for base que.\n",
3363 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003364 icb->msix = cpu_to_le16(msix->entry);
3365 }
3366 /* Use alternate PCI bus number */
3367 if (MSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003368 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003369 /* Use alternate PCI devfn */
3370 if (LSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003371 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003372
Anirban Chakraborty31557542009-12-02 10:36:55 -08003373 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003374 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
3375 (ha->flags.msix_enabled)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003376 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003377 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003378 ql_dbg(ql_dbg_init, vha, 0x00fe,
3379 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08003380 } else {
Bart Van Asschead950362015-07-09 07:24:08 -07003381 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003382 }
Bart Van Asschead950362015-07-09 07:24:08 -07003383 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003384
3385 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
3386 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
3387 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
3388 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
3389 } else {
3390 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
3391 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
3392 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
3393 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
3394 }
Arun Easiaa230bc2013-01-30 03:34:39 -05003395 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003396
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003397 /* PCI posting */
3398 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003399}
3400
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401/**
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 Malavali8ae6d9c2013-03-28 08:21:23 -04003410int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003411qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412{
3413 int rval;
3414 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003415 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003416 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003417 struct req_que *req;
3418 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003419 struct mid_init_cb_24xx *mid_init_cb =
3420 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421
3422 spin_lock_irqsave(&ha->hardware_lock, flags);
3423
3424 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003425 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003426 req = ha->req_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003427 if (!req || !test_bit(que, ha->req_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003428 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003429 req->out_ptr = (void *)(req->ring + req->length);
3430 *req->out_ptr = 0;
Chad Dupuis8d93f552013-01-30 03:34:37 -05003431 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003432 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003434 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003435
3436 /* Initialize firmware. */
3437 req->ring_ptr = req->ring;
3438 req->ring_index = 0;
3439 req->cnt = req->length;
3440 }
3441
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003442 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003443 rsp = ha->rsp_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003444 if (!rsp || !test_bit(que, ha->rsp_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003445 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003446 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
3447 *rsp->in_ptr = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003448 /* Initialize response queue entries */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003449 if (IS_QLAFX00(ha))
3450 qlafx00_init_response_q_entries(rsp);
3451 else
3452 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003453 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003455 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 Chakrabortye315cd22008-11-06 10:40:51 -08003460 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461
3462 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3463
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003464 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 Torvalds1da177e2005-04-16 15:20:36 -07003471 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003472 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003474 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04003475 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003476 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08003477 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003478 }
3479
Andrew Vasquez24a08132009-03-24 09:08:16 -07003480 if (IS_FWI2_CAPABLE(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003481 mid_init_cb->options = cpu_to_le16(BIT_1);
Andrew Vasquez24a08132009-03-24 09:08:16 -07003482 mid_init_cb->init_cb.execution_throttle =
Quinn Tran03e8c682015-12-17 14:56:59 -05003483 cpu_to_le16(ha->cur_fw_xcb_count);
Joe Carnuccio40f38622016-07-06 11:14:28 -04003484 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 Madhani2486c622014-09-25 05:17:00 -04003489 ha->flags.fawwpn_enabled =
Joe Carnuccio40f38622016-07-06 11:14:28 -04003490 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
Quinn Tran83548fe2017-06-02 09:12:01 -07003491 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
Himanshu Madhani2486c622014-09-25 05:17:00 -04003492 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
Andrew Vasquez24a08132009-03-24 09:08:16 -07003493 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003494
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003495 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003496next_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003498 ql_log(ql_log_fatal, vha, 0x00d2,
3499 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003501 ql_dbg(ql_dbg_init, vha, 0x00d3,
3502 "Init Firmware -- success.\n");
Quinn Tran4b60c822017-06-13 20:47:21 -07003503 QLA_FW_STARTED(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 }
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 */
3515static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003516qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517{
3518 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003519 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 uint16_t min_wait; /* Minimum wait time if loop is down */
3521 uint16_t wait_time; /* Wait time if loop is coming ready */
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003522 uint16_t state[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003523 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003525 if (IS_QLAFX00(vha->hw))
3526 return qlafx00_fw_ready(vha);
3527
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 rval = QLA_SUCCESS;
3529
Chad Dupuis334614912015-04-09 14:59:57 -04003530 /* Time to wait for loop down */
3531 if (IS_P3P_TYPE(ha))
3532 min_wait = 30;
3533 else
3534 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535
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 Chakrabortye315cd22008-11-06 10:40:51 -08003551 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003552 ql_log(ql_log_info, vha, 0x801e,
3553 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554
3555 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05003556 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003557 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003559 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003560 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003562 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003563 ql_dbg(ql_dbg_taskm, vha, 0x801f,
3564 "fw_state=%x 84xx=%x.\n", state[0],
3565 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003566 if ((state[2] & FSTATE_LOGGED_IN) &&
3567 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003568 ql_dbg(ql_dbg_taskm, vha, 0x8028,
3569 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003570
3571 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003572 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003573 if (rval != QLA_SUCCESS) {
3574 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08003575 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003576 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003577 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003578 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003579
3580 /* Add time taken to initialize. */
3581 cs84xx_time = jiffies - cs84xx_time;
3582 wtime += cs84xx_time;
3583 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08003584 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003585 "Increasing wait time by %ld. "
3586 "New time %ld.\n", cs84xx_time,
3587 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003588 }
3589 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003590 ql_dbg(ql_dbg_taskm, vha, 0x8037,
3591 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003593 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594 &ha->login_timeout, &ha->r_a_tov);
3595
3596 rval = QLA_SUCCESS;
3597 break;
3598 }
3599
3600 rval = QLA_FUNCTION_FAILED;
3601
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003602 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003603 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003605 * other than Wait for Login.
3606 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003608 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609 "Cable is unplugged...\n");
3610
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003611 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612 break;
3613 }
3614 }
3615 } else {
3616 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07003617 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08003618 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619 break;
3620 }
3621
3622 if (time_after_eq(jiffies, wtime))
3623 break;
3624
3625 /* Delay for a while */
3626 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627 } while (1);
3628
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003629 ql_dbg(ql_dbg_taskm, vha, 0x803a,
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003630 "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 Torvalds1da177e2005-04-16 15:20:36 -07003632
Chad Dupuiscfb09192011-11-18 09:03:07 -08003633 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003634 ql_log(ql_log_warn, vha, 0x803b,
3635 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636 }
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*/
3654static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003655qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656{
3657 int rval;
3658 uint16_t loop_id;
3659 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003660 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661 uint8_t al_pa;
3662 uint8_t area;
3663 uint8_t domain;
3664 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003665 struct qla_hw_data *ha = vha->hw;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003666 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003667 port_id_t id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668
3669 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003670 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003671 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003673 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003674 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08003675 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003676 ql_dbg(ql_dbg_disc, vha, 0x2008,
3677 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08003678 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003679 ql_log(ql_log_warn, vha, 0x2009,
3680 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003681 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 Chakrabortye315cd22008-11-06 10:40:51 -08003688 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08003689 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690 return (rval);
3691 }
3692
3693 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003694 ql_log(ql_log_info, vha, 0x200a,
3695 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 return (QLA_FUNCTION_FAILED);
3697 }
3698
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003699 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700
3701 /* initialize */
3702 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
3703 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003704 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705
3706 switch (topo) {
3707 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003708 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709 ha->current_topology = ISP_CFG_NL;
3710 strcpy(connect_type, "(Loop)");
3711 break;
3712
3713 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003714 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003715 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 ha->current_topology = ISP_CFG_FL;
3717 strcpy(connect_type, "(FL_Port)");
3718 break;
3719
3720 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003721 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 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 Kashyap7c3df132011-07-14 12:00:13 -07003728 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003729 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 ha->operating_mode = P2P;
3731 ha->current_topology = ISP_CFG_F;
3732 strcpy(connect_type, "(F_Port)");
3733 break;
3734
3735 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003736 ql_dbg(ql_dbg_disc, vha, 0x200f,
3737 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 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 Tran482c9dc2017-03-15 09:48:54 -07003745 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 Bellinger2d70c102012-05-15 14:34:28 -04003750
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003751 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003752 ql_log(ql_log_info, vha, 0x2010,
3753 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003754 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756 return(rval);
3757}
3758
Giridhar Malavalia9083012010-04-12 17:59:55 -07003759inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003760qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
3761 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003762{
3763 char *st, *en;
3764 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003765 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07003766 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003767 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003768
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 Vasquez7d0dba12009-04-06 22:33:45 -07003780 if (use_tbl &&
3781 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003782 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003783 strncpy(ha->model_desc,
3784 qla2x00_model_name[index * 2 + 1],
3785 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003786 } else {
3787 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07003788 if (use_tbl &&
3789 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003790 index < QLA_MODEL_NAMES) {
3791 strcpy(ha->model_number,
3792 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003793 strncpy(ha->model_desc,
3794 qla2x00_model_name[index * 2 + 1],
3795 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003796 } else {
3797 strcpy(ha->model_number, def);
3798 }
3799 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003800 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003801 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003802 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003803}
3804
David Miller4e08df32007-04-16 12:37:43 -07003805/* On sparc systems, obtain port and node WWN from firmware
3806 * properties.
3807 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003808static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07003809{
3810#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003811 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003812 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003813 struct device_node *dp = pci_device_to_OF_node(pdev);
3814 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003815 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 Torvalds1da177e2005-04-16 15:20:36 -07003827/*
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 Vasquezabbd8872005-07-06 10:30:05 -07003840int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003841qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842{
David Miller4e08df32007-04-16 12:37:43 -07003843 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003844 uint8_t chksum = 0;
3845 uint16_t cnt;
3846 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003847 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003848 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003849 nvram_t *nv = ha->nvram;
3850 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003851 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852
David Miller4e08df32007-04-16 12:37:43 -07003853 rval = QLA_SUCCESS;
3854
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003856 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857 ha->nvram_base = 0;
3858 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
3859 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
3860 ha->nvram_base = 0x80;
3861
3862 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003863 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003864 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
3865 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003867 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 Torvalds1da177e2005-04-16 15:20:36 -07003871
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 Kashyap7c3df132011-07-14 12:00:13 -07003876 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04003877 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003878 "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 Miller4e08df32007-04-16 12:37:43 -07003883
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 Carnuccio98aee702014-09-25 05:16:38 -04003895 nv->frame_payload_size = 2048;
David Miller4e08df32007-04-16 12:37:43 -07003896 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 Carnuccio98aee702014-09-25 05:16:38 -04003902 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07003903 } else if (IS_QLA2100(ha)) {
3904 nv->firmware_options[0] = BIT_3 | BIT_1;
3905 nv->firmware_options[1] = BIT_5;
Joe Carnuccio98aee702014-09-25 05:16:38 -04003906 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07003907 }
3908
Bart Van Asschead950362015-07-09 07:24:08 -07003909 nv->max_iocb_allocation = cpu_to_le16(256);
3910 nv->execution_throttle = cpu_to_le16(16);
David Miller4e08df32007-04-16 12:37:43 -07003911 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 Chakrabortye315cd22008-11-06 10:40:51 -08003918 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003919
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 Asschead950362015-07-09 07:24:08 -07003928 nv->max_luns_per_target = cpu_to_le16(8);
David Miller4e08df32007-04-16 12:37:43 -07003929 nv->link_down_timeout = 60;
3930
3931 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932 }
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 Carnuccio98aee702014-09-25 05:16:38 -04003942 nv->frame_payload_size = 2048;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 if (IS_QLA23XX(ha))
3944 nv->special_options[1] = BIT_7;
3945 }
3946#endif
3947
3948 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003949 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950
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 Bellinger2d70c102012-05-15 14:34:28 -04003962 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003963 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964
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 Chakrabortye315cd22008-11-06 10:40:51 -08003972 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003973 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974 }
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 Vasquez5341e862006-05-17 15:09:16 -07004007 /* 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 Torvalds1da177e2005-04-16 15:20:36 -07004013 /* 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 Kashyap3ce88662011-07-14 12:00:12 -07004026
4027 /*
4028 * BIT_7 in the host-parameters section allows for modification to
4029 * internal driver logging.
4030 */
Andrew Vasquez01819442006-06-23 16:11:10 -07004031 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08004032 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 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 Vasquez06c22bd2005-08-26 19:09:00 -07004040 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004041 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042
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 Chakrabortye315cd22008-11-06 10:40:51 -08004053 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4054 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055
Bart Van Asschead950362015-07-09 07:24:08 -07004056 icb->execution_throttle = cpu_to_le16(0xFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057
4058 ha->retry_count = nv->retry_count;
4059
4060 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07004061 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062 nv->login_timeout = ql2xlogintimeout;
4063 if (nv->login_timeout < 4)
4064 nv->login_timeout = 4;
4065 ha->login_timeout = nv->login_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004067 /* Set minimum RATOV to 100 tenths of a second. */
4068 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 ha->loop_reset_delay = nv->reset_delay;
4071
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072 /* 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 Vasquezfa2a1ce2005-07-06 10:32:07 -07004081 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 if (nv->link_down_timeout == 0) {
4083 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004084 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 } 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 Vasquezfa2a1ce2005-07-06 10:32:07 -07004089 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 /*
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 Asschead950362015-07-09 07:24:08 -07004107 icb->lun_enables = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004108 icb->command_resource_count = 0;
4109 icb->immediate_notify_resource_count = 0;
Bart Van Asschead950362015-07-09 07:24:08 -07004110 icb->timeout = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111
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 Chakrabortye315cd22008-11-06 10:40:51 -08004121 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004123 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004124 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004125 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 Torvalds1da177e2005-04-16 15:20:36 -07004130 icb->add_firmware_options[0] &=
4131 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004132 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004133 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004134 ha->zio_mode = QLA_ZIO_MODE_6;
4135
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004136 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004137 "ZIO mode %d enabled; timer delay (%d us).\n",
4138 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004140 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4141 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004142 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 }
4144 }
4145
David Miller4e08df32007-04-16 12:37:43 -07004146 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004147 ql_log(ql_log_warn, vha, 0x0069,
4148 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07004149 }
4150 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151}
4152
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004153static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004154qla2x00_rport_del(void *data)
4155{
4156 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004157 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004158 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004159
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004160 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004161 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004162 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004163 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004164 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004165 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 Tran726b8542017-01-19 22:28:00 -08004169
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004170 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08004171 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004172}
4173
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174/**
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 Malavali9a069e12010-01-12 13:02:47 -08004181fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004182qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183{
4184 fc_port_t *fcport;
4185
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004186 fcport = kzalloc(sizeof(fc_port_t), flags);
4187 if (!fcport)
4188 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004189
4190 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004191 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192 fcport->port_type = FCT_UNKNOWN;
4193 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07004194 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004195 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196
Quinn Tran726b8542017-01-19 22:28:00 -08004197 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 Tran6cb32162017-02-13 12:18:29 -08004199 flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004200 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 Tran83548fe2017-06-02 09:12:01 -07004208 ql_log(ql_log_warn, vha, 0xd049,
Quinn Tran726b8542017-01-19 22:28:00 -08004209 "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 Kozlowskibbfbbbc2007-08-11 10:13:24 +02004217 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218}
4219
Quinn Tran726b8542017-01-19 22:28:00 -08004220void
4221qla2x00_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 Torvalds1da177e2005-04-16 15:20:36 -07004233/*
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 */
4245static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004246qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247{
4248 int rval;
4249 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004250 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004251 rval = QLA_SUCCESS;
4252
4253 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004254 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4255 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004257 ql_dbg(ql_dbg_disc, vha, 0x2013,
4258 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004259 return (rval);
4260 }
4261 }
4262
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004263 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004264 ql_dbg(ql_dbg_disc, vha, 0x2014,
4265 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004266
4267 /*
4268 * If we have both an RSCN and PORT UPDATE pending then handle them
4269 * both at the same time.
4270 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004271 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4272 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273
Michael Hernandez3064ff32009-12-15 21:29:44 -08004274 qla2x00_get_data_rate(vha);
4275
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276 /* Determine what we need to do */
4277 if (ha->current_topology == ISP_CFG_FL &&
4278 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4279
Linus Torvalds1da177e2005-04-16 15:20:36 -07004280 set_bit(RSCN_UPDATE, &flags);
4281
4282 } else if (ha->current_topology == ISP_CFG_F &&
4283 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4284
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285 set_bit(RSCN_UPDATE, &flags);
4286 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4287
Andrew Vasquez21333b42006-05-17 15:09:56 -07004288 } else if (ha->current_topology == ISP_CFG_N) {
4289 clear_bit(RSCN_UPDATE, &flags);
Quinn Tran41dc5292017-01-19 22:28:03 -08004290 } else if (ha->current_topology == ISP_CFG_NL) {
4291 clear_bit(RSCN_UPDATE, &flags);
4292 set_bit(LOCAL_LOOP_UPDATE, &flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004293 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295 set_bit(RSCN_UPDATE, &flags);
4296 set_bit(LOCAL_LOOP_UPDATE, &flags);
4297 }
4298
4299 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004300 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4301 ql_dbg(ql_dbg_disc, vha, 0x2015,
4302 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08004304 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004305 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306 }
4307
4308 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004309 if (LOOP_TRANSITION(vha)) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004310 ql_dbg(ql_dbg_disc, vha, 0x2099,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004311 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004313 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004314 else
4315 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 }
4317
4318 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004319 if (atomic_read(&vha->loop_down_timer) ||
4320 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321 rval = QLA_FUNCTION_FAILED;
4322 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004323 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004324 ql_dbg(ql_dbg_disc, vha, 0x2069,
4325 "LOOP READY.\n");
Quinn Tranec7193e2017-03-15 09:48:55 -07004326 ha->flags.fw_init_done = 1;
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05004327
4328 /*
4329 * Process any ATIO queue entries that came in
4330 * while we weren't online.
4331 */
Quinn Tranead03852017-01-19 22:28:01 -08004332 if (qla_tgt_mode_enabled(vha) ||
4333 qla_dual_mode_enabled(vha)) {
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05004334 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 Torvalds1da177e2005-04-16 15:20:36 -07004348 }
4349 }
4350
4351 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004352 ql_dbg(ql_dbg_disc, vha, 0x206a,
4353 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004355 ql_dbg(ql_dbg_disc, vha, 0x206b,
4356 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357 }
4358
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07004359 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004360 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004362 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004363 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004364 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366 }
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 */
4383static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004384qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385{
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 Chakrabortye315cd22008-11-06 10:40:51 -08004396 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08004397 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398
4399 found_devs = 0;
4400 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08004401 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402
Linus Torvalds1da177e2005-04-16 15:20:36 -07004403 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08004404 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004405 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406 &entries);
4407 if (rval != QLA_SUCCESS)
4408 goto cleanup_allocation;
4409
Quinn Tran83548fe2017-06-02 09:12:01 -07004410 ql_dbg(ql_dbg_disc, vha, 0x2011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004411 "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 Torvalds1da177e2005-04-16 15:20:36 -07004415
4416 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004417 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004418 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004419 ql_log(ql_log_warn, vha, 0x2012,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004420 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 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 Chakrabortye315cd22008-11-06 10:40:51 -08004429 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430 if (atomic_read(&fcport->state) == FCS_ONLINE &&
4431 fcport->port_type != FCT_BROADCAST &&
4432 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
4433
Quinn Tran83548fe2017-06-02 09:12:01 -07004434 ql_dbg(ql_dbg_disc, vha, 0x2096,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004435 "Marking port lost loop_id=0x%04x.\n",
4436 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004437
Quinn Tran41dc5292017-01-19 22:28:03 -08004438 qla2x00_mark_device_lost(vha, fcport, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004439 }
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 Vasquezabbd8872005-07-06 10:30:05 -07004448 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449 loop_id = (uint16_t)
4450 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004451 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004452 loop_id = le16_to_cpu(
4453 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004454 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455
4456 /* Bypass reserved domain fields. */
4457 if ((domain & 0xf0) == 0xf0)
4458 continue;
4459
4460 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004461 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004462 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463 continue;
4464
4465 /* Bypass invalid local loop ID. */
4466 if (loop_id > LAST_LOCAL_LOOP_ID)
4467 continue;
4468
Quinn Tran41dc5292017-01-19 22:28:03 -08004469 memset(new_fcport->port_name, 0, WWN_SIZE);
Arun Easi370d5502012-08-22 14:21:10 -04004470
Linus Torvalds1da177e2005-04-16 15:20:36 -07004471 /* 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 Tran41dc5292017-01-19 22:28:03 -08004476
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004477 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 if (rval2 != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004479 ql_dbg(ql_dbg_disc, vha, 0x2097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004480 "Failed to retrieve fcport information "
4481 "-- get_port_database=%x, loop_id=0x%04x.\n",
4482 rval2, new_fcport->loop_id);
Quinn Tran83548fe2017-06-02 09:12:01 -07004483 ql_dbg(ql_dbg_disc, vha, 0x2105,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004484 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004485 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486 continue;
4487 }
4488
Quinn Tran41dc5292017-01-19 22:28:03 -08004489 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490 /* Check for matching device in port list. */
4491 found = 0;
4492 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004493 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004494 if (memcmp(new_fcport->port_name, fcport->port_name,
4495 WWN_SIZE))
4496 continue;
4497
Shyam Sundarddb9b122009-03-24 09:08:10 -07004498 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499 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 Tran41dc5292017-01-19 22:28:03 -08004505 if (!fcport->login_succ) {
4506 vha->fcport_count++;
4507 fcport->login_succ = 1;
4508 fcport->disc_state = DSC_LOGIN_COMPLETE;
4509 }
4510
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511 found++;
4512 break;
4513 }
4514
4515 if (!found) {
4516 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004517 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004518
4519 /* Allocate a new replacement fcport. */
4520 fcport = new_fcport;
Quinn Tran41dc5292017-01-19 22:28:03 -08004521 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 Chakrabortye315cd22008-11-06 10:40:51 -08004529 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Quinn Tran41dc5292017-01-19 22:28:03 -08004530
Linus Torvalds1da177e2005-04-16 15:20:36 -07004531 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004532 ql_log(ql_log_warn, vha, 0xd031,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004533 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534 rval = QLA_MEMORY_ALLOC_FAILED;
4535 goto cleanup_allocation;
4536 }
Quinn Tran41dc5292017-01-19 22:28:03 -08004537 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4539 }
4540
Quinn Tran41dc5292017-01-19 22:28:03 -08004541 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4542
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004543 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004544 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004545
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004546 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004547
4548 found_devs++;
4549 }
4550
4551cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08004552 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553
4554 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004555 ql_dbg(ql_dbg_disc, vha, 0x2098,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004556 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 }
4558
Linus Torvalds1da177e2005-04-16 15:20:36 -07004559 return (rval);
4560}
4561
4562static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004563qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004564{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004565 int rval;
Quinn Tran93f2bd62014-09-25 05:16:53 -04004566 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004567 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004568
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07004569 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004570 return;
4571
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07004572 if (atomic_read(&fcport->state) != FCS_ONLINE)
4573 return;
4574
Andrew Vasquez39bd9622007-09-20 14:07:34 -07004575 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
4576 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004577 return;
4578
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004579 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004580 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004581 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004582 ql_dbg(ql_dbg_disc, vha, 0x2004,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004583 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
4584 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004585 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004586 ql_dbg(ql_dbg_disc, vha, 0x2005,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004587 "iIDMA adjusted to %s GB/s on %8phN.\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -05004588 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004589 fcport->port_name);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004590 }
4591}
4592
Quinn Tran726b8542017-01-19 22:28:00 -08004593/* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
Adrian Bunk23be3312006-11-24 02:46:01 +01004594static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004595qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05004596{
4597 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05004598 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004599 unsigned long flags;
8482e1182005-04-17 15:04:54 -05004600
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07004601 rport_ids.node_name = wwn_to_u64(fcport->node_name);
4602 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05004603 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 Chakrabortye315cd22008-11-06 10:40:51 -08004606 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07004607 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004608 ql_log(ql_log_warn, vha, 0x2006,
4609 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07004610 return;
4611 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004612
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004613 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004614 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004615 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004616
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004617 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07004618
4619 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05004620 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 Tran726b8542017-01-19 22:28:00 -08004624
Quinn Tran83548fe2017-06-02 09:12:01 -07004625 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 Tran726b8542017-01-19 22:28:00 -08004629
Andrew Vasquez77d74142005-07-08 18:00:36 -07004630 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05004631}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004632
4633/*
Adrian Bunk23be3312006-11-24 02:46:01 +01004634 * 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 */
4648void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004649qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01004650{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004651 fcport->vha = vha;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004652
Quinn Tran726b8542017-01-19 22:28:00 -08004653 if (IS_SW_RESV_ADDR(fcport->d_id))
4654 return;
4655
Quinn Tran83548fe2017-06-02 09:12:01 -07004656 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
Quinn Tran726b8542017-01-19 22:28:00 -08004657 __func__, fcport->port_name);
4658
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004659 if (IS_QLAFX00(vha->hw)) {
4660 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004661 goto reg_port;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004662 }
Adrian Bunk23be3312006-11-24 02:46:01 +01004663 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004664 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Quinn Tran726b8542017-01-19 22:28:00 -08004665 fcport->disc_state = DSC_LOGIN_COMPLETE;
4666 fcport->deleted = 0;
4667 fcport->logout_on_delete = 1;
Adrian Bunk23be3312006-11-24 02:46:01 +01004668
Duane Grigsbye84067d2017-06-21 13:48:43 -07004669 if (fcport->fc4f_nvme) {
4670 qla_nvme_register_remote(vha, fcport);
4671 return;
4672 }
4673
Joe Carnuccio1f93da522012-11-21 02:40:38 -05004674 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004675 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08004676 qla24xx_update_fcport_fcp_prio(vha, fcport);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004677
4678reg_port:
Quinn Tran726b8542017-01-19 22:28:00 -08004679 switch (vha->host->active_mode) {
4680 case MODE_INITIATOR:
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004681 qla2x00_reg_remote_port(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08004682 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 Potashnikd20ed912015-07-14 16:00:47 -04004696 }
Adrian Bunk23be3312006-11-24 02:46:01 +01004697}
4698
4699/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004700 * 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 */
4710static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004711qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712{
Arun Easib3b02e62012-02-09 11:15:39 -08004713 int rval;
Quinn Tran726b8542017-01-19 22:28:00 -08004714 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004716 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004717 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004718 struct qla_hw_data *ha = vha->hw;
Alexei Potashnikdf673272015-07-14 16:00:46 -04004719 int discovery_gen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720
4721 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07004722 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004723 loop_id = NPH_F_PORT;
4724 else
4725 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004726 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004727 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004728 ql_dbg(ql_dbg_disc, vha, 0x20a0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004729 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004731 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732 return (QLA_SUCCESS);
4733 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004734 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735
Quinn Tran41dc5292017-01-19 22:28:03 -08004736
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 Torvalds1da177e2005-04-16 15:20:36 -07004746 do {
Quinn Tran726b8542017-01-19 22:28:00 -08004747 qla2x00_mgmt_svr_login(vha);
4748
Andrew Vasquezcca53352005-08-26 19:08:30 -07004749 /* FDMI support. */
4750 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004751 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
4752 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07004753
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07004755 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004756 loop_id = NPH_SNS;
4757 else
4758 loop_id = SIMPLE_NAME_SERVER;
Chad Dupuis0b91d112012-02-09 11:15:42 -08004759 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
4760 0xfc, mb, BIT_1|BIT_0);
4761 if (rval != QLA_SUCCESS) {
4762 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05004763 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08004764 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765 if (mb[0] != MBS_COMMAND_COMPLETE) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004766 ql_dbg(ql_dbg_disc, vha, 0x20a1,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004767 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
4768 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
4769 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004770 return (QLA_SUCCESS);
4771 }
4772
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004773 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
4774 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004775 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07004776 ql_dbg(ql_dbg_disc, vha, 0x20a2,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004777 "Register FC-4 TYPE failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004778 if (test_bit(LOOP_RESYNC_NEEDED,
4779 &vha->dpc_flags))
4780 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004781 }
Duane Grigsbyd3bae932017-06-21 13:48:44 -07004782 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07004784 ql_dbg(ql_dbg_disc, vha, 0x209a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004785 "Register FC-4 Features failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004786 if (test_bit(LOOP_RESYNC_NEEDED,
4787 &vha->dpc_flags))
4788 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789 }
Duane Grigsbyd3bae932017-06-21 13:48:44 -07004790 if (vha->flags.nvme_enabled) {
4791 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
4792 ql_dbg(ql_dbg_disc, vha, 0x2049,
4793 "Register NVME FC Type Features failed.\n");
4794 }
4795 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004796 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07004798 ql_dbg(ql_dbg_disc, vha, 0x2104,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004799 "Register Node Name failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004800 if (test_bit(LOOP_RESYNC_NEEDED,
4801 &vha->dpc_flags))
4802 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004803 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004804 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07004805 ql_dbg(ql_dbg_disc, vha, 0x209b,
Colin Ian King0bf0efa2017-06-30 14:47:41 +01004806 "Register Symbolic Node Name failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004807 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4808 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004809 }
4810 }
4811
Joe Carnuccio827210b2013-02-08 01:57:57 -05004812 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4813 fcport->scan_state = QLA_FCPORT_SCAN;
4814 }
4815
Alexei Potashnikdf673272015-07-14 16:00:46 -04004816 /* Mark the time right before querying FW for connected ports.
4817 * This process is long, asynchronous and by the time it's done,
4818 * collected information might not be accurate anymore. E.g.
4819 * disconnected port might have re-connected and a brand new
4820 * session has been created. In this case session's generation
4821 * will be newer than discovery_gen. */
4822 qlt_do_generation_tick(vha, &discovery_gen);
4823
Quinn Tran726b8542017-01-19 22:28:00 -08004824 rval = qla2x00_find_all_fabric_devs(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004825 if (rval != QLA_SUCCESS)
4826 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827 } while (0);
4828
Duane Grigsbye84067d2017-06-21 13:48:43 -07004829 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
4830 qla_nvme_register_hba(vha);
4831
Quinn Tran726b8542017-01-19 22:28:00 -08004832 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004833 ql_dbg(ql_dbg_disc, vha, 0x2068,
4834 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835
4836 return (rval);
4837}
4838
Linus Torvalds1da177e2005-04-16 15:20:36 -07004839/*
4840 * qla2x00_find_all_fabric_devs
4841 *
4842 * Input:
4843 * ha = adapter block pointer.
4844 * dev = database device entry pointer.
4845 *
4846 * Returns:
4847 * 0 = success.
4848 *
4849 * Context:
4850 * Kernel context.
4851 */
4852static int
Quinn Tran726b8542017-01-19 22:28:00 -08004853qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854{
4855 int rval;
4856 uint16_t loop_id;
Quinn Tran726b8542017-01-19 22:28:00 -08004857 fc_port_t *fcport, *new_fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858 int found;
4859
4860 sw_info_t *swl;
4861 int swl_idx;
4862 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07004863 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004864 struct qla_hw_data *ha = vha->hw;
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05004865 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran726b8542017-01-19 22:28:00 -08004866 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004867
4868 rval = QLA_SUCCESS;
4869
4870 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08004871 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08004872 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08004873 GFP_KERNEL);
4874 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004875 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876 /*EMPTY*/
Quinn Tran83548fe2017-06-02 09:12:01 -07004877 ql_dbg(ql_dbg_disc, vha, 0x209c,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004878 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08004880 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004881 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004882 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004883 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4884 return rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004885 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004887 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4888 return rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004889 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004891 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4892 return rval;
Quinn Tran726b8542017-01-19 22:28:00 -08004893 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
4894 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004895 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4896 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004897 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004898
4899 /* If other queries succeeded probe for FC-4 type */
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004900 if (swl) {
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004901 qla2x00_gff_id(vha, swl);
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004902 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4903 return rval;
4904 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905 }
4906 swl_idx = 0;
4907
4908 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004909 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004911 ql_log(ql_log_warn, vha, 0x209d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004912 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913 return (QLA_MEMORY_ALLOC_FAILED);
4914 }
4915 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916 /* Set start port ID scan at adapter ID. */
4917 first_dev = 1;
4918 last_dev = 0;
4919
4920 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004921 loop_id = ha->min_external_loopid;
4922 for (; loop_id <= ha->max_loop_id; loop_id++) {
4923 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004924 continue;
4925
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07004926 if (ha->current_topology == ISP_CFG_FL &&
4927 (atomic_read(&vha->loop_down_timer) ||
4928 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08004929 atomic_set(&vha->loop_down_timer, 0);
4930 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4931 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004932 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08004933 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004934
4935 if (swl != NULL) {
4936 if (last_dev) {
4937 wrap.b24 = new_fcport->d_id.b24;
4938 } else {
4939 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
4940 memcpy(new_fcport->node_name,
4941 swl[swl_idx].node_name, WWN_SIZE);
4942 memcpy(new_fcport->port_name,
4943 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004944 memcpy(new_fcport->fabric_port_name,
4945 swl[swl_idx].fabric_port_name, WWN_SIZE);
4946 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004947 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004949 new_fcport->nvme_flag = 0;
4950 if (vha->flags.nvme_enabled &&
4951 swl[swl_idx].fc4f_nvme) {
4952 new_fcport->fc4f_nvme =
4953 swl[swl_idx].fc4f_nvme;
4954 ql_log(ql_log_info, vha, 0x2131,
4955 "FOUND: NVME port %8phC as FC Type 28h\n",
4956 new_fcport->port_name);
4957 }
4958
Linus Torvalds1da177e2005-04-16 15:20:36 -07004959 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
4960 last_dev = 1;
4961 }
4962 swl_idx++;
4963 }
4964 } else {
4965 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004966 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004968 ql_log(ql_log_warn, vha, 0x209e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004969 "SNS scan failed -- assuming "
4970 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971 rval = QLA_SUCCESS;
4972 break;
4973 }
4974 }
4975
4976 /* If wrap on switch device list, exit. */
4977 if (first_dev) {
4978 wrap.b24 = new_fcport->d_id.b24;
4979 first_dev = 0;
4980 } else if (new_fcport->d_id.b24 == wrap.b24) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004981 ql_dbg(ql_dbg_disc, vha, 0x209f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004982 "Device wrap (%02x%02x%02x).\n",
4983 new_fcport->d_id.b.domain,
4984 new_fcport->d_id.b.area,
4985 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986 break;
4987 }
4988
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004989 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004990 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004991 continue;
4992
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004993 /* Bypass virtual ports of the same host. */
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05004994 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
4995 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004996
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004997 /* Bypass if same domain and area of adapter. */
4998 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004999 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07005000 ISP_CFG_FL)
5001 continue;
5002
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003 /* Bypass reserved domain fields. */
5004 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5005 continue;
5006
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005007 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07005008 if (ql2xgffidenable &&
5009 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5010 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005011 continue;
5012
Quinn Tran726b8542017-01-19 22:28:00 -08005013 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5014
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015 /* Locate matching device in database. */
5016 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005017 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018 if (memcmp(new_fcport->port_name, fcport->port_name,
5019 WWN_SIZE))
5020 continue;
5021
Joe Carnuccio827210b2013-02-08 01:57:57 -05005022 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08005023
Linus Torvalds1da177e2005-04-16 15:20:36 -07005024 found++;
5025
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005026 /* Update port state. */
5027 memcpy(fcport->fabric_port_name,
5028 new_fcport->fabric_port_name, WWN_SIZE);
5029 fcport->fp_speed = new_fcport->fp_speed;
5030
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031 /*
Roland Dreierb2032fd2015-07-14 16:00:42 -04005032 * If address the same and state FCS_ONLINE
5033 * (or in target mode), nothing changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034 */
5035 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
Roland Dreierb2032fd2015-07-14 16:00:42 -04005036 (atomic_read(&fcport->state) == FCS_ONLINE ||
Quinn Tran726b8542017-01-19 22:28:00 -08005037 (vha->host->active_mode == MODE_TARGET))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038 break;
5039 }
5040
5041 /*
5042 * If device was not a fabric device before.
5043 */
5044 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5045 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04005046 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005047 fcport->flags |= (FCF_FABRIC_DEVICE |
5048 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005049 break;
5050 }
5051
5052 /*
5053 * Port ID changed or device was marked to be updated;
5054 * Log it out if still logged in and mark it for
5055 * relogin later.
5056 */
Quinn Tran726b8542017-01-19 22:28:00 -08005057 if (qla_tgt_mode_enabled(base_vha)) {
Roland Dreierb2032fd2015-07-14 16:00:42 -04005058 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5059 "port changed FC ID, %8phC"
5060 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5061 fcport->port_name,
5062 fcport->d_id.b.domain,
5063 fcport->d_id.b.area,
5064 fcport->d_id.b.al_pa,
5065 fcport->loop_id,
5066 new_fcport->d_id.b.domain,
5067 new_fcport->d_id.b.area,
5068 new_fcport->d_id.b.al_pa);
5069 fcport->d_id.b24 = new_fcport->d_id.b24;
5070 break;
5071 }
5072
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073 fcport->d_id.b24 = new_fcport->d_id.b24;
5074 fcport->flags |= FCF_LOGIN_NEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005075 break;
5076 }
5077
Quinn Tran726b8542017-01-19 22:28:00 -08005078 if (found) {
5079 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005080 continue;
Quinn Tran726b8542017-01-19 22:28:00 -08005081 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082 /* If device was not in our fcports list, then add it. */
Roland Dreierb2032fd2015-07-14 16:00:42 -04005083 new_fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tran726b8542017-01-19 22:28:00 -08005084 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5085
5086 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5087
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088
5089 /* Allocate a new replacement fcport. */
5090 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005091 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005092 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005093 ql_log(ql_log_warn, vha, 0xd032,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005094 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005095 return (QLA_MEMORY_ALLOC_FAILED);
5096 }
5097 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5098 new_fcport->d_id.b24 = nxt_d_id.b24;
5099 }
5100
Quinn Tran726b8542017-01-19 22:28:00 -08005101 qla2x00_free_fcport(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102
Quinn Tran726b8542017-01-19 22:28:00 -08005103 /*
5104 * Logout all previous fabric dev marked lost, except FCP2 devices.
5105 */
5106 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5107 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5108 break;
5109
5110 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5111 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5112 continue;
5113
5114 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5115 if ((qla_dual_mode_enabled(vha) ||
5116 qla_ini_mode_enabled(vha)) &&
5117 atomic_read(&fcport->state) == FCS_ONLINE) {
5118 qla2x00_mark_device_lost(vha, fcport,
5119 ql2xplogiabsentdevice, 0);
5120 if (fcport->loop_id != FC_NO_LOOP_ID &&
5121 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5122 fcport->port_type != FCT_INITIATOR &&
5123 fcport->port_type != FCT_BROADCAST) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005124 ql_dbg(ql_dbg_disc, vha, 0x20f0,
Quinn Tran726b8542017-01-19 22:28:00 -08005125 "%s %d %8phC post del sess\n",
5126 __func__, __LINE__,
5127 fcport->port_name);
5128
5129 qlt_schedule_sess_for_deletion_lock
5130 (fcport);
5131 continue;
5132 }
5133 }
5134 }
5135
5136 if (fcport->scan_state == QLA_FCPORT_FOUND)
5137 qla24xx_fcport_handle_login(vha, fcport);
5138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139 return (rval);
5140}
5141
5142/*
5143 * qla2x00_find_new_loop_id
5144 * Scan through our port list and find a new usable loop ID.
5145 *
5146 * Input:
5147 * ha: adapter state pointer.
5148 * dev: port structure pointer.
5149 *
5150 * Returns:
5151 * qla2x00 local function return status code.
5152 *
5153 * Context:
5154 * Kernel context.
5155 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07005156int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005157qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005158{
5159 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005160 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07005161 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162
5163 rval = QLA_SUCCESS;
5164
Chad Dupuis5f16b332012-08-22 14:21:00 -04005165 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005166
Chad Dupuis5f16b332012-08-22 14:21:00 -04005167 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
5168 LOOPID_MAP_SIZE);
5169 if (dev->loop_id >= LOOPID_MAP_SIZE ||
5170 qla2x00_is_reserved_id(vha, dev->loop_id)) {
5171 dev->loop_id = FC_NO_LOOP_ID;
5172 rval = QLA_FUNCTION_FAILED;
5173 } else
5174 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005175
Chad Dupuis5f16b332012-08-22 14:21:00 -04005176 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005177
Chad Dupuis5f16b332012-08-22 14:21:00 -04005178 if (rval == QLA_SUCCESS)
5179 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
5180 "Assigning new loopid=%x, portid=%x.\n",
5181 dev->loop_id, dev->d_id.b24);
5182 else
5183 ql_log(ql_log_warn, dev->vha, 0x2087,
5184 "No loop_id's available, portid=%x.\n",
5185 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005186
5187 return (rval);
5188}
5189
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190
5191/*
5192 * qla2x00_fabric_login
5193 * Issue fabric login command.
5194 *
5195 * Input:
5196 * ha = adapter block pointer.
5197 * device = pointer to FC device type structure.
5198 *
5199 * Returns:
5200 * 0 - Login successfully
5201 * 1 - Login failed
5202 * 2 - Initiator device
5203 * 3 - Fatal error
5204 */
5205int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005206qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207 uint16_t *next_loopid)
5208{
5209 int rval;
5210 int retry;
5211 uint16_t tmp_loopid;
5212 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005213 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214
5215 retry = 0;
5216 tmp_loopid = 0;
5217
5218 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005219 ql_dbg(ql_dbg_disc, vha, 0x2000,
5220 "Trying Fabric Login w/loop id 0x%04x for port "
5221 "%02x%02x%02x.\n",
5222 fcport->loop_id, fcport->d_id.b.domain,
5223 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005224
5225 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08005226 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227 fcport->d_id.b.domain, fcport->d_id.b.area,
5228 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08005229 if (rval != QLA_SUCCESS) {
5230 return rval;
5231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005232 if (mb[0] == MBS_PORT_ID_USED) {
5233 /*
5234 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005235 * recommends the driver perform an implicit login with
5236 * the specified ID again. The ID we just used is save
5237 * here so we return with an ID that can be tried by
5238 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239 */
5240 retry++;
5241 tmp_loopid = fcport->loop_id;
5242 fcport->loop_id = mb[1];
5243
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005244 ql_dbg(ql_dbg_disc, vha, 0x2001,
5245 "Fabric Login: port in use - next loop "
5246 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07005247 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005248 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249
5250 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
5251 /*
5252 * Login succeeded.
5253 */
5254 if (retry) {
5255 /* A retry occurred before. */
5256 *next_loopid = tmp_loopid;
5257 } else {
5258 /*
5259 * No retry occurred before. Just increment the
5260 * ID value for next login.
5261 */
5262 *next_loopid = (fcport->loop_id + 1);
5263 }
5264
5265 if (mb[1] & BIT_0) {
5266 fcport->port_type = FCT_INITIATOR;
5267 } else {
5268 fcport->port_type = FCT_TARGET;
5269 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07005270 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271 }
5272 }
5273
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07005274 if (mb[10] & BIT_0)
5275 fcport->supported_classes |= FC_COS_CLASS2;
5276 if (mb[10] & BIT_1)
5277 fcport->supported_classes |= FC_COS_CLASS3;
5278
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005279 if (IS_FWI2_CAPABLE(ha)) {
5280 if (mb[10] & BIT_7)
5281 fcport->flags |=
5282 FCF_CONF_COMP_SUPPORTED;
5283 }
5284
Linus Torvalds1da177e2005-04-16 15:20:36 -07005285 rval = QLA_SUCCESS;
5286 break;
5287 } else if (mb[0] == MBS_LOOP_ID_USED) {
5288 /*
5289 * Loop ID already used, try next loop ID.
5290 */
5291 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005292 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005293 if (rval != QLA_SUCCESS) {
5294 /* Ran out of loop IDs to use */
5295 break;
5296 }
5297 } else if (mb[0] == MBS_COMMAND_ERROR) {
5298 /*
5299 * Firmware possibly timed out during login. If NO
5300 * retries are left to do then the device is declared
5301 * dead.
5302 */
5303 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005304 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07005305 fcport->d_id.b.domain, fcport->d_id.b.area,
5306 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005307 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005308
5309 rval = 1;
5310 break;
5311 } else {
5312 /*
5313 * unrecoverable / not handled error
5314 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005315 ql_dbg(ql_dbg_disc, vha, 0x2002,
5316 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
5317 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
5318 fcport->d_id.b.area, fcport->d_id.b.al_pa,
5319 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005320
5321 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005322 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07005323 fcport->d_id.b.domain, fcport->d_id.b.area,
5324 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04005325 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07005326 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005327
5328 rval = 3;
5329 break;
5330 }
5331 }
5332
5333 return (rval);
5334}
5335
5336/*
5337 * qla2x00_local_device_login
5338 * Issue local device login command.
5339 *
5340 * Input:
5341 * ha = adapter block pointer.
5342 * loop_id = loop id of device to login to.
5343 *
5344 * Returns (Where's the #define!!!!):
5345 * 0 - Login successfully
5346 * 1 - Login failed
5347 * 3 - Fatal error
5348 */
5349int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005350qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005351{
5352 int rval;
5353 uint16_t mb[MAILBOX_REGISTER_COUNT];
5354
5355 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005356 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005357 if (rval == QLA_SUCCESS) {
5358 /* Interrogate mailbox registers for any errors */
5359 if (mb[0] == MBS_COMMAND_ERROR)
5360 rval = 1;
5361 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
5362 /* device not in PCB table */
5363 rval = 3;
5364 }
5365
5366 return (rval);
5367}
5368
5369/*
5370 * qla2x00_loop_resync
5371 * Resync with fibre channel devices.
5372 *
5373 * Input:
5374 * ha = adapter block pointer.
5375 *
5376 * Returns:
5377 * 0 = success
5378 */
5379int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005380qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005381{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005382 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005383 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005384 struct req_que *req;
5385 struct rsp_que *rsp;
5386
Michael Hernandezd7459522016-12-12 14:40:07 -08005387 req = vha->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005388 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005390 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5391 if (vha->flags.online) {
5392 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005393 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5394 wait_time = 256;
5395 do {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005396 if (!IS_QLAFX00(vha->hw)) {
5397 /*
5398 * Issue a marker after FW becomes
5399 * ready.
5400 */
5401 qla2x00_marker(vha, req, rsp, 0, 0,
5402 MK_SYNC_ALL);
5403 vha->marker_needed = 0;
5404 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005405
5406 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005407 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005408
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005409 if (IS_QLAFX00(vha->hw))
5410 qlafx00_configure_devices(vha);
5411 else
5412 qla2x00_configure_loop(vha);
5413
Linus Torvalds1da177e2005-04-16 15:20:36 -07005414 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005415 } while (!atomic_read(&vha->loop_down_timer) &&
5416 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5417 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
5418 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005419 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005420 }
5421
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005422 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005423 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005424
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005425 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005426 ql_dbg(ql_dbg_disc, vha, 0x206c,
5427 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005428
5429 return (rval);
5430}
5431
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005432/*
5433* qla2x00_perform_loop_resync
5434* Description: This function will set the appropriate flags and call
5435* qla2x00_loop_resync. If successful loop will be resynced
5436* Arguments : scsi_qla_host_t pointer
5437* returm : Success or Failure
5438*/
5439
5440int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
5441{
5442 int32_t rval = 0;
5443
5444 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
5445 /*Configure the flags so that resync happens properly*/
5446 atomic_set(&ha->loop_down_timer, 0);
5447 if (!(ha->device_flags & DFLG_NO_CABLE)) {
5448 atomic_set(&ha->loop_state, LOOP_UP);
5449 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
5450 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
5451 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
5452
5453 rval = qla2x00_loop_resync(ha);
5454 } else
5455 atomic_set(&ha->loop_state, LOOP_DEAD);
5456
5457 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
5458 }
5459
5460 return rval;
5461}
5462
Linus Torvalds1da177e2005-04-16 15:20:36 -07005463void
Andrew Vasquez67becc02009-08-25 11:36:20 -07005464qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005465{
5466 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07005467 struct scsi_qla_host *vha;
5468 struct qla_hw_data *ha = base_vha->hw;
5469 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005470
Arun Easifeafb7b2010-09-03 14:57:00 -07005471 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005472 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07005473 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
5474 atomic_inc(&vha->vref_count);
5475 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08005476 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07005477 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
5478 spin_unlock_irqrestore(&ha->vport_slock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07005479 qla2x00_rport_del(fcport);
Alexei Potashnikdf673272015-07-14 16:00:46 -04005480
Arun Easifeafb7b2010-09-03 14:57:00 -07005481 spin_lock_irqsave(&ha->vport_slock, flags);
5482 }
5483 }
5484 atomic_dec(&vha->vref_count);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07005485 wake_up(&vha->vref_waitq);
Arun Easifeafb7b2010-09-03 14:57:00 -07005486 }
5487 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005488}
5489
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005490/* Assumes idc_lock always held on entry */
5491void
5492qla83xx_reset_ownership(scsi_qla_host_t *vha)
5493{
5494 struct qla_hw_data *ha = vha->hw;
5495 uint32_t drv_presence, drv_presence_mask;
5496 uint32_t dev_part_info1, dev_part_info2, class_type;
5497 uint32_t class_type_mask = 0x3;
5498 uint16_t fcoe_other_function = 0xffff, i;
5499
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005500 if (IS_QLA8044(ha)) {
5501 drv_presence = qla8044_rd_direct(vha,
5502 QLA8044_CRB_DRV_ACTIVE_INDEX);
5503 dev_part_info1 = qla8044_rd_direct(vha,
5504 QLA8044_CRB_DEV_PART_INFO_INDEX);
5505 dev_part_info2 = qla8044_rd_direct(vha,
5506 QLA8044_CRB_DEV_PART_INFO2);
5507 } else {
5508 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5509 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
5510 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
5511 }
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005512 for (i = 0; i < 8; i++) {
5513 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
5514 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5515 (i != ha->portnum)) {
5516 fcoe_other_function = i;
5517 break;
5518 }
5519 }
5520 if (fcoe_other_function == 0xffff) {
5521 for (i = 0; i < 8; i++) {
5522 class_type = ((dev_part_info2 >> (i * 4)) &
5523 class_type_mask);
5524 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5525 ((i + 8) != ha->portnum)) {
5526 fcoe_other_function = i + 8;
5527 break;
5528 }
5529 }
5530 }
5531 /*
5532 * Prepare drv-presence mask based on fcoe functions present.
5533 * However consider only valid physical fcoe function numbers (0-15).
5534 */
5535 drv_presence_mask = ~((1 << (ha->portnum)) |
5536 ((fcoe_other_function == 0xffff) ?
5537 0 : (1 << (fcoe_other_function))));
5538
5539 /* We are the reset owner iff:
5540 * - No other protocol drivers present.
5541 * - This is the lowest among fcoe functions. */
5542 if (!(drv_presence & drv_presence_mask) &&
5543 (ha->portnum < fcoe_other_function)) {
5544 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
5545 "This host is Reset owner.\n");
5546 ha->flags.nic_core_reset_owner = 1;
5547 }
5548}
5549
Saurav Kashyapfa492632012-11-21 02:40:29 -05005550static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005551__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
5552{
5553 int rval = QLA_SUCCESS;
5554 struct qla_hw_data *ha = vha->hw;
5555 uint32_t drv_ack;
5556
5557 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5558 if (rval == QLA_SUCCESS) {
5559 drv_ack |= (1 << ha->portnum);
5560 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5561 }
5562
5563 return rval;
5564}
5565
Saurav Kashyapfa492632012-11-21 02:40:29 -05005566static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005567__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
5568{
5569 int rval = QLA_SUCCESS;
5570 struct qla_hw_data *ha = vha->hw;
5571 uint32_t drv_ack;
5572
5573 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5574 if (rval == QLA_SUCCESS) {
5575 drv_ack &= ~(1 << ha->portnum);
5576 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5577 }
5578
5579 return rval;
5580}
5581
Saurav Kashyapfa492632012-11-21 02:40:29 -05005582static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005583qla83xx_dev_state_to_string(uint32_t dev_state)
5584{
5585 switch (dev_state) {
5586 case QLA8XXX_DEV_COLD:
5587 return "COLD/RE-INIT";
5588 case QLA8XXX_DEV_INITIALIZING:
5589 return "INITIALIZING";
5590 case QLA8XXX_DEV_READY:
5591 return "READY";
5592 case QLA8XXX_DEV_NEED_RESET:
5593 return "NEED RESET";
5594 case QLA8XXX_DEV_NEED_QUIESCENT:
5595 return "NEED QUIESCENT";
5596 case QLA8XXX_DEV_FAILED:
5597 return "FAILED";
5598 case QLA8XXX_DEV_QUIESCENT:
5599 return "QUIESCENT";
5600 default:
5601 return "Unknown";
5602 }
5603}
5604
5605/* Assumes idc-lock always held on entry */
5606void
5607qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
5608{
5609 struct qla_hw_data *ha = vha->hw;
5610 uint32_t idc_audit_reg = 0, duration_secs = 0;
5611
5612 switch (audit_type) {
5613 case IDC_AUDIT_TIMESTAMP:
5614 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
5615 idc_audit_reg = (ha->portnum) |
5616 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
5617 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5618 break;
5619
5620 case IDC_AUDIT_COMPLETION:
5621 duration_secs = ((jiffies_to_msecs(jiffies) -
5622 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
5623 idc_audit_reg = (ha->portnum) |
5624 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
5625 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5626 break;
5627
5628 default:
5629 ql_log(ql_log_warn, vha, 0xb078,
5630 "Invalid audit type specified.\n");
5631 break;
5632 }
5633}
5634
5635/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05005636static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005637qla83xx_initiating_reset(scsi_qla_host_t *vha)
5638{
5639 struct qla_hw_data *ha = vha->hw;
5640 uint32_t idc_control, dev_state;
5641
5642 __qla83xx_get_idc_control(vha, &idc_control);
5643 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
5644 ql_log(ql_log_info, vha, 0xb080,
5645 "NIC Core reset has been disabled. idc-control=0x%x\n",
5646 idc_control);
5647 return QLA_FUNCTION_FAILED;
5648 }
5649
5650 /* Set NEED-RESET iff in READY state and we are the reset-owner */
5651 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5652 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
5653 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
5654 QLA8XXX_DEV_NEED_RESET);
5655 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
5656 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
5657 } else {
5658 const char *state = qla83xx_dev_state_to_string(dev_state);
5659 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
5660
5661 /* SV: XXX: Is timeout required here? */
5662 /* Wait for IDC state change READY -> NEED_RESET */
5663 while (dev_state == QLA8XXX_DEV_READY) {
5664 qla83xx_idc_unlock(vha, 0);
5665 msleep(200);
5666 qla83xx_idc_lock(vha, 0);
5667 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5668 }
5669 }
5670
5671 /* Send IDC ack by writing to drv-ack register */
5672 __qla83xx_set_drv_ack(vha);
5673
5674 return QLA_SUCCESS;
5675}
5676
5677int
5678__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
5679{
5680 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5681}
5682
5683int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005684__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
5685{
5686 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5687}
5688
Saurav Kashyapfa492632012-11-21 02:40:29 -05005689static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005690qla83xx_check_driver_presence(scsi_qla_host_t *vha)
5691{
5692 uint32_t drv_presence = 0;
5693 struct qla_hw_data *ha = vha->hw;
5694
5695 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5696 if (drv_presence & (1 << ha->portnum))
5697 return QLA_SUCCESS;
5698 else
5699 return QLA_TEST_FAILED;
5700}
5701
5702int
5703qla83xx_nic_core_reset(scsi_qla_host_t *vha)
5704{
5705 int rval = QLA_SUCCESS;
5706 struct qla_hw_data *ha = vha->hw;
5707
5708 ql_dbg(ql_dbg_p3p, vha, 0xb058,
5709 "Entered %s().\n", __func__);
5710
5711 if (vha->device_flags & DFLG_DEV_FAILED) {
5712 ql_log(ql_log_warn, vha, 0xb059,
5713 "Device in unrecoverable FAILED state.\n");
5714 return QLA_FUNCTION_FAILED;
5715 }
5716
5717 qla83xx_idc_lock(vha, 0);
5718
5719 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
5720 ql_log(ql_log_warn, vha, 0xb05a,
5721 "Function=0x%x has been removed from IDC participation.\n",
5722 ha->portnum);
5723 rval = QLA_FUNCTION_FAILED;
5724 goto exit;
5725 }
5726
5727 qla83xx_reset_ownership(vha);
5728
5729 rval = qla83xx_initiating_reset(vha);
5730
5731 /*
5732 * Perform reset if we are the reset-owner,
5733 * else wait till IDC state changes to READY/FAILED.
5734 */
5735 if (rval == QLA_SUCCESS) {
5736 rval = qla83xx_idc_state_handler(vha);
5737
5738 if (rval == QLA_SUCCESS)
5739 ha->flags.nic_core_hung = 0;
5740 __qla83xx_clear_drv_ack(vha);
5741 }
5742
5743exit:
5744 qla83xx_idc_unlock(vha, 0);
5745
5746 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
5747
5748 return rval;
5749}
5750
Saurav Kashyap81178772012-08-22 14:21:04 -04005751int
5752qla2xxx_mctp_dump(scsi_qla_host_t *vha)
5753{
5754 struct qla_hw_data *ha = vha->hw;
5755 int rval = QLA_FUNCTION_FAILED;
5756
5757 if (!IS_MCTP_CAPABLE(ha)) {
5758 /* This message can be removed from the final version */
5759 ql_log(ql_log_info, vha, 0x506d,
5760 "This board is not MCTP capable\n");
5761 return rval;
5762 }
5763
5764 if (!ha->mctp_dump) {
5765 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
5766 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
5767
5768 if (!ha->mctp_dump) {
5769 ql_log(ql_log_warn, vha, 0x506e,
5770 "Failed to allocate memory for mctp dump\n");
5771 return rval;
5772 }
5773 }
5774
5775#define MCTP_DUMP_STR_ADDR 0x00000000
5776 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
5777 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
5778 if (rval != QLA_SUCCESS) {
5779 ql_log(ql_log_warn, vha, 0x506f,
5780 "Failed to capture mctp dump\n");
5781 } else {
5782 ql_log(ql_log_info, vha, 0x5070,
5783 "Mctp dump capture for host (%ld/%p).\n",
5784 vha->host_no, ha->mctp_dump);
5785 ha->mctp_dumped = 1;
5786 }
5787
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04005788 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04005789 ha->flags.nic_core_reset_hdlr_active = 1;
5790 rval = qla83xx_restart_nic_firmware(vha);
5791 if (rval)
5792 /* NIC Core reset failed. */
5793 ql_log(ql_log_warn, vha, 0x5071,
5794 "Failed to restart nic firmware\n");
5795 else
5796 ql_dbg(ql_dbg_p3p, vha, 0xb084,
5797 "Restarted NIC firmware successfully.\n");
5798 ha->flags.nic_core_reset_hdlr_active = 0;
5799 }
5800
5801 return rval;
5802
5803}
5804
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005805/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005806* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005807* Description: This function will block the new I/Os
5808* Its not aborting any I/Os as context
5809* is not destroyed during quiescence
5810* Arguments: scsi_qla_host_t
5811* return : void
5812*/
5813void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005814qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005815{
5816 struct qla_hw_data *ha = vha->hw;
5817 struct scsi_qla_host *vp;
5818
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005819 ql_dbg(ql_dbg_dpc, vha, 0x401d,
5820 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005821
5822 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
5823 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
5824 atomic_set(&vha->loop_state, LOOP_DOWN);
5825 qla2x00_mark_all_devices_lost(vha, 0);
5826 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005827 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005828 } else {
5829 if (!atomic_read(&vha->loop_down_timer))
5830 atomic_set(&vha->loop_down_timer,
5831 LOOP_DOWN_TIME);
5832 }
5833 /* Wait for pending cmds to complete */
5834 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
5835}
5836
Giridhar Malavalia9083012010-04-12 17:59:55 -07005837void
5838qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
5839{
5840 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005841 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005842 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08005843 fc_port_t *fcport;
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07005844 u16 i;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005845
Saurav Kashyape46ef002011-02-23 15:27:16 -08005846 /* For ISP82XX, driver waits for completion of the commands.
5847 * online flag should be set.
5848 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005849 if (!(IS_P3P_TYPE(ha)))
Saurav Kashyape46ef002011-02-23 15:27:16 -08005850 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005851 ha->flags.chip_reset_done = 0;
5852 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04005853 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005854
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005855 ql_log(ql_log_info, vha, 0x00af,
5856 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005857
Saurav Kashyape46ef002011-02-23 15:27:16 -08005858 /* For ISP82XX, reset_chip is just disabling interrupts.
5859 * Driver waits for the completion of the commands.
5860 * the interrupts need to be enabled.
5861 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005862 if (!(IS_P3P_TYPE(ha)))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005863 ha->isp_ops->reset_chip(vha);
5864
Quinn Tranec7193e2017-03-15 09:48:55 -07005865 ha->flags.n2n_ae = 0;
5866 ha->flags.lip_ae = 0;
5867 ha->current_topology = 0;
5868 ha->flags.fw_started = 0;
5869 ha->flags.fw_init_done = 0;
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07005870 ha->base_qpair->chip_reset++;
5871 for (i = 0; i < ha->max_qpairs; i++) {
5872 if (ha->queue_pair_map[i])
5873 ha->queue_pair_map[i]->chip_reset =
5874 ha->base_qpair->chip_reset;
5875 }
Quinn Tran726b8542017-01-19 22:28:00 -08005876
Giridhar Malavalia9083012010-04-12 17:59:55 -07005877 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
5878 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
5879 atomic_set(&vha->loop_state, LOOP_DOWN);
5880 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07005881
5882 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005883 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07005884 atomic_inc(&vp->vref_count);
5885 spin_unlock_irqrestore(&ha->vport_slock, flags);
5886
Giridhar Malavalia9083012010-04-12 17:59:55 -07005887 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07005888
5889 spin_lock_irqsave(&ha->vport_slock, flags);
5890 atomic_dec(&vp->vref_count);
5891 }
5892 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005893 } else {
5894 if (!atomic_read(&vha->loop_down_timer))
5895 atomic_set(&vha->loop_down_timer,
5896 LOOP_DOWN_TIME);
5897 }
5898
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08005899 /* Clear all async request states across all VPs. */
5900 list_for_each_entry(fcport, &vha->vp_fcports, list)
5901 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5902 spin_lock_irqsave(&ha->vport_slock, flags);
5903 list_for_each_entry(vp, &ha->vp_list, list) {
5904 atomic_inc(&vp->vref_count);
5905 spin_unlock_irqrestore(&ha->vport_slock, flags);
5906
5907 list_for_each_entry(fcport, &vp->vp_fcports, list)
5908 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5909
5910 spin_lock_irqsave(&ha->vport_slock, flags);
5911 atomic_dec(&vp->vref_count);
5912 }
5913 spin_unlock_irqrestore(&ha->vport_slock, flags);
5914
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005915 if (!ha->flags.eeh_busy) {
5916 /* Make sure for ISP 82XX IO DMA is complete */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005917 if (IS_P3P_TYPE(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005918 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005919 ql_log(ql_log_info, vha, 0x00b4,
5920 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005921
Saurav Kashyape46ef002011-02-23 15:27:16 -08005922 /* Done waiting for pending commands.
5923 * Reset the online flag.
5924 */
5925 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005926 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005927
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005928 /* Requeue all commands in outstanding command list. */
5929 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
5930 }
Arun Easib6a029e2014-09-25 06:14:52 -04005931 /* memory barrier */
5932 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005933}
5934
5935/*
5936* qla2x00_abort_isp
5937* Resets ISP and aborts all outstanding commands.
5938*
5939* Input:
5940* ha = adapter block pointer.
5941*
5942* Returns:
5943* 0 = success
5944*/
5945int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005946qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005947{
Andrew Vasquez476e8972006-08-23 14:54:55 -07005948 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005949 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005950 struct qla_hw_data *ha = vha->hw;
5951 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005952 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07005953 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005954
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005955 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07005956 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005957
Santosh Vernekara61712972012-08-22 14:21:13 -04005958 if (IS_QLA8031(ha)) {
5959 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
5960 "Clearing fcoe driver presence.\n");
5961 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
5962 ql_dbg(ql_dbg_p3p, vha, 0xb073,
5963 "Error while clearing DRV-Presence.\n");
5964 }
5965
Andrew Vasquez85880802009-12-15 21:29:46 -08005966 if (unlikely(pci_channel_offline(ha->pdev) &&
5967 ha->flags.pci_channel_io_perm_failure)) {
5968 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5969 status = 0;
5970 return status;
5971 }
5972
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005973 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08005974
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005975 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005976
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005977 if (!qla2x00_restart_isp(vha)) {
5978 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005980 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005981 /*
5982 * Issue marker command only when we are going
5983 * to start the I/O .
5984 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005985 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005986 }
5987
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005988 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005989
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005990 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005991
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07005992 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005993 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07005994
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005995 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
5996 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08005997 if (ha->fce) {
5998 ha->flags.fce_enabled = 1;
5999 memset(ha->fce, 0,
6000 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006001 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08006002 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6003 &ha->fce_bufs);
6004 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006005 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08006006 "Unable to reinitialize FCE "
6007 "(%d).\n", rval);
6008 ha->flags.fce_enabled = 0;
6009 }
6010 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006011
6012 if (ha->eft) {
6013 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006014 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006015 ha->eft_dma, EFT_NUM_BUFFERS);
6016 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006017 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006018 "Unable to reinitialize EFT "
6019 "(%d).\n", rval);
6020 }
6021 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006022 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006023 vha->flags.online = 1;
6024 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006025 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006026 ql_log(ql_log_fatal, vha, 0x8035,
6027 "ISP error recover failed - "
6028 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07006029 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006030 * The next call disables the board
6031 * completely.
6032 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006033 ha->isp_ops->reset_adapter(vha);
6034 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006035 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006036 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006037 status = 0;
6038 } else { /* schedule another ISP abort */
6039 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006040 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6041 "ISP abort - retry remaining %d.\n",
6042 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006043 status = 1;
6044 }
6045 } else {
6046 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006047 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6048 "ISP error recovery - retrying (%d) "
6049 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006050 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006051 status = 1;
6052 }
6053 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07006054
Linus Torvalds1da177e2005-04-16 15:20:36 -07006055 }
6056
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006057 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006058 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Quinn Tran1608cc42017-08-23 15:05:03 -07006059 qla2x00_configure_hba(vha);
Arun Easifeafb7b2010-09-03 14:57:00 -07006060 spin_lock_irqsave(&ha->vport_slock, flags);
6061 list_for_each_entry(vp, &ha->vp_list, list) {
6062 if (vp->vp_idx) {
6063 atomic_inc(&vp->vref_count);
6064 spin_unlock_irqrestore(&ha->vport_slock, flags);
6065
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006066 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07006067
6068 spin_lock_irqsave(&ha->vport_slock, flags);
6069 atomic_dec(&vp->vref_count);
6070 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006071 }
Arun Easifeafb7b2010-09-03 14:57:00 -07006072 spin_unlock_irqrestore(&ha->vport_slock, flags);
6073
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006074 if (IS_QLA8031(ha)) {
6075 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6076 "Setting back fcoe driver presence.\n");
6077 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6078 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6079 "Error while setting DRV-Presence.\n");
6080 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006081 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08006082 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6083 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006084 }
6085
6086 return(status);
6087}
6088
6089/*
6090* qla2x00_restart_isp
6091* restarts the ISP after a reset
6092*
6093* Input:
6094* ha = adapter block pointer.
6095*
6096* Returns:
6097* 0 = success
6098*/
6099static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006100qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08006102 int status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006103 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006104 struct req_que *req = ha->req_q_map[0];
6105 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106
6107 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006108 if (qla2x00_isp_firmware(vha)) {
6109 vha->flags.online = 0;
6110 status = ha->isp_ops->chip_diag(vha);
6111 if (!status)
6112 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006113 }
6114
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006115 if (!status && !(status = qla2x00_init_rings(vha))) {
6116 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07006117 ha->flags.chip_reset_done = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04006118
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006119 /* Initialize the queues in use */
6120 qla25xx_init_queues(ha);
6121
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006122 status = qla2x00_fw_ready(vha);
6123 if (!status) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006124 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006125 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Chad Dupuis7108b762014-04-11 16:54:45 -04006126 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006127 }
6128
6129 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006130 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006131 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006132 }
6133 return (status);
6134}
6135
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006136static int
6137qla25xx_init_queues(struct qla_hw_data *ha)
6138{
6139 struct rsp_que *rsp = NULL;
6140 struct req_que *req = NULL;
6141 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6142 int ret = -1;
6143 int i;
6144
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07006145 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006146 rsp = ha->rsp_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05006147 if (rsp && test_bit(i, ha->rsp_qid_map)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006148 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08006149 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006150 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006151 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6152 "%s Rsp que: %d init failed.\n",
6153 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006154 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006155 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6156 "%s Rsp que: %d inited.\n",
6157 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006158 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07006159 }
6160 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006161 req = ha->req_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05006162 if (req && test_bit(i, ha->req_qid_map)) {
6163 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006164 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08006165 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006166 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006167 ql_dbg(ql_dbg_init, base_vha, 0x0101,
6168 "%s Req que: %d init failed.\n",
6169 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006170 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006171 ql_dbg(ql_dbg_init, base_vha, 0x0102,
6172 "%s Req que: %d inited.\n",
6173 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006174 }
6175 }
6176 return ret;
6177}
6178
Linus Torvalds1da177e2005-04-16 15:20:36 -07006179/*
6180* qla2x00_reset_adapter
6181* Reset adapter.
6182*
6183* Input:
6184* ha = adapter block pointer.
6185*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07006186void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006187qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006188{
6189 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006190 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07006191 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006193 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006194 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196 spin_lock_irqsave(&ha->hardware_lock, flags);
6197 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
6198 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
6199 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
6200 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
6201 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6202}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006203
6204void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006205qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006206{
6207 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006208 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006209 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
6210
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006211 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07006212 return;
6213
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006214 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006215 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006216
6217 spin_lock_irqsave(&ha->hardware_lock, flags);
6218 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
6219 RD_REG_DWORD(&reg->hccr);
6220 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
6221 RD_REG_DWORD(&reg->hccr);
6222 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08006223
6224 if (IS_NOPOLLING_TYPE(ha))
6225 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006226}
6227
David Miller4e08df32007-04-16 12:37:43 -07006228/* On sparc systems, obtain port and node WWN from firmware
6229 * properties.
6230 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006231static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
6232 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07006233{
6234#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006235 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07006236 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07006237 struct device_node *dp = pci_device_to_OF_node(pdev);
6238 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07006239 int len;
6240
6241 val = of_get_property(dp, "port-wwn", &len);
6242 if (val && len >= WWN_SIZE)
6243 memcpy(nv->port_name, val, WWN_SIZE);
6244
6245 val = of_get_property(dp, "node-wwn", &len);
6246 if (val && len >= WWN_SIZE)
6247 memcpy(nv->node_name, val, WWN_SIZE);
6248#endif
6249}
6250
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006251int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006252qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006253{
David Miller4e08df32007-04-16 12:37:43 -07006254 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006255 struct init_cb_24xx *icb;
6256 struct nvram_24xx *nv;
6257 uint32_t *dptr;
6258 uint8_t *dptr1, *dptr2;
6259 uint32_t chksum;
6260 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006261 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006262
David Miller4e08df32007-04-16 12:37:43 -07006263 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006264 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07006265 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006266
6267 /* Determine NVRAM starting address. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05006268 if (ha->port_no == 0) {
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07006269 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
6270 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
6271 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006272 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08006273 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
6274 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05006275
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07006276 ha->nvram_size = sizeof(struct nvram_24xx);
6277 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006278
Seokmann Ju281afe12007-07-26 13:43:34 -07006279 /* Get VPD data into cache */
6280 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006281 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07006282 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
6283
6284 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006285 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006286 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006287 ha->nvram_size);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006288 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
6289 chksum += le32_to_cpu(*dptr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006290
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006291 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
6292 "Contents of NVRAM\n");
6293 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
6294 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006295
6296 /* Bad NVRAM data, set defaults parameters. */
6297 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6298 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07006299 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006300 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006301 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04006302 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006303 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
6304 ql_log(ql_log_warn, vha, 0x006c,
6305 "Falling back to functioning (yet invalid -- WWPN) "
6306 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07006307
6308 /*
6309 * Set default initialization control block.
6310 */
6311 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07006312 nv->nvram_version = cpu_to_le16(ICB_VERSION);
6313 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04006314 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07006315 nv->execution_throttle = cpu_to_le16(0xFFFF);
6316 nv->exchange_count = cpu_to_le16(0);
6317 nv->hard_address = cpu_to_le16(124);
David Miller4e08df32007-04-16 12:37:43 -07006318 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006319 nv->port_name[1] = 0x00 + ha->port_no + 1;
David Miller4e08df32007-04-16 12:37:43 -07006320 nv->port_name[2] = 0x00;
6321 nv->port_name[3] = 0xe0;
6322 nv->port_name[4] = 0x8b;
6323 nv->port_name[5] = 0x1c;
6324 nv->port_name[6] = 0x55;
6325 nv->port_name[7] = 0x86;
6326 nv->node_name[0] = 0x20;
6327 nv->node_name[1] = 0x00;
6328 nv->node_name[2] = 0x00;
6329 nv->node_name[3] = 0xe0;
6330 nv->node_name[4] = 0x8b;
6331 nv->node_name[5] = 0x1c;
6332 nv->node_name[6] = 0x55;
6333 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006334 qla24xx_nvram_wwn_from_ofw(vha, nv);
Bart Van Asschead950362015-07-09 07:24:08 -07006335 nv->login_retry_count = cpu_to_le16(8);
6336 nv->interrupt_delay_timer = cpu_to_le16(0);
6337 nv->login_timeout = cpu_to_le16(0);
David Miller4e08df32007-04-16 12:37:43 -07006338 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07006339 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6340 nv->firmware_options_2 = cpu_to_le32(2 << 4);
6341 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6342 nv->firmware_options_3 = cpu_to_le32(2 << 13);
6343 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6344 nv->efi_parameters = cpu_to_le32(0);
David Miller4e08df32007-04-16 12:37:43 -07006345 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07006346 nv->max_luns_per_target = cpu_to_le16(128);
6347 nv->port_down_retry_count = cpu_to_le16(30);
6348 nv->link_down_timeout = cpu_to_le16(30);
David Miller4e08df32007-04-16 12:37:43 -07006349
6350 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006351 }
6352
Quinn Tran726b8542017-01-19 22:28:00 -08006353 if (qla_tgt_mode_enabled(vha)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006354 /* Don't enable full login after initial LIP */
Bart Van Asschead950362015-07-09 07:24:08 -07006355 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006356 /* Don't enable LIP full login for initiator */
Bart Van Asschead950362015-07-09 07:24:08 -07006357 nv->host_p &= cpu_to_le32(~BIT_10);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006358 }
6359
6360 qlt_24xx_config_nvram_stage1(vha, nv);
6361
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006362 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006363 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006364
6365 /* Copy 1st segment. */
6366 dptr1 = (uint8_t *)icb;
6367 dptr2 = (uint8_t *)&nv->version;
6368 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6369 while (cnt--)
6370 *dptr1++ = *dptr2++;
6371
6372 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07006373 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006374
6375 /* Copy 2nd segment. */
6376 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6377 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6378 cnt = (uint8_t *)&icb->reserved_3 -
6379 (uint8_t *)&icb->interrupt_delay_timer;
6380 while (cnt--)
6381 *dptr1++ = *dptr2++;
6382
6383 /*
6384 * Setup driver NVRAM options.
6385 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006386 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08006387 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006388
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006389 qlt_24xx_config_nvram_stage2(vha, icb);
6390
Bart Van Asschead950362015-07-09 07:24:08 -07006391 if (nv->host_p & cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006392 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07006393 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6394 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6395 }
6396
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006397 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07006398 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006399 /*
6400 * Firmware will apply the following mask if the nodename was
6401 * not provided.
6402 */
6403 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6404 icb->node_name[0] &= 0xF0;
6405 }
6406
6407 /* Set host adapter parameters. */
6408 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08006409 ha->flags.enable_lip_reset = 0;
6410 ha->flags.enable_lip_full_login =
6411 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6412 ha->flags.enable_target_reset =
6413 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006414 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07006415 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006416
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07006417 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6418 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006419
6420 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
6421 sizeof(ha->fw_seriallink_options24));
6422
6423 /* save HBA serial number */
6424 ha->serial0 = icb->port_name[5];
6425 ha->serial1 = icb->port_name[6];
6426 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006427 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6428 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006429
Bart Van Asschead950362015-07-09 07:24:08 -07006430 icb->execution_throttle = cpu_to_le16(0xFFFF);
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08006431
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006432 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6433
6434 /* Set minimum login_timeout to 4 seconds. */
6435 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6436 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6437 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07006438 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006439 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006440
Andrew Vasquez00a537b2008-02-28 14:06:11 -08006441 /* Set minimum RATOV to 100 tenths of a second. */
6442 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006443
6444 ha->loop_reset_delay = nv->reset_delay;
6445
6446 /* Link Down Timeout = 0:
6447 *
6448 * When Port Down timer expires we will start returning
6449 * I/O's to OS with "DID_NO_CONNECT".
6450 *
6451 * Link Down Timeout != 0:
6452 *
6453 * The driver waits for the link to come up after link down
6454 * before returning I/Os to OS with "DID_NO_CONNECT".
6455 */
6456 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6457 ha->loop_down_abort_time =
6458 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6459 } else {
6460 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6461 ha->loop_down_abort_time =
6462 (LOOP_DOWN_TIME - ha->link_down_timeout);
6463 }
6464
6465 /* Need enough time to try and get the port back. */
6466 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6467 if (qlport_down_retry)
6468 ha->port_down_retry_count = qlport_down_retry;
6469
6470 /* Set login_retry_count */
6471 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6472 if (ha->port_down_retry_count ==
6473 le16_to_cpu(nv->port_down_retry_count) &&
6474 ha->port_down_retry_count > 3)
6475 ha->login_retry_count = ha->port_down_retry_count;
6476 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6477 ha->login_retry_count = ha->port_down_retry_count;
6478 if (ql2xloginretrycount)
6479 ha->login_retry_count = ql2xloginretrycount;
6480
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006481 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006482 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006483 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6484 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6485 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6486 le16_to_cpu(icb->interrupt_delay_timer): 2;
6487 }
Bart Van Asschead950362015-07-09 07:24:08 -07006488 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006489 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006490 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006491 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08006492 ha->zio_mode = QLA_ZIO_MODE_6;
6493
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006494 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006495 "ZIO mode %d enabled; timer delay (%d us).\n",
6496 ha->zio_mode, ha->zio_timer * 100);
6497
6498 icb->firmware_options_2 |= cpu_to_le32(
6499 (uint32_t)ha->zio_mode);
6500 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006501 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006502 }
6503
David Miller4e08df32007-04-16 12:37:43 -07006504 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006505 ql_log(ql_log_warn, vha, 0x0070,
6506 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07006507 }
6508 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006509}
6510
Sawan Chandak4243c112016-01-27 12:03:31 -05006511uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
6512{
6513 struct qla27xx_image_status pri_image_status, sec_image_status;
6514 uint8_t valid_pri_image, valid_sec_image;
6515 uint32_t *wptr;
6516 uint32_t cnt, chksum, size;
6517 struct qla_hw_data *ha = vha->hw;
6518
6519 valid_pri_image = valid_sec_image = 1;
6520 ha->active_image = 0;
6521 size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
6522
6523 if (!ha->flt_region_img_status_pri) {
6524 valid_pri_image = 0;
6525 goto check_sec_image;
6526 }
6527
6528 qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
6529 ha->flt_region_img_status_pri, size);
6530
6531 if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6532 ql_dbg(ql_dbg_init, vha, 0x018b,
6533 "Primary image signature (0x%x) not valid\n",
6534 pri_image_status.signature);
6535 valid_pri_image = 0;
6536 goto check_sec_image;
6537 }
6538
6539 wptr = (uint32_t *)(&pri_image_status);
6540 cnt = size;
6541
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006542 for (chksum = 0; cnt--; wptr++)
6543 chksum += le32_to_cpu(*wptr);
Quinn Tran41dc5292017-01-19 22:28:03 -08006544
Sawan Chandak4243c112016-01-27 12:03:31 -05006545 if (chksum) {
6546 ql_dbg(ql_dbg_init, vha, 0x018c,
6547 "Checksum validation failed for primary image (0x%x)\n",
6548 chksum);
6549 valid_pri_image = 0;
6550 }
6551
6552check_sec_image:
6553 if (!ha->flt_region_img_status_sec) {
6554 valid_sec_image = 0;
6555 goto check_valid_image;
6556 }
6557
6558 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
6559 ha->flt_region_img_status_sec, size);
6560
6561 if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6562 ql_dbg(ql_dbg_init, vha, 0x018d,
6563 "Secondary image signature(0x%x) not valid\n",
6564 sec_image_status.signature);
6565 valid_sec_image = 0;
6566 goto check_valid_image;
6567 }
6568
6569 wptr = (uint32_t *)(&sec_image_status);
6570 cnt = size;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006571 for (chksum = 0; cnt--; wptr++)
6572 chksum += le32_to_cpu(*wptr);
Sawan Chandak4243c112016-01-27 12:03:31 -05006573 if (chksum) {
6574 ql_dbg(ql_dbg_init, vha, 0x018e,
6575 "Checksum validation failed for secondary image (0x%x)\n",
6576 chksum);
6577 valid_sec_image = 0;
6578 }
6579
6580check_valid_image:
6581 if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
6582 ha->active_image = QLA27XX_PRIMARY_IMAGE;
6583 if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
6584 if (!ha->active_image ||
6585 pri_image_status.generation_number <
6586 sec_image_status.generation_number)
6587 ha->active_image = QLA27XX_SECONDARY_IMAGE;
6588 }
6589
6590 ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n",
6591 ha->active_image == 0 ? "default bootld and fw" :
6592 ha->active_image == 1 ? "primary" :
6593 ha->active_image == 2 ? "secondary" :
6594 "Invalid");
6595
6596 return ha->active_image;
6597}
6598
Adrian Bunk413975a2006-06-30 02:33:06 -07006599static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006600qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
6601 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006602{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006603 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006604 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006605 uint32_t *dcode, dlen;
6606 uint32_t risc_addr;
6607 uint32_t risc_size;
6608 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006609 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006610 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006611
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006612 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006613 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006614
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006615 rval = QLA_SUCCESS;
6616
6617 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006618 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006619 *srisc_addr = 0;
6620
Sawan Chandak4243c112016-01-27 12:03:31 -05006621 if (IS_QLA27XX(ha) &&
6622 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
6623 faddr = ha->flt_region_fw_sec;
6624
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006625 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006626 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006627 for (i = 0; i < 4; i++)
6628 dcode[i] = be32_to_cpu(dcode[i]);
6629 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
6630 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
6631 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
6632 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006633 ql_log(ql_log_fatal, vha, 0x008c,
6634 "Unable to verify the integrity of flash firmware "
6635 "image.\n");
6636 ql_log(ql_log_fatal, vha, 0x008d,
6637 "Firmware data: %08x %08x %08x %08x.\n",
6638 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006639
6640 return QLA_FUNCTION_FAILED;
6641 }
6642
6643 while (segments && rval == QLA_SUCCESS) {
6644 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006645 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006646
6647 risc_addr = be32_to_cpu(dcode[2]);
6648 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
6649 risc_size = be32_to_cpu(dcode[3]);
6650
6651 fragment = 0;
6652 while (risc_size > 0 && rval == QLA_SUCCESS) {
6653 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
6654 if (dlen > risc_size)
6655 dlen = risc_size;
6656
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006657 ql_dbg(ql_dbg_init, vha, 0x008e,
6658 "Loading risc segment@ risc addr %x "
6659 "number of dwords 0x%x offset 0x%x.\n",
6660 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006661
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006662 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006663 for (i = 0; i < dlen; i++)
6664 dcode[i] = swab32(dcode[i]);
6665
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006666 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006667 dlen);
6668 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006669 ql_log(ql_log_fatal, vha, 0x008f,
6670 "Failed to load segment %d of firmware.\n",
6671 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04006672 return QLA_FUNCTION_FAILED;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006673 }
6674
6675 faddr += dlen;
6676 risc_addr += dlen;
6677 risc_size -= dlen;
6678 fragment++;
6679 }
6680
6681 /* Next segment. */
6682 segments--;
6683 }
6684
Chad Dupuisf73cb692014-02-26 04:15:06 -05006685 if (!IS_QLA27XX(ha))
6686 return rval;
6687
6688 if (ha->fw_dump_template)
6689 vfree(ha->fw_dump_template);
6690 ha->fw_dump_template = NULL;
6691 ha->fw_dump_template_len = 0;
6692
6693 ql_dbg(ql_dbg_init, vha, 0x0161,
6694 "Loading fwdump template from %x\n", faddr);
6695 qla24xx_read_flash_data(vha, dcode, faddr, 7);
6696 risc_size = be32_to_cpu(dcode[2]);
6697 ql_dbg(ql_dbg_init, vha, 0x0162,
6698 "-> array size %x dwords\n", risc_size);
6699 if (risc_size == 0 || risc_size == ~0)
6700 goto default_template;
6701
6702 dlen = (risc_size - 8) * sizeof(*dcode);
6703 ql_dbg(ql_dbg_init, vha, 0x0163,
6704 "-> template allocating %x bytes...\n", dlen);
6705 ha->fw_dump_template = vmalloc(dlen);
6706 if (!ha->fw_dump_template) {
6707 ql_log(ql_log_warn, vha, 0x0164,
6708 "Failed fwdump template allocate %x bytes.\n", risc_size);
6709 goto default_template;
6710 }
6711
6712 faddr += 7;
6713 risc_size -= 8;
6714 dcode = ha->fw_dump_template;
6715 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
6716 for (i = 0; i < risc_size; i++)
6717 dcode[i] = le32_to_cpu(dcode[i]);
6718
6719 if (!qla27xx_fwdt_template_valid(dcode)) {
6720 ql_log(ql_log_warn, vha, 0x0165,
6721 "Failed fwdump template validate\n");
6722 goto default_template;
6723 }
6724
6725 dlen = qla27xx_fwdt_template_size(dcode);
6726 ql_dbg(ql_dbg_init, vha, 0x0166,
6727 "-> template size %x bytes\n", dlen);
6728 if (dlen > risc_size * sizeof(*dcode)) {
6729 ql_log(ql_log_warn, vha, 0x0167,
Himanshu Madhani4fae52b2017-06-06 13:55:23 -07006730 "Failed fwdump template exceeds array by %zx bytes\n",
Joe Carnuccio383a2982017-06-02 09:11:55 -07006731 (size_t)(dlen - risc_size * sizeof(*dcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05006732 goto default_template;
6733 }
6734 ha->fw_dump_template_len = dlen;
6735 return rval;
6736
6737default_template:
6738 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
6739 if (ha->fw_dump_template)
6740 vfree(ha->fw_dump_template);
6741 ha->fw_dump_template = NULL;
6742 ha->fw_dump_template_len = 0;
6743
6744 dlen = qla27xx_fwdt_template_default_size();
6745 ql_dbg(ql_dbg_init, vha, 0x0169,
6746 "-> template allocating %x bytes...\n", dlen);
6747 ha->fw_dump_template = vmalloc(dlen);
6748 if (!ha->fw_dump_template) {
6749 ql_log(ql_log_warn, vha, 0x016a,
6750 "Failed fwdump template allocate %x bytes.\n", risc_size);
6751 goto failed_template;
6752 }
6753
6754 dcode = ha->fw_dump_template;
6755 risc_size = dlen / sizeof(*dcode);
6756 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
6757 for (i = 0; i < risc_size; i++)
6758 dcode[i] = be32_to_cpu(dcode[i]);
6759
6760 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
6761 ql_log(ql_log_warn, vha, 0x016b,
6762 "Failed fwdump template validate\n");
6763 goto failed_template;
6764 }
6765
6766 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
6767 ql_dbg(ql_dbg_init, vha, 0x016c,
6768 "-> template size %x bytes\n", dlen);
6769 ha->fw_dump_template_len = dlen;
6770 return rval;
6771
6772failed_template:
6773 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
6774 if (ha->fw_dump_template)
6775 vfree(ha->fw_dump_template);
6776 ha->fw_dump_template = NULL;
6777 ha->fw_dump_template_len = 0;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006778 return rval;
6779}
6780
Giridhar Malavalie9454a82013-02-08 01:57:47 -05006781#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006782
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006783int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006784qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08006785{
6786 int rval;
6787 int i, fragment;
6788 uint16_t *wcode, *fwcode;
6789 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
6790 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006791 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006792 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08006793
6794 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006795 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08006796 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006797 ql_log(ql_log_info, vha, 0x0083,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01006798 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006799 ql_log(ql_log_info, vha, 0x0084,
6800 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08006801 return QLA_FUNCTION_FAILED;
6802 }
6803
6804 rval = QLA_SUCCESS;
6805
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006806 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08006807 *srisc_addr = 0;
6808 fwcode = (uint16_t *)blob->fw->data;
6809 fwclen = 0;
6810
6811 /* Validate firmware image by checking version. */
6812 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006813 ql_log(ql_log_fatal, vha, 0x0085,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006814 "Unable to verify integrity of firmware image (%zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08006815 blob->fw->size);
6816 goto fail_fw_integrity;
6817 }
6818 for (i = 0; i < 4; i++)
6819 wcode[i] = be16_to_cpu(fwcode[i + 4]);
6820 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
6821 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
6822 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006823 ql_log(ql_log_fatal, vha, 0x0086,
6824 "Unable to verify integrity of firmware image.\n");
6825 ql_log(ql_log_fatal, vha, 0x0087,
6826 "Firmware data: %04x %04x %04x %04x.\n",
6827 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08006828 goto fail_fw_integrity;
6829 }
6830
6831 seg = blob->segs;
6832 while (*seg && rval == QLA_SUCCESS) {
6833 risc_addr = *seg;
6834 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
6835 risc_size = be16_to_cpu(fwcode[3]);
6836
6837 /* Validate firmware image size. */
6838 fwclen += risc_size * sizeof(uint16_t);
6839 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006840 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08006841 "Unable to verify integrity of firmware image "
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006842 "(%zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08006843 goto fail_fw_integrity;
6844 }
6845
6846 fragment = 0;
6847 while (risc_size > 0 && rval == QLA_SUCCESS) {
6848 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
6849 if (wlen > risc_size)
6850 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006851 ql_dbg(ql_dbg_init, vha, 0x0089,
6852 "Loading risc segment@ risc addr %x number of "
6853 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08006854
6855 for (i = 0; i < wlen; i++)
6856 wcode[i] = swab16(fwcode[i]);
6857
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006858 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08006859 wlen);
6860 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006861 ql_log(ql_log_fatal, vha, 0x008a,
6862 "Failed to load segment %d of firmware.\n",
6863 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08006864 break;
6865 }
6866
6867 fwcode += wlen;
6868 risc_addr += wlen;
6869 risc_size -= wlen;
6870 fragment++;
6871 }
6872
6873 /* Next segment. */
6874 seg++;
6875 }
6876 return rval;
6877
6878fail_fw_integrity:
6879 return QLA_FUNCTION_FAILED;
6880}
6881
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006882static int
6883qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006884{
6885 int rval;
6886 int segments, fragment;
6887 uint32_t *dcode, dlen;
6888 uint32_t risc_addr;
6889 uint32_t risc_size;
6890 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08006891 struct fw_blob *blob;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006892 const uint32_t *fwcode;
6893 uint32_t fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006894 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006895 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006896
Andrew Vasquez54333832005-11-09 15:49:04 -08006897 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006898 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08006899 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006900 ql_log(ql_log_warn, vha, 0x0090,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01006901 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006902 ql_log(ql_log_warn, vha, 0x0091,
6903 "Firmware images can be retrieved from: "
6904 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006905
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006906 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006907 }
6908
Chad Dupuiscfb09192011-11-18 09:03:07 -08006909 ql_dbg(ql_dbg_init, vha, 0x0092,
6910 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006911
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006912 rval = QLA_SUCCESS;
6913
6914 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006915 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006916 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08006917 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006918 fwclen = 0;
6919
6920 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08006921 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006922 ql_log(ql_log_fatal, vha, 0x0093,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006923 "Unable to verify integrity of firmware image (%zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08006924 blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05006925 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006926 }
6927 for (i = 0; i < 4; i++)
6928 dcode[i] = be32_to_cpu(fwcode[i + 4]);
6929 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
6930 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
6931 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
6932 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006933 ql_log(ql_log_fatal, vha, 0x0094,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006934 "Unable to verify integrity of firmware image (%zd).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006935 blob->fw->size);
6936 ql_log(ql_log_fatal, vha, 0x0095,
6937 "Firmware data: %08x %08x %08x %08x.\n",
6938 dcode[0], dcode[1], dcode[2], dcode[3]);
Chad Dupuisf73cb692014-02-26 04:15:06 -05006939 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006940 }
6941
6942 while (segments && rval == QLA_SUCCESS) {
6943 risc_addr = be32_to_cpu(fwcode[2]);
6944 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
6945 risc_size = be32_to_cpu(fwcode[3]);
6946
6947 /* Validate firmware image size. */
6948 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08006949 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006950 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08006951 "Unable to verify integrity of firmware image "
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006952 "(%zd).\n", blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05006953 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006954 }
6955
6956 fragment = 0;
6957 while (risc_size > 0 && rval == QLA_SUCCESS) {
6958 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
6959 if (dlen > risc_size)
6960 dlen = risc_size;
6961
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006962 ql_dbg(ql_dbg_init, vha, 0x0097,
6963 "Loading risc segment@ risc addr %x "
6964 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006965
6966 for (i = 0; i < dlen; i++)
6967 dcode[i] = swab32(fwcode[i]);
6968
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006969 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08006970 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006971 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006972 ql_log(ql_log_fatal, vha, 0x0098,
6973 "Failed to load segment %d of firmware.\n",
6974 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04006975 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006976 }
6977
6978 fwcode += dlen;
6979 risc_addr += dlen;
6980 risc_size -= dlen;
6981 fragment++;
6982 }
6983
6984 /* Next segment. */
6985 segments--;
6986 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05006987
6988 if (!IS_QLA27XX(ha))
6989 return rval;
6990
6991 if (ha->fw_dump_template)
6992 vfree(ha->fw_dump_template);
6993 ha->fw_dump_template = NULL;
6994 ha->fw_dump_template_len = 0;
6995
6996 ql_dbg(ql_dbg_init, vha, 0x171,
Chad Dupuis97ea7022014-03-13 14:16:40 -04006997 "Loading fwdump template from %x\n",
6998 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
Chad Dupuisf73cb692014-02-26 04:15:06 -05006999 risc_size = be32_to_cpu(fwcode[2]);
7000 ql_dbg(ql_dbg_init, vha, 0x172,
7001 "-> array size %x dwords\n", risc_size);
7002 if (risc_size == 0 || risc_size == ~0)
7003 goto default_template;
7004
7005 dlen = (risc_size - 8) * sizeof(*fwcode);
7006 ql_dbg(ql_dbg_init, vha, 0x0173,
7007 "-> template allocating %x bytes...\n", dlen);
7008 ha->fw_dump_template = vmalloc(dlen);
7009 if (!ha->fw_dump_template) {
7010 ql_log(ql_log_warn, vha, 0x0174,
7011 "Failed fwdump template allocate %x bytes.\n", risc_size);
7012 goto default_template;
7013 }
7014
7015 fwcode += 7;
7016 risc_size -= 8;
7017 dcode = ha->fw_dump_template;
7018 for (i = 0; i < risc_size; i++)
7019 dcode[i] = le32_to_cpu(fwcode[i]);
7020
7021 if (!qla27xx_fwdt_template_valid(dcode)) {
7022 ql_log(ql_log_warn, vha, 0x0175,
7023 "Failed fwdump template validate\n");
7024 goto default_template;
7025 }
7026
7027 dlen = qla27xx_fwdt_template_size(dcode);
7028 ql_dbg(ql_dbg_init, vha, 0x0176,
7029 "-> template size %x bytes\n", dlen);
7030 if (dlen > risc_size * sizeof(*fwcode)) {
7031 ql_log(ql_log_warn, vha, 0x0177,
Himanshu Madhani4fae52b2017-06-06 13:55:23 -07007032 "Failed fwdump template exceeds array by %zx bytes\n",
Joe Carnuccio383a2982017-06-02 09:11:55 -07007033 (size_t)(dlen - risc_size * sizeof(*fwcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05007034 goto default_template;
7035 }
7036 ha->fw_dump_template_len = dlen;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007037 return rval;
7038
Chad Dupuisf73cb692014-02-26 04:15:06 -05007039default_template:
7040 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
7041 if (ha->fw_dump_template)
7042 vfree(ha->fw_dump_template);
7043 ha->fw_dump_template = NULL;
7044 ha->fw_dump_template_len = 0;
7045
7046 dlen = qla27xx_fwdt_template_default_size();
7047 ql_dbg(ql_dbg_init, vha, 0x0179,
7048 "-> template allocating %x bytes...\n", dlen);
7049 ha->fw_dump_template = vmalloc(dlen);
7050 if (!ha->fw_dump_template) {
7051 ql_log(ql_log_warn, vha, 0x017a,
7052 "Failed fwdump template allocate %x bytes.\n", risc_size);
7053 goto failed_template;
7054 }
7055
7056 dcode = ha->fw_dump_template;
7057 risc_size = dlen / sizeof(*fwcode);
7058 fwcode = qla27xx_fwdt_template_default();
7059 for (i = 0; i < risc_size; i++)
7060 dcode[i] = be32_to_cpu(fwcode[i]);
7061
7062 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7063 ql_log(ql_log_warn, vha, 0x017b,
7064 "Failed fwdump template validate\n");
7065 goto failed_template;
7066 }
7067
7068 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7069 ql_dbg(ql_dbg_init, vha, 0x017c,
7070 "-> template size %x bytes\n", dlen);
7071 ha->fw_dump_template_len = dlen;
7072 return rval;
7073
7074failed_template:
7075 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
7076 if (ha->fw_dump_template)
7077 vfree(ha->fw_dump_template);
7078 ha->fw_dump_template = NULL;
7079 ha->fw_dump_template_len = 0;
7080 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007081}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007082
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007083int
7084qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7085{
7086 int rval;
7087
Andrew Vasqueze337d902009-04-06 22:33:49 -07007088 if (ql2xfwloadbin == 1)
7089 return qla81xx_load_risc(vha, srisc_addr);
7090
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007091 /*
7092 * FW Load priority:
7093 * 1) Firmware via request-firmware interface (.bin file).
7094 * 2) Firmware residing in flash.
7095 */
7096 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7097 if (rval == QLA_SUCCESS)
7098 return rval;
7099
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007100 return qla24xx_load_risc_flash(vha, srisc_addr,
7101 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007102}
7103
7104int
7105qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7106{
7107 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007108 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007109
Andrew Vasqueze337d902009-04-06 22:33:49 -07007110 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007111 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07007112
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007113 /*
7114 * FW Load priority:
7115 * 1) Firmware residing in flash.
7116 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007117 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007118 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007119 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007120 if (rval == QLA_SUCCESS)
7121 return rval;
7122
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007123try_blob_fw:
7124 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7125 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
7126 return rval;
7127
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007128 ql_log(ql_log_info, vha, 0x0099,
7129 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007130 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
7131 if (rval != QLA_SUCCESS)
7132 return rval;
7133
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007134 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007135 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007136 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007137}
7138
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007139void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007140qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007141{
7142 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007143 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007144
Andrew Vasquez85880802009-12-15 21:29:46 -08007145 if (ha->flags.pci_channel_io_perm_failure)
7146 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07007147 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007148 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07007149 if (!ha->fw_major_version)
7150 return;
Quinn Tranec7193e2017-03-15 09:48:55 -07007151 if (!ha->flags.fw_started)
7152 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007153
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007154 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08007155 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07007156 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007157 ha->isp_ops->reset_chip(vha);
7158 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007159 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007160 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007161 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007162 ql_log(ql_log_info, vha, 0x8015,
7163 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007164 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007165 }
Quinn Tranec7193e2017-03-15 09:48:55 -07007166
Quinn Tran4b60c822017-06-13 20:47:21 -07007167 QLA_FW_STOPPED(ha);
Quinn Tranec7193e2017-03-15 09:48:55 -07007168 ha->flags.fw_init_done = 0;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007169}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007170
7171int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007172qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007173{
7174 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08007175 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007176 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007177 struct qla_hw_data *ha = vha->hw;
7178 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007179 struct req_que *req;
7180 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007181
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007182 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007183 return -EINVAL;
7184
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007185 rval = qla2x00_fw_ready(base_vha);
Michael Hernandezd7459522016-12-12 14:40:07 -08007186 if (vha->qpair)
7187 req = vha->qpair->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007188 else
Michael Hernandezd7459522016-12-12 14:40:07 -08007189 req = ha->req_q_map[0];
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007190 rsp = req->rsp;
7191
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007192 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007193 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007194 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007195 }
7196
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007197 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007198
7199 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08007200 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
7201 BIT_1);
7202 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
7203 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
7204 ql_dbg(ql_dbg_init, vha, 0x0120,
7205 "Failed SNS login: loop_id=%x, rval2=%d\n",
7206 NPH_SNS, rval2);
7207 else
7208 ql_dbg(ql_dbg_init, vha, 0x0103,
7209 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7210 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7211 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007212 return (QLA_FUNCTION_FAILED);
7213 }
7214
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007215 atomic_set(&vha->loop_down_timer, 0);
7216 atomic_set(&vha->loop_state, LOOP_UP);
7217 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7218 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
7219 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007220
7221 return rval;
7222}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007223
7224/* 84XX Support **************************************************************/
7225
7226static LIST_HEAD(qla_cs84xx_list);
7227static DEFINE_MUTEX(qla_cs84xx_mutex);
7228
7229static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007230qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007231{
7232 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007233 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007234
7235 mutex_lock(&qla_cs84xx_mutex);
7236
7237 /* Find any shared 84xx chip. */
7238 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
7239 if (cs84xx->bus == ha->pdev->bus) {
7240 kref_get(&cs84xx->kref);
7241 goto done;
7242 }
7243 }
7244
7245 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
7246 if (!cs84xx)
7247 goto done;
7248
7249 kref_init(&cs84xx->kref);
7250 spin_lock_init(&cs84xx->access_lock);
7251 mutex_init(&cs84xx->fw_update_mutex);
7252 cs84xx->bus = ha->pdev->bus;
7253
7254 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
7255done:
7256 mutex_unlock(&qla_cs84xx_mutex);
7257 return cs84xx;
7258}
7259
7260static void
7261__qla84xx_chip_release(struct kref *kref)
7262{
7263 struct qla_chip_state_84xx *cs84xx =
7264 container_of(kref, struct qla_chip_state_84xx, kref);
7265
7266 mutex_lock(&qla_cs84xx_mutex);
7267 list_del(&cs84xx->list);
7268 mutex_unlock(&qla_cs84xx_mutex);
7269 kfree(cs84xx);
7270}
7271
7272void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007273qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007274{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007275 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007276 if (ha->cs84xx)
7277 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
7278}
7279
7280static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007281qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007282{
7283 int rval;
7284 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007285 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007286
7287 mutex_lock(&ha->cs84xx->fw_update_mutex);
7288
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007289 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007290
7291 mutex_unlock(&ha->cs84xx->fw_update_mutex);
7292
7293 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
7294 QLA_SUCCESS;
7295}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007296
7297/* 81XX Support **************************************************************/
7298
7299int
7300qla81xx_nvram_config(scsi_qla_host_t *vha)
7301{
7302 int rval;
7303 struct init_cb_81xx *icb;
7304 struct nvram_81xx *nv;
7305 uint32_t *dptr;
7306 uint8_t *dptr1, *dptr2;
7307 uint32_t chksum;
7308 uint16_t cnt;
7309 struct qla_hw_data *ha = vha->hw;
7310
7311 rval = QLA_SUCCESS;
7312 icb = (struct init_cb_81xx *)ha->init_cb;
7313 nv = ha->nvram;
7314
7315 /* Determine NVRAM starting address. */
7316 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007317 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007318 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
7319 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007320
7321 /* Get VPD data into cache */
7322 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007323 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
7324 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007325
7326 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007327 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007328 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007329 dptr = (uint32_t *)nv;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05007330 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7331 chksum += le32_to_cpu(*dptr);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007332
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007333 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
7334 "Contents of NVRAM:\n");
7335 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
7336 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007337
7338 /* Bad NVRAM data, set defaults parameters. */
7339 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
7340 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07007341 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007342 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007343 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04007344 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007345 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007346 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007347 ql_log(ql_log_info, vha, 0x0074,
7348 "Falling back to functioning (yet invalid -- WWPN) "
7349 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007350
7351 /*
7352 * Set default initialization control block.
7353 */
7354 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07007355 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7356 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04007357 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07007358 nv->execution_throttle = cpu_to_le16(0xFFFF);
7359 nv->exchange_count = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007360 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007361 nv->port_name[1] = 0x00 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007362 nv->port_name[2] = 0x00;
7363 nv->port_name[3] = 0xe0;
7364 nv->port_name[4] = 0x8b;
7365 nv->port_name[5] = 0x1c;
7366 nv->port_name[6] = 0x55;
7367 nv->port_name[7] = 0x86;
7368 nv->node_name[0] = 0x20;
7369 nv->node_name[1] = 0x00;
7370 nv->node_name[2] = 0x00;
7371 nv->node_name[3] = 0xe0;
7372 nv->node_name[4] = 0x8b;
7373 nv->node_name[5] = 0x1c;
7374 nv->node_name[6] = 0x55;
7375 nv->node_name[7] = 0x86;
Bart Van Asschead950362015-07-09 07:24:08 -07007376 nv->login_retry_count = cpu_to_le16(8);
7377 nv->interrupt_delay_timer = cpu_to_le16(0);
7378 nv->login_timeout = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007379 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07007380 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7381 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7382 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7383 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7384 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7385 nv->efi_parameters = cpu_to_le32(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007386 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07007387 nv->max_luns_per_target = cpu_to_le16(128);
7388 nv->port_down_retry_count = cpu_to_le16(30);
7389 nv->link_down_timeout = cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07007390 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007391 nv->enode_mac[1] = 0xC0;
7392 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007393 nv->enode_mac[3] = 0x04;
7394 nv->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007395 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007396
7397 rval = 1;
7398 }
7399
Arun Easi9e522cd2012-08-22 14:21:31 -04007400 if (IS_T10_PI_CAPABLE(ha))
7401 nv->frame_payload_size &= ~7;
7402
Arun Easiaa230bc2013-01-30 03:34:39 -05007403 qlt_81xx_config_nvram_stage1(vha, nv);
7404
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007405 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07007406 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007407
7408 /* Copy 1st segment. */
7409 dptr1 = (uint8_t *)icb;
7410 dptr2 = (uint8_t *)&nv->version;
7411 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7412 while (cnt--)
7413 *dptr1++ = *dptr2++;
7414
7415 icb->login_retry_count = nv->login_retry_count;
7416
7417 /* Copy 2nd segment. */
7418 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7419 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7420 cnt = (uint8_t *)&icb->reserved_5 -
7421 (uint8_t *)&icb->interrupt_delay_timer;
7422 while (cnt--)
7423 *dptr1++ = *dptr2++;
7424
7425 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
7426 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
7427 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08007428 icb->enode_mac[0] = 0x00;
7429 icb->enode_mac[1] = 0xC0;
7430 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007431 icb->enode_mac[3] = 0x04;
7432 icb->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007433 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007434 }
7435
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07007436 /* Use extended-initialization control block. */
7437 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
7438
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007439 /*
7440 * Setup driver NVRAM options.
7441 */
7442 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07007443 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007444
Arun Easiaa230bc2013-01-30 03:34:39 -05007445 qlt_81xx_config_nvram_stage2(vha, icb);
7446
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007447 /* Use alternate WWN? */
Bart Van Asschead950362015-07-09 07:24:08 -07007448 if (nv->host_p & cpu_to_le32(BIT_15)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007449 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7450 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7451 }
7452
7453 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07007454 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007455 /*
7456 * Firmware will apply the following mask if the nodename was
7457 * not provided.
7458 */
7459 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7460 icb->node_name[0] &= 0xF0;
7461 }
7462
7463 /* Set host adapter parameters. */
7464 ha->flags.disable_risc_code_load = 0;
7465 ha->flags.enable_lip_reset = 0;
7466 ha->flags.enable_lip_full_login =
7467 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
7468 ha->flags.enable_target_reset =
7469 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
7470 ha->flags.enable_led_scheme = 0;
7471 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
7472
7473 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7474 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7475
7476 /* save HBA serial number */
7477 ha->serial0 = icb->port_name[5];
7478 ha->serial1 = icb->port_name[6];
7479 ha->serial2 = icb->port_name[7];
7480 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7481 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7482
Bart Van Asschead950362015-07-09 07:24:08 -07007483 icb->execution_throttle = cpu_to_le16(0xFFFF);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007484
7485 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7486
7487 /* Set minimum login_timeout to 4 seconds. */
7488 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7489 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7490 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07007491 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007492 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007493
7494 /* Set minimum RATOV to 100 tenths of a second. */
7495 ha->r_a_tov = 100;
7496
7497 ha->loop_reset_delay = nv->reset_delay;
7498
7499 /* Link Down Timeout = 0:
7500 *
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007501 * When Port Down timer expires we will start returning
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007502 * I/O's to OS with "DID_NO_CONNECT".
7503 *
7504 * Link Down Timeout != 0:
7505 *
7506 * The driver waits for the link to come up after link down
7507 * before returning I/Os to OS with "DID_NO_CONNECT".
7508 */
7509 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7510 ha->loop_down_abort_time =
7511 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7512 } else {
7513 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7514 ha->loop_down_abort_time =
7515 (LOOP_DOWN_TIME - ha->link_down_timeout);
7516 }
7517
7518 /* Need enough time to try and get the port back. */
7519 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7520 if (qlport_down_retry)
7521 ha->port_down_retry_count = qlport_down_retry;
7522
7523 /* Set login_retry_count */
7524 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7525 if (ha->port_down_retry_count ==
7526 le16_to_cpu(nv->port_down_retry_count) &&
7527 ha->port_down_retry_count > 3)
7528 ha->login_retry_count = ha->port_down_retry_count;
7529 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7530 ha->login_retry_count = ha->port_down_retry_count;
7531 if (ql2xloginretrycount)
7532 ha->login_retry_count = ql2xloginretrycount;
7533
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007534 /* if not running MSI-X we need handshaking on interrupts */
Chad Dupuisf73cb692014-02-26 04:15:06 -05007535 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
Bart Van Asschead950362015-07-09 07:24:08 -07007536 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007537
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007538 /* Enable ZIO. */
7539 if (!vha->flags.init_done) {
7540 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7541 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7542 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7543 le16_to_cpu(icb->interrupt_delay_timer): 2;
7544 }
Bart Van Asschead950362015-07-09 07:24:08 -07007545 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007546 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7547 vha->flags.process_response_queue = 0;
7548 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7549 ha->zio_mode = QLA_ZIO_MODE_6;
7550
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007551 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007552 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007553 ha->zio_mode,
7554 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007555
7556 icb->firmware_options_2 |= cpu_to_le32(
7557 (uint32_t)ha->zio_mode);
7558 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7559 vha->flags.process_response_queue = 1;
7560 }
7561
Quinn Tran41dc5292017-01-19 22:28:03 -08007562 /* enable RIDA Format2 */
7563 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))
7564 icb->firmware_options_3 |= BIT_0;
7565
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007566 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007567 ql_log(ql_log_warn, vha, 0x0076,
7568 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007569 }
7570 return (rval);
7571}
7572
Giridhar Malavalia9083012010-04-12 17:59:55 -07007573int
7574qla82xx_restart_isp(scsi_qla_host_t *vha)
7575{
7576 int status, rval;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007577 struct qla_hw_data *ha = vha->hw;
7578 struct req_que *req = ha->req_q_map[0];
7579 struct rsp_que *rsp = ha->rsp_q_map[0];
7580 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07007581 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007582
7583 status = qla2x00_init_rings(vha);
7584 if (!status) {
7585 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7586 ha->flags.chip_reset_done = 1;
7587
7588 status = qla2x00_fw_ready(vha);
7589 if (!status) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07007590 /* Issue a marker after FW becomes ready. */
7591 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007592 vha->flags.online = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04007593 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007594 }
7595
7596 /* if no cable then assume it's good */
7597 if ((vha->device_flags & DFLG_NO_CABLE))
7598 status = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007599 }
7600
7601 if (!status) {
7602 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7603
7604 if (!atomic_read(&vha->loop_down_timer)) {
7605 /*
7606 * Issue marker command only when we are going
7607 * to start the I/O .
7608 */
7609 vha->marker_needed = 1;
7610 }
7611
Giridhar Malavalia9083012010-04-12 17:59:55 -07007612 ha->isp_ops->enable_intrs(ha);
7613
7614 ha->isp_abort_cnt = 0;
7615 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7616
Saurav Kashyap53296782011-05-10 11:30:06 -07007617 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07007618 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07007619
Giridhar Malavalia9083012010-04-12 17:59:55 -07007620 if (ha->fce) {
7621 ha->flags.fce_enabled = 1;
7622 memset(ha->fce, 0,
7623 fce_calc_size(ha->fce_bufs));
7624 rval = qla2x00_enable_fce_trace(vha,
7625 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
7626 &ha->fce_bufs);
7627 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007628 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007629 "Unable to reinitialize FCE (%d).\n",
7630 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007631 ha->flags.fce_enabled = 0;
7632 }
7633 }
7634
7635 if (ha->eft) {
7636 memset(ha->eft, 0, EFT_SIZE);
7637 rval = qla2x00_enable_eft_trace(vha,
7638 ha->eft_dma, EFT_NUM_BUFFERS);
7639 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007640 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007641 "Unable to reinitialize EFT (%d).\n",
7642 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007643 }
7644 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07007645 }
7646
7647 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007648 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007649 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07007650
7651 spin_lock_irqsave(&ha->vport_slock, flags);
7652 list_for_each_entry(vp, &ha->vp_list, list) {
7653 if (vp->vp_idx) {
7654 atomic_inc(&vp->vref_count);
7655 spin_unlock_irqrestore(&ha->vport_slock, flags);
7656
Giridhar Malavalia9083012010-04-12 17:59:55 -07007657 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07007658
7659 spin_lock_irqsave(&ha->vport_slock, flags);
7660 atomic_dec(&vp->vref_count);
7661 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07007662 }
Arun Easifeafb7b2010-09-03 14:57:00 -07007663 spin_unlock_irqrestore(&ha->vport_slock, flags);
7664
Giridhar Malavalia9083012010-04-12 17:59:55 -07007665 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007666 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007667 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07007668 }
7669
7670 return status;
7671}
7672
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007673void
Andrew Vasquezae97c912010-02-18 10:07:28 -08007674qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007675{
Andrew Vasquezae97c912010-02-18 10:07:28 -08007676 struct qla_hw_data *ha = vha->hw;
7677
Himanshu Madhanif198caf2016-01-27 12:03:30 -05007678 /* Hold status IOCBs until ABTS response received. */
7679 if (ql2xfwholdabts)
7680 ha->fw_options[3] |= BIT_12;
7681
Giridhar Malavali088d09d2016-07-06 11:14:20 -04007682 /* Set Retry FLOGI in case of P2P connection */
7683 if (ha->operating_mode == P2P) {
7684 ha->fw_options[2] |= BIT_3;
7685 ql_dbg(ql_dbg_disc, vha, 0x2103,
7686 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
7687 __func__, ha->fw_options[2]);
7688 }
7689
Quinn Tran41dc5292017-01-19 22:28:03 -08007690 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
7691 if (ql2xmvasynctoatio) {
7692 if (qla_tgt_mode_enabled(vha) ||
7693 qla_dual_mode_enabled(vha))
7694 ha->fw_options[2] |= BIT_11;
7695 else
7696 ha->fw_options[2] &= ~BIT_11;
7697 }
Andrew Vasquezae97c912010-02-18 10:07:28 -08007698
Quinn Tranf7e761f2017-06-02 09:12:02 -07007699 if (qla_tgt_mode_enabled(vha) ||
Quinn Tran2da52732017-06-02 09:12:05 -07007700 qla_dual_mode_enabled(vha)) {
7701 /* FW auto send SCSI status during */
7702 ha->fw_options[1] |= BIT_8;
7703 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
7704
7705 /* FW perform Exchange validation */
Quinn Tranf7e761f2017-06-02 09:12:02 -07007706 ha->fw_options[2] |= BIT_4;
Quinn Tran2da52732017-06-02 09:12:05 -07007707 } else {
7708 ha->fw_options[1] &= ~BIT_8;
7709 ha->fw_options[10] &= 0x00ff;
7710
Quinn Tranf7e761f2017-06-02 09:12:02 -07007711 ha->fw_options[2] &= ~BIT_4;
Quinn Tran2da52732017-06-02 09:12:05 -07007712 }
Quinn Tranf7e761f2017-06-02 09:12:02 -07007713
Quinn Tran41dc5292017-01-19 22:28:03 -08007714 if (ql2xetsenable) {
7715 /* Enable ETS Burst. */
7716 memset(ha->fw_options, 0, sizeof(ha->fw_options));
7717 ha->fw_options[2] |= BIT_9;
7718 }
7719
Quinn Tran83548fe2017-06-02 09:12:01 -07007720 ql_dbg(ql_dbg_init, vha, 0x00e9,
7721 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
7722 __func__, ha->fw_options[1], ha->fw_options[2],
7723 ha->fw_options[3], vha->host->active_mode);
Quinn Tran41dc5292017-01-19 22:28:03 -08007724
Andrew Vasquezae97c912010-02-18 10:07:28 -08007725 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007726}
Sarang Radke09ff7012010-03-19 17:03:59 -07007727
7728/*
7729 * qla24xx_get_fcp_prio
7730 * Gets the fcp cmd priority value for the logged in port.
7731 * Looks for a match of the port descriptors within
7732 * each of the fcp prio config entries. If a match is found,
7733 * the tag (priority) value is returned.
7734 *
7735 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007736 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07007737 * fcport = port structure pointer.
7738 *
7739 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07007740 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007741 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07007742 *
7743 * Context:
7744 * Kernel context
7745 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007746static int
Sarang Radke09ff7012010-03-19 17:03:59 -07007747qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
7748{
7749 int i, entries;
7750 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007751 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07007752 uint32_t pid1, pid2;
7753 uint64_t wwn1, wwn2;
7754 struct qla_fcp_prio_entry *pri_entry;
7755 struct qla_hw_data *ha = vha->hw;
7756
7757 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007758 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07007759
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007760 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07007761 entries = ha->fcp_prio_cfg->num_entries;
7762 pri_entry = &ha->fcp_prio_cfg->entry[0];
7763
7764 for (i = 0; i < entries; i++) {
7765 pid_match = wwn_match = 0;
7766
7767 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
7768 pri_entry++;
7769 continue;
7770 }
7771
7772 /* check source pid for a match */
7773 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
7774 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
7775 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
7776 if (pid1 == INVALID_PORT_ID)
7777 pid_match++;
7778 else if (pid1 == pid2)
7779 pid_match++;
7780 }
7781
7782 /* check destination pid for a match */
7783 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
7784 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
7785 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
7786 if (pid1 == INVALID_PORT_ID)
7787 pid_match++;
7788 else if (pid1 == pid2)
7789 pid_match++;
7790 }
7791
7792 /* check source WWN for a match */
7793 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
7794 wwn1 = wwn_to_u64(vha->port_name);
7795 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
7796 if (wwn2 == (uint64_t)-1)
7797 wwn_match++;
7798 else if (wwn1 == wwn2)
7799 wwn_match++;
7800 }
7801
7802 /* check destination WWN for a match */
7803 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
7804 wwn1 = wwn_to_u64(fcport->port_name);
7805 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
7806 if (wwn2 == (uint64_t)-1)
7807 wwn_match++;
7808 else if (wwn1 == wwn2)
7809 wwn_match++;
7810 }
7811
7812 if (pid_match == 2 || wwn_match == 2) {
7813 /* Found a matching entry */
7814 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
7815 priority = pri_entry->tag;
7816 break;
7817 }
7818
7819 pri_entry++;
7820 }
7821
7822 return priority;
7823}
7824
7825/*
7826 * qla24xx_update_fcport_fcp_prio
7827 * Activates fcp priority for the logged in fc port
7828 *
7829 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007830 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07007831 * fcp = port structure pointer.
7832 *
7833 * Return:
7834 * QLA_SUCCESS or QLA_FUNCTION_FAILED
7835 *
7836 * Context:
7837 * Kernel context.
7838 */
7839int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007840qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07007841{
7842 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007843 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07007844 uint16_t mb[5];
7845
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007846 if (fcport->port_type != FCT_TARGET ||
7847 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07007848 return QLA_FUNCTION_FAILED;
7849
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007850 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007851 if (priority < 0)
7852 return QLA_FUNCTION_FAILED;
7853
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007854 if (IS_P3P_TYPE(vha->hw)) {
Saurav Kashyapa00f6292011-11-18 09:03:19 -08007855 fcport->fcp_prio = priority & 0xf;
7856 return QLA_SUCCESS;
7857 }
7858
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007859 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08007860 if (ret == QLA_SUCCESS) {
7861 if (fcport->fcp_prio != priority)
7862 ql_dbg(ql_dbg_user, vha, 0x709e,
7863 "Updated FCP_CMND priority - value=%d loop_id=%d "
7864 "port_id=%02x%02x%02x.\n", priority,
7865 fcport->loop_id, fcport->d_id.b.domain,
7866 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08007867 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08007868 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007869 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08007870 "Unable to update FCP_CMND priority - ret=0x%x for "
7871 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
7872 fcport->d_id.b.domain, fcport->d_id.b.area,
7873 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07007874 return ret;
7875}
7876
7877/*
7878 * qla24xx_update_all_fcp_prio
7879 * Activates fcp priority for all the logged in ports
7880 *
7881 * Input:
7882 * ha = adapter block pointer.
7883 *
7884 * Return:
7885 * QLA_SUCCESS or QLA_FUNCTION_FAILED
7886 *
7887 * Context:
7888 * Kernel context.
7889 */
7890int
7891qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
7892{
7893 int ret;
7894 fc_port_t *fcport;
7895
7896 ret = QLA_FUNCTION_FAILED;
7897 /* We need to set priority for all logged in ports */
7898 list_for_each_entry(fcport, &vha->vp_fcports, list)
7899 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
7900
7901 return ret;
7902}
Michael Hernandezd7459522016-12-12 14:40:07 -08007903
Quinn Tran82de8022017-06-13 20:47:17 -07007904struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
7905 int vp_idx, bool startqp)
Michael Hernandezd7459522016-12-12 14:40:07 -08007906{
7907 int rsp_id = 0;
7908 int req_id = 0;
7909 int i;
7910 struct qla_hw_data *ha = vha->hw;
7911 uint16_t qpair_id = 0;
7912 struct qla_qpair *qpair = NULL;
7913 struct qla_msix_entry *msix;
7914
7915 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
7916 ql_log(ql_log_warn, vha, 0x00181,
7917 "FW/Driver is not multi-queue capable.\n");
7918 return NULL;
7919 }
7920
7921 if (ql2xmqsupport) {
7922 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
7923 if (qpair == NULL) {
7924 ql_log(ql_log_warn, vha, 0x0182,
7925 "Failed to allocate memory for queue pair.\n");
7926 return NULL;
7927 }
7928 memset(qpair, 0, sizeof(struct qla_qpair));
7929
7930 qpair->hw = vha->hw;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08007931 qpair->vha = vha;
Quinn Tran82de8022017-06-13 20:47:17 -07007932 qpair->qp_lock_ptr = &qpair->qp_lock;
7933 spin_lock_init(&qpair->qp_lock);
Quinn Tranaf7bb382017-06-13 20:47:23 -07007934 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
Michael Hernandezd7459522016-12-12 14:40:07 -08007935
7936 /* Assign available que pair id */
7937 mutex_lock(&ha->mq_lock);
7938 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
Sawan Chandakb95b9452017-05-24 18:06:20 -07007939 if (ha->num_qpairs >= ha->max_qpairs) {
Michael Hernandezd7459522016-12-12 14:40:07 -08007940 mutex_unlock(&ha->mq_lock);
7941 ql_log(ql_log_warn, vha, 0x0183,
7942 "No resources to create additional q pair.\n");
7943 goto fail_qid_map;
7944 }
Sawan Chandakb95b9452017-05-24 18:06:20 -07007945 ha->num_qpairs++;
Michael Hernandezd7459522016-12-12 14:40:07 -08007946 set_bit(qpair_id, ha->qpair_qid_map);
7947 ha->queue_pair_map[qpair_id] = qpair;
7948 qpair->id = qpair_id;
7949 qpair->vp_idx = vp_idx;
himanshu.madhani@cavium.come6373f332017-08-23 15:04:57 -07007950 qpair->fw_started = ha->flags.fw_started;
Quinn Trane326d222017-06-13 20:47:18 -07007951 INIT_LIST_HEAD(&qpair->hints_list);
Duane Grigsbycf19c452017-08-23 15:04:58 -07007952 INIT_LIST_HEAD(&qpair->nvme_done_list);
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07007953 qpair->chip_reset = ha->base_qpair->chip_reset;
7954 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
7955 qpair->enable_explicit_conf =
7956 ha->base_qpair->enable_explicit_conf;
Michael Hernandezd7459522016-12-12 14:40:07 -08007957
7958 for (i = 0; i < ha->msix_count; i++) {
Quinn Tran093df732016-12-12 14:40:09 -08007959 msix = &ha->msix_entries[i];
Michael Hernandezd7459522016-12-12 14:40:07 -08007960 if (msix->in_use)
7961 continue;
7962 qpair->msix = msix;
Quinn Tran83548fe2017-06-02 09:12:01 -07007963 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
Michael Hernandezd7459522016-12-12 14:40:07 -08007964 "Vector %x selected for qpair\n", msix->vector);
7965 break;
7966 }
7967 if (!qpair->msix) {
7968 ql_log(ql_log_warn, vha, 0x0184,
7969 "Out of MSI-X vectors!.\n");
7970 goto fail_msix;
7971 }
7972
7973 qpair->msix->in_use = 1;
7974 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
Quinn Tran8abfa9e2017-06-13 20:47:24 -07007975 qpair->pdev = ha->pdev;
7976 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
7977 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
Michael Hernandezd7459522016-12-12 14:40:07 -08007978
7979 mutex_unlock(&ha->mq_lock);
7980
7981 /* Create response queue first */
Quinn Tran82de8022017-06-13 20:47:17 -07007982 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
Michael Hernandezd7459522016-12-12 14:40:07 -08007983 if (!rsp_id) {
7984 ql_log(ql_log_warn, vha, 0x0185,
7985 "Failed to create response queue.\n");
7986 goto fail_rsp;
7987 }
7988
7989 qpair->rsp = ha->rsp_q_map[rsp_id];
7990
7991 /* Create request queue */
Quinn Tran82de8022017-06-13 20:47:17 -07007992 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
7993 startqp);
Michael Hernandezd7459522016-12-12 14:40:07 -08007994 if (!req_id) {
7995 ql_log(ql_log_warn, vha, 0x0186,
7996 "Failed to create request queue.\n");
7997 goto fail_req;
7998 }
7999
8000 qpair->req = ha->req_q_map[req_id];
8001 qpair->rsp->req = qpair->req;
Quinn Tran82de8022017-06-13 20:47:17 -07008002 qpair->rsp->qpair = qpair;
Quinn Trane326d222017-06-13 20:47:18 -07008003 /* init qpair to this cpu. Will adjust at run time. */
8004 qla_cpu_update(qpair, smp_processor_id());
Michael Hernandezd7459522016-12-12 14:40:07 -08008005
8006 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
8007 if (ha->fw_attributes & BIT_4)
8008 qpair->difdix_supported = 1;
8009 }
8010
8011 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
8012 if (!qpair->srb_mempool) {
Quinn Tran83548fe2017-06-02 09:12:01 -07008013 ql_log(ql_log_warn, vha, 0xd036,
Michael Hernandezd7459522016-12-12 14:40:07 -08008014 "Failed to create srb mempool for qpair %d\n",
8015 qpair->id);
8016 goto fail_mempool;
8017 }
8018
8019 /* Mark as online */
8020 qpair->online = 1;
8021
8022 if (!vha->flags.qpairs_available)
8023 vha->flags.qpairs_available = 1;
8024
8025 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
8026 "Request/Response queue pair created, id %d\n",
8027 qpair->id);
8028 ql_dbg(ql_dbg_init, vha, 0x0187,
8029 "Request/Response queue pair created, id %d\n",
8030 qpair->id);
8031 }
8032 return qpair;
8033
8034fail_mempool:
8035fail_req:
8036 qla25xx_delete_rsp_que(vha, qpair->rsp);
8037fail_rsp:
8038 mutex_lock(&ha->mq_lock);
8039 qpair->msix->in_use = 0;
8040 list_del(&qpair->qp_list_elem);
8041 if (list_empty(&vha->qp_list))
8042 vha->flags.qpairs_available = 0;
8043fail_msix:
8044 ha->queue_pair_map[qpair_id] = NULL;
8045 clear_bit(qpair_id, ha->qpair_qid_map);
Sawan Chandakb95b9452017-05-24 18:06:20 -07008046 ha->num_qpairs--;
Michael Hernandezd7459522016-12-12 14:40:07 -08008047 mutex_unlock(&ha->mq_lock);
8048fail_qid_map:
8049 kfree(qpair);
8050 return NULL;
8051}
8052
8053int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
8054{
Sawan Chandakd65237c2017-06-13 20:47:19 -07008055 int ret = QLA_FUNCTION_FAILED;
Michael Hernandezd7459522016-12-12 14:40:07 -08008056 struct qla_hw_data *ha = qpair->hw;
8057
Sawan Chandakd65237c2017-06-13 20:47:19 -07008058 if (!vha->flags.qpairs_req_created && !vha->flags.qpairs_rsp_created)
8059 goto fail;
8060
Michael Hernandezd7459522016-12-12 14:40:07 -08008061 qpair->delete_in_progress = 1;
8062 while (atomic_read(&qpair->ref_count))
8063 msleep(500);
8064
8065 ret = qla25xx_delete_req_que(vha, qpair->req);
8066 if (ret != QLA_SUCCESS)
8067 goto fail;
8068 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
8069 if (ret != QLA_SUCCESS)
8070 goto fail;
8071
8072 mutex_lock(&ha->mq_lock);
8073 ha->queue_pair_map[qpair->id] = NULL;
8074 clear_bit(qpair->id, ha->qpair_qid_map);
Sawan Chandakb95b9452017-05-24 18:06:20 -07008075 ha->num_qpairs--;
Michael Hernandezd7459522016-12-12 14:40:07 -08008076 list_del(&qpair->qp_list_elem);
Sawan Chandakd65237c2017-06-13 20:47:19 -07008077 if (list_empty(&vha->qp_list)) {
Michael Hernandezd7459522016-12-12 14:40:07 -08008078 vha->flags.qpairs_available = 0;
Sawan Chandakd65237c2017-06-13 20:47:19 -07008079 vha->flags.qpairs_req_created = 0;
8080 vha->flags.qpairs_rsp_created = 0;
8081 }
Michael Hernandezd7459522016-12-12 14:40:07 -08008082 mempool_destroy(qpair->srb_mempool);
8083 kfree(qpair);
8084 mutex_unlock(&ha->mq_lock);
8085
8086 return QLA_SUCCESS;
8087fail:
8088 return ret;
8089}