blob: 56bff7856cf8f1e47b21b17166b4490c552c5cfb [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);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080062 sp->free(sp);
63 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -070064}
65
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080066void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080067qla2x00_sp_free(void *ptr)
Andrew Vasquezac280b62009-08-20 11:06:05 -070068{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080069 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080070 struct srb_iocb *iocb = &sp->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -070071
Chad Dupuis4d97cc52010-10-15 11:27:41 -070072 del_timer(&iocb->timer);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080073 qla2x00_rel_sp(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -070074}
75
Andrew Vasquezac280b62009-08-20 11:06:05 -070076/* Asynchronous Login/Logout Routines -------------------------------------- */
77
Saurav Kashyapa9b6f722012-08-22 14:21:01 -040078unsigned long
Andrew Vasquez5b914902010-05-28 15:08:30 -070079qla2x00_get_async_timeout(struct scsi_qla_host *vha)
80{
81 unsigned long tmo;
82 struct qla_hw_data *ha = vha->hw;
83
84 /* Firmware should use switch negotiated r_a_tov for timeout. */
85 tmo = ha->r_a_tov / 10 * 2;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040086 if (IS_QLAFX00(ha)) {
87 tmo = FX00_DEF_RATOV * 2;
88 } else if (!IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez5b914902010-05-28 15:08:30 -070089 /*
90 * Except for earlier ISPs where the timeout is seeded from the
91 * initialization control block.
92 */
93 tmo = ha->login_timeout;
94 }
95 return tmo;
96}
Andrew Vasquezac280b62009-08-20 11:06:05 -070097
Quinn Tran726b8542017-01-19 22:28:00 -080098void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080099qla2x00_async_iocb_timeout(void *data)
Andrew Vasquezac280b62009-08-20 11:06:05 -0700100{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800101 srb_t *sp = data;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700102 fc_port_t *fcport = sp->fcport;
Quinn Tran726b8542017-01-19 22:28:00 -0800103 struct srb_iocb *lio = &sp->u.iocb_cmd;
104 struct event_arg ea;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700105
Quinn Tran5c25d452017-12-28 12:33:09 -0800106 if (fcport) {
107 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
108 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
109 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700110
Quinn Tran5c25d452017-12-28 12:33:09 -0800111 fcport->flags &= ~FCF_ASYNC_SENT;
112 } else {
113 pr_info("Async-%s timeout - hdl=%x.\n",
114 sp->name, sp->handle);
115 }
Quinn Tran726b8542017-01-19 22:28:00 -0800116
117 switch (sp->type) {
118 case SRB_LOGIN_CMD:
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700119 /* Retry as needed. */
120 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
121 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
122 QLA_LOGIO_LOGIN_RETRIED : 0;
Quinn Tran726b8542017-01-19 22:28:00 -0800123 memset(&ea, 0, sizeof(ea));
124 ea.event = FCME_PLOGI_DONE;
125 ea.fcport = sp->fcport;
126 ea.data[0] = lio->u.logio.data[0];
127 ea.data[1] = lio->u.logio.data[1];
128 ea.sp = sp;
129 qla24xx_handle_plogi_done_event(fcport->vha, &ea);
130 break;
131 case SRB_LOGOUT_CMD:
Alexei Potashnika6ca8872015-07-14 16:00:44 -0400132 qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT);
Quinn Tran726b8542017-01-19 22:28:00 -0800133 break;
134 case SRB_CT_PTHRU_CMD:
135 case SRB_MB_IOCB:
136 case SRB_NACK_PLOGI:
137 case SRB_NACK_PRLI:
138 case SRB_NACK_LOGO:
Quinn Tran28531922017-12-28 12:33:10 -0800139 case SRB_CTRL_VP:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800140 sp->done(sp, QLA_FUNCTION_TIMEOUT);
Quinn Tran726b8542017-01-19 22:28:00 -0800141 break;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700142 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700143}
144
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700145static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800146qla2x00_async_login_sp_done(void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700147{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800148 srb_t *sp = ptr;
149 struct scsi_qla_host *vha = sp->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800150 struct srb_iocb *lio = &sp->u.iocb_cmd;
Quinn Tran726b8542017-01-19 22:28:00 -0800151 struct event_arg ea;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700152
Quinn Tran83548fe2017-06-02 09:12:01 -0700153 ql_dbg(ql_dbg_disc, vha, 0x20dd,
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800154 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
Quinn Tran726b8542017-01-19 22:28:00 -0800155
156 sp->fcport->flags &= ~FCF_ASYNC_SENT;
157 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
158 memset(&ea, 0, sizeof(ea));
159 ea.event = FCME_PLOGI_DONE;
160 ea.fcport = sp->fcport;
161 ea.data[0] = lio->u.logio.data[0];
162 ea.data[1] = lio->u.logio.data[1];
163 ea.iop[0] = lio->u.logio.iop[0];
164 ea.iop[1] = lio->u.logio.iop[1];
165 ea.sp = sp;
166 qla2x00_fcport_event_handler(vha, &ea);
167 }
168
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800169 sp->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700170}
171
Andrew Vasquezac280b62009-08-20 11:06:05 -0700172int
173qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
174 uint16_t *data)
175{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700176 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700177 struct srb_iocb *lio;
Quinn Tran726b8542017-01-19 22:28:00 -0800178 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700179
Quinn Tran726b8542017-01-19 22:28:00 -0800180 if (!vha->flags.online)
181 goto done;
182
183 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
184 (fcport->fw_login_state == DSC_LS_PLOGI_COMP) ||
185 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
186 goto done;
187
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800188 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700189 if (!sp)
190 goto done;
191
Quinn Tran726b8542017-01-19 22:28:00 -0800192 fcport->flags |= FCF_ASYNC_SENT;
193 fcport->logout_completed = 0;
194
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800195 sp->type = SRB_LOGIN_CMD;
196 sp->name = "login";
197 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
198
199 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700200 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800201 sp->done = qla2x00_async_login_sp_done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700202 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700203
204 if (fcport->fc4f_nvme)
205 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
206
Andrew Vasquezac280b62009-08-20 11:06:05 -0700207 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700208 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700209 rval = qla2x00_start_sp(sp);
Chad Dupuis080c9512016-01-27 12:03:37 -0500210 if (rval != QLA_SUCCESS) {
211 fcport->flags &= ~FCF_ASYNC_SENT;
212 fcport->flags |= FCF_LOGIN_NEEDED;
213 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700214 goto done_free_sp;
Chad Dupuis080c9512016-01-27 12:03:37 -0500215 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700216
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700217 ql_dbg(ql_dbg_disc, vha, 0x2072,
Quinn Tran726b8542017-01-19 22:28:00 -0800218 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
219 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800220 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
221 fcport->login_retry);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700222 return rval;
223
224done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800225 sp->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700226done:
Quinn Tran726b8542017-01-19 22:28:00 -0800227 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700228 return rval;
229}
230
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700231static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800232qla2x00_async_logout_sp_done(void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700233{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800234 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800235 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700236
Quinn Tran726b8542017-01-19 22:28:00 -0800237 sp->fcport->flags &= ~FCF_ASYNC_SENT;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800238 if (!test_bit(UNLOADING, &sp->vha->dpc_flags))
239 qla2x00_post_async_logout_done_work(sp->vha, sp->fcport,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800240 lio->u.logio.data);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800241 sp->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700242}
243
Andrew Vasquezac280b62009-08-20 11:06:05 -0700244int
245qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
246{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700247 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700248 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700249 int rval;
250
251 rval = QLA_FUNCTION_FAILED;
Quinn Tran726b8542017-01-19 22:28:00 -0800252 fcport->flags |= FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800253 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700254 if (!sp)
255 goto done;
256
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800257 sp->type = SRB_LOGOUT_CMD;
258 sp->name = "logout";
259 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
260
261 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700262 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800263 sp->done = qla2x00_async_logout_sp_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700264 rval = qla2x00_start_sp(sp);
265 if (rval != QLA_SUCCESS)
266 goto done_free_sp;
267
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700268 ql_dbg(ql_dbg_disc, vha, 0x2070,
Quinn Tran726b8542017-01-19 22:28:00 -0800269 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -0800270 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
Quinn Tran726b8542017-01-19 22:28:00 -0800271 fcport->d_id.b.area, fcport->d_id.b.al_pa,
272 fcport->port_name);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700273 return rval;
274
275done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800276 sp->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700277done:
Quinn Tran726b8542017-01-19 22:28:00 -0800278 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700279 return rval;
280}
Quinn Tran11aea162017-12-28 12:33:20 -0800281
282void
283qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
284 uint16_t *data)
285{
286 /* Don't re-login in target mode */
287 if (!fcport->tgt_session)
288 qla2x00_mark_device_lost(vha, fcport, 1, 0);
289 qlt_logo_completion_handler(fcport, data[0]);
290}
291
292static void
293qla2x00_async_prlo_sp_done(void *s, int res)
294{
295 srb_t *sp = (srb_t *)s;
296 struct srb_iocb *lio = &sp->u.iocb_cmd;
297 struct scsi_qla_host *vha = sp->vha;
298
299 if (!test_bit(UNLOADING, &vha->dpc_flags))
300 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
301 lio->u.logio.data);
302 sp->free(sp);
303}
304
305int
306qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
307{
308 srb_t *sp;
309 struct srb_iocb *lio;
310 int rval;
311
312 rval = QLA_FUNCTION_FAILED;
313 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
314 if (!sp)
315 goto done;
316
317 sp->type = SRB_PRLO_CMD;
318 sp->name = "prlo";
319 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
320
321 lio = &sp->u.iocb_cmd;
322 lio->timeout = qla2x00_async_iocb_timeout;
323 sp->done = qla2x00_async_prlo_sp_done;
324 rval = qla2x00_start_sp(sp);
325 if (rval != QLA_SUCCESS)
326 goto done_free_sp;
327
328 ql_dbg(ql_dbg_disc, vha, 0x2070,
329 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
330 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
331 fcport->d_id.b.area, fcport->d_id.b.al_pa);
332 return rval;
333
334done_free_sp:
335 sp->free(sp);
336done:
337 return rval;
338}
339
Quinn Tranf13515a2017-12-28 12:33:15 -0800340static
341void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
342{
343 qla24xx_handle_gpdb_event(vha, ea);
344}
Andrew Vasquezac280b62009-08-20 11:06:05 -0700345
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700346static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800347qla2x00_async_adisc_sp_done(void *ptr, int res)
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700348{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800349 srb_t *sp = ptr;
350 struct scsi_qla_host *vha = sp->vha;
Quinn Tranf13515a2017-12-28 12:33:15 -0800351 struct event_arg ea;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700352
Quinn Tranf13515a2017-12-28 12:33:15 -0800353 ql_dbg(ql_dbg_disc, vha, 0x2066,
354 "Async done-%s res %x %8phC\n",
355 sp->name, res, sp->fcport->port_name);
356
357 memset(&ea, 0, sizeof(ea));
358 ea.event = FCME_ADISC_DONE;
359 ea.rc = res;
360 ea.fcport = sp->fcport;
361 ea.sp = sp;
362
363 qla2x00_fcport_event_handler(vha, &ea);
364
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800365 sp->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700366}
367
368int
369qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
370 uint16_t *data)
371{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700372 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700373 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700374 int rval;
375
376 rval = QLA_FUNCTION_FAILED;
Quinn Tran726b8542017-01-19 22:28:00 -0800377 fcport->flags |= FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800378 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700379 if (!sp)
380 goto done;
381
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800382 sp->type = SRB_ADISC_CMD;
383 sp->name = "adisc";
384 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
385
386 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700387 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800388 sp->done = qla2x00_async_adisc_sp_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700389 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700390 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700391 rval = qla2x00_start_sp(sp);
392 if (rval != QLA_SUCCESS)
393 goto done_free_sp;
394
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700395 ql_dbg(ql_dbg_disc, vha, 0x206f,
Quinn Tranf13515a2017-12-28 12:33:15 -0800396 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
397 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700398 return rval;
399
400done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800401 sp->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700402done:
Quinn Tran726b8542017-01-19 22:28:00 -0800403 fcport->flags &= ~FCF_ASYNC_SENT;
Quinn Tranf13515a2017-12-28 12:33:15 -0800404 qla2x00_post_async_adisc_work(vha, fcport, data);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700405 return rval;
406}
407
Quinn Tran726b8542017-01-19 22:28:00 -0800408static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
409 struct event_arg *ea)
410{
411 fc_port_t *fcport, *conflict_fcport;
412 struct get_name_list_extended *e;
413 u16 i, n, found = 0, loop_id;
414 port_id_t id;
415 u64 wwn;
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700416 u8 opt = 0, current_login_state;
Quinn Tran726b8542017-01-19 22:28:00 -0800417
418 fcport = ea->fcport;
419
420 if (ea->rc) { /* rval */
421 if (fcport->login_retry == 0) {
422 fcport->login_retry = vha->hw->login_retry_count;
Quinn Tran83548fe2017-06-02 09:12:01 -0700423 ql_dbg(ql_dbg_disc, vha, 0x20de,
424 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
425 fcport->port_name, fcport->login_retry);
Quinn Tran726b8542017-01-19 22:28:00 -0800426 }
427 return;
428 }
429
430 if (fcport->last_rscn_gen != fcport->rscn_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700431 ql_dbg(ql_dbg_disc, vha, 0x20df,
Quinn Tran726b8542017-01-19 22:28:00 -0800432 "%s %8phC rscn gen changed rscn %d|%d \n",
433 __func__, fcport->port_name,
434 fcport->last_rscn_gen, fcport->rscn_gen);
435 qla24xx_post_gidpn_work(vha, fcport);
436 return;
437 } else if (fcport->last_login_gen != fcport->login_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700438 ql_dbg(ql_dbg_disc, vha, 0x20e0,
439 "%s %8phC login gen changed login %d|%d\n",
440 __func__, fcport->port_name,
441 fcport->last_login_gen, fcport->login_gen);
Quinn Tran726b8542017-01-19 22:28:00 -0800442 return;
443 }
444
445 n = ea->data[0] / sizeof(struct get_name_list_extended);
446
Quinn Tran83548fe2017-06-02 09:12:01 -0700447 ql_dbg(ql_dbg_disc, vha, 0x20e1,
Quinn Tran726b8542017-01-19 22:28:00 -0800448 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
449 __func__, __LINE__, fcport->port_name, n,
450 fcport->d_id.b.domain, fcport->d_id.b.area,
451 fcport->d_id.b.al_pa, fcport->loop_id);
452
453 for (i = 0; i < n; i++) {
454 e = &vha->gnl.l[i];
455 wwn = wwn_to_u64(e->port_name);
456
457 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
458 continue;
459
460 found = 1;
461 id.b.domain = e->port_id[2];
462 id.b.area = e->port_id[1];
463 id.b.al_pa = e->port_id[0];
464 id.b.rsvd_1 = 0;
465
466 loop_id = le16_to_cpu(e->nport_handle);
467 loop_id = (loop_id & 0x7fff);
468
Quinn Tran83548fe2017-06-02 09:12:01 -0700469 ql_dbg(ql_dbg_disc, vha, 0x20e2,
470 "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
471 __func__, fcport->port_name,
472 e->current_login_state, fcport->fw_login_state,
473 id.b.domain, id.b.area, id.b.al_pa,
474 fcport->d_id.b.domain, fcport->d_id.b.area,
475 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
Quinn Tran726b8542017-01-19 22:28:00 -0800476
477 if ((id.b24 != fcport->d_id.b24) ||
478 ((fcport->loop_id != FC_NO_LOOP_ID) &&
479 (fcport->loop_id != loop_id))) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700480 ql_dbg(ql_dbg_disc, vha, 0x20e3,
481 "%s %d %8phC post del sess\n",
482 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800483 qlt_schedule_sess_for_deletion(fcport, 1);
484 return;
485 }
486
487 fcport->loop_id = loop_id;
488
489 wwn = wwn_to_u64(fcport->port_name);
490 qlt_find_sess_invalidate_other(vha, wwn,
491 id, loop_id, &conflict_fcport);
492
493 if (conflict_fcport) {
494 /*
495 * Another share fcport share the same loop_id &
496 * nport id. Conflict fcport needs to finish
497 * cleanup before this fcport can proceed to login.
498 */
499 conflict_fcport->conflict = fcport;
500 fcport->login_pause = 1;
501 }
502
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700503 if (fcport->fc4f_nvme)
504 current_login_state = e->current_login_state >> 4;
505 else
506 current_login_state = e->current_login_state & 0xf;
507
508 switch (current_login_state) {
Quinn Tran726b8542017-01-19 22:28:00 -0800509 case DSC_LS_PRLI_COMP:
Quinn Tran83548fe2017-06-02 09:12:01 -0700510 ql_dbg(ql_dbg_disc, vha, 0x20e4,
511 "%s %d %8phC post gpdb\n",
512 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800513 opt = PDO_FORCE_ADISC;
514 qla24xx_post_gpdb_work(vha, fcport, opt);
515 break;
Quinn Tran726b8542017-01-19 22:28:00 -0800516 case DSC_LS_PORT_UNAVAIL:
517 default:
518 if (fcport->loop_id == FC_NO_LOOP_ID) {
519 qla2x00_find_new_loop_id(vha, fcport);
520 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
521 }
Quinn Tran83548fe2017-06-02 09:12:01 -0700522 ql_dbg(ql_dbg_disc, vha, 0x20e5,
523 "%s %d %8phC\n",
524 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800525 qla24xx_fcport_handle_login(vha, fcport);
526 break;
527 }
528 }
529
530 if (!found) {
531 /* fw has no record of this port */
532 if (fcport->loop_id == FC_NO_LOOP_ID) {
533 qla2x00_find_new_loop_id(vha, fcport);
534 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
535 } else {
536 for (i = 0; i < n; i++) {
537 e = &vha->gnl.l[i];
538 id.b.domain = e->port_id[0];
539 id.b.area = e->port_id[1];
540 id.b.al_pa = e->port_id[2];
541 id.b.rsvd_1 = 0;
542 loop_id = le16_to_cpu(e->nport_handle);
543
544 if (fcport->d_id.b24 == id.b24) {
545 conflict_fcport =
546 qla2x00_find_fcport_by_wwpn(vha,
547 e->port_name, 0);
548
Quinn Tran83548fe2017-06-02 09:12:01 -0700549 ql_dbg(ql_dbg_disc, vha, 0x20e6,
Quinn Tran726b8542017-01-19 22:28:00 -0800550 "%s %d %8phC post del sess\n",
551 __func__, __LINE__,
552 conflict_fcport->port_name);
553 qlt_schedule_sess_for_deletion
554 (conflict_fcport, 1);
555 }
556
557 if (fcport->loop_id == loop_id) {
558 /* FW already picked this loop id for another fcport */
559 qla2x00_find_new_loop_id(vha, fcport);
560 }
561 }
562 }
563 qla24xx_fcport_handle_login(vha, fcport);
564 }
565} /* gnl_event */
566
567static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800568qla24xx_async_gnl_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -0800569{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800570 struct srb *sp = s;
571 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -0800572 unsigned long flags;
573 struct fc_port *fcport = NULL, *tf;
574 u16 i, n = 0, loop_id;
575 struct event_arg ea;
576 struct get_name_list_extended *e;
577 u64 wwn;
578 struct list_head h;
579
Quinn Tran83548fe2017-06-02 09:12:01 -0700580 ql_dbg(ql_dbg_disc, vha, 0x20e7,
Quinn Tran726b8542017-01-19 22:28:00 -0800581 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
582 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
583 sp->u.iocb_cmd.u.mbx.in_mb[2]);
584
585 memset(&ea, 0, sizeof(ea));
586 ea.sp = sp;
587 ea.rc = res;
588 ea.event = FCME_GNL_DONE;
589
590 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
591 sizeof(struct get_name_list_extended)) {
592 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
593 sizeof(struct get_name_list_extended);
594 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
595 }
596
597 for (i = 0; i < n; i++) {
598 e = &vha->gnl.l[i];
599 loop_id = le16_to_cpu(e->nport_handle);
600 /* mask out reserve bit */
601 loop_id = (loop_id & 0x7fff);
602 set_bit(loop_id, vha->hw->loop_id_map);
603 wwn = wwn_to_u64(e->port_name);
604
Quinn Tran83548fe2017-06-02 09:12:01 -0700605 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
Quinn Tran726b8542017-01-19 22:28:00 -0800606 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
607 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
608 e->port_id[0], e->current_login_state, e->last_login_state,
609 (loop_id & 0x7fff));
610 }
611
612 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
613 vha->gnl.sent = 0;
614
615 INIT_LIST_HEAD(&h);
616 fcport = tf = NULL;
617 if (!list_empty(&vha->gnl.fcports))
618 list_splice_init(&vha->gnl.fcports, &h);
619
620 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
621 list_del_init(&fcport->gnl_entry);
622 fcport->flags &= ~FCF_ASYNC_SENT;
623 ea.fcport = fcport;
624
625 qla2x00_fcport_event_handler(vha, &ea);
626 }
627
628 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
629
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800630 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800631}
632
633int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
634{
635 srb_t *sp;
636 struct srb_iocb *mbx;
637 int rval = QLA_FUNCTION_FAILED;
638 unsigned long flags;
639 u16 *mb;
640
641 if (!vha->flags.online)
642 goto done;
643
Quinn Tran83548fe2017-06-02 09:12:01 -0700644 ql_dbg(ql_dbg_disc, vha, 0x20d9,
Quinn Tran726b8542017-01-19 22:28:00 -0800645 "Async-gnlist WWPN %8phC \n", fcport->port_name);
646
647 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
648 fcport->flags |= FCF_ASYNC_SENT;
649 fcport->disc_state = DSC_GNL;
650 fcport->last_rscn_gen = fcport->rscn_gen;
651 fcport->last_login_gen = fcport->login_gen;
652
653 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
654 if (vha->gnl.sent) {
655 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
656 rval = QLA_SUCCESS;
657 goto done;
658 }
659 vha->gnl.sent = 1;
660 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
661
662 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
663 if (!sp)
664 goto done;
665 sp->type = SRB_MB_IOCB;
666 sp->name = "gnlist";
667 sp->gen1 = fcport->rscn_gen;
668 sp->gen2 = fcport->login_gen;
669
670 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
671
672 mb = sp->u.iocb_cmd.u.mbx.out_mb;
673 mb[0] = MBC_PORT_NODE_NAME_LIST;
674 mb[1] = BIT_2 | BIT_3;
675 mb[2] = MSW(vha->gnl.ldma);
676 mb[3] = LSW(vha->gnl.ldma);
677 mb[6] = MSW(MSD(vha->gnl.ldma));
678 mb[7] = LSW(MSD(vha->gnl.ldma));
679 mb[8] = vha->gnl.size;
680 mb[9] = vha->vp_idx;
681
682 mbx = &sp->u.iocb_cmd;
683 mbx->timeout = qla2x00_async_iocb_timeout;
684
685 sp->done = qla24xx_async_gnl_sp_done;
686
687 rval = qla2x00_start_sp(sp);
688 if (rval != QLA_SUCCESS)
689 goto done_free_sp;
690
Quinn Tran83548fe2017-06-02 09:12:01 -0700691 ql_dbg(ql_dbg_disc, vha, 0x20da,
692 "Async-%s - OUT WWPN %8phC hndl %x\n",
693 sp->name, fcport->port_name, sp->handle);
Quinn Tran726b8542017-01-19 22:28:00 -0800694
695 return rval;
696
697done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800698 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800699done:
700 fcport->flags &= ~FCF_ASYNC_SENT;
701 return rval;
702}
703
704int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
705{
706 struct qla_work_evt *e;
707
708 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
709 if (!e)
710 return QLA_FUNCTION_FAILED;
711
712 e->u.fcport.fcport = fcport;
713 return qla2x00_post_work(vha, e);
714}
715
716static
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800717void qla24xx_async_gpdb_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -0800718{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800719 struct srb *sp = s;
720 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -0800721 struct qla_hw_data *ha = vha->hw;
Quinn Tran726b8542017-01-19 22:28:00 -0800722 struct port_database_24xx *pd;
723 fc_port_t *fcport = sp->fcport;
724 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
725 int rval = QLA_SUCCESS;
726 struct event_arg ea;
727
Quinn Tran83548fe2017-06-02 09:12:01 -0700728 ql_dbg(ql_dbg_disc, vha, 0x20db,
Quinn Tran726b8542017-01-19 22:28:00 -0800729 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
730 sp->name, res, fcport->port_name, mb[1], mb[2]);
731
732 fcport->flags &= ~FCF_ASYNC_SENT;
733
734 if (res) {
735 rval = res;
736 goto gpd_error_out;
737 }
738
739 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
740
Quinn Tran15f30a52017-03-15 09:48:52 -0700741 rval = __qla24xx_parse_gpdb(vha, fcport, pd);
Quinn Tran726b8542017-01-19 22:28:00 -0800742
743gpd_error_out:
744 memset(&ea, 0, sizeof(ea));
745 ea.event = FCME_GPDB_DONE;
746 ea.rc = rval;
747 ea.fcport = fcport;
748 ea.sp = sp;
749
750 qla2x00_fcport_event_handler(vha, &ea);
751
752 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
753 sp->u.iocb_cmd.u.mbx.in_dma);
754
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800755 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800756}
757
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700758static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
759{
760 struct qla_work_evt *e;
761
762 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
763 if (!e)
764 return QLA_FUNCTION_FAILED;
765
766 e->u.fcport.fcport = fcport;
767
768 return qla2x00_post_work(vha, e);
769}
770
771static void
772qla2x00_async_prli_sp_done(void *ptr, int res)
773{
774 srb_t *sp = ptr;
775 struct scsi_qla_host *vha = sp->vha;
776 struct srb_iocb *lio = &sp->u.iocb_cmd;
777 struct event_arg ea;
778
779 ql_dbg(ql_dbg_disc, vha, 0x2129,
780 "%s %8phC res %d \n", __func__,
781 sp->fcport->port_name, res);
782
783 sp->fcport->flags &= ~FCF_ASYNC_SENT;
784
785 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
786 memset(&ea, 0, sizeof(ea));
787 ea.event = FCME_PRLI_DONE;
788 ea.fcport = sp->fcport;
789 ea.data[0] = lio->u.logio.data[0];
790 ea.data[1] = lio->u.logio.data[1];
791 ea.iop[0] = lio->u.logio.iop[0];
792 ea.iop[1] = lio->u.logio.iop[1];
793 ea.sp = sp;
794
795 qla2x00_fcport_event_handler(vha, &ea);
796 }
797
798 sp->free(sp);
799}
800
801int
802qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
803{
804 srb_t *sp;
805 struct srb_iocb *lio;
806 int rval = QLA_FUNCTION_FAILED;
807
808 if (!vha->flags.online)
809 return rval;
810
811 if (fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
812 fcport->fw_login_state == DSC_LS_PLOGI_COMP ||
813 fcport->fw_login_state == DSC_LS_PRLI_PEND)
814 return rval;
815
816 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
817 if (!sp)
818 return rval;
819
820 fcport->flags |= FCF_ASYNC_SENT;
821 fcport->logout_completed = 0;
822
823 sp->type = SRB_PRLI_CMD;
824 sp->name = "prli";
825 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
826
827 lio = &sp->u.iocb_cmd;
828 lio->timeout = qla2x00_async_iocb_timeout;
829 sp->done = qla2x00_async_prli_sp_done;
830 lio->u.logio.flags = 0;
831
832 if (fcport->fc4f_nvme)
833 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
834
835 rval = qla2x00_start_sp(sp);
836 if (rval != QLA_SUCCESS) {
837 fcport->flags &= ~FCF_ASYNC_SENT;
838 fcport->flags |= FCF_LOGIN_NEEDED;
839 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
840 goto done_free_sp;
841 }
842
843 ql_dbg(ql_dbg_disc, vha, 0x211b,
844 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n",
845 fcport->port_name, sp->handle, fcport->loop_id,
846 fcport->d_id.b24, fcport->login_retry);
847
848 return rval;
849
850done_free_sp:
851 sp->free(sp);
852 fcport->flags &= ~FCF_ASYNC_SENT;
853 return rval;
854}
855
Quinn Trana07fc0a2017-08-23 15:05:21 -0700856int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
Quinn Tran726b8542017-01-19 22:28:00 -0800857{
858 struct qla_work_evt *e;
859
860 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
861 if (!e)
862 return QLA_FUNCTION_FAILED;
863
864 e->u.fcport.fcport = fcport;
865 e->u.fcport.opt = opt;
866 return qla2x00_post_work(vha, e);
867}
868
869int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
870{
871 srb_t *sp;
872 struct srb_iocb *mbx;
873 int rval = QLA_FUNCTION_FAILED;
874 u16 *mb;
875 dma_addr_t pd_dma;
876 struct port_database_24xx *pd;
877 struct qla_hw_data *ha = vha->hw;
878
879 if (!vha->flags.online)
880 goto done;
881
882 fcport->flags |= FCF_ASYNC_SENT;
883 fcport->disc_state = DSC_GPDB;
884
885 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
886 if (!sp)
887 goto done;
888
Joe Carnuccioe0824e62017-08-23 15:05:08 -0700889 sp->type = SRB_MB_IOCB;
890 sp->name = "gpdb";
891 sp->gen1 = fcport->rscn_gen;
892 sp->gen2 = fcport->login_gen;
893 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
894
Thomas Meyer08eb7f42017-09-21 08:15:26 +0200895 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Quinn Tran726b8542017-01-19 22:28:00 -0800896 if (pd == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700897 ql_log(ql_log_warn, vha, 0xd043,
898 "Failed to allocate port database structure.\n");
Quinn Tran726b8542017-01-19 22:28:00 -0800899 goto done_free_sp;
900 }
Quinn Tran726b8542017-01-19 22:28:00 -0800901
Quinn Tran726b8542017-01-19 22:28:00 -0800902 mb = sp->u.iocb_cmd.u.mbx.out_mb;
903 mb[0] = MBC_GET_PORT_DATABASE;
904 mb[1] = fcport->loop_id;
905 mb[2] = MSW(pd_dma);
906 mb[3] = LSW(pd_dma);
907 mb[6] = MSW(MSD(pd_dma));
908 mb[7] = LSW(MSD(pd_dma));
909 mb[9] = vha->vp_idx;
910 mb[10] = opt;
911
912 mbx = &sp->u.iocb_cmd;
913 mbx->timeout = qla2x00_async_iocb_timeout;
914 mbx->u.mbx.in = (void *)pd;
915 mbx->u.mbx.in_dma = pd_dma;
916
917 sp->done = qla24xx_async_gpdb_sp_done;
918
919 rval = qla2x00_start_sp(sp);
920 if (rval != QLA_SUCCESS)
921 goto done_free_sp;
922
Quinn Tran83548fe2017-06-02 09:12:01 -0700923 ql_dbg(ql_dbg_disc, vha, 0x20dc,
924 "Async-%s %8phC hndl %x opt %x\n",
925 sp->name, fcport->port_name, sp->handle, opt);
Quinn Tran726b8542017-01-19 22:28:00 -0800926
927 return rval;
928
929done_free_sp:
930 if (pd)
931 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
932
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800933 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800934done:
935 fcport->flags &= ~FCF_ASYNC_SENT;
936 qla24xx_post_gpdb_work(vha, fcport, opt);
937 return rval;
938}
939
940static
941void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
942{
943 int rval = ea->rc;
944 fc_port_t *fcport = ea->fcport;
945 unsigned long flags;
946
947 fcport->flags &= ~FCF_ASYNC_SENT;
948
Quinn Tran83548fe2017-06-02 09:12:01 -0700949 ql_dbg(ql_dbg_disc, vha, 0x20d2,
Quinn Tran726b8542017-01-19 22:28:00 -0800950 "%s %8phC DS %d LS %d rval %d\n", __func__, fcport->port_name,
951 fcport->disc_state, fcport->fw_login_state, rval);
952
953 if (ea->sp->gen2 != fcport->login_gen) {
954 /* target side must have changed it. */
Quinn Tran83548fe2017-06-02 09:12:01 -0700955 ql_dbg(ql_dbg_disc, vha, 0x20d3,
Quinn Tran726b8542017-01-19 22:28:00 -0800956 "%s %8phC generation changed rscn %d|%d login %d|%d \n",
957 __func__, fcport->port_name, fcport->last_rscn_gen,
958 fcport->rscn_gen, fcport->last_login_gen,
959 fcport->login_gen);
Quinn Tran9b3e0f42017-12-28 12:33:16 -0800960 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Quinn Tran726b8542017-01-19 22:28:00 -0800961 return;
962 } else if (ea->sp->gen1 != fcport->rscn_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700963 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
Quinn Tran726b8542017-01-19 22:28:00 -0800964 __func__, __LINE__, fcport->port_name);
965 qla24xx_post_gidpn_work(vha, fcport);
966 return;
967 }
968
969 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700970 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
Quinn Tran726b8542017-01-19 22:28:00 -0800971 __func__, __LINE__, fcport->port_name);
972 qlt_schedule_sess_for_deletion_lock(fcport);
973 return;
974 }
975
976 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Tranf13515a2017-12-28 12:33:15 -0800977 ea->fcport->login_gen++;
Quinn Tran726b8542017-01-19 22:28:00 -0800978 ea->fcport->deleted = 0;
979 ea->fcport->logout_on_delete = 1;
980
981 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
982 vha->fcport_count++;
983 ea->fcport->login_succ = 1;
984
985 if (!IS_IIDMA_CAPABLE(vha->hw) ||
986 !vha->hw->flags.gpsc_supported) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700987 ql_dbg(ql_dbg_disc, vha, 0x20d6,
Quinn Tran726b8542017-01-19 22:28:00 -0800988 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
989 __func__, __LINE__, fcport->port_name,
990 vha->fcport_count);
991
992 qla24xx_post_upd_fcport_work(vha, fcport);
993 } else {
Quinn Tran83548fe2017-06-02 09:12:01 -0700994 ql_dbg(ql_dbg_disc, vha, 0x20d7,
Quinn Tran726b8542017-01-19 22:28:00 -0800995 "%s %d %8phC post gpsc fcp_cnt %d\n",
996 __func__, __LINE__, fcport->port_name,
997 vha->fcport_count);
998
999 qla24xx_post_gpsc_work(vha, fcport);
1000 }
Quinn Tran414d9ff2017-12-04 14:45:03 -08001001 } else if (ea->fcport->login_succ) {
1002 /*
1003 * We have an existing session. A late RSCN delivery
1004 * must have triggered the session to be re-validate.
1005 * session is still valid.
1006 */
Quinn Tran5ef696a2017-12-04 14:45:05 -08001007 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1008 "%s %d %8phC session revalidate success\n",
1009 __func__, __LINE__, fcport->port_name);
Quinn Tran414d9ff2017-12-04 14:45:03 -08001010 fcport->disc_state = DSC_LOGIN_COMPLETE;
Quinn Tran726b8542017-01-19 22:28:00 -08001011 }
1012 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1013} /* gpdb event */
1014
1015int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1016{
Quinn Tranf13515a2017-12-28 12:33:15 -08001017 u16 data[2];
Quinn Tran726b8542017-01-19 22:28:00 -08001018 if (fcport->login_retry == 0)
1019 return 0;
1020
1021 if (fcport->scan_state != QLA_FCPORT_FOUND)
1022 return 0;
1023
Quinn Tran83548fe2017-06-02 09:12:01 -07001024 ql_dbg(ql_dbg_disc, vha, 0x20d8,
Quinn Tran726b8542017-01-19 22:28:00 -08001025 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d|%d retry %d lid %d\n",
1026 __func__, fcport->port_name, fcport->disc_state,
1027 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1028 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1029 fcport->last_login_gen, fcport->login_gen, fcport->login_retry,
1030 fcport->loop_id);
1031
1032 fcport->login_retry--;
1033
1034 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
Quinn Tran726b8542017-01-19 22:28:00 -08001035 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1036 return 0;
1037
Quinn Tran5b334692017-03-15 09:48:48 -07001038 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1039 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline))
1040 return 0;
1041 }
1042
Quinn Tran726b8542017-01-19 22:28:00 -08001043 /* for pure Target Mode. Login will not be initiated */
1044 if (vha->host->active_mode == MODE_TARGET)
1045 return 0;
1046
1047 if (fcport->flags & FCF_ASYNC_SENT) {
1048 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1049 return 0;
1050 }
1051
1052 switch (fcport->disc_state) {
1053 case DSC_DELETED:
1054 if (fcport->loop_id == FC_NO_LOOP_ID) {
Quinn Tran83548fe2017-06-02 09:12:01 -07001055 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1056 "%s %d %8phC post gnl\n",
1057 __func__, __LINE__, fcport->port_name);
Giridhar Malavali5d3300a2017-12-04 14:45:13 -08001058 qla24xx_post_gnl_work(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08001059 } else {
Quinn Tran83548fe2017-06-02 09:12:01 -07001060 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1061 "%s %d %8phC post login\n",
1062 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -08001063 fcport->disc_state = DSC_LOGIN_PEND;
1064 qla2x00_post_async_login_work(vha, fcport, NULL);
1065 }
1066 break;
1067
1068 case DSC_GNL:
1069 if (fcport->login_pause) {
1070 fcport->last_rscn_gen = fcport->rscn_gen;
1071 fcport->last_login_gen = fcport->login_gen;
1072 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1073 break;
1074 }
1075
Quinn Tranf13515a2017-12-28 12:33:15 -08001076 ql_dbg(ql_dbg_disc, vha, 0x20cf,
1077 "%s %d %8phC post login\n",
1078 __func__, __LINE__, fcport->port_name);
1079 fcport->disc_state = DSC_LOGIN_PEND;
1080 qla2x00_post_async_login_work(vha, fcport, NULL);
Quinn Tran726b8542017-01-19 22:28:00 -08001081 break;
1082
1083 case DSC_LOGIN_FAILED:
Quinn Tran83548fe2017-06-02 09:12:01 -07001084 ql_dbg(ql_dbg_disc, vha, 0x20d0,
1085 "%s %d %8phC post gidpn\n",
1086 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -08001087
1088 qla24xx_post_gidpn_work(vha, fcport);
1089 break;
1090
1091 case DSC_LOGIN_COMPLETE:
1092 /* recheck login state */
Quinn Tran83548fe2017-06-02 09:12:01 -07001093 ql_dbg(ql_dbg_disc, vha, 0x20d1,
Quinn Tranf13515a2017-12-28 12:33:15 -08001094 "%s %d %8phC post adisc\n",
Quinn Tran83548fe2017-06-02 09:12:01 -07001095 __func__, __LINE__, fcport->port_name);
Quinn Tranf13515a2017-12-28 12:33:15 -08001096 data[0] = data[1] = 0;
1097 qla2x00_post_async_adisc_work(vha, fcport, data);
Quinn Tran726b8542017-01-19 22:28:00 -08001098 break;
1099
1100 default:
1101 break;
1102 }
1103
1104 return 0;
1105}
1106
1107static
1108void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea)
1109{
1110 fcport->rscn_gen++;
1111
Quinn Tran83548fe2017-06-02 09:12:01 -07001112 ql_dbg(ql_dbg_disc, fcport->vha, 0x210c,
1113 "%s %8phC DS %d LS %d\n",
1114 __func__, fcport->port_name, fcport->disc_state,
1115 fcport->fw_login_state);
Quinn Tran726b8542017-01-19 22:28:00 -08001116
1117 if (fcport->flags & FCF_ASYNC_SENT)
1118 return;
1119
1120 switch (fcport->disc_state) {
1121 case DSC_DELETED:
1122 case DSC_LOGIN_COMPLETE:
Quinn Tran5ef696a2017-12-04 14:45:05 -08001123 qla24xx_post_gpnid_work(fcport->vha, &ea->id);
Quinn Tran726b8542017-01-19 22:28:00 -08001124 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001125 default:
1126 break;
1127 }
1128}
1129
1130int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1131 u8 *port_name, void *pla)
1132{
1133 struct qla_work_evt *e;
1134 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1135 if (!e)
1136 return QLA_FUNCTION_FAILED;
1137
1138 e->u.new_sess.id = *id;
1139 e->u.new_sess.pla = pla;
1140 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1141
1142 return qla2x00_post_work(vha, e);
1143}
1144
1145static
1146int qla24xx_handle_delete_done_event(scsi_qla_host_t *vha,
1147 struct event_arg *ea)
1148{
1149 fc_port_t *fcport = ea->fcport;
1150
1151 if (test_bit(UNLOADING, &vha->dpc_flags))
1152 return 0;
1153
1154 switch (vha->host->active_mode) {
1155 case MODE_INITIATOR:
1156 case MODE_DUAL:
1157 if (fcport->scan_state == QLA_FCPORT_FOUND)
1158 qla24xx_fcport_handle_login(vha, fcport);
1159 break;
1160
1161 case MODE_TARGET:
1162 default:
1163 /* no-op */
1164 break;
1165 }
1166
1167 return 0;
1168}
1169
1170static
1171void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1172 struct event_arg *ea)
1173{
1174 fc_port_t *fcport = ea->fcport;
1175
1176 if (fcport->scan_state != QLA_FCPORT_FOUND) {
1177 fcport->login_retry++;
1178 return;
1179 }
1180
Quinn Tran83548fe2017-06-02 09:12:01 -07001181 ql_dbg(ql_dbg_disc, vha, 0x2102,
1182 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1183 __func__, fcport->port_name, fcport->disc_state,
1184 fcport->fw_login_state, fcport->login_pause,
1185 fcport->deleted, fcport->conflict,
1186 fcport->last_rscn_gen, fcport->rscn_gen,
1187 fcport->last_login_gen, fcport->login_gen,
1188 fcport->flags);
Quinn Tran726b8542017-01-19 22:28:00 -08001189
1190 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
Quinn Tran726b8542017-01-19 22:28:00 -08001191 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1192 return;
1193
Quinn Tran5b334692017-03-15 09:48:48 -07001194 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1195 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline))
1196 return;
1197 }
1198
Quinn Tran726b8542017-01-19 22:28:00 -08001199 if (fcport->flags & FCF_ASYNC_SENT) {
1200 fcport->login_retry++;
1201 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1202 return;
1203 }
1204
1205 if (fcport->disc_state == DSC_DELETE_PEND) {
1206 fcport->login_retry++;
1207 return;
1208 }
1209
1210 if (fcport->last_rscn_gen != fcport->rscn_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -07001211 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n",
Quinn Tran726b8542017-01-19 22:28:00 -08001212 __func__, __LINE__, fcport->port_name);
1213
Giridhar Malavali5d3300a2017-12-04 14:45:13 -08001214 qla24xx_post_gidpn_work(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08001215 return;
1216 }
1217
1218 qla24xx_fcport_handle_login(vha, fcport);
1219}
1220
Quinn Tran41dc5292017-01-19 22:28:03 -08001221void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
Quinn Tran726b8542017-01-19 22:28:00 -08001222{
Quinn Tran41dc5292017-01-19 22:28:03 -08001223 fc_port_t *fcport, *f, *tf;
1224 uint32_t id = 0, mask, rid;
Quinn Tran726b8542017-01-19 22:28:00 -08001225 int rc;
1226
1227 switch (ea->event) {
1228 case FCME_RELOGIN:
Quinn Tranb98ae0d2017-06-02 09:12:00 -07001229 case FCME_RSCN:
1230 case FCME_GIDPN_DONE:
1231 case FCME_GPSC_DONE:
1232 case FCME_GPNID_DONE:
1233 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
1234 test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))
1235 return;
1236 break;
1237 default:
1238 break;
1239 }
1240
1241 switch (ea->event) {
1242 case FCME_RELOGIN:
Quinn Tran726b8542017-01-19 22:28:00 -08001243 if (test_bit(UNLOADING, &vha->dpc_flags))
1244 return;
1245
1246 qla24xx_handle_relogin_event(vha, ea);
1247 break;
1248 case FCME_RSCN:
1249 if (test_bit(UNLOADING, &vha->dpc_flags))
1250 return;
Quinn Tran41dc5292017-01-19 22:28:03 -08001251 switch (ea->id.b.rsvd_1) {
1252 case RSCN_PORT_ADDR:
1253 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1254 if (!fcport) {
1255 /* cable moved */
1256 rc = qla24xx_post_gpnid_work(vha, &ea->id);
1257 if (rc) {
Quinn Tran83548fe2017-06-02 09:12:01 -07001258 ql_log(ql_log_warn, vha, 0xd044,
1259 "RSCN GPNID work failed %02x%02x%02x\n",
1260 ea->id.b.domain, ea->id.b.area,
1261 ea->id.b.al_pa);
Quinn Tran41dc5292017-01-19 22:28:03 -08001262 }
1263 } else {
1264 ea->fcport = fcport;
1265 qla24xx_handle_rscn_event(fcport, ea);
Quinn Tran726b8542017-01-19 22:28:00 -08001266 }
Quinn Tran41dc5292017-01-19 22:28:03 -08001267 break;
1268 case RSCN_AREA_ADDR:
1269 case RSCN_DOM_ADDR:
1270 if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) {
1271 mask = 0xffff00;
Quinn Tran83548fe2017-06-02 09:12:01 -07001272 ql_dbg(ql_dbg_async, vha, 0x5044,
1273 "RSCN: Area 0x%06x was affected\n",
1274 ea->id.b24);
Quinn Tran41dc5292017-01-19 22:28:03 -08001275 } else {
1276 mask = 0xff0000;
Quinn Tran83548fe2017-06-02 09:12:01 -07001277 ql_dbg(ql_dbg_async, vha, 0x507a,
1278 "RSCN: Domain 0x%06x was affected\n",
1279 ea->id.b24);
Quinn Tran41dc5292017-01-19 22:28:03 -08001280 }
1281
1282 rid = ea->id.b24 & mask;
1283 list_for_each_entry_safe(f, tf, &vha->vp_fcports,
1284 list) {
1285 id = f->d_id.b24 & mask;
1286 if (rid == id) {
1287 ea->fcport = f;
1288 qla24xx_handle_rscn_event(f, ea);
1289 }
1290 }
1291 break;
1292 case RSCN_FAB_ADDR:
1293 default:
Quinn Tran83548fe2017-06-02 09:12:01 -07001294 ql_log(ql_log_warn, vha, 0xd045,
1295 "RSCN: Fabric was affected. Addr format %d\n",
1296 ea->id.b.rsvd_1);
Quinn Tran41dc5292017-01-19 22:28:03 -08001297 qla2x00_mark_all_devices_lost(vha, 1);
1298 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1299 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Quinn Tran726b8542017-01-19 22:28:00 -08001300 }
1301 break;
1302 case FCME_GIDPN_DONE:
1303 qla24xx_handle_gidpn_event(vha, ea);
1304 break;
1305 case FCME_GNL_DONE:
1306 qla24xx_handle_gnl_done_event(vha, ea);
1307 break;
1308 case FCME_GPSC_DONE:
1309 qla24xx_post_upd_fcport_work(vha, ea->fcport);
1310 break;
1311 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1312 qla24xx_handle_plogi_done_event(vha, ea);
1313 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001314 case FCME_PRLI_DONE:
1315 qla24xx_handle_prli_done_event(vha, ea);
1316 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001317 case FCME_GPDB_DONE:
1318 qla24xx_handle_gpdb_event(vha, ea);
1319 break;
1320 case FCME_GPNID_DONE:
1321 qla24xx_handle_gpnid_event(vha, ea);
1322 break;
Duane Grigsbyd3bae932017-06-21 13:48:44 -07001323 case FCME_GFFID_DONE:
1324 qla24xx_handle_gffid_event(vha, ea);
1325 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001326 case FCME_DELETE_DONE:
1327 qla24xx_handle_delete_done_event(vha, ea);
1328 break;
Quinn Tranf13515a2017-12-28 12:33:15 -08001329 case FCME_ADISC_DONE:
1330 qla24xx_handle_adisc_event(vha, ea);
1331 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001332 default:
1333 BUG_ON(1);
1334 break;
1335 }
1336}
1337
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001338static void
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001339qla2x00_tmf_iocb_timeout(void *data)
1340{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001341 srb_t *sp = data;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001342 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1343
1344 tmf->u.tmf.comp_status = CS_TIMEOUT;
1345 complete(&tmf->u.tmf.comp);
1346}
1347
1348static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001349qla2x00_tmf_sp_done(void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001350{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001351 srb_t *sp = ptr;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001352 struct srb_iocb *tmf = &sp->u.iocb_cmd;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001353
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001354 complete(&tmf->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001355}
1356
1357int
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001358qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001359 uint32_t tag)
1360{
1361 struct scsi_qla_host *vha = fcport->vha;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001362 struct srb_iocb *tm_iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001363 srb_t *sp;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001364 int rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001365
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001366 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001367 if (!sp)
1368 goto done;
1369
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001370 tm_iocb = &sp->u.iocb_cmd;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001371 sp->type = SRB_TM_CMD;
1372 sp->name = "tmf";
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001373 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1374 tm_iocb->u.tmf.flags = flags;
1375 tm_iocb->u.tmf.lun = lun;
1376 tm_iocb->u.tmf.data = tag;
1377 sp->done = qla2x00_tmf_sp_done;
1378 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1379 init_completion(&tm_iocb->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001380
1381 rval = qla2x00_start_sp(sp);
1382 if (rval != QLA_SUCCESS)
1383 goto done_free_sp;
1384
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001385 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001386 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1387 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1388 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001389
1390 wait_for_completion(&tm_iocb->u.tmf.comp);
1391
1392 rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
1393 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1394
1395 if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
1396 ql_dbg(ql_dbg_taskm, vha, 0x8030,
1397 "TM IOCB failed (%x).\n", rval);
1398 }
1399
1400 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1401 flags = tm_iocb->u.tmf.flags;
1402 lun = (uint16_t)tm_iocb->u.tmf.lun;
1403
1404 /* Issue Marker IOCB */
1405 qla2x00_marker(vha, vha->hw->req_q_map[0],
1406 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
1407 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1408 }
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001409
1410done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001411 sp->free(sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001412done:
1413 return rval;
1414}
1415
Armen Baloyan4440e462014-02-26 04:15:18 -05001416static void
1417qla24xx_abort_iocb_timeout(void *data)
1418{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001419 srb_t *sp = data;
Armen Baloyan4440e462014-02-26 04:15:18 -05001420 struct srb_iocb *abt = &sp->u.iocb_cmd;
1421
1422 abt->u.abt.comp_status = CS_TIMEOUT;
1423 complete(&abt->u.abt.comp);
1424}
1425
1426static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001427qla24xx_abort_sp_done(void *ptr, int res)
Armen Baloyan4440e462014-02-26 04:15:18 -05001428{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001429 srb_t *sp = ptr;
Armen Baloyan4440e462014-02-26 04:15:18 -05001430 struct srb_iocb *abt = &sp->u.iocb_cmd;
1431
1432 complete(&abt->u.abt.comp);
1433}
1434
Quinn Tran15f30a52017-03-15 09:48:52 -07001435int
Armen Baloyan4440e462014-02-26 04:15:18 -05001436qla24xx_async_abort_cmd(srb_t *cmd_sp)
1437{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001438 scsi_qla_host_t *vha = cmd_sp->vha;
Armen Baloyan4440e462014-02-26 04:15:18 -05001439 fc_port_t *fcport = cmd_sp->fcport;
1440 struct srb_iocb *abt_iocb;
1441 srb_t *sp;
1442 int rval = QLA_FUNCTION_FAILED;
1443
1444 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1445 if (!sp)
1446 goto done;
1447
1448 abt_iocb = &sp->u.iocb_cmd;
1449 sp->type = SRB_ABT_CMD;
1450 sp->name = "abort";
1451 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1452 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
1453 sp->done = qla24xx_abort_sp_done;
1454 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
1455 init_completion(&abt_iocb->u.abt.comp);
1456
1457 rval = qla2x00_start_sp(sp);
1458 if (rval != QLA_SUCCESS)
1459 goto done_free_sp;
1460
1461 ql_dbg(ql_dbg_async, vha, 0x507c,
1462 "Abort command issued - hdl=%x, target_id=%x\n",
1463 cmd_sp->handle, fcport->tgt_id);
1464
1465 wait_for_completion(&abt_iocb->u.abt.comp);
1466
1467 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
1468 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1469
1470done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001471 sp->free(sp);
Armen Baloyan4440e462014-02-26 04:15:18 -05001472done:
1473 return rval;
1474}
1475
1476int
1477qla24xx_async_abort_command(srb_t *sp)
1478{
1479 unsigned long flags = 0;
1480
1481 uint32_t handle;
1482 fc_port_t *fcport = sp->fcport;
1483 struct scsi_qla_host *vha = fcport->vha;
1484 struct qla_hw_data *ha = vha->hw;
1485 struct req_que *req = vha->req;
1486
1487 spin_lock_irqsave(&ha->hardware_lock, flags);
1488 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1489 if (req->outstanding_cmds[handle] == sp)
1490 break;
1491 }
1492 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1493 if (handle == req->num_outstanding_cmds) {
1494 /* Command not found. */
1495 return QLA_FUNCTION_FAILED;
1496 }
1497 if (sp->type == SRB_FXIOCB_DCMD)
1498 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1499 FXDISC_ABORT_IOCTL);
1500
1501 return qla24xx_async_abort_cmd(sp);
1502}
1503
Quinn Tran726b8542017-01-19 22:28:00 -08001504static void
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001505qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1506{
1507 switch (ea->data[0]) {
1508 case MBS_COMMAND_COMPLETE:
1509 ql_dbg(ql_dbg_disc, vha, 0x2118,
1510 "%s %d %8phC post gpdb\n",
1511 __func__, __LINE__, ea->fcport->port_name);
1512
1513 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1514 ea->fcport->logout_on_delete = 1;
1515 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1516 break;
1517 default:
Duane Grigsbyedd05de2017-10-13 09:34:06 -07001518 if (ea->fcport->n2n_flag) {
1519 ql_dbg(ql_dbg_disc, vha, 0x2118,
1520 "%s %d %8phC post fc4 prli\n",
1521 __func__, __LINE__, ea->fcport->port_name);
1522 ea->fcport->fc4f_nvme = 0;
1523 ea->fcport->n2n_flag = 0;
1524 qla24xx_post_prli_work(vha, ea->fcport);
1525 }
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001526 ql_dbg(ql_dbg_disc, vha, 0x2119,
1527 "%s %d %8phC unhandle event of %x\n",
1528 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1529 break;
1530 }
1531}
1532
1533static void
Quinn Tran726b8542017-01-19 22:28:00 -08001534qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001535{
Quinn Tran726b8542017-01-19 22:28:00 -08001536 port_id_t cid; /* conflict Nport id */
Quinn Trana084fd62017-12-04 14:45:00 -08001537 u16 lid;
1538 struct fc_port *conflict_fcport;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001539
Quinn Tran726b8542017-01-19 22:28:00 -08001540 switch (ea->data[0]) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07001541 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -07001542 /*
1543 * Driver must validate login state - If PRLI not complete,
1544 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1545 * requests.
1546 */
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001547 if (ea->fcport->fc4f_nvme) {
1548 ql_dbg(ql_dbg_disc, vha, 0x2117,
1549 "%s %d %8phC post prli\n",
1550 __func__, __LINE__, ea->fcport->port_name);
1551 qla24xx_post_prli_work(vha, ea->fcport);
1552 } else {
1553 ql_dbg(ql_dbg_disc, vha, 0x20ea,
Quinn Trana084fd62017-12-04 14:45:00 -08001554 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1555 __func__, __LINE__, ea->fcport->port_name,
1556 ea->fcport->loop_id, ea->fcport->d_id.b24);
1557
1558 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1559 ea->fcport->loop_id = FC_NO_LOOP_ID;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001560 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1561 ea->fcport->logout_on_delete = 1;
Quinn Tran35158322017-08-30 10:16:50 -07001562 ea->fcport->send_els_logo = 0;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001563 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1564 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001565 break;
1566 case MBS_COMMAND_ERROR:
Quinn Tran83548fe2017-06-02 09:12:01 -07001567 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
Quinn Tran726b8542017-01-19 22:28:00 -08001568 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
1569
1570 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1571 ea->fcport->disc_state = DSC_LOGIN_FAILED;
1572 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001573 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1574 else
Quinn Tran726b8542017-01-19 22:28:00 -08001575 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001576 break;
1577 case MBS_LOOP_ID_USED:
Quinn Tran726b8542017-01-19 22:28:00 -08001578 /* data[1] = IO PARAM 1 = nport ID */
1579 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
1580 cid.b.area = (ea->iop[1] >> 8) & 0xff;
1581 cid.b.al_pa = ea->iop[1] & 0xff;
1582 cid.b.rsvd_1 = 0;
1583
Quinn Tran83548fe2017-06-02 09:12:01 -07001584 ql_dbg(ql_dbg_disc, vha, 0x20ec,
1585 "%s %d %8phC LoopID 0x%x in use post gnl\n",
1586 __func__, __LINE__, ea->fcport->port_name,
1587 ea->fcport->loop_id);
Quinn Tran726b8542017-01-19 22:28:00 -08001588
1589 if (IS_SW_RESV_ADDR(cid)) {
1590 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1591 ea->fcport->loop_id = FC_NO_LOOP_ID;
1592 } else {
1593 qla2x00_clear_loop_id(ea->fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001594 }
Quinn Tran726b8542017-01-19 22:28:00 -08001595 qla24xx_post_gnl_work(vha, ea->fcport);
1596 break;
1597 case MBS_PORT_ID_USED:
Quinn Tran83548fe2017-06-02 09:12:01 -07001598 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1599 "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n",
1600 __func__, __LINE__, ea->fcport->port_name,
1601 ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area,
1602 ea->fcport->d_id.b.al_pa);
Quinn Tran726b8542017-01-19 22:28:00 -08001603
Quinn Trana084fd62017-12-04 14:45:00 -08001604 lid = ea->iop[1] & 0xffff;
1605 qlt_find_sess_invalidate_other(vha,
1606 wwn_to_u64(ea->fcport->port_name),
1607 ea->fcport->d_id, lid, &conflict_fcport);
1608
1609 if (conflict_fcport) {
1610 /*
1611 * Another fcport share the same loop_id/nport id.
1612 * Conflict fcport needs to finish cleanup before this
1613 * fcport can proceed to login.
1614 */
1615 conflict_fcport->conflict = ea->fcport;
1616 ea->fcport->login_pause = 1;
1617
1618 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1619 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
1620 __func__, __LINE__, ea->fcport->port_name,
1621 ea->fcport->d_id.b24, lid);
1622 qla2x00_clear_loop_id(ea->fcport);
1623 qla24xx_post_gidpn_work(vha, ea->fcport);
1624 } else {
1625 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1626 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
1627 __func__, __LINE__, ea->fcport->port_name,
1628 ea->fcport->d_id.b24, lid);
1629
1630 qla2x00_clear_loop_id(ea->fcport);
1631 set_bit(lid, vha->hw->loop_id_map);
1632 ea->fcport->loop_id = lid;
1633 ea->fcport->keep_nport_handle = 0;
1634 qlt_schedule_sess_for_deletion(ea->fcport, false);
1635 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001636 break;
1637 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001638 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001639}
1640
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001641void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001642qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1643 uint16_t *data)
1644{
Quinn Tran726b8542017-01-19 22:28:00 -08001645 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Alexei Potashnika6ca8872015-07-14 16:00:44 -04001646 qlt_logo_completion_handler(fcport, data[0]);
Quinn Tran726b8542017-01-19 22:28:00 -08001647 fcport->login_gen++;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001648 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001649}
1650
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001651void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001652qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1653 uint16_t *data)
1654{
1655 if (data[0] == MBS_COMMAND_COMPLETE) {
1656 qla2x00_update_fcport(vha, fcport);
1657
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001658 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001659 }
1660
1661 /* Retry login. */
1662 fcport->flags &= ~FCF_ASYNC_SENT;
1663 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
1664 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1665 else
Andrew Vasquez80d79442011-03-30 11:46:17 -07001666 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001667
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001668 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001669}
1670
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671/****************************************************************************/
1672/* QLogic ISP2x00 Hardware Support Functions. */
1673/****************************************************************************/
1674
Saurav Kashyapfa492632012-11-21 02:40:29 -05001675static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001676qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
1677{
1678 int rval = QLA_SUCCESS;
1679 struct qla_hw_data *ha = vha->hw;
1680 uint32_t idc_major_ver, idc_minor_ver;
Saurav Kashyap711aa7f2012-08-22 14:21:15 -04001681 uint16_t config[4];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001682
1683 qla83xx_idc_lock(vha, 0);
1684
1685 /* SV: TODO: Assign initialization timeout from
1686 * flash-info / other param
1687 */
1688 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
1689 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
1690
1691 /* Set our fcoe function presence */
1692 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
1693 ql_dbg(ql_dbg_p3p, vha, 0xb077,
1694 "Error while setting DRV-Presence.\n");
1695 rval = QLA_FUNCTION_FAILED;
1696 goto exit;
1697 }
1698
1699 /* Decide the reset ownership */
1700 qla83xx_reset_ownership(vha);
1701
1702 /*
1703 * On first protocol driver load:
1704 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
1705 * register.
1706 * Others: Check compatibility with current IDC Major version.
1707 */
1708 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
1709 if (ha->flags.nic_core_reset_owner) {
1710 /* Set IDC Major version */
1711 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
1712 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
1713
1714 /* Clearing IDC-Lock-Recovery register */
1715 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
1716 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
1717 /*
1718 * Clear further IDC participation if we are not compatible with
1719 * the current IDC Major Version.
1720 */
1721 ql_log(ql_log_warn, vha, 0xb07d,
1722 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
1723 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
1724 __qla83xx_clear_drv_presence(vha);
1725 rval = QLA_FUNCTION_FAILED;
1726 goto exit;
1727 }
1728 /* Each function sets its supported Minor version. */
1729 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
1730 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
1731 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
1732
Saurav Kashyap711aa7f2012-08-22 14:21:15 -04001733 if (ha->flags.nic_core_reset_owner) {
1734 memset(config, 0, sizeof(config));
1735 if (!qla81xx_get_port_config(vha, config))
1736 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
1737 QLA8XXX_DEV_READY);
1738 }
1739
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001740 rval = qla83xx_idc_state_handler(vha);
1741
1742exit:
1743 qla83xx_idc_unlock(vha, 0);
1744
1745 return rval;
1746}
1747
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748/*
1749* qla2x00_initialize_adapter
1750* Initialize board.
1751*
1752* Input:
1753* ha = adapter block pointer.
1754*
1755* Returns:
1756* 0 = success
1757*/
1758int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001759qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760{
1761 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001762 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001763 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001764
Joe Carnucciofc90ada2016-07-06 11:14:23 -04001765 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
1766 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
1767
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001769 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001770 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001771 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -08001772 ha->flags.pci_channel_io_perm_failure = 0;
1773 ha->flags.eeh_busy = 0;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -04001774 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001775 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1776 atomic_set(&vha->loop_state, LOOP_DOWN);
1777 vha->device_flags = DFLG_NO_CABLE;
1778 vha->dpc_flags = 0;
1779 vha->flags.management_server_logged_in = 0;
1780 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 ha->isp_abort_cnt = 0;
1782 ha->beacon_blink_led = 0;
1783
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001784 set_bit(0, ha->req_qid_map);
1785 set_bit(0, ha->rsp_qid_map);
1786
Chad Dupuiscfb09192011-11-18 09:03:07 -08001787 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001788 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001789 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001791 ql_log(ql_log_warn, vha, 0x0044,
1792 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 return (rval);
1794 }
1795
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001796 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001798 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001799 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001800 ql_log(ql_log_fatal, vha, 0x004f,
1801 "Unable to validate FLASH data.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001802 return rval;
1803 }
1804
1805 if (IS_QLA8044(ha)) {
1806 qla8044_read_reset_template(vha);
1807
1808 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
1809 * If DONRESET_BIT0 is set, drivers should not set dev_state
1810 * to NEED_RESET. But if NEED_RESET is set, drivers should
1811 * should honor the reset. */
1812 if (ql2xdontresethba == 1)
1813 qla8044_set_idc_dontreset(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001814 }
1815
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001816 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001817 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001818 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001819
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001820 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001822 if (ha->flags.disable_serdes) {
1823 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001824 ql_log(ql_log_info, vha, 0x0077,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001825 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001826 return QLA_FUNCTION_FAILED;
1827 }
1828
Chad Dupuiscfb09192011-11-18 09:03:07 -08001829 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001830 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001832 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
1833 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001834 if (rval)
1835 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001836 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001837 if (rval)
1838 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07001840
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001841 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001842 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001843 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001844 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001845 "Unable to configure ISP84XX.\n");
1846 return QLA_FUNCTION_FAILED;
1847 }
1848 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001849
Quinn Tranead03852017-01-19 22:28:01 -08001850 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001851 rval = qla2x00_init_rings(vha);
1852
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001853 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001855 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001856 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001857 rval = qla84xx_init_chip(vha);
1858 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001859 ql_log(ql_log_warn, vha, 0x00d4,
1860 "Unable to initialize ISP84XX.\n");
Bart Van Assche8d2b21d2015-06-04 15:58:09 -07001861 qla84xx_put_chip(vha);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001862 }
1863 }
1864
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001865 /* Load the NIC Core f/w if we are the first protocol driver. */
1866 if (IS_QLA8031(ha)) {
1867 rval = qla83xx_nic_core_fw_load(vha);
1868 if (rval)
1869 ql_log(ql_log_warn, vha, 0x0124,
1870 "Error in initializing NIC Core f/w.\n");
1871 }
1872
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +05001873 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
1874 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -07001875
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04001876 if (IS_P3P_TYPE(ha))
1877 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
1878 else
1879 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
1880
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 return (rval);
1882}
1883
1884/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001885 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 * @ha: HA context
1887 *
1888 * Returns 0 on success.
1889 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001890int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001891qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001893 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001894 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001895 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001896 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001899 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001902 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1904
Andrew Vasquez737faec2008-10-24 15:13:45 -07001905 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001907 /* Get PCI bus information. */
1908 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07001909 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001910 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1911
1912 return QLA_SUCCESS;
1913}
1914
1915/**
1916 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
1917 * @ha: HA context
1918 *
1919 * Returns 0 on success.
1920 */
1921int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001922qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001923{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001924 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001925 unsigned long flags = 0;
1926 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001927 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001928 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001929
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001930 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001931 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001932
1933 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001934 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001935
1936 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1937 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -07001938 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001939
1940 /*
1941 * If this is a 2300 card and not 2312, reset the
1942 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
1943 * the 2310 also reports itself as a 2300 so we need to get the
1944 * fb revision level -- a 6 indicates it really is a 2300 and
1945 * not a 2310.
1946 */
1947 if (IS_QLA2300(ha)) {
1948 spin_lock_irqsave(&ha->hardware_lock, flags);
1949
1950 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001951 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001952 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07001953 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001954 break;
1955
1956 udelay(10);
1957 }
1958
1959 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001960 WRT_REG_WORD(&reg->ctrl_status, 0x20);
1961 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001962
1963 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001964 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001965
1966 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -07001967 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001968
1969 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001970 WRT_REG_WORD(&reg->ctrl_status, 0x0);
1971 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001972
1973 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001974 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001975 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07001976 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001977 break;
1978
1979 udelay(10);
1980 }
1981
1982 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1983 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001984
1985 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
1986
Andrew Vasquez737faec2008-10-24 15:13:45 -07001987 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001988
1989 /* Get PCI bus information. */
1990 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07001991 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001992 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1993
1994 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995}
1996
1997/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001998 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
1999 * @ha: HA context
2000 *
2001 * Returns 0 on success.
2002 */
2003int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002004qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002005{
Andrew Vasqueza157b102007-05-07 07:43:01 -07002006 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002007 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002008 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002009 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002010
2011 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07002012 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002013
2014 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07002015 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002016 w &= ~PCI_COMMAND_INTX_DISABLE;
2017 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2018
2019 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2020
2021 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -07002022 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2023 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002024
2025 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07002026 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04002027 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002028
Andrew Vasquez737faec2008-10-24 15:13:45 -07002029 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002030
Auke Kok44c10132007-06-08 15:46:36 -07002031 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002032
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002033 /* Get PCI bus information. */
2034 spin_lock_irqsave(&ha->hardware_lock, flags);
2035 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
2036 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2037
2038 return QLA_SUCCESS;
2039}
2040
2041/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002042 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2043 * @ha: HA context
2044 *
2045 * Returns 0 on success.
2046 */
2047int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002048qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002049{
2050 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002051 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002052
2053 pci_set_master(ha->pdev);
2054 pci_try_set_mwi(ha->pdev);
2055
2056 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2057 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2058 w &= ~PCI_COMMAND_INTX_DISABLE;
2059 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2060
2061 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07002062 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04002063 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002064
Andrew Vasquez737faec2008-10-24 15:13:45 -07002065 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002066
2067 ha->chip_revision = ha->pdev->revision;
2068
2069 return QLA_SUCCESS;
2070}
2071
2072/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 * qla2x00_isp_firmware() - Choose firmware image.
2074 * @ha: HA context
2075 *
2076 * Returns 0 on success.
2077 */
2078static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002079qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080{
2081 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07002082 uint16_t loop_id, topo, sw_cap;
2083 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002084 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
2086 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002087 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088
2089 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002090 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
2092 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002093 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -07002094 if (rval == QLA_SUCCESS) {
2095 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002096 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -07002097 &area, &domain, &topo, &sw_cap);
2098 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 }
2100
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002101 if (rval)
2102 ql_dbg(ql_dbg_init, vha, 0x007a,
2103 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
2105 return (rval);
2106}
2107
2108/**
2109 * qla2x00_reset_chip() - Reset ISP chip.
2110 * @ha: HA context
2111 *
2112 * Returns 0 on success.
2113 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002114void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002115qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116{
2117 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002118 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002119 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 uint16_t cmd;
2122
Andrew Vasquez85880802009-12-15 21:29:46 -08002123 if (unlikely(pci_channel_offline(ha->pdev)))
2124 return;
2125
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002126 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127
2128 spin_lock_irqsave(&ha->hardware_lock, flags);
2129
2130 /* Turn off master enable */
2131 cmd = 0;
2132 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2133 cmd &= ~PCI_COMMAND_MASTER;
2134 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2135
2136 if (!IS_QLA2100(ha)) {
2137 /* Pause RISC. */
2138 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
2139 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2140 for (cnt = 0; cnt < 30000; cnt++) {
2141 if ((RD_REG_WORD(&reg->hccr) &
2142 HCCR_RISC_PAUSE) != 0)
2143 break;
2144 udelay(100);
2145 }
2146 } else {
2147 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2148 udelay(10);
2149 }
2150
2151 /* Select FPM registers. */
2152 WRT_REG_WORD(&reg->ctrl_status, 0x20);
2153 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2154
2155 /* FPM Soft Reset. */
2156 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
2157 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
2158
2159 /* Toggle Fpm Reset. */
2160 if (!IS_QLA2200(ha)) {
2161 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
2162 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
2163 }
2164
2165 /* Select frame buffer registers. */
2166 WRT_REG_WORD(&reg->ctrl_status, 0x10);
2167 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2168
2169 /* Reset frame buffer FIFOs. */
2170 if (IS_QLA2200(ha)) {
2171 WRT_FB_CMD_REG(ha, reg, 0xa000);
2172 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2173 } else {
2174 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2175
2176 /* Read back fb_cmd until zero or 3 seconds max */
2177 for (cnt = 0; cnt < 3000; cnt++) {
2178 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2179 break;
2180 udelay(100);
2181 }
2182 }
2183
2184 /* Select RISC module registers. */
2185 WRT_REG_WORD(&reg->ctrl_status, 0);
2186 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2187
2188 /* Reset RISC processor. */
2189 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2190 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2191
2192 /* Release RISC processor. */
2193 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2194 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2195 }
2196
2197 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
2198 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
2199
2200 /* Reset ISP chip. */
2201 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
2202
2203 /* Wait for RISC to recover from reset. */
2204 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2205 /*
2206 * It is necessary to for a delay here since the card doesn't
2207 * respond to PCI reads during a reset. On some architectures
2208 * this will result in an MCA.
2209 */
2210 udelay(20);
2211 for (cnt = 30000; cnt; cnt--) {
2212 if ((RD_REG_WORD(&reg->ctrl_status) &
2213 CSR_ISP_SOFT_RESET) == 0)
2214 break;
2215 udelay(100);
2216 }
2217 } else
2218 udelay(10);
2219
2220 /* Reset RISC processor. */
2221 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2222
2223 WRT_REG_WORD(&reg->semaphore, 0);
2224
2225 /* Release RISC processor. */
2226 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2227 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2228
2229 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2230 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -07002231 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233
2234 udelay(100);
2235 }
2236 } else
2237 udelay(100);
2238
2239 /* Turn on master enable */
2240 cmd |= PCI_COMMAND_MASTER;
2241 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2242
2243 /* Disable RISC pause on FPM parity error. */
2244 if (!IS_QLA2100(ha)) {
2245 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
2246 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2247 }
2248
2249 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2250}
2251
2252/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002253 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2254 *
2255 * Returns 0 on success.
2256 */
Saurav Kashyapfa492632012-11-21 02:40:29 -05002257static int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002258qla81xx_reset_mpi(scsi_qla_host_t *vha)
2259{
2260 uint16_t mb[4] = {0x1010, 0, 1, 0};
2261
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002262 if (!IS_QLA81XX(vha->hw))
2263 return QLA_SUCCESS;
2264
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002265 return qla81xx_write_mpi_register(vha, mb);
2266}
2267
2268/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002269 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002270 * @ha: HA context
2271 *
2272 * Returns 0 on success.
2273 */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002274static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002275qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002276{
2277 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002278 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002279 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Bart Van Assche52c82822015-07-09 07:23:26 -07002280 uint32_t cnt;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002281 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002282 static int abts_cnt; /* ISP abort retry counts */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002283 int rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002284
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002285 spin_lock_irqsave(&ha->hardware_lock, flags);
2286
2287 /* Reset RISC. */
2288 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2289 for (cnt = 0; cnt < 30000; cnt++) {
2290 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2291 break;
2292
2293 udelay(10);
2294 }
2295
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002296 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE))
2297 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2298
2299 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2300 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2301 RD_REG_DWORD(&reg->hccr),
2302 RD_REG_DWORD(&reg->ctrl_status),
2303 (RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE));
2304
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002305 WRT_REG_DWORD(&reg->ctrl_status,
2306 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002307 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002308
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002309 udelay(100);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002310
Andrew Vasquez88c26662005-07-08 17:59:26 -07002311 /* Wait for firmware to complete NVRAM accesses. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002312 RD_REG_WORD(&reg->mailbox0);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002313 for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
2314 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez88c26662005-07-08 17:59:26 -07002315 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002316 if (cnt)
2317 udelay(5);
2318 else
2319 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez88c26662005-07-08 17:59:26 -07002320 }
2321
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002322 if (rval == QLA_SUCCESS)
2323 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2324
2325 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2326 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2327 RD_REG_DWORD(&reg->hccr),
2328 RD_REG_DWORD(&reg->mailbox0));
2329
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002330 /* Wait for soft-reset to complete. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002331 RD_REG_DWORD(&reg->ctrl_status);
Quinn Tran200ffb12016-12-23 18:06:12 -08002332 for (cnt = 0; cnt < 60; cnt++) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002333 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002334 if ((RD_REG_DWORD(&reg->ctrl_status) &
2335 CSRX_ISP_SOFT_RESET) == 0)
2336 break;
2337
2338 udelay(5);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002339 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002340 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_ISP_SOFT_RESET))
2341 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2342
2343 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2344 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2345 RD_REG_DWORD(&reg->hccr),
2346 RD_REG_DWORD(&reg->ctrl_status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002347
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002348 /* If required, do an MPI FW reset now */
2349 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2350 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2351 if (++abts_cnt < 5) {
2352 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2353 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2354 } else {
2355 /*
2356 * We exhausted the ISP abort retries. We have to
2357 * set the board offline.
2358 */
2359 abts_cnt = 0;
2360 vha->flags.online = 0;
2361 }
2362 }
2363 }
2364
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002365 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
2366 RD_REG_DWORD(&reg->hccr);
2367
2368 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
2369 RD_REG_DWORD(&reg->hccr);
2370
2371 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
2372 RD_REG_DWORD(&reg->hccr);
2373
Bart Van Assche52c82822015-07-09 07:23:26 -07002374 RD_REG_WORD(&reg->mailbox0);
Quinn Tran200ffb12016-12-23 18:06:12 -08002375 for (cnt = 60; RD_REG_WORD(&reg->mailbox0) != 0 &&
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002376 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002377 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002378 if (cnt)
2379 udelay(5);
2380 else
2381 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002382 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002383 if (rval == QLA_SUCCESS)
2384 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2385
2386 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2387 "Host Risc 0x%x, mailbox0 0x%x\n",
2388 RD_REG_DWORD(&reg->hccr),
2389 RD_REG_WORD(&reg->mailbox0));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002390
2391 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002392
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002393 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2394 "Driver in %s mode\n",
2395 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2396
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002397 if (IS_NOPOLLING_TYPE(ha))
2398 ha->isp_ops->enable_intrs(ha);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002399
2400 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002401}
2402
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002403static void
2404qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2405{
2406 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2407
2408 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2409 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2410
2411}
2412
2413static void
2414qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2415{
2416 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2417
2418 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2419 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2420}
2421
2422static void
2423qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2424{
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002425 uint32_t wd32 = 0;
2426 uint delta_msec = 100;
2427 uint elapsed_msec = 0;
2428 uint timeout_msec;
2429 ulong n;
2430
Joe Carnucciocc790762015-08-04 13:37:53 -04002431 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2432 vha->hw->pdev->subsystem_device != 0x0240)
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002433 return;
2434
Joe Carnuccio8dd7e3a2015-08-04 13:37:54 -04002435 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2436 udelay(100);
2437
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002438attempt:
2439 timeout_msec = TIMEOUT_SEMAPHORE;
2440 n = timeout_msec / delta_msec;
2441 while (n--) {
2442 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2443 qla25xx_read_risc_sema_reg(vha, &wd32);
2444 if (wd32 & RISC_SEMAPHORE)
2445 break;
2446 msleep(delta_msec);
2447 elapsed_msec += delta_msec;
2448 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2449 goto force;
2450 }
2451
2452 if (!(wd32 & RISC_SEMAPHORE))
2453 goto force;
2454
2455 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2456 goto acquired;
2457
2458 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2459 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2460 n = timeout_msec / delta_msec;
2461 while (n--) {
2462 qla25xx_read_risc_sema_reg(vha, &wd32);
2463 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2464 break;
2465 msleep(delta_msec);
2466 elapsed_msec += delta_msec;
2467 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2468 goto force;
2469 }
2470
2471 if (wd32 & RISC_SEMAPHORE_FORCE)
2472 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2473
2474 goto attempt;
2475
2476force:
2477 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2478
2479acquired:
2480 return;
2481}
2482
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002483/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002484 * qla24xx_reset_chip() - Reset ISP24xx chip.
2485 * @ha: HA context
2486 *
2487 * Returns 0 on success.
2488 */
2489void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002490qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07002491{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002492 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08002493
2494 if (pci_channel_offline(ha->pdev) &&
2495 ha->flags.pci_channel_io_perm_failure) {
2496 return;
2497 }
2498
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002499 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002500
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002501 qla25xx_manipulate_risc_semaphore(vha);
2502
Andrew Vasquez88c26662005-07-08 17:59:26 -07002503 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002504 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002505}
2506
2507/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 * qla2x00_chip_diag() - Test chip for proper operation.
2509 * @ha: HA context
2510 *
2511 * Returns 0 on success.
2512 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002513int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002514qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515{
2516 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002517 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002518 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 unsigned long flags = 0;
2520 uint16_t data;
2521 uint32_t cnt;
2522 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002523 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524
2525 /* Assume a failed state */
2526 rval = QLA_FUNCTION_FAILED;
2527
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002528 ql_dbg(ql_dbg_init, vha, 0x007b,
2529 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530
2531 spin_lock_irqsave(&ha->hardware_lock, flags);
2532
2533 /* Reset ISP chip. */
2534 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
2535
2536 /*
2537 * We need to have a delay here since the card will not respond while
2538 * in reset causing an MCA on some architectures.
2539 */
2540 udelay(20);
2541 data = qla2x00_debounce_register(&reg->ctrl_status);
2542 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2543 udelay(5);
2544 data = RD_REG_WORD(&reg->ctrl_status);
2545 barrier();
2546 }
2547
2548 if (!cnt)
2549 goto chip_diag_failed;
2550
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002551 ql_dbg(ql_dbg_init, vha, 0x007c,
2552 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553
2554 /* Reset RISC processor. */
2555 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2556 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2557
2558 /* Workaround for QLA2312 PCI parity error */
2559 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2560 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2561 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2562 udelay(5);
2563 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002564 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 }
2566 } else
2567 udelay(10);
2568
2569 if (!cnt)
2570 goto chip_diag_failed;
2571
2572 /* Check product ID of chip */
Milan P Gandhi5a68a1c2017-03-31 14:37:04 -07002573 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574
2575 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
2576 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
2577 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
2578 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
2579 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
2580 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002581 ql_log(ql_log_warn, vha, 0x0062,
2582 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2583 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584
2585 goto chip_diag_failed;
2586 }
2587 ha->product_id[0] = mb[1];
2588 ha->product_id[1] = mb[2];
2589 ha->product_id[2] = mb[3];
2590 ha->product_id[3] = mb[4];
2591
2592 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002593 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
2595 else
2596 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002597 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598
2599 if (IS_QLA2200(ha) &&
2600 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
2601 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002602 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002604 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 ha->fw_transfer_size = 128;
2606 }
2607
2608 /* Wrap Incoming Mailboxes Test. */
2609 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2610
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002611 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002612 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002613 if (rval)
2614 ql_log(ql_log_warn, vha, 0x0080,
2615 "Failed mailbox send register test.\n");
2616 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 /* Flag a successful rval */
2618 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 spin_lock_irqsave(&ha->hardware_lock, flags);
2620
2621chip_diag_failed:
2622 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002623 ql_log(ql_log_info, vha, 0x0081,
2624 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625
2626 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2627
2628 return (rval);
2629}
2630
2631/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002632 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2633 * @ha: HA context
2634 *
2635 * Returns 0 on success.
2636 */
2637int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002638qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002639{
2640 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002641 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002642 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002643
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002644 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07002645 return QLA_SUCCESS;
2646
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002647 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002648
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002649 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002650 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002651 ql_log(ql_log_warn, vha, 0x0082,
2652 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002653 } else {
2654 /* Flag a successful rval */
2655 rval = QLA_SUCCESS;
2656 }
2657
2658 return rval;
2659}
2660
Quinn Tranad0a0b02017-12-28 12:33:14 -08002661static void
2662qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002663{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002664 int rval;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002665 dma_addr_t tc_dma;
2666 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002667 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002668
Quinn Tranad0a0b02017-12-28 12:33:14 -08002669 if (ha->eft) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002670 ql_dbg(ql_dbg_init, vha, 0x00bd,
Quinn Tranad0a0b02017-12-28 12:33:14 -08002671 "%s: Offload Mem is already allocated.\n",
2672 __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002673 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002674 }
2675
Quinn Tranad0a0b02017-12-28 12:33:14 -08002676 if (IS_FWI2_CAPABLE(ha)) {
2677 /* Allocate memory for Fibre Channel Event Buffer. */
2678 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2679 !IS_QLA27XX(ha))
2680 goto try_eft;
2681
2682 if (ha->fce)
2683 dma_free_coherent(&ha->pdev->dev,
2684 FCE_SIZE, ha->fce, ha->fce_dma);
2685
2686 /* Allocate memory for Fibre Channel Event Buffer. */
2687 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
2688 GFP_KERNEL);
2689 if (!tc) {
2690 ql_log(ql_log_warn, vha, 0x00be,
2691 "Unable to allocate (%d KB) for FCE.\n",
2692 FCE_SIZE / 1024);
2693 goto try_eft;
2694 }
2695
2696 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
2697 ha->fce_mb, &ha->fce_bufs);
2698 if (rval) {
2699 ql_log(ql_log_warn, vha, 0x00bf,
2700 "Unable to initialize FCE (%d).\n", rval);
2701 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
2702 tc_dma);
2703 ha->flags.fce_enabled = 0;
2704 goto try_eft;
2705 }
2706 ql_dbg(ql_dbg_init, vha, 0x00c0,
2707 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
2708
2709 ha->flags.fce_enabled = 1;
2710 ha->fce_dma = tc_dma;
2711 ha->fce = tc;
2712
2713try_eft:
2714 if (ha->eft)
2715 dma_free_coherent(&ha->pdev->dev,
2716 EFT_SIZE, ha->eft, ha->eft_dma);
2717
2718 /* Allocate memory for Extended Trace Buffer. */
2719 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
2720 GFP_KERNEL);
2721 if (!tc) {
2722 ql_log(ql_log_warn, vha, 0x00c1,
2723 "Unable to allocate (%d KB) for EFT.\n",
2724 EFT_SIZE / 1024);
2725 goto eft_err;
2726 }
2727
2728 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
2729 if (rval) {
2730 ql_log(ql_log_warn, vha, 0x00c2,
2731 "Unable to initialize EFT (%d).\n", rval);
2732 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
2733 tc_dma);
2734 goto eft_err;
2735 }
2736 ql_dbg(ql_dbg_init, vha, 0x00c3,
2737 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
2738
2739 ha->eft_dma = tc_dma;
2740 ha->eft = tc;
2741 }
2742
2743eft_err:
2744 return;
2745}
2746
2747void
2748qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
2749{
2750 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
2751 eft_size, fce_size, mq_size;
2752 struct qla_hw_data *ha = vha->hw;
2753 struct req_que *req = ha->req_q_map[0];
2754 struct rsp_que *rsp = ha->rsp_q_map[0];
2755 struct qla2xxx_fw_dump *fw_dump;
2756
Chad Dupuisf73cb692014-02-26 04:15:06 -05002757 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
2758 req_q_size = rsp_q_size = 0;
2759
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002760 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2761 fixed_size = sizeof(struct qla2100_fw_dump);
2762 } else if (IS_QLA23XX(ha)) {
2763 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
2764 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
2765 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07002766 } else if (IS_FWI2_CAPABLE(ha)) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002767 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002768 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
2769 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002770 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
2771 else if (IS_QLA25XX(ha))
2772 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
2773 else
2774 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002775
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002776 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
2777 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002778 if (ha->mqenable) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002779 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002780 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002781 /*
2782 * Allocate maximum buffer size for all queues.
2783 * Resizing must be done at end-of-dump processing.
2784 */
2785 mq_size += ha->max_req_queues *
2786 (req->length * sizeof(request_t));
2787 mq_size += ha->max_rsp_queues *
2788 (rsp->length * sizeof(response_t));
2789 }
Arun Easi00876ae2013-03-25 02:21:37 -04002790 if (ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002791 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002792 /* Allocate memory for Fibre Channel Event Buffer. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05002793 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2794 !IS_QLA27XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002795 goto try_eft;
2796
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07002797 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002798try_eft:
Chad Dupuiscfb09192011-11-18 09:03:07 -08002799 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002800 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002801 eft_size = EFT_SIZE;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002802 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05002803
Chad Dupuisf73cb692014-02-26 04:15:06 -05002804 if (IS_QLA27XX(ha)) {
2805 if (!ha->fw_dump_template) {
2806 ql_log(ql_log_warn, vha, 0x00ba,
2807 "Failed missing fwdump template\n");
2808 return;
2809 }
2810 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
2811 ql_dbg(ql_dbg_init, vha, 0x00fa,
2812 "-> allocating fwdump (%x bytes)...\n", dump_size);
2813 goto allocate;
2814 }
2815
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002816 req_q_size = req->length * sizeof(request_t);
2817 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002818 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002819 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08002820 ha->chain_offset = dump_size;
2821 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002822
Quinn Tranb945e772017-06-13 20:47:29 -07002823 if (ha->exchoffld_buf)
2824 dump_size += sizeof(struct qla2xxx_offld_chain) +
2825 ha->exchoffld_size;
2826 if (ha->exlogin_buf)
2827 dump_size += sizeof(struct qla2xxx_offld_chain) +
2828 ha->exlogin_size;
2829
Chad Dupuisf73cb692014-02-26 04:15:06 -05002830allocate:
Quinn Tranad0a0b02017-12-28 12:33:14 -08002831 if (!ha->fw_dump_len || dump_size != ha->fw_dump_len) {
2832 fw_dump = vmalloc(dump_size);
2833 if (!fw_dump) {
2834 ql_log(ql_log_warn, vha, 0x00c4,
2835 "Unable to allocate (%d KB) for firmware dump.\n",
2836 dump_size / 1024);
2837 } else {
2838 if (ha->fw_dump)
2839 vfree(ha->fw_dump);
2840 ha->fw_dump = fw_dump;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002841
Quinn Tranad0a0b02017-12-28 12:33:14 -08002842 ha->fw_dump_len = dump_size;
2843 ql_dbg(ql_dbg_init, vha, 0x00c5,
2844 "Allocated (%d KB) for firmware dump.\n",
2845 dump_size / 1024);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002846
Quinn Tranad0a0b02017-12-28 12:33:14 -08002847 if (IS_QLA27XX(ha))
2848 return;
2849
2850 ha->fw_dump->signature[0] = 'Q';
2851 ha->fw_dump->signature[1] = 'L';
2852 ha->fw_dump->signature[2] = 'G';
2853 ha->fw_dump->signature[3] = 'C';
2854 ha->fw_dump->version = htonl(1);
2855
2856 ha->fw_dump->fixed_size = htonl(fixed_size);
2857 ha->fw_dump->mem_size = htonl(mem_size);
2858 ha->fw_dump->req_q_size = htonl(req_q_size);
2859 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
2860
2861 ha->fw_dump->eft_size = htonl(eft_size);
2862 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
2863 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
2864
2865 ha->fw_dump->header_size =
2866 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002867 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002868 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002869}
2870
Andrew Vasquez18e75552009-06-03 09:55:30 -07002871static int
2872qla81xx_mpi_sync(scsi_qla_host_t *vha)
2873{
2874#define MPS_MASK 0xe0
2875 int rval;
2876 uint16_t dc;
2877 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07002878
2879 if (!IS_QLA81XX(vha->hw))
2880 return QLA_SUCCESS;
2881
2882 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
2883 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002884 ql_log(ql_log_warn, vha, 0x0105,
2885 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002886 goto done;
2887 }
2888
2889 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
2890 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
2891 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002892 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002893 goto done_release;
2894 }
2895
2896 dc &= MPS_MASK;
2897 if (dc == (dw & MPS_MASK))
2898 goto done_release;
2899
2900 dw &= ~MPS_MASK;
2901 dw |= dc;
2902 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
2903 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002904 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002905 }
2906
2907done_release:
2908 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
2909 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002910 ql_log(ql_log_warn, vha, 0x006d,
2911 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002912 }
2913
2914done:
2915 return rval;
2916}
2917
Chad Dupuis8d93f552013-01-30 03:34:37 -05002918int
2919qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
2920{
2921 /* Don't try to reallocate the array */
2922 if (req->outstanding_cmds)
2923 return QLA_SUCCESS;
2924
Michael Hernandezd7459522016-12-12 14:40:07 -08002925 if (!IS_FWI2_CAPABLE(ha))
Chad Dupuis8d93f552013-01-30 03:34:37 -05002926 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
2927 else {
Quinn Tran03e8c682015-12-17 14:56:59 -05002928 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
2929 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002930 else
Quinn Tran03e8c682015-12-17 14:56:59 -05002931 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002932 }
2933
2934 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
2935 req->num_outstanding_cmds, GFP_KERNEL);
2936
2937 if (!req->outstanding_cmds) {
2938 /*
2939 * Try to allocate a minimal size just so we can get through
2940 * initialization.
2941 */
2942 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
2943 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
2944 req->num_outstanding_cmds, GFP_KERNEL);
2945
2946 if (!req->outstanding_cmds) {
2947 ql_log(ql_log_fatal, NULL, 0x0126,
2948 "Failed to allocate memory for "
2949 "outstanding_cmds for req_que %p.\n", req);
2950 req->num_outstanding_cmds = 0;
2951 return QLA_FUNCTION_FAILED;
2952 }
2953 }
2954
2955 return QLA_SUCCESS;
2956}
2957
Quinn Trane4e3a2c2017-08-23 15:05:07 -07002958#define PRINT_FIELD(_field, _flag, _str) { \
2959 if (a0->_field & _flag) {\
2960 if (p) {\
2961 strcat(ptr, "|");\
2962 ptr++;\
2963 leftover--;\
2964 } \
2965 len = snprintf(ptr, leftover, "%s", _str); \
2966 p = 1;\
2967 leftover -= len;\
2968 ptr += len; \
2969 } \
2970}
2971
2972static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
2973{
2974#define STR_LEN 64
2975 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
2976 u8 str[STR_LEN], *ptr, p;
2977 int leftover, len;
2978
2979 memset(str, 0, STR_LEN);
2980 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
2981 ql_dbg(ql_dbg_init, vha, 0x015a,
2982 "SFP MFG Name: %s\n", str);
2983
2984 memset(str, 0, STR_LEN);
2985 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
2986 ql_dbg(ql_dbg_init, vha, 0x015c,
2987 "SFP Part Name: %s\n", str);
2988
2989 /* media */
2990 memset(str, 0, STR_LEN);
2991 ptr = str;
2992 leftover = STR_LEN;
2993 p = len = 0;
2994 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
2995 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
2996 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
2997 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
2998 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
2999 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3000 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3001 ql_dbg(ql_dbg_init, vha, 0x0160,
3002 "SFP Media: %s\n", str);
3003
3004 /* link length */
3005 memset(str, 0, STR_LEN);
3006 ptr = str;
3007 leftover = STR_LEN;
3008 p = len = 0;
3009 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3010 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3011 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3012 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3013 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3014 ql_dbg(ql_dbg_init, vha, 0x0196,
3015 "SFP Link Length: %s\n", str);
3016
3017 memset(str, 0, STR_LEN);
3018 ptr = str;
3019 leftover = STR_LEN;
3020 p = len = 0;
3021 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3022 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3023 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3024 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3025 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3026 ql_dbg(ql_dbg_init, vha, 0x016e,
3027 "SFP FC Link Tech: %s\n", str);
3028
3029 if (a0->length_km)
3030 ql_dbg(ql_dbg_init, vha, 0x016f,
3031 "SFP Distant: %d km\n", a0->length_km);
3032 if (a0->length_100m)
3033 ql_dbg(ql_dbg_init, vha, 0x0170,
3034 "SFP Distant: %d m\n", a0->length_100m*100);
3035 if (a0->length_50um_10m)
3036 ql_dbg(ql_dbg_init, vha, 0x0189,
3037 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3038 if (a0->length_62um_10m)
3039 ql_dbg(ql_dbg_init, vha, 0x018a,
3040 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3041 if (a0->length_om4_10m)
3042 ql_dbg(ql_dbg_init, vha, 0x0194,
3043 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3044 if (a0->length_om3_10m)
3045 ql_dbg(ql_dbg_init, vha, 0x0195,
3046 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3047}
3048
3049
3050/*
3051 * Return Code:
3052 * QLA_SUCCESS: no action
3053 * QLA_INTERFACE_ERROR: SFP is not there.
3054 * QLA_FUNCTION_FAILED: detected New SFP
3055 */
3056int
3057qla24xx_detect_sfp(scsi_qla_host_t *vha)
3058{
3059 int rc = QLA_SUCCESS;
3060 struct sff_8247_a0 *a;
3061 struct qla_hw_data *ha = vha->hw;
3062
3063 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3064 goto out;
3065
3066 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3067 if (rc)
3068 goto out;
3069
3070 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3071 qla2xxx_print_sfp_info(vha);
3072
3073 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3074 /* long range */
3075 ha->flags.detected_lr_sfp = 1;
3076
3077 if (a->length_km > 5 || a->length_100m > 50)
3078 ha->long_range_distance = LR_DISTANCE_10K;
3079 else
3080 ha->long_range_distance = LR_DISTANCE_5K;
3081
3082 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3083 ql_dbg(ql_dbg_async, vha, 0x507b,
3084 "Detected Long Range SFP.\n");
3085 } else {
3086 /* short range */
3087 ha->flags.detected_lr_sfp = 0;
3088 if (ha->flags.using_lr_setting)
3089 ql_dbg(ql_dbg_async, vha, 0x5084,
3090 "Detected Short Range SFP.\n");
3091 }
3092
3093 if (!vha->flags.init_done)
3094 rc = QLA_SUCCESS;
3095out:
3096 return rc;
3097}
3098
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003099/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 * qla2x00_setup_chip() - Load and start RISC firmware.
3101 * @ha: HA context
3102 *
3103 * Returns 0 on success.
3104 */
3105static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003106qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003108 int rval;
3109 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003110 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08003111 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3112 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07003113 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08003114
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003115 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003116 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05003117 if (rval == QLA_SUCCESS) {
3118 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003119 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05003120 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07003121 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003122 }
3123
Andrew Vasquez3db06522008-01-31 12:33:49 -08003124 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3125 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3126 spin_lock_irqsave(&ha->hardware_lock, flags);
3127 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
3128 RD_REG_WORD(&reg->hccr);
3129 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3130 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131
Andrew Vasquez18e75552009-06-03 09:55:30 -07003132 qla81xx_mpi_sync(vha);
3133
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003135 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003136 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003137 ql_dbg(ql_dbg_init, vha, 0x00c9,
3138 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003140 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 if (rval == QLA_SUCCESS) {
3142 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003143 ql_dbg(ql_dbg_init, vha, 0x00ca,
3144 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003146 if (ql2xexlogins)
3147 ha->flags.exlogins_enabled = 1;
3148
Quinn Tran99e1b682017-06-02 09:12:03 -07003149 if (qla_is_exch_offld_enabled(vha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003150 ha->flags.exchoffld_enabled = 1;
3151
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003152 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07003154 if (rval == QLA_SUCCESS) {
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003155 qla24xx_detect_sfp(vha);
3156
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003157 rval = qla2x00_set_exlogins_buffer(vha);
3158 if (rval != QLA_SUCCESS)
3159 goto failed;
3160
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003161 rval = qla2x00_set_exchoffld_buffer(vha);
3162 if (rval != QLA_SUCCESS)
3163 goto failed;
3164
Giridhar Malavalia9083012010-04-12 17:59:55 -07003165enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07003166 fw_major_version = ha->fw_major_version;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003167 if (IS_P3P_TYPE(ha))
Giridhar Malavali31731672011-08-16 11:31:54 -07003168 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003169 else
3170 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07003171 if (rval != QLA_SUCCESS)
3172 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003173 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003174 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07003175 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003176 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003177 if ((!ha->max_npiv_vports) ||
3178 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003179 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003180 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003181 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003182 }
Quinn Tran03e8c682015-12-17 14:56:59 -05003183 qla2x00_get_resource_cnts(vha);
Andrew Vasquezd743de62009-03-24 09:08:15 -07003184
Chad Dupuis8d93f552013-01-30 03:34:37 -05003185 /*
3186 * Allocate the array of outstanding commands
3187 * now that we know the firmware resources.
3188 */
3189 rval = qla2x00_alloc_outstanding_cmds(ha,
3190 vha->req);
3191 if (rval != QLA_SUCCESS)
3192 goto failed;
3193
Quinn Tranad0a0b02017-12-28 12:33:14 -08003194 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3195 qla2x00_alloc_offload_mem(vha);
3196
3197 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
Giridhar Malavali08de2842011-08-16 11:31:44 -07003198 qla2x00_alloc_fw_dump(vha);
Quinn Tranad0a0b02017-12-28 12:33:14 -08003199
Chad Dupuis3b6e5b92013-10-30 03:38:09 -04003200 } else {
3201 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 }
3203 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003204 ql_log(ql_log_fatal, vha, 0x00cd,
3205 "ISP Firmware failed checksum.\n");
3206 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04003208 } else
3209 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210
Andrew Vasquez3db06522008-01-31 12:33:49 -08003211 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3212 /* Enable proper parity. */
3213 spin_lock_irqsave(&ha->hardware_lock, flags);
3214 if (IS_QLA2300(ha))
3215 /* SRAM parity */
3216 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
3217 else
3218 /* SRAM, Instruction RAM and GP RAM parity */
3219 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
3220 RD_REG_WORD(&reg->hccr);
3221 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3222 }
3223
Chad Dupuisf3982d82014-09-25 05:16:57 -04003224 if (IS_QLA27XX(ha))
3225 ha->flags.fac_supported = 1;
3226 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003227 uint32_t size;
3228
3229 rval = qla81xx_fac_get_sector_size(vha, &size);
3230 if (rval == QLA_SUCCESS) {
3231 ha->flags.fac_supported = 1;
3232 ha->fdt_block_size = size << 2;
3233 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003234 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003235 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3236 ha->fw_major_version, ha->fw_minor_version,
3237 ha->fw_subminor_version);
Joe Carnuccio1ca60e32014-02-26 04:15:02 -05003238
Chad Dupuisf73cb692014-02-26 04:15:06 -05003239 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003240 ha->flags.fac_supported = 0;
3241 rval = QLA_SUCCESS;
3242 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003243 }
3244 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07003245failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003247 ql_log(ql_log_fatal, vha, 0x00cf,
3248 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249 }
3250
3251 return (rval);
3252}
3253
3254/**
3255 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3256 * @ha: HA context
3257 *
3258 * Beginning of request ring has initialization control block already built
3259 * by nvram config routine.
3260 *
3261 * Returns 0 on success.
3262 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003263void
3264qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265{
3266 uint16_t cnt;
3267 response_t *pkt;
3268
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003269 rsp->ring_ptr = rsp->ring;
3270 rsp->ring_index = 0;
3271 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003272 pkt = rsp->ring_ptr;
3273 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 pkt->signature = RESPONSE_PROCESSED;
3275 pkt++;
3276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277}
3278
3279/**
3280 * qla2x00_update_fw_options() - Read and process firmware options.
3281 * @ha: HA context
3282 *
3283 * Returns 0 on success.
3284 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003285void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003286qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287{
3288 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003289 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290
3291 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003292 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293
3294 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3295 return;
3296
3297 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003298 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3299 "Serial link options.\n");
3300 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3301 (uint8_t *)&ha->fw_seriallink_options,
3302 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303
3304 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3305 if (ha->fw_seriallink_options[3] & BIT_2) {
3306 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3307
3308 /* 1G settings */
3309 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3310 emphasis = (ha->fw_seriallink_options[2] &
3311 (BIT_4 | BIT_3)) >> 3;
3312 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003313 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 rx_sens = (ha->fw_seriallink_options[0] &
3315 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3316 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3317 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3318 if (rx_sens == 0x0)
3319 rx_sens = 0x3;
3320 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3321 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3322 ha->fw_options[10] |= BIT_5 |
3323 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3324 (tx_sens & (BIT_1 | BIT_0));
3325
3326 /* 2G settings */
3327 swing = (ha->fw_seriallink_options[2] &
3328 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3329 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3330 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003331 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 rx_sens = (ha->fw_seriallink_options[1] &
3333 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3334 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3335 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3336 if (rx_sens == 0x0)
3337 rx_sens = 0x3;
3338 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3339 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3340 ha->fw_options[11] |= BIT_5 |
3341 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3342 (tx_sens & (BIT_1 | BIT_0));
3343 }
3344
3345 /* FCP2 options. */
3346 /* Return command IOCBs without waiting for an ABTS to complete. */
3347 ha->fw_options[3] |= BIT_13;
3348
3349 /* LED scheme. */
3350 if (ha->flags.enable_led_scheme)
3351 ha->fw_options[2] |= BIT_12;
3352
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003353 /* Detect ISP6312. */
3354 if (IS_QLA6312(ha))
3355 ha->fw_options[2] |= BIT_13;
3356
Giridhar Malavali088d09d2016-07-06 11:14:20 -04003357 /* Set Retry FLOGI in case of P2P connection */
3358 if (ha->operating_mode == P2P) {
3359 ha->fw_options[2] |= BIT_3;
3360 ql_dbg(ql_dbg_disc, vha, 0x2100,
3361 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3362 __func__, ha->fw_options[2]);
3363 }
3364
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003366 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367}
3368
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003369void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003370qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003371{
3372 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003373 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003374
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003375 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07003376 return;
3377
Himanshu Madhanif198caf2016-01-27 12:03:30 -05003378 /* Hold status IOCBs until ABTS response received. */
3379 if (ql2xfwholdabts)
3380 ha->fw_options[3] |= BIT_12;
3381
Giridhar Malavali088d09d2016-07-06 11:14:20 -04003382 /* Set Retry FLOGI in case of P2P connection */
3383 if (ha->operating_mode == P2P) {
3384 ha->fw_options[2] |= BIT_3;
3385 ql_dbg(ql_dbg_disc, vha, 0x2101,
3386 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3387 __func__, ha->fw_options[2]);
3388 }
3389
Quinn Tran41dc5292017-01-19 22:28:03 -08003390 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
Quinn Tran3c4810f2017-06-02 09:11:53 -07003391 if (ql2xmvasynctoatio &&
3392 (IS_QLA83XX(ha) || IS_QLA27XX(ha))) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003393 if (qla_tgt_mode_enabled(vha) ||
3394 qla_dual_mode_enabled(vha))
3395 ha->fw_options[2] |= BIT_11;
3396 else
3397 ha->fw_options[2] &= ~BIT_11;
3398 }
3399
Quinn Tranf7e761f2017-06-02 09:12:02 -07003400 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3401 /*
3402 * Tell FW to track each exchange to prevent
3403 * driver from using stale exchange.
3404 */
3405 if (qla_tgt_mode_enabled(vha) ||
3406 qla_dual_mode_enabled(vha))
3407 ha->fw_options[2] |= BIT_4;
3408 else
3409 ha->fw_options[2] &= ~BIT_4;
Quinn Tran9ecf0b02017-12-28 12:33:19 -08003410
3411 /* Reserve 1/2 of emergency exchanges for ELS.*/
3412 if (qla2xuseresexchforels)
3413 ha->fw_options[2] |= BIT_8;
3414 else
3415 ha->fw_options[2] &= ~BIT_8;
Quinn Tranf7e761f2017-06-02 09:12:02 -07003416 }
3417
Quinn Tran83548fe2017-06-02 09:12:01 -07003418 ql_dbg(ql_dbg_init, vha, 0x00e8,
3419 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3420 __func__, ha->fw_options[1], ha->fw_options[2],
3421 ha->fw_options[3], vha->host->active_mode);
Quinn Tran3c4810f2017-06-02 09:11:53 -07003422
3423 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3424 qla2x00_set_fw_options(vha, ha->fw_options);
Quinn Tran41dc5292017-01-19 22:28:03 -08003425
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003426 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08003427 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003428 return;
3429
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003430 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08003431 le16_to_cpu(ha->fw_seriallink_options24[1]),
3432 le16_to_cpu(ha->fw_seriallink_options24[2]),
3433 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003434 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003435 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003436 "Unable to update Serial Link options (%x).\n", rval);
3437 }
3438}
3439
3440void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003441qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003442{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003443 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003444 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003445 struct req_que *req = ha->req_q_map[0];
3446 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003447
3448 /* Setup ring parameters in initialization control block. */
Bart Van Asschead950362015-07-09 07:24:08 -07003449 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3450 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003451 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3452 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3453 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3454 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3455 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3456 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003457
3458 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3459 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3460 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3461 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3462 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3463}
3464
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003465void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003466qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003467{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003468 struct qla_hw_data *ha = vha->hw;
Bart Van Assche118e2ef2015-07-09 07:24:27 -07003469 device_reg_t *reg = ISP_QUE_REG(ha, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003470 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3471 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003472 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003473 uint16_t rid = 0;
3474 struct req_que *req = ha->req_q_map[0];
3475 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003476
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003477 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003478 icb = (struct init_cb_24xx *)ha->init_cb;
Bart Van Asschead950362015-07-09 07:24:08 -07003479 icb->request_q_outpointer = cpu_to_le16(0);
3480 icb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003481 icb->request_q_length = cpu_to_le16(req->length);
3482 icb->response_q_length = cpu_to_le16(rsp->length);
3483 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3484 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3485 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3486 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003487
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003488 /* Setup ATIO queue dma pointers for target mode */
Bart Van Asschead950362015-07-09 07:24:08 -07003489 icb->atio_q_inpointer = cpu_to_le16(0);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003490 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3491 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
3492 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
3493
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003494 if (IS_SHADOW_REG_CAPABLE(ha))
Bart Van Asschead950362015-07-09 07:24:08 -07003495 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003496
Chad Dupuisf73cb692014-02-26 04:15:06 -05003497 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003498 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3499 icb->rid = cpu_to_le16(rid);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003500 if (ha->flags.msix_enabled) {
3501 msix = &ha->msix_entries[1];
Quinn Tran83548fe2017-06-02 09:12:01 -07003502 ql_dbg(ql_dbg_init, vha, 0x0019,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003503 "Registering vector 0x%x for base que.\n",
3504 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003505 icb->msix = cpu_to_le16(msix->entry);
3506 }
3507 /* Use alternate PCI bus number */
3508 if (MSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003509 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003510 /* Use alternate PCI devfn */
3511 if (LSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003512 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003513
Anirban Chakraborty31557542009-12-02 10:36:55 -08003514 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003515 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
3516 (ha->flags.msix_enabled)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003517 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003518 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003519 ql_dbg(ql_dbg_init, vha, 0x00fe,
3520 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08003521 } else {
Bart Van Asschead950362015-07-09 07:24:08 -07003522 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003523 }
Bart Van Asschead950362015-07-09 07:24:08 -07003524 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003525
3526 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
3527 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
3528 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
3529 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
3530 } else {
3531 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
3532 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
3533 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
3534 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
3535 }
Arun Easiaa230bc2013-01-30 03:34:39 -05003536 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003537
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003538 /* PCI posting */
3539 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003540}
3541
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542/**
3543 * qla2x00_init_rings() - Initializes firmware.
3544 * @ha: HA context
3545 *
3546 * Beginning of request ring has initialization control block already built
3547 * by nvram config routine.
3548 *
3549 * Returns 0 on success.
3550 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003551int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003552qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553{
3554 int rval;
3555 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003556 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003557 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003558 struct req_que *req;
3559 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003560 struct mid_init_cb_24xx *mid_init_cb =
3561 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562
3563 spin_lock_irqsave(&ha->hardware_lock, flags);
3564
3565 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003566 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003567 req = ha->req_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003568 if (!req || !test_bit(que, ha->req_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003569 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003570 req->out_ptr = (void *)(req->ring + req->length);
3571 *req->out_ptr = 0;
Chad Dupuis8d93f552013-01-30 03:34:37 -05003572 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003573 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003575 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003576
3577 /* Initialize firmware. */
3578 req->ring_ptr = req->ring;
3579 req->ring_index = 0;
3580 req->cnt = req->length;
3581 }
3582
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003583 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003584 rsp = ha->rsp_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003585 if (!rsp || !test_bit(que, ha->rsp_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003586 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003587 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
3588 *rsp->in_ptr = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003589 /* Initialize response queue entries */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003590 if (IS_QLAFX00(ha))
3591 qlafx00_init_response_q_entries(rsp);
3592 else
3593 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003594 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003596 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
3597 ha->tgt.atio_ring_index = 0;
3598 /* Initialize ATIO queue entries */
3599 qlt_init_atio_q_entries(vha);
3600
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003601 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602
3603 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3604
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003605 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
3606
3607 if (IS_QLAFX00(ha)) {
3608 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
3609 goto next_check;
3610 }
3611
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003613 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003615 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04003616 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003617 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08003618 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003619 }
3620
Andrew Vasquez24a08132009-03-24 09:08:16 -07003621 if (IS_FWI2_CAPABLE(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003622 mid_init_cb->options = cpu_to_le16(BIT_1);
Andrew Vasquez24a08132009-03-24 09:08:16 -07003623 mid_init_cb->init_cb.execution_throttle =
Quinn Tran03e8c682015-12-17 14:56:59 -05003624 cpu_to_le16(ha->cur_fw_xcb_count);
Joe Carnuccio40f38622016-07-06 11:14:28 -04003625 ha->flags.dport_enabled =
3626 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
3627 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
3628 (ha->flags.dport_enabled) ? "enabled" : "disabled");
3629 /* FA-WWPN Status */
Himanshu Madhani2486c622014-09-25 05:17:00 -04003630 ha->flags.fawwpn_enabled =
Joe Carnuccio40f38622016-07-06 11:14:28 -04003631 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
Quinn Tran83548fe2017-06-02 09:12:01 -07003632 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
Himanshu Madhani2486c622014-09-25 05:17:00 -04003633 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
Andrew Vasquez24a08132009-03-24 09:08:16 -07003634 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003635
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003636 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003637next_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003639 ql_log(ql_log_fatal, vha, 0x00d2,
3640 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003642 ql_dbg(ql_dbg_init, vha, 0x00d3,
3643 "Init Firmware -- success.\n");
Quinn Tran4b60c822017-06-13 20:47:21 -07003644 QLA_FW_STARTED(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 }
3646
3647 return (rval);
3648}
3649
3650/**
3651 * qla2x00_fw_ready() - Waits for firmware ready.
3652 * @ha: HA context
3653 *
3654 * Returns 0 on success.
3655 */
3656static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003657qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658{
3659 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003660 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661 uint16_t min_wait; /* Minimum wait time if loop is down */
3662 uint16_t wait_time; /* Wait time if loop is coming ready */
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003663 uint16_t state[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003664 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003666 if (IS_QLAFX00(vha->hw))
3667 return qlafx00_fw_ready(vha);
3668
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 rval = QLA_SUCCESS;
3670
Chad Dupuis334614912015-04-09 14:59:57 -04003671 /* Time to wait for loop down */
3672 if (IS_P3P_TYPE(ha))
3673 min_wait = 30;
3674 else
3675 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676
3677 /*
3678 * Firmware should take at most one RATOV to login, plus 5 seconds for
3679 * our own processing.
3680 */
3681 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
3682 wait_time = min_wait;
3683 }
3684
3685 /* Min wait time if loop down */
3686 mtime = jiffies + (min_wait * HZ);
3687
3688 /* wait time before firmware ready */
3689 wtime = jiffies + (wait_time * HZ);
3690
3691 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003692 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003693 ql_log(ql_log_info, vha, 0x801e,
3694 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695
3696 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05003697 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003698 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003700 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003701 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003703 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003704 ql_dbg(ql_dbg_taskm, vha, 0x801f,
3705 "fw_state=%x 84xx=%x.\n", state[0],
3706 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003707 if ((state[2] & FSTATE_LOGGED_IN) &&
3708 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003709 ql_dbg(ql_dbg_taskm, vha, 0x8028,
3710 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003711
3712 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003713 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003714 if (rval != QLA_SUCCESS) {
3715 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08003716 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003717 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003718 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003719 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003720
3721 /* Add time taken to initialize. */
3722 cs84xx_time = jiffies - cs84xx_time;
3723 wtime += cs84xx_time;
3724 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08003725 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003726 "Increasing wait time by %ld. "
3727 "New time %ld.\n", cs84xx_time,
3728 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003729 }
3730 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003731 ql_dbg(ql_dbg_taskm, vha, 0x8037,
3732 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003734 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735 &ha->login_timeout, &ha->r_a_tov);
3736
3737 rval = QLA_SUCCESS;
3738 break;
3739 }
3740
3741 rval = QLA_FUNCTION_FAILED;
3742
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003743 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003744 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003746 * other than Wait for Login.
3747 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003749 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750 "Cable is unplugged...\n");
3751
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003752 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 break;
3754 }
3755 }
3756 } else {
3757 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07003758 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08003759 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760 break;
3761 }
3762
3763 if (time_after_eq(jiffies, wtime))
3764 break;
3765
3766 /* Delay for a while */
3767 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 } while (1);
3769
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003770 ql_dbg(ql_dbg_taskm, vha, 0x803a,
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003771 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
3772 state[1], state[2], state[3], state[4], state[5], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773
Chad Dupuiscfb09192011-11-18 09:03:07 -08003774 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003775 ql_log(ql_log_warn, vha, 0x803b,
3776 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 }
3778
3779 return (rval);
3780}
3781
3782/*
3783* qla2x00_configure_hba
3784* Setup adapter context.
3785*
3786* Input:
3787* ha = adapter state pointer.
3788*
3789* Returns:
3790* 0 = success
3791*
3792* Context:
3793* Kernel context.
3794*/
3795static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003796qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797{
3798 int rval;
3799 uint16_t loop_id;
3800 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003801 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 uint8_t al_pa;
3803 uint8_t area;
3804 uint8_t domain;
3805 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003806 struct qla_hw_data *ha = vha->hw;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003807 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003808 port_id_t id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809
3810 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003811 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003812 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003814 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003815 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08003816 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003817 ql_dbg(ql_dbg_disc, vha, 0x2008,
3818 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08003819 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003820 ql_log(ql_log_warn, vha, 0x2009,
3821 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003822 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
3823 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
3824 ql_log(ql_log_warn, vha, 0x1151,
3825 "Doing link init.\n");
3826 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
3827 return rval;
3828 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003829 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08003830 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 return (rval);
3832 }
3833
3834 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003835 ql_log(ql_log_info, vha, 0x200a,
3836 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837 return (QLA_FUNCTION_FAILED);
3838 }
3839
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003840 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841
3842 /* initialize */
3843 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
3844 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003845 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846
3847 switch (topo) {
3848 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003849 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 ha->current_topology = ISP_CFG_NL;
3851 strcpy(connect_type, "(Loop)");
3852 break;
3853
3854 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003855 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003856 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857 ha->current_topology = ISP_CFG_FL;
3858 strcpy(connect_type, "(FL_Port)");
3859 break;
3860
3861 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003862 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 ha->operating_mode = P2P;
3864 ha->current_topology = ISP_CFG_N;
3865 strcpy(connect_type, "(N_Port-to-N_Port)");
3866 break;
3867
3868 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003869 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003870 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 ha->operating_mode = P2P;
3872 ha->current_topology = ISP_CFG_F;
3873 strcpy(connect_type, "(F_Port)");
3874 break;
3875
3876 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003877 ql_dbg(ql_dbg_disc, vha, 0x200f,
3878 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879 ha->current_topology = ISP_CFG_NL;
3880 strcpy(connect_type, "(Loop)");
3881 break;
3882 }
3883
3884 /* Save Host port and loop ID. */
3885 /* byte order - Big Endian */
Quinn Tran482c9dc2017-03-15 09:48:54 -07003886 id.b.domain = domain;
3887 id.b.area = area;
3888 id.b.al_pa = al_pa;
3889 id.b.rsvd_1 = 0;
3890 qlt_update_host_map(vha, id);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003891
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003892 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003893 ql_log(ql_log_info, vha, 0x2010,
3894 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003895 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 return(rval);
3898}
3899
Giridhar Malavalia9083012010-04-12 17:59:55 -07003900inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003901qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
3902 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003903{
3904 char *st, *en;
3905 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003906 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07003907 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003908 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003909
3910 if (memcmp(model, BINZERO, len) != 0) {
3911 strncpy(ha->model_number, model, len);
3912 st = en = ha->model_number;
3913 en += len - 1;
3914 while (en > st) {
3915 if (*en != 0x20 && *en != 0x00)
3916 break;
3917 *en-- = '\0';
3918 }
3919
3920 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07003921 if (use_tbl &&
3922 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003923 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003924 strncpy(ha->model_desc,
3925 qla2x00_model_name[index * 2 + 1],
3926 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003927 } else {
3928 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07003929 if (use_tbl &&
3930 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003931 index < QLA_MODEL_NAMES) {
3932 strcpy(ha->model_number,
3933 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003934 strncpy(ha->model_desc,
3935 qla2x00_model_name[index * 2 + 1],
3936 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003937 } else {
3938 strcpy(ha->model_number, def);
3939 }
3940 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003941 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003942 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003943 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003944}
3945
David Miller4e08df32007-04-16 12:37:43 -07003946/* On sparc systems, obtain port and node WWN from firmware
3947 * properties.
3948 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003949static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07003950{
3951#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003952 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003953 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003954 struct device_node *dp = pci_device_to_OF_node(pdev);
3955 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003956 int len;
3957
3958 val = of_get_property(dp, "port-wwn", &len);
3959 if (val && len >= WWN_SIZE)
3960 memcpy(nv->port_name, val, WWN_SIZE);
3961
3962 val = of_get_property(dp, "node-wwn", &len);
3963 if (val && len >= WWN_SIZE)
3964 memcpy(nv->node_name, val, WWN_SIZE);
3965#endif
3966}
3967
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968/*
3969* NVRAM configuration for ISP 2xxx
3970*
3971* Input:
3972* ha = adapter block pointer.
3973*
3974* Output:
3975* initialization control block in response_ring
3976* host adapters parameters in host adapter block
3977*
3978* Returns:
3979* 0 = success.
3980*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003981int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003982qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983{
David Miller4e08df32007-04-16 12:37:43 -07003984 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003985 uint8_t chksum = 0;
3986 uint16_t cnt;
3987 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003988 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003989 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003990 nvram_t *nv = ha->nvram;
3991 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003992 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993
David Miller4e08df32007-04-16 12:37:43 -07003994 rval = QLA_SUCCESS;
3995
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003997 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 ha->nvram_base = 0;
3999 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4000 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
4001 ha->nvram_base = 0x80;
4002
4003 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004004 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004005 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4006 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004008 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4009 "Contents of NVRAM.\n");
4010 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4011 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012
4013 /* Bad NVRAM data, set defaults parameters. */
4014 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
4015 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
4016 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004017 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04004018 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004019 "detected: checksum=0x%x id=%c version=0x%x.\n",
4020 chksum, nv->id[0], nv->nvram_version);
4021 ql_log(ql_log_warn, vha, 0x0065,
4022 "Falling back to "
4023 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07004024
4025 /*
4026 * Set default initialization control block.
4027 */
4028 memset(nv, 0, ha->nvram_size);
4029 nv->parameter_block_version = ICB_VERSION;
4030
4031 if (IS_QLA23XX(ha)) {
4032 nv->firmware_options[0] = BIT_2 | BIT_1;
4033 nv->firmware_options[1] = BIT_7 | BIT_5;
4034 nv->add_firmware_options[0] = BIT_5;
4035 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04004036 nv->frame_payload_size = 2048;
David Miller4e08df32007-04-16 12:37:43 -07004037 nv->special_options[1] = BIT_7;
4038 } else if (IS_QLA2200(ha)) {
4039 nv->firmware_options[0] = BIT_2 | BIT_1;
4040 nv->firmware_options[1] = BIT_7 | BIT_5;
4041 nv->add_firmware_options[0] = BIT_5;
4042 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04004043 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07004044 } else if (IS_QLA2100(ha)) {
4045 nv->firmware_options[0] = BIT_3 | BIT_1;
4046 nv->firmware_options[1] = BIT_5;
Joe Carnuccio98aee702014-09-25 05:16:38 -04004047 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07004048 }
4049
Bart Van Asschead950362015-07-09 07:24:08 -07004050 nv->max_iocb_allocation = cpu_to_le16(256);
4051 nv->execution_throttle = cpu_to_le16(16);
David Miller4e08df32007-04-16 12:37:43 -07004052 nv->retry_count = 8;
4053 nv->retry_delay = 1;
4054
4055 nv->port_name[0] = 33;
4056 nv->port_name[3] = 224;
4057 nv->port_name[4] = 139;
4058
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004059 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004060
4061 nv->login_timeout = 4;
4062
4063 /*
4064 * Set default host adapter parameters
4065 */
4066 nv->host_p[1] = BIT_2;
4067 nv->reset_delay = 5;
4068 nv->port_down_retry_count = 8;
Bart Van Asschead950362015-07-09 07:24:08 -07004069 nv->max_luns_per_target = cpu_to_le16(8);
David Miller4e08df32007-04-16 12:37:43 -07004070 nv->link_down_timeout = 60;
4071
4072 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 }
4074
4075#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4076 /*
4077 * The SN2 does not provide BIOS emulation which means you can't change
4078 * potentially bogus BIOS settings. Force the use of default settings
4079 * for link rate and frame size. Hope that the rest of the settings
4080 * are valid.
4081 */
4082 if (ia64_platform_is("sn2")) {
Joe Carnuccio98aee702014-09-25 05:16:38 -04004083 nv->frame_payload_size = 2048;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 if (IS_QLA23XX(ha))
4085 nv->special_options[1] = BIT_7;
4086 }
4087#endif
4088
4089 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004090 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091
4092 /*
4093 * Setup driver NVRAM options.
4094 */
4095 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4096 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4097 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4098 nv->firmware_options[1] &= ~BIT_4;
4099
4100 if (IS_QLA23XX(ha)) {
4101 nv->firmware_options[0] |= BIT_2;
4102 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004103 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004104 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105
4106 if (IS_QLA2300(ha)) {
4107 if (ha->fb_rev == FPM_2310) {
4108 strcpy(ha->model_number, "QLA2310");
4109 } else {
4110 strcpy(ha->model_number, "QLA2300");
4111 }
4112 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004113 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004114 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115 }
4116 } else if (IS_QLA2200(ha)) {
4117 nv->firmware_options[0] |= BIT_2;
4118 /*
4119 * 'Point-to-point preferred, else loop' is not a safe
4120 * connection mode setting.
4121 */
4122 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4123 (BIT_5 | BIT_4)) {
4124 /* Force 'loop preferred, else point-to-point'. */
4125 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4126 nv->add_firmware_options[0] |= BIT_5;
4127 }
4128 strcpy(ha->model_number, "QLA22xx");
4129 } else /*if (IS_QLA2100(ha))*/ {
4130 strcpy(ha->model_number, "QLA2100");
4131 }
4132
4133 /*
4134 * Copy over NVRAM RISC parameter block to initialization control block.
4135 */
4136 dptr1 = (uint8_t *)icb;
4137 dptr2 = (uint8_t *)&nv->parameter_block_version;
4138 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4139 while (cnt--)
4140 *dptr1++ = *dptr2++;
4141
4142 /* Copy 2nd half. */
4143 dptr1 = (uint8_t *)icb->add_firmware_options;
4144 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4145 while (cnt--)
4146 *dptr1++ = *dptr2++;
4147
Andrew Vasquez5341e862006-05-17 15:09:16 -07004148 /* Use alternate WWN? */
4149 if (nv->host_p[1] & BIT_7) {
4150 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4151 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4152 }
4153
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154 /* Prepare nodename */
4155 if ((icb->firmware_options[1] & BIT_6) == 0) {
4156 /*
4157 * Firmware will apply the following mask if the nodename was
4158 * not provided.
4159 */
4160 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4161 icb->node_name[0] &= 0xF0;
4162 }
4163
4164 /*
4165 * Set host adapter parameters.
4166 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07004167
4168 /*
4169 * BIT_7 in the host-parameters section allows for modification to
4170 * internal driver logging.
4171 */
Andrew Vasquez01819442006-06-23 16:11:10 -07004172 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08004173 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4175 /* Always load RISC code on non ISP2[12]00 chips. */
4176 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4177 ha->flags.disable_risc_code_load = 0;
4178 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4179 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4180 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07004181 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004182 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183
4184 ha->operating_mode =
4185 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4186
4187 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4188 sizeof(ha->fw_seriallink_options));
4189
4190 /* save HBA serial number */
4191 ha->serial0 = icb->port_name[5];
4192 ha->serial1 = icb->port_name[6];
4193 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004194 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4195 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196
Bart Van Asschead950362015-07-09 07:24:08 -07004197 icb->execution_throttle = cpu_to_le16(0xFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198
4199 ha->retry_count = nv->retry_count;
4200
4201 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07004202 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203 nv->login_timeout = ql2xlogintimeout;
4204 if (nv->login_timeout < 4)
4205 nv->login_timeout = 4;
4206 ha->login_timeout = nv->login_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004208 /* Set minimum RATOV to 100 tenths of a second. */
4209 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211 ha->loop_reset_delay = nv->reset_delay;
4212
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 /* Link Down Timeout = 0:
4214 *
4215 * When Port Down timer expires we will start returning
4216 * I/O's to OS with "DID_NO_CONNECT".
4217 *
4218 * Link Down Timeout != 0:
4219 *
4220 * The driver waits for the link to come up after link down
4221 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004222 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223 if (nv->link_down_timeout == 0) {
4224 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004225 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226 } else {
4227 ha->link_down_timeout = nv->link_down_timeout;
4228 ha->loop_down_abort_time =
4229 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232 /*
4233 * Need enough time to try and get the port back.
4234 */
4235 ha->port_down_retry_count = nv->port_down_retry_count;
4236 if (qlport_down_retry)
4237 ha->port_down_retry_count = qlport_down_retry;
4238 /* Set login_retry_count */
4239 ha->login_retry_count = nv->retry_count;
4240 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4241 ha->port_down_retry_count > 3)
4242 ha->login_retry_count = ha->port_down_retry_count;
4243 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4244 ha->login_retry_count = ha->port_down_retry_count;
4245 if (ql2xloginretrycount)
4246 ha->login_retry_count = ql2xloginretrycount;
4247
Bart Van Asschead950362015-07-09 07:24:08 -07004248 icb->lun_enables = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249 icb->command_resource_count = 0;
4250 icb->immediate_notify_resource_count = 0;
Bart Van Asschead950362015-07-09 07:24:08 -07004251 icb->timeout = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252
4253 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4254 /* Enable RIO */
4255 icb->firmware_options[0] &= ~BIT_3;
4256 icb->add_firmware_options[0] &=
4257 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4258 icb->add_firmware_options[0] |= BIT_2;
4259 icb->response_accumulation_timer = 3;
4260 icb->interrupt_delay_timer = 5;
4261
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004262 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004264 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004265 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004266 ha->zio_mode = icb->add_firmware_options[0] &
4267 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4268 ha->zio_timer = icb->interrupt_delay_timer ?
4269 icb->interrupt_delay_timer: 2;
4270 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271 icb->add_firmware_options[0] &=
4272 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004273 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004274 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004275 ha->zio_mode = QLA_ZIO_MODE_6;
4276
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004277 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004278 "ZIO mode %d enabled; timer delay (%d us).\n",
4279 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004280
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004281 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4282 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004283 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004284 }
4285 }
4286
David Miller4e08df32007-04-16 12:37:43 -07004287 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004288 ql_log(ql_log_warn, vha, 0x0069,
4289 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07004290 }
4291 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292}
4293
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004294static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004295qla2x00_rport_del(void *data)
4296{
4297 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004298 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004299 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004300
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004301 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004302 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004303 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004304 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004305 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004306 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4307 "%s %8phN. rport %p roles %x\n",
4308 __func__, fcport->port_name, rport,
4309 rport->roles);
Quinn Tran726b8542017-01-19 22:28:00 -08004310
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004311 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08004312 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004313}
4314
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315/**
4316 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4317 * @ha: HA context
4318 * @flags: allocation flags
4319 *
4320 * Returns a pointer to the allocated fcport, or NULL, if none available.
4321 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004322fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004323qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324{
4325 fc_port_t *fcport;
4326
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004327 fcport = kzalloc(sizeof(fc_port_t), flags);
4328 if (!fcport)
4329 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004330
4331 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004332 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004333 fcport->port_type = FCT_UNKNOWN;
4334 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07004335 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004336 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337
Quinn Tran726b8542017-01-19 22:28:00 -08004338 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4339 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
Quinn Tran6cb32162017-02-13 12:18:29 -08004340 flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004341 fcport->disc_state = DSC_DELETED;
4342 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4343 fcport->deleted = QLA_SESS_DELETED;
4344 fcport->login_retry = vha->hw->login_retry_count;
4345 fcport->login_retry = 5;
4346 fcport->logout_on_delete = 1;
4347
4348 if (!fcport->ct_desc.ct_sns) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004349 ql_log(ql_log_warn, vha, 0xd049,
Quinn Tran726b8542017-01-19 22:28:00 -08004350 "Failed to allocate ct_sns request.\n");
4351 kfree(fcport);
4352 fcport = NULL;
4353 }
4354 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4355 INIT_LIST_HEAD(&fcport->gnl_entry);
4356 INIT_LIST_HEAD(&fcport->list);
4357
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004358 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359}
4360
Quinn Tran726b8542017-01-19 22:28:00 -08004361void
4362qla2x00_free_fcport(fc_port_t *fcport)
4363{
4364 if (fcport->ct_desc.ct_sns) {
4365 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4366 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4367 fcport->ct_desc.ct_sns_dma);
4368
4369 fcport->ct_desc.ct_sns = NULL;
4370 }
4371 kfree(fcport);
4372}
4373
Linus Torvalds1da177e2005-04-16 15:20:36 -07004374/*
4375 * qla2x00_configure_loop
4376 * Updates Fibre Channel Device Database with what is actually on loop.
4377 *
4378 * Input:
4379 * ha = adapter block pointer.
4380 *
4381 * Returns:
4382 * 0 = success.
4383 * 1 = error.
4384 * 2 = database was full and device was not configured.
4385 */
4386static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004387qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388{
4389 int rval;
4390 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004391 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392 rval = QLA_SUCCESS;
4393
4394 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004395 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4396 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004398 ql_dbg(ql_dbg_disc, vha, 0x2013,
4399 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004400 return (rval);
4401 }
4402 }
4403
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004404 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004405 ql_dbg(ql_dbg_disc, vha, 0x2014,
4406 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004407
4408 /*
4409 * If we have both an RSCN and PORT UPDATE pending then handle them
4410 * both at the same time.
4411 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004412 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4413 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414
Michael Hernandez3064ff32009-12-15 21:29:44 -08004415 qla2x00_get_data_rate(vha);
4416
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417 /* Determine what we need to do */
4418 if (ha->current_topology == ISP_CFG_FL &&
4419 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4420
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421 set_bit(RSCN_UPDATE, &flags);
4422
4423 } else if (ha->current_topology == ISP_CFG_F &&
4424 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4425
Linus Torvalds1da177e2005-04-16 15:20:36 -07004426 set_bit(RSCN_UPDATE, &flags);
4427 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4428
Andrew Vasquez21333b42006-05-17 15:09:56 -07004429 } else if (ha->current_topology == ISP_CFG_N) {
4430 clear_bit(RSCN_UPDATE, &flags);
Quinn Tran41dc5292017-01-19 22:28:03 -08004431 } else if (ha->current_topology == ISP_CFG_NL) {
4432 clear_bit(RSCN_UPDATE, &flags);
4433 set_bit(LOCAL_LOOP_UPDATE, &flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004434 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004436 set_bit(RSCN_UPDATE, &flags);
4437 set_bit(LOCAL_LOOP_UPDATE, &flags);
4438 }
4439
4440 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004441 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4442 ql_dbg(ql_dbg_disc, vha, 0x2015,
4443 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004444 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08004445 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004446 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004447 }
4448
4449 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004450 if (LOOP_TRANSITION(vha)) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004451 ql_dbg(ql_dbg_disc, vha, 0x2099,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004452 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004454 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004455 else
4456 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004457 }
4458
4459 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004460 if (atomic_read(&vha->loop_down_timer) ||
4461 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462 rval = QLA_FUNCTION_FAILED;
4463 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004464 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004465 ql_dbg(ql_dbg_disc, vha, 0x2069,
4466 "LOOP READY.\n");
Quinn Tranec7193e2017-03-15 09:48:55 -07004467 ha->flags.fw_init_done = 1;
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05004468
4469 /*
4470 * Process any ATIO queue entries that came in
4471 * while we weren't online.
4472 */
Quinn Tranead03852017-01-19 22:28:01 -08004473 if (qla_tgt_mode_enabled(vha) ||
4474 qla_dual_mode_enabled(vha)) {
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05004475 if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) {
4476 spin_lock_irqsave(&ha->tgt.atio_lock,
4477 flags);
4478 qlt_24xx_process_atio_queue(vha, 0);
4479 spin_unlock_irqrestore(
4480 &ha->tgt.atio_lock, flags);
4481 } else {
4482 spin_lock_irqsave(&ha->hardware_lock,
4483 flags);
4484 qlt_24xx_process_atio_queue(vha, 1);
4485 spin_unlock_irqrestore(
4486 &ha->hardware_lock, flags);
4487 }
4488 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489 }
4490 }
4491
4492 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004493 ql_dbg(ql_dbg_disc, vha, 0x206a,
4494 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004496 ql_dbg(ql_dbg_disc, vha, 0x206b,
4497 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004498 }
4499
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07004500 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004501 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004503 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004504 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004505 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507 }
4508
4509 return (rval);
4510}
4511
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004512/*
4513 * N2N Login
4514 * Updates Fibre Channel Device Database with local loop devices.
4515 *
4516 * Input:
4517 * ha = adapter block pointer.
4518 *
4519 * Returns:
4520 */
4521static int qla24xx_n2n_handle_login(struct scsi_qla_host *vha,
4522 fc_port_t *fcport)
4523{
4524 struct qla_hw_data *ha = vha->hw;
4525 int res = QLA_SUCCESS, rval;
4526 int greater_wwpn = 0;
4527 int logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004529 if (ha->current_topology != ISP_CFG_N)
4530 return res;
4531
4532 if (wwn_to_u64(vha->port_name) >
4533 wwn_to_u64(vha->n2n_port_name)) {
4534 ql_dbg(ql_dbg_disc, vha, 0x2002,
4535 "HBA WWPN is greater %llx > target %llx\n",
4536 wwn_to_u64(vha->port_name),
4537 wwn_to_u64(vha->n2n_port_name));
4538 greater_wwpn = 1;
4539 fcport->d_id.b24 = vha->n2n_id;
4540 }
4541
4542 fcport->loop_id = vha->loop_id;
4543 fcport->fc4f_nvme = 0;
4544 fcport->query = 1;
4545
4546 ql_dbg(ql_dbg_disc, vha, 0x4001,
4547 "Initiate N2N login handler: HBA port_id=%06x loopid=%d\n",
4548 fcport->d_id.b24, vha->loop_id);
4549
4550 /* Fill in member data. */
4551 if (!greater_wwpn) {
4552 rval = qla2x00_get_port_database(vha, fcport, 0);
4553 ql_dbg(ql_dbg_disc, vha, 0x1051,
4554 "Remote login-state (%x/%x) port_id=%06x loop_id=%x, rval=%d\n",
4555 fcport->current_login_state, fcport->last_login_state,
4556 fcport->d_id.b24, fcport->loop_id, rval);
4557
4558 if (((fcport->current_login_state & 0xf) == 0x4) ||
4559 ((fcport->current_login_state & 0xf) == 0x6))
4560 logged_in = 1;
4561 }
4562
4563 if (logged_in || greater_wwpn) {
4564 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
4565 qla_nvme_register_hba(vha);
4566
4567 /* Set connected N_Port d_id */
4568 if (vha->flags.nvme_enabled)
4569 fcport->fc4f_nvme = 1;
4570
4571 fcport->scan_state = QLA_FCPORT_FOUND;
4572 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4573 fcport->disc_state = DSC_GNL;
4574 fcport->n2n_flag = 1;
4575 fcport->flags = 3;
4576 vha->hw->flags.gpsc_supported = 0;
4577
4578 if (greater_wwpn) {
4579 ql_dbg(ql_dbg_disc, vha, 0x20e5,
4580 "%s %d PLOGI ELS %8phC\n",
4581 __func__, __LINE__, fcport->port_name);
4582
4583 res = qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
4584 fcport, fcport->d_id);
4585 }
4586
4587 if (res != QLA_SUCCESS) {
4588 ql_log(ql_log_info, vha, 0xd04d,
4589 "PLOGI Failed: portid=%06x - retrying\n",
4590 fcport->d_id.b24);
4591 res = QLA_SUCCESS;
4592 } else {
4593 /* State 0x6 means FCP PRLI complete */
4594 if ((fcport->current_login_state & 0xf) == 0x6) {
4595 ql_dbg(ql_dbg_disc, vha, 0x2118,
4596 "%s %d %8phC post GPDB work\n",
4597 __func__, __LINE__, fcport->port_name);
4598 fcport->chip_reset =
4599 vha->hw->base_qpair->chip_reset;
4600 qla24xx_post_gpdb_work(vha, fcport, 0);
4601 } else {
4602 ql_dbg(ql_dbg_disc, vha, 0x2118,
4603 "%s %d %8phC post NVMe PRLI\n",
4604 __func__, __LINE__, fcport->port_name);
4605 qla24xx_post_prli_work(vha, fcport);
4606 }
4607 }
4608 } else {
4609 /* Wait for next database change */
4610 set_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags);
4611 }
4612
4613 return res;
4614}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004615
4616/*
4617 * qla2x00_configure_local_loop
4618 * Updates Fibre Channel Device Database with local loop devices.
4619 *
4620 * Input:
4621 * ha = adapter block pointer.
4622 *
4623 * Returns:
4624 * 0 = success.
4625 */
4626static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004627qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628{
4629 int rval, rval2;
4630 int found_devs;
4631 int found;
4632 fc_port_t *fcport, *new_fcport;
4633
4634 uint16_t index;
4635 uint16_t entries;
4636 char *id_iter;
4637 uint16_t loop_id;
4638 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004639 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08004640 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641
4642 found_devs = 0;
4643 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08004644 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08004647 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004648 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649 &entries);
4650 if (rval != QLA_SUCCESS)
4651 goto cleanup_allocation;
4652
Quinn Tran83548fe2017-06-02 09:12:01 -07004653 ql_dbg(ql_dbg_disc, vha, 0x2011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004654 "Entries in ID list (%d).\n", entries);
4655 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
4656 (uint8_t *)ha->gid_list,
4657 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658
4659 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004660 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004661 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004662 ql_log(ql_log_warn, vha, 0x2012,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004663 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004664 rval = QLA_MEMORY_ALLOC_FAILED;
4665 goto cleanup_allocation;
4666 }
4667 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4668
4669 /*
4670 * Mark local devices that were present with FCF_DEVICE_LOST for now.
4671 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004672 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004673 if (atomic_read(&fcport->state) == FCS_ONLINE &&
4674 fcport->port_type != FCT_BROADCAST &&
4675 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
4676
Quinn Tran83548fe2017-06-02 09:12:01 -07004677 ql_dbg(ql_dbg_disc, vha, 0x2096,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004678 "Marking port lost loop_id=0x%04x.\n",
4679 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004680
Quinn Tran41dc5292017-01-19 22:28:03 -08004681 qla2x00_mark_device_lost(vha, fcport, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682 }
4683 }
4684
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004685 /* Inititae N2N login. */
4686 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
4687 rval = qla24xx_n2n_handle_login(vha, new_fcport);
4688 if (rval != QLA_SUCCESS)
4689 goto cleanup_allocation;
4690 return QLA_SUCCESS;
4691 }
4692
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693 /* Add devices to port list. */
4694 id_iter = (char *)ha->gid_list;
4695 for (index = 0; index < entries; index++) {
4696 domain = ((struct gid_list_info *)id_iter)->domain;
4697 area = ((struct gid_list_info *)id_iter)->area;
4698 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004699 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004700 loop_id = (uint16_t)
4701 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004702 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703 loop_id = le16_to_cpu(
4704 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004705 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706
4707 /* Bypass reserved domain fields. */
4708 if ((domain & 0xf0) == 0xf0)
4709 continue;
4710
4711 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004712 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004713 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004714 continue;
4715
4716 /* Bypass invalid local loop ID. */
4717 if (loop_id > LAST_LOCAL_LOOP_ID)
4718 continue;
4719
Quinn Tran41dc5292017-01-19 22:28:03 -08004720 memset(new_fcport->port_name, 0, WWN_SIZE);
Arun Easi370d5502012-08-22 14:21:10 -04004721
Linus Torvalds1da177e2005-04-16 15:20:36 -07004722 /* Fill in member data. */
4723 new_fcport->d_id.b.domain = domain;
4724 new_fcport->d_id.b.area = area;
4725 new_fcport->d_id.b.al_pa = al_pa;
4726 new_fcport->loop_id = loop_id;
Quinn Tran41dc5292017-01-19 22:28:03 -08004727
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004728 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004729 if (rval2 != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004730 ql_dbg(ql_dbg_disc, vha, 0x2097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004731 "Failed to retrieve fcport information "
4732 "-- get_port_database=%x, loop_id=0x%04x.\n",
4733 rval2, new_fcport->loop_id);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004734 /* Skip retry if N2N */
4735 if (ha->current_topology != ISP_CFG_N) {
4736 ql_dbg(ql_dbg_disc, vha, 0x2105,
4737 "Scheduling resync.\n");
4738 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4739 continue;
4740 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741 }
4742
Quinn Tran41dc5292017-01-19 22:28:03 -08004743 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744 /* Check for matching device in port list. */
4745 found = 0;
4746 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004747 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004748 if (memcmp(new_fcport->port_name, fcport->port_name,
4749 WWN_SIZE))
4750 continue;
4751
Shyam Sundarddb9b122009-03-24 09:08:10 -07004752 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004753 fcport->loop_id = new_fcport->loop_id;
4754 fcport->port_type = new_fcport->port_type;
4755 fcport->d_id.b24 = new_fcport->d_id.b24;
4756 memcpy(fcport->node_name, new_fcport->node_name,
4757 WWN_SIZE);
4758
Quinn Tran41dc5292017-01-19 22:28:03 -08004759 if (!fcport->login_succ) {
4760 vha->fcport_count++;
4761 fcport->login_succ = 1;
4762 fcport->disc_state = DSC_LOGIN_COMPLETE;
4763 }
4764
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765 found++;
4766 break;
4767 }
4768
4769 if (!found) {
4770 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004771 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772
4773 /* Allocate a new replacement fcport. */
4774 fcport = new_fcport;
Quinn Tran41dc5292017-01-19 22:28:03 -08004775 if (!fcport->login_succ) {
4776 vha->fcport_count++;
4777 fcport->login_succ = 1;
4778 fcport->disc_state = DSC_LOGIN_COMPLETE;
4779 }
4780
4781 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4782
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004783 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Quinn Tran41dc5292017-01-19 22:28:03 -08004784
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004786 ql_log(ql_log_warn, vha, 0xd031,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004787 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788 rval = QLA_MEMORY_ALLOC_FAILED;
4789 goto cleanup_allocation;
4790 }
Quinn Tran41dc5292017-01-19 22:28:03 -08004791 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4793 }
4794
Quinn Tran41dc5292017-01-19 22:28:03 -08004795 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4796
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004797 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004798 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004799
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004800 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801
4802 found_devs++;
4803 }
4804
4805cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08004806 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807
4808 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004809 ql_dbg(ql_dbg_disc, vha, 0x2098,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004810 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811 }
4812
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813 return (rval);
4814}
4815
4816static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004817qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004818{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004819 int rval;
Quinn Tran93f2bd62014-09-25 05:16:53 -04004820 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004821 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004822
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07004823 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004824 return;
4825
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07004826 if (atomic_read(&fcport->state) != FCS_ONLINE)
4827 return;
4828
Andrew Vasquez39bd9622007-09-20 14:07:34 -07004829 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
4830 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004831 return;
4832
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004833 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004834 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004835 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004836 ql_dbg(ql_dbg_disc, vha, 0x2004,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004837 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
4838 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004839 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004840 ql_dbg(ql_dbg_disc, vha, 0x2005,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004841 "iIDMA adjusted to %s GB/s on %8phN.\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -05004842 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004843 fcport->port_name);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004844 }
4845}
4846
Quinn Tran726b8542017-01-19 22:28:00 -08004847/* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
Adrian Bunk23be3312006-11-24 02:46:01 +01004848static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004849qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05004850{
4851 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05004852 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004853 unsigned long flags;
8482e1182005-04-17 15:04:54 -05004854
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07004855 rport_ids.node_name = wwn_to_u64(fcport->node_name);
4856 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05004857 rport_ids.port_id = fcport->d_id.b.domain << 16 |
4858 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
4859 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004860 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07004861 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004862 ql_log(ql_log_warn, vha, 0x2006,
4863 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07004864 return;
4865 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004866
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004867 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004868 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004869 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004870
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004871 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07004872
4873 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05004874 if (fcport->port_type == FCT_INITIATOR)
4875 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
4876 if (fcport->port_type == FCT_TARGET)
4877 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Quinn Tran726b8542017-01-19 22:28:00 -08004878
Quinn Tran83548fe2017-06-02 09:12:01 -07004879 ql_dbg(ql_dbg_disc, vha, 0x20ee,
4880 "%s %8phN. rport %p is %s mode\n",
4881 __func__, fcport->port_name, rport,
4882 (fcport->port_type == FCT_TARGET) ? "tgt" : "ini");
Quinn Tran726b8542017-01-19 22:28:00 -08004883
Andrew Vasquez77d74142005-07-08 18:00:36 -07004884 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05004885}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886
4887/*
Adrian Bunk23be3312006-11-24 02:46:01 +01004888 * qla2x00_update_fcport
4889 * Updates device on list.
4890 *
4891 * Input:
4892 * ha = adapter block pointer.
4893 * fcport = port structure pointer.
4894 *
4895 * Return:
4896 * 0 - Success
4897 * BIT_0 - error
4898 *
4899 * Context:
4900 * Kernel context.
4901 */
4902void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004903qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01004904{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004905 fcport->vha = vha;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004906
Quinn Tran726b8542017-01-19 22:28:00 -08004907 if (IS_SW_RESV_ADDR(fcport->d_id))
4908 return;
4909
Quinn Tran83548fe2017-06-02 09:12:01 -07004910 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
Quinn Tran726b8542017-01-19 22:28:00 -08004911 __func__, fcport->port_name);
4912
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004913 if (IS_QLAFX00(vha->hw)) {
4914 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004915 goto reg_port;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004916 }
Adrian Bunk23be3312006-11-24 02:46:01 +01004917 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004918 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Quinn Tran726b8542017-01-19 22:28:00 -08004919 fcport->disc_state = DSC_LOGIN_COMPLETE;
4920 fcport->deleted = 0;
4921 fcport->logout_on_delete = 1;
Adrian Bunk23be3312006-11-24 02:46:01 +01004922
Duane Grigsbye84067d2017-06-21 13:48:43 -07004923 if (fcport->fc4f_nvme) {
4924 qla_nvme_register_remote(vha, fcport);
4925 return;
4926 }
4927
Joe Carnuccio1f93da522012-11-21 02:40:38 -05004928 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004929 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08004930 qla24xx_update_fcport_fcp_prio(vha, fcport);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004931
4932reg_port:
Quinn Tran726b8542017-01-19 22:28:00 -08004933 switch (vha->host->active_mode) {
4934 case MODE_INITIATOR:
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004935 qla2x00_reg_remote_port(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08004936 break;
4937 case MODE_TARGET:
4938 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
4939 !vha->vha_tgt.qla_tgt->tgt_stopped)
4940 qlt_fc_port_added(vha, fcport);
4941 break;
4942 case MODE_DUAL:
4943 qla2x00_reg_remote_port(vha, fcport);
4944 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
4945 !vha->vha_tgt.qla_tgt->tgt_stopped)
4946 qlt_fc_port_added(vha, fcport);
4947 break;
4948 default:
4949 break;
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004950 }
Adrian Bunk23be3312006-11-24 02:46:01 +01004951}
4952
4953/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 * qla2x00_configure_fabric
4955 * Setup SNS devices with loop ID's.
4956 *
4957 * Input:
4958 * ha = adapter block pointer.
4959 *
4960 * Returns:
4961 * 0 = success.
4962 * BIT_0 = error
4963 */
4964static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004965qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004966{
Arun Easib3b02e62012-02-09 11:15:39 -08004967 int rval;
Quinn Tran726b8542017-01-19 22:28:00 -08004968 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004969 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004970 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004972 struct qla_hw_data *ha = vha->hw;
Alexei Potashnikdf673272015-07-14 16:00:46 -04004973 int discovery_gen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004974
4975 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07004976 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004977 loop_id = NPH_F_PORT;
4978 else
4979 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004980 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004981 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004982 ql_dbg(ql_dbg_disc, vha, 0x20a0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004983 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004984
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004985 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004986 return (QLA_SUCCESS);
4987 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004988 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989
Quinn Tran41dc5292017-01-19 22:28:03 -08004990
4991 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
4992 rval = qla2x00_send_change_request(vha, 0x3, 0);
4993 if (rval != QLA_SUCCESS)
4994 ql_log(ql_log_warn, vha, 0x121,
4995 "Failed to enable receiving of RSCN requests: 0x%x.\n",
4996 rval);
4997 }
4998
4999
Linus Torvalds1da177e2005-04-16 15:20:36 -07005000 do {
Quinn Tran726b8542017-01-19 22:28:00 -08005001 qla2x00_mgmt_svr_login(vha);
5002
Andrew Vasquezcca53352005-08-26 19:08:30 -07005003 /* FDMI support. */
5004 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005005 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5006 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07005007
Linus Torvalds1da177e2005-04-16 15:20:36 -07005008 /* Ensure we are logged into the SNS. */
Joe Carnuccioa14c7712017-08-23 15:05:12 -07005009 loop_id = NPH_SNS_LID(ha);
Chad Dupuis0b91d112012-02-09 11:15:42 -08005010 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5011 0xfc, mb, BIT_1|BIT_0);
Joe Carnuccioa14c7712017-08-23 15:05:12 -07005012 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5013 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5014 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5015 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
Chad Dupuis0b91d112012-02-09 11:15:42 -08005016 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05005017 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08005018 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005019 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5020 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005021 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07005022 ql_dbg(ql_dbg_disc, vha, 0x20a2,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005023 "Register FC-4 TYPE failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005024 if (test_bit(LOOP_RESYNC_NEEDED,
5025 &vha->dpc_flags))
5026 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005027 }
Duane Grigsbyd3bae932017-06-21 13:48:44 -07005028 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07005030 ql_dbg(ql_dbg_disc, vha, 0x209a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005031 "Register FC-4 Features failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005032 if (test_bit(LOOP_RESYNC_NEEDED,
5033 &vha->dpc_flags))
5034 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035 }
Duane Grigsbyd3bae932017-06-21 13:48:44 -07005036 if (vha->flags.nvme_enabled) {
5037 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5038 ql_dbg(ql_dbg_disc, vha, 0x2049,
5039 "Register NVME FC Type Features failed.\n");
5040 }
5041 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005042 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005043 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07005044 ql_dbg(ql_dbg_disc, vha, 0x2104,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005045 "Register Node Name failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005046 if (test_bit(LOOP_RESYNC_NEEDED,
5047 &vha->dpc_flags))
5048 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005049 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07005051 ql_dbg(ql_dbg_disc, vha, 0x209b,
Colin Ian King0bf0efa2017-06-30 14:47:41 +01005052 "Register Symbolic Node Name failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005053 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5054 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005055 }
5056 }
5057
Joe Carnuccio827210b2013-02-08 01:57:57 -05005058 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5059 fcport->scan_state = QLA_FCPORT_SCAN;
5060 }
5061
Alexei Potashnikdf673272015-07-14 16:00:46 -04005062 /* Mark the time right before querying FW for connected ports.
5063 * This process is long, asynchronous and by the time it's done,
5064 * collected information might not be accurate anymore. E.g.
5065 * disconnected port might have re-connected and a brand new
5066 * session has been created. In this case session's generation
5067 * will be newer than discovery_gen. */
5068 qlt_do_generation_tick(vha, &discovery_gen);
5069
Quinn Tran726b8542017-01-19 22:28:00 -08005070 rval = qla2x00_find_all_fabric_devs(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071 if (rval != QLA_SUCCESS)
5072 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073 } while (0);
5074
Duane Grigsbye84067d2017-06-21 13:48:43 -07005075 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5076 qla_nvme_register_hba(vha);
5077
Quinn Tran726b8542017-01-19 22:28:00 -08005078 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005079 ql_dbg(ql_dbg_disc, vha, 0x2068,
5080 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081
5082 return (rval);
5083}
5084
Linus Torvalds1da177e2005-04-16 15:20:36 -07005085/*
5086 * qla2x00_find_all_fabric_devs
5087 *
5088 * Input:
5089 * ha = adapter block pointer.
5090 * dev = database device entry pointer.
5091 *
5092 * Returns:
5093 * 0 = success.
5094 *
5095 * Context:
5096 * Kernel context.
5097 */
5098static int
Quinn Tran726b8542017-01-19 22:28:00 -08005099qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005100{
5101 int rval;
5102 uint16_t loop_id;
Quinn Tran726b8542017-01-19 22:28:00 -08005103 fc_port_t *fcport, *new_fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104 int found;
5105
5106 sw_info_t *swl;
5107 int swl_idx;
5108 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07005109 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005110 struct qla_hw_data *ha = vha->hw;
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05005111 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran726b8542017-01-19 22:28:00 -08005112 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113
5114 rval = QLA_SUCCESS;
5115
5116 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08005117 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08005118 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08005119 GFP_KERNEL);
5120 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02005121 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005122 /*EMPTY*/
Quinn Tran83548fe2017-06-02 09:12:01 -07005123 ql_dbg(ql_dbg_disc, vha, 0x209c,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005124 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005125 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08005126 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005127 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005129 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5130 return rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005131 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005133 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5134 return rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005135 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005137 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5138 return rval;
Quinn Tran726b8542017-01-19 22:28:00 -08005139 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5140 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005141 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5142 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005144
5145 /* If other queries succeeded probe for FC-4 type */
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005146 if (swl) {
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005147 qla2x00_gff_id(vha, swl);
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005148 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5149 return rval;
5150 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005151 }
5152 swl_idx = 0;
5153
5154 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005155 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005156 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005157 ql_log(ql_log_warn, vha, 0x209d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005158 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005159 return (QLA_MEMORY_ALLOC_FAILED);
5160 }
5161 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162 /* Set start port ID scan at adapter ID. */
5163 first_dev = 1;
5164 last_dev = 0;
5165
5166 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005167 loop_id = ha->min_external_loopid;
5168 for (; loop_id <= ha->max_loop_id; loop_id++) {
5169 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170 continue;
5171
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07005172 if (ha->current_topology == ISP_CFG_FL &&
5173 (atomic_read(&vha->loop_down_timer) ||
5174 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08005175 atomic_set(&vha->loop_down_timer, 0);
5176 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5177 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005178 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08005179 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005180
5181 if (swl != NULL) {
5182 if (last_dev) {
5183 wrap.b24 = new_fcport->d_id.b24;
5184 } else {
5185 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5186 memcpy(new_fcport->node_name,
5187 swl[swl_idx].node_name, WWN_SIZE);
5188 memcpy(new_fcport->port_name,
5189 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005190 memcpy(new_fcport->fabric_port_name,
5191 swl[swl_idx].fabric_port_name, WWN_SIZE);
5192 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005193 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005194
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005195 new_fcport->nvme_flag = 0;
Darren Trap1a28faa2017-08-30 10:16:48 -07005196 new_fcport->fc4f_nvme = 0;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005197 if (vha->flags.nvme_enabled &&
5198 swl[swl_idx].fc4f_nvme) {
5199 new_fcport->fc4f_nvme =
5200 swl[swl_idx].fc4f_nvme;
5201 ql_log(ql_log_info, vha, 0x2131,
5202 "FOUND: NVME port %8phC as FC Type 28h\n",
5203 new_fcport->port_name);
5204 }
5205
Linus Torvalds1da177e2005-04-16 15:20:36 -07005206 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5207 last_dev = 1;
5208 }
5209 swl_idx++;
5210 }
5211 } else {
5212 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005213 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005215 ql_log(ql_log_warn, vha, 0x209e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005216 "SNS scan failed -- assuming "
5217 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218 rval = QLA_SUCCESS;
5219 break;
5220 }
5221 }
5222
5223 /* If wrap on switch device list, exit. */
5224 if (first_dev) {
5225 wrap.b24 = new_fcport->d_id.b24;
5226 first_dev = 0;
5227 } else if (new_fcport->d_id.b24 == wrap.b24) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005228 ql_dbg(ql_dbg_disc, vha, 0x209f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005229 "Device wrap (%02x%02x%02x).\n",
5230 new_fcport->d_id.b.domain,
5231 new_fcport->d_id.b.area,
5232 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005233 break;
5234 }
5235
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005236 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005237 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238 continue;
5239
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005240 /* Bypass virtual ports of the same host. */
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05005241 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5242 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005243
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07005244 /* Bypass if same domain and area of adapter. */
5245 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005246 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07005247 ISP_CFG_FL)
5248 continue;
5249
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250 /* Bypass reserved domain fields. */
5251 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5252 continue;
5253
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005254 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07005255 if (ql2xgffidenable &&
5256 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5257 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005258 continue;
5259
Quinn Tran726b8542017-01-19 22:28:00 -08005260 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5261
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262 /* Locate matching device in database. */
5263 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005264 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005265 if (memcmp(new_fcport->port_name, fcport->port_name,
5266 WWN_SIZE))
5267 continue;
5268
Joe Carnuccio827210b2013-02-08 01:57:57 -05005269 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08005270
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271 found++;
5272
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005273 /* Update port state. */
5274 memcpy(fcport->fabric_port_name,
5275 new_fcport->fabric_port_name, WWN_SIZE);
5276 fcport->fp_speed = new_fcport->fp_speed;
5277
Linus Torvalds1da177e2005-04-16 15:20:36 -07005278 /*
Roland Dreierb2032fd2015-07-14 16:00:42 -04005279 * If address the same and state FCS_ONLINE
5280 * (or in target mode), nothing changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005281 */
5282 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
Roland Dreierb2032fd2015-07-14 16:00:42 -04005283 (atomic_read(&fcport->state) == FCS_ONLINE ||
Quinn Tran726b8542017-01-19 22:28:00 -08005284 (vha->host->active_mode == MODE_TARGET))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005285 break;
5286 }
5287
5288 /*
5289 * If device was not a fabric device before.
5290 */
5291 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5292 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04005293 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005294 fcport->flags |= (FCF_FABRIC_DEVICE |
5295 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005296 break;
5297 }
5298
5299 /*
5300 * Port ID changed or device was marked to be updated;
5301 * Log it out if still logged in and mark it for
5302 * relogin later.
5303 */
Quinn Tran726b8542017-01-19 22:28:00 -08005304 if (qla_tgt_mode_enabled(base_vha)) {
Roland Dreierb2032fd2015-07-14 16:00:42 -04005305 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5306 "port changed FC ID, %8phC"
5307 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5308 fcport->port_name,
5309 fcport->d_id.b.domain,
5310 fcport->d_id.b.area,
5311 fcport->d_id.b.al_pa,
5312 fcport->loop_id,
5313 new_fcport->d_id.b.domain,
5314 new_fcport->d_id.b.area,
5315 new_fcport->d_id.b.al_pa);
5316 fcport->d_id.b24 = new_fcport->d_id.b24;
5317 break;
5318 }
5319
Linus Torvalds1da177e2005-04-16 15:20:36 -07005320 fcport->d_id.b24 = new_fcport->d_id.b24;
5321 fcport->flags |= FCF_LOGIN_NEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005322 break;
5323 }
5324
Quinn Tran726b8542017-01-19 22:28:00 -08005325 if (found) {
5326 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005327 continue;
Quinn Tran726b8542017-01-19 22:28:00 -08005328 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005329 /* If device was not in our fcports list, then add it. */
Roland Dreierb2032fd2015-07-14 16:00:42 -04005330 new_fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tran726b8542017-01-19 22:28:00 -08005331 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5332
5333 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5334
Linus Torvalds1da177e2005-04-16 15:20:36 -07005335
5336 /* Allocate a new replacement fcport. */
5337 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005338 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005339 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005340 ql_log(ql_log_warn, vha, 0xd032,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005341 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005342 return (QLA_MEMORY_ALLOC_FAILED);
5343 }
5344 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5345 new_fcport->d_id.b24 = nxt_d_id.b24;
5346 }
5347
Quinn Tran726b8542017-01-19 22:28:00 -08005348 qla2x00_free_fcport(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005349
Quinn Tran726b8542017-01-19 22:28:00 -08005350 /*
5351 * Logout all previous fabric dev marked lost, except FCP2 devices.
5352 */
5353 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5354 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5355 break;
5356
5357 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5358 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5359 continue;
5360
5361 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5362 if ((qla_dual_mode_enabled(vha) ||
5363 qla_ini_mode_enabled(vha)) &&
5364 atomic_read(&fcport->state) == FCS_ONLINE) {
5365 qla2x00_mark_device_lost(vha, fcport,
5366 ql2xplogiabsentdevice, 0);
5367 if (fcport->loop_id != FC_NO_LOOP_ID &&
5368 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5369 fcport->port_type != FCT_INITIATOR &&
5370 fcport->port_type != FCT_BROADCAST) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005371 ql_dbg(ql_dbg_disc, vha, 0x20f0,
Quinn Tran726b8542017-01-19 22:28:00 -08005372 "%s %d %8phC post del sess\n",
5373 __func__, __LINE__,
5374 fcport->port_name);
5375
5376 qlt_schedule_sess_for_deletion_lock
5377 (fcport);
5378 continue;
5379 }
5380 }
5381 }
5382
5383 if (fcport->scan_state == QLA_FCPORT_FOUND)
5384 qla24xx_fcport_handle_login(vha, fcport);
5385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005386 return (rval);
5387}
5388
5389/*
5390 * qla2x00_find_new_loop_id
5391 * Scan through our port list and find a new usable loop ID.
5392 *
5393 * Input:
5394 * ha: adapter state pointer.
5395 * dev: port structure pointer.
5396 *
5397 * Returns:
5398 * qla2x00 local function return status code.
5399 *
5400 * Context:
5401 * Kernel context.
5402 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07005403int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005404qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005405{
5406 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005407 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07005408 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005409
5410 rval = QLA_SUCCESS;
5411
Chad Dupuis5f16b332012-08-22 14:21:00 -04005412 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005413
Chad Dupuis5f16b332012-08-22 14:21:00 -04005414 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
5415 LOOPID_MAP_SIZE);
5416 if (dev->loop_id >= LOOPID_MAP_SIZE ||
5417 qla2x00_is_reserved_id(vha, dev->loop_id)) {
5418 dev->loop_id = FC_NO_LOOP_ID;
5419 rval = QLA_FUNCTION_FAILED;
5420 } else
5421 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005422
Chad Dupuis5f16b332012-08-22 14:21:00 -04005423 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005424
Chad Dupuis5f16b332012-08-22 14:21:00 -04005425 if (rval == QLA_SUCCESS)
5426 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
5427 "Assigning new loopid=%x, portid=%x.\n",
5428 dev->loop_id, dev->d_id.b24);
5429 else
5430 ql_log(ql_log_warn, dev->vha, 0x2087,
5431 "No loop_id's available, portid=%x.\n",
5432 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005433
5434 return (rval);
5435}
5436
Linus Torvalds1da177e2005-04-16 15:20:36 -07005437
5438/*
5439 * qla2x00_fabric_login
5440 * Issue fabric login command.
5441 *
5442 * Input:
5443 * ha = adapter block pointer.
5444 * device = pointer to FC device type structure.
5445 *
5446 * Returns:
5447 * 0 - Login successfully
5448 * 1 - Login failed
5449 * 2 - Initiator device
5450 * 3 - Fatal error
5451 */
5452int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005453qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005454 uint16_t *next_loopid)
5455{
5456 int rval;
5457 int retry;
5458 uint16_t tmp_loopid;
5459 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005460 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005461
5462 retry = 0;
5463 tmp_loopid = 0;
5464
5465 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005466 ql_dbg(ql_dbg_disc, vha, 0x2000,
5467 "Trying Fabric Login w/loop id 0x%04x for port "
5468 "%02x%02x%02x.\n",
5469 fcport->loop_id, fcport->d_id.b.domain,
5470 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005471
5472 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08005473 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005474 fcport->d_id.b.domain, fcport->d_id.b.area,
5475 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08005476 if (rval != QLA_SUCCESS) {
5477 return rval;
5478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005479 if (mb[0] == MBS_PORT_ID_USED) {
5480 /*
5481 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005482 * recommends the driver perform an implicit login with
5483 * the specified ID again. The ID we just used is save
5484 * here so we return with an ID that can be tried by
5485 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005486 */
5487 retry++;
5488 tmp_loopid = fcport->loop_id;
5489 fcport->loop_id = mb[1];
5490
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005491 ql_dbg(ql_dbg_disc, vha, 0x2001,
5492 "Fabric Login: port in use - next loop "
5493 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07005494 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005495 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005496
5497 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
5498 /*
5499 * Login succeeded.
5500 */
5501 if (retry) {
5502 /* A retry occurred before. */
5503 *next_loopid = tmp_loopid;
5504 } else {
5505 /*
5506 * No retry occurred before. Just increment the
5507 * ID value for next login.
5508 */
5509 *next_loopid = (fcport->loop_id + 1);
5510 }
5511
5512 if (mb[1] & BIT_0) {
5513 fcport->port_type = FCT_INITIATOR;
5514 } else {
5515 fcport->port_type = FCT_TARGET;
5516 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07005517 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005518 }
5519 }
5520
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07005521 if (mb[10] & BIT_0)
5522 fcport->supported_classes |= FC_COS_CLASS2;
5523 if (mb[10] & BIT_1)
5524 fcport->supported_classes |= FC_COS_CLASS3;
5525
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005526 if (IS_FWI2_CAPABLE(ha)) {
5527 if (mb[10] & BIT_7)
5528 fcport->flags |=
5529 FCF_CONF_COMP_SUPPORTED;
5530 }
5531
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532 rval = QLA_SUCCESS;
5533 break;
5534 } else if (mb[0] == MBS_LOOP_ID_USED) {
5535 /*
5536 * Loop ID already used, try next loop ID.
5537 */
5538 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005539 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005540 if (rval != QLA_SUCCESS) {
5541 /* Ran out of loop IDs to use */
5542 break;
5543 }
5544 } else if (mb[0] == MBS_COMMAND_ERROR) {
5545 /*
5546 * Firmware possibly timed out during login. If NO
5547 * retries are left to do then the device is declared
5548 * dead.
5549 */
5550 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005551 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07005552 fcport->d_id.b.domain, fcport->d_id.b.area,
5553 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005554 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005555
5556 rval = 1;
5557 break;
5558 } else {
5559 /*
5560 * unrecoverable / not handled error
5561 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005562 ql_dbg(ql_dbg_disc, vha, 0x2002,
5563 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
5564 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
5565 fcport->d_id.b.area, fcport->d_id.b.al_pa,
5566 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005567
5568 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005569 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07005570 fcport->d_id.b.domain, fcport->d_id.b.area,
5571 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04005572 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07005573 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005574
5575 rval = 3;
5576 break;
5577 }
5578 }
5579
5580 return (rval);
5581}
5582
5583/*
5584 * qla2x00_local_device_login
5585 * Issue local device login command.
5586 *
5587 * Input:
5588 * ha = adapter block pointer.
5589 * loop_id = loop id of device to login to.
5590 *
5591 * Returns (Where's the #define!!!!):
5592 * 0 - Login successfully
5593 * 1 - Login failed
5594 * 3 - Fatal error
5595 */
5596int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005597qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005598{
5599 int rval;
5600 uint16_t mb[MAILBOX_REGISTER_COUNT];
5601
5602 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005603 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005604 if (rval == QLA_SUCCESS) {
5605 /* Interrogate mailbox registers for any errors */
5606 if (mb[0] == MBS_COMMAND_ERROR)
5607 rval = 1;
5608 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
5609 /* device not in PCB table */
5610 rval = 3;
5611 }
5612
5613 return (rval);
5614}
5615
5616/*
5617 * qla2x00_loop_resync
5618 * Resync with fibre channel devices.
5619 *
5620 * Input:
5621 * ha = adapter block pointer.
5622 *
5623 * Returns:
5624 * 0 = success
5625 */
5626int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005627qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005628{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005629 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005630 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005631 struct req_que *req;
5632 struct rsp_que *rsp;
5633
Michael Hernandezd7459522016-12-12 14:40:07 -08005634 req = vha->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005635 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005636
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005637 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5638 if (vha->flags.online) {
5639 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005640 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5641 wait_time = 256;
5642 do {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005643 if (!IS_QLAFX00(vha->hw)) {
5644 /*
5645 * Issue a marker after FW becomes
5646 * ready.
5647 */
5648 qla2x00_marker(vha, req, rsp, 0, 0,
5649 MK_SYNC_ALL);
5650 vha->marker_needed = 0;
5651 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005652
5653 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005654 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005655
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005656 if (IS_QLAFX00(vha->hw))
5657 qlafx00_configure_devices(vha);
5658 else
5659 qla2x00_configure_loop(vha);
5660
Linus Torvalds1da177e2005-04-16 15:20:36 -07005661 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005662 } while (!atomic_read(&vha->loop_down_timer) &&
5663 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5664 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
5665 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005666 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005667 }
5668
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005669 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005670 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005671
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005672 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005673 ql_dbg(ql_dbg_disc, vha, 0x206c,
5674 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005675
5676 return (rval);
5677}
5678
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005679/*
5680* qla2x00_perform_loop_resync
5681* Description: This function will set the appropriate flags and call
5682* qla2x00_loop_resync. If successful loop will be resynced
5683* Arguments : scsi_qla_host_t pointer
5684* returm : Success or Failure
5685*/
5686
5687int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
5688{
5689 int32_t rval = 0;
5690
5691 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
5692 /*Configure the flags so that resync happens properly*/
5693 atomic_set(&ha->loop_down_timer, 0);
5694 if (!(ha->device_flags & DFLG_NO_CABLE)) {
5695 atomic_set(&ha->loop_state, LOOP_UP);
5696 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
5697 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
5698 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
5699
5700 rval = qla2x00_loop_resync(ha);
5701 } else
5702 atomic_set(&ha->loop_state, LOOP_DEAD);
5703
5704 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
5705 }
5706
5707 return rval;
5708}
5709
Linus Torvalds1da177e2005-04-16 15:20:36 -07005710void
Andrew Vasquez67becc02009-08-25 11:36:20 -07005711qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005712{
5713 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07005714 struct scsi_qla_host *vha;
5715 struct qla_hw_data *ha = base_vha->hw;
5716 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005717
Arun Easifeafb7b2010-09-03 14:57:00 -07005718 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005719 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07005720 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
5721 atomic_inc(&vha->vref_count);
5722 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08005723 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07005724 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
5725 spin_unlock_irqrestore(&ha->vport_slock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07005726 qla2x00_rport_del(fcport);
Alexei Potashnikdf673272015-07-14 16:00:46 -04005727
Arun Easifeafb7b2010-09-03 14:57:00 -07005728 spin_lock_irqsave(&ha->vport_slock, flags);
5729 }
5730 }
5731 atomic_dec(&vha->vref_count);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07005732 wake_up(&vha->vref_waitq);
Arun Easifeafb7b2010-09-03 14:57:00 -07005733 }
5734 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005735}
5736
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005737/* Assumes idc_lock always held on entry */
5738void
5739qla83xx_reset_ownership(scsi_qla_host_t *vha)
5740{
5741 struct qla_hw_data *ha = vha->hw;
5742 uint32_t drv_presence, drv_presence_mask;
5743 uint32_t dev_part_info1, dev_part_info2, class_type;
5744 uint32_t class_type_mask = 0x3;
5745 uint16_t fcoe_other_function = 0xffff, i;
5746
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005747 if (IS_QLA8044(ha)) {
5748 drv_presence = qla8044_rd_direct(vha,
5749 QLA8044_CRB_DRV_ACTIVE_INDEX);
5750 dev_part_info1 = qla8044_rd_direct(vha,
5751 QLA8044_CRB_DEV_PART_INFO_INDEX);
5752 dev_part_info2 = qla8044_rd_direct(vha,
5753 QLA8044_CRB_DEV_PART_INFO2);
5754 } else {
5755 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5756 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
5757 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
5758 }
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005759 for (i = 0; i < 8; i++) {
5760 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
5761 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5762 (i != ha->portnum)) {
5763 fcoe_other_function = i;
5764 break;
5765 }
5766 }
5767 if (fcoe_other_function == 0xffff) {
5768 for (i = 0; i < 8; i++) {
5769 class_type = ((dev_part_info2 >> (i * 4)) &
5770 class_type_mask);
5771 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5772 ((i + 8) != ha->portnum)) {
5773 fcoe_other_function = i + 8;
5774 break;
5775 }
5776 }
5777 }
5778 /*
5779 * Prepare drv-presence mask based on fcoe functions present.
5780 * However consider only valid physical fcoe function numbers (0-15).
5781 */
5782 drv_presence_mask = ~((1 << (ha->portnum)) |
5783 ((fcoe_other_function == 0xffff) ?
5784 0 : (1 << (fcoe_other_function))));
5785
5786 /* We are the reset owner iff:
5787 * - No other protocol drivers present.
5788 * - This is the lowest among fcoe functions. */
5789 if (!(drv_presence & drv_presence_mask) &&
5790 (ha->portnum < fcoe_other_function)) {
5791 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
5792 "This host is Reset owner.\n");
5793 ha->flags.nic_core_reset_owner = 1;
5794 }
5795}
5796
Saurav Kashyapfa492632012-11-21 02:40:29 -05005797static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005798__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
5799{
5800 int rval = QLA_SUCCESS;
5801 struct qla_hw_data *ha = vha->hw;
5802 uint32_t drv_ack;
5803
5804 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5805 if (rval == QLA_SUCCESS) {
5806 drv_ack |= (1 << ha->portnum);
5807 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5808 }
5809
5810 return rval;
5811}
5812
Saurav Kashyapfa492632012-11-21 02:40:29 -05005813static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005814__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
5815{
5816 int rval = QLA_SUCCESS;
5817 struct qla_hw_data *ha = vha->hw;
5818 uint32_t drv_ack;
5819
5820 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5821 if (rval == QLA_SUCCESS) {
5822 drv_ack &= ~(1 << ha->portnum);
5823 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5824 }
5825
5826 return rval;
5827}
5828
Saurav Kashyapfa492632012-11-21 02:40:29 -05005829static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005830qla83xx_dev_state_to_string(uint32_t dev_state)
5831{
5832 switch (dev_state) {
5833 case QLA8XXX_DEV_COLD:
5834 return "COLD/RE-INIT";
5835 case QLA8XXX_DEV_INITIALIZING:
5836 return "INITIALIZING";
5837 case QLA8XXX_DEV_READY:
5838 return "READY";
5839 case QLA8XXX_DEV_NEED_RESET:
5840 return "NEED RESET";
5841 case QLA8XXX_DEV_NEED_QUIESCENT:
5842 return "NEED QUIESCENT";
5843 case QLA8XXX_DEV_FAILED:
5844 return "FAILED";
5845 case QLA8XXX_DEV_QUIESCENT:
5846 return "QUIESCENT";
5847 default:
5848 return "Unknown";
5849 }
5850}
5851
5852/* Assumes idc-lock always held on entry */
5853void
5854qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
5855{
5856 struct qla_hw_data *ha = vha->hw;
5857 uint32_t idc_audit_reg = 0, duration_secs = 0;
5858
5859 switch (audit_type) {
5860 case IDC_AUDIT_TIMESTAMP:
5861 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
5862 idc_audit_reg = (ha->portnum) |
5863 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
5864 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5865 break;
5866
5867 case IDC_AUDIT_COMPLETION:
5868 duration_secs = ((jiffies_to_msecs(jiffies) -
5869 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
5870 idc_audit_reg = (ha->portnum) |
5871 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
5872 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5873 break;
5874
5875 default:
5876 ql_log(ql_log_warn, vha, 0xb078,
5877 "Invalid audit type specified.\n");
5878 break;
5879 }
5880}
5881
5882/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05005883static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005884qla83xx_initiating_reset(scsi_qla_host_t *vha)
5885{
5886 struct qla_hw_data *ha = vha->hw;
5887 uint32_t idc_control, dev_state;
5888
5889 __qla83xx_get_idc_control(vha, &idc_control);
5890 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
5891 ql_log(ql_log_info, vha, 0xb080,
5892 "NIC Core reset has been disabled. idc-control=0x%x\n",
5893 idc_control);
5894 return QLA_FUNCTION_FAILED;
5895 }
5896
5897 /* Set NEED-RESET iff in READY state and we are the reset-owner */
5898 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5899 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
5900 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
5901 QLA8XXX_DEV_NEED_RESET);
5902 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
5903 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
5904 } else {
5905 const char *state = qla83xx_dev_state_to_string(dev_state);
5906 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
5907
5908 /* SV: XXX: Is timeout required here? */
5909 /* Wait for IDC state change READY -> NEED_RESET */
5910 while (dev_state == QLA8XXX_DEV_READY) {
5911 qla83xx_idc_unlock(vha, 0);
5912 msleep(200);
5913 qla83xx_idc_lock(vha, 0);
5914 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5915 }
5916 }
5917
5918 /* Send IDC ack by writing to drv-ack register */
5919 __qla83xx_set_drv_ack(vha);
5920
5921 return QLA_SUCCESS;
5922}
5923
5924int
5925__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
5926{
5927 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5928}
5929
5930int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005931__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
5932{
5933 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5934}
5935
Saurav Kashyapfa492632012-11-21 02:40:29 -05005936static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005937qla83xx_check_driver_presence(scsi_qla_host_t *vha)
5938{
5939 uint32_t drv_presence = 0;
5940 struct qla_hw_data *ha = vha->hw;
5941
5942 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5943 if (drv_presence & (1 << ha->portnum))
5944 return QLA_SUCCESS;
5945 else
5946 return QLA_TEST_FAILED;
5947}
5948
5949int
5950qla83xx_nic_core_reset(scsi_qla_host_t *vha)
5951{
5952 int rval = QLA_SUCCESS;
5953 struct qla_hw_data *ha = vha->hw;
5954
5955 ql_dbg(ql_dbg_p3p, vha, 0xb058,
5956 "Entered %s().\n", __func__);
5957
5958 if (vha->device_flags & DFLG_DEV_FAILED) {
5959 ql_log(ql_log_warn, vha, 0xb059,
5960 "Device in unrecoverable FAILED state.\n");
5961 return QLA_FUNCTION_FAILED;
5962 }
5963
5964 qla83xx_idc_lock(vha, 0);
5965
5966 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
5967 ql_log(ql_log_warn, vha, 0xb05a,
5968 "Function=0x%x has been removed from IDC participation.\n",
5969 ha->portnum);
5970 rval = QLA_FUNCTION_FAILED;
5971 goto exit;
5972 }
5973
5974 qla83xx_reset_ownership(vha);
5975
5976 rval = qla83xx_initiating_reset(vha);
5977
5978 /*
5979 * Perform reset if we are the reset-owner,
5980 * else wait till IDC state changes to READY/FAILED.
5981 */
5982 if (rval == QLA_SUCCESS) {
5983 rval = qla83xx_idc_state_handler(vha);
5984
5985 if (rval == QLA_SUCCESS)
5986 ha->flags.nic_core_hung = 0;
5987 __qla83xx_clear_drv_ack(vha);
5988 }
5989
5990exit:
5991 qla83xx_idc_unlock(vha, 0);
5992
5993 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
5994
5995 return rval;
5996}
5997
Saurav Kashyap81178772012-08-22 14:21:04 -04005998int
5999qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6000{
6001 struct qla_hw_data *ha = vha->hw;
6002 int rval = QLA_FUNCTION_FAILED;
6003
6004 if (!IS_MCTP_CAPABLE(ha)) {
6005 /* This message can be removed from the final version */
6006 ql_log(ql_log_info, vha, 0x506d,
6007 "This board is not MCTP capable\n");
6008 return rval;
6009 }
6010
6011 if (!ha->mctp_dump) {
6012 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6013 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6014
6015 if (!ha->mctp_dump) {
6016 ql_log(ql_log_warn, vha, 0x506e,
6017 "Failed to allocate memory for mctp dump\n");
6018 return rval;
6019 }
6020 }
6021
6022#define MCTP_DUMP_STR_ADDR 0x00000000
6023 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6024 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6025 if (rval != QLA_SUCCESS) {
6026 ql_log(ql_log_warn, vha, 0x506f,
6027 "Failed to capture mctp dump\n");
6028 } else {
6029 ql_log(ql_log_info, vha, 0x5070,
6030 "Mctp dump capture for host (%ld/%p).\n",
6031 vha->host_no, ha->mctp_dump);
6032 ha->mctp_dumped = 1;
6033 }
6034
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04006035 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04006036 ha->flags.nic_core_reset_hdlr_active = 1;
6037 rval = qla83xx_restart_nic_firmware(vha);
6038 if (rval)
6039 /* NIC Core reset failed. */
6040 ql_log(ql_log_warn, vha, 0x5071,
6041 "Failed to restart nic firmware\n");
6042 else
6043 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6044 "Restarted NIC firmware successfully.\n");
6045 ha->flags.nic_core_reset_hdlr_active = 0;
6046 }
6047
6048 return rval;
6049
6050}
6051
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006052/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006053* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006054* Description: This function will block the new I/Os
6055* Its not aborting any I/Os as context
6056* is not destroyed during quiescence
6057* Arguments: scsi_qla_host_t
6058* return : void
6059*/
6060void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006061qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006062{
6063 struct qla_hw_data *ha = vha->hw;
6064 struct scsi_qla_host *vp;
6065
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006066 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6067 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006068
6069 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6070 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6071 atomic_set(&vha->loop_state, LOOP_DOWN);
6072 qla2x00_mark_all_devices_lost(vha, 0);
6073 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006074 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006075 } else {
6076 if (!atomic_read(&vha->loop_down_timer))
6077 atomic_set(&vha->loop_down_timer,
6078 LOOP_DOWN_TIME);
6079 }
6080 /* Wait for pending cmds to complete */
6081 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
6082}
6083
Giridhar Malavalia9083012010-04-12 17:59:55 -07006084void
6085qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6086{
6087 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006088 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07006089 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08006090 fc_port_t *fcport;
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07006091 u16 i;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006092
Saurav Kashyape46ef002011-02-23 15:27:16 -08006093 /* For ISP82XX, driver waits for completion of the commands.
6094 * online flag should be set.
6095 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006096 if (!(IS_P3P_TYPE(ha)))
Saurav Kashyape46ef002011-02-23 15:27:16 -08006097 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006098 ha->flags.chip_reset_done = 0;
6099 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04006100 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006101
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006102 ql_log(ql_log_info, vha, 0x00af,
6103 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006104
Saurav Kashyape46ef002011-02-23 15:27:16 -08006105 /* For ISP82XX, reset_chip is just disabling interrupts.
6106 * Driver waits for the completion of the commands.
6107 * the interrupts need to be enabled.
6108 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006109 if (!(IS_P3P_TYPE(ha)))
Giridhar Malavalia9083012010-04-12 17:59:55 -07006110 ha->isp_ops->reset_chip(vha);
6111
Quinn Tranec7193e2017-03-15 09:48:55 -07006112 ha->flags.n2n_ae = 0;
6113 ha->flags.lip_ae = 0;
6114 ha->current_topology = 0;
6115 ha->flags.fw_started = 0;
6116 ha->flags.fw_init_done = 0;
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07006117 ha->base_qpair->chip_reset++;
6118 for (i = 0; i < ha->max_qpairs; i++) {
6119 if (ha->queue_pair_map[i])
6120 ha->queue_pair_map[i]->chip_reset =
6121 ha->base_qpair->chip_reset;
6122 }
Quinn Tran726b8542017-01-19 22:28:00 -08006123
Giridhar Malavalia9083012010-04-12 17:59:55 -07006124 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6125 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6126 atomic_set(&vha->loop_state, LOOP_DOWN);
6127 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07006128
6129 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006130 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07006131 atomic_inc(&vp->vref_count);
6132 spin_unlock_irqrestore(&ha->vport_slock, flags);
6133
Giridhar Malavalia9083012010-04-12 17:59:55 -07006134 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07006135
6136 spin_lock_irqsave(&ha->vport_slock, flags);
6137 atomic_dec(&vp->vref_count);
6138 }
6139 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006140 } else {
6141 if (!atomic_read(&vha->loop_down_timer))
6142 atomic_set(&vha->loop_down_timer,
6143 LOOP_DOWN_TIME);
6144 }
6145
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08006146 /* Clear all async request states across all VPs. */
6147 list_for_each_entry(fcport, &vha->vp_fcports, list)
6148 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6149 spin_lock_irqsave(&ha->vport_slock, flags);
6150 list_for_each_entry(vp, &ha->vp_list, list) {
6151 atomic_inc(&vp->vref_count);
6152 spin_unlock_irqrestore(&ha->vport_slock, flags);
6153
6154 list_for_each_entry(fcport, &vp->vp_fcports, list)
6155 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6156
6157 spin_lock_irqsave(&ha->vport_slock, flags);
6158 atomic_dec(&vp->vref_count);
6159 }
6160 spin_unlock_irqrestore(&ha->vport_slock, flags);
6161
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006162 if (!ha->flags.eeh_busy) {
6163 /* Make sure for ISP 82XX IO DMA is complete */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006164 if (IS_P3P_TYPE(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006165 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006166 ql_log(ql_log_info, vha, 0x00b4,
6167 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006168
Saurav Kashyape46ef002011-02-23 15:27:16 -08006169 /* Done waiting for pending commands.
6170 * Reset the online flag.
6171 */
6172 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006174
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006175 /* Requeue all commands in outstanding command list. */
6176 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6177 }
Arun Easib6a029e2014-09-25 06:14:52 -04006178 /* memory barrier */
6179 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006180}
6181
6182/*
6183* qla2x00_abort_isp
6184* Resets ISP and aborts all outstanding commands.
6185*
6186* Input:
6187* ha = adapter block pointer.
6188*
6189* Returns:
6190* 0 = success
6191*/
6192int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006193qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194{
Andrew Vasquez476e8972006-08-23 14:54:55 -07006195 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006196 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006197 struct qla_hw_data *ha = vha->hw;
6198 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006199 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07006200 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006201
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006202 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07006203 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006204
Santosh Vernekara61712972012-08-22 14:21:13 -04006205 if (IS_QLA8031(ha)) {
6206 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6207 "Clearing fcoe driver presence.\n");
6208 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6209 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6210 "Error while clearing DRV-Presence.\n");
6211 }
6212
Andrew Vasquez85880802009-12-15 21:29:46 -08006213 if (unlikely(pci_channel_offline(ha->pdev) &&
6214 ha->flags.pci_channel_io_perm_failure)) {
6215 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6216 status = 0;
6217 return status;
6218 }
6219
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006220 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08006221
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006222 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006223
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006224 if (!qla2x00_restart_isp(vha)) {
6225 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006226
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006227 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228 /*
6229 * Issue marker command only when we are going
6230 * to start the I/O .
6231 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006232 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006233 }
6234
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006235 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006236
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006237 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006238
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07006239 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006240 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07006241
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006242 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6243 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08006244 if (ha->fce) {
6245 ha->flags.fce_enabled = 1;
6246 memset(ha->fce, 0,
6247 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006248 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08006249 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6250 &ha->fce_bufs);
6251 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006252 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08006253 "Unable to reinitialize FCE "
6254 "(%d).\n", rval);
6255 ha->flags.fce_enabled = 0;
6256 }
6257 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006258
6259 if (ha->eft) {
6260 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006261 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006262 ha->eft_dma, EFT_NUM_BUFFERS);
6263 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006264 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006265 "Unable to reinitialize EFT "
6266 "(%d).\n", rval);
6267 }
6268 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006269 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006270 vha->flags.online = 1;
6271 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006272 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006273 ql_log(ql_log_fatal, vha, 0x8035,
6274 "ISP error recover failed - "
6275 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07006276 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006277 * The next call disables the board
6278 * completely.
6279 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006280 ha->isp_ops->reset_adapter(vha);
6281 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006282 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006283 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006284 status = 0;
6285 } else { /* schedule another ISP abort */
6286 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006287 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6288 "ISP abort - retry remaining %d.\n",
6289 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006290 status = 1;
6291 }
6292 } else {
6293 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006294 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6295 "ISP error recovery - retrying (%d) "
6296 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006297 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006298 status = 1;
6299 }
6300 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07006301
Linus Torvalds1da177e2005-04-16 15:20:36 -07006302 }
6303
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006304 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006305 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Quinn Tran1608cc42017-08-23 15:05:03 -07006306 qla2x00_configure_hba(vha);
Arun Easifeafb7b2010-09-03 14:57:00 -07006307 spin_lock_irqsave(&ha->vport_slock, flags);
6308 list_for_each_entry(vp, &ha->vp_list, list) {
6309 if (vp->vp_idx) {
6310 atomic_inc(&vp->vref_count);
6311 spin_unlock_irqrestore(&ha->vport_slock, flags);
6312
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006313 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07006314
6315 spin_lock_irqsave(&ha->vport_slock, flags);
6316 atomic_dec(&vp->vref_count);
6317 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006318 }
Arun Easifeafb7b2010-09-03 14:57:00 -07006319 spin_unlock_irqrestore(&ha->vport_slock, flags);
6320
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006321 if (IS_QLA8031(ha)) {
6322 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6323 "Setting back fcoe driver presence.\n");
6324 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6325 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6326 "Error while setting DRV-Presence.\n");
6327 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006328 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08006329 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6330 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006331 }
6332
6333 return(status);
6334}
6335
6336/*
6337* qla2x00_restart_isp
6338* restarts the ISP after a reset
6339*
6340* Input:
6341* ha = adapter block pointer.
6342*
6343* Returns:
6344* 0 = success
6345*/
6346static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006347qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08006349 int status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006350 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006351 struct req_que *req = ha->req_q_map[0];
6352 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07006353
6354 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006355 if (qla2x00_isp_firmware(vha)) {
6356 vha->flags.online = 0;
6357 status = ha->isp_ops->chip_diag(vha);
6358 if (!status)
6359 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006360 }
6361
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006362 if (!status && !(status = qla2x00_init_rings(vha))) {
6363 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07006364 ha->flags.chip_reset_done = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04006365
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006366 /* Initialize the queues in use */
6367 qla25xx_init_queues(ha);
6368
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006369 status = qla2x00_fw_ready(vha);
6370 if (!status) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006371 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006372 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Chad Dupuis7108b762014-04-11 16:54:45 -04006373 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006374 }
6375
6376 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006377 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006378 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006379 }
6380 return (status);
6381}
6382
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006383static int
6384qla25xx_init_queues(struct qla_hw_data *ha)
6385{
6386 struct rsp_que *rsp = NULL;
6387 struct req_que *req = NULL;
6388 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6389 int ret = -1;
6390 int i;
6391
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07006392 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006393 rsp = ha->rsp_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05006394 if (rsp && test_bit(i, ha->rsp_qid_map)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006395 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08006396 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006397 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006398 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6399 "%s Rsp que: %d init failed.\n",
6400 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006401 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006402 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6403 "%s Rsp que: %d inited.\n",
6404 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006405 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07006406 }
6407 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006408 req = ha->req_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05006409 if (req && test_bit(i, ha->req_qid_map)) {
6410 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006411 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08006412 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006413 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006414 ql_dbg(ql_dbg_init, base_vha, 0x0101,
6415 "%s Req que: %d init failed.\n",
6416 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006417 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006418 ql_dbg(ql_dbg_init, base_vha, 0x0102,
6419 "%s Req que: %d inited.\n",
6420 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006421 }
6422 }
6423 return ret;
6424}
6425
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426/*
6427* qla2x00_reset_adapter
6428* Reset adapter.
6429*
6430* Input:
6431* ha = adapter block pointer.
6432*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07006433void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006434qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435{
6436 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006437 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07006438 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006440 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006441 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006442
Linus Torvalds1da177e2005-04-16 15:20:36 -07006443 spin_lock_irqsave(&ha->hardware_lock, flags);
6444 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
6445 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
6446 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
6447 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
6448 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6449}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006450
6451void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006452qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006453{
6454 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006455 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006456 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
6457
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006458 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07006459 return;
6460
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006461 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006462 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006463
6464 spin_lock_irqsave(&ha->hardware_lock, flags);
6465 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
6466 RD_REG_DWORD(&reg->hccr);
6467 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
6468 RD_REG_DWORD(&reg->hccr);
6469 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08006470
6471 if (IS_NOPOLLING_TYPE(ha))
6472 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006473}
6474
David Miller4e08df32007-04-16 12:37:43 -07006475/* On sparc systems, obtain port and node WWN from firmware
6476 * properties.
6477 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006478static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
6479 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07006480{
6481#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006482 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07006483 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07006484 struct device_node *dp = pci_device_to_OF_node(pdev);
6485 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07006486 int len;
6487
6488 val = of_get_property(dp, "port-wwn", &len);
6489 if (val && len >= WWN_SIZE)
6490 memcpy(nv->port_name, val, WWN_SIZE);
6491
6492 val = of_get_property(dp, "node-wwn", &len);
6493 if (val && len >= WWN_SIZE)
6494 memcpy(nv->node_name, val, WWN_SIZE);
6495#endif
6496}
6497
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006498int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006499qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006500{
David Miller4e08df32007-04-16 12:37:43 -07006501 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006502 struct init_cb_24xx *icb;
6503 struct nvram_24xx *nv;
6504 uint32_t *dptr;
6505 uint8_t *dptr1, *dptr2;
6506 uint32_t chksum;
6507 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006508 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006509
David Miller4e08df32007-04-16 12:37:43 -07006510 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006511 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07006512 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006513
6514 /* Determine NVRAM starting address. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05006515 if (ha->port_no == 0) {
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07006516 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
6517 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
6518 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006519 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08006520 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
6521 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05006522
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07006523 ha->nvram_size = sizeof(struct nvram_24xx);
6524 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006525
Seokmann Ju281afe12007-07-26 13:43:34 -07006526 /* Get VPD data into cache */
6527 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006528 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07006529 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
6530
6531 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006532 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006533 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006534 ha->nvram_size);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006535 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
6536 chksum += le32_to_cpu(*dptr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006537
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006538 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
6539 "Contents of NVRAM\n");
6540 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
6541 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006542
6543 /* Bad NVRAM data, set defaults parameters. */
6544 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6545 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07006546 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006547 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006548 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04006549 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006550 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
6551 ql_log(ql_log_warn, vha, 0x006c,
6552 "Falling back to functioning (yet invalid -- WWPN) "
6553 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07006554
6555 /*
6556 * Set default initialization control block.
6557 */
6558 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07006559 nv->nvram_version = cpu_to_le16(ICB_VERSION);
6560 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04006561 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07006562 nv->execution_throttle = cpu_to_le16(0xFFFF);
6563 nv->exchange_count = cpu_to_le16(0);
6564 nv->hard_address = cpu_to_le16(124);
David Miller4e08df32007-04-16 12:37:43 -07006565 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006566 nv->port_name[1] = 0x00 + ha->port_no + 1;
David Miller4e08df32007-04-16 12:37:43 -07006567 nv->port_name[2] = 0x00;
6568 nv->port_name[3] = 0xe0;
6569 nv->port_name[4] = 0x8b;
6570 nv->port_name[5] = 0x1c;
6571 nv->port_name[6] = 0x55;
6572 nv->port_name[7] = 0x86;
6573 nv->node_name[0] = 0x20;
6574 nv->node_name[1] = 0x00;
6575 nv->node_name[2] = 0x00;
6576 nv->node_name[3] = 0xe0;
6577 nv->node_name[4] = 0x8b;
6578 nv->node_name[5] = 0x1c;
6579 nv->node_name[6] = 0x55;
6580 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006581 qla24xx_nvram_wwn_from_ofw(vha, nv);
Bart Van Asschead950362015-07-09 07:24:08 -07006582 nv->login_retry_count = cpu_to_le16(8);
6583 nv->interrupt_delay_timer = cpu_to_le16(0);
6584 nv->login_timeout = cpu_to_le16(0);
David Miller4e08df32007-04-16 12:37:43 -07006585 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07006586 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6587 nv->firmware_options_2 = cpu_to_le32(2 << 4);
6588 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6589 nv->firmware_options_3 = cpu_to_le32(2 << 13);
6590 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6591 nv->efi_parameters = cpu_to_le32(0);
David Miller4e08df32007-04-16 12:37:43 -07006592 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07006593 nv->max_luns_per_target = cpu_to_le16(128);
6594 nv->port_down_retry_count = cpu_to_le16(30);
6595 nv->link_down_timeout = cpu_to_le16(30);
David Miller4e08df32007-04-16 12:37:43 -07006596
6597 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006598 }
6599
Quinn Tran726b8542017-01-19 22:28:00 -08006600 if (qla_tgt_mode_enabled(vha)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006601 /* Don't enable full login after initial LIP */
Bart Van Asschead950362015-07-09 07:24:08 -07006602 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006603 /* Don't enable LIP full login for initiator */
Bart Van Asschead950362015-07-09 07:24:08 -07006604 nv->host_p &= cpu_to_le32(~BIT_10);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006605 }
6606
6607 qlt_24xx_config_nvram_stage1(vha, nv);
6608
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006609 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006610 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006611
6612 /* Copy 1st segment. */
6613 dptr1 = (uint8_t *)icb;
6614 dptr2 = (uint8_t *)&nv->version;
6615 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6616 while (cnt--)
6617 *dptr1++ = *dptr2++;
6618
6619 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07006620 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006621
6622 /* Copy 2nd segment. */
6623 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6624 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6625 cnt = (uint8_t *)&icb->reserved_3 -
6626 (uint8_t *)&icb->interrupt_delay_timer;
6627 while (cnt--)
6628 *dptr1++ = *dptr2++;
6629
6630 /*
6631 * Setup driver NVRAM options.
6632 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006633 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08006634 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006635
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006636 qlt_24xx_config_nvram_stage2(vha, icb);
6637
Bart Van Asschead950362015-07-09 07:24:08 -07006638 if (nv->host_p & cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006639 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07006640 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6641 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6642 }
6643
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006644 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07006645 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006646 /*
6647 * Firmware will apply the following mask if the nodename was
6648 * not provided.
6649 */
6650 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6651 icb->node_name[0] &= 0xF0;
6652 }
6653
6654 /* Set host adapter parameters. */
6655 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08006656 ha->flags.enable_lip_reset = 0;
6657 ha->flags.enable_lip_full_login =
6658 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6659 ha->flags.enable_target_reset =
6660 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006661 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07006662 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006663
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07006664 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6665 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006666
6667 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
6668 sizeof(ha->fw_seriallink_options24));
6669
6670 /* save HBA serial number */
6671 ha->serial0 = icb->port_name[5];
6672 ha->serial1 = icb->port_name[6];
6673 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006674 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6675 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006676
Bart Van Asschead950362015-07-09 07:24:08 -07006677 icb->execution_throttle = cpu_to_le16(0xFFFF);
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08006678
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006679 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6680
6681 /* Set minimum login_timeout to 4 seconds. */
6682 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6683 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6684 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07006685 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006686 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006687
Andrew Vasquez00a537b2008-02-28 14:06:11 -08006688 /* Set minimum RATOV to 100 tenths of a second. */
6689 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006690
6691 ha->loop_reset_delay = nv->reset_delay;
6692
6693 /* Link Down Timeout = 0:
6694 *
6695 * When Port Down timer expires we will start returning
6696 * I/O's to OS with "DID_NO_CONNECT".
6697 *
6698 * Link Down Timeout != 0:
6699 *
6700 * The driver waits for the link to come up after link down
6701 * before returning I/Os to OS with "DID_NO_CONNECT".
6702 */
6703 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6704 ha->loop_down_abort_time =
6705 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6706 } else {
6707 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6708 ha->loop_down_abort_time =
6709 (LOOP_DOWN_TIME - ha->link_down_timeout);
6710 }
6711
6712 /* Need enough time to try and get the port back. */
6713 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6714 if (qlport_down_retry)
6715 ha->port_down_retry_count = qlport_down_retry;
6716
6717 /* Set login_retry_count */
6718 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6719 if (ha->port_down_retry_count ==
6720 le16_to_cpu(nv->port_down_retry_count) &&
6721 ha->port_down_retry_count > 3)
6722 ha->login_retry_count = ha->port_down_retry_count;
6723 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6724 ha->login_retry_count = ha->port_down_retry_count;
6725 if (ql2xloginretrycount)
6726 ha->login_retry_count = ql2xloginretrycount;
6727
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006728 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006729 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006730 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6731 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6732 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6733 le16_to_cpu(icb->interrupt_delay_timer): 2;
6734 }
Bart Van Asschead950362015-07-09 07:24:08 -07006735 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006736 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006737 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006738 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08006739 ha->zio_mode = QLA_ZIO_MODE_6;
6740
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006741 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006742 "ZIO mode %d enabled; timer delay (%d us).\n",
6743 ha->zio_mode, ha->zio_timer * 100);
6744
6745 icb->firmware_options_2 |= cpu_to_le32(
6746 (uint32_t)ha->zio_mode);
6747 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006748 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006749 }
6750
David Miller4e08df32007-04-16 12:37:43 -07006751 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006752 ql_log(ql_log_warn, vha, 0x0070,
6753 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07006754 }
6755 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006756}
6757
Sawan Chandak4243c112016-01-27 12:03:31 -05006758uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
6759{
6760 struct qla27xx_image_status pri_image_status, sec_image_status;
6761 uint8_t valid_pri_image, valid_sec_image;
6762 uint32_t *wptr;
6763 uint32_t cnt, chksum, size;
6764 struct qla_hw_data *ha = vha->hw;
6765
6766 valid_pri_image = valid_sec_image = 1;
6767 ha->active_image = 0;
6768 size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
6769
6770 if (!ha->flt_region_img_status_pri) {
6771 valid_pri_image = 0;
6772 goto check_sec_image;
6773 }
6774
6775 qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
6776 ha->flt_region_img_status_pri, size);
6777
6778 if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6779 ql_dbg(ql_dbg_init, vha, 0x018b,
6780 "Primary image signature (0x%x) not valid\n",
6781 pri_image_status.signature);
6782 valid_pri_image = 0;
6783 goto check_sec_image;
6784 }
6785
6786 wptr = (uint32_t *)(&pri_image_status);
6787 cnt = size;
6788
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006789 for (chksum = 0; cnt--; wptr++)
6790 chksum += le32_to_cpu(*wptr);
Quinn Tran41dc5292017-01-19 22:28:03 -08006791
Sawan Chandak4243c112016-01-27 12:03:31 -05006792 if (chksum) {
6793 ql_dbg(ql_dbg_init, vha, 0x018c,
6794 "Checksum validation failed for primary image (0x%x)\n",
6795 chksum);
6796 valid_pri_image = 0;
6797 }
6798
6799check_sec_image:
6800 if (!ha->flt_region_img_status_sec) {
6801 valid_sec_image = 0;
6802 goto check_valid_image;
6803 }
6804
6805 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
6806 ha->flt_region_img_status_sec, size);
6807
6808 if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6809 ql_dbg(ql_dbg_init, vha, 0x018d,
6810 "Secondary image signature(0x%x) not valid\n",
6811 sec_image_status.signature);
6812 valid_sec_image = 0;
6813 goto check_valid_image;
6814 }
6815
6816 wptr = (uint32_t *)(&sec_image_status);
6817 cnt = size;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006818 for (chksum = 0; cnt--; wptr++)
6819 chksum += le32_to_cpu(*wptr);
Sawan Chandak4243c112016-01-27 12:03:31 -05006820 if (chksum) {
6821 ql_dbg(ql_dbg_init, vha, 0x018e,
6822 "Checksum validation failed for secondary image (0x%x)\n",
6823 chksum);
6824 valid_sec_image = 0;
6825 }
6826
6827check_valid_image:
6828 if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
6829 ha->active_image = QLA27XX_PRIMARY_IMAGE;
6830 if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
6831 if (!ha->active_image ||
6832 pri_image_status.generation_number <
6833 sec_image_status.generation_number)
6834 ha->active_image = QLA27XX_SECONDARY_IMAGE;
6835 }
6836
6837 ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n",
6838 ha->active_image == 0 ? "default bootld and fw" :
6839 ha->active_image == 1 ? "primary" :
6840 ha->active_image == 2 ? "secondary" :
6841 "Invalid");
6842
6843 return ha->active_image;
6844}
6845
Adrian Bunk413975a2006-06-30 02:33:06 -07006846static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006847qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
6848 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006849{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006850 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006851 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006852 uint32_t *dcode, dlen;
6853 uint32_t risc_addr;
6854 uint32_t risc_size;
6855 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006856 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006857 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006858
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006859 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006860 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006861
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006862 rval = QLA_SUCCESS;
6863
6864 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006865 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006866 *srisc_addr = 0;
6867
Sawan Chandak4243c112016-01-27 12:03:31 -05006868 if (IS_QLA27XX(ha) &&
6869 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
6870 faddr = ha->flt_region_fw_sec;
6871
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006872 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006873 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006874 for (i = 0; i < 4; i++)
6875 dcode[i] = be32_to_cpu(dcode[i]);
6876 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
6877 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
6878 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
6879 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006880 ql_log(ql_log_fatal, vha, 0x008c,
6881 "Unable to verify the integrity of flash firmware "
6882 "image.\n");
6883 ql_log(ql_log_fatal, vha, 0x008d,
6884 "Firmware data: %08x %08x %08x %08x.\n",
6885 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006886
6887 return QLA_FUNCTION_FAILED;
6888 }
6889
6890 while (segments && rval == QLA_SUCCESS) {
6891 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006892 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006893
6894 risc_addr = be32_to_cpu(dcode[2]);
6895 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
6896 risc_size = be32_to_cpu(dcode[3]);
6897
6898 fragment = 0;
6899 while (risc_size > 0 && rval == QLA_SUCCESS) {
6900 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
6901 if (dlen > risc_size)
6902 dlen = risc_size;
6903
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006904 ql_dbg(ql_dbg_init, vha, 0x008e,
6905 "Loading risc segment@ risc addr %x "
6906 "number of dwords 0x%x offset 0x%x.\n",
6907 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006908
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006909 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006910 for (i = 0; i < dlen; i++)
6911 dcode[i] = swab32(dcode[i]);
6912
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006913 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006914 dlen);
6915 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006916 ql_log(ql_log_fatal, vha, 0x008f,
6917 "Failed to load segment %d of firmware.\n",
6918 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04006919 return QLA_FUNCTION_FAILED;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006920 }
6921
6922 faddr += dlen;
6923 risc_addr += dlen;
6924 risc_size -= dlen;
6925 fragment++;
6926 }
6927
6928 /* Next segment. */
6929 segments--;
6930 }
6931
Chad Dupuisf73cb692014-02-26 04:15:06 -05006932 if (!IS_QLA27XX(ha))
6933 return rval;
6934
6935 if (ha->fw_dump_template)
6936 vfree(ha->fw_dump_template);
6937 ha->fw_dump_template = NULL;
6938 ha->fw_dump_template_len = 0;
6939
6940 ql_dbg(ql_dbg_init, vha, 0x0161,
6941 "Loading fwdump template from %x\n", faddr);
6942 qla24xx_read_flash_data(vha, dcode, faddr, 7);
6943 risc_size = be32_to_cpu(dcode[2]);
6944 ql_dbg(ql_dbg_init, vha, 0x0162,
6945 "-> array size %x dwords\n", risc_size);
6946 if (risc_size == 0 || risc_size == ~0)
6947 goto default_template;
6948
6949 dlen = (risc_size - 8) * sizeof(*dcode);
6950 ql_dbg(ql_dbg_init, vha, 0x0163,
6951 "-> template allocating %x bytes...\n", dlen);
6952 ha->fw_dump_template = vmalloc(dlen);
6953 if (!ha->fw_dump_template) {
6954 ql_log(ql_log_warn, vha, 0x0164,
6955 "Failed fwdump template allocate %x bytes.\n", risc_size);
6956 goto default_template;
6957 }
6958
6959 faddr += 7;
6960 risc_size -= 8;
6961 dcode = ha->fw_dump_template;
6962 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
6963 for (i = 0; i < risc_size; i++)
6964 dcode[i] = le32_to_cpu(dcode[i]);
6965
6966 if (!qla27xx_fwdt_template_valid(dcode)) {
6967 ql_log(ql_log_warn, vha, 0x0165,
6968 "Failed fwdump template validate\n");
6969 goto default_template;
6970 }
6971
6972 dlen = qla27xx_fwdt_template_size(dcode);
6973 ql_dbg(ql_dbg_init, vha, 0x0166,
6974 "-> template size %x bytes\n", dlen);
6975 if (dlen > risc_size * sizeof(*dcode)) {
6976 ql_log(ql_log_warn, vha, 0x0167,
Himanshu Madhani4fae52b2017-06-06 13:55:23 -07006977 "Failed fwdump template exceeds array by %zx bytes\n",
Joe Carnuccio383a2982017-06-02 09:11:55 -07006978 (size_t)(dlen - risc_size * sizeof(*dcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05006979 goto default_template;
6980 }
6981 ha->fw_dump_template_len = dlen;
6982 return rval;
6983
6984default_template:
6985 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
6986 if (ha->fw_dump_template)
6987 vfree(ha->fw_dump_template);
6988 ha->fw_dump_template = NULL;
6989 ha->fw_dump_template_len = 0;
6990
6991 dlen = qla27xx_fwdt_template_default_size();
6992 ql_dbg(ql_dbg_init, vha, 0x0169,
6993 "-> template allocating %x bytes...\n", dlen);
6994 ha->fw_dump_template = vmalloc(dlen);
6995 if (!ha->fw_dump_template) {
6996 ql_log(ql_log_warn, vha, 0x016a,
6997 "Failed fwdump template allocate %x bytes.\n", risc_size);
6998 goto failed_template;
6999 }
7000
7001 dcode = ha->fw_dump_template;
7002 risc_size = dlen / sizeof(*dcode);
7003 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
7004 for (i = 0; i < risc_size; i++)
7005 dcode[i] = be32_to_cpu(dcode[i]);
7006
7007 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7008 ql_log(ql_log_warn, vha, 0x016b,
7009 "Failed fwdump template validate\n");
7010 goto failed_template;
7011 }
7012
7013 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7014 ql_dbg(ql_dbg_init, vha, 0x016c,
7015 "-> template size %x bytes\n", dlen);
7016 ha->fw_dump_template_len = dlen;
7017 return rval;
7018
7019failed_template:
7020 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
7021 if (ha->fw_dump_template)
7022 vfree(ha->fw_dump_template);
7023 ha->fw_dump_template = NULL;
7024 ha->fw_dump_template_len = 0;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007025 return rval;
7026}
7027
Giridhar Malavalie9454a82013-02-08 01:57:47 -05007028#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007029
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007030int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007031qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08007032{
7033 int rval;
7034 int i, fragment;
7035 uint16_t *wcode, *fwcode;
7036 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7037 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007038 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007039 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08007040
7041 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007042 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08007043 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007044 ql_log(ql_log_info, vha, 0x0083,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01007045 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007046 ql_log(ql_log_info, vha, 0x0084,
7047 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08007048 return QLA_FUNCTION_FAILED;
7049 }
7050
7051 rval = QLA_SUCCESS;
7052
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007053 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08007054 *srisc_addr = 0;
7055 fwcode = (uint16_t *)blob->fw->data;
7056 fwclen = 0;
7057
7058 /* Validate firmware image by checking version. */
7059 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007060 ql_log(ql_log_fatal, vha, 0x0085,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007061 "Unable to verify integrity of firmware image (%zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08007062 blob->fw->size);
7063 goto fail_fw_integrity;
7064 }
7065 for (i = 0; i < 4; i++)
7066 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7067 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7068 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7069 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007070 ql_log(ql_log_fatal, vha, 0x0086,
7071 "Unable to verify integrity of firmware image.\n");
7072 ql_log(ql_log_fatal, vha, 0x0087,
7073 "Firmware data: %04x %04x %04x %04x.\n",
7074 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08007075 goto fail_fw_integrity;
7076 }
7077
7078 seg = blob->segs;
7079 while (*seg && rval == QLA_SUCCESS) {
7080 risc_addr = *seg;
7081 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7082 risc_size = be16_to_cpu(fwcode[3]);
7083
7084 /* Validate firmware image size. */
7085 fwclen += risc_size * sizeof(uint16_t);
7086 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007087 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08007088 "Unable to verify integrity of firmware image "
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007089 "(%zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08007090 goto fail_fw_integrity;
7091 }
7092
7093 fragment = 0;
7094 while (risc_size > 0 && rval == QLA_SUCCESS) {
7095 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7096 if (wlen > risc_size)
7097 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007098 ql_dbg(ql_dbg_init, vha, 0x0089,
7099 "Loading risc segment@ risc addr %x number of "
7100 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08007101
7102 for (i = 0; i < wlen; i++)
7103 wcode[i] = swab16(fwcode[i]);
7104
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007105 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08007106 wlen);
7107 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007108 ql_log(ql_log_fatal, vha, 0x008a,
7109 "Failed to load segment %d of firmware.\n",
7110 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08007111 break;
7112 }
7113
7114 fwcode += wlen;
7115 risc_addr += wlen;
7116 risc_size -= wlen;
7117 fragment++;
7118 }
7119
7120 /* Next segment. */
7121 seg++;
7122 }
7123 return rval;
7124
7125fail_fw_integrity:
7126 return QLA_FUNCTION_FAILED;
7127}
7128
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007129static int
7130qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007131{
7132 int rval;
7133 int segments, fragment;
7134 uint32_t *dcode, dlen;
7135 uint32_t risc_addr;
7136 uint32_t risc_size;
7137 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08007138 struct fw_blob *blob;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007139 const uint32_t *fwcode;
7140 uint32_t fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007141 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007142 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007143
Andrew Vasquez54333832005-11-09 15:49:04 -08007144 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007145 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08007146 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007147 ql_log(ql_log_warn, vha, 0x0090,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01007148 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007149 ql_log(ql_log_warn, vha, 0x0091,
7150 "Firmware images can be retrieved from: "
7151 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007152
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007153 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007154 }
7155
Chad Dupuiscfb09192011-11-18 09:03:07 -08007156 ql_dbg(ql_dbg_init, vha, 0x0092,
7157 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007158
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007159 rval = QLA_SUCCESS;
7160
7161 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007162 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007163 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08007164 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007165 fwclen = 0;
7166
7167 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08007168 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007169 ql_log(ql_log_fatal, vha, 0x0093,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007170 "Unable to verify integrity of firmware image (%zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08007171 blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05007172 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007173 }
7174 for (i = 0; i < 4; i++)
7175 dcode[i] = be32_to_cpu(fwcode[i + 4]);
7176 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
7177 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
7178 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
7179 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007180 ql_log(ql_log_fatal, vha, 0x0094,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007181 "Unable to verify integrity of firmware image (%zd).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007182 blob->fw->size);
7183 ql_log(ql_log_fatal, vha, 0x0095,
7184 "Firmware data: %08x %08x %08x %08x.\n",
7185 dcode[0], dcode[1], dcode[2], dcode[3]);
Chad Dupuisf73cb692014-02-26 04:15:06 -05007186 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007187 }
7188
7189 while (segments && rval == QLA_SUCCESS) {
7190 risc_addr = be32_to_cpu(fwcode[2]);
7191 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
7192 risc_size = be32_to_cpu(fwcode[3]);
7193
7194 /* Validate firmware image size. */
7195 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08007196 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007197 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08007198 "Unable to verify integrity of firmware image "
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007199 "(%zd).\n", blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05007200 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007201 }
7202
7203 fragment = 0;
7204 while (risc_size > 0 && rval == QLA_SUCCESS) {
7205 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
7206 if (dlen > risc_size)
7207 dlen = risc_size;
7208
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007209 ql_dbg(ql_dbg_init, vha, 0x0097,
7210 "Loading risc segment@ risc addr %x "
7211 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007212
7213 for (i = 0; i < dlen; i++)
7214 dcode[i] = swab32(fwcode[i]);
7215
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007216 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08007217 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007218 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007219 ql_log(ql_log_fatal, vha, 0x0098,
7220 "Failed to load segment %d of firmware.\n",
7221 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04007222 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007223 }
7224
7225 fwcode += dlen;
7226 risc_addr += dlen;
7227 risc_size -= dlen;
7228 fragment++;
7229 }
7230
7231 /* Next segment. */
7232 segments--;
7233 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05007234
7235 if (!IS_QLA27XX(ha))
7236 return rval;
7237
7238 if (ha->fw_dump_template)
7239 vfree(ha->fw_dump_template);
7240 ha->fw_dump_template = NULL;
7241 ha->fw_dump_template_len = 0;
7242
7243 ql_dbg(ql_dbg_init, vha, 0x171,
Chad Dupuis97ea7022014-03-13 14:16:40 -04007244 "Loading fwdump template from %x\n",
7245 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
Chad Dupuisf73cb692014-02-26 04:15:06 -05007246 risc_size = be32_to_cpu(fwcode[2]);
7247 ql_dbg(ql_dbg_init, vha, 0x172,
7248 "-> array size %x dwords\n", risc_size);
7249 if (risc_size == 0 || risc_size == ~0)
7250 goto default_template;
7251
7252 dlen = (risc_size - 8) * sizeof(*fwcode);
7253 ql_dbg(ql_dbg_init, vha, 0x0173,
7254 "-> template allocating %x bytes...\n", dlen);
7255 ha->fw_dump_template = vmalloc(dlen);
7256 if (!ha->fw_dump_template) {
7257 ql_log(ql_log_warn, vha, 0x0174,
7258 "Failed fwdump template allocate %x bytes.\n", risc_size);
7259 goto default_template;
7260 }
7261
7262 fwcode += 7;
7263 risc_size -= 8;
7264 dcode = ha->fw_dump_template;
7265 for (i = 0; i < risc_size; i++)
7266 dcode[i] = le32_to_cpu(fwcode[i]);
7267
7268 if (!qla27xx_fwdt_template_valid(dcode)) {
7269 ql_log(ql_log_warn, vha, 0x0175,
7270 "Failed fwdump template validate\n");
7271 goto default_template;
7272 }
7273
7274 dlen = qla27xx_fwdt_template_size(dcode);
7275 ql_dbg(ql_dbg_init, vha, 0x0176,
7276 "-> template size %x bytes\n", dlen);
7277 if (dlen > risc_size * sizeof(*fwcode)) {
7278 ql_log(ql_log_warn, vha, 0x0177,
Himanshu Madhani4fae52b2017-06-06 13:55:23 -07007279 "Failed fwdump template exceeds array by %zx bytes\n",
Joe Carnuccio383a2982017-06-02 09:11:55 -07007280 (size_t)(dlen - risc_size * sizeof(*fwcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05007281 goto default_template;
7282 }
7283 ha->fw_dump_template_len = dlen;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007284 return rval;
7285
Chad Dupuisf73cb692014-02-26 04:15:06 -05007286default_template:
7287 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
7288 if (ha->fw_dump_template)
7289 vfree(ha->fw_dump_template);
7290 ha->fw_dump_template = NULL;
7291 ha->fw_dump_template_len = 0;
7292
7293 dlen = qla27xx_fwdt_template_default_size();
7294 ql_dbg(ql_dbg_init, vha, 0x0179,
7295 "-> template allocating %x bytes...\n", dlen);
7296 ha->fw_dump_template = vmalloc(dlen);
7297 if (!ha->fw_dump_template) {
7298 ql_log(ql_log_warn, vha, 0x017a,
7299 "Failed fwdump template allocate %x bytes.\n", risc_size);
7300 goto failed_template;
7301 }
7302
7303 dcode = ha->fw_dump_template;
7304 risc_size = dlen / sizeof(*fwcode);
7305 fwcode = qla27xx_fwdt_template_default();
7306 for (i = 0; i < risc_size; i++)
7307 dcode[i] = be32_to_cpu(fwcode[i]);
7308
7309 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7310 ql_log(ql_log_warn, vha, 0x017b,
7311 "Failed fwdump template validate\n");
7312 goto failed_template;
7313 }
7314
7315 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7316 ql_dbg(ql_dbg_init, vha, 0x017c,
7317 "-> template size %x bytes\n", dlen);
7318 ha->fw_dump_template_len = dlen;
7319 return rval;
7320
7321failed_template:
7322 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
7323 if (ha->fw_dump_template)
7324 vfree(ha->fw_dump_template);
7325 ha->fw_dump_template = NULL;
7326 ha->fw_dump_template_len = 0;
7327 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007328}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007329
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007330int
7331qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7332{
7333 int rval;
7334
Andrew Vasqueze337d902009-04-06 22:33:49 -07007335 if (ql2xfwloadbin == 1)
7336 return qla81xx_load_risc(vha, srisc_addr);
7337
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007338 /*
7339 * FW Load priority:
7340 * 1) Firmware via request-firmware interface (.bin file).
7341 * 2) Firmware residing in flash.
7342 */
7343 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7344 if (rval == QLA_SUCCESS)
7345 return rval;
7346
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007347 return qla24xx_load_risc_flash(vha, srisc_addr,
7348 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007349}
7350
7351int
7352qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7353{
7354 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007355 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007356
Andrew Vasqueze337d902009-04-06 22:33:49 -07007357 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007358 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07007359
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007360 /*
7361 * FW Load priority:
7362 * 1) Firmware residing in flash.
7363 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007364 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007365 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007366 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007367 if (rval == QLA_SUCCESS)
7368 return rval;
7369
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007370try_blob_fw:
7371 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7372 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
7373 return rval;
7374
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007375 ql_log(ql_log_info, vha, 0x0099,
7376 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007377 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
7378 if (rval != QLA_SUCCESS)
7379 return rval;
7380
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007381 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007382 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007383 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007384}
7385
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007386void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007387qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007388{
7389 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007390 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007391
Andrew Vasquez85880802009-12-15 21:29:46 -08007392 if (ha->flags.pci_channel_io_perm_failure)
7393 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07007394 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007395 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07007396 if (!ha->fw_major_version)
7397 return;
Quinn Tranec7193e2017-03-15 09:48:55 -07007398 if (!ha->flags.fw_started)
7399 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007400
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007401 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08007402 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07007403 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007404 ha->isp_ops->reset_chip(vha);
7405 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007406 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007407 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007408 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007409 ql_log(ql_log_info, vha, 0x8015,
7410 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007411 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007412 }
Quinn Tranec7193e2017-03-15 09:48:55 -07007413
Quinn Tran4b60c822017-06-13 20:47:21 -07007414 QLA_FW_STOPPED(ha);
Quinn Tranec7193e2017-03-15 09:48:55 -07007415 ha->flags.fw_init_done = 0;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007416}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007417
7418int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007419qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007420{
7421 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08007422 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007423 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007424 struct qla_hw_data *ha = vha->hw;
7425 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007426 struct req_que *req;
7427 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007428
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007429 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007430 return -EINVAL;
7431
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007432 rval = qla2x00_fw_ready(base_vha);
Michael Hernandezd7459522016-12-12 14:40:07 -08007433 if (vha->qpair)
7434 req = vha->qpair->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007435 else
Michael Hernandezd7459522016-12-12 14:40:07 -08007436 req = ha->req_q_map[0];
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007437 rsp = req->rsp;
7438
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007439 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007440 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007441 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007442 }
7443
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007444 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007445
7446 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08007447 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
7448 BIT_1);
7449 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
7450 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
7451 ql_dbg(ql_dbg_init, vha, 0x0120,
7452 "Failed SNS login: loop_id=%x, rval2=%d\n",
7453 NPH_SNS, rval2);
7454 else
7455 ql_dbg(ql_dbg_init, vha, 0x0103,
7456 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7457 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7458 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007459 return (QLA_FUNCTION_FAILED);
7460 }
7461
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007462 atomic_set(&vha->loop_down_timer, 0);
7463 atomic_set(&vha->loop_state, LOOP_UP);
7464 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7465 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
7466 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007467
7468 return rval;
7469}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007470
7471/* 84XX Support **************************************************************/
7472
7473static LIST_HEAD(qla_cs84xx_list);
7474static DEFINE_MUTEX(qla_cs84xx_mutex);
7475
7476static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007477qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007478{
7479 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007480 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007481
7482 mutex_lock(&qla_cs84xx_mutex);
7483
7484 /* Find any shared 84xx chip. */
7485 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
7486 if (cs84xx->bus == ha->pdev->bus) {
7487 kref_get(&cs84xx->kref);
7488 goto done;
7489 }
7490 }
7491
7492 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
7493 if (!cs84xx)
7494 goto done;
7495
7496 kref_init(&cs84xx->kref);
7497 spin_lock_init(&cs84xx->access_lock);
7498 mutex_init(&cs84xx->fw_update_mutex);
7499 cs84xx->bus = ha->pdev->bus;
7500
7501 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
7502done:
7503 mutex_unlock(&qla_cs84xx_mutex);
7504 return cs84xx;
7505}
7506
7507static void
7508__qla84xx_chip_release(struct kref *kref)
7509{
7510 struct qla_chip_state_84xx *cs84xx =
7511 container_of(kref, struct qla_chip_state_84xx, kref);
7512
7513 mutex_lock(&qla_cs84xx_mutex);
7514 list_del(&cs84xx->list);
7515 mutex_unlock(&qla_cs84xx_mutex);
7516 kfree(cs84xx);
7517}
7518
7519void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007520qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007521{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007522 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007523 if (ha->cs84xx)
7524 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
7525}
7526
7527static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007528qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007529{
7530 int rval;
7531 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007532 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007533
7534 mutex_lock(&ha->cs84xx->fw_update_mutex);
7535
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007536 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007537
7538 mutex_unlock(&ha->cs84xx->fw_update_mutex);
7539
7540 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
7541 QLA_SUCCESS;
7542}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007543
7544/* 81XX Support **************************************************************/
7545
7546int
7547qla81xx_nvram_config(scsi_qla_host_t *vha)
7548{
7549 int rval;
7550 struct init_cb_81xx *icb;
7551 struct nvram_81xx *nv;
7552 uint32_t *dptr;
7553 uint8_t *dptr1, *dptr2;
7554 uint32_t chksum;
7555 uint16_t cnt;
7556 struct qla_hw_data *ha = vha->hw;
7557
7558 rval = QLA_SUCCESS;
7559 icb = (struct init_cb_81xx *)ha->init_cb;
7560 nv = ha->nvram;
7561
7562 /* Determine NVRAM starting address. */
7563 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007564 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007565 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
7566 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007567
7568 /* Get VPD data into cache */
7569 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007570 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
7571 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007572
7573 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007574 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007575 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007576 dptr = (uint32_t *)nv;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05007577 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7578 chksum += le32_to_cpu(*dptr);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007579
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007580 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
7581 "Contents of NVRAM:\n");
7582 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
7583 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007584
7585 /* Bad NVRAM data, set defaults parameters. */
7586 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
7587 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07007588 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007589 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007590 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04007591 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007592 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007593 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007594 ql_log(ql_log_info, vha, 0x0074,
7595 "Falling back to functioning (yet invalid -- WWPN) "
7596 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007597
7598 /*
7599 * Set default initialization control block.
7600 */
7601 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07007602 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7603 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04007604 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07007605 nv->execution_throttle = cpu_to_le16(0xFFFF);
7606 nv->exchange_count = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007607 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007608 nv->port_name[1] = 0x00 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007609 nv->port_name[2] = 0x00;
7610 nv->port_name[3] = 0xe0;
7611 nv->port_name[4] = 0x8b;
7612 nv->port_name[5] = 0x1c;
7613 nv->port_name[6] = 0x55;
7614 nv->port_name[7] = 0x86;
7615 nv->node_name[0] = 0x20;
7616 nv->node_name[1] = 0x00;
7617 nv->node_name[2] = 0x00;
7618 nv->node_name[3] = 0xe0;
7619 nv->node_name[4] = 0x8b;
7620 nv->node_name[5] = 0x1c;
7621 nv->node_name[6] = 0x55;
7622 nv->node_name[7] = 0x86;
Bart Van Asschead950362015-07-09 07:24:08 -07007623 nv->login_retry_count = cpu_to_le16(8);
7624 nv->interrupt_delay_timer = cpu_to_le16(0);
7625 nv->login_timeout = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007626 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07007627 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7628 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7629 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7630 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7631 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7632 nv->efi_parameters = cpu_to_le32(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007633 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07007634 nv->max_luns_per_target = cpu_to_le16(128);
7635 nv->port_down_retry_count = cpu_to_le16(30);
7636 nv->link_down_timeout = cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07007637 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007638 nv->enode_mac[1] = 0xC0;
7639 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007640 nv->enode_mac[3] = 0x04;
7641 nv->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007642 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007643
7644 rval = 1;
7645 }
7646
Arun Easi9e522cd2012-08-22 14:21:31 -04007647 if (IS_T10_PI_CAPABLE(ha))
7648 nv->frame_payload_size &= ~7;
7649
Arun Easiaa230bc2013-01-30 03:34:39 -05007650 qlt_81xx_config_nvram_stage1(vha, nv);
7651
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007652 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07007653 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007654
7655 /* Copy 1st segment. */
7656 dptr1 = (uint8_t *)icb;
7657 dptr2 = (uint8_t *)&nv->version;
7658 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7659 while (cnt--)
7660 *dptr1++ = *dptr2++;
7661
7662 icb->login_retry_count = nv->login_retry_count;
7663
7664 /* Copy 2nd segment. */
7665 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7666 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7667 cnt = (uint8_t *)&icb->reserved_5 -
7668 (uint8_t *)&icb->interrupt_delay_timer;
7669 while (cnt--)
7670 *dptr1++ = *dptr2++;
7671
7672 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
7673 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
7674 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08007675 icb->enode_mac[0] = 0x00;
7676 icb->enode_mac[1] = 0xC0;
7677 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007678 icb->enode_mac[3] = 0x04;
7679 icb->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007680 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007681 }
7682
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07007683 /* Use extended-initialization control block. */
7684 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
7685
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007686 /*
7687 * Setup driver NVRAM options.
7688 */
7689 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07007690 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007691
Arun Easiaa230bc2013-01-30 03:34:39 -05007692 qlt_81xx_config_nvram_stage2(vha, icb);
7693
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007694 /* Use alternate WWN? */
Bart Van Asschead950362015-07-09 07:24:08 -07007695 if (nv->host_p & cpu_to_le32(BIT_15)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007696 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7697 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7698 }
7699
7700 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07007701 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007702 /*
7703 * Firmware will apply the following mask if the nodename was
7704 * not provided.
7705 */
7706 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7707 icb->node_name[0] &= 0xF0;
7708 }
7709
7710 /* Set host adapter parameters. */
7711 ha->flags.disable_risc_code_load = 0;
7712 ha->flags.enable_lip_reset = 0;
7713 ha->flags.enable_lip_full_login =
7714 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
7715 ha->flags.enable_target_reset =
7716 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
7717 ha->flags.enable_led_scheme = 0;
7718 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
7719
7720 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7721 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7722
7723 /* save HBA serial number */
7724 ha->serial0 = icb->port_name[5];
7725 ha->serial1 = icb->port_name[6];
7726 ha->serial2 = icb->port_name[7];
7727 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7728 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7729
Bart Van Asschead950362015-07-09 07:24:08 -07007730 icb->execution_throttle = cpu_to_le16(0xFFFF);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007731
7732 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7733
7734 /* Set minimum login_timeout to 4 seconds. */
7735 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7736 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7737 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07007738 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007739 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007740
7741 /* Set minimum RATOV to 100 tenths of a second. */
7742 ha->r_a_tov = 100;
7743
7744 ha->loop_reset_delay = nv->reset_delay;
7745
7746 /* Link Down Timeout = 0:
7747 *
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007748 * When Port Down timer expires we will start returning
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007749 * I/O's to OS with "DID_NO_CONNECT".
7750 *
7751 * Link Down Timeout != 0:
7752 *
7753 * The driver waits for the link to come up after link down
7754 * before returning I/Os to OS with "DID_NO_CONNECT".
7755 */
7756 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7757 ha->loop_down_abort_time =
7758 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7759 } else {
7760 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7761 ha->loop_down_abort_time =
7762 (LOOP_DOWN_TIME - ha->link_down_timeout);
7763 }
7764
7765 /* Need enough time to try and get the port back. */
7766 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7767 if (qlport_down_retry)
7768 ha->port_down_retry_count = qlport_down_retry;
7769
7770 /* Set login_retry_count */
7771 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7772 if (ha->port_down_retry_count ==
7773 le16_to_cpu(nv->port_down_retry_count) &&
7774 ha->port_down_retry_count > 3)
7775 ha->login_retry_count = ha->port_down_retry_count;
7776 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7777 ha->login_retry_count = ha->port_down_retry_count;
7778 if (ql2xloginretrycount)
7779 ha->login_retry_count = ql2xloginretrycount;
7780
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007781 /* if not running MSI-X we need handshaking on interrupts */
Chad Dupuisf73cb692014-02-26 04:15:06 -05007782 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
Bart Van Asschead950362015-07-09 07:24:08 -07007783 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007784
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007785 /* Enable ZIO. */
7786 if (!vha->flags.init_done) {
7787 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7788 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7789 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7790 le16_to_cpu(icb->interrupt_delay_timer): 2;
7791 }
Bart Van Asschead950362015-07-09 07:24:08 -07007792 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007793 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7794 vha->flags.process_response_queue = 0;
7795 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7796 ha->zio_mode = QLA_ZIO_MODE_6;
7797
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007798 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007799 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007800 ha->zio_mode,
7801 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007802
7803 icb->firmware_options_2 |= cpu_to_le32(
7804 (uint32_t)ha->zio_mode);
7805 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7806 vha->flags.process_response_queue = 1;
7807 }
7808
Quinn Tran41dc5292017-01-19 22:28:03 -08007809 /* enable RIDA Format2 */
7810 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))
7811 icb->firmware_options_3 |= BIT_0;
7812
Duane Grigsbyedd05de2017-10-13 09:34:06 -07007813 if (IS_QLA27XX(ha)) {
7814 icb->firmware_options_3 |= BIT_8;
7815 ql_dbg(ql_log_info, vha, 0x0075,
7816 "Enabling direct connection.\n");
7817 }
7818
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007819 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007820 ql_log(ql_log_warn, vha, 0x0076,
7821 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007822 }
7823 return (rval);
7824}
7825
Giridhar Malavalia9083012010-04-12 17:59:55 -07007826int
7827qla82xx_restart_isp(scsi_qla_host_t *vha)
7828{
7829 int status, rval;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007830 struct qla_hw_data *ha = vha->hw;
7831 struct req_que *req = ha->req_q_map[0];
7832 struct rsp_que *rsp = ha->rsp_q_map[0];
7833 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07007834 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007835
7836 status = qla2x00_init_rings(vha);
7837 if (!status) {
7838 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7839 ha->flags.chip_reset_done = 1;
7840
7841 status = qla2x00_fw_ready(vha);
7842 if (!status) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07007843 /* Issue a marker after FW becomes ready. */
7844 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007845 vha->flags.online = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04007846 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007847 }
7848
7849 /* if no cable then assume it's good */
7850 if ((vha->device_flags & DFLG_NO_CABLE))
7851 status = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007852 }
7853
7854 if (!status) {
7855 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7856
7857 if (!atomic_read(&vha->loop_down_timer)) {
7858 /*
7859 * Issue marker command only when we are going
7860 * to start the I/O .
7861 */
7862 vha->marker_needed = 1;
7863 }
7864
Giridhar Malavalia9083012010-04-12 17:59:55 -07007865 ha->isp_ops->enable_intrs(ha);
7866
7867 ha->isp_abort_cnt = 0;
7868 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7869
Saurav Kashyap53296782011-05-10 11:30:06 -07007870 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07007871 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07007872
Giridhar Malavalia9083012010-04-12 17:59:55 -07007873 if (ha->fce) {
7874 ha->flags.fce_enabled = 1;
7875 memset(ha->fce, 0,
7876 fce_calc_size(ha->fce_bufs));
7877 rval = qla2x00_enable_fce_trace(vha,
7878 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
7879 &ha->fce_bufs);
7880 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007881 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007882 "Unable to reinitialize FCE (%d).\n",
7883 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007884 ha->flags.fce_enabled = 0;
7885 }
7886 }
7887
7888 if (ha->eft) {
7889 memset(ha->eft, 0, EFT_SIZE);
7890 rval = qla2x00_enable_eft_trace(vha,
7891 ha->eft_dma, EFT_NUM_BUFFERS);
7892 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007893 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007894 "Unable to reinitialize EFT (%d).\n",
7895 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007896 }
7897 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07007898 }
7899
7900 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007901 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007902 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07007903
7904 spin_lock_irqsave(&ha->vport_slock, flags);
7905 list_for_each_entry(vp, &ha->vp_list, list) {
7906 if (vp->vp_idx) {
7907 atomic_inc(&vp->vref_count);
7908 spin_unlock_irqrestore(&ha->vport_slock, flags);
7909
Giridhar Malavalia9083012010-04-12 17:59:55 -07007910 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07007911
7912 spin_lock_irqsave(&ha->vport_slock, flags);
7913 atomic_dec(&vp->vref_count);
7914 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07007915 }
Arun Easifeafb7b2010-09-03 14:57:00 -07007916 spin_unlock_irqrestore(&ha->vport_slock, flags);
7917
Giridhar Malavalia9083012010-04-12 17:59:55 -07007918 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007919 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007920 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07007921 }
7922
7923 return status;
7924}
7925
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007926void
Andrew Vasquezae97c912010-02-18 10:07:28 -08007927qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007928{
Andrew Vasquezae97c912010-02-18 10:07:28 -08007929 struct qla_hw_data *ha = vha->hw;
7930
Himanshu Madhanif198caf2016-01-27 12:03:30 -05007931 /* Hold status IOCBs until ABTS response received. */
7932 if (ql2xfwholdabts)
7933 ha->fw_options[3] |= BIT_12;
7934
Giridhar Malavali088d09d2016-07-06 11:14:20 -04007935 /* Set Retry FLOGI in case of P2P connection */
7936 if (ha->operating_mode == P2P) {
7937 ha->fw_options[2] |= BIT_3;
7938 ql_dbg(ql_dbg_disc, vha, 0x2103,
7939 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
7940 __func__, ha->fw_options[2]);
7941 }
7942
Quinn Tran41dc5292017-01-19 22:28:03 -08007943 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
7944 if (ql2xmvasynctoatio) {
7945 if (qla_tgt_mode_enabled(vha) ||
7946 qla_dual_mode_enabled(vha))
7947 ha->fw_options[2] |= BIT_11;
7948 else
7949 ha->fw_options[2] &= ~BIT_11;
7950 }
Andrew Vasquezae97c912010-02-18 10:07:28 -08007951
Quinn Tranf7e761f2017-06-02 09:12:02 -07007952 if (qla_tgt_mode_enabled(vha) ||
Quinn Tran2da52732017-06-02 09:12:05 -07007953 qla_dual_mode_enabled(vha)) {
7954 /* FW auto send SCSI status during */
7955 ha->fw_options[1] |= BIT_8;
7956 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
7957
7958 /* FW perform Exchange validation */
Quinn Tranf7e761f2017-06-02 09:12:02 -07007959 ha->fw_options[2] |= BIT_4;
Quinn Tran2da52732017-06-02 09:12:05 -07007960 } else {
7961 ha->fw_options[1] &= ~BIT_8;
7962 ha->fw_options[10] &= 0x00ff;
7963
Quinn Tranf7e761f2017-06-02 09:12:02 -07007964 ha->fw_options[2] &= ~BIT_4;
Quinn Tran2da52732017-06-02 09:12:05 -07007965 }
Quinn Tranf7e761f2017-06-02 09:12:02 -07007966
Quinn Tran41dc5292017-01-19 22:28:03 -08007967 if (ql2xetsenable) {
7968 /* Enable ETS Burst. */
7969 memset(ha->fw_options, 0, sizeof(ha->fw_options));
7970 ha->fw_options[2] |= BIT_9;
7971 }
7972
Quinn Tran83548fe2017-06-02 09:12:01 -07007973 ql_dbg(ql_dbg_init, vha, 0x00e9,
7974 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
7975 __func__, ha->fw_options[1], ha->fw_options[2],
7976 ha->fw_options[3], vha->host->active_mode);
Quinn Tran41dc5292017-01-19 22:28:03 -08007977
Andrew Vasquezae97c912010-02-18 10:07:28 -08007978 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007979}
Sarang Radke09ff7012010-03-19 17:03:59 -07007980
7981/*
7982 * qla24xx_get_fcp_prio
7983 * Gets the fcp cmd priority value for the logged in port.
7984 * Looks for a match of the port descriptors within
7985 * each of the fcp prio config entries. If a match is found,
7986 * the tag (priority) value is returned.
7987 *
7988 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007989 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07007990 * fcport = port structure pointer.
7991 *
7992 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07007993 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007994 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07007995 *
7996 * Context:
7997 * Kernel context
7998 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007999static int
Sarang Radke09ff7012010-03-19 17:03:59 -07008000qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8001{
8002 int i, entries;
8003 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008004 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07008005 uint32_t pid1, pid2;
8006 uint64_t wwn1, wwn2;
8007 struct qla_fcp_prio_entry *pri_entry;
8008 struct qla_hw_data *ha = vha->hw;
8009
8010 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008011 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07008012
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008013 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07008014 entries = ha->fcp_prio_cfg->num_entries;
8015 pri_entry = &ha->fcp_prio_cfg->entry[0];
8016
8017 for (i = 0; i < entries; i++) {
8018 pid_match = wwn_match = 0;
8019
8020 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8021 pri_entry++;
8022 continue;
8023 }
8024
8025 /* check source pid for a match */
8026 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8027 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8028 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8029 if (pid1 == INVALID_PORT_ID)
8030 pid_match++;
8031 else if (pid1 == pid2)
8032 pid_match++;
8033 }
8034
8035 /* check destination pid for a match */
8036 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8037 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8038 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8039 if (pid1 == INVALID_PORT_ID)
8040 pid_match++;
8041 else if (pid1 == pid2)
8042 pid_match++;
8043 }
8044
8045 /* check source WWN for a match */
8046 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8047 wwn1 = wwn_to_u64(vha->port_name);
8048 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8049 if (wwn2 == (uint64_t)-1)
8050 wwn_match++;
8051 else if (wwn1 == wwn2)
8052 wwn_match++;
8053 }
8054
8055 /* check destination WWN for a match */
8056 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8057 wwn1 = wwn_to_u64(fcport->port_name);
8058 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8059 if (wwn2 == (uint64_t)-1)
8060 wwn_match++;
8061 else if (wwn1 == wwn2)
8062 wwn_match++;
8063 }
8064
8065 if (pid_match == 2 || wwn_match == 2) {
8066 /* Found a matching entry */
8067 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8068 priority = pri_entry->tag;
8069 break;
8070 }
8071
8072 pri_entry++;
8073 }
8074
8075 return priority;
8076}
8077
8078/*
8079 * qla24xx_update_fcport_fcp_prio
8080 * Activates fcp priority for the logged in fc port
8081 *
8082 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008083 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07008084 * fcp = port structure pointer.
8085 *
8086 * Return:
8087 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8088 *
8089 * Context:
8090 * Kernel context.
8091 */
8092int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008093qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07008094{
8095 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008096 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07008097 uint16_t mb[5];
8098
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008099 if (fcport->port_type != FCT_TARGET ||
8100 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07008101 return QLA_FUNCTION_FAILED;
8102
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008103 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008104 if (priority < 0)
8105 return QLA_FUNCTION_FAILED;
8106
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04008107 if (IS_P3P_TYPE(vha->hw)) {
Saurav Kashyapa00f6292011-11-18 09:03:19 -08008108 fcport->fcp_prio = priority & 0xf;
8109 return QLA_SUCCESS;
8110 }
8111
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008112 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08008113 if (ret == QLA_SUCCESS) {
8114 if (fcport->fcp_prio != priority)
8115 ql_dbg(ql_dbg_user, vha, 0x709e,
8116 "Updated FCP_CMND priority - value=%d loop_id=%d "
8117 "port_id=%02x%02x%02x.\n", priority,
8118 fcport->loop_id, fcport->d_id.b.domain,
8119 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08008120 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08008121 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07008122 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08008123 "Unable to update FCP_CMND priority - ret=0x%x for "
8124 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8125 fcport->d_id.b.domain, fcport->d_id.b.area,
8126 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07008127 return ret;
8128}
8129
8130/*
8131 * qla24xx_update_all_fcp_prio
8132 * Activates fcp priority for all the logged in ports
8133 *
8134 * Input:
8135 * ha = adapter block pointer.
8136 *
8137 * Return:
8138 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8139 *
8140 * Context:
8141 * Kernel context.
8142 */
8143int
8144qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8145{
8146 int ret;
8147 fc_port_t *fcport;
8148
8149 ret = QLA_FUNCTION_FAILED;
8150 /* We need to set priority for all logged in ports */
8151 list_for_each_entry(fcport, &vha->vp_fcports, list)
8152 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8153
8154 return ret;
8155}
Michael Hernandezd7459522016-12-12 14:40:07 -08008156
Quinn Tran82de8022017-06-13 20:47:17 -07008157struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8158 int vp_idx, bool startqp)
Michael Hernandezd7459522016-12-12 14:40:07 -08008159{
8160 int rsp_id = 0;
8161 int req_id = 0;
8162 int i;
8163 struct qla_hw_data *ha = vha->hw;
8164 uint16_t qpair_id = 0;
8165 struct qla_qpair *qpair = NULL;
8166 struct qla_msix_entry *msix;
8167
8168 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8169 ql_log(ql_log_warn, vha, 0x00181,
8170 "FW/Driver is not multi-queue capable.\n");
8171 return NULL;
8172 }
8173
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07008174 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08008175 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8176 if (qpair == NULL) {
8177 ql_log(ql_log_warn, vha, 0x0182,
8178 "Failed to allocate memory for queue pair.\n");
8179 return NULL;
8180 }
8181 memset(qpair, 0, sizeof(struct qla_qpair));
8182
8183 qpair->hw = vha->hw;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08008184 qpair->vha = vha;
Quinn Tran82de8022017-06-13 20:47:17 -07008185 qpair->qp_lock_ptr = &qpair->qp_lock;
8186 spin_lock_init(&qpair->qp_lock);
Quinn Tranaf7bb382017-06-13 20:47:23 -07008187 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
Michael Hernandezd7459522016-12-12 14:40:07 -08008188
8189 /* Assign available que pair id */
8190 mutex_lock(&ha->mq_lock);
8191 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
Sawan Chandakb95b9452017-05-24 18:06:20 -07008192 if (ha->num_qpairs >= ha->max_qpairs) {
Michael Hernandezd7459522016-12-12 14:40:07 -08008193 mutex_unlock(&ha->mq_lock);
8194 ql_log(ql_log_warn, vha, 0x0183,
8195 "No resources to create additional q pair.\n");
8196 goto fail_qid_map;
8197 }
Sawan Chandakb95b9452017-05-24 18:06:20 -07008198 ha->num_qpairs++;
Michael Hernandezd7459522016-12-12 14:40:07 -08008199 set_bit(qpair_id, ha->qpair_qid_map);
8200 ha->queue_pair_map[qpair_id] = qpair;
8201 qpair->id = qpair_id;
8202 qpair->vp_idx = vp_idx;
himanshu.madhani@cavium.come6373f332017-08-23 15:04:57 -07008203 qpair->fw_started = ha->flags.fw_started;
Quinn Trane326d222017-06-13 20:47:18 -07008204 INIT_LIST_HEAD(&qpair->hints_list);
Duane Grigsbycf19c452017-08-23 15:04:58 -07008205 INIT_LIST_HEAD(&qpair->nvme_done_list);
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07008206 qpair->chip_reset = ha->base_qpair->chip_reset;
8207 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8208 qpair->enable_explicit_conf =
8209 ha->base_qpair->enable_explicit_conf;
Michael Hernandezd7459522016-12-12 14:40:07 -08008210
8211 for (i = 0; i < ha->msix_count; i++) {
Quinn Tran093df732016-12-12 14:40:09 -08008212 msix = &ha->msix_entries[i];
Michael Hernandezd7459522016-12-12 14:40:07 -08008213 if (msix->in_use)
8214 continue;
8215 qpair->msix = msix;
Quinn Tran83548fe2017-06-02 09:12:01 -07008216 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
Michael Hernandezd7459522016-12-12 14:40:07 -08008217 "Vector %x selected for qpair\n", msix->vector);
8218 break;
8219 }
8220 if (!qpair->msix) {
8221 ql_log(ql_log_warn, vha, 0x0184,
8222 "Out of MSI-X vectors!.\n");
8223 goto fail_msix;
8224 }
8225
8226 qpair->msix->in_use = 1;
8227 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
Quinn Tran8abfa9e2017-06-13 20:47:24 -07008228 qpair->pdev = ha->pdev;
8229 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
8230 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
Michael Hernandezd7459522016-12-12 14:40:07 -08008231
8232 mutex_unlock(&ha->mq_lock);
8233
8234 /* Create response queue first */
Quinn Tran82de8022017-06-13 20:47:17 -07008235 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
Michael Hernandezd7459522016-12-12 14:40:07 -08008236 if (!rsp_id) {
8237 ql_log(ql_log_warn, vha, 0x0185,
8238 "Failed to create response queue.\n");
8239 goto fail_rsp;
8240 }
8241
8242 qpair->rsp = ha->rsp_q_map[rsp_id];
8243
8244 /* Create request queue */
Quinn Tran82de8022017-06-13 20:47:17 -07008245 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
8246 startqp);
Michael Hernandezd7459522016-12-12 14:40:07 -08008247 if (!req_id) {
8248 ql_log(ql_log_warn, vha, 0x0186,
8249 "Failed to create request queue.\n");
8250 goto fail_req;
8251 }
8252
8253 qpair->req = ha->req_q_map[req_id];
8254 qpair->rsp->req = qpair->req;
Quinn Tran82de8022017-06-13 20:47:17 -07008255 qpair->rsp->qpair = qpair;
Quinn Trane326d222017-06-13 20:47:18 -07008256 /* init qpair to this cpu. Will adjust at run time. */
8257 qla_cpu_update(qpair, smp_processor_id());
Michael Hernandezd7459522016-12-12 14:40:07 -08008258
8259 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
8260 if (ha->fw_attributes & BIT_4)
8261 qpair->difdix_supported = 1;
8262 }
8263
8264 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
8265 if (!qpair->srb_mempool) {
Quinn Tran83548fe2017-06-02 09:12:01 -07008266 ql_log(ql_log_warn, vha, 0xd036,
Michael Hernandezd7459522016-12-12 14:40:07 -08008267 "Failed to create srb mempool for qpair %d\n",
8268 qpair->id);
8269 goto fail_mempool;
8270 }
8271
8272 /* Mark as online */
8273 qpair->online = 1;
8274
8275 if (!vha->flags.qpairs_available)
8276 vha->flags.qpairs_available = 1;
8277
8278 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
8279 "Request/Response queue pair created, id %d\n",
8280 qpair->id);
8281 ql_dbg(ql_dbg_init, vha, 0x0187,
8282 "Request/Response queue pair created, id %d\n",
8283 qpair->id);
8284 }
8285 return qpair;
8286
8287fail_mempool:
8288fail_req:
8289 qla25xx_delete_rsp_que(vha, qpair->rsp);
8290fail_rsp:
8291 mutex_lock(&ha->mq_lock);
8292 qpair->msix->in_use = 0;
8293 list_del(&qpair->qp_list_elem);
8294 if (list_empty(&vha->qp_list))
8295 vha->flags.qpairs_available = 0;
8296fail_msix:
8297 ha->queue_pair_map[qpair_id] = NULL;
8298 clear_bit(qpair_id, ha->qpair_qid_map);
Sawan Chandakb95b9452017-05-24 18:06:20 -07008299 ha->num_qpairs--;
Michael Hernandezd7459522016-12-12 14:40:07 -08008300 mutex_unlock(&ha->mq_lock);
8301fail_qid_map:
8302 kfree(qpair);
8303 return NULL;
8304}
8305
8306int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
8307{
Sawan Chandakd65237c2017-06-13 20:47:19 -07008308 int ret = QLA_FUNCTION_FAILED;
Michael Hernandezd7459522016-12-12 14:40:07 -08008309 struct qla_hw_data *ha = qpair->hw;
8310
8311 qpair->delete_in_progress = 1;
8312 while (atomic_read(&qpair->ref_count))
8313 msleep(500);
8314
8315 ret = qla25xx_delete_req_que(vha, qpair->req);
8316 if (ret != QLA_SUCCESS)
8317 goto fail;
himanshu.madhani@cavium.com7867b982017-12-04 14:45:16 -08008318
Michael Hernandezd7459522016-12-12 14:40:07 -08008319 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
8320 if (ret != QLA_SUCCESS)
8321 goto fail;
8322
8323 mutex_lock(&ha->mq_lock);
8324 ha->queue_pair_map[qpair->id] = NULL;
8325 clear_bit(qpair->id, ha->qpair_qid_map);
Sawan Chandakb95b9452017-05-24 18:06:20 -07008326 ha->num_qpairs--;
Michael Hernandezd7459522016-12-12 14:40:07 -08008327 list_del(&qpair->qp_list_elem);
Sawan Chandakd65237c2017-06-13 20:47:19 -07008328 if (list_empty(&vha->qp_list)) {
Michael Hernandezd7459522016-12-12 14:40:07 -08008329 vha->flags.qpairs_available = 0;
Sawan Chandakd65237c2017-06-13 20:47:19 -07008330 vha->flags.qpairs_req_created = 0;
8331 vha->flags.qpairs_rsp_created = 0;
8332 }
Michael Hernandezd7459522016-12-12 14:40:07 -08008333 mempool_destroy(qpair->srb_mempool);
8334 kfree(qpair);
8335 mutex_unlock(&ha->mq_lock);
8336
8337 return QLA_SUCCESS;
8338fail:
8339 return ret;
8340}