blob: 4e6d3eb4caa4cea110051584bdf18228c5b3a3f2 [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 *);
Duane Grigsbya5d42f42017-06-21 13:48:41 -070039static int qla24xx_post_prli_work(struct scsi_qla_host*, fc_port_t *);
Quinn Tran726b8542017-01-19 22:28:00 -080040static void qla24xx_handle_plogi_done_event(struct scsi_qla_host *,
41 struct event_arg *);
Duane Grigsbya5d42f42017-06-21 13:48:41 -070042static void qla24xx_handle_prli_done_event(struct scsi_qla_host *,
43 struct event_arg *);
Quinn Tranf13515a2017-12-28 12:33:15 -080044static void qla24xx_handle_gpdb_event(scsi_qla_host_t *, 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
Kees Cook8e5f4ba2017-09-03 13:23:32 -070049qla2x00_sp_timeout(struct timer_list *t)
Andrew Vasquezac280b62009-08-20 11:06:05 -070050{
Kees Cook8e5f4ba2017-09-03 13:23:32 -070051 srb_t *sp = from_timer(sp, t, u.iocb_cmd.timer);
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);
Giridhar Malavali045d6ea2017-12-28 12:33:21 -080062 if (sp->type != SRB_ELS_DCMD)
63 sp->free(sp);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080064 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -070065}
66
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080067void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080068qla2x00_sp_free(void *ptr)
Andrew Vasquezac280b62009-08-20 11:06:05 -070069{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080070 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080071 struct srb_iocb *iocb = &sp->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -070072
Chad Dupuis4d97cc52010-10-15 11:27:41 -070073 del_timer(&iocb->timer);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080074 qla2x00_rel_sp(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -070075}
76
Andrew Vasquezac280b62009-08-20 11:06:05 -070077/* Asynchronous Login/Logout Routines -------------------------------------- */
78
Saurav Kashyapa9b6f722012-08-22 14:21:01 -040079unsigned long
Andrew Vasquez5b914902010-05-28 15:08:30 -070080qla2x00_get_async_timeout(struct scsi_qla_host *vha)
81{
82 unsigned long tmo;
83 struct qla_hw_data *ha = vha->hw;
84
85 /* Firmware should use switch negotiated r_a_tov for timeout. */
86 tmo = ha->r_a_tov / 10 * 2;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040087 if (IS_QLAFX00(ha)) {
88 tmo = FX00_DEF_RATOV * 2;
89 } else if (!IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez5b914902010-05-28 15:08:30 -070090 /*
91 * Except for earlier ISPs where the timeout is seeded from the
92 * initialization control block.
93 */
94 tmo = ha->login_timeout;
95 }
96 return tmo;
97}
Andrew Vasquezac280b62009-08-20 11:06:05 -070098
Quinn Tran726b8542017-01-19 22:28:00 -080099void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800100qla2x00_async_iocb_timeout(void *data)
Andrew Vasquezac280b62009-08-20 11:06:05 -0700101{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800102 srb_t *sp = data;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700103 fc_port_t *fcport = sp->fcport;
Quinn Tran726b8542017-01-19 22:28:00 -0800104 struct srb_iocb *lio = &sp->u.iocb_cmd;
105 struct event_arg ea;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700106
Quinn Tran5c25d452017-12-28 12:33:09 -0800107 if (fcport) {
108 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
109 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
110 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700111
Quinn Tran5c25d452017-12-28 12:33:09 -0800112 fcport->flags &= ~FCF_ASYNC_SENT;
113 } else {
114 pr_info("Async-%s timeout - hdl=%x.\n",
115 sp->name, sp->handle);
116 }
Quinn Tran726b8542017-01-19 22:28:00 -0800117
118 switch (sp->type) {
119 case SRB_LOGIN_CMD:
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700120 /* Retry as needed. */
121 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
122 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
123 QLA_LOGIO_LOGIN_RETRIED : 0;
Quinn Tran726b8542017-01-19 22:28:00 -0800124 memset(&ea, 0, sizeof(ea));
125 ea.event = FCME_PLOGI_DONE;
126 ea.fcport = sp->fcport;
127 ea.data[0] = lio->u.logio.data[0];
128 ea.data[1] = lio->u.logio.data[1];
129 ea.sp = sp;
130 qla24xx_handle_plogi_done_event(fcport->vha, &ea);
131 break;
132 case SRB_LOGOUT_CMD:
Alexei Potashnika6ca8872015-07-14 16:00:44 -0400133 qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT);
Quinn Tran726b8542017-01-19 22:28:00 -0800134 break;
135 case SRB_CT_PTHRU_CMD:
136 case SRB_MB_IOCB:
137 case SRB_NACK_PLOGI:
138 case SRB_NACK_PRLI:
139 case SRB_NACK_LOGO:
Quinn Tran28531922017-12-28 12:33:10 -0800140 case SRB_CTRL_VP:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800141 sp->done(sp, QLA_FUNCTION_TIMEOUT);
Quinn Tran726b8542017-01-19 22:28:00 -0800142 break;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700143 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700144}
145
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700146static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800147qla2x00_async_login_sp_done(void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700148{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800149 srb_t *sp = ptr;
150 struct scsi_qla_host *vha = sp->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800151 struct srb_iocb *lio = &sp->u.iocb_cmd;
Quinn Tran726b8542017-01-19 22:28:00 -0800152 struct event_arg ea;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700153
Quinn Tran83548fe2017-06-02 09:12:01 -0700154 ql_dbg(ql_dbg_disc, vha, 0x20dd,
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800155 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
Quinn Tran726b8542017-01-19 22:28:00 -0800156
157 sp->fcport->flags &= ~FCF_ASYNC_SENT;
158 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
159 memset(&ea, 0, sizeof(ea));
160 ea.event = FCME_PLOGI_DONE;
161 ea.fcport = sp->fcport;
162 ea.data[0] = lio->u.logio.data[0];
163 ea.data[1] = lio->u.logio.data[1];
164 ea.iop[0] = lio->u.logio.iop[0];
165 ea.iop[1] = lio->u.logio.iop[1];
166 ea.sp = sp;
167 qla2x00_fcport_event_handler(vha, &ea);
168 }
169
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800170 sp->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700171}
172
Andrew Vasquezac280b62009-08-20 11:06:05 -0700173int
174qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
175 uint16_t *data)
176{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700177 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700178 struct srb_iocb *lio;
Quinn Tran726b8542017-01-19 22:28:00 -0800179 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700180
Quinn Tran726b8542017-01-19 22:28:00 -0800181 if (!vha->flags.online)
182 goto done;
183
184 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
185 (fcport->fw_login_state == DSC_LS_PLOGI_COMP) ||
186 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
187 goto done;
188
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800189 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700190 if (!sp)
191 goto done;
192
Quinn Tran726b8542017-01-19 22:28:00 -0800193 fcport->flags |= FCF_ASYNC_SENT;
194 fcport->logout_completed = 0;
195
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800196 sp->type = SRB_LOGIN_CMD;
197 sp->name = "login";
198 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
199
200 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700201 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800202 sp->done = qla2x00_async_login_sp_done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700203 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700204
205 if (fcport->fc4f_nvme)
206 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
207
Andrew Vasquezac280b62009-08-20 11:06:05 -0700208 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700209 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700210 rval = qla2x00_start_sp(sp);
Chad Dupuis080c9512016-01-27 12:03:37 -0500211 if (rval != QLA_SUCCESS) {
212 fcport->flags &= ~FCF_ASYNC_SENT;
213 fcport->flags |= FCF_LOGIN_NEEDED;
214 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700215 goto done_free_sp;
Chad Dupuis080c9512016-01-27 12:03:37 -0500216 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700217
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700218 ql_dbg(ql_dbg_disc, vha, 0x2072,
Quinn Tran726b8542017-01-19 22:28:00 -0800219 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
220 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800221 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
222 fcport->login_retry);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700223 return rval;
224
225done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800226 sp->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700227done:
Quinn Tran726b8542017-01-19 22:28:00 -0800228 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700229 return rval;
230}
231
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700232static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800233qla2x00_async_logout_sp_done(void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700234{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800235 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800236 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700237
Quinn Tran726b8542017-01-19 22:28:00 -0800238 sp->fcport->flags &= ~FCF_ASYNC_SENT;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800239 if (!test_bit(UNLOADING, &sp->vha->dpc_flags))
240 qla2x00_post_async_logout_done_work(sp->vha, sp->fcport,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800241 lio->u.logio.data);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800242 sp->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700243}
244
Andrew Vasquezac280b62009-08-20 11:06:05 -0700245int
246qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
247{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700248 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700249 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700250 int rval;
251
252 rval = QLA_FUNCTION_FAILED;
Quinn Tran726b8542017-01-19 22:28:00 -0800253 fcport->flags |= FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800254 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700255 if (!sp)
256 goto done;
257
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800258 sp->type = SRB_LOGOUT_CMD;
259 sp->name = "logout";
260 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
261
262 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700263 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800264 sp->done = qla2x00_async_logout_sp_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700265 rval = qla2x00_start_sp(sp);
266 if (rval != QLA_SUCCESS)
267 goto done_free_sp;
268
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700269 ql_dbg(ql_dbg_disc, vha, 0x2070,
Quinn Tran726b8542017-01-19 22:28:00 -0800270 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -0800271 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
Quinn Tran726b8542017-01-19 22:28:00 -0800272 fcport->d_id.b.area, fcport->d_id.b.al_pa,
273 fcport->port_name);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700274 return rval;
275
276done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800277 sp->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700278done:
Quinn Tran726b8542017-01-19 22:28:00 -0800279 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700280 return rval;
281}
Quinn Tran11aea162017-12-28 12:33:20 -0800282
283void
284qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
285 uint16_t *data)
286{
287 /* Don't re-login in target mode */
288 if (!fcport->tgt_session)
289 qla2x00_mark_device_lost(vha, fcport, 1, 0);
290 qlt_logo_completion_handler(fcport, data[0]);
291}
292
293static void
294qla2x00_async_prlo_sp_done(void *s, int res)
295{
296 srb_t *sp = (srb_t *)s;
297 struct srb_iocb *lio = &sp->u.iocb_cmd;
298 struct scsi_qla_host *vha = sp->vha;
299
300 if (!test_bit(UNLOADING, &vha->dpc_flags))
301 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
302 lio->u.logio.data);
303 sp->free(sp);
304}
305
306int
307qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
308{
309 srb_t *sp;
310 struct srb_iocb *lio;
311 int rval;
312
313 rval = QLA_FUNCTION_FAILED;
314 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
315 if (!sp)
316 goto done;
317
318 sp->type = SRB_PRLO_CMD;
319 sp->name = "prlo";
320 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
321
322 lio = &sp->u.iocb_cmd;
323 lio->timeout = qla2x00_async_iocb_timeout;
324 sp->done = qla2x00_async_prlo_sp_done;
325 rval = qla2x00_start_sp(sp);
326 if (rval != QLA_SUCCESS)
327 goto done_free_sp;
328
329 ql_dbg(ql_dbg_disc, vha, 0x2070,
330 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
331 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
332 fcport->d_id.b.area, fcport->d_id.b.al_pa);
333 return rval;
334
335done_free_sp:
336 sp->free(sp);
337done:
338 return rval;
339}
340
Quinn Tranf13515a2017-12-28 12:33:15 -0800341static
342void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
343{
344 qla24xx_handle_gpdb_event(vha, ea);
345}
Andrew Vasquezac280b62009-08-20 11:06:05 -0700346
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700347static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800348qla2x00_async_adisc_sp_done(void *ptr, int res)
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700349{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800350 srb_t *sp = ptr;
351 struct scsi_qla_host *vha = sp->vha;
Quinn Tranf13515a2017-12-28 12:33:15 -0800352 struct event_arg ea;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700353
Quinn Tranf13515a2017-12-28 12:33:15 -0800354 ql_dbg(ql_dbg_disc, vha, 0x2066,
355 "Async done-%s res %x %8phC\n",
356 sp->name, res, sp->fcport->port_name);
357
358 memset(&ea, 0, sizeof(ea));
359 ea.event = FCME_ADISC_DONE;
360 ea.rc = res;
361 ea.fcport = sp->fcport;
362 ea.sp = sp;
363
364 qla2x00_fcport_event_handler(vha, &ea);
365
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800366 sp->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700367}
368
369int
370qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
371 uint16_t *data)
372{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700373 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700374 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700375 int rval;
376
377 rval = QLA_FUNCTION_FAILED;
Quinn Tran726b8542017-01-19 22:28:00 -0800378 fcport->flags |= FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800379 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700380 if (!sp)
381 goto done;
382
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800383 sp->type = SRB_ADISC_CMD;
384 sp->name = "adisc";
385 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
386
387 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700388 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800389 sp->done = qla2x00_async_adisc_sp_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700390 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700391 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700392 rval = qla2x00_start_sp(sp);
393 if (rval != QLA_SUCCESS)
394 goto done_free_sp;
395
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700396 ql_dbg(ql_dbg_disc, vha, 0x206f,
Quinn Tranf13515a2017-12-28 12:33:15 -0800397 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
398 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700399 return rval;
400
401done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800402 sp->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700403done:
Quinn Tran726b8542017-01-19 22:28:00 -0800404 fcport->flags &= ~FCF_ASYNC_SENT;
Quinn Tranf13515a2017-12-28 12:33:15 -0800405 qla2x00_post_async_adisc_work(vha, fcport, data);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700406 return rval;
407}
408
Quinn Tran726b8542017-01-19 22:28:00 -0800409static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
410 struct event_arg *ea)
411{
412 fc_port_t *fcport, *conflict_fcport;
413 struct get_name_list_extended *e;
414 u16 i, n, found = 0, loop_id;
415 port_id_t id;
416 u64 wwn;
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700417 u8 opt = 0, current_login_state;
Quinn Tran726b8542017-01-19 22:28:00 -0800418
419 fcport = ea->fcport;
420
421 if (ea->rc) { /* rval */
422 if (fcport->login_retry == 0) {
423 fcport->login_retry = vha->hw->login_retry_count;
Quinn Tran83548fe2017-06-02 09:12:01 -0700424 ql_dbg(ql_dbg_disc, vha, 0x20de,
425 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
426 fcport->port_name, fcport->login_retry);
Quinn Tran726b8542017-01-19 22:28:00 -0800427 }
428 return;
429 }
430
431 if (fcport->last_rscn_gen != fcport->rscn_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700432 ql_dbg(ql_dbg_disc, vha, 0x20df,
Quinn Tran726b8542017-01-19 22:28:00 -0800433 "%s %8phC rscn gen changed rscn %d|%d \n",
434 __func__, fcport->port_name,
435 fcport->last_rscn_gen, fcport->rscn_gen);
436 qla24xx_post_gidpn_work(vha, fcport);
437 return;
438 } else if (fcport->last_login_gen != fcport->login_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700439 ql_dbg(ql_dbg_disc, vha, 0x20e0,
440 "%s %8phC login gen changed login %d|%d\n",
441 __func__, fcport->port_name,
442 fcport->last_login_gen, fcport->login_gen);
Quinn Tran726b8542017-01-19 22:28:00 -0800443 return;
444 }
445
446 n = ea->data[0] / sizeof(struct get_name_list_extended);
447
Quinn Tran83548fe2017-06-02 09:12:01 -0700448 ql_dbg(ql_dbg_disc, vha, 0x20e1,
Quinn Tran726b8542017-01-19 22:28:00 -0800449 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
450 __func__, __LINE__, fcport->port_name, n,
451 fcport->d_id.b.domain, fcport->d_id.b.area,
452 fcport->d_id.b.al_pa, fcport->loop_id);
453
454 for (i = 0; i < n; i++) {
455 e = &vha->gnl.l[i];
456 wwn = wwn_to_u64(e->port_name);
457
458 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
459 continue;
460
461 found = 1;
462 id.b.domain = e->port_id[2];
463 id.b.area = e->port_id[1];
464 id.b.al_pa = e->port_id[0];
465 id.b.rsvd_1 = 0;
466
467 loop_id = le16_to_cpu(e->nport_handle);
468 loop_id = (loop_id & 0x7fff);
469
Quinn Tran83548fe2017-06-02 09:12:01 -0700470 ql_dbg(ql_dbg_disc, vha, 0x20e2,
471 "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
472 __func__, fcport->port_name,
473 e->current_login_state, fcport->fw_login_state,
474 id.b.domain, id.b.area, id.b.al_pa,
475 fcport->d_id.b.domain, fcport->d_id.b.area,
476 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
Quinn Tran726b8542017-01-19 22:28:00 -0800477
478 if ((id.b24 != fcport->d_id.b24) ||
479 ((fcport->loop_id != FC_NO_LOOP_ID) &&
480 (fcport->loop_id != loop_id))) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700481 ql_dbg(ql_dbg_disc, vha, 0x20e3,
482 "%s %d %8phC post del sess\n",
483 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800484 qlt_schedule_sess_for_deletion(fcport, 1);
485 return;
486 }
487
488 fcport->loop_id = loop_id;
489
490 wwn = wwn_to_u64(fcport->port_name);
491 qlt_find_sess_invalidate_other(vha, wwn,
492 id, loop_id, &conflict_fcport);
493
494 if (conflict_fcport) {
495 /*
496 * Another share fcport share the same loop_id &
497 * nport id. Conflict fcport needs to finish
498 * cleanup before this fcport can proceed to login.
499 */
500 conflict_fcport->conflict = fcport;
501 fcport->login_pause = 1;
502 }
503
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700504 if (fcport->fc4f_nvme)
505 current_login_state = e->current_login_state >> 4;
506 else
507 current_login_state = e->current_login_state & 0xf;
508
509 switch (current_login_state) {
Quinn Tran726b8542017-01-19 22:28:00 -0800510 case DSC_LS_PRLI_COMP:
Quinn Tran83548fe2017-06-02 09:12:01 -0700511 ql_dbg(ql_dbg_disc, vha, 0x20e4,
512 "%s %d %8phC post gpdb\n",
513 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800514 opt = PDO_FORCE_ADISC;
515 qla24xx_post_gpdb_work(vha, fcport, opt);
516 break;
Quinn Tran726b8542017-01-19 22:28:00 -0800517 case DSC_LS_PORT_UNAVAIL:
518 default:
519 if (fcport->loop_id == FC_NO_LOOP_ID) {
520 qla2x00_find_new_loop_id(vha, fcport);
521 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
522 }
Quinn Tran83548fe2017-06-02 09:12:01 -0700523 ql_dbg(ql_dbg_disc, vha, 0x20e5,
524 "%s %d %8phC\n",
525 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800526 qla24xx_fcport_handle_login(vha, fcport);
527 break;
528 }
529 }
530
531 if (!found) {
532 /* fw has no record of this port */
533 if (fcport->loop_id == FC_NO_LOOP_ID) {
534 qla2x00_find_new_loop_id(vha, fcport);
535 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
536 } else {
537 for (i = 0; i < n; i++) {
538 e = &vha->gnl.l[i];
539 id.b.domain = e->port_id[0];
540 id.b.area = e->port_id[1];
541 id.b.al_pa = e->port_id[2];
542 id.b.rsvd_1 = 0;
543 loop_id = le16_to_cpu(e->nport_handle);
544
545 if (fcport->d_id.b24 == id.b24) {
546 conflict_fcport =
547 qla2x00_find_fcport_by_wwpn(vha,
548 e->port_name, 0);
549
Quinn Tran83548fe2017-06-02 09:12:01 -0700550 ql_dbg(ql_dbg_disc, vha, 0x20e6,
Quinn Tran726b8542017-01-19 22:28:00 -0800551 "%s %d %8phC post del sess\n",
552 __func__, __LINE__,
553 conflict_fcport->port_name);
554 qlt_schedule_sess_for_deletion
555 (conflict_fcport, 1);
556 }
557
558 if (fcport->loop_id == loop_id) {
559 /* FW already picked this loop id for another fcport */
560 qla2x00_find_new_loop_id(vha, fcport);
561 }
562 }
563 }
564 qla24xx_fcport_handle_login(vha, fcport);
565 }
566} /* gnl_event */
567
568static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800569qla24xx_async_gnl_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -0800570{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800571 struct srb *sp = s;
572 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -0800573 unsigned long flags;
574 struct fc_port *fcport = NULL, *tf;
575 u16 i, n = 0, loop_id;
576 struct event_arg ea;
577 struct get_name_list_extended *e;
578 u64 wwn;
579 struct list_head h;
580
Quinn Tran83548fe2017-06-02 09:12:01 -0700581 ql_dbg(ql_dbg_disc, vha, 0x20e7,
Quinn Tran726b8542017-01-19 22:28:00 -0800582 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
583 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
584 sp->u.iocb_cmd.u.mbx.in_mb[2]);
585
586 memset(&ea, 0, sizeof(ea));
587 ea.sp = sp;
588 ea.rc = res;
589 ea.event = FCME_GNL_DONE;
590
591 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
592 sizeof(struct get_name_list_extended)) {
593 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
594 sizeof(struct get_name_list_extended);
595 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
596 }
597
598 for (i = 0; i < n; i++) {
599 e = &vha->gnl.l[i];
600 loop_id = le16_to_cpu(e->nport_handle);
601 /* mask out reserve bit */
602 loop_id = (loop_id & 0x7fff);
603 set_bit(loop_id, vha->hw->loop_id_map);
604 wwn = wwn_to_u64(e->port_name);
605
Quinn Tran83548fe2017-06-02 09:12:01 -0700606 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
Quinn Tran726b8542017-01-19 22:28:00 -0800607 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
608 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
609 e->port_id[0], e->current_login_state, e->last_login_state,
610 (loop_id & 0x7fff));
611 }
612
613 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
614 vha->gnl.sent = 0;
615
616 INIT_LIST_HEAD(&h);
617 fcport = tf = NULL;
618 if (!list_empty(&vha->gnl.fcports))
619 list_splice_init(&vha->gnl.fcports, &h);
620
621 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
622 list_del_init(&fcport->gnl_entry);
623 fcport->flags &= ~FCF_ASYNC_SENT;
624 ea.fcport = fcport;
625
626 qla2x00_fcport_event_handler(vha, &ea);
627 }
628
629 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
630
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800631 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800632}
633
634int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
635{
636 srb_t *sp;
637 struct srb_iocb *mbx;
638 int rval = QLA_FUNCTION_FAILED;
639 unsigned long flags;
640 u16 *mb;
641
642 if (!vha->flags.online)
643 goto done;
644
Quinn Tran83548fe2017-06-02 09:12:01 -0700645 ql_dbg(ql_dbg_disc, vha, 0x20d9,
Quinn Tran726b8542017-01-19 22:28:00 -0800646 "Async-gnlist WWPN %8phC \n", fcport->port_name);
647
648 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
649 fcport->flags |= FCF_ASYNC_SENT;
650 fcport->disc_state = DSC_GNL;
651 fcport->last_rscn_gen = fcport->rscn_gen;
652 fcport->last_login_gen = fcport->login_gen;
653
654 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
655 if (vha->gnl.sent) {
656 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
657 rval = QLA_SUCCESS;
658 goto done;
659 }
660 vha->gnl.sent = 1;
661 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
662
663 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
664 if (!sp)
665 goto done;
666 sp->type = SRB_MB_IOCB;
667 sp->name = "gnlist";
668 sp->gen1 = fcport->rscn_gen;
669 sp->gen2 = fcport->login_gen;
670
671 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
672
673 mb = sp->u.iocb_cmd.u.mbx.out_mb;
674 mb[0] = MBC_PORT_NODE_NAME_LIST;
675 mb[1] = BIT_2 | BIT_3;
676 mb[2] = MSW(vha->gnl.ldma);
677 mb[3] = LSW(vha->gnl.ldma);
678 mb[6] = MSW(MSD(vha->gnl.ldma));
679 mb[7] = LSW(MSD(vha->gnl.ldma));
680 mb[8] = vha->gnl.size;
681 mb[9] = vha->vp_idx;
682
683 mbx = &sp->u.iocb_cmd;
684 mbx->timeout = qla2x00_async_iocb_timeout;
685
686 sp->done = qla24xx_async_gnl_sp_done;
687
688 rval = qla2x00_start_sp(sp);
689 if (rval != QLA_SUCCESS)
690 goto done_free_sp;
691
Quinn Tran83548fe2017-06-02 09:12:01 -0700692 ql_dbg(ql_dbg_disc, vha, 0x20da,
693 "Async-%s - OUT WWPN %8phC hndl %x\n",
694 sp->name, fcport->port_name, sp->handle);
Quinn Tran726b8542017-01-19 22:28:00 -0800695
696 return rval;
697
698done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800699 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800700done:
701 fcport->flags &= ~FCF_ASYNC_SENT;
702 return rval;
703}
704
705int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
706{
707 struct qla_work_evt *e;
708
709 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
710 if (!e)
711 return QLA_FUNCTION_FAILED;
712
713 e->u.fcport.fcport = fcport;
714 return qla2x00_post_work(vha, e);
715}
716
717static
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800718void qla24xx_async_gpdb_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -0800719{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800720 struct srb *sp = s;
721 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -0800722 struct qla_hw_data *ha = vha->hw;
Quinn Tran726b8542017-01-19 22:28:00 -0800723 struct port_database_24xx *pd;
724 fc_port_t *fcport = sp->fcport;
725 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
726 int rval = QLA_SUCCESS;
727 struct event_arg ea;
728
Quinn Tran83548fe2017-06-02 09:12:01 -0700729 ql_dbg(ql_dbg_disc, vha, 0x20db,
Quinn Tran726b8542017-01-19 22:28:00 -0800730 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
731 sp->name, res, fcport->port_name, mb[1], mb[2]);
732
733 fcport->flags &= ~FCF_ASYNC_SENT;
734
735 if (res) {
736 rval = res;
737 goto gpd_error_out;
738 }
739
740 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
741
Quinn Tran15f30a52017-03-15 09:48:52 -0700742 rval = __qla24xx_parse_gpdb(vha, fcport, pd);
Quinn Tran726b8542017-01-19 22:28:00 -0800743
744gpd_error_out:
745 memset(&ea, 0, sizeof(ea));
746 ea.event = FCME_GPDB_DONE;
747 ea.rc = rval;
748 ea.fcport = fcport;
749 ea.sp = sp;
750
751 qla2x00_fcport_event_handler(vha, &ea);
752
753 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
754 sp->u.iocb_cmd.u.mbx.in_dma);
755
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800756 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800757}
758
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700759static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
760{
761 struct qla_work_evt *e;
762
763 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
764 if (!e)
765 return QLA_FUNCTION_FAILED;
766
767 e->u.fcport.fcport = fcport;
768
769 return qla2x00_post_work(vha, e);
770}
771
772static void
773qla2x00_async_prli_sp_done(void *ptr, int res)
774{
775 srb_t *sp = ptr;
776 struct scsi_qla_host *vha = sp->vha;
777 struct srb_iocb *lio = &sp->u.iocb_cmd;
778 struct event_arg ea;
779
780 ql_dbg(ql_dbg_disc, vha, 0x2129,
781 "%s %8phC res %d \n", __func__,
782 sp->fcport->port_name, res);
783
784 sp->fcport->flags &= ~FCF_ASYNC_SENT;
785
786 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
787 memset(&ea, 0, sizeof(ea));
788 ea.event = FCME_PRLI_DONE;
789 ea.fcport = sp->fcport;
790 ea.data[0] = lio->u.logio.data[0];
791 ea.data[1] = lio->u.logio.data[1];
792 ea.iop[0] = lio->u.logio.iop[0];
793 ea.iop[1] = lio->u.logio.iop[1];
794 ea.sp = sp;
795
796 qla2x00_fcport_event_handler(vha, &ea);
797 }
798
799 sp->free(sp);
800}
801
802int
803qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
804{
805 srb_t *sp;
806 struct srb_iocb *lio;
807 int rval = QLA_FUNCTION_FAILED;
808
809 if (!vha->flags.online)
810 return rval;
811
812 if (fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
813 fcport->fw_login_state == DSC_LS_PLOGI_COMP ||
814 fcport->fw_login_state == DSC_LS_PRLI_PEND)
815 return rval;
816
817 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
818 if (!sp)
819 return rval;
820
821 fcport->flags |= FCF_ASYNC_SENT;
822 fcport->logout_completed = 0;
823
824 sp->type = SRB_PRLI_CMD;
825 sp->name = "prli";
826 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
827
828 lio = &sp->u.iocb_cmd;
829 lio->timeout = qla2x00_async_iocb_timeout;
830 sp->done = qla2x00_async_prli_sp_done;
831 lio->u.logio.flags = 0;
832
833 if (fcport->fc4f_nvme)
834 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
835
836 rval = qla2x00_start_sp(sp);
837 if (rval != QLA_SUCCESS) {
838 fcport->flags &= ~FCF_ASYNC_SENT;
839 fcport->flags |= FCF_LOGIN_NEEDED;
840 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
841 goto done_free_sp;
842 }
843
844 ql_dbg(ql_dbg_disc, vha, 0x211b,
845 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n",
846 fcport->port_name, sp->handle, fcport->loop_id,
847 fcport->d_id.b24, fcport->login_retry);
848
849 return rval;
850
851done_free_sp:
852 sp->free(sp);
853 fcport->flags &= ~FCF_ASYNC_SENT;
854 return rval;
855}
856
Quinn Trana07fc0a2017-08-23 15:05:21 -0700857int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
Quinn Tran726b8542017-01-19 22:28:00 -0800858{
859 struct qla_work_evt *e;
860
861 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
862 if (!e)
863 return QLA_FUNCTION_FAILED;
864
865 e->u.fcport.fcport = fcport;
866 e->u.fcport.opt = opt;
867 return qla2x00_post_work(vha, e);
868}
869
870int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
871{
872 srb_t *sp;
873 struct srb_iocb *mbx;
874 int rval = QLA_FUNCTION_FAILED;
875 u16 *mb;
876 dma_addr_t pd_dma;
877 struct port_database_24xx *pd;
878 struct qla_hw_data *ha = vha->hw;
879
880 if (!vha->flags.online)
881 goto done;
882
883 fcport->flags |= FCF_ASYNC_SENT;
884 fcport->disc_state = DSC_GPDB;
885
886 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
887 if (!sp)
888 goto done;
889
Joe Carnuccioe0824e62017-08-23 15:05:08 -0700890 sp->type = SRB_MB_IOCB;
891 sp->name = "gpdb";
892 sp->gen1 = fcport->rscn_gen;
893 sp->gen2 = fcport->login_gen;
894 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
895
Thomas Meyer08eb7f42017-09-21 08:15:26 +0200896 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Quinn Tran726b8542017-01-19 22:28:00 -0800897 if (pd == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700898 ql_log(ql_log_warn, vha, 0xd043,
899 "Failed to allocate port database structure.\n");
Quinn Tran726b8542017-01-19 22:28:00 -0800900 goto done_free_sp;
901 }
Quinn Tran726b8542017-01-19 22:28:00 -0800902
Quinn Tran726b8542017-01-19 22:28:00 -0800903 mb = sp->u.iocb_cmd.u.mbx.out_mb;
904 mb[0] = MBC_GET_PORT_DATABASE;
905 mb[1] = fcport->loop_id;
906 mb[2] = MSW(pd_dma);
907 mb[3] = LSW(pd_dma);
908 mb[6] = MSW(MSD(pd_dma));
909 mb[7] = LSW(MSD(pd_dma));
910 mb[9] = vha->vp_idx;
911 mb[10] = opt;
912
913 mbx = &sp->u.iocb_cmd;
914 mbx->timeout = qla2x00_async_iocb_timeout;
915 mbx->u.mbx.in = (void *)pd;
916 mbx->u.mbx.in_dma = pd_dma;
917
918 sp->done = qla24xx_async_gpdb_sp_done;
919
920 rval = qla2x00_start_sp(sp);
921 if (rval != QLA_SUCCESS)
922 goto done_free_sp;
923
Quinn Tran83548fe2017-06-02 09:12:01 -0700924 ql_dbg(ql_dbg_disc, vha, 0x20dc,
925 "Async-%s %8phC hndl %x opt %x\n",
926 sp->name, fcport->port_name, sp->handle, opt);
Quinn Tran726b8542017-01-19 22:28:00 -0800927
928 return rval;
929
930done_free_sp:
931 if (pd)
932 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
933
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800934 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800935done:
936 fcport->flags &= ~FCF_ASYNC_SENT;
937 qla24xx_post_gpdb_work(vha, fcport, opt);
938 return rval;
939}
940
941static
942void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
943{
944 int rval = ea->rc;
945 fc_port_t *fcport = ea->fcport;
946 unsigned long flags;
947
948 fcport->flags &= ~FCF_ASYNC_SENT;
949
Quinn Tran83548fe2017-06-02 09:12:01 -0700950 ql_dbg(ql_dbg_disc, vha, 0x20d2,
Quinn Tran726b8542017-01-19 22:28:00 -0800951 "%s %8phC DS %d LS %d rval %d\n", __func__, fcport->port_name,
952 fcport->disc_state, fcport->fw_login_state, rval);
953
954 if (ea->sp->gen2 != fcport->login_gen) {
955 /* target side must have changed it. */
Quinn Tran83548fe2017-06-02 09:12:01 -0700956 ql_dbg(ql_dbg_disc, vha, 0x20d3,
Quinn Tran726b8542017-01-19 22:28:00 -0800957 "%s %8phC generation changed rscn %d|%d login %d|%d \n",
958 __func__, fcport->port_name, fcport->last_rscn_gen,
959 fcport->rscn_gen, fcport->last_login_gen,
960 fcport->login_gen);
Quinn Tran9b3e0f42017-12-28 12:33:16 -0800961 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Quinn Tran726b8542017-01-19 22:28:00 -0800962 return;
963 } else if (ea->sp->gen1 != fcport->rscn_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700964 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
Quinn Tran726b8542017-01-19 22:28:00 -0800965 __func__, __LINE__, fcport->port_name);
966 qla24xx_post_gidpn_work(vha, fcport);
967 return;
968 }
969
970 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700971 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
Quinn Tran726b8542017-01-19 22:28:00 -0800972 __func__, __LINE__, fcport->port_name);
973 qlt_schedule_sess_for_deletion_lock(fcport);
974 return;
975 }
976
977 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Tranf13515a2017-12-28 12:33:15 -0800978 ea->fcport->login_gen++;
Quinn Tran726b8542017-01-19 22:28:00 -0800979 ea->fcport->deleted = 0;
980 ea->fcport->logout_on_delete = 1;
981
982 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
983 vha->fcport_count++;
984 ea->fcport->login_succ = 1;
985
986 if (!IS_IIDMA_CAPABLE(vha->hw) ||
987 !vha->hw->flags.gpsc_supported) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700988 ql_dbg(ql_dbg_disc, vha, 0x20d6,
Quinn Tran726b8542017-01-19 22:28:00 -0800989 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
990 __func__, __LINE__, fcport->port_name,
991 vha->fcport_count);
992
993 qla24xx_post_upd_fcport_work(vha, fcport);
994 } else {
Quinn Tran83548fe2017-06-02 09:12:01 -0700995 ql_dbg(ql_dbg_disc, vha, 0x20d7,
Quinn Tran726b8542017-01-19 22:28:00 -0800996 "%s %d %8phC post gpsc fcp_cnt %d\n",
997 __func__, __LINE__, fcport->port_name,
998 vha->fcport_count);
999
1000 qla24xx_post_gpsc_work(vha, fcport);
1001 }
Quinn Tran414d9ff2017-12-04 14:45:03 -08001002 } else if (ea->fcport->login_succ) {
1003 /*
1004 * We have an existing session. A late RSCN delivery
1005 * must have triggered the session to be re-validate.
1006 * session is still valid.
1007 */
Quinn Tran5ef696a2017-12-04 14:45:05 -08001008 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1009 "%s %d %8phC session revalidate success\n",
1010 __func__, __LINE__, fcport->port_name);
Quinn Tran414d9ff2017-12-04 14:45:03 -08001011 fcport->disc_state = DSC_LOGIN_COMPLETE;
Quinn Tran726b8542017-01-19 22:28:00 -08001012 }
1013 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1014} /* gpdb event */
1015
1016int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1017{
Quinn Tranf13515a2017-12-28 12:33:15 -08001018 u16 data[2];
Quinn Tran726b8542017-01-19 22:28:00 -08001019 if (fcport->login_retry == 0)
1020 return 0;
1021
1022 if (fcport->scan_state != QLA_FCPORT_FOUND)
1023 return 0;
1024
Quinn Tran83548fe2017-06-02 09:12:01 -07001025 ql_dbg(ql_dbg_disc, vha, 0x20d8,
Quinn Tran726b8542017-01-19 22:28:00 -08001026 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d|%d retry %d lid %d\n",
1027 __func__, fcport->port_name, fcport->disc_state,
1028 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1029 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1030 fcport->last_login_gen, fcport->login_gen, fcport->login_retry,
1031 fcport->loop_id);
1032
1033 fcport->login_retry--;
1034
1035 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
Quinn Tran726b8542017-01-19 22:28:00 -08001036 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1037 return 0;
1038
Quinn Tran5b334692017-03-15 09:48:48 -07001039 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1040 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline))
1041 return 0;
1042 }
1043
Quinn Tran726b8542017-01-19 22:28:00 -08001044 /* for pure Target Mode. Login will not be initiated */
1045 if (vha->host->active_mode == MODE_TARGET)
1046 return 0;
1047
1048 if (fcport->flags & FCF_ASYNC_SENT) {
1049 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1050 return 0;
1051 }
1052
1053 switch (fcport->disc_state) {
1054 case DSC_DELETED:
1055 if (fcport->loop_id == FC_NO_LOOP_ID) {
Quinn Tran83548fe2017-06-02 09:12:01 -07001056 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1057 "%s %d %8phC post gnl\n",
1058 __func__, __LINE__, fcport->port_name);
Giridhar Malavali5d3300a2017-12-04 14:45:13 -08001059 qla24xx_post_gnl_work(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08001060 } else {
Quinn Tran83548fe2017-06-02 09:12:01 -07001061 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1062 "%s %d %8phC post login\n",
1063 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -08001064 fcport->disc_state = DSC_LOGIN_PEND;
1065 qla2x00_post_async_login_work(vha, fcport, NULL);
1066 }
1067 break;
1068
1069 case DSC_GNL:
1070 if (fcport->login_pause) {
1071 fcport->last_rscn_gen = fcport->rscn_gen;
1072 fcport->last_login_gen = fcport->login_gen;
1073 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1074 break;
1075 }
1076
Quinn Tranf13515a2017-12-28 12:33:15 -08001077 ql_dbg(ql_dbg_disc, vha, 0x20cf,
1078 "%s %d %8phC post login\n",
1079 __func__, __LINE__, fcport->port_name);
1080 fcport->disc_state = DSC_LOGIN_PEND;
1081 qla2x00_post_async_login_work(vha, fcport, NULL);
Quinn Tran726b8542017-01-19 22:28:00 -08001082 break;
1083
1084 case DSC_LOGIN_FAILED:
Quinn Tran83548fe2017-06-02 09:12:01 -07001085 ql_dbg(ql_dbg_disc, vha, 0x20d0,
1086 "%s %d %8phC post gidpn\n",
1087 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -08001088
1089 qla24xx_post_gidpn_work(vha, fcport);
1090 break;
1091
1092 case DSC_LOGIN_COMPLETE:
1093 /* recheck login state */
Quinn Tran83548fe2017-06-02 09:12:01 -07001094 ql_dbg(ql_dbg_disc, vha, 0x20d1,
Quinn Tranf13515a2017-12-28 12:33:15 -08001095 "%s %d %8phC post adisc\n",
Quinn Tran83548fe2017-06-02 09:12:01 -07001096 __func__, __LINE__, fcport->port_name);
Quinn Tranf13515a2017-12-28 12:33:15 -08001097 data[0] = data[1] = 0;
1098 qla2x00_post_async_adisc_work(vha, fcport, data);
Quinn Tran726b8542017-01-19 22:28:00 -08001099 break;
1100
1101 default:
1102 break;
1103 }
1104
1105 return 0;
1106}
1107
1108static
1109void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea)
1110{
1111 fcport->rscn_gen++;
1112
Quinn Tran83548fe2017-06-02 09:12:01 -07001113 ql_dbg(ql_dbg_disc, fcport->vha, 0x210c,
1114 "%s %8phC DS %d LS %d\n",
1115 __func__, fcport->port_name, fcport->disc_state,
1116 fcport->fw_login_state);
Quinn Tran726b8542017-01-19 22:28:00 -08001117
1118 if (fcport->flags & FCF_ASYNC_SENT)
1119 return;
1120
1121 switch (fcport->disc_state) {
1122 case DSC_DELETED:
1123 case DSC_LOGIN_COMPLETE:
Quinn Tran5ef696a2017-12-04 14:45:05 -08001124 qla24xx_post_gpnid_work(fcport->vha, &ea->id);
Quinn Tran726b8542017-01-19 22:28:00 -08001125 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001126 default:
1127 break;
1128 }
1129}
1130
1131int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1132 u8 *port_name, void *pla)
1133{
1134 struct qla_work_evt *e;
1135 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1136 if (!e)
1137 return QLA_FUNCTION_FAILED;
1138
1139 e->u.new_sess.id = *id;
1140 e->u.new_sess.pla = pla;
1141 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1142
1143 return qla2x00_post_work(vha, e);
1144}
1145
1146static
1147int qla24xx_handle_delete_done_event(scsi_qla_host_t *vha,
1148 struct event_arg *ea)
1149{
1150 fc_port_t *fcport = ea->fcport;
1151
1152 if (test_bit(UNLOADING, &vha->dpc_flags))
1153 return 0;
1154
1155 switch (vha->host->active_mode) {
1156 case MODE_INITIATOR:
1157 case MODE_DUAL:
1158 if (fcport->scan_state == QLA_FCPORT_FOUND)
1159 qla24xx_fcport_handle_login(vha, fcport);
1160 break;
1161
1162 case MODE_TARGET:
1163 default:
1164 /* no-op */
1165 break;
1166 }
1167
1168 return 0;
1169}
1170
1171static
1172void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1173 struct event_arg *ea)
1174{
1175 fc_port_t *fcport = ea->fcport;
1176
1177 if (fcport->scan_state != QLA_FCPORT_FOUND) {
1178 fcport->login_retry++;
1179 return;
1180 }
1181
Quinn Tran83548fe2017-06-02 09:12:01 -07001182 ql_dbg(ql_dbg_disc, vha, 0x2102,
1183 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1184 __func__, fcport->port_name, fcport->disc_state,
1185 fcport->fw_login_state, fcport->login_pause,
1186 fcport->deleted, fcport->conflict,
1187 fcport->last_rscn_gen, fcport->rscn_gen,
1188 fcport->last_login_gen, fcport->login_gen,
1189 fcport->flags);
Quinn Tran726b8542017-01-19 22:28:00 -08001190
1191 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
Quinn Tran726b8542017-01-19 22:28:00 -08001192 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1193 return;
1194
Quinn Tran5b334692017-03-15 09:48:48 -07001195 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1196 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline))
1197 return;
1198 }
1199
Quinn Tran726b8542017-01-19 22:28:00 -08001200 if (fcport->flags & FCF_ASYNC_SENT) {
1201 fcport->login_retry++;
1202 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1203 return;
1204 }
1205
1206 if (fcport->disc_state == DSC_DELETE_PEND) {
1207 fcport->login_retry++;
1208 return;
1209 }
1210
1211 if (fcport->last_rscn_gen != fcport->rscn_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -07001212 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n",
Quinn Tran726b8542017-01-19 22:28:00 -08001213 __func__, __LINE__, fcport->port_name);
1214
Giridhar Malavali5d3300a2017-12-04 14:45:13 -08001215 qla24xx_post_gidpn_work(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08001216 return;
1217 }
1218
1219 qla24xx_fcport_handle_login(vha, fcport);
1220}
1221
Quinn Tran41dc5292017-01-19 22:28:03 -08001222void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
Quinn Tran726b8542017-01-19 22:28:00 -08001223{
Quinn Tran41dc5292017-01-19 22:28:03 -08001224 fc_port_t *fcport, *f, *tf;
1225 uint32_t id = 0, mask, rid;
Quinn Tran726b8542017-01-19 22:28:00 -08001226 int rc;
1227
1228 switch (ea->event) {
1229 case FCME_RELOGIN:
Quinn Tranb98ae0d2017-06-02 09:12:00 -07001230 case FCME_RSCN:
1231 case FCME_GIDPN_DONE:
1232 case FCME_GPSC_DONE:
1233 case FCME_GPNID_DONE:
1234 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
1235 test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))
1236 return;
1237 break;
1238 default:
1239 break;
1240 }
1241
1242 switch (ea->event) {
1243 case FCME_RELOGIN:
Quinn Tran726b8542017-01-19 22:28:00 -08001244 if (test_bit(UNLOADING, &vha->dpc_flags))
1245 return;
1246
1247 qla24xx_handle_relogin_event(vha, ea);
1248 break;
1249 case FCME_RSCN:
1250 if (test_bit(UNLOADING, &vha->dpc_flags))
1251 return;
Quinn Tran41dc5292017-01-19 22:28:03 -08001252 switch (ea->id.b.rsvd_1) {
1253 case RSCN_PORT_ADDR:
1254 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1255 if (!fcport) {
1256 /* cable moved */
1257 rc = qla24xx_post_gpnid_work(vha, &ea->id);
1258 if (rc) {
Quinn Tran83548fe2017-06-02 09:12:01 -07001259 ql_log(ql_log_warn, vha, 0xd044,
1260 "RSCN GPNID work failed %02x%02x%02x\n",
1261 ea->id.b.domain, ea->id.b.area,
1262 ea->id.b.al_pa);
Quinn Tran41dc5292017-01-19 22:28:03 -08001263 }
1264 } else {
1265 ea->fcport = fcport;
1266 qla24xx_handle_rscn_event(fcport, ea);
Quinn Tran726b8542017-01-19 22:28:00 -08001267 }
Quinn Tran41dc5292017-01-19 22:28:03 -08001268 break;
1269 case RSCN_AREA_ADDR:
1270 case RSCN_DOM_ADDR:
1271 if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) {
1272 mask = 0xffff00;
Quinn Tran83548fe2017-06-02 09:12:01 -07001273 ql_dbg(ql_dbg_async, vha, 0x5044,
1274 "RSCN: Area 0x%06x was affected\n",
1275 ea->id.b24);
Quinn Tran41dc5292017-01-19 22:28:03 -08001276 } else {
1277 mask = 0xff0000;
Quinn Tran83548fe2017-06-02 09:12:01 -07001278 ql_dbg(ql_dbg_async, vha, 0x507a,
1279 "RSCN: Domain 0x%06x was affected\n",
1280 ea->id.b24);
Quinn Tran41dc5292017-01-19 22:28:03 -08001281 }
1282
1283 rid = ea->id.b24 & mask;
1284 list_for_each_entry_safe(f, tf, &vha->vp_fcports,
1285 list) {
1286 id = f->d_id.b24 & mask;
1287 if (rid == id) {
1288 ea->fcport = f;
1289 qla24xx_handle_rscn_event(f, ea);
1290 }
1291 }
1292 break;
1293 case RSCN_FAB_ADDR:
1294 default:
Quinn Tran83548fe2017-06-02 09:12:01 -07001295 ql_log(ql_log_warn, vha, 0xd045,
1296 "RSCN: Fabric was affected. Addr format %d\n",
1297 ea->id.b.rsvd_1);
Quinn Tran41dc5292017-01-19 22:28:03 -08001298 qla2x00_mark_all_devices_lost(vha, 1);
1299 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1300 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Quinn Tran726b8542017-01-19 22:28:00 -08001301 }
1302 break;
1303 case FCME_GIDPN_DONE:
1304 qla24xx_handle_gidpn_event(vha, ea);
1305 break;
1306 case FCME_GNL_DONE:
1307 qla24xx_handle_gnl_done_event(vha, ea);
1308 break;
1309 case FCME_GPSC_DONE:
1310 qla24xx_post_upd_fcport_work(vha, ea->fcport);
1311 break;
1312 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1313 qla24xx_handle_plogi_done_event(vha, ea);
1314 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001315 case FCME_PRLI_DONE:
1316 qla24xx_handle_prli_done_event(vha, ea);
1317 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001318 case FCME_GPDB_DONE:
1319 qla24xx_handle_gpdb_event(vha, ea);
1320 break;
1321 case FCME_GPNID_DONE:
1322 qla24xx_handle_gpnid_event(vha, ea);
1323 break;
Duane Grigsbyd3bae932017-06-21 13:48:44 -07001324 case FCME_GFFID_DONE:
1325 qla24xx_handle_gffid_event(vha, ea);
1326 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001327 case FCME_DELETE_DONE:
1328 qla24xx_handle_delete_done_event(vha, ea);
1329 break;
Quinn Tranf13515a2017-12-28 12:33:15 -08001330 case FCME_ADISC_DONE:
1331 qla24xx_handle_adisc_event(vha, ea);
1332 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001333 default:
1334 BUG_ON(1);
1335 break;
1336 }
1337}
1338
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001339static void
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001340qla2x00_tmf_iocb_timeout(void *data)
1341{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001342 srb_t *sp = data;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001343 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1344
1345 tmf->u.tmf.comp_status = CS_TIMEOUT;
1346 complete(&tmf->u.tmf.comp);
1347}
1348
1349static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001350qla2x00_tmf_sp_done(void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001351{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001352 srb_t *sp = ptr;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001353 struct srb_iocb *tmf = &sp->u.iocb_cmd;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001354
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001355 complete(&tmf->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001356}
1357
1358int
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001359qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001360 uint32_t tag)
1361{
1362 struct scsi_qla_host *vha = fcport->vha;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001363 struct srb_iocb *tm_iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001364 srb_t *sp;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001365 int rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001366
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001367 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001368 if (!sp)
1369 goto done;
1370
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001371 tm_iocb = &sp->u.iocb_cmd;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001372 sp->type = SRB_TM_CMD;
1373 sp->name = "tmf";
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001374 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1375 tm_iocb->u.tmf.flags = flags;
1376 tm_iocb->u.tmf.lun = lun;
1377 tm_iocb->u.tmf.data = tag;
1378 sp->done = qla2x00_tmf_sp_done;
1379 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1380 init_completion(&tm_iocb->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001381
1382 rval = qla2x00_start_sp(sp);
1383 if (rval != QLA_SUCCESS)
1384 goto done_free_sp;
1385
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001386 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001387 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1388 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1389 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001390
1391 wait_for_completion(&tm_iocb->u.tmf.comp);
1392
1393 rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
1394 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1395
1396 if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
1397 ql_dbg(ql_dbg_taskm, vha, 0x8030,
1398 "TM IOCB failed (%x).\n", rval);
1399 }
1400
1401 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1402 flags = tm_iocb->u.tmf.flags;
1403 lun = (uint16_t)tm_iocb->u.tmf.lun;
1404
1405 /* Issue Marker IOCB */
1406 qla2x00_marker(vha, vha->hw->req_q_map[0],
1407 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
1408 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1409 }
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001410
1411done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001412 sp->free(sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001413done:
1414 return rval;
1415}
1416
Armen Baloyan4440e462014-02-26 04:15:18 -05001417static void
1418qla24xx_abort_iocb_timeout(void *data)
1419{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001420 srb_t *sp = data;
Armen Baloyan4440e462014-02-26 04:15:18 -05001421 struct srb_iocb *abt = &sp->u.iocb_cmd;
1422
1423 abt->u.abt.comp_status = CS_TIMEOUT;
1424 complete(&abt->u.abt.comp);
1425}
1426
1427static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001428qla24xx_abort_sp_done(void *ptr, int res)
Armen Baloyan4440e462014-02-26 04:15:18 -05001429{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001430 srb_t *sp = ptr;
Armen Baloyan4440e462014-02-26 04:15:18 -05001431 struct srb_iocb *abt = &sp->u.iocb_cmd;
1432
1433 complete(&abt->u.abt.comp);
1434}
1435
Quinn Tran15f30a52017-03-15 09:48:52 -07001436int
Armen Baloyan4440e462014-02-26 04:15:18 -05001437qla24xx_async_abort_cmd(srb_t *cmd_sp)
1438{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001439 scsi_qla_host_t *vha = cmd_sp->vha;
Armen Baloyan4440e462014-02-26 04:15:18 -05001440 fc_port_t *fcport = cmd_sp->fcport;
1441 struct srb_iocb *abt_iocb;
1442 srb_t *sp;
1443 int rval = QLA_FUNCTION_FAILED;
1444
1445 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1446 if (!sp)
1447 goto done;
1448
1449 abt_iocb = &sp->u.iocb_cmd;
1450 sp->type = SRB_ABT_CMD;
1451 sp->name = "abort";
1452 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1453 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
1454 sp->done = qla24xx_abort_sp_done;
1455 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
1456 init_completion(&abt_iocb->u.abt.comp);
1457
1458 rval = qla2x00_start_sp(sp);
1459 if (rval != QLA_SUCCESS)
1460 goto done_free_sp;
1461
1462 ql_dbg(ql_dbg_async, vha, 0x507c,
1463 "Abort command issued - hdl=%x, target_id=%x\n",
1464 cmd_sp->handle, fcport->tgt_id);
1465
1466 wait_for_completion(&abt_iocb->u.abt.comp);
1467
1468 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
1469 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1470
1471done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001472 sp->free(sp);
Armen Baloyan4440e462014-02-26 04:15:18 -05001473done:
1474 return rval;
1475}
1476
1477int
1478qla24xx_async_abort_command(srb_t *sp)
1479{
1480 unsigned long flags = 0;
1481
1482 uint32_t handle;
1483 fc_port_t *fcport = sp->fcport;
1484 struct scsi_qla_host *vha = fcport->vha;
1485 struct qla_hw_data *ha = vha->hw;
1486 struct req_que *req = vha->req;
1487
1488 spin_lock_irqsave(&ha->hardware_lock, flags);
1489 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1490 if (req->outstanding_cmds[handle] == sp)
1491 break;
1492 }
1493 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1494 if (handle == req->num_outstanding_cmds) {
1495 /* Command not found. */
1496 return QLA_FUNCTION_FAILED;
1497 }
1498 if (sp->type == SRB_FXIOCB_DCMD)
1499 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1500 FXDISC_ABORT_IOCTL);
1501
1502 return qla24xx_async_abort_cmd(sp);
1503}
1504
Quinn Tran726b8542017-01-19 22:28:00 -08001505static void
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001506qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1507{
1508 switch (ea->data[0]) {
1509 case MBS_COMMAND_COMPLETE:
1510 ql_dbg(ql_dbg_disc, vha, 0x2118,
1511 "%s %d %8phC post gpdb\n",
1512 __func__, __LINE__, ea->fcport->port_name);
1513
1514 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1515 ea->fcport->logout_on_delete = 1;
1516 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1517 break;
1518 default:
Duane Grigsbyedd05de2017-10-13 09:34:06 -07001519 if (ea->fcport->n2n_flag) {
1520 ql_dbg(ql_dbg_disc, vha, 0x2118,
1521 "%s %d %8phC post fc4 prli\n",
1522 __func__, __LINE__, ea->fcport->port_name);
1523 ea->fcport->fc4f_nvme = 0;
1524 ea->fcport->n2n_flag = 0;
1525 qla24xx_post_prli_work(vha, ea->fcport);
1526 }
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001527 ql_dbg(ql_dbg_disc, vha, 0x2119,
1528 "%s %d %8phC unhandle event of %x\n",
1529 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1530 break;
1531 }
1532}
1533
1534static void
Quinn Tran726b8542017-01-19 22:28:00 -08001535qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001536{
Quinn Tran726b8542017-01-19 22:28:00 -08001537 port_id_t cid; /* conflict Nport id */
Quinn Trana084fd62017-12-04 14:45:00 -08001538 u16 lid;
1539 struct fc_port *conflict_fcport;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001540
Quinn Tran726b8542017-01-19 22:28:00 -08001541 switch (ea->data[0]) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07001542 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -07001543 /*
1544 * Driver must validate login state - If PRLI not complete,
1545 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1546 * requests.
1547 */
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001548 if (ea->fcport->fc4f_nvme) {
1549 ql_dbg(ql_dbg_disc, vha, 0x2117,
1550 "%s %d %8phC post prli\n",
1551 __func__, __LINE__, ea->fcport->port_name);
1552 qla24xx_post_prli_work(vha, ea->fcport);
1553 } else {
1554 ql_dbg(ql_dbg_disc, vha, 0x20ea,
Quinn Trana084fd62017-12-04 14:45:00 -08001555 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1556 __func__, __LINE__, ea->fcport->port_name,
1557 ea->fcport->loop_id, ea->fcport->d_id.b24);
1558
1559 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1560 ea->fcport->loop_id = FC_NO_LOOP_ID;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001561 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1562 ea->fcport->logout_on_delete = 1;
Quinn Tran35158322017-08-30 10:16:50 -07001563 ea->fcport->send_els_logo = 0;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001564 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1565 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001566 break;
1567 case MBS_COMMAND_ERROR:
Quinn Tran83548fe2017-06-02 09:12:01 -07001568 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
Quinn Tran726b8542017-01-19 22:28:00 -08001569 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
1570
1571 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1572 ea->fcport->disc_state = DSC_LOGIN_FAILED;
1573 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001574 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1575 else
Quinn Tran726b8542017-01-19 22:28:00 -08001576 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001577 break;
1578 case MBS_LOOP_ID_USED:
Quinn Tran726b8542017-01-19 22:28:00 -08001579 /* data[1] = IO PARAM 1 = nport ID */
1580 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
1581 cid.b.area = (ea->iop[1] >> 8) & 0xff;
1582 cid.b.al_pa = ea->iop[1] & 0xff;
1583 cid.b.rsvd_1 = 0;
1584
Quinn Tran83548fe2017-06-02 09:12:01 -07001585 ql_dbg(ql_dbg_disc, vha, 0x20ec,
1586 "%s %d %8phC LoopID 0x%x in use post gnl\n",
1587 __func__, __LINE__, ea->fcport->port_name,
1588 ea->fcport->loop_id);
Quinn Tran726b8542017-01-19 22:28:00 -08001589
1590 if (IS_SW_RESV_ADDR(cid)) {
1591 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1592 ea->fcport->loop_id = FC_NO_LOOP_ID;
1593 } else {
1594 qla2x00_clear_loop_id(ea->fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001595 }
Quinn Tran726b8542017-01-19 22:28:00 -08001596 qla24xx_post_gnl_work(vha, ea->fcport);
1597 break;
1598 case MBS_PORT_ID_USED:
Quinn Tran83548fe2017-06-02 09:12:01 -07001599 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1600 "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n",
1601 __func__, __LINE__, ea->fcport->port_name,
1602 ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area,
1603 ea->fcport->d_id.b.al_pa);
Quinn Tran726b8542017-01-19 22:28:00 -08001604
Quinn Trana084fd62017-12-04 14:45:00 -08001605 lid = ea->iop[1] & 0xffff;
1606 qlt_find_sess_invalidate_other(vha,
1607 wwn_to_u64(ea->fcport->port_name),
1608 ea->fcport->d_id, lid, &conflict_fcport);
1609
1610 if (conflict_fcport) {
1611 /*
1612 * Another fcport share the same loop_id/nport id.
1613 * Conflict fcport needs to finish cleanup before this
1614 * fcport can proceed to login.
1615 */
1616 conflict_fcport->conflict = ea->fcport;
1617 ea->fcport->login_pause = 1;
1618
1619 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1620 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
1621 __func__, __LINE__, ea->fcport->port_name,
1622 ea->fcport->d_id.b24, lid);
1623 qla2x00_clear_loop_id(ea->fcport);
1624 qla24xx_post_gidpn_work(vha, ea->fcport);
1625 } else {
1626 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1627 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
1628 __func__, __LINE__, ea->fcport->port_name,
1629 ea->fcport->d_id.b24, lid);
1630
1631 qla2x00_clear_loop_id(ea->fcport);
1632 set_bit(lid, vha->hw->loop_id_map);
1633 ea->fcport->loop_id = lid;
1634 ea->fcport->keep_nport_handle = 0;
1635 qlt_schedule_sess_for_deletion(ea->fcport, false);
1636 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001637 break;
1638 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001639 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001640}
1641
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001642void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001643qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1644 uint16_t *data)
1645{
Quinn Tran726b8542017-01-19 22:28:00 -08001646 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Alexei Potashnika6ca8872015-07-14 16:00:44 -04001647 qlt_logo_completion_handler(fcport, data[0]);
Quinn Tran726b8542017-01-19 22:28:00 -08001648 fcport->login_gen++;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001649 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001650}
1651
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001652void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001653qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1654 uint16_t *data)
1655{
1656 if (data[0] == MBS_COMMAND_COMPLETE) {
1657 qla2x00_update_fcport(vha, fcport);
1658
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001659 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001660 }
1661
1662 /* Retry login. */
1663 fcport->flags &= ~FCF_ASYNC_SENT;
1664 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
1665 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1666 else
Andrew Vasquez80d79442011-03-30 11:46:17 -07001667 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001668
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001669 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001670}
1671
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672/****************************************************************************/
1673/* QLogic ISP2x00 Hardware Support Functions. */
1674/****************************************************************************/
1675
Saurav Kashyapfa492632012-11-21 02:40:29 -05001676static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001677qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
1678{
1679 int rval = QLA_SUCCESS;
1680 struct qla_hw_data *ha = vha->hw;
1681 uint32_t idc_major_ver, idc_minor_ver;
Saurav Kashyap711aa7f2012-08-22 14:21:15 -04001682 uint16_t config[4];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001683
1684 qla83xx_idc_lock(vha, 0);
1685
1686 /* SV: TODO: Assign initialization timeout from
1687 * flash-info / other param
1688 */
1689 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
1690 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
1691
1692 /* Set our fcoe function presence */
1693 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
1694 ql_dbg(ql_dbg_p3p, vha, 0xb077,
1695 "Error while setting DRV-Presence.\n");
1696 rval = QLA_FUNCTION_FAILED;
1697 goto exit;
1698 }
1699
1700 /* Decide the reset ownership */
1701 qla83xx_reset_ownership(vha);
1702
1703 /*
1704 * On first protocol driver load:
1705 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
1706 * register.
1707 * Others: Check compatibility with current IDC Major version.
1708 */
1709 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
1710 if (ha->flags.nic_core_reset_owner) {
1711 /* Set IDC Major version */
1712 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
1713 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
1714
1715 /* Clearing IDC-Lock-Recovery register */
1716 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
1717 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
1718 /*
1719 * Clear further IDC participation if we are not compatible with
1720 * the current IDC Major Version.
1721 */
1722 ql_log(ql_log_warn, vha, 0xb07d,
1723 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
1724 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
1725 __qla83xx_clear_drv_presence(vha);
1726 rval = QLA_FUNCTION_FAILED;
1727 goto exit;
1728 }
1729 /* Each function sets its supported Minor version. */
1730 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
1731 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
1732 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
1733
Saurav Kashyap711aa7f2012-08-22 14:21:15 -04001734 if (ha->flags.nic_core_reset_owner) {
1735 memset(config, 0, sizeof(config));
1736 if (!qla81xx_get_port_config(vha, config))
1737 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
1738 QLA8XXX_DEV_READY);
1739 }
1740
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001741 rval = qla83xx_idc_state_handler(vha);
1742
1743exit:
1744 qla83xx_idc_unlock(vha, 0);
1745
1746 return rval;
1747}
1748
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749/*
1750* qla2x00_initialize_adapter
1751* Initialize board.
1752*
1753* Input:
1754* ha = adapter block pointer.
1755*
1756* Returns:
1757* 0 = success
1758*/
1759int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001760qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761{
1762 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001763 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001764 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001765
Joe Carnucciofc90ada2016-07-06 11:14:23 -04001766 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
1767 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
1768
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001770 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001771 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001772 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -08001773 ha->flags.pci_channel_io_perm_failure = 0;
1774 ha->flags.eeh_busy = 0;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -04001775 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001776 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1777 atomic_set(&vha->loop_state, LOOP_DOWN);
1778 vha->device_flags = DFLG_NO_CABLE;
1779 vha->dpc_flags = 0;
1780 vha->flags.management_server_logged_in = 0;
1781 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 ha->isp_abort_cnt = 0;
1783 ha->beacon_blink_led = 0;
1784
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001785 set_bit(0, ha->req_qid_map);
1786 set_bit(0, ha->rsp_qid_map);
1787
Chad Dupuiscfb09192011-11-18 09:03:07 -08001788 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001789 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001790 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001792 ql_log(ql_log_warn, vha, 0x0044,
1793 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 return (rval);
1795 }
1796
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001797 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001799 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001800 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001801 ql_log(ql_log_fatal, vha, 0x004f,
1802 "Unable to validate FLASH data.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001803 return rval;
1804 }
1805
1806 if (IS_QLA8044(ha)) {
1807 qla8044_read_reset_template(vha);
1808
1809 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
1810 * If DONRESET_BIT0 is set, drivers should not set dev_state
1811 * to NEED_RESET. But if NEED_RESET is set, drivers should
1812 * should honor the reset. */
1813 if (ql2xdontresethba == 1)
1814 qla8044_set_idc_dontreset(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001815 }
1816
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001817 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001818 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001819 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001820
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001821 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001823 if (ha->flags.disable_serdes) {
1824 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001825 ql_log(ql_log_info, vha, 0x0077,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001826 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001827 return QLA_FUNCTION_FAILED;
1828 }
1829
Chad Dupuiscfb09192011-11-18 09:03:07 -08001830 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001831 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001833 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
1834 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001835 if (rval)
1836 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001837 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001838 if (rval)
1839 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07001841
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001842 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001843 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001844 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001845 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001846 "Unable to configure ISP84XX.\n");
1847 return QLA_FUNCTION_FAILED;
1848 }
1849 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001850
Quinn Tranead03852017-01-19 22:28:01 -08001851 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001852 rval = qla2x00_init_rings(vha);
1853
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001854 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001856 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001857 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001858 rval = qla84xx_init_chip(vha);
1859 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001860 ql_log(ql_log_warn, vha, 0x00d4,
1861 "Unable to initialize ISP84XX.\n");
Bart Van Assche8d2b21d2015-06-04 15:58:09 -07001862 qla84xx_put_chip(vha);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001863 }
1864 }
1865
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001866 /* Load the NIC Core f/w if we are the first protocol driver. */
1867 if (IS_QLA8031(ha)) {
1868 rval = qla83xx_nic_core_fw_load(vha);
1869 if (rval)
1870 ql_log(ql_log_warn, vha, 0x0124,
1871 "Error in initializing NIC Core f/w.\n");
1872 }
1873
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +05001874 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
1875 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -07001876
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04001877 if (IS_P3P_TYPE(ha))
1878 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
1879 else
1880 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
1881
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 return (rval);
1883}
1884
1885/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001886 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 * @ha: HA context
1888 *
1889 * Returns 0 on success.
1890 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001891int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001892qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001894 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001895 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001896 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001897 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001900 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001903 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1905
Andrew Vasquez737faec2008-10-24 15:13:45 -07001906 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001908 /* Get PCI bus information. */
1909 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07001910 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001911 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1912
1913 return QLA_SUCCESS;
1914}
1915
1916/**
1917 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
1918 * @ha: HA context
1919 *
1920 * Returns 0 on success.
1921 */
1922int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001923qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001924{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001925 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001926 unsigned long flags = 0;
1927 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001928 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001929 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001930
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001931 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001932 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001933
1934 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001935 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001936
1937 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1938 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -07001939 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001940
1941 /*
1942 * If this is a 2300 card and not 2312, reset the
1943 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
1944 * the 2310 also reports itself as a 2300 so we need to get the
1945 * fb revision level -- a 6 indicates it really is a 2300 and
1946 * not a 2310.
1947 */
1948 if (IS_QLA2300(ha)) {
1949 spin_lock_irqsave(&ha->hardware_lock, flags);
1950
1951 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001952 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001953 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07001954 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001955 break;
1956
1957 udelay(10);
1958 }
1959
1960 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001961 WRT_REG_WORD(&reg->ctrl_status, 0x20);
1962 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001963
1964 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001965 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001966
1967 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -07001968 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001969
1970 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001971 WRT_REG_WORD(&reg->ctrl_status, 0x0);
1972 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001973
1974 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001975 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001976 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07001977 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001978 break;
1979
1980 udelay(10);
1981 }
1982
1983 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1984 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001985
1986 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
1987
Andrew Vasquez737faec2008-10-24 15:13:45 -07001988 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001989
1990 /* Get PCI bus information. */
1991 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07001992 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001993 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1994
1995 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996}
1997
1998/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001999 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2000 * @ha: HA context
2001 *
2002 * Returns 0 on success.
2003 */
2004int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002005qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002006{
Andrew Vasqueza157b102007-05-07 07:43:01 -07002007 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002008 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002009 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002010 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002011
2012 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07002013 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002014
2015 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07002016 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002017 w &= ~PCI_COMMAND_INTX_DISABLE;
2018 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2019
2020 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2021
2022 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -07002023 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2024 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002025
2026 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07002027 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04002028 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002029
Andrew Vasquez737faec2008-10-24 15:13:45 -07002030 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002031
Auke Kok44c10132007-06-08 15:46:36 -07002032 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002033
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002034 /* Get PCI bus information. */
2035 spin_lock_irqsave(&ha->hardware_lock, flags);
2036 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
2037 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2038
2039 return QLA_SUCCESS;
2040}
2041
2042/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002043 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2044 * @ha: HA context
2045 *
2046 * Returns 0 on success.
2047 */
2048int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002049qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002050{
2051 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002053
2054 pci_set_master(ha->pdev);
2055 pci_try_set_mwi(ha->pdev);
2056
2057 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2058 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2059 w &= ~PCI_COMMAND_INTX_DISABLE;
2060 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2061
2062 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07002063 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04002064 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002065
Andrew Vasquez737faec2008-10-24 15:13:45 -07002066 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002067
2068 ha->chip_revision = ha->pdev->revision;
2069
2070 return QLA_SUCCESS;
2071}
2072
2073/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 * qla2x00_isp_firmware() - Choose firmware image.
2075 * @ha: HA context
2076 *
2077 * Returns 0 on success.
2078 */
2079static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002080qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081{
2082 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07002083 uint16_t loop_id, topo, sw_cap;
2084 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002085 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086
2087 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002088 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089
2090 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002091 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092
2093 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002094 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -07002095 if (rval == QLA_SUCCESS) {
2096 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002097 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -07002098 &area, &domain, &topo, &sw_cap);
2099 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 }
2101
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002102 if (rval)
2103 ql_dbg(ql_dbg_init, vha, 0x007a,
2104 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105
2106 return (rval);
2107}
2108
2109/**
2110 * qla2x00_reset_chip() - Reset ISP chip.
2111 * @ha: HA context
2112 *
2113 * Returns 0 on success.
2114 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002115void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002116qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117{
2118 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002119 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002120 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 uint16_t cmd;
2123
Andrew Vasquez85880802009-12-15 21:29:46 -08002124 if (unlikely(pci_channel_offline(ha->pdev)))
2125 return;
2126
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002127 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128
2129 spin_lock_irqsave(&ha->hardware_lock, flags);
2130
2131 /* Turn off master enable */
2132 cmd = 0;
2133 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2134 cmd &= ~PCI_COMMAND_MASTER;
2135 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2136
2137 if (!IS_QLA2100(ha)) {
2138 /* Pause RISC. */
2139 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
2140 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2141 for (cnt = 0; cnt < 30000; cnt++) {
2142 if ((RD_REG_WORD(&reg->hccr) &
2143 HCCR_RISC_PAUSE) != 0)
2144 break;
2145 udelay(100);
2146 }
2147 } else {
2148 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2149 udelay(10);
2150 }
2151
2152 /* Select FPM registers. */
2153 WRT_REG_WORD(&reg->ctrl_status, 0x20);
2154 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2155
2156 /* FPM Soft Reset. */
2157 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
2158 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
2159
2160 /* Toggle Fpm Reset. */
2161 if (!IS_QLA2200(ha)) {
2162 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
2163 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
2164 }
2165
2166 /* Select frame buffer registers. */
2167 WRT_REG_WORD(&reg->ctrl_status, 0x10);
2168 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2169
2170 /* Reset frame buffer FIFOs. */
2171 if (IS_QLA2200(ha)) {
2172 WRT_FB_CMD_REG(ha, reg, 0xa000);
2173 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2174 } else {
2175 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2176
2177 /* Read back fb_cmd until zero or 3 seconds max */
2178 for (cnt = 0; cnt < 3000; cnt++) {
2179 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2180 break;
2181 udelay(100);
2182 }
2183 }
2184
2185 /* Select RISC module registers. */
2186 WRT_REG_WORD(&reg->ctrl_status, 0);
2187 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2188
2189 /* Reset RISC processor. */
2190 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2191 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2192
2193 /* Release RISC processor. */
2194 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2195 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2196 }
2197
2198 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
2199 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
2200
2201 /* Reset ISP chip. */
2202 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
2203
2204 /* Wait for RISC to recover from reset. */
2205 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2206 /*
2207 * It is necessary to for a delay here since the card doesn't
2208 * respond to PCI reads during a reset. On some architectures
2209 * this will result in an MCA.
2210 */
2211 udelay(20);
2212 for (cnt = 30000; cnt; cnt--) {
2213 if ((RD_REG_WORD(&reg->ctrl_status) &
2214 CSR_ISP_SOFT_RESET) == 0)
2215 break;
2216 udelay(100);
2217 }
2218 } else
2219 udelay(10);
2220
2221 /* Reset RISC processor. */
2222 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2223
2224 WRT_REG_WORD(&reg->semaphore, 0);
2225
2226 /* Release RISC processor. */
2227 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2228 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2229
2230 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2231 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -07002232 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234
2235 udelay(100);
2236 }
2237 } else
2238 udelay(100);
2239
2240 /* Turn on master enable */
2241 cmd |= PCI_COMMAND_MASTER;
2242 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2243
2244 /* Disable RISC pause on FPM parity error. */
2245 if (!IS_QLA2100(ha)) {
2246 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
2247 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2248 }
2249
2250 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2251}
2252
2253/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002254 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2255 *
2256 * Returns 0 on success.
2257 */
Saurav Kashyapfa492632012-11-21 02:40:29 -05002258static int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002259qla81xx_reset_mpi(scsi_qla_host_t *vha)
2260{
2261 uint16_t mb[4] = {0x1010, 0, 1, 0};
2262
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002263 if (!IS_QLA81XX(vha->hw))
2264 return QLA_SUCCESS;
2265
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002266 return qla81xx_write_mpi_register(vha, mb);
2267}
2268
2269/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002270 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002271 * @ha: HA context
2272 *
2273 * Returns 0 on success.
2274 */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002275static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002276qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002277{
2278 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002279 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002280 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Bart Van Assche52c82822015-07-09 07:23:26 -07002281 uint32_t cnt;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002282 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002283 static int abts_cnt; /* ISP abort retry counts */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002284 int rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002285
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002286 spin_lock_irqsave(&ha->hardware_lock, flags);
2287
2288 /* Reset RISC. */
2289 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2290 for (cnt = 0; cnt < 30000; cnt++) {
2291 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2292 break;
2293
2294 udelay(10);
2295 }
2296
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002297 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE))
2298 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2299
2300 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2301 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2302 RD_REG_DWORD(&reg->hccr),
2303 RD_REG_DWORD(&reg->ctrl_status),
2304 (RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE));
2305
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002306 WRT_REG_DWORD(&reg->ctrl_status,
2307 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002308 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002309
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002310 udelay(100);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002311
Andrew Vasquez88c26662005-07-08 17:59:26 -07002312 /* Wait for firmware to complete NVRAM accesses. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002313 RD_REG_WORD(&reg->mailbox0);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002314 for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
2315 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez88c26662005-07-08 17:59:26 -07002316 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002317 if (cnt)
2318 udelay(5);
2319 else
2320 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez88c26662005-07-08 17:59:26 -07002321 }
2322
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002323 if (rval == QLA_SUCCESS)
2324 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2325
2326 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2327 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2328 RD_REG_DWORD(&reg->hccr),
2329 RD_REG_DWORD(&reg->mailbox0));
2330
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002331 /* Wait for soft-reset to complete. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002332 RD_REG_DWORD(&reg->ctrl_status);
Quinn Tran200ffb12016-12-23 18:06:12 -08002333 for (cnt = 0; cnt < 60; cnt++) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002334 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002335 if ((RD_REG_DWORD(&reg->ctrl_status) &
2336 CSRX_ISP_SOFT_RESET) == 0)
2337 break;
2338
2339 udelay(5);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002340 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002341 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_ISP_SOFT_RESET))
2342 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2343
2344 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2345 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2346 RD_REG_DWORD(&reg->hccr),
2347 RD_REG_DWORD(&reg->ctrl_status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002348
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002349 /* If required, do an MPI FW reset now */
2350 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2351 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2352 if (++abts_cnt < 5) {
2353 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2354 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2355 } else {
2356 /*
2357 * We exhausted the ISP abort retries. We have to
2358 * set the board offline.
2359 */
2360 abts_cnt = 0;
2361 vha->flags.online = 0;
2362 }
2363 }
2364 }
2365
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002366 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
2367 RD_REG_DWORD(&reg->hccr);
2368
2369 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
2370 RD_REG_DWORD(&reg->hccr);
2371
2372 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
2373 RD_REG_DWORD(&reg->hccr);
2374
Bart Van Assche52c82822015-07-09 07:23:26 -07002375 RD_REG_WORD(&reg->mailbox0);
Quinn Tran200ffb12016-12-23 18:06:12 -08002376 for (cnt = 60; RD_REG_WORD(&reg->mailbox0) != 0 &&
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002377 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002378 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002379 if (cnt)
2380 udelay(5);
2381 else
2382 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002383 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002384 if (rval == QLA_SUCCESS)
2385 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2386
2387 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2388 "Host Risc 0x%x, mailbox0 0x%x\n",
2389 RD_REG_DWORD(&reg->hccr),
2390 RD_REG_WORD(&reg->mailbox0));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002391
2392 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002393
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002394 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2395 "Driver in %s mode\n",
2396 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2397
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002398 if (IS_NOPOLLING_TYPE(ha))
2399 ha->isp_ops->enable_intrs(ha);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002400
2401 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002402}
2403
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002404static void
2405qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2406{
2407 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2408
2409 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2410 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2411
2412}
2413
2414static void
2415qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2416{
2417 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2418
2419 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2420 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2421}
2422
2423static void
2424qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2425{
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002426 uint32_t wd32 = 0;
2427 uint delta_msec = 100;
2428 uint elapsed_msec = 0;
2429 uint timeout_msec;
2430 ulong n;
2431
Joe Carnucciocc790762015-08-04 13:37:53 -04002432 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2433 vha->hw->pdev->subsystem_device != 0x0240)
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002434 return;
2435
Joe Carnuccio8dd7e3a2015-08-04 13:37:54 -04002436 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2437 udelay(100);
2438
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002439attempt:
2440 timeout_msec = TIMEOUT_SEMAPHORE;
2441 n = timeout_msec / delta_msec;
2442 while (n--) {
2443 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2444 qla25xx_read_risc_sema_reg(vha, &wd32);
2445 if (wd32 & RISC_SEMAPHORE)
2446 break;
2447 msleep(delta_msec);
2448 elapsed_msec += delta_msec;
2449 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2450 goto force;
2451 }
2452
2453 if (!(wd32 & RISC_SEMAPHORE))
2454 goto force;
2455
2456 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2457 goto acquired;
2458
2459 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2460 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2461 n = timeout_msec / delta_msec;
2462 while (n--) {
2463 qla25xx_read_risc_sema_reg(vha, &wd32);
2464 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2465 break;
2466 msleep(delta_msec);
2467 elapsed_msec += delta_msec;
2468 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2469 goto force;
2470 }
2471
2472 if (wd32 & RISC_SEMAPHORE_FORCE)
2473 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2474
2475 goto attempt;
2476
2477force:
2478 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2479
2480acquired:
2481 return;
2482}
2483
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002484/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002485 * qla24xx_reset_chip() - Reset ISP24xx chip.
2486 * @ha: HA context
2487 *
2488 * Returns 0 on success.
2489 */
2490void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002491qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07002492{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002493 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08002494
2495 if (pci_channel_offline(ha->pdev) &&
2496 ha->flags.pci_channel_io_perm_failure) {
2497 return;
2498 }
2499
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002500 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002501
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002502 qla25xx_manipulate_risc_semaphore(vha);
2503
Andrew Vasquez88c26662005-07-08 17:59:26 -07002504 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002505 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002506}
2507
2508/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 * qla2x00_chip_diag() - Test chip for proper operation.
2510 * @ha: HA context
2511 *
2512 * Returns 0 on success.
2513 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002514int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002515qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516{
2517 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002518 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002519 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 unsigned long flags = 0;
2521 uint16_t data;
2522 uint32_t cnt;
2523 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002524 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525
2526 /* Assume a failed state */
2527 rval = QLA_FUNCTION_FAILED;
2528
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002529 ql_dbg(ql_dbg_init, vha, 0x007b,
2530 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531
2532 spin_lock_irqsave(&ha->hardware_lock, flags);
2533
2534 /* Reset ISP chip. */
2535 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
2536
2537 /*
2538 * We need to have a delay here since the card will not respond while
2539 * in reset causing an MCA on some architectures.
2540 */
2541 udelay(20);
2542 data = qla2x00_debounce_register(&reg->ctrl_status);
2543 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2544 udelay(5);
2545 data = RD_REG_WORD(&reg->ctrl_status);
2546 barrier();
2547 }
2548
2549 if (!cnt)
2550 goto chip_diag_failed;
2551
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002552 ql_dbg(ql_dbg_init, vha, 0x007c,
2553 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554
2555 /* Reset RISC processor. */
2556 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2557 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2558
2559 /* Workaround for QLA2312 PCI parity error */
2560 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2561 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2562 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2563 udelay(5);
2564 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002565 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 }
2567 } else
2568 udelay(10);
2569
2570 if (!cnt)
2571 goto chip_diag_failed;
2572
2573 /* Check product ID of chip */
Milan P Gandhi5a68a1c2017-03-31 14:37:04 -07002574 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575
2576 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
2577 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
2578 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
2579 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
2580 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
2581 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002582 ql_log(ql_log_warn, vha, 0x0062,
2583 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2584 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585
2586 goto chip_diag_failed;
2587 }
2588 ha->product_id[0] = mb[1];
2589 ha->product_id[1] = mb[2];
2590 ha->product_id[2] = mb[3];
2591 ha->product_id[3] = mb[4];
2592
2593 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002594 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
2596 else
2597 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002598 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599
2600 if (IS_QLA2200(ha) &&
2601 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
2602 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002603 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002605 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 ha->fw_transfer_size = 128;
2607 }
2608
2609 /* Wrap Incoming Mailboxes Test. */
2610 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2611
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002612 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002613 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002614 if (rval)
2615 ql_log(ql_log_warn, vha, 0x0080,
2616 "Failed mailbox send register test.\n");
2617 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 /* Flag a successful rval */
2619 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 spin_lock_irqsave(&ha->hardware_lock, flags);
2621
2622chip_diag_failed:
2623 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002624 ql_log(ql_log_info, vha, 0x0081,
2625 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626
2627 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2628
2629 return (rval);
2630}
2631
2632/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002633 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2634 * @ha: HA context
2635 *
2636 * Returns 0 on success.
2637 */
2638int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002639qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002640{
2641 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002642 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002643 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002644
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002645 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07002646 return QLA_SUCCESS;
2647
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002648 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002649
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002650 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002651 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002652 ql_log(ql_log_warn, vha, 0x0082,
2653 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002654 } else {
2655 /* Flag a successful rval */
2656 rval = QLA_SUCCESS;
2657 }
2658
2659 return rval;
2660}
2661
Quinn Tranad0a0b02017-12-28 12:33:14 -08002662static void
2663qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002664{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002665 int rval;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002666 dma_addr_t tc_dma;
2667 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002668 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002669
Quinn Tranad0a0b02017-12-28 12:33:14 -08002670 if (ha->eft) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002671 ql_dbg(ql_dbg_init, vha, 0x00bd,
Quinn Tranad0a0b02017-12-28 12:33:14 -08002672 "%s: Offload Mem is already allocated.\n",
2673 __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002674 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002675 }
2676
Quinn Tranad0a0b02017-12-28 12:33:14 -08002677 if (IS_FWI2_CAPABLE(ha)) {
2678 /* Allocate memory for Fibre Channel Event Buffer. */
2679 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2680 !IS_QLA27XX(ha))
2681 goto try_eft;
2682
2683 if (ha->fce)
2684 dma_free_coherent(&ha->pdev->dev,
2685 FCE_SIZE, ha->fce, ha->fce_dma);
2686
2687 /* Allocate memory for Fibre Channel Event Buffer. */
2688 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
2689 GFP_KERNEL);
2690 if (!tc) {
2691 ql_log(ql_log_warn, vha, 0x00be,
2692 "Unable to allocate (%d KB) for FCE.\n",
2693 FCE_SIZE / 1024);
2694 goto try_eft;
2695 }
2696
2697 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
2698 ha->fce_mb, &ha->fce_bufs);
2699 if (rval) {
2700 ql_log(ql_log_warn, vha, 0x00bf,
2701 "Unable to initialize FCE (%d).\n", rval);
2702 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
2703 tc_dma);
2704 ha->flags.fce_enabled = 0;
2705 goto try_eft;
2706 }
2707 ql_dbg(ql_dbg_init, vha, 0x00c0,
2708 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
2709
2710 ha->flags.fce_enabled = 1;
2711 ha->fce_dma = tc_dma;
2712 ha->fce = tc;
2713
2714try_eft:
2715 if (ha->eft)
2716 dma_free_coherent(&ha->pdev->dev,
2717 EFT_SIZE, ha->eft, ha->eft_dma);
2718
2719 /* Allocate memory for Extended Trace Buffer. */
2720 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
2721 GFP_KERNEL);
2722 if (!tc) {
2723 ql_log(ql_log_warn, vha, 0x00c1,
2724 "Unable to allocate (%d KB) for EFT.\n",
2725 EFT_SIZE / 1024);
2726 goto eft_err;
2727 }
2728
2729 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
2730 if (rval) {
2731 ql_log(ql_log_warn, vha, 0x00c2,
2732 "Unable to initialize EFT (%d).\n", rval);
2733 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
2734 tc_dma);
2735 goto eft_err;
2736 }
2737 ql_dbg(ql_dbg_init, vha, 0x00c3,
2738 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
2739
2740 ha->eft_dma = tc_dma;
2741 ha->eft = tc;
2742 }
2743
2744eft_err:
2745 return;
2746}
2747
2748void
2749qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
2750{
2751 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
2752 eft_size, fce_size, mq_size;
2753 struct qla_hw_data *ha = vha->hw;
2754 struct req_que *req = ha->req_q_map[0];
2755 struct rsp_que *rsp = ha->rsp_q_map[0];
2756 struct qla2xxx_fw_dump *fw_dump;
2757
Chad Dupuisf73cb692014-02-26 04:15:06 -05002758 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
2759 req_q_size = rsp_q_size = 0;
2760
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002761 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2762 fixed_size = sizeof(struct qla2100_fw_dump);
2763 } else if (IS_QLA23XX(ha)) {
2764 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
2765 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
2766 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07002767 } else if (IS_FWI2_CAPABLE(ha)) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002768 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002769 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
2770 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002771 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
2772 else if (IS_QLA25XX(ha))
2773 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
2774 else
2775 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002776
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002777 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
2778 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002779 if (ha->mqenable) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002780 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002781 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002782 /*
2783 * Allocate maximum buffer size for all queues.
2784 * Resizing must be done at end-of-dump processing.
2785 */
2786 mq_size += ha->max_req_queues *
2787 (req->length * sizeof(request_t));
2788 mq_size += ha->max_rsp_queues *
2789 (rsp->length * sizeof(response_t));
2790 }
Arun Easi00876ae2013-03-25 02:21:37 -04002791 if (ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002792 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002793 /* Allocate memory for Fibre Channel Event Buffer. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05002794 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2795 !IS_QLA27XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002796 goto try_eft;
2797
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07002798 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002799try_eft:
Chad Dupuiscfb09192011-11-18 09:03:07 -08002800 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002801 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002802 eft_size = EFT_SIZE;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002803 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05002804
Chad Dupuisf73cb692014-02-26 04:15:06 -05002805 if (IS_QLA27XX(ha)) {
2806 if (!ha->fw_dump_template) {
2807 ql_log(ql_log_warn, vha, 0x00ba,
2808 "Failed missing fwdump template\n");
2809 return;
2810 }
2811 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
2812 ql_dbg(ql_dbg_init, vha, 0x00fa,
2813 "-> allocating fwdump (%x bytes)...\n", dump_size);
2814 goto allocate;
2815 }
2816
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002817 req_q_size = req->length * sizeof(request_t);
2818 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002819 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002820 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08002821 ha->chain_offset = dump_size;
2822 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002823
Quinn Tranb945e772017-06-13 20:47:29 -07002824 if (ha->exchoffld_buf)
2825 dump_size += sizeof(struct qla2xxx_offld_chain) +
2826 ha->exchoffld_size;
2827 if (ha->exlogin_buf)
2828 dump_size += sizeof(struct qla2xxx_offld_chain) +
2829 ha->exlogin_size;
2830
Chad Dupuisf73cb692014-02-26 04:15:06 -05002831allocate:
Quinn Tranad0a0b02017-12-28 12:33:14 -08002832 if (!ha->fw_dump_len || dump_size != ha->fw_dump_len) {
2833 fw_dump = vmalloc(dump_size);
2834 if (!fw_dump) {
2835 ql_log(ql_log_warn, vha, 0x00c4,
2836 "Unable to allocate (%d KB) for firmware dump.\n",
2837 dump_size / 1024);
2838 } else {
2839 if (ha->fw_dump)
2840 vfree(ha->fw_dump);
2841 ha->fw_dump = fw_dump;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002842
Quinn Tranad0a0b02017-12-28 12:33:14 -08002843 ha->fw_dump_len = dump_size;
2844 ql_dbg(ql_dbg_init, vha, 0x00c5,
2845 "Allocated (%d KB) for firmware dump.\n",
2846 dump_size / 1024);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002847
Quinn Tranad0a0b02017-12-28 12:33:14 -08002848 if (IS_QLA27XX(ha))
2849 return;
2850
2851 ha->fw_dump->signature[0] = 'Q';
2852 ha->fw_dump->signature[1] = 'L';
2853 ha->fw_dump->signature[2] = 'G';
2854 ha->fw_dump->signature[3] = 'C';
2855 ha->fw_dump->version = htonl(1);
2856
2857 ha->fw_dump->fixed_size = htonl(fixed_size);
2858 ha->fw_dump->mem_size = htonl(mem_size);
2859 ha->fw_dump->req_q_size = htonl(req_q_size);
2860 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
2861
2862 ha->fw_dump->eft_size = htonl(eft_size);
2863 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
2864 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
2865
2866 ha->fw_dump->header_size =
2867 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002868 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002869 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002870}
2871
Andrew Vasquez18e75552009-06-03 09:55:30 -07002872static int
2873qla81xx_mpi_sync(scsi_qla_host_t *vha)
2874{
2875#define MPS_MASK 0xe0
2876 int rval;
2877 uint16_t dc;
2878 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07002879
2880 if (!IS_QLA81XX(vha->hw))
2881 return QLA_SUCCESS;
2882
2883 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
2884 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002885 ql_log(ql_log_warn, vha, 0x0105,
2886 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002887 goto done;
2888 }
2889
2890 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
2891 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
2892 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002893 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002894 goto done_release;
2895 }
2896
2897 dc &= MPS_MASK;
2898 if (dc == (dw & MPS_MASK))
2899 goto done_release;
2900
2901 dw &= ~MPS_MASK;
2902 dw |= dc;
2903 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
2904 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002905 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002906 }
2907
2908done_release:
2909 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
2910 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002911 ql_log(ql_log_warn, vha, 0x006d,
2912 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002913 }
2914
2915done:
2916 return rval;
2917}
2918
Chad Dupuis8d93f552013-01-30 03:34:37 -05002919int
2920qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
2921{
2922 /* Don't try to reallocate the array */
2923 if (req->outstanding_cmds)
2924 return QLA_SUCCESS;
2925
Michael Hernandezd7459522016-12-12 14:40:07 -08002926 if (!IS_FWI2_CAPABLE(ha))
Chad Dupuis8d93f552013-01-30 03:34:37 -05002927 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
2928 else {
Quinn Tran03e8c682015-12-17 14:56:59 -05002929 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
2930 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002931 else
Quinn Tran03e8c682015-12-17 14:56:59 -05002932 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002933 }
2934
2935 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
2936 req->num_outstanding_cmds, GFP_KERNEL);
2937
2938 if (!req->outstanding_cmds) {
2939 /*
2940 * Try to allocate a minimal size just so we can get through
2941 * initialization.
2942 */
2943 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
2944 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
2945 req->num_outstanding_cmds, GFP_KERNEL);
2946
2947 if (!req->outstanding_cmds) {
2948 ql_log(ql_log_fatal, NULL, 0x0126,
2949 "Failed to allocate memory for "
2950 "outstanding_cmds for req_que %p.\n", req);
2951 req->num_outstanding_cmds = 0;
2952 return QLA_FUNCTION_FAILED;
2953 }
2954 }
2955
2956 return QLA_SUCCESS;
2957}
2958
Quinn Trane4e3a2c2017-08-23 15:05:07 -07002959#define PRINT_FIELD(_field, _flag, _str) { \
2960 if (a0->_field & _flag) {\
2961 if (p) {\
2962 strcat(ptr, "|");\
2963 ptr++;\
2964 leftover--;\
2965 } \
2966 len = snprintf(ptr, leftover, "%s", _str); \
2967 p = 1;\
2968 leftover -= len;\
2969 ptr += len; \
2970 } \
2971}
2972
2973static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
2974{
2975#define STR_LEN 64
2976 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
2977 u8 str[STR_LEN], *ptr, p;
2978 int leftover, len;
2979
2980 memset(str, 0, STR_LEN);
2981 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
2982 ql_dbg(ql_dbg_init, vha, 0x015a,
2983 "SFP MFG Name: %s\n", str);
2984
2985 memset(str, 0, STR_LEN);
2986 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
2987 ql_dbg(ql_dbg_init, vha, 0x015c,
2988 "SFP Part Name: %s\n", str);
2989
2990 /* media */
2991 memset(str, 0, STR_LEN);
2992 ptr = str;
2993 leftover = STR_LEN;
2994 p = len = 0;
2995 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
2996 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
2997 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
2998 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
2999 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3000 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3001 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3002 ql_dbg(ql_dbg_init, vha, 0x0160,
3003 "SFP Media: %s\n", str);
3004
3005 /* link length */
3006 memset(str, 0, STR_LEN);
3007 ptr = str;
3008 leftover = STR_LEN;
3009 p = len = 0;
3010 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3011 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3012 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3013 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3014 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3015 ql_dbg(ql_dbg_init, vha, 0x0196,
3016 "SFP Link Length: %s\n", str);
3017
3018 memset(str, 0, STR_LEN);
3019 ptr = str;
3020 leftover = STR_LEN;
3021 p = len = 0;
3022 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3023 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3024 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3025 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3026 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3027 ql_dbg(ql_dbg_init, vha, 0x016e,
3028 "SFP FC Link Tech: %s\n", str);
3029
3030 if (a0->length_km)
3031 ql_dbg(ql_dbg_init, vha, 0x016f,
3032 "SFP Distant: %d km\n", a0->length_km);
3033 if (a0->length_100m)
3034 ql_dbg(ql_dbg_init, vha, 0x0170,
3035 "SFP Distant: %d m\n", a0->length_100m*100);
3036 if (a0->length_50um_10m)
3037 ql_dbg(ql_dbg_init, vha, 0x0189,
3038 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3039 if (a0->length_62um_10m)
3040 ql_dbg(ql_dbg_init, vha, 0x018a,
3041 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3042 if (a0->length_om4_10m)
3043 ql_dbg(ql_dbg_init, vha, 0x0194,
3044 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3045 if (a0->length_om3_10m)
3046 ql_dbg(ql_dbg_init, vha, 0x0195,
3047 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3048}
3049
3050
3051/*
3052 * Return Code:
3053 * QLA_SUCCESS: no action
3054 * QLA_INTERFACE_ERROR: SFP is not there.
3055 * QLA_FUNCTION_FAILED: detected New SFP
3056 */
3057int
3058qla24xx_detect_sfp(scsi_qla_host_t *vha)
3059{
3060 int rc = QLA_SUCCESS;
3061 struct sff_8247_a0 *a;
3062 struct qla_hw_data *ha = vha->hw;
3063
3064 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3065 goto out;
3066
3067 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3068 if (rc)
3069 goto out;
3070
3071 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3072 qla2xxx_print_sfp_info(vha);
3073
3074 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3075 /* long range */
3076 ha->flags.detected_lr_sfp = 1;
3077
3078 if (a->length_km > 5 || a->length_100m > 50)
3079 ha->long_range_distance = LR_DISTANCE_10K;
3080 else
3081 ha->long_range_distance = LR_DISTANCE_5K;
3082
3083 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3084 ql_dbg(ql_dbg_async, vha, 0x507b,
3085 "Detected Long Range SFP.\n");
3086 } else {
3087 /* short range */
3088 ha->flags.detected_lr_sfp = 0;
3089 if (ha->flags.using_lr_setting)
3090 ql_dbg(ql_dbg_async, vha, 0x5084,
3091 "Detected Short Range SFP.\n");
3092 }
3093
3094 if (!vha->flags.init_done)
3095 rc = QLA_SUCCESS;
3096out:
3097 return rc;
3098}
3099
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003100/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 * qla2x00_setup_chip() - Load and start RISC firmware.
3102 * @ha: HA context
3103 *
3104 * Returns 0 on success.
3105 */
3106static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003107qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003109 int rval;
3110 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003111 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08003112 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3113 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07003114 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08003115
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003116 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003117 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05003118 if (rval == QLA_SUCCESS) {
3119 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003120 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05003121 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07003122 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003123 }
3124
Andrew Vasquez3db06522008-01-31 12:33:49 -08003125 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3126 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3127 spin_lock_irqsave(&ha->hardware_lock, flags);
3128 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
3129 RD_REG_WORD(&reg->hccr);
3130 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3131 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132
Andrew Vasquez18e75552009-06-03 09:55:30 -07003133 qla81xx_mpi_sync(vha);
3134
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003136 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003137 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003138 ql_dbg(ql_dbg_init, vha, 0x00c9,
3139 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003141 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 if (rval == QLA_SUCCESS) {
3143 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003144 ql_dbg(ql_dbg_init, vha, 0x00ca,
3145 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003147 if (ql2xexlogins)
3148 ha->flags.exlogins_enabled = 1;
3149
Quinn Tran99e1b682017-06-02 09:12:03 -07003150 if (qla_is_exch_offld_enabled(vha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003151 ha->flags.exchoffld_enabled = 1;
3152
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003153 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07003155 if (rval == QLA_SUCCESS) {
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003156 qla24xx_detect_sfp(vha);
3157
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003158 rval = qla2x00_set_exlogins_buffer(vha);
3159 if (rval != QLA_SUCCESS)
3160 goto failed;
3161
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003162 rval = qla2x00_set_exchoffld_buffer(vha);
3163 if (rval != QLA_SUCCESS)
3164 goto failed;
3165
Giridhar Malavalia9083012010-04-12 17:59:55 -07003166enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07003167 fw_major_version = ha->fw_major_version;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003168 if (IS_P3P_TYPE(ha))
Giridhar Malavali31731672011-08-16 11:31:54 -07003169 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003170 else
3171 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07003172 if (rval != QLA_SUCCESS)
3173 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003174 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003175 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07003176 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003177 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003178 if ((!ha->max_npiv_vports) ||
3179 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003180 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003181 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003182 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003183 }
Quinn Tran03e8c682015-12-17 14:56:59 -05003184 qla2x00_get_resource_cnts(vha);
Andrew Vasquezd743de62009-03-24 09:08:15 -07003185
Chad Dupuis8d93f552013-01-30 03:34:37 -05003186 /*
3187 * Allocate the array of outstanding commands
3188 * now that we know the firmware resources.
3189 */
3190 rval = qla2x00_alloc_outstanding_cmds(ha,
3191 vha->req);
3192 if (rval != QLA_SUCCESS)
3193 goto failed;
3194
Quinn Tranad0a0b02017-12-28 12:33:14 -08003195 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3196 qla2x00_alloc_offload_mem(vha);
3197
3198 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
Giridhar Malavali08de2842011-08-16 11:31:44 -07003199 qla2x00_alloc_fw_dump(vha);
Quinn Tranad0a0b02017-12-28 12:33:14 -08003200
Chad Dupuis3b6e5b92013-10-30 03:38:09 -04003201 } else {
3202 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 }
3204 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003205 ql_log(ql_log_fatal, vha, 0x00cd,
3206 "ISP Firmware failed checksum.\n");
3207 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04003209 } else
3210 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211
Andrew Vasquez3db06522008-01-31 12:33:49 -08003212 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3213 /* Enable proper parity. */
3214 spin_lock_irqsave(&ha->hardware_lock, flags);
3215 if (IS_QLA2300(ha))
3216 /* SRAM parity */
3217 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
3218 else
3219 /* SRAM, Instruction RAM and GP RAM parity */
3220 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
3221 RD_REG_WORD(&reg->hccr);
3222 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3223 }
3224
Chad Dupuisf3982d82014-09-25 05:16:57 -04003225 if (IS_QLA27XX(ha))
3226 ha->flags.fac_supported = 1;
3227 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003228 uint32_t size;
3229
3230 rval = qla81xx_fac_get_sector_size(vha, &size);
3231 if (rval == QLA_SUCCESS) {
3232 ha->flags.fac_supported = 1;
3233 ha->fdt_block_size = size << 2;
3234 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003235 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003236 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3237 ha->fw_major_version, ha->fw_minor_version,
3238 ha->fw_subminor_version);
Joe Carnuccio1ca60e32014-02-26 04:15:02 -05003239
Chad Dupuisf73cb692014-02-26 04:15:06 -05003240 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003241 ha->flags.fac_supported = 0;
3242 rval = QLA_SUCCESS;
3243 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003244 }
3245 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07003246failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003248 ql_log(ql_log_fatal, vha, 0x00cf,
3249 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 }
3251
3252 return (rval);
3253}
3254
3255/**
3256 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3257 * @ha: HA context
3258 *
3259 * Beginning of request ring has initialization control block already built
3260 * by nvram config routine.
3261 *
3262 * Returns 0 on success.
3263 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003264void
3265qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266{
3267 uint16_t cnt;
3268 response_t *pkt;
3269
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003270 rsp->ring_ptr = rsp->ring;
3271 rsp->ring_index = 0;
3272 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003273 pkt = rsp->ring_ptr;
3274 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 pkt->signature = RESPONSE_PROCESSED;
3276 pkt++;
3277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278}
3279
3280/**
3281 * qla2x00_update_fw_options() - Read and process firmware options.
3282 * @ha: HA context
3283 *
3284 * Returns 0 on success.
3285 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003286void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003287qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288{
3289 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003290 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291
3292 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003293 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294
3295 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3296 return;
3297
3298 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003299 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3300 "Serial link options.\n");
3301 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3302 (uint8_t *)&ha->fw_seriallink_options,
3303 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304
3305 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3306 if (ha->fw_seriallink_options[3] & BIT_2) {
3307 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3308
3309 /* 1G settings */
3310 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3311 emphasis = (ha->fw_seriallink_options[2] &
3312 (BIT_4 | BIT_3)) >> 3;
3313 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003314 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 rx_sens = (ha->fw_seriallink_options[0] &
3316 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3317 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3318 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3319 if (rx_sens == 0x0)
3320 rx_sens = 0x3;
3321 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3322 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3323 ha->fw_options[10] |= BIT_5 |
3324 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3325 (tx_sens & (BIT_1 | BIT_0));
3326
3327 /* 2G settings */
3328 swing = (ha->fw_seriallink_options[2] &
3329 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3330 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3331 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003332 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 rx_sens = (ha->fw_seriallink_options[1] &
3334 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3335 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3336 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3337 if (rx_sens == 0x0)
3338 rx_sens = 0x3;
3339 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3340 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3341 ha->fw_options[11] |= BIT_5 |
3342 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3343 (tx_sens & (BIT_1 | BIT_0));
3344 }
3345
3346 /* FCP2 options. */
3347 /* Return command IOCBs without waiting for an ABTS to complete. */
3348 ha->fw_options[3] |= BIT_13;
3349
3350 /* LED scheme. */
3351 if (ha->flags.enable_led_scheme)
3352 ha->fw_options[2] |= BIT_12;
3353
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003354 /* Detect ISP6312. */
3355 if (IS_QLA6312(ha))
3356 ha->fw_options[2] |= BIT_13;
3357
Giridhar Malavali088d09d2016-07-06 11:14:20 -04003358 /* Set Retry FLOGI in case of P2P connection */
3359 if (ha->operating_mode == P2P) {
3360 ha->fw_options[2] |= BIT_3;
3361 ql_dbg(ql_dbg_disc, vha, 0x2100,
3362 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3363 __func__, ha->fw_options[2]);
3364 }
3365
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003367 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368}
3369
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003370void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003371qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003372{
3373 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003374 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003375
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003376 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07003377 return;
3378
Himanshu Madhanif198caf2016-01-27 12:03:30 -05003379 /* Hold status IOCBs until ABTS response received. */
3380 if (ql2xfwholdabts)
3381 ha->fw_options[3] |= BIT_12;
3382
Giridhar Malavali088d09d2016-07-06 11:14:20 -04003383 /* Set Retry FLOGI in case of P2P connection */
3384 if (ha->operating_mode == P2P) {
3385 ha->fw_options[2] |= BIT_3;
3386 ql_dbg(ql_dbg_disc, vha, 0x2101,
3387 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3388 __func__, ha->fw_options[2]);
3389 }
3390
Quinn Tran41dc5292017-01-19 22:28:03 -08003391 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
Quinn Tran3c4810f2017-06-02 09:11:53 -07003392 if (ql2xmvasynctoatio &&
3393 (IS_QLA83XX(ha) || IS_QLA27XX(ha))) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003394 if (qla_tgt_mode_enabled(vha) ||
3395 qla_dual_mode_enabled(vha))
3396 ha->fw_options[2] |= BIT_11;
3397 else
3398 ha->fw_options[2] &= ~BIT_11;
3399 }
3400
Quinn Tranf7e761f2017-06-02 09:12:02 -07003401 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3402 /*
3403 * Tell FW to track each exchange to prevent
3404 * driver from using stale exchange.
3405 */
3406 if (qla_tgt_mode_enabled(vha) ||
3407 qla_dual_mode_enabled(vha))
3408 ha->fw_options[2] |= BIT_4;
3409 else
3410 ha->fw_options[2] &= ~BIT_4;
Quinn Tran9ecf0b02017-12-28 12:33:19 -08003411
3412 /* Reserve 1/2 of emergency exchanges for ELS.*/
3413 if (qla2xuseresexchforels)
3414 ha->fw_options[2] |= BIT_8;
3415 else
3416 ha->fw_options[2] &= ~BIT_8;
Quinn Tranf7e761f2017-06-02 09:12:02 -07003417 }
3418
Quinn Tran83548fe2017-06-02 09:12:01 -07003419 ql_dbg(ql_dbg_init, vha, 0x00e8,
3420 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3421 __func__, ha->fw_options[1], ha->fw_options[2],
3422 ha->fw_options[3], vha->host->active_mode);
Quinn Tran3c4810f2017-06-02 09:11:53 -07003423
3424 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3425 qla2x00_set_fw_options(vha, ha->fw_options);
Quinn Tran41dc5292017-01-19 22:28:03 -08003426
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003427 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08003428 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003429 return;
3430
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003431 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08003432 le16_to_cpu(ha->fw_seriallink_options24[1]),
3433 le16_to_cpu(ha->fw_seriallink_options24[2]),
3434 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003435 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003436 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003437 "Unable to update Serial Link options (%x).\n", rval);
3438 }
3439}
3440
3441void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003442qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003443{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003444 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003445 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003446 struct req_que *req = ha->req_q_map[0];
3447 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003448
3449 /* Setup ring parameters in initialization control block. */
Bart Van Asschead950362015-07-09 07:24:08 -07003450 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3451 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003452 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3453 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3454 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3455 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3456 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3457 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003458
3459 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3460 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3461 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3462 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3463 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3464}
3465
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003466void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003467qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003468{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003469 struct qla_hw_data *ha = vha->hw;
Bart Van Assche118e2ef2015-07-09 07:24:27 -07003470 device_reg_t *reg = ISP_QUE_REG(ha, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003471 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3472 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003473 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003474 uint16_t rid = 0;
3475 struct req_que *req = ha->req_q_map[0];
3476 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003477
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003478 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003479 icb = (struct init_cb_24xx *)ha->init_cb;
Bart Van Asschead950362015-07-09 07:24:08 -07003480 icb->request_q_outpointer = cpu_to_le16(0);
3481 icb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003482 icb->request_q_length = cpu_to_le16(req->length);
3483 icb->response_q_length = cpu_to_le16(rsp->length);
3484 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3485 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3486 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3487 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003488
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003489 /* Setup ATIO queue dma pointers for target mode */
Bart Van Asschead950362015-07-09 07:24:08 -07003490 icb->atio_q_inpointer = cpu_to_le16(0);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003491 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3492 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
3493 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
3494
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003495 if (IS_SHADOW_REG_CAPABLE(ha))
Bart Van Asschead950362015-07-09 07:24:08 -07003496 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003497
Chad Dupuisf73cb692014-02-26 04:15:06 -05003498 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003499 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3500 icb->rid = cpu_to_le16(rid);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003501 if (ha->flags.msix_enabled) {
3502 msix = &ha->msix_entries[1];
Quinn Tran83548fe2017-06-02 09:12:01 -07003503 ql_dbg(ql_dbg_init, vha, 0x0019,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003504 "Registering vector 0x%x for base que.\n",
3505 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003506 icb->msix = cpu_to_le16(msix->entry);
3507 }
3508 /* Use alternate PCI bus number */
3509 if (MSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003510 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003511 /* Use alternate PCI devfn */
3512 if (LSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003513 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003514
Anirban Chakraborty31557542009-12-02 10:36:55 -08003515 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003516 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
3517 (ha->flags.msix_enabled)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003518 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003519 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003520 ql_dbg(ql_dbg_init, vha, 0x00fe,
3521 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08003522 } else {
Bart Van Asschead950362015-07-09 07:24:08 -07003523 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003524 }
Bart Van Asschead950362015-07-09 07:24:08 -07003525 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003526
3527 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
3528 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
3529 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
3530 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
3531 } else {
3532 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
3533 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
3534 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
3535 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
3536 }
Arun Easiaa230bc2013-01-30 03:34:39 -05003537 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003538
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003539 /* PCI posting */
3540 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003541}
3542
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543/**
3544 * qla2x00_init_rings() - Initializes firmware.
3545 * @ha: HA context
3546 *
3547 * Beginning of request ring has initialization control block already built
3548 * by nvram config routine.
3549 *
3550 * Returns 0 on success.
3551 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003552int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003553qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554{
3555 int rval;
3556 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003557 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003558 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003559 struct req_que *req;
3560 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003561 struct mid_init_cb_24xx *mid_init_cb =
3562 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563
3564 spin_lock_irqsave(&ha->hardware_lock, flags);
3565
3566 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003567 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003568 req = ha->req_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003569 if (!req || !test_bit(que, ha->req_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003570 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003571 req->out_ptr = (void *)(req->ring + req->length);
3572 *req->out_ptr = 0;
Chad Dupuis8d93f552013-01-30 03:34:37 -05003573 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003574 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003576 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003577
3578 /* Initialize firmware. */
3579 req->ring_ptr = req->ring;
3580 req->ring_index = 0;
3581 req->cnt = req->length;
3582 }
3583
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003584 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003585 rsp = ha->rsp_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003586 if (!rsp || !test_bit(que, ha->rsp_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003587 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003588 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
3589 *rsp->in_ptr = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003590 /* Initialize response queue entries */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003591 if (IS_QLAFX00(ha))
3592 qlafx00_init_response_q_entries(rsp);
3593 else
3594 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003595 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003596
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003597 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
3598 ha->tgt.atio_ring_index = 0;
3599 /* Initialize ATIO queue entries */
3600 qlt_init_atio_q_entries(vha);
3601
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003602 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603
3604 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3605
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003606 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
3607
3608 if (IS_QLAFX00(ha)) {
3609 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
3610 goto next_check;
3611 }
3612
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003614 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003616 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04003617 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003618 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08003619 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003620 }
3621
Andrew Vasquez24a08132009-03-24 09:08:16 -07003622 if (IS_FWI2_CAPABLE(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003623 mid_init_cb->options = cpu_to_le16(BIT_1);
Andrew Vasquez24a08132009-03-24 09:08:16 -07003624 mid_init_cb->init_cb.execution_throttle =
Quinn Tran03e8c682015-12-17 14:56:59 -05003625 cpu_to_le16(ha->cur_fw_xcb_count);
Joe Carnuccio40f38622016-07-06 11:14:28 -04003626 ha->flags.dport_enabled =
3627 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
3628 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
3629 (ha->flags.dport_enabled) ? "enabled" : "disabled");
3630 /* FA-WWPN Status */
Himanshu Madhani2486c622014-09-25 05:17:00 -04003631 ha->flags.fawwpn_enabled =
Joe Carnuccio40f38622016-07-06 11:14:28 -04003632 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
Quinn Tran83548fe2017-06-02 09:12:01 -07003633 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
Himanshu Madhani2486c622014-09-25 05:17:00 -04003634 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
Andrew Vasquez24a08132009-03-24 09:08:16 -07003635 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003636
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003637 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003638next_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003640 ql_log(ql_log_fatal, vha, 0x00d2,
3641 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003643 ql_dbg(ql_dbg_init, vha, 0x00d3,
3644 "Init Firmware -- success.\n");
Quinn Tran4b60c822017-06-13 20:47:21 -07003645 QLA_FW_STARTED(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 }
3647
3648 return (rval);
3649}
3650
3651/**
3652 * qla2x00_fw_ready() - Waits for firmware ready.
3653 * @ha: HA context
3654 *
3655 * Returns 0 on success.
3656 */
3657static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003658qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659{
3660 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003661 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662 uint16_t min_wait; /* Minimum wait time if loop is down */
3663 uint16_t wait_time; /* Wait time if loop is coming ready */
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003664 uint16_t state[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003665 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003667 if (IS_QLAFX00(vha->hw))
3668 return qlafx00_fw_ready(vha);
3669
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 rval = QLA_SUCCESS;
3671
Chad Dupuis334614912015-04-09 14:59:57 -04003672 /* Time to wait for loop down */
3673 if (IS_P3P_TYPE(ha))
3674 min_wait = 30;
3675 else
3676 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677
3678 /*
3679 * Firmware should take at most one RATOV to login, plus 5 seconds for
3680 * our own processing.
3681 */
3682 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
3683 wait_time = min_wait;
3684 }
3685
3686 /* Min wait time if loop down */
3687 mtime = jiffies + (min_wait * HZ);
3688
3689 /* wait time before firmware ready */
3690 wtime = jiffies + (wait_time * HZ);
3691
3692 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003693 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003694 ql_log(ql_log_info, vha, 0x801e,
3695 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696
3697 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05003698 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003699 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003701 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003702 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003704 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003705 ql_dbg(ql_dbg_taskm, vha, 0x801f,
3706 "fw_state=%x 84xx=%x.\n", state[0],
3707 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003708 if ((state[2] & FSTATE_LOGGED_IN) &&
3709 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003710 ql_dbg(ql_dbg_taskm, vha, 0x8028,
3711 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003712
3713 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003714 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003715 if (rval != QLA_SUCCESS) {
3716 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08003717 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003718 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003719 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003720 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003721
3722 /* Add time taken to initialize. */
3723 cs84xx_time = jiffies - cs84xx_time;
3724 wtime += cs84xx_time;
3725 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08003726 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003727 "Increasing wait time by %ld. "
3728 "New time %ld.\n", cs84xx_time,
3729 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003730 }
3731 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003732 ql_dbg(ql_dbg_taskm, vha, 0x8037,
3733 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003735 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736 &ha->login_timeout, &ha->r_a_tov);
3737
3738 rval = QLA_SUCCESS;
3739 break;
3740 }
3741
3742 rval = QLA_FUNCTION_FAILED;
3743
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003744 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003745 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003747 * other than Wait for Login.
3748 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003750 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751 "Cable is unplugged...\n");
3752
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003753 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 break;
3755 }
3756 }
3757 } else {
3758 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07003759 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08003760 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 break;
3762 }
3763
3764 if (time_after_eq(jiffies, wtime))
3765 break;
3766
3767 /* Delay for a while */
3768 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769 } while (1);
3770
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003771 ql_dbg(ql_dbg_taskm, vha, 0x803a,
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003772 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
3773 state[1], state[2], state[3], state[4], state[5], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774
Chad Dupuiscfb09192011-11-18 09:03:07 -08003775 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003776 ql_log(ql_log_warn, vha, 0x803b,
3777 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778 }
3779
3780 return (rval);
3781}
3782
3783/*
3784* qla2x00_configure_hba
3785* Setup adapter context.
3786*
3787* Input:
3788* ha = adapter state pointer.
3789*
3790* Returns:
3791* 0 = success
3792*
3793* Context:
3794* Kernel context.
3795*/
3796static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003797qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798{
3799 int rval;
3800 uint16_t loop_id;
3801 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003802 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 uint8_t al_pa;
3804 uint8_t area;
3805 uint8_t domain;
3806 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003807 struct qla_hw_data *ha = vha->hw;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003808 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003809 port_id_t id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810
3811 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003812 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003813 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003815 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003816 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08003817 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003818 ql_dbg(ql_dbg_disc, vha, 0x2008,
3819 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08003820 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003821 ql_log(ql_log_warn, vha, 0x2009,
3822 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003823 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
3824 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
3825 ql_log(ql_log_warn, vha, 0x1151,
3826 "Doing link init.\n");
3827 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
3828 return rval;
3829 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003830 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08003831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 return (rval);
3833 }
3834
3835 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003836 ql_log(ql_log_info, vha, 0x200a,
3837 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 return (QLA_FUNCTION_FAILED);
3839 }
3840
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003841 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842
3843 /* initialize */
3844 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
3845 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003846 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847
3848 switch (topo) {
3849 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003850 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851 ha->current_topology = ISP_CFG_NL;
3852 strcpy(connect_type, "(Loop)");
3853 break;
3854
3855 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003856 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003857 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 ha->current_topology = ISP_CFG_FL;
3859 strcpy(connect_type, "(FL_Port)");
3860 break;
3861
3862 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003863 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 ha->operating_mode = P2P;
3865 ha->current_topology = ISP_CFG_N;
3866 strcpy(connect_type, "(N_Port-to-N_Port)");
3867 break;
3868
3869 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003870 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003871 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 ha->operating_mode = P2P;
3873 ha->current_topology = ISP_CFG_F;
3874 strcpy(connect_type, "(F_Port)");
3875 break;
3876
3877 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003878 ql_dbg(ql_dbg_disc, vha, 0x200f,
3879 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880 ha->current_topology = ISP_CFG_NL;
3881 strcpy(connect_type, "(Loop)");
3882 break;
3883 }
3884
3885 /* Save Host port and loop ID. */
3886 /* byte order - Big Endian */
Quinn Tran482c9dc2017-03-15 09:48:54 -07003887 id.b.domain = domain;
3888 id.b.area = area;
3889 id.b.al_pa = al_pa;
3890 id.b.rsvd_1 = 0;
3891 qlt_update_host_map(vha, id);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003892
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003893 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003894 ql_log(ql_log_info, vha, 0x2010,
3895 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003896 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 return(rval);
3899}
3900
Giridhar Malavalia9083012010-04-12 17:59:55 -07003901inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003902qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
3903 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003904{
3905 char *st, *en;
3906 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003907 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07003908 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003909 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003910
3911 if (memcmp(model, BINZERO, len) != 0) {
3912 strncpy(ha->model_number, model, len);
3913 st = en = ha->model_number;
3914 en += len - 1;
3915 while (en > st) {
3916 if (*en != 0x20 && *en != 0x00)
3917 break;
3918 *en-- = '\0';
3919 }
3920
3921 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07003922 if (use_tbl &&
3923 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003924 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003925 strncpy(ha->model_desc,
3926 qla2x00_model_name[index * 2 + 1],
3927 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003928 } else {
3929 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07003930 if (use_tbl &&
3931 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003932 index < QLA_MODEL_NAMES) {
3933 strcpy(ha->model_number,
3934 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003935 strncpy(ha->model_desc,
3936 qla2x00_model_name[index * 2 + 1],
3937 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003938 } else {
3939 strcpy(ha->model_number, def);
3940 }
3941 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003942 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003943 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003944 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003945}
3946
David Miller4e08df32007-04-16 12:37:43 -07003947/* On sparc systems, obtain port and node WWN from firmware
3948 * properties.
3949 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003950static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07003951{
3952#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003953 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003954 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003955 struct device_node *dp = pci_device_to_OF_node(pdev);
3956 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003957 int len;
3958
3959 val = of_get_property(dp, "port-wwn", &len);
3960 if (val && len >= WWN_SIZE)
3961 memcpy(nv->port_name, val, WWN_SIZE);
3962
3963 val = of_get_property(dp, "node-wwn", &len);
3964 if (val && len >= WWN_SIZE)
3965 memcpy(nv->node_name, val, WWN_SIZE);
3966#endif
3967}
3968
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969/*
3970* NVRAM configuration for ISP 2xxx
3971*
3972* Input:
3973* ha = adapter block pointer.
3974*
3975* Output:
3976* initialization control block in response_ring
3977* host adapters parameters in host adapter block
3978*
3979* Returns:
3980* 0 = success.
3981*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003982int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003983qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984{
David Miller4e08df32007-04-16 12:37:43 -07003985 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003986 uint8_t chksum = 0;
3987 uint16_t cnt;
3988 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003989 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003990 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003991 nvram_t *nv = ha->nvram;
3992 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003993 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994
David Miller4e08df32007-04-16 12:37:43 -07003995 rval = QLA_SUCCESS;
3996
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003998 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 ha->nvram_base = 0;
4000 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4001 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
4002 ha->nvram_base = 0x80;
4003
4004 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004005 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004006 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4007 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004009 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4010 "Contents of NVRAM.\n");
4011 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4012 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004013
4014 /* Bad NVRAM data, set defaults parameters. */
4015 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
4016 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
4017 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004018 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04004019 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004020 "detected: checksum=0x%x id=%c version=0x%x.\n",
4021 chksum, nv->id[0], nv->nvram_version);
4022 ql_log(ql_log_warn, vha, 0x0065,
4023 "Falling back to "
4024 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07004025
4026 /*
4027 * Set default initialization control block.
4028 */
4029 memset(nv, 0, ha->nvram_size);
4030 nv->parameter_block_version = ICB_VERSION;
4031
4032 if (IS_QLA23XX(ha)) {
4033 nv->firmware_options[0] = BIT_2 | BIT_1;
4034 nv->firmware_options[1] = BIT_7 | BIT_5;
4035 nv->add_firmware_options[0] = BIT_5;
4036 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04004037 nv->frame_payload_size = 2048;
David Miller4e08df32007-04-16 12:37:43 -07004038 nv->special_options[1] = BIT_7;
4039 } else if (IS_QLA2200(ha)) {
4040 nv->firmware_options[0] = BIT_2 | BIT_1;
4041 nv->firmware_options[1] = BIT_7 | BIT_5;
4042 nv->add_firmware_options[0] = BIT_5;
4043 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04004044 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07004045 } else if (IS_QLA2100(ha)) {
4046 nv->firmware_options[0] = BIT_3 | BIT_1;
4047 nv->firmware_options[1] = BIT_5;
Joe Carnuccio98aee702014-09-25 05:16:38 -04004048 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07004049 }
4050
Bart Van Asschead950362015-07-09 07:24:08 -07004051 nv->max_iocb_allocation = cpu_to_le16(256);
4052 nv->execution_throttle = cpu_to_le16(16);
David Miller4e08df32007-04-16 12:37:43 -07004053 nv->retry_count = 8;
4054 nv->retry_delay = 1;
4055
4056 nv->port_name[0] = 33;
4057 nv->port_name[3] = 224;
4058 nv->port_name[4] = 139;
4059
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004060 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004061
4062 nv->login_timeout = 4;
4063
4064 /*
4065 * Set default host adapter parameters
4066 */
4067 nv->host_p[1] = BIT_2;
4068 nv->reset_delay = 5;
4069 nv->port_down_retry_count = 8;
Bart Van Asschead950362015-07-09 07:24:08 -07004070 nv->max_luns_per_target = cpu_to_le16(8);
David Miller4e08df32007-04-16 12:37:43 -07004071 nv->link_down_timeout = 60;
4072
4073 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074 }
4075
4076#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4077 /*
4078 * The SN2 does not provide BIOS emulation which means you can't change
4079 * potentially bogus BIOS settings. Force the use of default settings
4080 * for link rate and frame size. Hope that the rest of the settings
4081 * are valid.
4082 */
4083 if (ia64_platform_is("sn2")) {
Joe Carnuccio98aee702014-09-25 05:16:38 -04004084 nv->frame_payload_size = 2048;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 if (IS_QLA23XX(ha))
4086 nv->special_options[1] = BIT_7;
4087 }
4088#endif
4089
4090 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004091 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092
4093 /*
4094 * Setup driver NVRAM options.
4095 */
4096 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4097 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4098 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4099 nv->firmware_options[1] &= ~BIT_4;
4100
4101 if (IS_QLA23XX(ha)) {
4102 nv->firmware_options[0] |= BIT_2;
4103 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004104 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004105 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106
4107 if (IS_QLA2300(ha)) {
4108 if (ha->fb_rev == FPM_2310) {
4109 strcpy(ha->model_number, "QLA2310");
4110 } else {
4111 strcpy(ha->model_number, "QLA2300");
4112 }
4113 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004114 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004115 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116 }
4117 } else if (IS_QLA2200(ha)) {
4118 nv->firmware_options[0] |= BIT_2;
4119 /*
4120 * 'Point-to-point preferred, else loop' is not a safe
4121 * connection mode setting.
4122 */
4123 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4124 (BIT_5 | BIT_4)) {
4125 /* Force 'loop preferred, else point-to-point'. */
4126 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4127 nv->add_firmware_options[0] |= BIT_5;
4128 }
4129 strcpy(ha->model_number, "QLA22xx");
4130 } else /*if (IS_QLA2100(ha))*/ {
4131 strcpy(ha->model_number, "QLA2100");
4132 }
4133
4134 /*
4135 * Copy over NVRAM RISC parameter block to initialization control block.
4136 */
4137 dptr1 = (uint8_t *)icb;
4138 dptr2 = (uint8_t *)&nv->parameter_block_version;
4139 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4140 while (cnt--)
4141 *dptr1++ = *dptr2++;
4142
4143 /* Copy 2nd half. */
4144 dptr1 = (uint8_t *)icb->add_firmware_options;
4145 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4146 while (cnt--)
4147 *dptr1++ = *dptr2++;
4148
Andrew Vasquez5341e862006-05-17 15:09:16 -07004149 /* Use alternate WWN? */
4150 if (nv->host_p[1] & BIT_7) {
4151 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4152 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4153 }
4154
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155 /* Prepare nodename */
4156 if ((icb->firmware_options[1] & BIT_6) == 0) {
4157 /*
4158 * Firmware will apply the following mask if the nodename was
4159 * not provided.
4160 */
4161 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4162 icb->node_name[0] &= 0xF0;
4163 }
4164
4165 /*
4166 * Set host adapter parameters.
4167 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07004168
4169 /*
4170 * BIT_7 in the host-parameters section allows for modification to
4171 * internal driver logging.
4172 */
Andrew Vasquez01819442006-06-23 16:11:10 -07004173 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08004174 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4176 /* Always load RISC code on non ISP2[12]00 chips. */
4177 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4178 ha->flags.disable_risc_code_load = 0;
4179 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4180 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4181 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07004182 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004183 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184
4185 ha->operating_mode =
4186 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4187
4188 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4189 sizeof(ha->fw_seriallink_options));
4190
4191 /* save HBA serial number */
4192 ha->serial0 = icb->port_name[5];
4193 ha->serial1 = icb->port_name[6];
4194 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004195 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4196 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197
Bart Van Asschead950362015-07-09 07:24:08 -07004198 icb->execution_throttle = cpu_to_le16(0xFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199
4200 ha->retry_count = nv->retry_count;
4201
4202 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07004203 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204 nv->login_timeout = ql2xlogintimeout;
4205 if (nv->login_timeout < 4)
4206 nv->login_timeout = 4;
4207 ha->login_timeout = nv->login_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004209 /* Set minimum RATOV to 100 tenths of a second. */
4210 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212 ha->loop_reset_delay = nv->reset_delay;
4213
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214 /* Link Down Timeout = 0:
4215 *
4216 * When Port Down timer expires we will start returning
4217 * I/O's to OS with "DID_NO_CONNECT".
4218 *
4219 * Link Down Timeout != 0:
4220 *
4221 * The driver waits for the link to come up after link down
4222 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004223 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224 if (nv->link_down_timeout == 0) {
4225 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004226 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227 } else {
4228 ha->link_down_timeout = nv->link_down_timeout;
4229 ha->loop_down_abort_time =
4230 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233 /*
4234 * Need enough time to try and get the port back.
4235 */
4236 ha->port_down_retry_count = nv->port_down_retry_count;
4237 if (qlport_down_retry)
4238 ha->port_down_retry_count = qlport_down_retry;
4239 /* Set login_retry_count */
4240 ha->login_retry_count = nv->retry_count;
4241 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4242 ha->port_down_retry_count > 3)
4243 ha->login_retry_count = ha->port_down_retry_count;
4244 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4245 ha->login_retry_count = ha->port_down_retry_count;
4246 if (ql2xloginretrycount)
4247 ha->login_retry_count = ql2xloginretrycount;
4248
Bart Van Asschead950362015-07-09 07:24:08 -07004249 icb->lun_enables = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250 icb->command_resource_count = 0;
4251 icb->immediate_notify_resource_count = 0;
Bart Van Asschead950362015-07-09 07:24:08 -07004252 icb->timeout = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253
4254 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4255 /* Enable RIO */
4256 icb->firmware_options[0] &= ~BIT_3;
4257 icb->add_firmware_options[0] &=
4258 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4259 icb->add_firmware_options[0] |= BIT_2;
4260 icb->response_accumulation_timer = 3;
4261 icb->interrupt_delay_timer = 5;
4262
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004263 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004265 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004266 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004267 ha->zio_mode = icb->add_firmware_options[0] &
4268 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4269 ha->zio_timer = icb->interrupt_delay_timer ?
4270 icb->interrupt_delay_timer: 2;
4271 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272 icb->add_firmware_options[0] &=
4273 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004274 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004275 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004276 ha->zio_mode = QLA_ZIO_MODE_6;
4277
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004278 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004279 "ZIO mode %d enabled; timer delay (%d us).\n",
4280 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004282 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4283 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004284 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285 }
4286 }
4287
David Miller4e08df32007-04-16 12:37:43 -07004288 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004289 ql_log(ql_log_warn, vha, 0x0069,
4290 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07004291 }
4292 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293}
4294
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004295static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004296qla2x00_rport_del(void *data)
4297{
4298 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004299 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004300 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004301
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004302 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004303 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004304 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004305 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004306 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004307 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4308 "%s %8phN. rport %p roles %x\n",
4309 __func__, fcport->port_name, rport,
4310 rport->roles);
Quinn Tran726b8542017-01-19 22:28:00 -08004311
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004312 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08004313 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004314}
4315
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316/**
4317 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4318 * @ha: HA context
4319 * @flags: allocation flags
4320 *
4321 * Returns a pointer to the allocated fcport, or NULL, if none available.
4322 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004323fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004324qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325{
4326 fc_port_t *fcport;
4327
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004328 fcport = kzalloc(sizeof(fc_port_t), flags);
4329 if (!fcport)
4330 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004331
4332 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004333 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334 fcport->port_type = FCT_UNKNOWN;
4335 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07004336 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004337 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338
Quinn Tran726b8542017-01-19 22:28:00 -08004339 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4340 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
Quinn Tran6cb32162017-02-13 12:18:29 -08004341 flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004342 fcport->disc_state = DSC_DELETED;
4343 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4344 fcport->deleted = QLA_SESS_DELETED;
4345 fcport->login_retry = vha->hw->login_retry_count;
4346 fcport->login_retry = 5;
4347 fcport->logout_on_delete = 1;
4348
4349 if (!fcport->ct_desc.ct_sns) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004350 ql_log(ql_log_warn, vha, 0xd049,
Quinn Tran726b8542017-01-19 22:28:00 -08004351 "Failed to allocate ct_sns request.\n");
4352 kfree(fcport);
4353 fcport = NULL;
4354 }
4355 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4356 INIT_LIST_HEAD(&fcport->gnl_entry);
4357 INIT_LIST_HEAD(&fcport->list);
4358
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004359 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360}
4361
Quinn Tran726b8542017-01-19 22:28:00 -08004362void
4363qla2x00_free_fcport(fc_port_t *fcport)
4364{
4365 if (fcport->ct_desc.ct_sns) {
4366 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4367 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4368 fcport->ct_desc.ct_sns_dma);
4369
4370 fcport->ct_desc.ct_sns = NULL;
4371 }
4372 kfree(fcport);
4373}
4374
Linus Torvalds1da177e2005-04-16 15:20:36 -07004375/*
4376 * qla2x00_configure_loop
4377 * Updates Fibre Channel Device Database with what is actually on loop.
4378 *
4379 * Input:
4380 * ha = adapter block pointer.
4381 *
4382 * Returns:
4383 * 0 = success.
4384 * 1 = error.
4385 * 2 = database was full and device was not configured.
4386 */
4387static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004388qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389{
4390 int rval;
4391 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004392 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393 rval = QLA_SUCCESS;
4394
4395 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004396 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4397 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004399 ql_dbg(ql_dbg_disc, vha, 0x2013,
4400 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 return (rval);
4402 }
4403 }
4404
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004405 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004406 ql_dbg(ql_dbg_disc, vha, 0x2014,
4407 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408
4409 /*
4410 * If we have both an RSCN and PORT UPDATE pending then handle them
4411 * both at the same time.
4412 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004413 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4414 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415
Michael Hernandez3064ff32009-12-15 21:29:44 -08004416 qla2x00_get_data_rate(vha);
4417
Linus Torvalds1da177e2005-04-16 15:20:36 -07004418 /* Determine what we need to do */
4419 if (ha->current_topology == ISP_CFG_FL &&
4420 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4421
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422 set_bit(RSCN_UPDATE, &flags);
4423
4424 } else if (ha->current_topology == ISP_CFG_F &&
4425 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4426
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427 set_bit(RSCN_UPDATE, &flags);
4428 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4429
Andrew Vasquez21333b42006-05-17 15:09:56 -07004430 } else if (ha->current_topology == ISP_CFG_N) {
4431 clear_bit(RSCN_UPDATE, &flags);
Quinn Tran41dc5292017-01-19 22:28:03 -08004432 } else if (ha->current_topology == ISP_CFG_NL) {
4433 clear_bit(RSCN_UPDATE, &flags);
4434 set_bit(LOCAL_LOOP_UPDATE, &flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004435 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004436 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004437 set_bit(RSCN_UPDATE, &flags);
4438 set_bit(LOCAL_LOOP_UPDATE, &flags);
4439 }
4440
4441 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004442 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4443 ql_dbg(ql_dbg_disc, vha, 0x2015,
4444 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08004446 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004447 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004448 }
4449
4450 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004451 if (LOOP_TRANSITION(vha)) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004452 ql_dbg(ql_dbg_disc, vha, 0x2099,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004453 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004455 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004456 else
4457 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458 }
4459
4460 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004461 if (atomic_read(&vha->loop_down_timer) ||
4462 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463 rval = QLA_FUNCTION_FAILED;
4464 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004465 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004466 ql_dbg(ql_dbg_disc, vha, 0x2069,
4467 "LOOP READY.\n");
Quinn Tranec7193e2017-03-15 09:48:55 -07004468 ha->flags.fw_init_done = 1;
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05004469
4470 /*
4471 * Process any ATIO queue entries that came in
4472 * while we weren't online.
4473 */
Quinn Tranead03852017-01-19 22:28:01 -08004474 if (qla_tgt_mode_enabled(vha) ||
4475 qla_dual_mode_enabled(vha)) {
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05004476 if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) {
4477 spin_lock_irqsave(&ha->tgt.atio_lock,
4478 flags);
4479 qlt_24xx_process_atio_queue(vha, 0);
4480 spin_unlock_irqrestore(
4481 &ha->tgt.atio_lock, flags);
4482 } else {
4483 spin_lock_irqsave(&ha->hardware_lock,
4484 flags);
4485 qlt_24xx_process_atio_queue(vha, 1);
4486 spin_unlock_irqrestore(
4487 &ha->hardware_lock, flags);
4488 }
4489 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490 }
4491 }
4492
4493 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004494 ql_dbg(ql_dbg_disc, vha, 0x206a,
4495 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004497 ql_dbg(ql_dbg_disc, vha, 0x206b,
4498 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499 }
4500
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07004501 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004502 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004503 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004504 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004505 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004506 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004507 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508 }
4509
4510 return (rval);
4511}
4512
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004513/*
4514 * N2N Login
4515 * Updates Fibre Channel Device Database with local loop devices.
4516 *
4517 * Input:
4518 * ha = adapter block pointer.
4519 *
4520 * Returns:
4521 */
4522static int qla24xx_n2n_handle_login(struct scsi_qla_host *vha,
4523 fc_port_t *fcport)
4524{
4525 struct qla_hw_data *ha = vha->hw;
4526 int res = QLA_SUCCESS, rval;
4527 int greater_wwpn = 0;
4528 int logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004530 if (ha->current_topology != ISP_CFG_N)
4531 return res;
4532
4533 if (wwn_to_u64(vha->port_name) >
4534 wwn_to_u64(vha->n2n_port_name)) {
4535 ql_dbg(ql_dbg_disc, vha, 0x2002,
4536 "HBA WWPN is greater %llx > target %llx\n",
4537 wwn_to_u64(vha->port_name),
4538 wwn_to_u64(vha->n2n_port_name));
4539 greater_wwpn = 1;
4540 fcport->d_id.b24 = vha->n2n_id;
4541 }
4542
4543 fcport->loop_id = vha->loop_id;
4544 fcport->fc4f_nvme = 0;
4545 fcport->query = 1;
4546
4547 ql_dbg(ql_dbg_disc, vha, 0x4001,
4548 "Initiate N2N login handler: HBA port_id=%06x loopid=%d\n",
4549 fcport->d_id.b24, vha->loop_id);
4550
4551 /* Fill in member data. */
4552 if (!greater_wwpn) {
4553 rval = qla2x00_get_port_database(vha, fcport, 0);
4554 ql_dbg(ql_dbg_disc, vha, 0x1051,
4555 "Remote login-state (%x/%x) port_id=%06x loop_id=%x, rval=%d\n",
4556 fcport->current_login_state, fcport->last_login_state,
4557 fcport->d_id.b24, fcport->loop_id, rval);
4558
4559 if (((fcport->current_login_state & 0xf) == 0x4) ||
4560 ((fcport->current_login_state & 0xf) == 0x6))
4561 logged_in = 1;
4562 }
4563
4564 if (logged_in || greater_wwpn) {
4565 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
4566 qla_nvme_register_hba(vha);
4567
4568 /* Set connected N_Port d_id */
4569 if (vha->flags.nvme_enabled)
4570 fcport->fc4f_nvme = 1;
4571
4572 fcport->scan_state = QLA_FCPORT_FOUND;
4573 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4574 fcport->disc_state = DSC_GNL;
4575 fcport->n2n_flag = 1;
4576 fcport->flags = 3;
4577 vha->hw->flags.gpsc_supported = 0;
4578
4579 if (greater_wwpn) {
4580 ql_dbg(ql_dbg_disc, vha, 0x20e5,
4581 "%s %d PLOGI ELS %8phC\n",
4582 __func__, __LINE__, fcport->port_name);
4583
4584 res = qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
4585 fcport, fcport->d_id);
4586 }
4587
4588 if (res != QLA_SUCCESS) {
4589 ql_log(ql_log_info, vha, 0xd04d,
4590 "PLOGI Failed: portid=%06x - retrying\n",
4591 fcport->d_id.b24);
4592 res = QLA_SUCCESS;
4593 } else {
4594 /* State 0x6 means FCP PRLI complete */
4595 if ((fcport->current_login_state & 0xf) == 0x6) {
4596 ql_dbg(ql_dbg_disc, vha, 0x2118,
4597 "%s %d %8phC post GPDB work\n",
4598 __func__, __LINE__, fcport->port_name);
4599 fcport->chip_reset =
4600 vha->hw->base_qpair->chip_reset;
4601 qla24xx_post_gpdb_work(vha, fcport, 0);
4602 } else {
4603 ql_dbg(ql_dbg_disc, vha, 0x2118,
4604 "%s %d %8phC post NVMe PRLI\n",
4605 __func__, __LINE__, fcport->port_name);
4606 qla24xx_post_prli_work(vha, fcport);
4607 }
4608 }
4609 } else {
4610 /* Wait for next database change */
4611 set_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags);
4612 }
4613
4614 return res;
4615}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616
4617/*
4618 * qla2x00_configure_local_loop
4619 * Updates Fibre Channel Device Database with local loop devices.
4620 *
4621 * Input:
4622 * ha = adapter block pointer.
4623 *
4624 * Returns:
4625 * 0 = success.
4626 */
4627static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004628qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004629{
4630 int rval, rval2;
4631 int found_devs;
4632 int found;
4633 fc_port_t *fcport, *new_fcport;
4634
4635 uint16_t index;
4636 uint16_t entries;
4637 char *id_iter;
4638 uint16_t loop_id;
4639 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004640 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08004641 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642
4643 found_devs = 0;
4644 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08004645 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08004648 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004649 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004650 &entries);
4651 if (rval != QLA_SUCCESS)
4652 goto cleanup_allocation;
4653
Quinn Tran83548fe2017-06-02 09:12:01 -07004654 ql_dbg(ql_dbg_disc, vha, 0x2011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004655 "Entries in ID list (%d).\n", entries);
4656 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
4657 (uint8_t *)ha->gid_list,
4658 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659
4660 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004661 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004663 ql_log(ql_log_warn, vha, 0x2012,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004664 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 rval = QLA_MEMORY_ALLOC_FAILED;
4666 goto cleanup_allocation;
4667 }
4668 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4669
4670 /*
4671 * Mark local devices that were present with FCF_DEVICE_LOST for now.
4672 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004673 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674 if (atomic_read(&fcport->state) == FCS_ONLINE &&
4675 fcport->port_type != FCT_BROADCAST &&
4676 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
4677
Quinn Tran83548fe2017-06-02 09:12:01 -07004678 ql_dbg(ql_dbg_disc, vha, 0x2096,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004679 "Marking port lost loop_id=0x%04x.\n",
4680 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004681
Quinn Tran41dc5292017-01-19 22:28:03 -08004682 qla2x00_mark_device_lost(vha, fcport, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004683 }
4684 }
4685
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004686 /* Inititae N2N login. */
4687 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
4688 rval = qla24xx_n2n_handle_login(vha, new_fcport);
4689 if (rval != QLA_SUCCESS)
4690 goto cleanup_allocation;
4691 return QLA_SUCCESS;
4692 }
4693
Linus Torvalds1da177e2005-04-16 15:20:36 -07004694 /* Add devices to port list. */
4695 id_iter = (char *)ha->gid_list;
4696 for (index = 0; index < entries; index++) {
4697 domain = ((struct gid_list_info *)id_iter)->domain;
4698 area = ((struct gid_list_info *)id_iter)->area;
4699 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004700 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004701 loop_id = (uint16_t)
4702 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004703 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004704 loop_id = le16_to_cpu(
4705 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004706 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004707
4708 /* Bypass reserved domain fields. */
4709 if ((domain & 0xf0) == 0xf0)
4710 continue;
4711
4712 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004713 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004714 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715 continue;
4716
4717 /* Bypass invalid local loop ID. */
4718 if (loop_id > LAST_LOCAL_LOOP_ID)
4719 continue;
4720
Quinn Tran41dc5292017-01-19 22:28:03 -08004721 memset(new_fcport->port_name, 0, WWN_SIZE);
Arun Easi370d5502012-08-22 14:21:10 -04004722
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723 /* Fill in member data. */
4724 new_fcport->d_id.b.domain = domain;
4725 new_fcport->d_id.b.area = area;
4726 new_fcport->d_id.b.al_pa = al_pa;
4727 new_fcport->loop_id = loop_id;
Quinn Tran41dc5292017-01-19 22:28:03 -08004728
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004729 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730 if (rval2 != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004731 ql_dbg(ql_dbg_disc, vha, 0x2097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004732 "Failed to retrieve fcport information "
4733 "-- get_port_database=%x, loop_id=0x%04x.\n",
4734 rval2, new_fcport->loop_id);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004735 /* Skip retry if N2N */
4736 if (ha->current_topology != ISP_CFG_N) {
4737 ql_dbg(ql_dbg_disc, vha, 0x2105,
4738 "Scheduling resync.\n");
4739 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4740 continue;
4741 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004742 }
4743
Quinn Tran41dc5292017-01-19 22:28:03 -08004744 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745 /* Check for matching device in port list. */
4746 found = 0;
4747 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004748 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749 if (memcmp(new_fcport->port_name, fcport->port_name,
4750 WWN_SIZE))
4751 continue;
4752
Shyam Sundarddb9b122009-03-24 09:08:10 -07004753 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754 fcport->loop_id = new_fcport->loop_id;
4755 fcport->port_type = new_fcport->port_type;
4756 fcport->d_id.b24 = new_fcport->d_id.b24;
4757 memcpy(fcport->node_name, new_fcport->node_name,
4758 WWN_SIZE);
4759
Quinn Tran41dc5292017-01-19 22:28:03 -08004760 if (!fcport->login_succ) {
4761 vha->fcport_count++;
4762 fcport->login_succ = 1;
4763 fcport->disc_state = DSC_LOGIN_COMPLETE;
4764 }
4765
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766 found++;
4767 break;
4768 }
4769
4770 if (!found) {
4771 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004772 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773
4774 /* Allocate a new replacement fcport. */
4775 fcport = new_fcport;
Quinn Tran41dc5292017-01-19 22:28:03 -08004776 if (!fcport->login_succ) {
4777 vha->fcport_count++;
4778 fcport->login_succ = 1;
4779 fcport->disc_state = DSC_LOGIN_COMPLETE;
4780 }
4781
4782 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4783
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004784 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Quinn Tran41dc5292017-01-19 22:28:03 -08004785
Linus Torvalds1da177e2005-04-16 15:20:36 -07004786 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004787 ql_log(ql_log_warn, vha, 0xd031,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004788 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789 rval = QLA_MEMORY_ALLOC_FAILED;
4790 goto cleanup_allocation;
4791 }
Quinn Tran41dc5292017-01-19 22:28:03 -08004792 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4794 }
4795
Quinn Tran41dc5292017-01-19 22:28:03 -08004796 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4797
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004798 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004799 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004800
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004801 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802
4803 found_devs++;
4804 }
4805
4806cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08004807 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808
4809 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004810 ql_dbg(ql_dbg_disc, vha, 0x2098,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004811 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812 }
4813
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814 return (rval);
4815}
4816
4817static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004818qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004819{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004820 int rval;
Quinn Tran93f2bd62014-09-25 05:16:53 -04004821 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004822 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004823
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07004824 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004825 return;
4826
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07004827 if (atomic_read(&fcport->state) != FCS_ONLINE)
4828 return;
4829
Andrew Vasquez39bd9622007-09-20 14:07:34 -07004830 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
4831 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004832 return;
4833
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004834 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004835 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004836 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004837 ql_dbg(ql_dbg_disc, vha, 0x2004,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004838 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
4839 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004840 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004841 ql_dbg(ql_dbg_disc, vha, 0x2005,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004842 "iIDMA adjusted to %s GB/s on %8phN.\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -05004843 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004844 fcport->port_name);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004845 }
4846}
4847
Quinn Tran726b8542017-01-19 22:28:00 -08004848/* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
Adrian Bunk23be3312006-11-24 02:46:01 +01004849static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004850qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05004851{
4852 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05004853 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004854 unsigned long flags;
8482e1182005-04-17 15:04:54 -05004855
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07004856 rport_ids.node_name = wwn_to_u64(fcport->node_name);
4857 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05004858 rport_ids.port_id = fcport->d_id.b.domain << 16 |
4859 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
4860 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004861 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07004862 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004863 ql_log(ql_log_warn, vha, 0x2006,
4864 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07004865 return;
4866 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004867
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004868 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004869 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004870 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004871
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004872 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07004873
4874 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05004875 if (fcport->port_type == FCT_INITIATOR)
4876 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
4877 if (fcport->port_type == FCT_TARGET)
4878 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Quinn Tran726b8542017-01-19 22:28:00 -08004879
Quinn Tran83548fe2017-06-02 09:12:01 -07004880 ql_dbg(ql_dbg_disc, vha, 0x20ee,
4881 "%s %8phN. rport %p is %s mode\n",
4882 __func__, fcport->port_name, rport,
4883 (fcport->port_type == FCT_TARGET) ? "tgt" : "ini");
Quinn Tran726b8542017-01-19 22:28:00 -08004884
Andrew Vasquez77d74142005-07-08 18:00:36 -07004885 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05004886}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887
4888/*
Adrian Bunk23be3312006-11-24 02:46:01 +01004889 * qla2x00_update_fcport
4890 * Updates device on list.
4891 *
4892 * Input:
4893 * ha = adapter block pointer.
4894 * fcport = port structure pointer.
4895 *
4896 * Return:
4897 * 0 - Success
4898 * BIT_0 - error
4899 *
4900 * Context:
4901 * Kernel context.
4902 */
4903void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004904qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01004905{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004906 fcport->vha = vha;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004907
Quinn Tran726b8542017-01-19 22:28:00 -08004908 if (IS_SW_RESV_ADDR(fcport->d_id))
4909 return;
4910
Quinn Tran83548fe2017-06-02 09:12:01 -07004911 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
Quinn Tran726b8542017-01-19 22:28:00 -08004912 __func__, fcport->port_name);
4913
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004914 if (IS_QLAFX00(vha->hw)) {
4915 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004916 goto reg_port;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004917 }
Adrian Bunk23be3312006-11-24 02:46:01 +01004918 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004919 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Quinn Tran726b8542017-01-19 22:28:00 -08004920 fcport->disc_state = DSC_LOGIN_COMPLETE;
4921 fcport->deleted = 0;
4922 fcport->logout_on_delete = 1;
Adrian Bunk23be3312006-11-24 02:46:01 +01004923
Duane Grigsbye84067d2017-06-21 13:48:43 -07004924 if (fcport->fc4f_nvme) {
4925 qla_nvme_register_remote(vha, fcport);
4926 return;
4927 }
4928
Joe Carnuccio1f93da522012-11-21 02:40:38 -05004929 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004930 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08004931 qla24xx_update_fcport_fcp_prio(vha, fcport);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004932
4933reg_port:
Quinn Tran726b8542017-01-19 22:28:00 -08004934 switch (vha->host->active_mode) {
4935 case MODE_INITIATOR:
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004936 qla2x00_reg_remote_port(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08004937 break;
4938 case MODE_TARGET:
4939 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
4940 !vha->vha_tgt.qla_tgt->tgt_stopped)
4941 qlt_fc_port_added(vha, fcport);
4942 break;
4943 case MODE_DUAL:
4944 qla2x00_reg_remote_port(vha, fcport);
4945 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
4946 !vha->vha_tgt.qla_tgt->tgt_stopped)
4947 qlt_fc_port_added(vha, fcport);
4948 break;
4949 default:
4950 break;
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004951 }
Adrian Bunk23be3312006-11-24 02:46:01 +01004952}
4953
4954/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004955 * qla2x00_configure_fabric
4956 * Setup SNS devices with loop ID's.
4957 *
4958 * Input:
4959 * ha = adapter block pointer.
4960 *
4961 * Returns:
4962 * 0 = success.
4963 * BIT_0 = error
4964 */
4965static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004966qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967{
Arun Easib3b02e62012-02-09 11:15:39 -08004968 int rval;
Quinn Tran726b8542017-01-19 22:28:00 -08004969 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004971 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004972 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004973 struct qla_hw_data *ha = vha->hw;
Alexei Potashnikdf673272015-07-14 16:00:46 -04004974 int discovery_gen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975
4976 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07004977 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004978 loop_id = NPH_F_PORT;
4979 else
4980 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004981 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004983 ql_dbg(ql_dbg_disc, vha, 0x20a0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004984 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004986 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987 return (QLA_SUCCESS);
4988 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004989 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990
Quinn Tran41dc5292017-01-19 22:28:03 -08004991
4992 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
4993 rval = qla2x00_send_change_request(vha, 0x3, 0);
4994 if (rval != QLA_SUCCESS)
4995 ql_log(ql_log_warn, vha, 0x121,
4996 "Failed to enable receiving of RSCN requests: 0x%x.\n",
4997 rval);
4998 }
4999
5000
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001 do {
Quinn Tran726b8542017-01-19 22:28:00 -08005002 qla2x00_mgmt_svr_login(vha);
5003
Andrew Vasquezcca53352005-08-26 19:08:30 -07005004 /* FDMI support. */
5005 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005006 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5007 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07005008
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009 /* Ensure we are logged into the SNS. */
Joe Carnuccioa14c7712017-08-23 15:05:12 -07005010 loop_id = NPH_SNS_LID(ha);
Chad Dupuis0b91d112012-02-09 11:15:42 -08005011 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5012 0xfc, mb, BIT_1|BIT_0);
Joe Carnuccioa14c7712017-08-23 15:05:12 -07005013 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5014 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5015 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5016 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
Chad Dupuis0b91d112012-02-09 11:15:42 -08005017 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05005018 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08005019 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005020 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5021 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005022 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07005023 ql_dbg(ql_dbg_disc, vha, 0x20a2,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005024 "Register FC-4 TYPE failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005025 if (test_bit(LOOP_RESYNC_NEEDED,
5026 &vha->dpc_flags))
5027 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005028 }
Duane Grigsbyd3bae932017-06-21 13:48:44 -07005029 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005030 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07005031 ql_dbg(ql_dbg_disc, vha, 0x209a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005032 "Register FC-4 Features failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005033 if (test_bit(LOOP_RESYNC_NEEDED,
5034 &vha->dpc_flags))
5035 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005036 }
Duane Grigsbyd3bae932017-06-21 13:48:44 -07005037 if (vha->flags.nvme_enabled) {
5038 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5039 ql_dbg(ql_dbg_disc, vha, 0x2049,
5040 "Register NVME FC Type Features failed.\n");
5041 }
5042 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005043 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07005045 ql_dbg(ql_dbg_disc, vha, 0x2104,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005046 "Register Node Name failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005047 if (test_bit(LOOP_RESYNC_NEEDED,
5048 &vha->dpc_flags))
5049 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005050 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005051 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07005052 ql_dbg(ql_dbg_disc, vha, 0x209b,
Colin Ian King0bf0efa2017-06-30 14:47:41 +01005053 "Register Symbolic Node Name failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005054 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5055 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005056 }
5057 }
5058
Joe Carnuccio827210b2013-02-08 01:57:57 -05005059 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5060 fcport->scan_state = QLA_FCPORT_SCAN;
5061 }
5062
Alexei Potashnikdf673272015-07-14 16:00:46 -04005063 /* Mark the time right before querying FW for connected ports.
5064 * This process is long, asynchronous and by the time it's done,
5065 * collected information might not be accurate anymore. E.g.
5066 * disconnected port might have re-connected and a brand new
5067 * session has been created. In this case session's generation
5068 * will be newer than discovery_gen. */
5069 qlt_do_generation_tick(vha, &discovery_gen);
5070
Quinn Tran726b8542017-01-19 22:28:00 -08005071 rval = qla2x00_find_all_fabric_devs(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005072 if (rval != QLA_SUCCESS)
5073 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074 } while (0);
5075
Duane Grigsbye84067d2017-06-21 13:48:43 -07005076 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5077 qla_nvme_register_hba(vha);
5078
Quinn Tran726b8542017-01-19 22:28:00 -08005079 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005080 ql_dbg(ql_dbg_disc, vha, 0x2068,
5081 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082
5083 return (rval);
5084}
5085
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086/*
5087 * qla2x00_find_all_fabric_devs
5088 *
5089 * Input:
5090 * ha = adapter block pointer.
5091 * dev = database device entry pointer.
5092 *
5093 * Returns:
5094 * 0 = success.
5095 *
5096 * Context:
5097 * Kernel context.
5098 */
5099static int
Quinn Tran726b8542017-01-19 22:28:00 -08005100qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101{
5102 int rval;
5103 uint16_t loop_id;
Quinn Tran726b8542017-01-19 22:28:00 -08005104 fc_port_t *fcport, *new_fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005105 int found;
5106
5107 sw_info_t *swl;
5108 int swl_idx;
5109 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07005110 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005111 struct qla_hw_data *ha = vha->hw;
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05005112 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran726b8542017-01-19 22:28:00 -08005113 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005114
5115 rval = QLA_SUCCESS;
5116
5117 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08005118 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08005119 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08005120 GFP_KERNEL);
5121 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02005122 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123 /*EMPTY*/
Quinn Tran83548fe2017-06-02 09:12:01 -07005124 ql_dbg(ql_dbg_disc, vha, 0x209c,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005125 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005126 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08005127 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005128 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005130 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5131 return rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005132 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005134 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5135 return rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005136 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005137 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005138 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5139 return rval;
Quinn Tran726b8542017-01-19 22:28:00 -08005140 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5141 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005142 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5143 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005145
5146 /* If other queries succeeded probe for FC-4 type */
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005147 if (swl) {
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005148 qla2x00_gff_id(vha, swl);
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005149 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5150 return rval;
5151 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152 }
5153 swl_idx = 0;
5154
5155 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005156 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005158 ql_log(ql_log_warn, vha, 0x209d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005159 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005160 return (QLA_MEMORY_ALLOC_FAILED);
5161 }
5162 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163 /* Set start port ID scan at adapter ID. */
5164 first_dev = 1;
5165 last_dev = 0;
5166
5167 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005168 loop_id = ha->min_external_loopid;
5169 for (; loop_id <= ha->max_loop_id; loop_id++) {
5170 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005171 continue;
5172
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07005173 if (ha->current_topology == ISP_CFG_FL &&
5174 (atomic_read(&vha->loop_down_timer) ||
5175 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08005176 atomic_set(&vha->loop_down_timer, 0);
5177 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5178 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005179 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08005180 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005181
5182 if (swl != NULL) {
5183 if (last_dev) {
5184 wrap.b24 = new_fcport->d_id.b24;
5185 } else {
5186 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5187 memcpy(new_fcport->node_name,
5188 swl[swl_idx].node_name, WWN_SIZE);
5189 memcpy(new_fcport->port_name,
5190 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005191 memcpy(new_fcport->fabric_port_name,
5192 swl[swl_idx].fabric_port_name, WWN_SIZE);
5193 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005194 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005195
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005196 new_fcport->nvme_flag = 0;
Darren Trap1a28faa2017-08-30 10:16:48 -07005197 new_fcport->fc4f_nvme = 0;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005198 if (vha->flags.nvme_enabled &&
5199 swl[swl_idx].fc4f_nvme) {
5200 new_fcport->fc4f_nvme =
5201 swl[swl_idx].fc4f_nvme;
5202 ql_log(ql_log_info, vha, 0x2131,
5203 "FOUND: NVME port %8phC as FC Type 28h\n",
5204 new_fcport->port_name);
5205 }
5206
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5208 last_dev = 1;
5209 }
5210 swl_idx++;
5211 }
5212 } else {
5213 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005214 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005216 ql_log(ql_log_warn, vha, 0x209e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005217 "SNS scan failed -- assuming "
5218 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005219 rval = QLA_SUCCESS;
5220 break;
5221 }
5222 }
5223
5224 /* If wrap on switch device list, exit. */
5225 if (first_dev) {
5226 wrap.b24 = new_fcport->d_id.b24;
5227 first_dev = 0;
5228 } else if (new_fcport->d_id.b24 == wrap.b24) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005229 ql_dbg(ql_dbg_disc, vha, 0x209f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005230 "Device wrap (%02x%02x%02x).\n",
5231 new_fcport->d_id.b.domain,
5232 new_fcport->d_id.b.area,
5233 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005234 break;
5235 }
5236
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005237 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005238 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239 continue;
5240
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005241 /* Bypass virtual ports of the same host. */
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05005242 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5243 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005244
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07005245 /* Bypass if same domain and area of adapter. */
5246 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005247 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07005248 ISP_CFG_FL)
5249 continue;
5250
Linus Torvalds1da177e2005-04-16 15:20:36 -07005251 /* Bypass reserved domain fields. */
5252 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5253 continue;
5254
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005255 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07005256 if (ql2xgffidenable &&
5257 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5258 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005259 continue;
5260
Quinn Tran726b8542017-01-19 22:28:00 -08005261 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5262
Linus Torvalds1da177e2005-04-16 15:20:36 -07005263 /* Locate matching device in database. */
5264 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005265 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266 if (memcmp(new_fcport->port_name, fcport->port_name,
5267 WWN_SIZE))
5268 continue;
5269
Joe Carnuccio827210b2013-02-08 01:57:57 -05005270 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08005271
Linus Torvalds1da177e2005-04-16 15:20:36 -07005272 found++;
5273
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005274 /* Update port state. */
5275 memcpy(fcport->fabric_port_name,
5276 new_fcport->fabric_port_name, WWN_SIZE);
5277 fcport->fp_speed = new_fcport->fp_speed;
5278
Linus Torvalds1da177e2005-04-16 15:20:36 -07005279 /*
Roland Dreierb2032fd2015-07-14 16:00:42 -04005280 * If address the same and state FCS_ONLINE
5281 * (or in target mode), nothing changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282 */
5283 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
Roland Dreierb2032fd2015-07-14 16:00:42 -04005284 (atomic_read(&fcport->state) == FCS_ONLINE ||
Quinn Tran726b8542017-01-19 22:28:00 -08005285 (vha->host->active_mode == MODE_TARGET))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286 break;
5287 }
5288
5289 /*
5290 * If device was not a fabric device before.
5291 */
5292 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5293 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04005294 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005295 fcport->flags |= (FCF_FABRIC_DEVICE |
5296 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005297 break;
5298 }
5299
5300 /*
5301 * Port ID changed or device was marked to be updated;
5302 * Log it out if still logged in and mark it for
5303 * relogin later.
5304 */
Quinn Tran726b8542017-01-19 22:28:00 -08005305 if (qla_tgt_mode_enabled(base_vha)) {
Roland Dreierb2032fd2015-07-14 16:00:42 -04005306 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5307 "port changed FC ID, %8phC"
5308 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5309 fcport->port_name,
5310 fcport->d_id.b.domain,
5311 fcport->d_id.b.area,
5312 fcport->d_id.b.al_pa,
5313 fcport->loop_id,
5314 new_fcport->d_id.b.domain,
5315 new_fcport->d_id.b.area,
5316 new_fcport->d_id.b.al_pa);
5317 fcport->d_id.b24 = new_fcport->d_id.b24;
5318 break;
5319 }
5320
Linus Torvalds1da177e2005-04-16 15:20:36 -07005321 fcport->d_id.b24 = new_fcport->d_id.b24;
5322 fcport->flags |= FCF_LOGIN_NEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005323 break;
5324 }
5325
Quinn Tran726b8542017-01-19 22:28:00 -08005326 if (found) {
5327 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005328 continue;
Quinn Tran726b8542017-01-19 22:28:00 -08005329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005330 /* If device was not in our fcports list, then add it. */
Roland Dreierb2032fd2015-07-14 16:00:42 -04005331 new_fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tran726b8542017-01-19 22:28:00 -08005332 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5333
5334 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5335
Linus Torvalds1da177e2005-04-16 15:20:36 -07005336
5337 /* Allocate a new replacement fcport. */
5338 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005339 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005340 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005341 ql_log(ql_log_warn, vha, 0xd032,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005342 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005343 return (QLA_MEMORY_ALLOC_FAILED);
5344 }
5345 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5346 new_fcport->d_id.b24 = nxt_d_id.b24;
5347 }
5348
Quinn Tran726b8542017-01-19 22:28:00 -08005349 qla2x00_free_fcport(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005350
Quinn Tran726b8542017-01-19 22:28:00 -08005351 /*
5352 * Logout all previous fabric dev marked lost, except FCP2 devices.
5353 */
5354 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5355 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5356 break;
5357
5358 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5359 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5360 continue;
5361
5362 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5363 if ((qla_dual_mode_enabled(vha) ||
5364 qla_ini_mode_enabled(vha)) &&
5365 atomic_read(&fcport->state) == FCS_ONLINE) {
5366 qla2x00_mark_device_lost(vha, fcport,
5367 ql2xplogiabsentdevice, 0);
5368 if (fcport->loop_id != FC_NO_LOOP_ID &&
5369 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5370 fcport->port_type != FCT_INITIATOR &&
5371 fcport->port_type != FCT_BROADCAST) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005372 ql_dbg(ql_dbg_disc, vha, 0x20f0,
Quinn Tran726b8542017-01-19 22:28:00 -08005373 "%s %d %8phC post del sess\n",
5374 __func__, __LINE__,
5375 fcport->port_name);
5376
5377 qlt_schedule_sess_for_deletion_lock
5378 (fcport);
5379 continue;
5380 }
5381 }
5382 }
5383
5384 if (fcport->scan_state == QLA_FCPORT_FOUND)
5385 qla24xx_fcport_handle_login(vha, fcport);
5386 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005387 return (rval);
5388}
5389
5390/*
5391 * qla2x00_find_new_loop_id
5392 * Scan through our port list and find a new usable loop ID.
5393 *
5394 * Input:
5395 * ha: adapter state pointer.
5396 * dev: port structure pointer.
5397 *
5398 * Returns:
5399 * qla2x00 local function return status code.
5400 *
5401 * Context:
5402 * Kernel context.
5403 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07005404int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005405qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406{
5407 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005408 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07005409 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005410
5411 rval = QLA_SUCCESS;
5412
Chad Dupuis5f16b332012-08-22 14:21:00 -04005413 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005414
Chad Dupuis5f16b332012-08-22 14:21:00 -04005415 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
5416 LOOPID_MAP_SIZE);
5417 if (dev->loop_id >= LOOPID_MAP_SIZE ||
5418 qla2x00_is_reserved_id(vha, dev->loop_id)) {
5419 dev->loop_id = FC_NO_LOOP_ID;
5420 rval = QLA_FUNCTION_FAILED;
5421 } else
5422 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005423
Chad Dupuis5f16b332012-08-22 14:21:00 -04005424 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005425
Chad Dupuis5f16b332012-08-22 14:21:00 -04005426 if (rval == QLA_SUCCESS)
5427 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
5428 "Assigning new loopid=%x, portid=%x.\n",
5429 dev->loop_id, dev->d_id.b24);
5430 else
5431 ql_log(ql_log_warn, dev->vha, 0x2087,
5432 "No loop_id's available, portid=%x.\n",
5433 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005434
5435 return (rval);
5436}
5437
Linus Torvalds1da177e2005-04-16 15:20:36 -07005438
5439/*
5440 * qla2x00_fabric_login
5441 * Issue fabric login command.
5442 *
5443 * Input:
5444 * ha = adapter block pointer.
5445 * device = pointer to FC device type structure.
5446 *
5447 * Returns:
5448 * 0 - Login successfully
5449 * 1 - Login failed
5450 * 2 - Initiator device
5451 * 3 - Fatal error
5452 */
5453int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005454qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005455 uint16_t *next_loopid)
5456{
5457 int rval;
5458 int retry;
5459 uint16_t tmp_loopid;
5460 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005461 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005462
5463 retry = 0;
5464 tmp_loopid = 0;
5465
5466 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005467 ql_dbg(ql_dbg_disc, vha, 0x2000,
5468 "Trying Fabric Login w/loop id 0x%04x for port "
5469 "%02x%02x%02x.\n",
5470 fcport->loop_id, fcport->d_id.b.domain,
5471 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005472
5473 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08005474 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005475 fcport->d_id.b.domain, fcport->d_id.b.area,
5476 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08005477 if (rval != QLA_SUCCESS) {
5478 return rval;
5479 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005480 if (mb[0] == MBS_PORT_ID_USED) {
5481 /*
5482 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005483 * recommends the driver perform an implicit login with
5484 * the specified ID again. The ID we just used is save
5485 * here so we return with an ID that can be tried by
5486 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005487 */
5488 retry++;
5489 tmp_loopid = fcport->loop_id;
5490 fcport->loop_id = mb[1];
5491
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005492 ql_dbg(ql_dbg_disc, vha, 0x2001,
5493 "Fabric Login: port in use - next loop "
5494 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07005495 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005496 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005497
5498 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
5499 /*
5500 * Login succeeded.
5501 */
5502 if (retry) {
5503 /* A retry occurred before. */
5504 *next_loopid = tmp_loopid;
5505 } else {
5506 /*
5507 * No retry occurred before. Just increment the
5508 * ID value for next login.
5509 */
5510 *next_loopid = (fcport->loop_id + 1);
5511 }
5512
5513 if (mb[1] & BIT_0) {
5514 fcport->port_type = FCT_INITIATOR;
5515 } else {
5516 fcport->port_type = FCT_TARGET;
5517 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07005518 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005519 }
5520 }
5521
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07005522 if (mb[10] & BIT_0)
5523 fcport->supported_classes |= FC_COS_CLASS2;
5524 if (mb[10] & BIT_1)
5525 fcport->supported_classes |= FC_COS_CLASS3;
5526
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005527 if (IS_FWI2_CAPABLE(ha)) {
5528 if (mb[10] & BIT_7)
5529 fcport->flags |=
5530 FCF_CONF_COMP_SUPPORTED;
5531 }
5532
Linus Torvalds1da177e2005-04-16 15:20:36 -07005533 rval = QLA_SUCCESS;
5534 break;
5535 } else if (mb[0] == MBS_LOOP_ID_USED) {
5536 /*
5537 * Loop ID already used, try next loop ID.
5538 */
5539 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005540 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005541 if (rval != QLA_SUCCESS) {
5542 /* Ran out of loop IDs to use */
5543 break;
5544 }
5545 } else if (mb[0] == MBS_COMMAND_ERROR) {
5546 /*
5547 * Firmware possibly timed out during login. If NO
5548 * retries are left to do then the device is declared
5549 * dead.
5550 */
5551 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005552 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07005553 fcport->d_id.b.domain, fcport->d_id.b.area,
5554 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005555 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005556
5557 rval = 1;
5558 break;
5559 } else {
5560 /*
5561 * unrecoverable / not handled error
5562 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005563 ql_dbg(ql_dbg_disc, vha, 0x2002,
5564 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
5565 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
5566 fcport->d_id.b.area, fcport->d_id.b.al_pa,
5567 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005568
5569 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005570 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07005571 fcport->d_id.b.domain, fcport->d_id.b.area,
5572 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04005573 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07005574 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005575
5576 rval = 3;
5577 break;
5578 }
5579 }
5580
5581 return (rval);
5582}
5583
5584/*
5585 * qla2x00_local_device_login
5586 * Issue local device login command.
5587 *
5588 * Input:
5589 * ha = adapter block pointer.
5590 * loop_id = loop id of device to login to.
5591 *
5592 * Returns (Where's the #define!!!!):
5593 * 0 - Login successfully
5594 * 1 - Login failed
5595 * 3 - Fatal error
5596 */
5597int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005598qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005599{
5600 int rval;
5601 uint16_t mb[MAILBOX_REGISTER_COUNT];
5602
5603 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005604 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005605 if (rval == QLA_SUCCESS) {
5606 /* Interrogate mailbox registers for any errors */
5607 if (mb[0] == MBS_COMMAND_ERROR)
5608 rval = 1;
5609 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
5610 /* device not in PCB table */
5611 rval = 3;
5612 }
5613
5614 return (rval);
5615}
5616
5617/*
5618 * qla2x00_loop_resync
5619 * Resync with fibre channel devices.
5620 *
5621 * Input:
5622 * ha = adapter block pointer.
5623 *
5624 * Returns:
5625 * 0 = success
5626 */
5627int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005628qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005629{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005630 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005631 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005632 struct req_que *req;
5633 struct rsp_que *rsp;
5634
Michael Hernandezd7459522016-12-12 14:40:07 -08005635 req = vha->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005636 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005637
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005638 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5639 if (vha->flags.online) {
5640 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005641 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5642 wait_time = 256;
5643 do {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005644 if (!IS_QLAFX00(vha->hw)) {
5645 /*
5646 * Issue a marker after FW becomes
5647 * ready.
5648 */
5649 qla2x00_marker(vha, req, rsp, 0, 0,
5650 MK_SYNC_ALL);
5651 vha->marker_needed = 0;
5652 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005653
5654 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005655 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005656
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005657 if (IS_QLAFX00(vha->hw))
5658 qlafx00_configure_devices(vha);
5659 else
5660 qla2x00_configure_loop(vha);
5661
Linus Torvalds1da177e2005-04-16 15:20:36 -07005662 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005663 } while (!atomic_read(&vha->loop_down_timer) &&
5664 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5665 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
5666 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005667 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005668 }
5669
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005670 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005671 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005672
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005673 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005674 ql_dbg(ql_dbg_disc, vha, 0x206c,
5675 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005676
5677 return (rval);
5678}
5679
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005680/*
5681* qla2x00_perform_loop_resync
5682* Description: This function will set the appropriate flags and call
5683* qla2x00_loop_resync. If successful loop will be resynced
5684* Arguments : scsi_qla_host_t pointer
5685* returm : Success or Failure
5686*/
5687
5688int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
5689{
5690 int32_t rval = 0;
5691
5692 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
5693 /*Configure the flags so that resync happens properly*/
5694 atomic_set(&ha->loop_down_timer, 0);
5695 if (!(ha->device_flags & DFLG_NO_CABLE)) {
5696 atomic_set(&ha->loop_state, LOOP_UP);
5697 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
5698 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
5699 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
5700
5701 rval = qla2x00_loop_resync(ha);
5702 } else
5703 atomic_set(&ha->loop_state, LOOP_DEAD);
5704
5705 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
5706 }
5707
5708 return rval;
5709}
5710
Linus Torvalds1da177e2005-04-16 15:20:36 -07005711void
Andrew Vasquez67becc02009-08-25 11:36:20 -07005712qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005713{
5714 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07005715 struct scsi_qla_host *vha;
5716 struct qla_hw_data *ha = base_vha->hw;
5717 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005718
Arun Easifeafb7b2010-09-03 14:57:00 -07005719 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005720 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07005721 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
5722 atomic_inc(&vha->vref_count);
5723 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08005724 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07005725 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
5726 spin_unlock_irqrestore(&ha->vport_slock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07005727 qla2x00_rport_del(fcport);
Alexei Potashnikdf673272015-07-14 16:00:46 -04005728
Arun Easifeafb7b2010-09-03 14:57:00 -07005729 spin_lock_irqsave(&ha->vport_slock, flags);
5730 }
5731 }
5732 atomic_dec(&vha->vref_count);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07005733 wake_up(&vha->vref_waitq);
Arun Easifeafb7b2010-09-03 14:57:00 -07005734 }
5735 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005736}
5737
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005738/* Assumes idc_lock always held on entry */
5739void
5740qla83xx_reset_ownership(scsi_qla_host_t *vha)
5741{
5742 struct qla_hw_data *ha = vha->hw;
5743 uint32_t drv_presence, drv_presence_mask;
5744 uint32_t dev_part_info1, dev_part_info2, class_type;
5745 uint32_t class_type_mask = 0x3;
5746 uint16_t fcoe_other_function = 0xffff, i;
5747
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005748 if (IS_QLA8044(ha)) {
5749 drv_presence = qla8044_rd_direct(vha,
5750 QLA8044_CRB_DRV_ACTIVE_INDEX);
5751 dev_part_info1 = qla8044_rd_direct(vha,
5752 QLA8044_CRB_DEV_PART_INFO_INDEX);
5753 dev_part_info2 = qla8044_rd_direct(vha,
5754 QLA8044_CRB_DEV_PART_INFO2);
5755 } else {
5756 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5757 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
5758 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
5759 }
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005760 for (i = 0; i < 8; i++) {
5761 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
5762 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5763 (i != ha->portnum)) {
5764 fcoe_other_function = i;
5765 break;
5766 }
5767 }
5768 if (fcoe_other_function == 0xffff) {
5769 for (i = 0; i < 8; i++) {
5770 class_type = ((dev_part_info2 >> (i * 4)) &
5771 class_type_mask);
5772 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5773 ((i + 8) != ha->portnum)) {
5774 fcoe_other_function = i + 8;
5775 break;
5776 }
5777 }
5778 }
5779 /*
5780 * Prepare drv-presence mask based on fcoe functions present.
5781 * However consider only valid physical fcoe function numbers (0-15).
5782 */
5783 drv_presence_mask = ~((1 << (ha->portnum)) |
5784 ((fcoe_other_function == 0xffff) ?
5785 0 : (1 << (fcoe_other_function))));
5786
5787 /* We are the reset owner iff:
5788 * - No other protocol drivers present.
5789 * - This is the lowest among fcoe functions. */
5790 if (!(drv_presence & drv_presence_mask) &&
5791 (ha->portnum < fcoe_other_function)) {
5792 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
5793 "This host is Reset owner.\n");
5794 ha->flags.nic_core_reset_owner = 1;
5795 }
5796}
5797
Saurav Kashyapfa492632012-11-21 02:40:29 -05005798static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005799__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
5800{
5801 int rval = QLA_SUCCESS;
5802 struct qla_hw_data *ha = vha->hw;
5803 uint32_t drv_ack;
5804
5805 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5806 if (rval == QLA_SUCCESS) {
5807 drv_ack |= (1 << ha->portnum);
5808 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5809 }
5810
5811 return rval;
5812}
5813
Saurav Kashyapfa492632012-11-21 02:40:29 -05005814static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005815__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
5816{
5817 int rval = QLA_SUCCESS;
5818 struct qla_hw_data *ha = vha->hw;
5819 uint32_t drv_ack;
5820
5821 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5822 if (rval == QLA_SUCCESS) {
5823 drv_ack &= ~(1 << ha->portnum);
5824 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5825 }
5826
5827 return rval;
5828}
5829
Saurav Kashyapfa492632012-11-21 02:40:29 -05005830static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005831qla83xx_dev_state_to_string(uint32_t dev_state)
5832{
5833 switch (dev_state) {
5834 case QLA8XXX_DEV_COLD:
5835 return "COLD/RE-INIT";
5836 case QLA8XXX_DEV_INITIALIZING:
5837 return "INITIALIZING";
5838 case QLA8XXX_DEV_READY:
5839 return "READY";
5840 case QLA8XXX_DEV_NEED_RESET:
5841 return "NEED RESET";
5842 case QLA8XXX_DEV_NEED_QUIESCENT:
5843 return "NEED QUIESCENT";
5844 case QLA8XXX_DEV_FAILED:
5845 return "FAILED";
5846 case QLA8XXX_DEV_QUIESCENT:
5847 return "QUIESCENT";
5848 default:
5849 return "Unknown";
5850 }
5851}
5852
5853/* Assumes idc-lock always held on entry */
5854void
5855qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
5856{
5857 struct qla_hw_data *ha = vha->hw;
5858 uint32_t idc_audit_reg = 0, duration_secs = 0;
5859
5860 switch (audit_type) {
5861 case IDC_AUDIT_TIMESTAMP:
5862 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
5863 idc_audit_reg = (ha->portnum) |
5864 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
5865 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5866 break;
5867
5868 case IDC_AUDIT_COMPLETION:
5869 duration_secs = ((jiffies_to_msecs(jiffies) -
5870 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
5871 idc_audit_reg = (ha->portnum) |
5872 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
5873 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5874 break;
5875
5876 default:
5877 ql_log(ql_log_warn, vha, 0xb078,
5878 "Invalid audit type specified.\n");
5879 break;
5880 }
5881}
5882
5883/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05005884static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005885qla83xx_initiating_reset(scsi_qla_host_t *vha)
5886{
5887 struct qla_hw_data *ha = vha->hw;
5888 uint32_t idc_control, dev_state;
5889
5890 __qla83xx_get_idc_control(vha, &idc_control);
5891 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
5892 ql_log(ql_log_info, vha, 0xb080,
5893 "NIC Core reset has been disabled. idc-control=0x%x\n",
5894 idc_control);
5895 return QLA_FUNCTION_FAILED;
5896 }
5897
5898 /* Set NEED-RESET iff in READY state and we are the reset-owner */
5899 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5900 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
5901 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
5902 QLA8XXX_DEV_NEED_RESET);
5903 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
5904 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
5905 } else {
5906 const char *state = qla83xx_dev_state_to_string(dev_state);
5907 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
5908
5909 /* SV: XXX: Is timeout required here? */
5910 /* Wait for IDC state change READY -> NEED_RESET */
5911 while (dev_state == QLA8XXX_DEV_READY) {
5912 qla83xx_idc_unlock(vha, 0);
5913 msleep(200);
5914 qla83xx_idc_lock(vha, 0);
5915 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5916 }
5917 }
5918
5919 /* Send IDC ack by writing to drv-ack register */
5920 __qla83xx_set_drv_ack(vha);
5921
5922 return QLA_SUCCESS;
5923}
5924
5925int
5926__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
5927{
5928 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5929}
5930
5931int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005932__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
5933{
5934 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5935}
5936
Saurav Kashyapfa492632012-11-21 02:40:29 -05005937static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005938qla83xx_check_driver_presence(scsi_qla_host_t *vha)
5939{
5940 uint32_t drv_presence = 0;
5941 struct qla_hw_data *ha = vha->hw;
5942
5943 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5944 if (drv_presence & (1 << ha->portnum))
5945 return QLA_SUCCESS;
5946 else
5947 return QLA_TEST_FAILED;
5948}
5949
5950int
5951qla83xx_nic_core_reset(scsi_qla_host_t *vha)
5952{
5953 int rval = QLA_SUCCESS;
5954 struct qla_hw_data *ha = vha->hw;
5955
5956 ql_dbg(ql_dbg_p3p, vha, 0xb058,
5957 "Entered %s().\n", __func__);
5958
5959 if (vha->device_flags & DFLG_DEV_FAILED) {
5960 ql_log(ql_log_warn, vha, 0xb059,
5961 "Device in unrecoverable FAILED state.\n");
5962 return QLA_FUNCTION_FAILED;
5963 }
5964
5965 qla83xx_idc_lock(vha, 0);
5966
5967 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
5968 ql_log(ql_log_warn, vha, 0xb05a,
5969 "Function=0x%x has been removed from IDC participation.\n",
5970 ha->portnum);
5971 rval = QLA_FUNCTION_FAILED;
5972 goto exit;
5973 }
5974
5975 qla83xx_reset_ownership(vha);
5976
5977 rval = qla83xx_initiating_reset(vha);
5978
5979 /*
5980 * Perform reset if we are the reset-owner,
5981 * else wait till IDC state changes to READY/FAILED.
5982 */
5983 if (rval == QLA_SUCCESS) {
5984 rval = qla83xx_idc_state_handler(vha);
5985
5986 if (rval == QLA_SUCCESS)
5987 ha->flags.nic_core_hung = 0;
5988 __qla83xx_clear_drv_ack(vha);
5989 }
5990
5991exit:
5992 qla83xx_idc_unlock(vha, 0);
5993
5994 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
5995
5996 return rval;
5997}
5998
Saurav Kashyap81178772012-08-22 14:21:04 -04005999int
6000qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6001{
6002 struct qla_hw_data *ha = vha->hw;
6003 int rval = QLA_FUNCTION_FAILED;
6004
6005 if (!IS_MCTP_CAPABLE(ha)) {
6006 /* This message can be removed from the final version */
6007 ql_log(ql_log_info, vha, 0x506d,
6008 "This board is not MCTP capable\n");
6009 return rval;
6010 }
6011
6012 if (!ha->mctp_dump) {
6013 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6014 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6015
6016 if (!ha->mctp_dump) {
6017 ql_log(ql_log_warn, vha, 0x506e,
6018 "Failed to allocate memory for mctp dump\n");
6019 return rval;
6020 }
6021 }
6022
6023#define MCTP_DUMP_STR_ADDR 0x00000000
6024 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6025 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6026 if (rval != QLA_SUCCESS) {
6027 ql_log(ql_log_warn, vha, 0x506f,
6028 "Failed to capture mctp dump\n");
6029 } else {
6030 ql_log(ql_log_info, vha, 0x5070,
6031 "Mctp dump capture for host (%ld/%p).\n",
6032 vha->host_no, ha->mctp_dump);
6033 ha->mctp_dumped = 1;
6034 }
6035
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04006036 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04006037 ha->flags.nic_core_reset_hdlr_active = 1;
6038 rval = qla83xx_restart_nic_firmware(vha);
6039 if (rval)
6040 /* NIC Core reset failed. */
6041 ql_log(ql_log_warn, vha, 0x5071,
6042 "Failed to restart nic firmware\n");
6043 else
6044 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6045 "Restarted NIC firmware successfully.\n");
6046 ha->flags.nic_core_reset_hdlr_active = 0;
6047 }
6048
6049 return rval;
6050
6051}
6052
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006053/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006054* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006055* Description: This function will block the new I/Os
6056* Its not aborting any I/Os as context
6057* is not destroyed during quiescence
6058* Arguments: scsi_qla_host_t
6059* return : void
6060*/
6061void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006062qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006063{
6064 struct qla_hw_data *ha = vha->hw;
6065 struct scsi_qla_host *vp;
6066
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006067 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6068 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006069
6070 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6071 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6072 atomic_set(&vha->loop_state, LOOP_DOWN);
6073 qla2x00_mark_all_devices_lost(vha, 0);
6074 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006075 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006076 } else {
6077 if (!atomic_read(&vha->loop_down_timer))
6078 atomic_set(&vha->loop_down_timer,
6079 LOOP_DOWN_TIME);
6080 }
6081 /* Wait for pending cmds to complete */
6082 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
6083}
6084
Giridhar Malavalia9083012010-04-12 17:59:55 -07006085void
6086qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6087{
6088 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006089 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07006090 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08006091 fc_port_t *fcport;
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07006092 u16 i;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006093
Saurav Kashyape46ef002011-02-23 15:27:16 -08006094 /* For ISP82XX, driver waits for completion of the commands.
6095 * online flag should be set.
6096 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006097 if (!(IS_P3P_TYPE(ha)))
Saurav Kashyape46ef002011-02-23 15:27:16 -08006098 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006099 ha->flags.chip_reset_done = 0;
6100 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04006101 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006102
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006103 ql_log(ql_log_info, vha, 0x00af,
6104 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006105
Saurav Kashyape46ef002011-02-23 15:27:16 -08006106 /* For ISP82XX, reset_chip is just disabling interrupts.
6107 * Driver waits for the completion of the commands.
6108 * the interrupts need to be enabled.
6109 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006110 if (!(IS_P3P_TYPE(ha)))
Giridhar Malavalia9083012010-04-12 17:59:55 -07006111 ha->isp_ops->reset_chip(vha);
6112
Quinn Tranec7193e2017-03-15 09:48:55 -07006113 ha->flags.n2n_ae = 0;
6114 ha->flags.lip_ae = 0;
6115 ha->current_topology = 0;
6116 ha->flags.fw_started = 0;
6117 ha->flags.fw_init_done = 0;
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07006118 ha->base_qpair->chip_reset++;
6119 for (i = 0; i < ha->max_qpairs; i++) {
6120 if (ha->queue_pair_map[i])
6121 ha->queue_pair_map[i]->chip_reset =
6122 ha->base_qpair->chip_reset;
6123 }
Quinn Tran726b8542017-01-19 22:28:00 -08006124
Giridhar Malavalia9083012010-04-12 17:59:55 -07006125 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6126 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6127 atomic_set(&vha->loop_state, LOOP_DOWN);
6128 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07006129
6130 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006131 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07006132 atomic_inc(&vp->vref_count);
6133 spin_unlock_irqrestore(&ha->vport_slock, flags);
6134
Giridhar Malavalia9083012010-04-12 17:59:55 -07006135 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07006136
6137 spin_lock_irqsave(&ha->vport_slock, flags);
6138 atomic_dec(&vp->vref_count);
6139 }
6140 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006141 } else {
6142 if (!atomic_read(&vha->loop_down_timer))
6143 atomic_set(&vha->loop_down_timer,
6144 LOOP_DOWN_TIME);
6145 }
6146
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08006147 /* Clear all async request states across all VPs. */
6148 list_for_each_entry(fcport, &vha->vp_fcports, list)
6149 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6150 spin_lock_irqsave(&ha->vport_slock, flags);
6151 list_for_each_entry(vp, &ha->vp_list, list) {
6152 atomic_inc(&vp->vref_count);
6153 spin_unlock_irqrestore(&ha->vport_slock, flags);
6154
6155 list_for_each_entry(fcport, &vp->vp_fcports, list)
6156 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6157
6158 spin_lock_irqsave(&ha->vport_slock, flags);
6159 atomic_dec(&vp->vref_count);
6160 }
6161 spin_unlock_irqrestore(&ha->vport_slock, flags);
6162
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006163 if (!ha->flags.eeh_busy) {
6164 /* Make sure for ISP 82XX IO DMA is complete */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006165 if (IS_P3P_TYPE(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006166 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006167 ql_log(ql_log_info, vha, 0x00b4,
6168 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006169
Saurav Kashyape46ef002011-02-23 15:27:16 -08006170 /* Done waiting for pending commands.
6171 * Reset the online flag.
6172 */
6173 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006174 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006175
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006176 /* Requeue all commands in outstanding command list. */
6177 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6178 }
Arun Easib6a029e2014-09-25 06:14:52 -04006179 /* memory barrier */
6180 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181}
6182
6183/*
6184* qla2x00_abort_isp
6185* Resets ISP and aborts all outstanding commands.
6186*
6187* Input:
6188* ha = adapter block pointer.
6189*
6190* Returns:
6191* 0 = success
6192*/
6193int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006194qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195{
Andrew Vasquez476e8972006-08-23 14:54:55 -07006196 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006197 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006198 struct qla_hw_data *ha = vha->hw;
6199 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006200 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07006201 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006203 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07006204 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006205
Santosh Vernekara61712972012-08-22 14:21:13 -04006206 if (IS_QLA8031(ha)) {
6207 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6208 "Clearing fcoe driver presence.\n");
6209 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6210 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6211 "Error while clearing DRV-Presence.\n");
6212 }
6213
Andrew Vasquez85880802009-12-15 21:29:46 -08006214 if (unlikely(pci_channel_offline(ha->pdev) &&
6215 ha->flags.pci_channel_io_perm_failure)) {
6216 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6217 status = 0;
6218 return status;
6219 }
6220
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006221 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08006222
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006223 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006224
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006225 if (!qla2x00_restart_isp(vha)) {
6226 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006227
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006228 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006229 /*
6230 * Issue marker command only when we are going
6231 * to start the I/O .
6232 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006233 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006234 }
6235
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006236 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006237
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006238 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07006240 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006241 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07006242
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006243 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6244 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08006245 if (ha->fce) {
6246 ha->flags.fce_enabled = 1;
6247 memset(ha->fce, 0,
6248 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006249 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08006250 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6251 &ha->fce_bufs);
6252 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006253 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08006254 "Unable to reinitialize FCE "
6255 "(%d).\n", rval);
6256 ha->flags.fce_enabled = 0;
6257 }
6258 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006259
6260 if (ha->eft) {
6261 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006262 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006263 ha->eft_dma, EFT_NUM_BUFFERS);
6264 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006265 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006266 "Unable to reinitialize EFT "
6267 "(%d).\n", rval);
6268 }
6269 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006271 vha->flags.online = 1;
6272 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006274 ql_log(ql_log_fatal, vha, 0x8035,
6275 "ISP error recover failed - "
6276 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07006277 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006278 * The next call disables the board
6279 * completely.
6280 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006281 ha->isp_ops->reset_adapter(vha);
6282 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006283 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006284 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285 status = 0;
6286 } else { /* schedule another ISP abort */
6287 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006288 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6289 "ISP abort - retry remaining %d.\n",
6290 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006291 status = 1;
6292 }
6293 } else {
6294 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006295 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6296 "ISP error recovery - retrying (%d) "
6297 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006298 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006299 status = 1;
6300 }
6301 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07006302
Linus Torvalds1da177e2005-04-16 15:20:36 -07006303 }
6304
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006305 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006306 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Quinn Tran1608cc42017-08-23 15:05:03 -07006307 qla2x00_configure_hba(vha);
Arun Easifeafb7b2010-09-03 14:57:00 -07006308 spin_lock_irqsave(&ha->vport_slock, flags);
6309 list_for_each_entry(vp, &ha->vp_list, list) {
6310 if (vp->vp_idx) {
6311 atomic_inc(&vp->vref_count);
6312 spin_unlock_irqrestore(&ha->vport_slock, flags);
6313
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006314 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07006315
6316 spin_lock_irqsave(&ha->vport_slock, flags);
6317 atomic_dec(&vp->vref_count);
6318 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006319 }
Arun Easifeafb7b2010-09-03 14:57:00 -07006320 spin_unlock_irqrestore(&ha->vport_slock, flags);
6321
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006322 if (IS_QLA8031(ha)) {
6323 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6324 "Setting back fcoe driver presence.\n");
6325 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6326 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6327 "Error while setting DRV-Presence.\n");
6328 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006329 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08006330 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6331 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332 }
6333
6334 return(status);
6335}
6336
6337/*
6338* qla2x00_restart_isp
6339* restarts the ISP after a reset
6340*
6341* Input:
6342* ha = adapter block pointer.
6343*
6344* Returns:
6345* 0 = success
6346*/
6347static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006348qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006349{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08006350 int status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006351 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006352 struct req_que *req = ha->req_q_map[0];
6353 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354
6355 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006356 if (qla2x00_isp_firmware(vha)) {
6357 vha->flags.online = 0;
6358 status = ha->isp_ops->chip_diag(vha);
6359 if (!status)
6360 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006361 }
6362
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006363 if (!status && !(status = qla2x00_init_rings(vha))) {
6364 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07006365 ha->flags.chip_reset_done = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04006366
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006367 /* Initialize the queues in use */
6368 qla25xx_init_queues(ha);
6369
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006370 status = qla2x00_fw_ready(vha);
6371 if (!status) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006372 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006373 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Chad Dupuis7108b762014-04-11 16:54:45 -04006374 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006375 }
6376
6377 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006378 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006379 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006380 }
6381 return (status);
6382}
6383
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006384static int
6385qla25xx_init_queues(struct qla_hw_data *ha)
6386{
6387 struct rsp_que *rsp = NULL;
6388 struct req_que *req = NULL;
6389 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6390 int ret = -1;
6391 int i;
6392
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07006393 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006394 rsp = ha->rsp_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05006395 if (rsp && test_bit(i, ha->rsp_qid_map)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006396 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08006397 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006398 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006399 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6400 "%s Rsp que: %d init failed.\n",
6401 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006402 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006403 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6404 "%s Rsp que: %d inited.\n",
6405 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006406 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07006407 }
6408 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006409 req = ha->req_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05006410 if (req && test_bit(i, ha->req_qid_map)) {
6411 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006412 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08006413 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006414 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006415 ql_dbg(ql_dbg_init, base_vha, 0x0101,
6416 "%s Req que: %d init failed.\n",
6417 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006418 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006419 ql_dbg(ql_dbg_init, base_vha, 0x0102,
6420 "%s Req que: %d inited.\n",
6421 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006422 }
6423 }
6424 return ret;
6425}
6426
Linus Torvalds1da177e2005-04-16 15:20:36 -07006427/*
6428* qla2x00_reset_adapter
6429* Reset adapter.
6430*
6431* Input:
6432* ha = adapter block pointer.
6433*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07006434void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006435qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006436{
6437 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006438 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07006439 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006440
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006441 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006442 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444 spin_lock_irqsave(&ha->hardware_lock, flags);
6445 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
6446 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
6447 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
6448 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
6449 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6450}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006451
6452void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006453qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006454{
6455 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006456 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006457 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
6458
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006459 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07006460 return;
6461
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006462 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006463 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006464
6465 spin_lock_irqsave(&ha->hardware_lock, flags);
6466 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
6467 RD_REG_DWORD(&reg->hccr);
6468 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
6469 RD_REG_DWORD(&reg->hccr);
6470 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08006471
6472 if (IS_NOPOLLING_TYPE(ha))
6473 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006474}
6475
David Miller4e08df32007-04-16 12:37:43 -07006476/* On sparc systems, obtain port and node WWN from firmware
6477 * properties.
6478 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006479static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
6480 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07006481{
6482#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006483 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07006484 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07006485 struct device_node *dp = pci_device_to_OF_node(pdev);
6486 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07006487 int len;
6488
6489 val = of_get_property(dp, "port-wwn", &len);
6490 if (val && len >= WWN_SIZE)
6491 memcpy(nv->port_name, val, WWN_SIZE);
6492
6493 val = of_get_property(dp, "node-wwn", &len);
6494 if (val && len >= WWN_SIZE)
6495 memcpy(nv->node_name, val, WWN_SIZE);
6496#endif
6497}
6498
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006499int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006500qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006501{
David Miller4e08df32007-04-16 12:37:43 -07006502 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006503 struct init_cb_24xx *icb;
6504 struct nvram_24xx *nv;
6505 uint32_t *dptr;
6506 uint8_t *dptr1, *dptr2;
6507 uint32_t chksum;
6508 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006509 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006510
David Miller4e08df32007-04-16 12:37:43 -07006511 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006512 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07006513 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006514
6515 /* Determine NVRAM starting address. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05006516 if (ha->port_no == 0) {
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07006517 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
6518 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
6519 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006520 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08006521 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
6522 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05006523
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07006524 ha->nvram_size = sizeof(struct nvram_24xx);
6525 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006526
Seokmann Ju281afe12007-07-26 13:43:34 -07006527 /* Get VPD data into cache */
6528 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006529 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07006530 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
6531
6532 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006533 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006534 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006535 ha->nvram_size);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006536 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
6537 chksum += le32_to_cpu(*dptr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006538
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006539 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
6540 "Contents of NVRAM\n");
6541 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
6542 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006543
6544 /* Bad NVRAM data, set defaults parameters. */
6545 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6546 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07006547 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006548 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006549 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04006550 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006551 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
6552 ql_log(ql_log_warn, vha, 0x006c,
6553 "Falling back to functioning (yet invalid -- WWPN) "
6554 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07006555
6556 /*
6557 * Set default initialization control block.
6558 */
6559 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07006560 nv->nvram_version = cpu_to_le16(ICB_VERSION);
6561 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04006562 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07006563 nv->execution_throttle = cpu_to_le16(0xFFFF);
6564 nv->exchange_count = cpu_to_le16(0);
6565 nv->hard_address = cpu_to_le16(124);
David Miller4e08df32007-04-16 12:37:43 -07006566 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006567 nv->port_name[1] = 0x00 + ha->port_no + 1;
David Miller4e08df32007-04-16 12:37:43 -07006568 nv->port_name[2] = 0x00;
6569 nv->port_name[3] = 0xe0;
6570 nv->port_name[4] = 0x8b;
6571 nv->port_name[5] = 0x1c;
6572 nv->port_name[6] = 0x55;
6573 nv->port_name[7] = 0x86;
6574 nv->node_name[0] = 0x20;
6575 nv->node_name[1] = 0x00;
6576 nv->node_name[2] = 0x00;
6577 nv->node_name[3] = 0xe0;
6578 nv->node_name[4] = 0x8b;
6579 nv->node_name[5] = 0x1c;
6580 nv->node_name[6] = 0x55;
6581 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006582 qla24xx_nvram_wwn_from_ofw(vha, nv);
Bart Van Asschead950362015-07-09 07:24:08 -07006583 nv->login_retry_count = cpu_to_le16(8);
6584 nv->interrupt_delay_timer = cpu_to_le16(0);
6585 nv->login_timeout = cpu_to_le16(0);
David Miller4e08df32007-04-16 12:37:43 -07006586 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07006587 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6588 nv->firmware_options_2 = cpu_to_le32(2 << 4);
6589 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6590 nv->firmware_options_3 = cpu_to_le32(2 << 13);
6591 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6592 nv->efi_parameters = cpu_to_le32(0);
David Miller4e08df32007-04-16 12:37:43 -07006593 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07006594 nv->max_luns_per_target = cpu_to_le16(128);
6595 nv->port_down_retry_count = cpu_to_le16(30);
6596 nv->link_down_timeout = cpu_to_le16(30);
David Miller4e08df32007-04-16 12:37:43 -07006597
6598 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006599 }
6600
Quinn Tran726b8542017-01-19 22:28:00 -08006601 if (qla_tgt_mode_enabled(vha)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006602 /* Don't enable full login after initial LIP */
Bart Van Asschead950362015-07-09 07:24:08 -07006603 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006604 /* Don't enable LIP full login for initiator */
Bart Van Asschead950362015-07-09 07:24:08 -07006605 nv->host_p &= cpu_to_le32(~BIT_10);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006606 }
6607
6608 qlt_24xx_config_nvram_stage1(vha, nv);
6609
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006610 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006611 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006612
6613 /* Copy 1st segment. */
6614 dptr1 = (uint8_t *)icb;
6615 dptr2 = (uint8_t *)&nv->version;
6616 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6617 while (cnt--)
6618 *dptr1++ = *dptr2++;
6619
6620 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07006621 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006622
6623 /* Copy 2nd segment. */
6624 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6625 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6626 cnt = (uint8_t *)&icb->reserved_3 -
6627 (uint8_t *)&icb->interrupt_delay_timer;
6628 while (cnt--)
6629 *dptr1++ = *dptr2++;
6630
6631 /*
6632 * Setup driver NVRAM options.
6633 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006634 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08006635 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006636
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006637 qlt_24xx_config_nvram_stage2(vha, icb);
6638
Bart Van Asschead950362015-07-09 07:24:08 -07006639 if (nv->host_p & cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006640 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07006641 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6642 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6643 }
6644
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006645 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07006646 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006647 /*
6648 * Firmware will apply the following mask if the nodename was
6649 * not provided.
6650 */
6651 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6652 icb->node_name[0] &= 0xF0;
6653 }
6654
6655 /* Set host adapter parameters. */
6656 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08006657 ha->flags.enable_lip_reset = 0;
6658 ha->flags.enable_lip_full_login =
6659 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6660 ha->flags.enable_target_reset =
6661 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006662 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07006663 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006664
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07006665 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6666 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006667
6668 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
6669 sizeof(ha->fw_seriallink_options24));
6670
6671 /* save HBA serial number */
6672 ha->serial0 = icb->port_name[5];
6673 ha->serial1 = icb->port_name[6];
6674 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006675 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6676 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006677
Bart Van Asschead950362015-07-09 07:24:08 -07006678 icb->execution_throttle = cpu_to_le16(0xFFFF);
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08006679
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006680 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6681
6682 /* Set minimum login_timeout to 4 seconds. */
6683 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6684 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6685 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07006686 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006687 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006688
Andrew Vasquez00a537b2008-02-28 14:06:11 -08006689 /* Set minimum RATOV to 100 tenths of a second. */
6690 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006691
6692 ha->loop_reset_delay = nv->reset_delay;
6693
6694 /* Link Down Timeout = 0:
6695 *
6696 * When Port Down timer expires we will start returning
6697 * I/O's to OS with "DID_NO_CONNECT".
6698 *
6699 * Link Down Timeout != 0:
6700 *
6701 * The driver waits for the link to come up after link down
6702 * before returning I/Os to OS with "DID_NO_CONNECT".
6703 */
6704 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6705 ha->loop_down_abort_time =
6706 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6707 } else {
6708 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6709 ha->loop_down_abort_time =
6710 (LOOP_DOWN_TIME - ha->link_down_timeout);
6711 }
6712
6713 /* Need enough time to try and get the port back. */
6714 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6715 if (qlport_down_retry)
6716 ha->port_down_retry_count = qlport_down_retry;
6717
6718 /* Set login_retry_count */
6719 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6720 if (ha->port_down_retry_count ==
6721 le16_to_cpu(nv->port_down_retry_count) &&
6722 ha->port_down_retry_count > 3)
6723 ha->login_retry_count = ha->port_down_retry_count;
6724 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6725 ha->login_retry_count = ha->port_down_retry_count;
6726 if (ql2xloginretrycount)
6727 ha->login_retry_count = ql2xloginretrycount;
6728
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006729 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006730 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006731 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6732 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6733 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6734 le16_to_cpu(icb->interrupt_delay_timer): 2;
6735 }
Bart Van Asschead950362015-07-09 07:24:08 -07006736 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006737 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006738 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006739 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08006740 ha->zio_mode = QLA_ZIO_MODE_6;
6741
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006742 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006743 "ZIO mode %d enabled; timer delay (%d us).\n",
6744 ha->zio_mode, ha->zio_timer * 100);
6745
6746 icb->firmware_options_2 |= cpu_to_le32(
6747 (uint32_t)ha->zio_mode);
6748 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006749 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006750 }
6751
David Miller4e08df32007-04-16 12:37:43 -07006752 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006753 ql_log(ql_log_warn, vha, 0x0070,
6754 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07006755 }
6756 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006757}
6758
Sawan Chandak4243c112016-01-27 12:03:31 -05006759uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
6760{
6761 struct qla27xx_image_status pri_image_status, sec_image_status;
6762 uint8_t valid_pri_image, valid_sec_image;
6763 uint32_t *wptr;
6764 uint32_t cnt, chksum, size;
6765 struct qla_hw_data *ha = vha->hw;
6766
6767 valid_pri_image = valid_sec_image = 1;
6768 ha->active_image = 0;
6769 size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
6770
6771 if (!ha->flt_region_img_status_pri) {
6772 valid_pri_image = 0;
6773 goto check_sec_image;
6774 }
6775
6776 qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
6777 ha->flt_region_img_status_pri, size);
6778
6779 if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6780 ql_dbg(ql_dbg_init, vha, 0x018b,
6781 "Primary image signature (0x%x) not valid\n",
6782 pri_image_status.signature);
6783 valid_pri_image = 0;
6784 goto check_sec_image;
6785 }
6786
6787 wptr = (uint32_t *)(&pri_image_status);
6788 cnt = size;
6789
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006790 for (chksum = 0; cnt--; wptr++)
6791 chksum += le32_to_cpu(*wptr);
Quinn Tran41dc5292017-01-19 22:28:03 -08006792
Sawan Chandak4243c112016-01-27 12:03:31 -05006793 if (chksum) {
6794 ql_dbg(ql_dbg_init, vha, 0x018c,
6795 "Checksum validation failed for primary image (0x%x)\n",
6796 chksum);
6797 valid_pri_image = 0;
6798 }
6799
6800check_sec_image:
6801 if (!ha->flt_region_img_status_sec) {
6802 valid_sec_image = 0;
6803 goto check_valid_image;
6804 }
6805
6806 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
6807 ha->flt_region_img_status_sec, size);
6808
6809 if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6810 ql_dbg(ql_dbg_init, vha, 0x018d,
6811 "Secondary image signature(0x%x) not valid\n",
6812 sec_image_status.signature);
6813 valid_sec_image = 0;
6814 goto check_valid_image;
6815 }
6816
6817 wptr = (uint32_t *)(&sec_image_status);
6818 cnt = size;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006819 for (chksum = 0; cnt--; wptr++)
6820 chksum += le32_to_cpu(*wptr);
Sawan Chandak4243c112016-01-27 12:03:31 -05006821 if (chksum) {
6822 ql_dbg(ql_dbg_init, vha, 0x018e,
6823 "Checksum validation failed for secondary image (0x%x)\n",
6824 chksum);
6825 valid_sec_image = 0;
6826 }
6827
6828check_valid_image:
6829 if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
6830 ha->active_image = QLA27XX_PRIMARY_IMAGE;
6831 if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
6832 if (!ha->active_image ||
6833 pri_image_status.generation_number <
6834 sec_image_status.generation_number)
6835 ha->active_image = QLA27XX_SECONDARY_IMAGE;
6836 }
6837
6838 ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n",
6839 ha->active_image == 0 ? "default bootld and fw" :
6840 ha->active_image == 1 ? "primary" :
6841 ha->active_image == 2 ? "secondary" :
6842 "Invalid");
6843
6844 return ha->active_image;
6845}
6846
Adrian Bunk413975a2006-06-30 02:33:06 -07006847static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006848qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
6849 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006850{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006851 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006852 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006853 uint32_t *dcode, dlen;
6854 uint32_t risc_addr;
6855 uint32_t risc_size;
6856 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006857 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006858 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006859
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006860 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006861 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006862
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006863 rval = QLA_SUCCESS;
6864
6865 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006866 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006867 *srisc_addr = 0;
6868
Sawan Chandak4243c112016-01-27 12:03:31 -05006869 if (IS_QLA27XX(ha) &&
6870 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
6871 faddr = ha->flt_region_fw_sec;
6872
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006873 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006874 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006875 for (i = 0; i < 4; i++)
6876 dcode[i] = be32_to_cpu(dcode[i]);
6877 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
6878 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
6879 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
6880 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006881 ql_log(ql_log_fatal, vha, 0x008c,
6882 "Unable to verify the integrity of flash firmware "
6883 "image.\n");
6884 ql_log(ql_log_fatal, vha, 0x008d,
6885 "Firmware data: %08x %08x %08x %08x.\n",
6886 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006887
6888 return QLA_FUNCTION_FAILED;
6889 }
6890
6891 while (segments && rval == QLA_SUCCESS) {
6892 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006893 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006894
6895 risc_addr = be32_to_cpu(dcode[2]);
6896 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
6897 risc_size = be32_to_cpu(dcode[3]);
6898
6899 fragment = 0;
6900 while (risc_size > 0 && rval == QLA_SUCCESS) {
6901 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
6902 if (dlen > risc_size)
6903 dlen = risc_size;
6904
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006905 ql_dbg(ql_dbg_init, vha, 0x008e,
6906 "Loading risc segment@ risc addr %x "
6907 "number of dwords 0x%x offset 0x%x.\n",
6908 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006909
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006910 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006911 for (i = 0; i < dlen; i++)
6912 dcode[i] = swab32(dcode[i]);
6913
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006914 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006915 dlen);
6916 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006917 ql_log(ql_log_fatal, vha, 0x008f,
6918 "Failed to load segment %d of firmware.\n",
6919 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04006920 return QLA_FUNCTION_FAILED;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006921 }
6922
6923 faddr += dlen;
6924 risc_addr += dlen;
6925 risc_size -= dlen;
6926 fragment++;
6927 }
6928
6929 /* Next segment. */
6930 segments--;
6931 }
6932
Chad Dupuisf73cb692014-02-26 04:15:06 -05006933 if (!IS_QLA27XX(ha))
6934 return rval;
6935
6936 if (ha->fw_dump_template)
6937 vfree(ha->fw_dump_template);
6938 ha->fw_dump_template = NULL;
6939 ha->fw_dump_template_len = 0;
6940
6941 ql_dbg(ql_dbg_init, vha, 0x0161,
6942 "Loading fwdump template from %x\n", faddr);
6943 qla24xx_read_flash_data(vha, dcode, faddr, 7);
6944 risc_size = be32_to_cpu(dcode[2]);
6945 ql_dbg(ql_dbg_init, vha, 0x0162,
6946 "-> array size %x dwords\n", risc_size);
6947 if (risc_size == 0 || risc_size == ~0)
6948 goto default_template;
6949
6950 dlen = (risc_size - 8) * sizeof(*dcode);
6951 ql_dbg(ql_dbg_init, vha, 0x0163,
6952 "-> template allocating %x bytes...\n", dlen);
6953 ha->fw_dump_template = vmalloc(dlen);
6954 if (!ha->fw_dump_template) {
6955 ql_log(ql_log_warn, vha, 0x0164,
6956 "Failed fwdump template allocate %x bytes.\n", risc_size);
6957 goto default_template;
6958 }
6959
6960 faddr += 7;
6961 risc_size -= 8;
6962 dcode = ha->fw_dump_template;
6963 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
6964 for (i = 0; i < risc_size; i++)
6965 dcode[i] = le32_to_cpu(dcode[i]);
6966
6967 if (!qla27xx_fwdt_template_valid(dcode)) {
6968 ql_log(ql_log_warn, vha, 0x0165,
6969 "Failed fwdump template validate\n");
6970 goto default_template;
6971 }
6972
6973 dlen = qla27xx_fwdt_template_size(dcode);
6974 ql_dbg(ql_dbg_init, vha, 0x0166,
6975 "-> template size %x bytes\n", dlen);
6976 if (dlen > risc_size * sizeof(*dcode)) {
6977 ql_log(ql_log_warn, vha, 0x0167,
Himanshu Madhani4fae52b2017-06-06 13:55:23 -07006978 "Failed fwdump template exceeds array by %zx bytes\n",
Joe Carnuccio383a2982017-06-02 09:11:55 -07006979 (size_t)(dlen - risc_size * sizeof(*dcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05006980 goto default_template;
6981 }
6982 ha->fw_dump_template_len = dlen;
6983 return rval;
6984
6985default_template:
6986 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
6987 if (ha->fw_dump_template)
6988 vfree(ha->fw_dump_template);
6989 ha->fw_dump_template = NULL;
6990 ha->fw_dump_template_len = 0;
6991
6992 dlen = qla27xx_fwdt_template_default_size();
6993 ql_dbg(ql_dbg_init, vha, 0x0169,
6994 "-> template allocating %x bytes...\n", dlen);
6995 ha->fw_dump_template = vmalloc(dlen);
6996 if (!ha->fw_dump_template) {
6997 ql_log(ql_log_warn, vha, 0x016a,
6998 "Failed fwdump template allocate %x bytes.\n", risc_size);
6999 goto failed_template;
7000 }
7001
7002 dcode = ha->fw_dump_template;
7003 risc_size = dlen / sizeof(*dcode);
7004 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
7005 for (i = 0; i < risc_size; i++)
7006 dcode[i] = be32_to_cpu(dcode[i]);
7007
7008 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7009 ql_log(ql_log_warn, vha, 0x016b,
7010 "Failed fwdump template validate\n");
7011 goto failed_template;
7012 }
7013
7014 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7015 ql_dbg(ql_dbg_init, vha, 0x016c,
7016 "-> template size %x bytes\n", dlen);
7017 ha->fw_dump_template_len = dlen;
7018 return rval;
7019
7020failed_template:
7021 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
7022 if (ha->fw_dump_template)
7023 vfree(ha->fw_dump_template);
7024 ha->fw_dump_template = NULL;
7025 ha->fw_dump_template_len = 0;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007026 return rval;
7027}
7028
Giridhar Malavalie9454a82013-02-08 01:57:47 -05007029#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007030
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007031int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007032qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08007033{
7034 int rval;
7035 int i, fragment;
7036 uint16_t *wcode, *fwcode;
7037 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7038 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007039 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007040 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08007041
7042 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007043 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08007044 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007045 ql_log(ql_log_info, vha, 0x0083,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01007046 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007047 ql_log(ql_log_info, vha, 0x0084,
7048 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08007049 return QLA_FUNCTION_FAILED;
7050 }
7051
7052 rval = QLA_SUCCESS;
7053
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007054 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08007055 *srisc_addr = 0;
7056 fwcode = (uint16_t *)blob->fw->data;
7057 fwclen = 0;
7058
7059 /* Validate firmware image by checking version. */
7060 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007061 ql_log(ql_log_fatal, vha, 0x0085,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007062 "Unable to verify integrity of firmware image (%zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08007063 blob->fw->size);
7064 goto fail_fw_integrity;
7065 }
7066 for (i = 0; i < 4; i++)
7067 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7068 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7069 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7070 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007071 ql_log(ql_log_fatal, vha, 0x0086,
7072 "Unable to verify integrity of firmware image.\n");
7073 ql_log(ql_log_fatal, vha, 0x0087,
7074 "Firmware data: %04x %04x %04x %04x.\n",
7075 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08007076 goto fail_fw_integrity;
7077 }
7078
7079 seg = blob->segs;
7080 while (*seg && rval == QLA_SUCCESS) {
7081 risc_addr = *seg;
7082 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7083 risc_size = be16_to_cpu(fwcode[3]);
7084
7085 /* Validate firmware image size. */
7086 fwclen += risc_size * sizeof(uint16_t);
7087 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007088 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08007089 "Unable to verify integrity of firmware image "
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007090 "(%zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08007091 goto fail_fw_integrity;
7092 }
7093
7094 fragment = 0;
7095 while (risc_size > 0 && rval == QLA_SUCCESS) {
7096 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7097 if (wlen > risc_size)
7098 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007099 ql_dbg(ql_dbg_init, vha, 0x0089,
7100 "Loading risc segment@ risc addr %x number of "
7101 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08007102
7103 for (i = 0; i < wlen; i++)
7104 wcode[i] = swab16(fwcode[i]);
7105
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007106 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08007107 wlen);
7108 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007109 ql_log(ql_log_fatal, vha, 0x008a,
7110 "Failed to load segment %d of firmware.\n",
7111 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08007112 break;
7113 }
7114
7115 fwcode += wlen;
7116 risc_addr += wlen;
7117 risc_size -= wlen;
7118 fragment++;
7119 }
7120
7121 /* Next segment. */
7122 seg++;
7123 }
7124 return rval;
7125
7126fail_fw_integrity:
7127 return QLA_FUNCTION_FAILED;
7128}
7129
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007130static int
7131qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007132{
7133 int rval;
7134 int segments, fragment;
7135 uint32_t *dcode, dlen;
7136 uint32_t risc_addr;
7137 uint32_t risc_size;
7138 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08007139 struct fw_blob *blob;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007140 const uint32_t *fwcode;
7141 uint32_t fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007142 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007143 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007144
Andrew Vasquez54333832005-11-09 15:49:04 -08007145 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007146 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08007147 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007148 ql_log(ql_log_warn, vha, 0x0090,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01007149 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007150 ql_log(ql_log_warn, vha, 0x0091,
7151 "Firmware images can be retrieved from: "
7152 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007153
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007154 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007155 }
7156
Chad Dupuiscfb09192011-11-18 09:03:07 -08007157 ql_dbg(ql_dbg_init, vha, 0x0092,
7158 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007159
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007160 rval = QLA_SUCCESS;
7161
7162 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007163 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007164 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08007165 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007166 fwclen = 0;
7167
7168 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08007169 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007170 ql_log(ql_log_fatal, vha, 0x0093,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007171 "Unable to verify integrity of firmware image (%zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08007172 blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05007173 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007174 }
7175 for (i = 0; i < 4; i++)
7176 dcode[i] = be32_to_cpu(fwcode[i + 4]);
7177 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
7178 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
7179 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
7180 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007181 ql_log(ql_log_fatal, vha, 0x0094,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007182 "Unable to verify integrity of firmware image (%zd).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007183 blob->fw->size);
7184 ql_log(ql_log_fatal, vha, 0x0095,
7185 "Firmware data: %08x %08x %08x %08x.\n",
7186 dcode[0], dcode[1], dcode[2], dcode[3]);
Chad Dupuisf73cb692014-02-26 04:15:06 -05007187 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007188 }
7189
7190 while (segments && rval == QLA_SUCCESS) {
7191 risc_addr = be32_to_cpu(fwcode[2]);
7192 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
7193 risc_size = be32_to_cpu(fwcode[3]);
7194
7195 /* Validate firmware image size. */
7196 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08007197 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007198 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08007199 "Unable to verify integrity of firmware image "
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007200 "(%zd).\n", blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05007201 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007202 }
7203
7204 fragment = 0;
7205 while (risc_size > 0 && rval == QLA_SUCCESS) {
7206 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
7207 if (dlen > risc_size)
7208 dlen = risc_size;
7209
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007210 ql_dbg(ql_dbg_init, vha, 0x0097,
7211 "Loading risc segment@ risc addr %x "
7212 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007213
7214 for (i = 0; i < dlen; i++)
7215 dcode[i] = swab32(fwcode[i]);
7216
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007217 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08007218 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007219 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007220 ql_log(ql_log_fatal, vha, 0x0098,
7221 "Failed to load segment %d of firmware.\n",
7222 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04007223 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007224 }
7225
7226 fwcode += dlen;
7227 risc_addr += dlen;
7228 risc_size -= dlen;
7229 fragment++;
7230 }
7231
7232 /* Next segment. */
7233 segments--;
7234 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05007235
7236 if (!IS_QLA27XX(ha))
7237 return rval;
7238
7239 if (ha->fw_dump_template)
7240 vfree(ha->fw_dump_template);
7241 ha->fw_dump_template = NULL;
7242 ha->fw_dump_template_len = 0;
7243
7244 ql_dbg(ql_dbg_init, vha, 0x171,
Chad Dupuis97ea7022014-03-13 14:16:40 -04007245 "Loading fwdump template from %x\n",
7246 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
Chad Dupuisf73cb692014-02-26 04:15:06 -05007247 risc_size = be32_to_cpu(fwcode[2]);
7248 ql_dbg(ql_dbg_init, vha, 0x172,
7249 "-> array size %x dwords\n", risc_size);
7250 if (risc_size == 0 || risc_size == ~0)
7251 goto default_template;
7252
7253 dlen = (risc_size - 8) * sizeof(*fwcode);
7254 ql_dbg(ql_dbg_init, vha, 0x0173,
7255 "-> template allocating %x bytes...\n", dlen);
7256 ha->fw_dump_template = vmalloc(dlen);
7257 if (!ha->fw_dump_template) {
7258 ql_log(ql_log_warn, vha, 0x0174,
7259 "Failed fwdump template allocate %x bytes.\n", risc_size);
7260 goto default_template;
7261 }
7262
7263 fwcode += 7;
7264 risc_size -= 8;
7265 dcode = ha->fw_dump_template;
7266 for (i = 0; i < risc_size; i++)
7267 dcode[i] = le32_to_cpu(fwcode[i]);
7268
7269 if (!qla27xx_fwdt_template_valid(dcode)) {
7270 ql_log(ql_log_warn, vha, 0x0175,
7271 "Failed fwdump template validate\n");
7272 goto default_template;
7273 }
7274
7275 dlen = qla27xx_fwdt_template_size(dcode);
7276 ql_dbg(ql_dbg_init, vha, 0x0176,
7277 "-> template size %x bytes\n", dlen);
7278 if (dlen > risc_size * sizeof(*fwcode)) {
7279 ql_log(ql_log_warn, vha, 0x0177,
Himanshu Madhani4fae52b2017-06-06 13:55:23 -07007280 "Failed fwdump template exceeds array by %zx bytes\n",
Joe Carnuccio383a2982017-06-02 09:11:55 -07007281 (size_t)(dlen - risc_size * sizeof(*fwcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05007282 goto default_template;
7283 }
7284 ha->fw_dump_template_len = dlen;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007285 return rval;
7286
Chad Dupuisf73cb692014-02-26 04:15:06 -05007287default_template:
7288 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
7289 if (ha->fw_dump_template)
7290 vfree(ha->fw_dump_template);
7291 ha->fw_dump_template = NULL;
7292 ha->fw_dump_template_len = 0;
7293
7294 dlen = qla27xx_fwdt_template_default_size();
7295 ql_dbg(ql_dbg_init, vha, 0x0179,
7296 "-> template allocating %x bytes...\n", dlen);
7297 ha->fw_dump_template = vmalloc(dlen);
7298 if (!ha->fw_dump_template) {
7299 ql_log(ql_log_warn, vha, 0x017a,
7300 "Failed fwdump template allocate %x bytes.\n", risc_size);
7301 goto failed_template;
7302 }
7303
7304 dcode = ha->fw_dump_template;
7305 risc_size = dlen / sizeof(*fwcode);
7306 fwcode = qla27xx_fwdt_template_default();
7307 for (i = 0; i < risc_size; i++)
7308 dcode[i] = be32_to_cpu(fwcode[i]);
7309
7310 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7311 ql_log(ql_log_warn, vha, 0x017b,
7312 "Failed fwdump template validate\n");
7313 goto failed_template;
7314 }
7315
7316 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7317 ql_dbg(ql_dbg_init, vha, 0x017c,
7318 "-> template size %x bytes\n", dlen);
7319 ha->fw_dump_template_len = dlen;
7320 return rval;
7321
7322failed_template:
7323 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
7324 if (ha->fw_dump_template)
7325 vfree(ha->fw_dump_template);
7326 ha->fw_dump_template = NULL;
7327 ha->fw_dump_template_len = 0;
7328 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007329}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007330
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007331int
7332qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7333{
7334 int rval;
7335
Andrew Vasqueze337d902009-04-06 22:33:49 -07007336 if (ql2xfwloadbin == 1)
7337 return qla81xx_load_risc(vha, srisc_addr);
7338
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007339 /*
7340 * FW Load priority:
7341 * 1) Firmware via request-firmware interface (.bin file).
7342 * 2) Firmware residing in flash.
7343 */
7344 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7345 if (rval == QLA_SUCCESS)
7346 return rval;
7347
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007348 return qla24xx_load_risc_flash(vha, srisc_addr,
7349 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007350}
7351
7352int
7353qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7354{
7355 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007356 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007357
Andrew Vasqueze337d902009-04-06 22:33:49 -07007358 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007359 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07007360
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007361 /*
7362 * FW Load priority:
7363 * 1) Firmware residing in flash.
7364 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007365 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007366 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007367 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007368 if (rval == QLA_SUCCESS)
7369 return rval;
7370
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007371try_blob_fw:
7372 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7373 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
7374 return rval;
7375
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007376 ql_log(ql_log_info, vha, 0x0099,
7377 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007378 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
7379 if (rval != QLA_SUCCESS)
7380 return rval;
7381
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007382 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007383 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007384 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007385}
7386
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007387void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007388qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007389{
7390 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007391 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007392
Andrew Vasquez85880802009-12-15 21:29:46 -08007393 if (ha->flags.pci_channel_io_perm_failure)
7394 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07007395 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007396 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07007397 if (!ha->fw_major_version)
7398 return;
Quinn Tranec7193e2017-03-15 09:48:55 -07007399 if (!ha->flags.fw_started)
7400 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007401
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007402 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08007403 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07007404 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007405 ha->isp_ops->reset_chip(vha);
7406 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007407 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007408 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007409 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007410 ql_log(ql_log_info, vha, 0x8015,
7411 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007412 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007413 }
Quinn Tranec7193e2017-03-15 09:48:55 -07007414
Quinn Tran4b60c822017-06-13 20:47:21 -07007415 QLA_FW_STOPPED(ha);
Quinn Tranec7193e2017-03-15 09:48:55 -07007416 ha->flags.fw_init_done = 0;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007417}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007418
7419int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007420qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007421{
7422 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08007423 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007424 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007425 struct qla_hw_data *ha = vha->hw;
7426 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007427 struct req_que *req;
7428 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007429
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007430 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007431 return -EINVAL;
7432
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007433 rval = qla2x00_fw_ready(base_vha);
Michael Hernandezd7459522016-12-12 14:40:07 -08007434 if (vha->qpair)
7435 req = vha->qpair->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007436 else
Michael Hernandezd7459522016-12-12 14:40:07 -08007437 req = ha->req_q_map[0];
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007438 rsp = req->rsp;
7439
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007440 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007441 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007442 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007443 }
7444
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007445 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007446
7447 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08007448 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
7449 BIT_1);
7450 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
7451 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
7452 ql_dbg(ql_dbg_init, vha, 0x0120,
7453 "Failed SNS login: loop_id=%x, rval2=%d\n",
7454 NPH_SNS, rval2);
7455 else
7456 ql_dbg(ql_dbg_init, vha, 0x0103,
7457 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7458 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7459 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007460 return (QLA_FUNCTION_FAILED);
7461 }
7462
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007463 atomic_set(&vha->loop_down_timer, 0);
7464 atomic_set(&vha->loop_state, LOOP_UP);
7465 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7466 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
7467 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007468
7469 return rval;
7470}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007471
7472/* 84XX Support **************************************************************/
7473
7474static LIST_HEAD(qla_cs84xx_list);
7475static DEFINE_MUTEX(qla_cs84xx_mutex);
7476
7477static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007478qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007479{
7480 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007481 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007482
7483 mutex_lock(&qla_cs84xx_mutex);
7484
7485 /* Find any shared 84xx chip. */
7486 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
7487 if (cs84xx->bus == ha->pdev->bus) {
7488 kref_get(&cs84xx->kref);
7489 goto done;
7490 }
7491 }
7492
7493 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
7494 if (!cs84xx)
7495 goto done;
7496
7497 kref_init(&cs84xx->kref);
7498 spin_lock_init(&cs84xx->access_lock);
7499 mutex_init(&cs84xx->fw_update_mutex);
7500 cs84xx->bus = ha->pdev->bus;
7501
7502 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
7503done:
7504 mutex_unlock(&qla_cs84xx_mutex);
7505 return cs84xx;
7506}
7507
7508static void
7509__qla84xx_chip_release(struct kref *kref)
7510{
7511 struct qla_chip_state_84xx *cs84xx =
7512 container_of(kref, struct qla_chip_state_84xx, kref);
7513
7514 mutex_lock(&qla_cs84xx_mutex);
7515 list_del(&cs84xx->list);
7516 mutex_unlock(&qla_cs84xx_mutex);
7517 kfree(cs84xx);
7518}
7519
7520void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007521qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007522{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007523 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007524 if (ha->cs84xx)
7525 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
7526}
7527
7528static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007529qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007530{
7531 int rval;
7532 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007533 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007534
7535 mutex_lock(&ha->cs84xx->fw_update_mutex);
7536
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007537 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007538
7539 mutex_unlock(&ha->cs84xx->fw_update_mutex);
7540
7541 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
7542 QLA_SUCCESS;
7543}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007544
7545/* 81XX Support **************************************************************/
7546
7547int
7548qla81xx_nvram_config(scsi_qla_host_t *vha)
7549{
7550 int rval;
7551 struct init_cb_81xx *icb;
7552 struct nvram_81xx *nv;
7553 uint32_t *dptr;
7554 uint8_t *dptr1, *dptr2;
7555 uint32_t chksum;
7556 uint16_t cnt;
7557 struct qla_hw_data *ha = vha->hw;
7558
7559 rval = QLA_SUCCESS;
7560 icb = (struct init_cb_81xx *)ha->init_cb;
7561 nv = ha->nvram;
7562
7563 /* Determine NVRAM starting address. */
7564 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007565 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007566 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
7567 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007568
7569 /* Get VPD data into cache */
7570 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007571 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
7572 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007573
7574 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007575 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007576 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007577 dptr = (uint32_t *)nv;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05007578 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7579 chksum += le32_to_cpu(*dptr);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007580
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007581 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
7582 "Contents of NVRAM:\n");
7583 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
7584 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007585
7586 /* Bad NVRAM data, set defaults parameters. */
7587 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
7588 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07007589 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007590 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007591 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04007592 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007593 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007594 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007595 ql_log(ql_log_info, vha, 0x0074,
7596 "Falling back to functioning (yet invalid -- WWPN) "
7597 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007598
7599 /*
7600 * Set default initialization control block.
7601 */
7602 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07007603 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7604 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04007605 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07007606 nv->execution_throttle = cpu_to_le16(0xFFFF);
7607 nv->exchange_count = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007608 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007609 nv->port_name[1] = 0x00 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007610 nv->port_name[2] = 0x00;
7611 nv->port_name[3] = 0xe0;
7612 nv->port_name[4] = 0x8b;
7613 nv->port_name[5] = 0x1c;
7614 nv->port_name[6] = 0x55;
7615 nv->port_name[7] = 0x86;
7616 nv->node_name[0] = 0x20;
7617 nv->node_name[1] = 0x00;
7618 nv->node_name[2] = 0x00;
7619 nv->node_name[3] = 0xe0;
7620 nv->node_name[4] = 0x8b;
7621 nv->node_name[5] = 0x1c;
7622 nv->node_name[6] = 0x55;
7623 nv->node_name[7] = 0x86;
Bart Van Asschead950362015-07-09 07:24:08 -07007624 nv->login_retry_count = cpu_to_le16(8);
7625 nv->interrupt_delay_timer = cpu_to_le16(0);
7626 nv->login_timeout = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007627 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07007628 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7629 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7630 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7631 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7632 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7633 nv->efi_parameters = cpu_to_le32(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007634 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07007635 nv->max_luns_per_target = cpu_to_le16(128);
7636 nv->port_down_retry_count = cpu_to_le16(30);
7637 nv->link_down_timeout = cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07007638 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007639 nv->enode_mac[1] = 0xC0;
7640 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007641 nv->enode_mac[3] = 0x04;
7642 nv->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007643 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007644
7645 rval = 1;
7646 }
7647
Arun Easi9e522cd2012-08-22 14:21:31 -04007648 if (IS_T10_PI_CAPABLE(ha))
7649 nv->frame_payload_size &= ~7;
7650
Arun Easiaa230bc2013-01-30 03:34:39 -05007651 qlt_81xx_config_nvram_stage1(vha, nv);
7652
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007653 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07007654 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007655
7656 /* Copy 1st segment. */
7657 dptr1 = (uint8_t *)icb;
7658 dptr2 = (uint8_t *)&nv->version;
7659 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7660 while (cnt--)
7661 *dptr1++ = *dptr2++;
7662
7663 icb->login_retry_count = nv->login_retry_count;
7664
7665 /* Copy 2nd segment. */
7666 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7667 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7668 cnt = (uint8_t *)&icb->reserved_5 -
7669 (uint8_t *)&icb->interrupt_delay_timer;
7670 while (cnt--)
7671 *dptr1++ = *dptr2++;
7672
7673 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
7674 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
7675 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08007676 icb->enode_mac[0] = 0x00;
7677 icb->enode_mac[1] = 0xC0;
7678 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007679 icb->enode_mac[3] = 0x04;
7680 icb->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007681 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007682 }
7683
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07007684 /* Use extended-initialization control block. */
7685 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
7686
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007687 /*
7688 * Setup driver NVRAM options.
7689 */
7690 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07007691 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007692
Arun Easiaa230bc2013-01-30 03:34:39 -05007693 qlt_81xx_config_nvram_stage2(vha, icb);
7694
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007695 /* Use alternate WWN? */
Bart Van Asschead950362015-07-09 07:24:08 -07007696 if (nv->host_p & cpu_to_le32(BIT_15)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007697 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7698 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7699 }
7700
7701 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07007702 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007703 /*
7704 * Firmware will apply the following mask if the nodename was
7705 * not provided.
7706 */
7707 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7708 icb->node_name[0] &= 0xF0;
7709 }
7710
7711 /* Set host adapter parameters. */
7712 ha->flags.disable_risc_code_load = 0;
7713 ha->flags.enable_lip_reset = 0;
7714 ha->flags.enable_lip_full_login =
7715 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
7716 ha->flags.enable_target_reset =
7717 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
7718 ha->flags.enable_led_scheme = 0;
7719 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
7720
7721 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7722 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7723
7724 /* save HBA serial number */
7725 ha->serial0 = icb->port_name[5];
7726 ha->serial1 = icb->port_name[6];
7727 ha->serial2 = icb->port_name[7];
7728 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7729 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7730
Bart Van Asschead950362015-07-09 07:24:08 -07007731 icb->execution_throttle = cpu_to_le16(0xFFFF);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007732
7733 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7734
7735 /* Set minimum login_timeout to 4 seconds. */
7736 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7737 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7738 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07007739 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007740 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007741
7742 /* Set minimum RATOV to 100 tenths of a second. */
7743 ha->r_a_tov = 100;
7744
7745 ha->loop_reset_delay = nv->reset_delay;
7746
7747 /* Link Down Timeout = 0:
7748 *
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007749 * When Port Down timer expires we will start returning
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007750 * I/O's to OS with "DID_NO_CONNECT".
7751 *
7752 * Link Down Timeout != 0:
7753 *
7754 * The driver waits for the link to come up after link down
7755 * before returning I/Os to OS with "DID_NO_CONNECT".
7756 */
7757 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7758 ha->loop_down_abort_time =
7759 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7760 } else {
7761 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7762 ha->loop_down_abort_time =
7763 (LOOP_DOWN_TIME - ha->link_down_timeout);
7764 }
7765
7766 /* Need enough time to try and get the port back. */
7767 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7768 if (qlport_down_retry)
7769 ha->port_down_retry_count = qlport_down_retry;
7770
7771 /* Set login_retry_count */
7772 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7773 if (ha->port_down_retry_count ==
7774 le16_to_cpu(nv->port_down_retry_count) &&
7775 ha->port_down_retry_count > 3)
7776 ha->login_retry_count = ha->port_down_retry_count;
7777 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7778 ha->login_retry_count = ha->port_down_retry_count;
7779 if (ql2xloginretrycount)
7780 ha->login_retry_count = ql2xloginretrycount;
7781
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007782 /* if not running MSI-X we need handshaking on interrupts */
Chad Dupuisf73cb692014-02-26 04:15:06 -05007783 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
Bart Van Asschead950362015-07-09 07:24:08 -07007784 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007785
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007786 /* Enable ZIO. */
7787 if (!vha->flags.init_done) {
7788 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7789 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7790 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7791 le16_to_cpu(icb->interrupt_delay_timer): 2;
7792 }
Bart Van Asschead950362015-07-09 07:24:08 -07007793 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007794 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7795 vha->flags.process_response_queue = 0;
7796 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7797 ha->zio_mode = QLA_ZIO_MODE_6;
7798
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007799 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007800 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007801 ha->zio_mode,
7802 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007803
7804 icb->firmware_options_2 |= cpu_to_le32(
7805 (uint32_t)ha->zio_mode);
7806 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7807 vha->flags.process_response_queue = 1;
7808 }
7809
Quinn Tran41dc5292017-01-19 22:28:03 -08007810 /* enable RIDA Format2 */
7811 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))
7812 icb->firmware_options_3 |= BIT_0;
7813
Duane Grigsbyedd05de2017-10-13 09:34:06 -07007814 if (IS_QLA27XX(ha)) {
7815 icb->firmware_options_3 |= BIT_8;
7816 ql_dbg(ql_log_info, vha, 0x0075,
7817 "Enabling direct connection.\n");
7818 }
7819
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007820 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007821 ql_log(ql_log_warn, vha, 0x0076,
7822 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007823 }
7824 return (rval);
7825}
7826
Giridhar Malavalia9083012010-04-12 17:59:55 -07007827int
7828qla82xx_restart_isp(scsi_qla_host_t *vha)
7829{
7830 int status, rval;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007831 struct qla_hw_data *ha = vha->hw;
7832 struct req_que *req = ha->req_q_map[0];
7833 struct rsp_que *rsp = ha->rsp_q_map[0];
7834 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07007835 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007836
7837 status = qla2x00_init_rings(vha);
7838 if (!status) {
7839 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7840 ha->flags.chip_reset_done = 1;
7841
7842 status = qla2x00_fw_ready(vha);
7843 if (!status) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07007844 /* Issue a marker after FW becomes ready. */
7845 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007846 vha->flags.online = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04007847 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007848 }
7849
7850 /* if no cable then assume it's good */
7851 if ((vha->device_flags & DFLG_NO_CABLE))
7852 status = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007853 }
7854
7855 if (!status) {
7856 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7857
7858 if (!atomic_read(&vha->loop_down_timer)) {
7859 /*
7860 * Issue marker command only when we are going
7861 * to start the I/O .
7862 */
7863 vha->marker_needed = 1;
7864 }
7865
Giridhar Malavalia9083012010-04-12 17:59:55 -07007866 ha->isp_ops->enable_intrs(ha);
7867
7868 ha->isp_abort_cnt = 0;
7869 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7870
Saurav Kashyap53296782011-05-10 11:30:06 -07007871 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07007872 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07007873
Giridhar Malavalia9083012010-04-12 17:59:55 -07007874 if (ha->fce) {
7875 ha->flags.fce_enabled = 1;
7876 memset(ha->fce, 0,
7877 fce_calc_size(ha->fce_bufs));
7878 rval = qla2x00_enable_fce_trace(vha,
7879 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
7880 &ha->fce_bufs);
7881 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007882 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007883 "Unable to reinitialize FCE (%d).\n",
7884 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007885 ha->flags.fce_enabled = 0;
7886 }
7887 }
7888
7889 if (ha->eft) {
7890 memset(ha->eft, 0, EFT_SIZE);
7891 rval = qla2x00_enable_eft_trace(vha,
7892 ha->eft_dma, EFT_NUM_BUFFERS);
7893 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007894 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007895 "Unable to reinitialize EFT (%d).\n",
7896 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007897 }
7898 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07007899 }
7900
7901 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007902 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007903 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07007904
7905 spin_lock_irqsave(&ha->vport_slock, flags);
7906 list_for_each_entry(vp, &ha->vp_list, list) {
7907 if (vp->vp_idx) {
7908 atomic_inc(&vp->vref_count);
7909 spin_unlock_irqrestore(&ha->vport_slock, flags);
7910
Giridhar Malavalia9083012010-04-12 17:59:55 -07007911 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07007912
7913 spin_lock_irqsave(&ha->vport_slock, flags);
7914 atomic_dec(&vp->vref_count);
7915 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07007916 }
Arun Easifeafb7b2010-09-03 14:57:00 -07007917 spin_unlock_irqrestore(&ha->vport_slock, flags);
7918
Giridhar Malavalia9083012010-04-12 17:59:55 -07007919 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007920 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007921 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07007922 }
7923
7924 return status;
7925}
7926
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007927void
Andrew Vasquezae97c912010-02-18 10:07:28 -08007928qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007929{
Andrew Vasquezae97c912010-02-18 10:07:28 -08007930 struct qla_hw_data *ha = vha->hw;
7931
Himanshu Madhanif198caf2016-01-27 12:03:30 -05007932 /* Hold status IOCBs until ABTS response received. */
7933 if (ql2xfwholdabts)
7934 ha->fw_options[3] |= BIT_12;
7935
Giridhar Malavali088d09d2016-07-06 11:14:20 -04007936 /* Set Retry FLOGI in case of P2P connection */
7937 if (ha->operating_mode == P2P) {
7938 ha->fw_options[2] |= BIT_3;
7939 ql_dbg(ql_dbg_disc, vha, 0x2103,
7940 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
7941 __func__, ha->fw_options[2]);
7942 }
7943
Quinn Tran41dc5292017-01-19 22:28:03 -08007944 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
7945 if (ql2xmvasynctoatio) {
7946 if (qla_tgt_mode_enabled(vha) ||
7947 qla_dual_mode_enabled(vha))
7948 ha->fw_options[2] |= BIT_11;
7949 else
7950 ha->fw_options[2] &= ~BIT_11;
7951 }
Andrew Vasquezae97c912010-02-18 10:07:28 -08007952
Quinn Tranf7e761f2017-06-02 09:12:02 -07007953 if (qla_tgt_mode_enabled(vha) ||
Quinn Tran2da52732017-06-02 09:12:05 -07007954 qla_dual_mode_enabled(vha)) {
7955 /* FW auto send SCSI status during */
7956 ha->fw_options[1] |= BIT_8;
7957 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
7958
7959 /* FW perform Exchange validation */
Quinn Tranf7e761f2017-06-02 09:12:02 -07007960 ha->fw_options[2] |= BIT_4;
Quinn Tran2da52732017-06-02 09:12:05 -07007961 } else {
7962 ha->fw_options[1] &= ~BIT_8;
7963 ha->fw_options[10] &= 0x00ff;
7964
Quinn Tranf7e761f2017-06-02 09:12:02 -07007965 ha->fw_options[2] &= ~BIT_4;
Quinn Tran2da52732017-06-02 09:12:05 -07007966 }
Quinn Tranf7e761f2017-06-02 09:12:02 -07007967
Quinn Tran41dc5292017-01-19 22:28:03 -08007968 if (ql2xetsenable) {
7969 /* Enable ETS Burst. */
7970 memset(ha->fw_options, 0, sizeof(ha->fw_options));
7971 ha->fw_options[2] |= BIT_9;
7972 }
7973
Quinn Tran83548fe2017-06-02 09:12:01 -07007974 ql_dbg(ql_dbg_init, vha, 0x00e9,
7975 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
7976 __func__, ha->fw_options[1], ha->fw_options[2],
7977 ha->fw_options[3], vha->host->active_mode);
Quinn Tran41dc5292017-01-19 22:28:03 -08007978
Andrew Vasquezae97c912010-02-18 10:07:28 -08007979 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007980}
Sarang Radke09ff7012010-03-19 17:03:59 -07007981
7982/*
7983 * qla24xx_get_fcp_prio
7984 * Gets the fcp cmd priority value for the logged in port.
7985 * Looks for a match of the port descriptors within
7986 * each of the fcp prio config entries. If a match is found,
7987 * the tag (priority) value is returned.
7988 *
7989 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007990 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07007991 * fcport = port structure pointer.
7992 *
7993 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07007994 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007995 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07007996 *
7997 * Context:
7998 * Kernel context
7999 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008000static int
Sarang Radke09ff7012010-03-19 17:03:59 -07008001qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8002{
8003 int i, entries;
8004 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008005 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07008006 uint32_t pid1, pid2;
8007 uint64_t wwn1, wwn2;
8008 struct qla_fcp_prio_entry *pri_entry;
8009 struct qla_hw_data *ha = vha->hw;
8010
8011 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008012 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07008013
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008014 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07008015 entries = ha->fcp_prio_cfg->num_entries;
8016 pri_entry = &ha->fcp_prio_cfg->entry[0];
8017
8018 for (i = 0; i < entries; i++) {
8019 pid_match = wwn_match = 0;
8020
8021 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8022 pri_entry++;
8023 continue;
8024 }
8025
8026 /* check source pid for a match */
8027 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8028 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8029 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8030 if (pid1 == INVALID_PORT_ID)
8031 pid_match++;
8032 else if (pid1 == pid2)
8033 pid_match++;
8034 }
8035
8036 /* check destination pid for a match */
8037 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8038 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8039 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8040 if (pid1 == INVALID_PORT_ID)
8041 pid_match++;
8042 else if (pid1 == pid2)
8043 pid_match++;
8044 }
8045
8046 /* check source WWN for a match */
8047 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8048 wwn1 = wwn_to_u64(vha->port_name);
8049 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8050 if (wwn2 == (uint64_t)-1)
8051 wwn_match++;
8052 else if (wwn1 == wwn2)
8053 wwn_match++;
8054 }
8055
8056 /* check destination WWN for a match */
8057 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8058 wwn1 = wwn_to_u64(fcport->port_name);
8059 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8060 if (wwn2 == (uint64_t)-1)
8061 wwn_match++;
8062 else if (wwn1 == wwn2)
8063 wwn_match++;
8064 }
8065
8066 if (pid_match == 2 || wwn_match == 2) {
8067 /* Found a matching entry */
8068 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8069 priority = pri_entry->tag;
8070 break;
8071 }
8072
8073 pri_entry++;
8074 }
8075
8076 return priority;
8077}
8078
8079/*
8080 * qla24xx_update_fcport_fcp_prio
8081 * Activates fcp priority for the logged in fc port
8082 *
8083 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008084 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07008085 * fcp = port structure pointer.
8086 *
8087 * Return:
8088 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8089 *
8090 * Context:
8091 * Kernel context.
8092 */
8093int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008094qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07008095{
8096 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008097 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07008098 uint16_t mb[5];
8099
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008100 if (fcport->port_type != FCT_TARGET ||
8101 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07008102 return QLA_FUNCTION_FAILED;
8103
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008104 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008105 if (priority < 0)
8106 return QLA_FUNCTION_FAILED;
8107
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04008108 if (IS_P3P_TYPE(vha->hw)) {
Saurav Kashyapa00f6292011-11-18 09:03:19 -08008109 fcport->fcp_prio = priority & 0xf;
8110 return QLA_SUCCESS;
8111 }
8112
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008113 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08008114 if (ret == QLA_SUCCESS) {
8115 if (fcport->fcp_prio != priority)
8116 ql_dbg(ql_dbg_user, vha, 0x709e,
8117 "Updated FCP_CMND priority - value=%d loop_id=%d "
8118 "port_id=%02x%02x%02x.\n", priority,
8119 fcport->loop_id, fcport->d_id.b.domain,
8120 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08008121 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08008122 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07008123 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08008124 "Unable to update FCP_CMND priority - ret=0x%x for "
8125 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8126 fcport->d_id.b.domain, fcport->d_id.b.area,
8127 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07008128 return ret;
8129}
8130
8131/*
8132 * qla24xx_update_all_fcp_prio
8133 * Activates fcp priority for all the logged in ports
8134 *
8135 * Input:
8136 * ha = adapter block pointer.
8137 *
8138 * Return:
8139 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8140 *
8141 * Context:
8142 * Kernel context.
8143 */
8144int
8145qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8146{
8147 int ret;
8148 fc_port_t *fcport;
8149
8150 ret = QLA_FUNCTION_FAILED;
8151 /* We need to set priority for all logged in ports */
8152 list_for_each_entry(fcport, &vha->vp_fcports, list)
8153 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8154
8155 return ret;
8156}
Michael Hernandezd7459522016-12-12 14:40:07 -08008157
Quinn Tran82de8022017-06-13 20:47:17 -07008158struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8159 int vp_idx, bool startqp)
Michael Hernandezd7459522016-12-12 14:40:07 -08008160{
8161 int rsp_id = 0;
8162 int req_id = 0;
8163 int i;
8164 struct qla_hw_data *ha = vha->hw;
8165 uint16_t qpair_id = 0;
8166 struct qla_qpair *qpair = NULL;
8167 struct qla_msix_entry *msix;
8168
8169 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8170 ql_log(ql_log_warn, vha, 0x00181,
8171 "FW/Driver is not multi-queue capable.\n");
8172 return NULL;
8173 }
8174
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07008175 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08008176 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8177 if (qpair == NULL) {
8178 ql_log(ql_log_warn, vha, 0x0182,
8179 "Failed to allocate memory for queue pair.\n");
8180 return NULL;
8181 }
8182 memset(qpair, 0, sizeof(struct qla_qpair));
8183
8184 qpair->hw = vha->hw;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08008185 qpair->vha = vha;
Quinn Tran82de8022017-06-13 20:47:17 -07008186 qpair->qp_lock_ptr = &qpair->qp_lock;
8187 spin_lock_init(&qpair->qp_lock);
Quinn Tranaf7bb382017-06-13 20:47:23 -07008188 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
Michael Hernandezd7459522016-12-12 14:40:07 -08008189
8190 /* Assign available que pair id */
8191 mutex_lock(&ha->mq_lock);
8192 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
Sawan Chandakb95b9452017-05-24 18:06:20 -07008193 if (ha->num_qpairs >= ha->max_qpairs) {
Michael Hernandezd7459522016-12-12 14:40:07 -08008194 mutex_unlock(&ha->mq_lock);
8195 ql_log(ql_log_warn, vha, 0x0183,
8196 "No resources to create additional q pair.\n");
8197 goto fail_qid_map;
8198 }
Sawan Chandakb95b9452017-05-24 18:06:20 -07008199 ha->num_qpairs++;
Michael Hernandezd7459522016-12-12 14:40:07 -08008200 set_bit(qpair_id, ha->qpair_qid_map);
8201 ha->queue_pair_map[qpair_id] = qpair;
8202 qpair->id = qpair_id;
8203 qpair->vp_idx = vp_idx;
himanshu.madhani@cavium.come6373f332017-08-23 15:04:57 -07008204 qpair->fw_started = ha->flags.fw_started;
Quinn Trane326d222017-06-13 20:47:18 -07008205 INIT_LIST_HEAD(&qpair->hints_list);
Duane Grigsbycf19c452017-08-23 15:04:58 -07008206 INIT_LIST_HEAD(&qpair->nvme_done_list);
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07008207 qpair->chip_reset = ha->base_qpair->chip_reset;
8208 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8209 qpair->enable_explicit_conf =
8210 ha->base_qpair->enable_explicit_conf;
Michael Hernandezd7459522016-12-12 14:40:07 -08008211
8212 for (i = 0; i < ha->msix_count; i++) {
Quinn Tran093df732016-12-12 14:40:09 -08008213 msix = &ha->msix_entries[i];
Michael Hernandezd7459522016-12-12 14:40:07 -08008214 if (msix->in_use)
8215 continue;
8216 qpair->msix = msix;
Quinn Tran83548fe2017-06-02 09:12:01 -07008217 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
Michael Hernandezd7459522016-12-12 14:40:07 -08008218 "Vector %x selected for qpair\n", msix->vector);
8219 break;
8220 }
8221 if (!qpair->msix) {
8222 ql_log(ql_log_warn, vha, 0x0184,
8223 "Out of MSI-X vectors!.\n");
8224 goto fail_msix;
8225 }
8226
8227 qpair->msix->in_use = 1;
8228 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
Quinn Tran8abfa9e2017-06-13 20:47:24 -07008229 qpair->pdev = ha->pdev;
8230 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
8231 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
Michael Hernandezd7459522016-12-12 14:40:07 -08008232
8233 mutex_unlock(&ha->mq_lock);
8234
8235 /* Create response queue first */
Quinn Tran82de8022017-06-13 20:47:17 -07008236 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
Michael Hernandezd7459522016-12-12 14:40:07 -08008237 if (!rsp_id) {
8238 ql_log(ql_log_warn, vha, 0x0185,
8239 "Failed to create response queue.\n");
8240 goto fail_rsp;
8241 }
8242
8243 qpair->rsp = ha->rsp_q_map[rsp_id];
8244
8245 /* Create request queue */
Quinn Tran82de8022017-06-13 20:47:17 -07008246 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
8247 startqp);
Michael Hernandezd7459522016-12-12 14:40:07 -08008248 if (!req_id) {
8249 ql_log(ql_log_warn, vha, 0x0186,
8250 "Failed to create request queue.\n");
8251 goto fail_req;
8252 }
8253
8254 qpair->req = ha->req_q_map[req_id];
8255 qpair->rsp->req = qpair->req;
Quinn Tran82de8022017-06-13 20:47:17 -07008256 qpair->rsp->qpair = qpair;
Quinn Trane326d222017-06-13 20:47:18 -07008257 /* init qpair to this cpu. Will adjust at run time. */
8258 qla_cpu_update(qpair, smp_processor_id());
Michael Hernandezd7459522016-12-12 14:40:07 -08008259
8260 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
8261 if (ha->fw_attributes & BIT_4)
8262 qpair->difdix_supported = 1;
8263 }
8264
8265 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
8266 if (!qpair->srb_mempool) {
Quinn Tran83548fe2017-06-02 09:12:01 -07008267 ql_log(ql_log_warn, vha, 0xd036,
Michael Hernandezd7459522016-12-12 14:40:07 -08008268 "Failed to create srb mempool for qpair %d\n",
8269 qpair->id);
8270 goto fail_mempool;
8271 }
8272
8273 /* Mark as online */
8274 qpair->online = 1;
8275
8276 if (!vha->flags.qpairs_available)
8277 vha->flags.qpairs_available = 1;
8278
8279 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
8280 "Request/Response queue pair created, id %d\n",
8281 qpair->id);
8282 ql_dbg(ql_dbg_init, vha, 0x0187,
8283 "Request/Response queue pair created, id %d\n",
8284 qpair->id);
8285 }
8286 return qpair;
8287
8288fail_mempool:
8289fail_req:
8290 qla25xx_delete_rsp_que(vha, qpair->rsp);
8291fail_rsp:
8292 mutex_lock(&ha->mq_lock);
8293 qpair->msix->in_use = 0;
8294 list_del(&qpair->qp_list_elem);
8295 if (list_empty(&vha->qp_list))
8296 vha->flags.qpairs_available = 0;
8297fail_msix:
8298 ha->queue_pair_map[qpair_id] = NULL;
8299 clear_bit(qpair_id, ha->qpair_qid_map);
Sawan Chandakb95b9452017-05-24 18:06:20 -07008300 ha->num_qpairs--;
Michael Hernandezd7459522016-12-12 14:40:07 -08008301 mutex_unlock(&ha->mq_lock);
8302fail_qid_map:
8303 kfree(qpair);
8304 return NULL;
8305}
8306
8307int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
8308{
Sawan Chandakd65237c2017-06-13 20:47:19 -07008309 int ret = QLA_FUNCTION_FAILED;
Michael Hernandezd7459522016-12-12 14:40:07 -08008310 struct qla_hw_data *ha = qpair->hw;
8311
8312 qpair->delete_in_progress = 1;
8313 while (atomic_read(&qpair->ref_count))
8314 msleep(500);
8315
8316 ret = qla25xx_delete_req_que(vha, qpair->req);
8317 if (ret != QLA_SUCCESS)
8318 goto fail;
himanshu.madhani@cavium.com7867b982017-12-04 14:45:16 -08008319
Michael Hernandezd7459522016-12-12 14:40:07 -08008320 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
8321 if (ret != QLA_SUCCESS)
8322 goto fail;
8323
8324 mutex_lock(&ha->mq_lock);
8325 ha->queue_pair_map[qpair->id] = NULL;
8326 clear_bit(qpair->id, ha->qpair_qid_map);
Sawan Chandakb95b9452017-05-24 18:06:20 -07008327 ha->num_qpairs--;
Michael Hernandezd7459522016-12-12 14:40:07 -08008328 list_del(&qpair->qp_list_elem);
Sawan Chandakd65237c2017-06-13 20:47:19 -07008329 if (list_empty(&vha->qp_list)) {
Michael Hernandezd7459522016-12-12 14:40:07 -08008330 vha->flags.qpairs_available = 0;
Sawan Chandakd65237c2017-06-13 20:47:19 -07008331 vha->flags.qpairs_req_created = 0;
8332 vha->flags.qpairs_rsp_created = 0;
8333 }
Michael Hernandezd7459522016-12-12 14:40:07 -08008334 mempool_destroy(qpair->srb_mempool);
8335 kfree(qpair);
8336 mutex_unlock(&ha->mq_lock);
8337
8338 return QLA_SUCCESS;
8339fail:
8340 return ret;
8341}