blob: 7b675243bd16c61a703cffa69c0f5f0a55a62ea6 [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 Trana4239942017-12-28 12:33:26 -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 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -070063}
64
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080065void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080066qla2x00_sp_free(void *ptr)
Andrew Vasquezac280b62009-08-20 11:06:05 -070067{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080068 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080069 struct srb_iocb *iocb = &sp->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -070070
Chad Dupuis4d97cc52010-10-15 11:27:41 -070071 del_timer(&iocb->timer);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080072 qla2x00_rel_sp(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -070073}
74
Andrew Vasquezac280b62009-08-20 11:06:05 -070075/* Asynchronous Login/Logout Routines -------------------------------------- */
76
Saurav Kashyapa9b6f722012-08-22 14:21:01 -040077unsigned long
Andrew Vasquez5b914902010-05-28 15:08:30 -070078qla2x00_get_async_timeout(struct scsi_qla_host *vha)
79{
80 unsigned long tmo;
81 struct qla_hw_data *ha = vha->hw;
82
83 /* Firmware should use switch negotiated r_a_tov for timeout. */
84 tmo = ha->r_a_tov / 10 * 2;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040085 if (IS_QLAFX00(ha)) {
86 tmo = FX00_DEF_RATOV * 2;
87 } else if (!IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez5b914902010-05-28 15:08:30 -070088 /*
89 * Except for earlier ISPs where the timeout is seeded from the
90 * initialization control block.
91 */
92 tmo = ha->login_timeout;
93 }
94 return tmo;
95}
Andrew Vasquezac280b62009-08-20 11:06:05 -070096
Quinn Tran726b8542017-01-19 22:28:00 -080097void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080098qla2x00_async_iocb_timeout(void *data)
Andrew Vasquezac280b62009-08-20 11:06:05 -070099{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800100 srb_t *sp = data;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700101 fc_port_t *fcport = sp->fcport;
Quinn Tran726b8542017-01-19 22:28:00 -0800102 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700103
Quinn Tran5c25d452017-12-28 12:33:09 -0800104 if (fcport) {
105 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
106 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
107 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700108
Quinn Tran6d6749272017-12-28 12:33:41 -0800109 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
Quinn Tran5c25d452017-12-28 12:33:09 -0800110 } else {
111 pr_info("Async-%s timeout - hdl=%x.\n",
112 sp->name, sp->handle);
113 }
Quinn Tran726b8542017-01-19 22:28:00 -0800114
115 switch (sp->type) {
116 case SRB_LOGIN_CMD:
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700117 /* Retry as needed. */
118 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
119 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
120 QLA_LOGIO_LOGIN_RETRIED : 0;
Quinn Traneaf75d12018-02-01 10:33:17 -0800121 sp->done(sp, QLA_FUNCTION_TIMEOUT);
Quinn Tran726b8542017-01-19 22:28:00 -0800122 break;
123 case SRB_LOGOUT_CMD:
Quinn Tran726b8542017-01-19 22:28:00 -0800124 case SRB_CT_PTHRU_CMD:
125 case SRB_MB_IOCB:
126 case SRB_NACK_PLOGI:
127 case SRB_NACK_PRLI:
128 case SRB_NACK_LOGO:
Quinn Tran28531922017-12-28 12:33:10 -0800129 case SRB_CTRL_VP:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800130 sp->done(sp, QLA_FUNCTION_TIMEOUT);
Quinn Tran726b8542017-01-19 22:28:00 -0800131 break;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700132 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700133}
134
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700135static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800136qla2x00_async_login_sp_done(void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700137{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800138 srb_t *sp = ptr;
139 struct scsi_qla_host *vha = sp->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800140 struct srb_iocb *lio = &sp->u.iocb_cmd;
Quinn Tran726b8542017-01-19 22:28:00 -0800141 struct event_arg ea;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700142
Quinn Tran83548fe2017-06-02 09:12:01 -0700143 ql_dbg(ql_dbg_disc, vha, 0x20dd,
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800144 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
Quinn Tran726b8542017-01-19 22:28:00 -0800145
Quinn Tran6d6749272017-12-28 12:33:41 -0800146 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
147
Quinn Tran726b8542017-01-19 22:28:00 -0800148 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
149 memset(&ea, 0, sizeof(ea));
150 ea.event = FCME_PLOGI_DONE;
151 ea.fcport = sp->fcport;
152 ea.data[0] = lio->u.logio.data[0];
153 ea.data[1] = lio->u.logio.data[1];
154 ea.iop[0] = lio->u.logio.iop[0];
155 ea.iop[1] = lio->u.logio.iop[1];
156 ea.sp = sp;
157 qla2x00_fcport_event_handler(vha, &ea);
158 }
159
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800160 sp->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700161}
162
Andrew Vasquezac280b62009-08-20 11:06:05 -0700163int
164qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
165 uint16_t *data)
166{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700167 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700168 struct srb_iocb *lio;
Quinn Tran726b8542017-01-19 22:28:00 -0800169 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700170
Quinn Tran726b8542017-01-19 22:28:00 -0800171 if (!vha->flags.online)
172 goto done;
173
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800174 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700175 if (!sp)
176 goto done;
177
Quinn Tran726b8542017-01-19 22:28:00 -0800178 fcport->flags |= FCF_ASYNC_SENT;
179 fcport->logout_completed = 0;
180
Quinn Trana4239942017-12-28 12:33:26 -0800181 fcport->disc_state = DSC_LOGIN_PEND;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800182 sp->type = SRB_LOGIN_CMD;
183 sp->name = "login";
Quinn Trana4239942017-12-28 12:33:26 -0800184 sp->gen1 = fcport->rscn_gen;
185 sp->gen2 = fcport->login_gen;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800186
187 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700188 lio->timeout = qla2x00_async_iocb_timeout;
Ben Hutchingse74e7d92018-03-20 21:36:14 +0000189 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
190
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800191 sp->done = qla2x00_async_login_sp_done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700192 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700193
194 if (fcport->fc4f_nvme)
195 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
196
Andrew Vasquezac280b62009-08-20 11:06:05 -0700197 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700198 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700199 rval = qla2x00_start_sp(sp);
Chad Dupuis080c9512016-01-27 12:03:37 -0500200 if (rval != QLA_SUCCESS) {
Chad Dupuis080c9512016-01-27 12:03:37 -0500201 fcport->flags |= FCF_LOGIN_NEEDED;
202 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700203 goto done_free_sp;
Chad Dupuis080c9512016-01-27 12:03:37 -0500204 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700205
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700206 ql_dbg(ql_dbg_disc, vha, 0x2072,
Quinn Tran726b8542017-01-19 22:28:00 -0800207 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
208 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800209 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
210 fcport->login_retry);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700211 return rval;
212
213done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800214 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800215 fcport->flags &= ~FCF_ASYNC_SENT;
Quinn Tran3dbec592017-12-28 12:33:40 -0800216done:
Hannes Reineckefa83e652018-02-22 09:49:37 +0100217 fcport->flags &= ~FCF_ASYNC_ACTIVE;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700218 return rval;
219}
220
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700221static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800222qla2x00_async_logout_sp_done(void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700223{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800224 srb_t *sp = ptr;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700225
Quinn Tran6d6749272017-12-28 12:33:41 -0800226 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
Quinn Traneaf75d12018-02-01 10:33:17 -0800227 sp->fcport->login_gen++;
228 qlt_logo_completion_handler(sp->fcport, res);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800229 sp->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700230}
231
Andrew Vasquezac280b62009-08-20 11:06:05 -0700232int
233qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
234{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700235 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700236 struct srb_iocb *lio;
Quinn Tran3dbec592017-12-28 12:33:40 -0800237 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700238
Quinn Tran3dbec592017-12-28 12:33:40 -0800239 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
240 return rval;
241
Quinn Tran726b8542017-01-19 22:28:00 -0800242 fcport->flags |= FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800243 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700244 if (!sp)
245 goto done;
246
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800247 sp->type = SRB_LOGOUT_CMD;
248 sp->name = "logout";
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800249
250 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700251 lio->timeout = qla2x00_async_iocb_timeout;
Ben Hutchingse74e7d92018-03-20 21:36:14 +0000252 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
253
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800254 sp->done = qla2x00_async_logout_sp_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700255 rval = qla2x00_start_sp(sp);
256 if (rval != QLA_SUCCESS)
257 goto done_free_sp;
258
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700259 ql_dbg(ql_dbg_disc, vha, 0x2070,
Quinn Tran726b8542017-01-19 22:28:00 -0800260 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -0800261 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
Quinn Tran726b8542017-01-19 22:28:00 -0800262 fcport->d_id.b.area, fcport->d_id.b.al_pa,
263 fcport->port_name);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700264 return rval;
265
266done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800267 sp->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700268done:
Hannes Reineckefa83e652018-02-22 09:49:37 +0100269 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700270 return rval;
271}
Quinn Tran11aea162017-12-28 12:33:20 -0800272
273void
274qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
275 uint16_t *data)
276{
Hannes Reineckefa83e652018-02-22 09:49:37 +0100277 fcport->flags &= ~FCF_ASYNC_ACTIVE;
Quinn Tran11aea162017-12-28 12:33:20 -0800278 /* Don't re-login in target mode */
279 if (!fcport->tgt_session)
280 qla2x00_mark_device_lost(vha, fcport, 1, 0);
281 qlt_logo_completion_handler(fcport, data[0]);
282}
283
284static void
285qla2x00_async_prlo_sp_done(void *s, int res)
286{
287 srb_t *sp = (srb_t *)s;
288 struct srb_iocb *lio = &sp->u.iocb_cmd;
289 struct scsi_qla_host *vha = sp->vha;
290
Hannes Reineckefa83e652018-02-22 09:49:37 +0100291 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
Quinn Tran11aea162017-12-28 12:33:20 -0800292 if (!test_bit(UNLOADING, &vha->dpc_flags))
293 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
294 lio->u.logio.data);
295 sp->free(sp);
296}
297
298int
299qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
300{
301 srb_t *sp;
302 struct srb_iocb *lio;
303 int rval;
304
305 rval = QLA_FUNCTION_FAILED;
306 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
307 if (!sp)
308 goto done;
309
310 sp->type = SRB_PRLO_CMD;
311 sp->name = "prlo";
Quinn Tran11aea162017-12-28 12:33:20 -0800312
313 lio = &sp->u.iocb_cmd;
314 lio->timeout = qla2x00_async_iocb_timeout;
Ben Hutchingse74e7d92018-03-20 21:36:14 +0000315 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
316
Quinn Tran11aea162017-12-28 12:33:20 -0800317 sp->done = qla2x00_async_prlo_sp_done;
318 rval = qla2x00_start_sp(sp);
319 if (rval != QLA_SUCCESS)
320 goto done_free_sp;
321
322 ql_dbg(ql_dbg_disc, vha, 0x2070,
323 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
324 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
325 fcport->d_id.b.area, fcport->d_id.b.al_pa);
326 return rval;
327
328done_free_sp:
329 sp->free(sp);
330done:
Hannes Reineckefa83e652018-02-22 09:49:37 +0100331 fcport->flags &= ~FCF_ASYNC_ACTIVE;
Quinn Tran11aea162017-12-28 12:33:20 -0800332 return rval;
333}
334
Quinn Tranf13515a2017-12-28 12:33:15 -0800335static
336void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
337{
Quinn Tran0616e962017-12-28 12:33:34 -0800338 struct fc_port *fcport = ea->fcport;
339
340 ql_dbg(ql_dbg_disc, vha, 0x20d2,
341 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
342 __func__, fcport->port_name, fcport->disc_state,
343 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
344 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
345
346 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
Quinn Trana4239942017-12-28 12:33:26 -0800347 ql_dbg(ql_dbg_disc, vha, 0x2066,
348 "%s %8phC: adisc fail: post delete\n",
349 __func__, ea->fcport->port_name);
Quinn Tran94cff6e2017-12-28 12:33:42 -0800350 qlt_schedule_sess_for_deletion(ea->fcport);
Quinn Trana4239942017-12-28 12:33:26 -0800351 return;
352 }
Quinn Trana4239942017-12-28 12:33:26 -0800353
354 if (ea->fcport->disc_state == DSC_DELETE_PEND)
355 return;
356
357 if (ea->sp->gen2 != ea->fcport->login_gen) {
358 /* target side must have changed it. */
359 ql_dbg(ql_dbg_disc, vha, 0x20d3,
Quinn Tran0616e962017-12-28 12:33:34 -0800360 "%s %8phC generation changed\n",
361 __func__, ea->fcport->port_name);
Quinn Trana4239942017-12-28 12:33:26 -0800362 return;
363 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
364 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
365 __func__, __LINE__, ea->fcport->port_name);
366 qla24xx_post_gidpn_work(vha, ea->fcport);
367 return;
368 }
369
370 __qla24xx_handle_gpdb_event(vha, ea);
Quinn Tranf13515a2017-12-28 12:33:15 -0800371}
Andrew Vasquezac280b62009-08-20 11:06:05 -0700372
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700373static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800374qla2x00_async_adisc_sp_done(void *ptr, int res)
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700375{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800376 srb_t *sp = ptr;
377 struct scsi_qla_host *vha = sp->vha;
Quinn Tranf13515a2017-12-28 12:33:15 -0800378 struct event_arg ea;
Quinn Tran0616e962017-12-28 12:33:34 -0800379 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700380
Quinn Tranf13515a2017-12-28 12:33:15 -0800381 ql_dbg(ql_dbg_disc, vha, 0x2066,
382 "Async done-%s res %x %8phC\n",
383 sp->name, res, sp->fcport->port_name);
384
Hannes Reineckefa83e652018-02-22 09:49:37 +0100385 sp->fcport->flags &= ~FCF_ASYNC_SENT;
386
Quinn Tranf13515a2017-12-28 12:33:15 -0800387 memset(&ea, 0, sizeof(ea));
388 ea.event = FCME_ADISC_DONE;
389 ea.rc = res;
Quinn Tran0616e962017-12-28 12:33:34 -0800390 ea.data[0] = lio->u.logio.data[0];
391 ea.data[1] = lio->u.logio.data[1];
392 ea.iop[0] = lio->u.logio.iop[0];
393 ea.iop[1] = lio->u.logio.iop[1];
Quinn Tranf13515a2017-12-28 12:33:15 -0800394 ea.fcport = sp->fcport;
395 ea.sp = sp;
396
397 qla2x00_fcport_event_handler(vha, &ea);
398
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800399 sp->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700400}
401
402int
403qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
404 uint16_t *data)
405{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700406 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700407 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700408 int rval;
409
410 rval = QLA_FUNCTION_FAILED;
Quinn Tran726b8542017-01-19 22:28:00 -0800411 fcport->flags |= FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800412 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700413 if (!sp)
414 goto done;
415
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800416 sp->type = SRB_ADISC_CMD;
417 sp->name = "adisc";
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800418
419 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700420 lio->timeout = qla2x00_async_iocb_timeout;
Ben Hutchingse74e7d92018-03-20 21:36:14 +0000421 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
422
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800423 sp->done = qla2x00_async_adisc_sp_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700424 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700425 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700426 rval = qla2x00_start_sp(sp);
427 if (rval != QLA_SUCCESS)
428 goto done_free_sp;
429
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700430 ql_dbg(ql_dbg_disc, vha, 0x206f,
Quinn Tranf13515a2017-12-28 12:33:15 -0800431 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
432 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700433 return rval;
434
435done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800436 sp->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700437done:
Hannes Reineckefa83e652018-02-22 09:49:37 +0100438 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
Quinn Tranf13515a2017-12-28 12:33:15 -0800439 qla2x00_post_async_adisc_work(vha, fcport, data);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700440 return rval;
441}
442
Quinn Tran726b8542017-01-19 22:28:00 -0800443static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
444 struct event_arg *ea)
445{
446 fc_port_t *fcport, *conflict_fcport;
447 struct get_name_list_extended *e;
448 u16 i, n, found = 0, loop_id;
449 port_id_t id;
450 u64 wwn;
Quinn Trana4239942017-12-28 12:33:26 -0800451 u16 data[2];
452 u8 current_login_state;
Quinn Tran726b8542017-01-19 22:28:00 -0800453
454 fcport = ea->fcport;
Quinn Tranf352eeb2017-12-28 12:33:35 -0800455 ql_dbg(ql_dbg_disc, vha, 0xffff,
456 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
457 __func__, fcport->port_name, fcport->disc_state,
458 fcport->fw_login_state, ea->rc,
459 fcport->login_gen, fcport->last_login_gen,
460 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id);
Quinn Tran726b8542017-01-19 22:28:00 -0800461
Quinn Trana4239942017-12-28 12:33:26 -0800462 if (fcport->disc_state == DSC_DELETE_PEND)
463 return;
464
Quinn Tran726b8542017-01-19 22:28:00 -0800465 if (ea->rc) { /* rval */
466 if (fcport->login_retry == 0) {
467 fcport->login_retry = vha->hw->login_retry_count;
Quinn Tran83548fe2017-06-02 09:12:01 -0700468 ql_dbg(ql_dbg_disc, vha, 0x20de,
469 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
470 fcport->port_name, fcport->login_retry);
Quinn Tran726b8542017-01-19 22:28:00 -0800471 }
472 return;
473 }
474
475 if (fcport->last_rscn_gen != fcport->rscn_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700476 ql_dbg(ql_dbg_disc, vha, 0x20df,
Quinn Tran726b8542017-01-19 22:28:00 -0800477 "%s %8phC rscn gen changed rscn %d|%d \n",
478 __func__, fcport->port_name,
479 fcport->last_rscn_gen, fcport->rscn_gen);
480 qla24xx_post_gidpn_work(vha, fcport);
481 return;
482 } else if (fcport->last_login_gen != fcport->login_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700483 ql_dbg(ql_dbg_disc, vha, 0x20e0,
Quinn Tranf352eeb2017-12-28 12:33:35 -0800484 "%s %8phC login gen changed\n",
485 __func__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800486 return;
487 }
488
489 n = ea->data[0] / sizeof(struct get_name_list_extended);
490
Quinn Tran83548fe2017-06-02 09:12:01 -0700491 ql_dbg(ql_dbg_disc, vha, 0x20e1,
Quinn Tran726b8542017-01-19 22:28:00 -0800492 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
493 __func__, __LINE__, fcport->port_name, n,
494 fcport->d_id.b.domain, fcport->d_id.b.area,
495 fcport->d_id.b.al_pa, fcport->loop_id);
496
497 for (i = 0; i < n; i++) {
498 e = &vha->gnl.l[i];
499 wwn = wwn_to_u64(e->port_name);
500
501 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
502 continue;
503
504 found = 1;
505 id.b.domain = e->port_id[2];
506 id.b.area = e->port_id[1];
507 id.b.al_pa = e->port_id[0];
508 id.b.rsvd_1 = 0;
509
510 loop_id = le16_to_cpu(e->nport_handle);
511 loop_id = (loop_id & 0x7fff);
512
Quinn Tran83548fe2017-06-02 09:12:01 -0700513 ql_dbg(ql_dbg_disc, vha, 0x20e2,
514 "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
515 __func__, fcport->port_name,
516 e->current_login_state, fcport->fw_login_state,
517 id.b.domain, id.b.area, id.b.al_pa,
518 fcport->d_id.b.domain, fcport->d_id.b.area,
519 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
Quinn Tran726b8542017-01-19 22:28:00 -0800520
521 if ((id.b24 != fcport->d_id.b24) ||
522 ((fcport->loop_id != FC_NO_LOOP_ID) &&
523 (fcport->loop_id != loop_id))) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700524 ql_dbg(ql_dbg_disc, vha, 0x20e3,
525 "%s %d %8phC post del sess\n",
526 __func__, __LINE__, fcport->port_name);
Quinn Tran94cff6e2017-12-28 12:33:42 -0800527 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran726b8542017-01-19 22:28:00 -0800528 return;
529 }
530
531 fcport->loop_id = loop_id;
532
533 wwn = wwn_to_u64(fcport->port_name);
534 qlt_find_sess_invalidate_other(vha, wwn,
535 id, loop_id, &conflict_fcport);
536
537 if (conflict_fcport) {
538 /*
539 * Another share fcport share the same loop_id &
540 * nport id. Conflict fcport needs to finish
541 * cleanup before this fcport can proceed to login.
542 */
543 conflict_fcport->conflict = fcport;
544 fcport->login_pause = 1;
545 }
546
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700547 if (fcport->fc4f_nvme)
548 current_login_state = e->current_login_state >> 4;
549 else
550 current_login_state = e->current_login_state & 0xf;
551
552 switch (current_login_state) {
Quinn Tran726b8542017-01-19 22:28:00 -0800553 case DSC_LS_PRLI_COMP:
Quinn Tran83548fe2017-06-02 09:12:01 -0700554 ql_dbg(ql_dbg_disc, vha, 0x20e4,
555 "%s %d %8phC post gpdb\n",
556 __func__, __LINE__, fcport->port_name);
Quinn Trana4239942017-12-28 12:33:26 -0800557
558 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
559 fcport->port_type = FCT_INITIATOR;
560 else
561 fcport->port_type = FCT_TARGET;
562
563 data[0] = data[1] = 0;
564 qla2x00_post_async_adisc_work(vha, fcport, data);
Quinn Tran726b8542017-01-19 22:28:00 -0800565 break;
Quinn Tran726b8542017-01-19 22:28:00 -0800566 case DSC_LS_PORT_UNAVAIL:
567 default:
568 if (fcport->loop_id == FC_NO_LOOP_ID) {
569 qla2x00_find_new_loop_id(vha, fcport);
570 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
571 }
Quinn Tran83548fe2017-06-02 09:12:01 -0700572 ql_dbg(ql_dbg_disc, vha, 0x20e5,
573 "%s %d %8phC\n",
574 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800575 qla24xx_fcport_handle_login(vha, fcport);
576 break;
577 }
578 }
579
580 if (!found) {
581 /* fw has no record of this port */
Quinn Tran040036b2017-12-28 12:33:38 -0800582 for (i = 0; i < n; i++) {
583 e = &vha->gnl.l[i];
584 id.b.domain = e->port_id[0];
585 id.b.area = e->port_id[1];
586 id.b.al_pa = e->port_id[2];
587 id.b.rsvd_1 = 0;
588 loop_id = le16_to_cpu(e->nport_handle);
Quinn Tran726b8542017-01-19 22:28:00 -0800589
Quinn Tran040036b2017-12-28 12:33:38 -0800590 if (fcport->d_id.b24 == id.b24) {
591 conflict_fcport =
592 qla2x00_find_fcport_by_wwpn(vha,
593 e->port_name, 0);
594 ql_dbg(ql_dbg_disc, vha, 0x20e6,
595 "%s %d %8phC post del sess\n",
596 __func__, __LINE__,
597 conflict_fcport->port_name);
598 qlt_schedule_sess_for_deletion
Quinn Tran94cff6e2017-12-28 12:33:42 -0800599 (conflict_fcport);
Quinn Tran726b8542017-01-19 22:28:00 -0800600 }
Quinn Tran040036b2017-12-28 12:33:38 -0800601
602 /* FW already picked this loop id for another fcport */
603 if (fcport->loop_id == loop_id)
604 fcport->loop_id = FC_NO_LOOP_ID;
Quinn Tran726b8542017-01-19 22:28:00 -0800605 }
606 qla24xx_fcport_handle_login(vha, fcport);
607 }
608} /* gnl_event */
609
610static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800611qla24xx_async_gnl_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -0800612{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800613 struct srb *sp = s;
614 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -0800615 unsigned long flags;
616 struct fc_port *fcport = NULL, *tf;
617 u16 i, n = 0, loop_id;
618 struct event_arg ea;
619 struct get_name_list_extended *e;
620 u64 wwn;
621 struct list_head h;
Quinn Trana4239942017-12-28 12:33:26 -0800622 bool found = false;
Quinn Tran726b8542017-01-19 22:28:00 -0800623
Quinn Tran83548fe2017-06-02 09:12:01 -0700624 ql_dbg(ql_dbg_disc, vha, 0x20e7,
Quinn Tran726b8542017-01-19 22:28:00 -0800625 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
626 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
627 sp->u.iocb_cmd.u.mbx.in_mb[2]);
628
629 memset(&ea, 0, sizeof(ea));
630 ea.sp = sp;
631 ea.rc = res;
632 ea.event = FCME_GNL_DONE;
633
634 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
635 sizeof(struct get_name_list_extended)) {
636 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
637 sizeof(struct get_name_list_extended);
638 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
639 }
640
641 for (i = 0; i < n; i++) {
642 e = &vha->gnl.l[i];
643 loop_id = le16_to_cpu(e->nport_handle);
644 /* mask out reserve bit */
645 loop_id = (loop_id & 0x7fff);
646 set_bit(loop_id, vha->hw->loop_id_map);
647 wwn = wwn_to_u64(e->port_name);
648
Quinn Tran83548fe2017-06-02 09:12:01 -0700649 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
Quinn Tran726b8542017-01-19 22:28:00 -0800650 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
651 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
652 e->port_id[0], e->current_login_state, e->last_login_state,
653 (loop_id & 0x7fff));
654 }
655
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +0100656 spin_lock_irqsave(&vha->gnl.fcports_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -0800657
658 INIT_LIST_HEAD(&h);
659 fcport = tf = NULL;
660 if (!list_empty(&vha->gnl.fcports))
661 list_splice_init(&vha->gnl.fcports, &h);
662
663 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
664 list_del_init(&fcport->gnl_entry);
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +0100665 spin_lock(&vha->hw->tgt.sess_lock);
Quinn Tran6d6749272017-12-28 12:33:41 -0800666 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +0100667 spin_unlock(&vha->hw->tgt.sess_lock);
Quinn Tran726b8542017-01-19 22:28:00 -0800668 ea.fcport = fcport;
669
670 qla2x00_fcport_event_handler(vha, &ea);
671 }
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +0100672 spin_unlock_irqrestore(&vha->gnl.fcports_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -0800673
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +0100674 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -0800675 /* create new fcport if fw has knowledge of new sessions */
676 for (i = 0; i < n; i++) {
677 port_id_t id;
678 u64 wwnn;
679
680 e = &vha->gnl.l[i];
681 wwn = wwn_to_u64(e->port_name);
682
683 found = false;
684 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
685 if (!memcmp((u8 *)&wwn, fcport->port_name,
686 WWN_SIZE)) {
687 found = true;
688 break;
689 }
690 }
691
Quinn Trancf055fb2017-12-28 12:33:33 -0800692 id.b.domain = e->port_id[2];
Quinn Trana4239942017-12-28 12:33:26 -0800693 id.b.area = e->port_id[1];
Quinn Trancf055fb2017-12-28 12:33:33 -0800694 id.b.al_pa = e->port_id[0];
Quinn Trana4239942017-12-28 12:33:26 -0800695 id.b.rsvd_1 = 0;
696
697 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
698 ql_dbg(ql_dbg_disc, vha, 0x2065,
Quinn Trancf055fb2017-12-28 12:33:33 -0800699 "%s %d %8phC %06x post new sess\n",
700 __func__, __LINE__, (u8 *)&wwn, id.b24);
Quinn Trana4239942017-12-28 12:33:26 -0800701 wwnn = wwn_to_u64(e->node_name);
702 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
703 (u8 *)&wwnn, NULL, FC4_TYPE_UNKNOWN);
704 }
705 }
706
Quinn Tran726b8542017-01-19 22:28:00 -0800707 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
708
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800709 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800710}
711
712int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
713{
714 srb_t *sp;
715 struct srb_iocb *mbx;
716 int rval = QLA_FUNCTION_FAILED;
717 unsigned long flags;
718 u16 *mb;
719
Quinn Tran3dbec592017-12-28 12:33:40 -0800720 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
721 return rval;
Quinn Tran726b8542017-01-19 22:28:00 -0800722
Quinn Tran83548fe2017-06-02 09:12:01 -0700723 ql_dbg(ql_dbg_disc, vha, 0x20d9,
Quinn Tran726b8542017-01-19 22:28:00 -0800724 "Async-gnlist WWPN %8phC \n", fcport->port_name);
725
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +0100726 spin_lock_irqsave(&vha->gnl.fcports_lock, flags);
727 if (!list_empty(&fcport->gnl_entry)) {
728 spin_unlock_irqrestore(&vha->gnl.fcports_lock, flags);
729 rval = QLA_SUCCESS;
730 goto done;
731 }
732
733 spin_lock(&vha->hw->tgt.sess_lock);
Quinn Tran726b8542017-01-19 22:28:00 -0800734 fcport->disc_state = DSC_GNL;
735 fcport->last_rscn_gen = fcport->rscn_gen;
736 fcport->last_login_gen = fcport->login_gen;
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +0100737 spin_unlock(&vha->hw->tgt.sess_lock);
Quinn Tran726b8542017-01-19 22:28:00 -0800738
739 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
Hannes Reinecke1c6cacf2018-02-22 09:49:35 +0100740 spin_unlock_irqrestore(&vha->gnl.fcports_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -0800741
742 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
743 if (!sp)
744 goto done;
Quinn Tran3dbec592017-12-28 12:33:40 -0800745
746 fcport->flags |= FCF_ASYNC_SENT;
Quinn Tran726b8542017-01-19 22:28:00 -0800747 sp->type = SRB_MB_IOCB;
748 sp->name = "gnlist";
749 sp->gen1 = fcport->rscn_gen;
750 sp->gen2 = fcport->login_gen;
751
Ben Hutchingse74e7d92018-03-20 21:36:14 +0000752 mbx = &sp->u.iocb_cmd;
753 mbx->timeout = qla2x00_async_iocb_timeout;
Quinn Tran726b8542017-01-19 22:28:00 -0800754 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
755
756 mb = sp->u.iocb_cmd.u.mbx.out_mb;
757 mb[0] = MBC_PORT_NODE_NAME_LIST;
758 mb[1] = BIT_2 | BIT_3;
759 mb[2] = MSW(vha->gnl.ldma);
760 mb[3] = LSW(vha->gnl.ldma);
761 mb[6] = MSW(MSD(vha->gnl.ldma));
762 mb[7] = LSW(MSD(vha->gnl.ldma));
763 mb[8] = vha->gnl.size;
764 mb[9] = vha->vp_idx;
765
Quinn Tran726b8542017-01-19 22:28:00 -0800766 sp->done = qla24xx_async_gnl_sp_done;
767
768 rval = qla2x00_start_sp(sp);
769 if (rval != QLA_SUCCESS)
770 goto done_free_sp;
771
Quinn Tran83548fe2017-06-02 09:12:01 -0700772 ql_dbg(ql_dbg_disc, vha, 0x20da,
773 "Async-%s - OUT WWPN %8phC hndl %x\n",
774 sp->name, fcport->port_name, sp->handle);
Quinn Tran726b8542017-01-19 22:28:00 -0800775
776 return rval;
777
778done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800779 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800780 fcport->flags &= ~FCF_ASYNC_SENT;
Quinn Tran3dbec592017-12-28 12:33:40 -0800781done:
Quinn Tran726b8542017-01-19 22:28:00 -0800782 return rval;
783}
784
785int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
786{
787 struct qla_work_evt *e;
788
789 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
790 if (!e)
791 return QLA_FUNCTION_FAILED;
792
793 e->u.fcport.fcport = fcport;
Quinn Tran6d6749272017-12-28 12:33:41 -0800794 fcport->flags |= FCF_ASYNC_ACTIVE;
Quinn Tran726b8542017-01-19 22:28:00 -0800795 return qla2x00_post_work(vha, e);
796}
797
798static
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800799void qla24xx_async_gpdb_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -0800800{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800801 struct srb *sp = s;
802 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -0800803 struct qla_hw_data *ha = vha->hw;
Quinn Tran726b8542017-01-19 22:28:00 -0800804 fc_port_t *fcport = sp->fcport;
805 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
Quinn Tran726b8542017-01-19 22:28:00 -0800806 struct event_arg ea;
807
Quinn Tran83548fe2017-06-02 09:12:01 -0700808 ql_dbg(ql_dbg_disc, vha, 0x20db,
Quinn Tran726b8542017-01-19 22:28:00 -0800809 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
810 sp->name, res, fcport->port_name, mb[1], mb[2]);
811
Quinn Tran6d6749272017-12-28 12:33:41 -0800812 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
Quinn Tran726b8542017-01-19 22:28:00 -0800813
Quinn Tran726b8542017-01-19 22:28:00 -0800814 memset(&ea, 0, sizeof(ea));
815 ea.event = FCME_GPDB_DONE;
Quinn Tran726b8542017-01-19 22:28:00 -0800816 ea.fcport = fcport;
817 ea.sp = sp;
818
819 qla2x00_fcport_event_handler(vha, &ea);
820
821 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
822 sp->u.iocb_cmd.u.mbx.in_dma);
823
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800824 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800825}
826
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700827static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
828{
829 struct qla_work_evt *e;
830
831 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
832 if (!e)
833 return QLA_FUNCTION_FAILED;
834
835 e->u.fcport.fcport = fcport;
836
837 return qla2x00_post_work(vha, e);
838}
839
840static void
841qla2x00_async_prli_sp_done(void *ptr, int res)
842{
843 srb_t *sp = ptr;
844 struct scsi_qla_host *vha = sp->vha;
845 struct srb_iocb *lio = &sp->u.iocb_cmd;
846 struct event_arg ea;
847
848 ql_dbg(ql_dbg_disc, vha, 0x2129,
849 "%s %8phC res %d \n", __func__,
850 sp->fcport->port_name, res);
851
852 sp->fcport->flags &= ~FCF_ASYNC_SENT;
853
854 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
855 memset(&ea, 0, sizeof(ea));
856 ea.event = FCME_PRLI_DONE;
857 ea.fcport = sp->fcport;
858 ea.data[0] = lio->u.logio.data[0];
859 ea.data[1] = lio->u.logio.data[1];
860 ea.iop[0] = lio->u.logio.iop[0];
861 ea.iop[1] = lio->u.logio.iop[1];
862 ea.sp = sp;
863
864 qla2x00_fcport_event_handler(vha, &ea);
865 }
866
867 sp->free(sp);
868}
869
870int
871qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
872{
873 srb_t *sp;
874 struct srb_iocb *lio;
875 int rval = QLA_FUNCTION_FAILED;
876
877 if (!vha->flags.online)
878 return rval;
879
880 if (fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700881 fcport->fw_login_state == DSC_LS_PRLI_PEND)
882 return rval;
883
884 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
885 if (!sp)
886 return rval;
887
888 fcport->flags |= FCF_ASYNC_SENT;
889 fcport->logout_completed = 0;
890
891 sp->type = SRB_PRLI_CMD;
892 sp->name = "prli";
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700893
894 lio = &sp->u.iocb_cmd;
895 lio->timeout = qla2x00_async_iocb_timeout;
Ben Hutchingse74e7d92018-03-20 21:36:14 +0000896 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
897
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700898 sp->done = qla2x00_async_prli_sp_done;
899 lio->u.logio.flags = 0;
900
901 if (fcport->fc4f_nvme)
902 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
903
904 rval = qla2x00_start_sp(sp);
905 if (rval != QLA_SUCCESS) {
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700906 fcport->flags |= FCF_LOGIN_NEEDED;
907 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
908 goto done_free_sp;
909 }
910
911 ql_dbg(ql_dbg_disc, vha, 0x211b,
912 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n",
913 fcport->port_name, sp->handle, fcport->loop_id,
914 fcport->d_id.b24, fcport->login_retry);
915
916 return rval;
917
918done_free_sp:
919 sp->free(sp);
920 fcport->flags &= ~FCF_ASYNC_SENT;
921 return rval;
922}
923
Quinn Trana07fc0a2017-08-23 15:05:21 -0700924int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
Quinn Tran726b8542017-01-19 22:28:00 -0800925{
926 struct qla_work_evt *e;
927
928 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
929 if (!e)
930 return QLA_FUNCTION_FAILED;
931
932 e->u.fcport.fcport = fcport;
933 e->u.fcport.opt = opt;
Quinn Tran6d6749272017-12-28 12:33:41 -0800934 fcport->flags |= FCF_ASYNC_ACTIVE;
Quinn Tran726b8542017-01-19 22:28:00 -0800935 return qla2x00_post_work(vha, e);
936}
937
938int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
939{
940 srb_t *sp;
941 struct srb_iocb *mbx;
942 int rval = QLA_FUNCTION_FAILED;
943 u16 *mb;
944 dma_addr_t pd_dma;
945 struct port_database_24xx *pd;
946 struct qla_hw_data *ha = vha->hw;
947
Quinn Tran3dbec592017-12-28 12:33:40 -0800948 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
949 return rval;
Quinn Tran726b8542017-01-19 22:28:00 -0800950
Quinn Tran726b8542017-01-19 22:28:00 -0800951 fcport->disc_state = DSC_GPDB;
952
953 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
954 if (!sp)
955 goto done;
956
Quinn Tran3dbec592017-12-28 12:33:40 -0800957 fcport->flags |= FCF_ASYNC_SENT;
Joe Carnuccioe0824e62017-08-23 15:05:08 -0700958 sp->type = SRB_MB_IOCB;
959 sp->name = "gpdb";
960 sp->gen1 = fcport->rscn_gen;
961 sp->gen2 = fcport->login_gen;
Ben Hutchingse74e7d92018-03-20 21:36:14 +0000962
963 mbx = &sp->u.iocb_cmd;
964 mbx->timeout = qla2x00_async_iocb_timeout;
Joe Carnuccioe0824e62017-08-23 15:05:08 -0700965 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
966
Thomas Meyer08eb7f42017-09-21 08:15:26 +0200967 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Quinn Tran726b8542017-01-19 22:28:00 -0800968 if (pd == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700969 ql_log(ql_log_warn, vha, 0xd043,
970 "Failed to allocate port database structure.\n");
Quinn Tran726b8542017-01-19 22:28:00 -0800971 goto done_free_sp;
972 }
Quinn Tran726b8542017-01-19 22:28:00 -0800973
Quinn Tran726b8542017-01-19 22:28:00 -0800974 mb = sp->u.iocb_cmd.u.mbx.out_mb;
975 mb[0] = MBC_GET_PORT_DATABASE;
976 mb[1] = fcport->loop_id;
977 mb[2] = MSW(pd_dma);
978 mb[3] = LSW(pd_dma);
979 mb[6] = MSW(MSD(pd_dma));
980 mb[7] = LSW(MSD(pd_dma));
981 mb[9] = vha->vp_idx;
982 mb[10] = opt;
983
Quinn Tran726b8542017-01-19 22:28:00 -0800984 mbx->u.mbx.in = (void *)pd;
985 mbx->u.mbx.in_dma = pd_dma;
986
987 sp->done = qla24xx_async_gpdb_sp_done;
988
989 rval = qla2x00_start_sp(sp);
990 if (rval != QLA_SUCCESS)
991 goto done_free_sp;
992
Quinn Tran83548fe2017-06-02 09:12:01 -0700993 ql_dbg(ql_dbg_disc, vha, 0x20dc,
994 "Async-%s %8phC hndl %x opt %x\n",
995 sp->name, fcport->port_name, sp->handle, opt);
Quinn Tran726b8542017-01-19 22:28:00 -0800996
997 return rval;
998
999done_free_sp:
1000 if (pd)
1001 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1002
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001003 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -08001004 fcport->flags &= ~FCF_ASYNC_SENT;
Quinn Tran3dbec592017-12-28 12:33:40 -08001005done:
Quinn Tran726b8542017-01-19 22:28:00 -08001006 qla24xx_post_gpdb_work(vha, fcport, opt);
1007 return rval;
1008}
1009
1010static
Quinn Trana4239942017-12-28 12:33:26 -08001011void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
Quinn Tran726b8542017-01-19 22:28:00 -08001012{
Quinn Tran726b8542017-01-19 22:28:00 -08001013 unsigned long flags;
1014
Quinn Tran726b8542017-01-19 22:28:00 -08001015 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Tranf13515a2017-12-28 12:33:15 -08001016 ea->fcport->login_gen++;
Quinn Tran726b8542017-01-19 22:28:00 -08001017 ea->fcport->deleted = 0;
1018 ea->fcport->logout_on_delete = 1;
1019
1020 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1021 vha->fcport_count++;
1022 ea->fcport->login_succ = 1;
1023
Quinn Trancc28e0a2018-05-01 09:01:48 -07001024 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1025 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
1026 __func__, __LINE__, ea->fcport->port_name,
1027 vha->fcport_count);
1028 qla24xx_post_upd_fcport_work(vha, ea->fcport);
Quinn Tran414d9ff2017-12-04 14:45:03 -08001029 } else if (ea->fcport->login_succ) {
1030 /*
1031 * We have an existing session. A late RSCN delivery
1032 * must have triggered the session to be re-validate.
Quinn Trana4239942017-12-28 12:33:26 -08001033 * Session is still valid.
Quinn Tran414d9ff2017-12-04 14:45:03 -08001034 */
Quinn Tran5ef696a2017-12-04 14:45:05 -08001035 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1036 "%s %d %8phC session revalidate success\n",
Quinn Trana4239942017-12-28 12:33:26 -08001037 __func__, __LINE__, ea->fcport->port_name);
himanshu.madhani@cavium.com8a7eac22018-01-15 20:46:50 -08001038 ea->fcport->disc_state = DSC_LOGIN_COMPLETE;
Quinn Tran726b8542017-01-19 22:28:00 -08001039 }
1040 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Quinn Trana4239942017-12-28 12:33:26 -08001041}
Quinn Tran726b8542017-01-19 22:28:00 -08001042
Quinn Trana4239942017-12-28 12:33:26 -08001043static
1044void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1045{
Quinn Trana4239942017-12-28 12:33:26 -08001046 fc_port_t *fcport = ea->fcport;
1047 struct port_database_24xx *pd;
1048 struct srb *sp = ea->sp;
Darren Trapp2b5b9642018-02-27 16:31:12 -08001049 uint8_t ls;
Quinn Trana4239942017-12-28 12:33:26 -08001050
1051 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1052
1053 fcport->flags &= ~FCF_ASYNC_SENT;
1054
1055 ql_dbg(ql_dbg_disc, vha, 0x20d2,
Quinn Tranf352eeb2017-12-28 12:33:35 -08001056 "%s %8phC DS %d LS %d rc %d\n", __func__, fcport->port_name,
1057 fcport->disc_state, pd->current_login_state, ea->rc);
Quinn Trana4239942017-12-28 12:33:26 -08001058
1059 if (fcport->disc_state == DSC_DELETE_PEND)
1060 return;
1061
Darren Trapp2b5b9642018-02-27 16:31:12 -08001062 if (fcport->fc4f_nvme)
1063 ls = pd->current_login_state >> 4;
1064 else
1065 ls = pd->current_login_state & 0xf;
1066
1067 switch (ls) {
Quinn Trana4239942017-12-28 12:33:26 -08001068 case PDS_PRLI_COMPLETE:
1069 __qla24xx_parse_gpdb(vha, fcport, pd);
1070 break;
1071 case PDS_PLOGI_PENDING:
1072 case PDS_PLOGI_COMPLETE:
1073 case PDS_PRLI_PENDING:
1074 case PDS_PRLI2_PENDING:
1075 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC relogin needed\n",
1076 __func__, __LINE__, fcport->port_name);
1077 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1078 return;
1079 case PDS_LOGO_PENDING:
1080 case PDS_PORT_UNAVAILABLE:
1081 default:
1082 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1083 __func__, __LINE__, fcport->port_name);
Quinn Trand8630bb2017-12-28 12:33:43 -08001084 qlt_schedule_sess_for_deletion(fcport);
Quinn Trana4239942017-12-28 12:33:26 -08001085 return;
1086 }
1087 __qla24xx_handle_gpdb_event(vha, ea);
1088} /* gpdb event */
Quinn Tran9cd883f2017-12-28 12:33:24 -08001089
1090static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1091{
1092 u8 login = 0;
Quinn Tran040036b2017-12-28 12:33:38 -08001093 int rc;
Quinn Tran9cd883f2017-12-28 12:33:24 -08001094
1095 if (qla_tgt_mode_enabled(vha))
1096 return;
1097
1098 if (qla_dual_mode_enabled(vha)) {
1099 if (N2N_TOPO(vha->hw)) {
1100 u64 mywwn, wwn;
1101
1102 mywwn = wwn_to_u64(vha->port_name);
1103 wwn = wwn_to_u64(fcport->port_name);
1104 if (mywwn > wwn)
1105 login = 1;
1106 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1107 && time_after_eq(jiffies,
1108 fcport->plogi_nack_done_deadline))
1109 login = 1;
1110 } else {
1111 login = 1;
1112 }
1113 } else {
1114 /* initiator mode */
1115 login = 1;
1116 }
1117
1118 if (login) {
Quinn Tran040036b2017-12-28 12:33:38 -08001119 if (fcport->loop_id == FC_NO_LOOP_ID) {
1120 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1121 rc = qla2x00_find_new_loop_id(vha, fcport);
1122 if (rc) {
1123 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1124 "%s %d %8phC post del sess - out of loopid\n",
1125 __func__, __LINE__, fcport->port_name);
1126 fcport->scan_state = 0;
Quinn Tran94cff6e2017-12-28 12:33:42 -08001127 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran040036b2017-12-28 12:33:38 -08001128 return;
1129 }
1130 }
Quinn Tran9cd883f2017-12-28 12:33:24 -08001131 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1132 "%s %d %8phC post login\n",
1133 __func__, __LINE__, fcport->port_name);
Quinn Tran9cd883f2017-12-28 12:33:24 -08001134 qla2x00_post_async_login_work(vha, fcport, NULL);
1135 }
1136}
1137
Quinn Tran726b8542017-01-19 22:28:00 -08001138int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1139{
Quinn Tranf13515a2017-12-28 12:33:15 -08001140 u16 data[2];
Quinn Trana4239942017-12-28 12:33:26 -08001141 u64 wwn;
1142
1143 ql_dbg(ql_dbg_disc, vha, 0x20d8,
Quinn Tranf352eeb2017-12-28 12:33:35 -08001144 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d retry %d lid %d scan %d\n",
Quinn Trana4239942017-12-28 12:33:26 -08001145 __func__, fcport->port_name, fcport->disc_state,
1146 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1147 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
Quinn Tranf352eeb2017-12-28 12:33:35 -08001148 fcport->login_gen, fcport->login_retry,
Quinn Trana4239942017-12-28 12:33:26 -08001149 fcport->loop_id, fcport->scan_state);
1150
Quinn Tran726b8542017-01-19 22:28:00 -08001151 if (fcport->scan_state != QLA_FCPORT_FOUND)
1152 return 0;
1153
Hannes Reinecke07ea4b62018-02-22 09:49:36 +01001154 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1155 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1156 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
Quinn Tran726b8542017-01-19 22:28:00 -08001157 return 0;
1158
Quinn Tran5b334692017-03-15 09:48:48 -07001159 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08001160 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1161 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Quinn Tran5b334692017-03-15 09:48:48 -07001162 return 0;
Quinn Tran9cd883f2017-12-28 12:33:24 -08001163 }
Quinn Tran5b334692017-03-15 09:48:48 -07001164 }
1165
Quinn Tran726b8542017-01-19 22:28:00 -08001166 /* for pure Target Mode. Login will not be initiated */
1167 if (vha->host->active_mode == MODE_TARGET)
1168 return 0;
1169
1170 if (fcport->flags & FCF_ASYNC_SENT) {
1171 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1172 return 0;
1173 }
1174
Quinn Tran625a1ca2018-05-01 09:01:44 -07001175 if (fcport->login_retry > 0)
1176 fcport->login_retry--;
Quinn Trana4239942017-12-28 12:33:26 -08001177
Quinn Tran726b8542017-01-19 22:28:00 -08001178 switch (fcport->disc_state) {
1179 case DSC_DELETED:
Quinn Trana4239942017-12-28 12:33:26 -08001180 wwn = wwn_to_u64(fcport->node_name);
1181 if (wwn == 0) {
1182 ql_dbg(ql_dbg_disc, vha, 0xffff,
1183 "%s %d %8phC post GNNID\n",
1184 __func__, __LINE__, fcport->port_name);
1185 qla24xx_post_gnnid_work(vha, fcport);
1186 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
Quinn Tran83548fe2017-06-02 09:12:01 -07001187 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1188 "%s %d %8phC post gnl\n",
1189 __func__, __LINE__, fcport->port_name);
Giridhar Malavali5d3300a2017-12-04 14:45:13 -08001190 qla24xx_post_gnl_work(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08001191 } else {
Quinn Tran9cd883f2017-12-28 12:33:24 -08001192 qla_chk_n2n_b4_login(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08001193 }
1194 break;
1195
1196 case DSC_GNL:
1197 if (fcport->login_pause) {
1198 fcport->last_rscn_gen = fcport->rscn_gen;
1199 fcport->last_login_gen = fcport->login_gen;
1200 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1201 break;
1202 }
1203
Quinn Tran9cd883f2017-12-28 12:33:24 -08001204 qla_chk_n2n_b4_login(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08001205 break;
1206
1207 case DSC_LOGIN_FAILED:
Quinn Tran83548fe2017-06-02 09:12:01 -07001208 ql_dbg(ql_dbg_disc, vha, 0x20d0,
1209 "%s %d %8phC post gidpn\n",
1210 __func__, __LINE__, fcport->port_name);
Quinn Tran9cd883f2017-12-28 12:33:24 -08001211 if (N2N_TOPO(vha->hw))
1212 qla_chk_n2n_b4_login(vha, fcport);
1213 else
1214 qla24xx_post_gidpn_work(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08001215 break;
1216
1217 case DSC_LOGIN_COMPLETE:
1218 /* recheck login state */
Quinn Tran83548fe2017-06-02 09:12:01 -07001219 ql_dbg(ql_dbg_disc, vha, 0x20d1,
Quinn Tranf13515a2017-12-28 12:33:15 -08001220 "%s %d %8phC post adisc\n",
Quinn Tran83548fe2017-06-02 09:12:01 -07001221 __func__, __LINE__, fcport->port_name);
Quinn Tranf13515a2017-12-28 12:33:15 -08001222 data[0] = data[1] = 0;
1223 qla2x00_post_async_adisc_work(vha, fcport, data);
Quinn Tran726b8542017-01-19 22:28:00 -08001224 break;
1225
Darren Trapp1cbc0ef2018-03-20 23:09:37 -07001226 case DSC_LOGIN_PEND:
1227 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1228 qla24xx_post_prli_work(vha, fcport);
1229 break;
1230
Quinn Tran726b8542017-01-19 22:28:00 -08001231 default:
1232 break;
1233 }
1234
1235 return 0;
1236}
1237
1238static
1239void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea)
1240{
1241 fcport->rscn_gen++;
1242
Quinn Tran83548fe2017-06-02 09:12:01 -07001243 ql_dbg(ql_dbg_disc, fcport->vha, 0x210c,
1244 "%s %8phC DS %d LS %d\n",
1245 __func__, fcport->port_name, fcport->disc_state,
1246 fcport->fw_login_state);
Quinn Tran726b8542017-01-19 22:28:00 -08001247
1248 if (fcport->flags & FCF_ASYNC_SENT)
1249 return;
1250
1251 switch (fcport->disc_state) {
1252 case DSC_DELETED:
1253 case DSC_LOGIN_COMPLETE:
Quinn Tran5ef696a2017-12-04 14:45:05 -08001254 qla24xx_post_gpnid_work(fcport->vha, &ea->id);
Quinn Tran726b8542017-01-19 22:28:00 -08001255 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001256 default:
1257 break;
1258 }
1259}
1260
1261int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
Quinn Trana4239942017-12-28 12:33:26 -08001262 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
Quinn Tran726b8542017-01-19 22:28:00 -08001263{
1264 struct qla_work_evt *e;
1265 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1266 if (!e)
1267 return QLA_FUNCTION_FAILED;
1268
1269 e->u.new_sess.id = *id;
1270 e->u.new_sess.pla = pla;
Quinn Trana4239942017-12-28 12:33:26 -08001271 e->u.new_sess.fc4_type = fc4_type;
Quinn Tran726b8542017-01-19 22:28:00 -08001272 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
Quinn Trana4239942017-12-28 12:33:26 -08001273 if (node_name)
1274 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
Quinn Tran726b8542017-01-19 22:28:00 -08001275
1276 return qla2x00_post_work(vha, e);
1277}
1278
1279static
Quinn Tran726b8542017-01-19 22:28:00 -08001280void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1281 struct event_arg *ea)
1282{
1283 fc_port_t *fcport = ea->fcport;
1284
Quinn Tran83548fe2017-06-02 09:12:01 -07001285 ql_dbg(ql_dbg_disc, vha, 0x2102,
1286 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1287 __func__, fcport->port_name, fcport->disc_state,
1288 fcport->fw_login_state, fcport->login_pause,
1289 fcport->deleted, fcport->conflict,
1290 fcport->last_rscn_gen, fcport->rscn_gen,
1291 fcport->last_login_gen, fcport->login_gen,
1292 fcport->flags);
Quinn Tran726b8542017-01-19 22:28:00 -08001293
1294 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
Quinn Tran726b8542017-01-19 22:28:00 -08001295 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1296 return;
1297
Quinn Tran5b334692017-03-15 09:48:48 -07001298 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
Quinn Tran9cd883f2017-12-28 12:33:24 -08001299 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1300 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Quinn Tran5b334692017-03-15 09:48:48 -07001301 return;
Quinn Tran9cd883f2017-12-28 12:33:24 -08001302 }
Quinn Tran5b334692017-03-15 09:48:48 -07001303 }
1304
Quinn Tran726b8542017-01-19 22:28:00 -08001305 if (fcport->flags & FCF_ASYNC_SENT) {
1306 fcport->login_retry++;
1307 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1308 return;
1309 }
1310
1311 if (fcport->disc_state == DSC_DELETE_PEND) {
1312 fcport->login_retry++;
1313 return;
1314 }
1315
1316 if (fcport->last_rscn_gen != fcport->rscn_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -07001317 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n",
Quinn Tran726b8542017-01-19 22:28:00 -08001318 __func__, __LINE__, fcport->port_name);
1319
Giridhar Malavali5d3300a2017-12-04 14:45:13 -08001320 qla24xx_post_gidpn_work(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08001321 return;
1322 }
1323
1324 qla24xx_fcport_handle_login(vha, fcport);
1325}
1326
Quinn Tran41dc5292017-01-19 22:28:03 -08001327void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
Quinn Tran726b8542017-01-19 22:28:00 -08001328{
Quinn Tranf352eeb2017-12-28 12:33:35 -08001329 fc_port_t *f, *tf;
Quinn Tran41dc5292017-01-19 22:28:03 -08001330 uint32_t id = 0, mask, rid;
Quinn Tranf352eeb2017-12-28 12:33:35 -08001331 unsigned long flags;
Quinn Tranbee8b8462018-05-01 09:01:47 -07001332 fc_port_t *fcport;
Quinn Tran726b8542017-01-19 22:28:00 -08001333
1334 switch (ea->event) {
Quinn Tranb98ae0d2017-06-02 09:12:00 -07001335 case FCME_RELOGIN:
Quinn Tran726b8542017-01-19 22:28:00 -08001336 if (test_bit(UNLOADING, &vha->dpc_flags))
1337 return;
1338
1339 qla24xx_handle_relogin_event(vha, ea);
1340 break;
1341 case FCME_RSCN:
1342 if (test_bit(UNLOADING, &vha->dpc_flags))
1343 return;
Quinn Tran41dc5292017-01-19 22:28:03 -08001344 switch (ea->id.b.rsvd_1) {
1345 case RSCN_PORT_ADDR:
Quinn Tranbee8b8462018-05-01 09:01:47 -07001346 fcport = qla2x00_find_fcport_by_nportid
1347 (vha, &ea->id, 1);
1348 if (fcport)
1349 fcport->rscn_rcvd = 1;
1350
Quinn Tranf352eeb2017-12-28 12:33:35 -08001351 spin_lock_irqsave(&vha->work_lock, flags);
1352 if (vha->scan.scan_flags == 0) {
1353 ql_dbg(ql_dbg_disc, vha, 0xffff,
1354 "%s: schedule\n", __func__);
1355 vha->scan.scan_flags |= SF_QUEUED;
1356 schedule_delayed_work(&vha->scan.scan_work, 5);
Quinn Tran726b8542017-01-19 22:28:00 -08001357 }
Quinn Tranf352eeb2017-12-28 12:33:35 -08001358 spin_unlock_irqrestore(&vha->work_lock, flags);
1359
Quinn Tran41dc5292017-01-19 22:28:03 -08001360 break;
1361 case RSCN_AREA_ADDR:
1362 case RSCN_DOM_ADDR:
1363 if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) {
1364 mask = 0xffff00;
Quinn Tran83548fe2017-06-02 09:12:01 -07001365 ql_dbg(ql_dbg_async, vha, 0x5044,
1366 "RSCN: Area 0x%06x was affected\n",
1367 ea->id.b24);
Quinn Tran41dc5292017-01-19 22:28:03 -08001368 } else {
1369 mask = 0xff0000;
Quinn Tran83548fe2017-06-02 09:12:01 -07001370 ql_dbg(ql_dbg_async, vha, 0x507a,
1371 "RSCN: Domain 0x%06x was affected\n",
1372 ea->id.b24);
Quinn Tran41dc5292017-01-19 22:28:03 -08001373 }
1374
1375 rid = ea->id.b24 & mask;
1376 list_for_each_entry_safe(f, tf, &vha->vp_fcports,
1377 list) {
1378 id = f->d_id.b24 & mask;
1379 if (rid == id) {
1380 ea->fcport = f;
1381 qla24xx_handle_rscn_event(f, ea);
1382 }
1383 }
1384 break;
1385 case RSCN_FAB_ADDR:
1386 default:
Quinn Tran83548fe2017-06-02 09:12:01 -07001387 ql_log(ql_log_warn, vha, 0xd045,
1388 "RSCN: Fabric was affected. Addr format %d\n",
1389 ea->id.b.rsvd_1);
Quinn Tran41dc5292017-01-19 22:28:03 -08001390 qla2x00_mark_all_devices_lost(vha, 1);
1391 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1392 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Quinn Tran726b8542017-01-19 22:28:00 -08001393 }
1394 break;
1395 case FCME_GIDPN_DONE:
1396 qla24xx_handle_gidpn_event(vha, ea);
1397 break;
1398 case FCME_GNL_DONE:
1399 qla24xx_handle_gnl_done_event(vha, ea);
1400 break;
1401 case FCME_GPSC_DONE:
Quinn Trana4239942017-12-28 12:33:26 -08001402 qla24xx_handle_gpsc_event(vha, ea);
Quinn Tran726b8542017-01-19 22:28:00 -08001403 break;
1404 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1405 qla24xx_handle_plogi_done_event(vha, ea);
1406 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001407 case FCME_PRLI_DONE:
1408 qla24xx_handle_prli_done_event(vha, ea);
1409 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001410 case FCME_GPDB_DONE:
1411 qla24xx_handle_gpdb_event(vha, ea);
1412 break;
1413 case FCME_GPNID_DONE:
1414 qla24xx_handle_gpnid_event(vha, ea);
1415 break;
Duane Grigsbyd3bae932017-06-21 13:48:44 -07001416 case FCME_GFFID_DONE:
1417 qla24xx_handle_gffid_event(vha, ea);
1418 break;
Quinn Tranf13515a2017-12-28 12:33:15 -08001419 case FCME_ADISC_DONE:
1420 qla24xx_handle_adisc_event(vha, ea);
1421 break;
Quinn Trana4239942017-12-28 12:33:26 -08001422 case FCME_GNNID_DONE:
1423 qla24xx_handle_gnnid_event(vha, ea);
1424 break;
1425 case FCME_GFPNID_DONE:
1426 qla24xx_handle_gfpnid_event(vha, ea);
1427 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001428 default:
1429 BUG_ON(1);
1430 break;
1431 }
1432}
1433
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001434static void
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001435qla2x00_tmf_iocb_timeout(void *data)
1436{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001437 srb_t *sp = data;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001438 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1439
1440 tmf->u.tmf.comp_status = CS_TIMEOUT;
1441 complete(&tmf->u.tmf.comp);
1442}
1443
1444static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001445qla2x00_tmf_sp_done(void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001446{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001447 srb_t *sp = ptr;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001448 struct srb_iocb *tmf = &sp->u.iocb_cmd;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001449
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001450 complete(&tmf->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001451}
1452
1453int
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001454qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001455 uint32_t tag)
1456{
1457 struct scsi_qla_host *vha = fcport->vha;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001458 struct srb_iocb *tm_iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001459 srb_t *sp;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001460 int rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001461
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001462 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001463 if (!sp)
1464 goto done;
1465
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001466 tm_iocb = &sp->u.iocb_cmd;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001467 sp->type = SRB_TM_CMD;
1468 sp->name = "tmf";
Ben Hutchingse74e7d92018-03-20 21:36:14 +00001469
1470 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1471 init_completion(&tm_iocb->u.tmf.comp);
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001472 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
Ben Hutchingse74e7d92018-03-20 21:36:14 +00001473
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001474 tm_iocb->u.tmf.flags = flags;
1475 tm_iocb->u.tmf.lun = lun;
1476 tm_iocb->u.tmf.data = tag;
1477 sp->done = qla2x00_tmf_sp_done;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001478
1479 rval = qla2x00_start_sp(sp);
1480 if (rval != QLA_SUCCESS)
1481 goto done_free_sp;
1482
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001483 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001484 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1485 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1486 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001487
1488 wait_for_completion(&tm_iocb->u.tmf.comp);
1489
1490 rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
1491 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1492
1493 if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
1494 ql_dbg(ql_dbg_taskm, vha, 0x8030,
1495 "TM IOCB failed (%x).\n", rval);
1496 }
1497
1498 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1499 flags = tm_iocb->u.tmf.flags;
1500 lun = (uint16_t)tm_iocb->u.tmf.lun;
1501
1502 /* Issue Marker IOCB */
1503 qla2x00_marker(vha, vha->hw->req_q_map[0],
1504 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
1505 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1506 }
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001507
1508done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001509 sp->free(sp);
Quinn Tran6d6749272017-12-28 12:33:41 -08001510 sp->fcport->flags &= ~FCF_ASYNC_SENT;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001511done:
1512 return rval;
1513}
1514
Armen Baloyan4440e462014-02-26 04:15:18 -05001515static void
1516qla24xx_abort_iocb_timeout(void *data)
1517{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001518 srb_t *sp = data;
Armen Baloyan4440e462014-02-26 04:15:18 -05001519 struct srb_iocb *abt = &sp->u.iocb_cmd;
1520
1521 abt->u.abt.comp_status = CS_TIMEOUT;
1522 complete(&abt->u.abt.comp);
1523}
1524
1525static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001526qla24xx_abort_sp_done(void *ptr, int res)
Armen Baloyan4440e462014-02-26 04:15:18 -05001527{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001528 srb_t *sp = ptr;
Armen Baloyan4440e462014-02-26 04:15:18 -05001529 struct srb_iocb *abt = &sp->u.iocb_cmd;
1530
Ben Hutchings3a9910d2018-03-20 21:05:48 +00001531 if (del_timer(&sp->u.iocb_cmd.timer))
1532 complete(&abt->u.abt.comp);
Armen Baloyan4440e462014-02-26 04:15:18 -05001533}
1534
Quinn Tran15f30a52017-03-15 09:48:52 -07001535int
Armen Baloyan4440e462014-02-26 04:15:18 -05001536qla24xx_async_abort_cmd(srb_t *cmd_sp)
1537{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001538 scsi_qla_host_t *vha = cmd_sp->vha;
Armen Baloyan4440e462014-02-26 04:15:18 -05001539 fc_port_t *fcport = cmd_sp->fcport;
1540 struct srb_iocb *abt_iocb;
1541 srb_t *sp;
1542 int rval = QLA_FUNCTION_FAILED;
1543
1544 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1545 if (!sp)
1546 goto done;
1547
1548 abt_iocb = &sp->u.iocb_cmd;
1549 sp->type = SRB_ABT_CMD;
1550 sp->name = "abort";
Ben Hutchingse74e7d92018-03-20 21:36:14 +00001551
1552 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
1553 init_completion(&abt_iocb->u.abt.comp);
Armen Baloyan4440e462014-02-26 04:15:18 -05001554 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
Ben Hutchingse74e7d92018-03-20 21:36:14 +00001555
Armen Baloyan4440e462014-02-26 04:15:18 -05001556 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
Darren Trappb027a5a2018-01-15 20:46:51 -08001557
1558 if (vha->flags.qpairs_available && cmd_sp->qpair)
1559 abt_iocb->u.abt.req_que_no =
1560 cpu_to_le16(cmd_sp->qpair->req->id);
1561 else
1562 abt_iocb->u.abt.req_que_no = cpu_to_le16(vha->req->id);
1563
Armen Baloyan4440e462014-02-26 04:15:18 -05001564 sp->done = qla24xx_abort_sp_done;
Armen Baloyan4440e462014-02-26 04:15:18 -05001565
1566 rval = qla2x00_start_sp(sp);
1567 if (rval != QLA_SUCCESS)
1568 goto done_free_sp;
1569
1570 ql_dbg(ql_dbg_async, vha, 0x507c,
1571 "Abort command issued - hdl=%x, target_id=%x\n",
1572 cmd_sp->handle, fcport->tgt_id);
1573
1574 wait_for_completion(&abt_iocb->u.abt.comp);
1575
1576 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
1577 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1578
1579done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001580 sp->free(sp);
Armen Baloyan4440e462014-02-26 04:15:18 -05001581done:
1582 return rval;
1583}
1584
1585int
1586qla24xx_async_abort_command(srb_t *sp)
1587{
1588 unsigned long flags = 0;
1589
1590 uint32_t handle;
1591 fc_port_t *fcport = sp->fcport;
1592 struct scsi_qla_host *vha = fcport->vha;
1593 struct qla_hw_data *ha = vha->hw;
1594 struct req_que *req = vha->req;
1595
Darren Trappb027a5a2018-01-15 20:46:51 -08001596 if (vha->flags.qpairs_available && sp->qpair)
1597 req = sp->qpair->req;
1598
Armen Baloyan4440e462014-02-26 04:15:18 -05001599 spin_lock_irqsave(&ha->hardware_lock, flags);
1600 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1601 if (req->outstanding_cmds[handle] == sp)
1602 break;
1603 }
1604 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1605 if (handle == req->num_outstanding_cmds) {
1606 /* Command not found. */
1607 return QLA_FUNCTION_FAILED;
1608 }
1609 if (sp->type == SRB_FXIOCB_DCMD)
1610 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1611 FXDISC_ABORT_IOCTL);
1612
1613 return qla24xx_async_abort_cmd(sp);
1614}
1615
Quinn Tran726b8542017-01-19 22:28:00 -08001616static void
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001617qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1618{
1619 switch (ea->data[0]) {
1620 case MBS_COMMAND_COMPLETE:
1621 ql_dbg(ql_dbg_disc, vha, 0x2118,
1622 "%s %d %8phC post gpdb\n",
1623 __func__, __LINE__, ea->fcport->port_name);
1624
1625 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1626 ea->fcport->logout_on_delete = 1;
1627 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1628 break;
1629 default:
Darren Trapp1cbc0ef2018-03-20 23:09:37 -07001630 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
1631 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1632 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1633 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
1634 break;
1635 }
1636
Duane Grigsbyedd05de2017-10-13 09:34:06 -07001637 if (ea->fcport->n2n_flag) {
1638 ql_dbg(ql_dbg_disc, vha, 0x2118,
1639 "%s %d %8phC post fc4 prli\n",
1640 __func__, __LINE__, ea->fcport->port_name);
1641 ea->fcport->fc4f_nvme = 0;
1642 ea->fcport->n2n_flag = 0;
1643 qla24xx_post_prli_work(vha, ea->fcport);
1644 }
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001645 ql_dbg(ql_dbg_disc, vha, 0x2119,
1646 "%s %d %8phC unhandle event of %x\n",
1647 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1648 break;
1649 }
1650}
1651
1652static void
Quinn Tran726b8542017-01-19 22:28:00 -08001653qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001654{
Quinn Tran726b8542017-01-19 22:28:00 -08001655 port_id_t cid; /* conflict Nport id */
Quinn Trana084fd62017-12-04 14:45:00 -08001656 u16 lid;
1657 struct fc_port *conflict_fcport;
Quinn Tran82abdca2017-12-28 12:33:22 -08001658 unsigned long flags;
Quinn Trana4239942017-12-28 12:33:26 -08001659 struct fc_port *fcport = ea->fcport;
1660
Quinn Tranf352eeb2017-12-28 12:33:35 -08001661 ql_dbg(ql_dbg_disc, vha, 0xffff,
1662 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1663 __func__, fcport->port_name, fcport->disc_state,
1664 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
1665 ea->sp->gen2, fcport->rscn_gen|ea->sp->gen1,
1666 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
1667
Quinn Trana4239942017-12-28 12:33:26 -08001668 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1669 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
1670 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1671 "%s %d %8phC Remote is trying to login\n",
1672 __func__, __LINE__, fcport->port_name);
1673 return;
1674 }
1675
1676 if (fcport->disc_state == DSC_DELETE_PEND)
1677 return;
1678
1679 if (ea->sp->gen2 != fcport->login_gen) {
1680 /* target side must have changed it. */
1681 ql_dbg(ql_dbg_disc, vha, 0x20d3,
Quinn Tranf352eeb2017-12-28 12:33:35 -08001682 "%s %8phC generation changed\n",
1683 __func__, fcport->port_name);
1684 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Quinn Trana4239942017-12-28 12:33:26 -08001685 return;
1686 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1687 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
1688 __func__, __LINE__, fcport->port_name);
1689 qla24xx_post_gidpn_work(vha, fcport);
1690 return;
1691 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001692
Quinn Tran726b8542017-01-19 22:28:00 -08001693 switch (ea->data[0]) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07001694 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -07001695 /*
1696 * Driver must validate login state - If PRLI not complete,
1697 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1698 * requests.
1699 */
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001700 if (ea->fcport->fc4f_nvme) {
1701 ql_dbg(ql_dbg_disc, vha, 0x2117,
1702 "%s %d %8phC post prli\n",
1703 __func__, __LINE__, ea->fcport->port_name);
1704 qla24xx_post_prli_work(vha, ea->fcport);
1705 } else {
1706 ql_dbg(ql_dbg_disc, vha, 0x20ea,
Quinn Trana084fd62017-12-04 14:45:00 -08001707 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1708 __func__, __LINE__, ea->fcport->port_name,
1709 ea->fcport->loop_id, ea->fcport->d_id.b24);
1710
1711 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
Quinn Tran82abdca2017-12-28 12:33:22 -08001712 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001713 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1714 ea->fcport->logout_on_delete = 1;
Quinn Tran35158322017-08-30 10:16:50 -07001715 ea->fcport->send_els_logo = 0;
Quinn Tran82abdca2017-12-28 12:33:22 -08001716 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
1717 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1718
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001719 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1720 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001721 break;
1722 case MBS_COMMAND_ERROR:
Quinn Tran83548fe2017-06-02 09:12:01 -07001723 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
Quinn Tran726b8542017-01-19 22:28:00 -08001724 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
1725
1726 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1727 ea->fcport->disc_state = DSC_LOGIN_FAILED;
1728 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001729 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1730 else
Quinn Tran726b8542017-01-19 22:28:00 -08001731 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001732 break;
1733 case MBS_LOOP_ID_USED:
Quinn Tran726b8542017-01-19 22:28:00 -08001734 /* data[1] = IO PARAM 1 = nport ID */
1735 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
1736 cid.b.area = (ea->iop[1] >> 8) & 0xff;
1737 cid.b.al_pa = ea->iop[1] & 0xff;
1738 cid.b.rsvd_1 = 0;
1739
Quinn Tran83548fe2017-06-02 09:12:01 -07001740 ql_dbg(ql_dbg_disc, vha, 0x20ec,
1741 "%s %d %8phC LoopID 0x%x in use post gnl\n",
1742 __func__, __LINE__, ea->fcport->port_name,
1743 ea->fcport->loop_id);
Quinn Tran726b8542017-01-19 22:28:00 -08001744
1745 if (IS_SW_RESV_ADDR(cid)) {
1746 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1747 ea->fcport->loop_id = FC_NO_LOOP_ID;
1748 } else {
1749 qla2x00_clear_loop_id(ea->fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001750 }
Quinn Tran726b8542017-01-19 22:28:00 -08001751 qla24xx_post_gnl_work(vha, ea->fcport);
1752 break;
1753 case MBS_PORT_ID_USED:
Quinn Tran83548fe2017-06-02 09:12:01 -07001754 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1755 "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n",
1756 __func__, __LINE__, ea->fcport->port_name,
1757 ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area,
1758 ea->fcport->d_id.b.al_pa);
Quinn Tran726b8542017-01-19 22:28:00 -08001759
Quinn Trana084fd62017-12-04 14:45:00 -08001760 lid = ea->iop[1] & 0xffff;
1761 qlt_find_sess_invalidate_other(vha,
1762 wwn_to_u64(ea->fcport->port_name),
1763 ea->fcport->d_id, lid, &conflict_fcport);
1764
1765 if (conflict_fcport) {
1766 /*
1767 * Another fcport share the same loop_id/nport id.
1768 * Conflict fcport needs to finish cleanup before this
1769 * fcport can proceed to login.
1770 */
1771 conflict_fcport->conflict = ea->fcport;
1772 ea->fcport->login_pause = 1;
1773
1774 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1775 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
1776 __func__, __LINE__, ea->fcport->port_name,
1777 ea->fcport->d_id.b24, lid);
1778 qla2x00_clear_loop_id(ea->fcport);
1779 qla24xx_post_gidpn_work(vha, ea->fcport);
1780 } else {
1781 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1782 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
1783 __func__, __LINE__, ea->fcport->port_name,
1784 ea->fcport->d_id.b24, lid);
1785
1786 qla2x00_clear_loop_id(ea->fcport);
1787 set_bit(lid, vha->hw->loop_id_map);
1788 ea->fcport->loop_id = lid;
1789 ea->fcport->keep_nport_handle = 0;
Quinn Tran94cff6e2017-12-28 12:33:42 -08001790 qlt_schedule_sess_for_deletion(ea->fcport);
Quinn Trana084fd62017-12-04 14:45:00 -08001791 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001792 break;
1793 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001794 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001795}
1796
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001797void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001798qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1799 uint16_t *data)
1800{
Quinn Tran726b8542017-01-19 22:28:00 -08001801 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Alexei Potashnika6ca8872015-07-14 16:00:44 -04001802 qlt_logo_completion_handler(fcport, data[0]);
Quinn Tran726b8542017-01-19 22:28:00 -08001803 fcport->login_gen++;
Hannes Reineckefa83e652018-02-22 09:49:37 +01001804 fcport->flags &= ~FCF_ASYNC_ACTIVE;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001805 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001806}
1807
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001808void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001809qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1810 uint16_t *data)
1811{
Hannes Reineckefa83e652018-02-22 09:49:37 +01001812 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001813 if (data[0] == MBS_COMMAND_COMPLETE) {
1814 qla2x00_update_fcport(vha, fcport);
1815
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001816 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001817 }
1818
1819 /* Retry login. */
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001820 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
1821 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1822 else
Andrew Vasquez80d79442011-03-30 11:46:17 -07001823 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001824
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001825 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001826}
1827
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828/****************************************************************************/
1829/* QLogic ISP2x00 Hardware Support Functions. */
1830/****************************************************************************/
1831
Saurav Kashyapfa492632012-11-21 02:40:29 -05001832static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001833qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
1834{
1835 int rval = QLA_SUCCESS;
1836 struct qla_hw_data *ha = vha->hw;
1837 uint32_t idc_major_ver, idc_minor_ver;
Saurav Kashyap711aa7f2012-08-22 14:21:15 -04001838 uint16_t config[4];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001839
1840 qla83xx_idc_lock(vha, 0);
1841
1842 /* SV: TODO: Assign initialization timeout from
1843 * flash-info / other param
1844 */
1845 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
1846 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
1847
1848 /* Set our fcoe function presence */
1849 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
1850 ql_dbg(ql_dbg_p3p, vha, 0xb077,
1851 "Error while setting DRV-Presence.\n");
1852 rval = QLA_FUNCTION_FAILED;
1853 goto exit;
1854 }
1855
1856 /* Decide the reset ownership */
1857 qla83xx_reset_ownership(vha);
1858
1859 /*
1860 * On first protocol driver load:
1861 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
1862 * register.
1863 * Others: Check compatibility with current IDC Major version.
1864 */
1865 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
1866 if (ha->flags.nic_core_reset_owner) {
1867 /* Set IDC Major version */
1868 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
1869 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
1870
1871 /* Clearing IDC-Lock-Recovery register */
1872 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
1873 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
1874 /*
1875 * Clear further IDC participation if we are not compatible with
1876 * the current IDC Major Version.
1877 */
1878 ql_log(ql_log_warn, vha, 0xb07d,
1879 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
1880 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
1881 __qla83xx_clear_drv_presence(vha);
1882 rval = QLA_FUNCTION_FAILED;
1883 goto exit;
1884 }
1885 /* Each function sets its supported Minor version. */
1886 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
1887 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
1888 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
1889
Saurav Kashyap711aa7f2012-08-22 14:21:15 -04001890 if (ha->flags.nic_core_reset_owner) {
1891 memset(config, 0, sizeof(config));
1892 if (!qla81xx_get_port_config(vha, config))
1893 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
1894 QLA8XXX_DEV_READY);
1895 }
1896
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001897 rval = qla83xx_idc_state_handler(vha);
1898
1899exit:
1900 qla83xx_idc_unlock(vha, 0);
1901
1902 return rval;
1903}
1904
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905/*
1906* qla2x00_initialize_adapter
1907* Initialize board.
1908*
1909* Input:
1910* ha = adapter block pointer.
1911*
1912* Returns:
1913* 0 = success
1914*/
1915int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001916qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917{
1918 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001919 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001920 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001921
Joe Carnucciofc90ada2016-07-06 11:14:23 -04001922 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
1923 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
1924
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001926 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001927 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001928 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -08001929 ha->flags.pci_channel_io_perm_failure = 0;
1930 ha->flags.eeh_busy = 0;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -04001931 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001932 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1933 atomic_set(&vha->loop_state, LOOP_DOWN);
1934 vha->device_flags = DFLG_NO_CABLE;
1935 vha->dpc_flags = 0;
1936 vha->flags.management_server_logged_in = 0;
1937 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 ha->isp_abort_cnt = 0;
1939 ha->beacon_blink_led = 0;
1940
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001941 set_bit(0, ha->req_qid_map);
1942 set_bit(0, ha->rsp_qid_map);
1943
Chad Dupuiscfb09192011-11-18 09:03:07 -08001944 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001945 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001946 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001948 ql_log(ql_log_warn, vha, 0x0044,
1949 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 return (rval);
1951 }
1952
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001953 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001955 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001956 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001957 ql_log(ql_log_fatal, vha, 0x004f,
1958 "Unable to validate FLASH data.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001959 return rval;
1960 }
1961
1962 if (IS_QLA8044(ha)) {
1963 qla8044_read_reset_template(vha);
1964
1965 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
1966 * If DONRESET_BIT0 is set, drivers should not set dev_state
1967 * to NEED_RESET. But if NEED_RESET is set, drivers should
1968 * should honor the reset. */
1969 if (ql2xdontresethba == 1)
1970 qla8044_set_idc_dontreset(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001971 }
1972
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001973 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001974 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001975 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001976
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001977 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001979 if (ha->flags.disable_serdes) {
1980 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001981 ql_log(ql_log_info, vha, 0x0077,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001982 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001983 return QLA_FUNCTION_FAILED;
1984 }
1985
Chad Dupuiscfb09192011-11-18 09:03:07 -08001986 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001987 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001989 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
1990 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001991 if (rval)
1992 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001993 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001994 if (rval)
1995 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07001997
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001998 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001999 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002000 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002001 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002002 "Unable to configure ISP84XX.\n");
2003 return QLA_FUNCTION_FAILED;
2004 }
2005 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002006
Quinn Tranead03852017-01-19 22:28:01 -08002007 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002008 rval = qla2x00_init_rings(vha);
2009
Lalit Chandivade2533cf62009-03-24 09:08:07 -07002010 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002012 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -07002013 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002014 rval = qla84xx_init_chip(vha);
2015 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002016 ql_log(ql_log_warn, vha, 0x00d4,
2017 "Unable to initialize ISP84XX.\n");
Bart Van Assche8d2b21d2015-06-04 15:58:09 -07002018 qla84xx_put_chip(vha);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002019 }
2020 }
2021
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04002022 /* Load the NIC Core f/w if we are the first protocol driver. */
2023 if (IS_QLA8031(ha)) {
2024 rval = qla83xx_nic_core_fw_load(vha);
2025 if (rval)
2026 ql_log(ql_log_warn, vha, 0x0124,
2027 "Error in initializing NIC Core f/w.\n");
2028 }
2029
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +05002030 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2031 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -07002032
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04002033 if (IS_P3P_TYPE(ha))
2034 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2035 else
2036 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2037
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 return (rval);
2039}
2040
2041/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002042 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Bart Van Assche2db62282018-01-23 16:33:51 -08002043 * @vha: HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 *
2045 * Returns 0 on success.
2046 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002047int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002048qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049{
Andrew Vasqueza157b102007-05-07 07:43:01 -07002050 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002051 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002053 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07002056 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07002059 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2061
Andrew Vasquez737faec2008-10-24 15:13:45 -07002062 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002064 /* Get PCI bus information. */
2065 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07002066 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002067 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2068
2069 return QLA_SUCCESS;
2070}
2071
2072/**
2073 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
Bart Van Assche2db62282018-01-23 16:33:51 -08002074 * @vha: HA context
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002075 *
2076 * Returns 0 on success.
2077 */
2078int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002079qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002080{
Andrew Vasqueza157b102007-05-07 07:43:01 -07002081 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002082 unsigned long flags = 0;
2083 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002084 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002085 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002086
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002087 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07002088 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002089
2090 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07002091 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002092
2093 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2094 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -07002095 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002096
2097 /*
2098 * If this is a 2300 card and not 2312, reset the
2099 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2100 * the 2310 also reports itself as a 2300 so we need to get the
2101 * fb revision level -- a 6 indicates it really is a 2300 and
2102 * not a 2310.
2103 */
2104 if (IS_QLA2300(ha)) {
2105 spin_lock_irqsave(&ha->hardware_lock, flags);
2106
2107 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07002108 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002109 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07002110 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002111 break;
2112
2113 udelay(10);
2114 }
2115
2116 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07002117 WRT_REG_WORD(&reg->ctrl_status, 0x20);
2118 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002119
2120 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -07002121 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002122
2123 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -07002124 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002125
2126 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07002127 WRT_REG_WORD(&reg->ctrl_status, 0x0);
2128 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002129
2130 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07002131 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002132 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07002133 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002134 break;
2135
2136 udelay(10);
2137 }
2138
2139 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2140 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002141
2142 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2143
Andrew Vasquez737faec2008-10-24 15:13:45 -07002144 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002145
2146 /* Get PCI bus information. */
2147 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07002148 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002149 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2150
2151 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152}
2153
2154/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002155 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
Bart Van Assche2db62282018-01-23 16:33:51 -08002156 * @vha: HA context
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002157 *
2158 * Returns 0 on success.
2159 */
2160int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002161qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002162{
Andrew Vasqueza157b102007-05-07 07:43:01 -07002163 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002164 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002165 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002166 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002167
2168 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07002169 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002170
2171 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07002172 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002173 w &= ~PCI_COMMAND_INTX_DISABLE;
2174 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2175
2176 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2177
2178 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -07002179 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2180 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002181
2182 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07002183 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04002184 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002185
Andrew Vasquez737faec2008-10-24 15:13:45 -07002186 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002187
Auke Kok44c10132007-06-08 15:46:36 -07002188 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08002189
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002190 /* Get PCI bus information. */
2191 spin_lock_irqsave(&ha->hardware_lock, flags);
2192 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
2193 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2194
2195 return QLA_SUCCESS;
2196}
2197
2198/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002199 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
Bart Van Assche2db62282018-01-23 16:33:51 -08002200 * @vha: HA context
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002201 *
2202 * Returns 0 on success.
2203 */
2204int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002205qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002206{
2207 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002208 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002209
2210 pci_set_master(ha->pdev);
2211 pci_try_set_mwi(ha->pdev);
2212
2213 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2214 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2215 w &= ~PCI_COMMAND_INTX_DISABLE;
2216 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2217
2218 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07002219 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04002220 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002221
Andrew Vasquez737faec2008-10-24 15:13:45 -07002222 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002223
2224 ha->chip_revision = ha->pdev->revision;
2225
2226 return QLA_SUCCESS;
2227}
2228
2229/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 * qla2x00_isp_firmware() - Choose firmware image.
Bart Van Assche2db62282018-01-23 16:33:51 -08002231 * @vha: HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 *
2233 * Returns 0 on success.
2234 */
2235static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002236qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237{
2238 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07002239 uint16_t loop_id, topo, sw_cap;
2240 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002241 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
2243 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002244 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
2246 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002247 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
2249 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002250 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -07002251 if (rval == QLA_SUCCESS) {
2252 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002253 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -07002254 &area, &domain, &topo, &sw_cap);
2255 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 }
2257
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002258 if (rval)
2259 ql_dbg(ql_dbg_init, vha, 0x007a,
2260 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
2262 return (rval);
2263}
2264
2265/**
2266 * qla2x00_reset_chip() - Reset ISP chip.
Bart Van Assche2db62282018-01-23 16:33:51 -08002267 * @vha: HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 *
2269 * Returns 0 on success.
2270 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002271void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002272qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273{
2274 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002275 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002276 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 uint16_t cmd;
2279
Andrew Vasquez85880802009-12-15 21:29:46 -08002280 if (unlikely(pci_channel_offline(ha->pdev)))
2281 return;
2282
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002283 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284
2285 spin_lock_irqsave(&ha->hardware_lock, flags);
2286
2287 /* Turn off master enable */
2288 cmd = 0;
2289 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2290 cmd &= ~PCI_COMMAND_MASTER;
2291 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2292
2293 if (!IS_QLA2100(ha)) {
2294 /* Pause RISC. */
2295 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
2296 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2297 for (cnt = 0; cnt < 30000; cnt++) {
2298 if ((RD_REG_WORD(&reg->hccr) &
2299 HCCR_RISC_PAUSE) != 0)
2300 break;
2301 udelay(100);
2302 }
2303 } else {
2304 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2305 udelay(10);
2306 }
2307
2308 /* Select FPM registers. */
2309 WRT_REG_WORD(&reg->ctrl_status, 0x20);
2310 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2311
2312 /* FPM Soft Reset. */
2313 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
2314 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
2315
2316 /* Toggle Fpm Reset. */
2317 if (!IS_QLA2200(ha)) {
2318 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
2319 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
2320 }
2321
2322 /* Select frame buffer registers. */
2323 WRT_REG_WORD(&reg->ctrl_status, 0x10);
2324 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2325
2326 /* Reset frame buffer FIFOs. */
2327 if (IS_QLA2200(ha)) {
2328 WRT_FB_CMD_REG(ha, reg, 0xa000);
2329 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2330 } else {
2331 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2332
2333 /* Read back fb_cmd until zero or 3 seconds max */
2334 for (cnt = 0; cnt < 3000; cnt++) {
2335 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2336 break;
2337 udelay(100);
2338 }
2339 }
2340
2341 /* Select RISC module registers. */
2342 WRT_REG_WORD(&reg->ctrl_status, 0);
2343 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2344
2345 /* Reset RISC processor. */
2346 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2347 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2348
2349 /* Release RISC processor. */
2350 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2351 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2352 }
2353
2354 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
2355 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
2356
2357 /* Reset ISP chip. */
2358 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
2359
2360 /* Wait for RISC to recover from reset. */
2361 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2362 /*
2363 * It is necessary to for a delay here since the card doesn't
2364 * respond to PCI reads during a reset. On some architectures
2365 * this will result in an MCA.
2366 */
2367 udelay(20);
2368 for (cnt = 30000; cnt; cnt--) {
2369 if ((RD_REG_WORD(&reg->ctrl_status) &
2370 CSR_ISP_SOFT_RESET) == 0)
2371 break;
2372 udelay(100);
2373 }
2374 } else
2375 udelay(10);
2376
2377 /* Reset RISC processor. */
2378 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2379
2380 WRT_REG_WORD(&reg->semaphore, 0);
2381
2382 /* Release RISC processor. */
2383 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2384 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2385
2386 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2387 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -07002388 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390
2391 udelay(100);
2392 }
2393 } else
2394 udelay(100);
2395
2396 /* Turn on master enable */
2397 cmd |= PCI_COMMAND_MASTER;
2398 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2399
2400 /* Disable RISC pause on FPM parity error. */
2401 if (!IS_QLA2100(ha)) {
2402 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
2403 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2404 }
2405
2406 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2407}
2408
2409/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002410 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
Bart Van Assche2db62282018-01-23 16:33:51 -08002411 * @vha: HA context
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002412 *
2413 * Returns 0 on success.
2414 */
Saurav Kashyapfa492632012-11-21 02:40:29 -05002415static int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002416qla81xx_reset_mpi(scsi_qla_host_t *vha)
2417{
2418 uint16_t mb[4] = {0x1010, 0, 1, 0};
2419
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002420 if (!IS_QLA81XX(vha->hw))
2421 return QLA_SUCCESS;
2422
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002423 return qla81xx_write_mpi_register(vha, mb);
2424}
2425
2426/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002427 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Bart Van Assche2db62282018-01-23 16:33:51 -08002428 * @vha: HA context
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002429 *
2430 * Returns 0 on success.
2431 */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002432static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002433qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002434{
2435 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002436 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002437 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Bart Van Assche52c82822015-07-09 07:23:26 -07002438 uint32_t cnt;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002439 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002440 static int abts_cnt; /* ISP abort retry counts */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002441 int rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002442
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002443 spin_lock_irqsave(&ha->hardware_lock, flags);
2444
2445 /* Reset RISC. */
2446 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2447 for (cnt = 0; cnt < 30000; cnt++) {
2448 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2449 break;
2450
2451 udelay(10);
2452 }
2453
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002454 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE))
2455 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2456
2457 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2458 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2459 RD_REG_DWORD(&reg->hccr),
2460 RD_REG_DWORD(&reg->ctrl_status),
2461 (RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE));
2462
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002463 WRT_REG_DWORD(&reg->ctrl_status,
2464 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002465 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002466
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002467 udelay(100);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002468
Andrew Vasquez88c26662005-07-08 17:59:26 -07002469 /* Wait for firmware to complete NVRAM accesses. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002470 RD_REG_WORD(&reg->mailbox0);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002471 for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
2472 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez88c26662005-07-08 17:59:26 -07002473 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002474 if (cnt)
2475 udelay(5);
2476 else
2477 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez88c26662005-07-08 17:59:26 -07002478 }
2479
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002480 if (rval == QLA_SUCCESS)
2481 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2482
2483 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2484 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2485 RD_REG_DWORD(&reg->hccr),
2486 RD_REG_DWORD(&reg->mailbox0));
2487
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002488 /* Wait for soft-reset to complete. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002489 RD_REG_DWORD(&reg->ctrl_status);
Quinn Tran200ffb12016-12-23 18:06:12 -08002490 for (cnt = 0; cnt < 60; cnt++) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002491 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002492 if ((RD_REG_DWORD(&reg->ctrl_status) &
2493 CSRX_ISP_SOFT_RESET) == 0)
2494 break;
2495
2496 udelay(5);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002497 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002498 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_ISP_SOFT_RESET))
2499 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2500
2501 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2502 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2503 RD_REG_DWORD(&reg->hccr),
2504 RD_REG_DWORD(&reg->ctrl_status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002505
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002506 /* If required, do an MPI FW reset now */
2507 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2508 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2509 if (++abts_cnt < 5) {
2510 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2511 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2512 } else {
2513 /*
2514 * We exhausted the ISP abort retries. We have to
2515 * set the board offline.
2516 */
2517 abts_cnt = 0;
2518 vha->flags.online = 0;
2519 }
2520 }
2521 }
2522
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002523 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
2524 RD_REG_DWORD(&reg->hccr);
2525
2526 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
2527 RD_REG_DWORD(&reg->hccr);
2528
2529 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
2530 RD_REG_DWORD(&reg->hccr);
2531
Bart Van Assche52c82822015-07-09 07:23:26 -07002532 RD_REG_WORD(&reg->mailbox0);
Quinn Tran200ffb12016-12-23 18:06:12 -08002533 for (cnt = 60; RD_REG_WORD(&reg->mailbox0) != 0 &&
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002534 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002535 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002536 if (cnt)
2537 udelay(5);
2538 else
2539 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002540 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002541 if (rval == QLA_SUCCESS)
2542 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2543
2544 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2545 "Host Risc 0x%x, mailbox0 0x%x\n",
2546 RD_REG_DWORD(&reg->hccr),
2547 RD_REG_WORD(&reg->mailbox0));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002548
2549 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002550
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002551 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2552 "Driver in %s mode\n",
2553 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2554
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002555 if (IS_NOPOLLING_TYPE(ha))
2556 ha->isp_ops->enable_intrs(ha);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002557
2558 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002559}
2560
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002561static void
2562qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2563{
2564 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2565
2566 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2567 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2568
2569}
2570
2571static void
2572qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2573{
2574 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2575
2576 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2577 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2578}
2579
2580static void
2581qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2582{
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002583 uint32_t wd32 = 0;
2584 uint delta_msec = 100;
2585 uint elapsed_msec = 0;
2586 uint timeout_msec;
2587 ulong n;
2588
Joe Carnucciocc790762015-08-04 13:37:53 -04002589 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2590 vha->hw->pdev->subsystem_device != 0x0240)
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002591 return;
2592
Joe Carnuccio8dd7e3a2015-08-04 13:37:54 -04002593 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2594 udelay(100);
2595
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002596attempt:
2597 timeout_msec = TIMEOUT_SEMAPHORE;
2598 n = timeout_msec / delta_msec;
2599 while (n--) {
2600 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2601 qla25xx_read_risc_sema_reg(vha, &wd32);
2602 if (wd32 & RISC_SEMAPHORE)
2603 break;
2604 msleep(delta_msec);
2605 elapsed_msec += delta_msec;
2606 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2607 goto force;
2608 }
2609
2610 if (!(wd32 & RISC_SEMAPHORE))
2611 goto force;
2612
2613 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2614 goto acquired;
2615
2616 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2617 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2618 n = timeout_msec / delta_msec;
2619 while (n--) {
2620 qla25xx_read_risc_sema_reg(vha, &wd32);
2621 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2622 break;
2623 msleep(delta_msec);
2624 elapsed_msec += delta_msec;
2625 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2626 goto force;
2627 }
2628
2629 if (wd32 & RISC_SEMAPHORE_FORCE)
2630 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2631
2632 goto attempt;
2633
2634force:
2635 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2636
2637acquired:
2638 return;
2639}
2640
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002641/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002642 * qla24xx_reset_chip() - Reset ISP24xx chip.
Bart Van Assche2db62282018-01-23 16:33:51 -08002643 * @vha: HA context
Andrew Vasquez88c26662005-07-08 17:59:26 -07002644 *
2645 * Returns 0 on success.
2646 */
2647void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002648qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07002649{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002650 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08002651
2652 if (pci_channel_offline(ha->pdev) &&
2653 ha->flags.pci_channel_io_perm_failure) {
2654 return;
2655 }
2656
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002657 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002658
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002659 qla25xx_manipulate_risc_semaphore(vha);
2660
Andrew Vasquez88c26662005-07-08 17:59:26 -07002661 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002662 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002663}
2664
2665/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 * qla2x00_chip_diag() - Test chip for proper operation.
Bart Van Assche2db62282018-01-23 16:33:51 -08002667 * @vha: HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 *
2669 * Returns 0 on success.
2670 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002671int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002672qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673{
2674 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002675 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002676 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 unsigned long flags = 0;
2678 uint16_t data;
2679 uint32_t cnt;
2680 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002681 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682
2683 /* Assume a failed state */
2684 rval = QLA_FUNCTION_FAILED;
2685
Bart Van Asscheda4704d2018-01-23 16:33:47 -08002686 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
2687 &reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688
2689 spin_lock_irqsave(&ha->hardware_lock, flags);
2690
2691 /* Reset ISP chip. */
2692 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
2693
2694 /*
2695 * We need to have a delay here since the card will not respond while
2696 * in reset causing an MCA on some architectures.
2697 */
2698 udelay(20);
2699 data = qla2x00_debounce_register(&reg->ctrl_status);
2700 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2701 udelay(5);
2702 data = RD_REG_WORD(&reg->ctrl_status);
2703 barrier();
2704 }
2705
2706 if (!cnt)
2707 goto chip_diag_failed;
2708
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002709 ql_dbg(ql_dbg_init, vha, 0x007c,
2710 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711
2712 /* Reset RISC processor. */
2713 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2714 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2715
2716 /* Workaround for QLA2312 PCI parity error */
2717 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2718 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2719 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2720 udelay(5);
2721 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002722 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 }
2724 } else
2725 udelay(10);
2726
2727 if (!cnt)
2728 goto chip_diag_failed;
2729
2730 /* Check product ID of chip */
Milan P Gandhi5a68a1c2017-03-31 14:37:04 -07002731 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732
2733 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
2734 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
2735 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
2736 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
2737 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
2738 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002739 ql_log(ql_log_warn, vha, 0x0062,
2740 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2741 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742
2743 goto chip_diag_failed;
2744 }
2745 ha->product_id[0] = mb[1];
2746 ha->product_id[1] = mb[2];
2747 ha->product_id[2] = mb[3];
2748 ha->product_id[3] = mb[4];
2749
2750 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002751 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
2753 else
2754 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002755 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756
2757 if (IS_QLA2200(ha) &&
2758 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
2759 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002760 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002762 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 ha->fw_transfer_size = 128;
2764 }
2765
2766 /* Wrap Incoming Mailboxes Test. */
2767 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2768
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002769 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002770 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002771 if (rval)
2772 ql_log(ql_log_warn, vha, 0x0080,
2773 "Failed mailbox send register test.\n");
2774 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 /* Flag a successful rval */
2776 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 spin_lock_irqsave(&ha->hardware_lock, flags);
2778
2779chip_diag_failed:
2780 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002781 ql_log(ql_log_info, vha, 0x0081,
2782 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783
2784 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2785
2786 return (rval);
2787}
2788
2789/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002790 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
Bart Van Assche2db62282018-01-23 16:33:51 -08002791 * @vha: HA context
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002792 *
2793 * Returns 0 on success.
2794 */
2795int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002796qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002797{
2798 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002799 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002800 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002801
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002802 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07002803 return QLA_SUCCESS;
2804
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002805 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002806
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002807 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002808 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002809 ql_log(ql_log_warn, vha, 0x0082,
2810 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002811 } else {
2812 /* Flag a successful rval */
2813 rval = QLA_SUCCESS;
2814 }
2815
2816 return rval;
2817}
2818
Quinn Tranad0a0b02017-12-28 12:33:14 -08002819static void
2820qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002821{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002822 int rval;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002823 dma_addr_t tc_dma;
2824 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002825 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002826
Quinn Tranad0a0b02017-12-28 12:33:14 -08002827 if (ha->eft) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002828 ql_dbg(ql_dbg_init, vha, 0x00bd,
Quinn Tranad0a0b02017-12-28 12:33:14 -08002829 "%s: Offload Mem is already allocated.\n",
2830 __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002831 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002832 }
2833
Quinn Tranad0a0b02017-12-28 12:33:14 -08002834 if (IS_FWI2_CAPABLE(ha)) {
2835 /* Allocate memory for Fibre Channel Event Buffer. */
2836 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2837 !IS_QLA27XX(ha))
2838 goto try_eft;
2839
2840 if (ha->fce)
2841 dma_free_coherent(&ha->pdev->dev,
2842 FCE_SIZE, ha->fce, ha->fce_dma);
2843
2844 /* Allocate memory for Fibre Channel Event Buffer. */
2845 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
2846 GFP_KERNEL);
2847 if (!tc) {
2848 ql_log(ql_log_warn, vha, 0x00be,
2849 "Unable to allocate (%d KB) for FCE.\n",
2850 FCE_SIZE / 1024);
2851 goto try_eft;
2852 }
2853
2854 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
2855 ha->fce_mb, &ha->fce_bufs);
2856 if (rval) {
2857 ql_log(ql_log_warn, vha, 0x00bf,
2858 "Unable to initialize FCE (%d).\n", rval);
2859 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
2860 tc_dma);
2861 ha->flags.fce_enabled = 0;
2862 goto try_eft;
2863 }
2864 ql_dbg(ql_dbg_init, vha, 0x00c0,
2865 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
2866
2867 ha->flags.fce_enabled = 1;
2868 ha->fce_dma = tc_dma;
2869 ha->fce = tc;
2870
2871try_eft:
2872 if (ha->eft)
2873 dma_free_coherent(&ha->pdev->dev,
2874 EFT_SIZE, ha->eft, ha->eft_dma);
2875
2876 /* Allocate memory for Extended Trace Buffer. */
2877 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
2878 GFP_KERNEL);
2879 if (!tc) {
2880 ql_log(ql_log_warn, vha, 0x00c1,
2881 "Unable to allocate (%d KB) for EFT.\n",
2882 EFT_SIZE / 1024);
2883 goto eft_err;
2884 }
2885
2886 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
2887 if (rval) {
2888 ql_log(ql_log_warn, vha, 0x00c2,
2889 "Unable to initialize EFT (%d).\n", rval);
2890 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
2891 tc_dma);
2892 goto eft_err;
2893 }
2894 ql_dbg(ql_dbg_init, vha, 0x00c3,
2895 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
2896
2897 ha->eft_dma = tc_dma;
2898 ha->eft = tc;
2899 }
2900
2901eft_err:
2902 return;
2903}
2904
2905void
2906qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
2907{
2908 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
2909 eft_size, fce_size, mq_size;
2910 struct qla_hw_data *ha = vha->hw;
2911 struct req_que *req = ha->req_q_map[0];
2912 struct rsp_que *rsp = ha->rsp_q_map[0];
2913 struct qla2xxx_fw_dump *fw_dump;
2914
Chad Dupuisf73cb692014-02-26 04:15:06 -05002915 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
2916 req_q_size = rsp_q_size = 0;
2917
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002918 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2919 fixed_size = sizeof(struct qla2100_fw_dump);
2920 } else if (IS_QLA23XX(ha)) {
2921 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
2922 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
2923 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07002924 } else if (IS_FWI2_CAPABLE(ha)) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002925 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002926 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
2927 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002928 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
2929 else if (IS_QLA25XX(ha))
2930 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
2931 else
2932 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002933
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002934 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
2935 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002936 if (ha->mqenable) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002937 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002938 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002939 /*
2940 * Allocate maximum buffer size for all queues.
2941 * Resizing must be done at end-of-dump processing.
2942 */
2943 mq_size += ha->max_req_queues *
2944 (req->length * sizeof(request_t));
2945 mq_size += ha->max_rsp_queues *
2946 (rsp->length * sizeof(response_t));
2947 }
Arun Easi00876ae2013-03-25 02:21:37 -04002948 if (ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002949 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002950 /* Allocate memory for Fibre Channel Event Buffer. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05002951 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2952 !IS_QLA27XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002953 goto try_eft;
2954
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07002955 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002956try_eft:
Chad Dupuiscfb09192011-11-18 09:03:07 -08002957 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002958 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002959 eft_size = EFT_SIZE;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002960 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05002961
Chad Dupuisf73cb692014-02-26 04:15:06 -05002962 if (IS_QLA27XX(ha)) {
2963 if (!ha->fw_dump_template) {
2964 ql_log(ql_log_warn, vha, 0x00ba,
2965 "Failed missing fwdump template\n");
2966 return;
2967 }
2968 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
2969 ql_dbg(ql_dbg_init, vha, 0x00fa,
2970 "-> allocating fwdump (%x bytes)...\n", dump_size);
2971 goto allocate;
2972 }
2973
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002974 req_q_size = req->length * sizeof(request_t);
2975 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002976 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002977 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08002978 ha->chain_offset = dump_size;
2979 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002980
Quinn Tranb945e772017-06-13 20:47:29 -07002981 if (ha->exchoffld_buf)
2982 dump_size += sizeof(struct qla2xxx_offld_chain) +
2983 ha->exchoffld_size;
2984 if (ha->exlogin_buf)
2985 dump_size += sizeof(struct qla2xxx_offld_chain) +
2986 ha->exlogin_size;
2987
Chad Dupuisf73cb692014-02-26 04:15:06 -05002988allocate:
Quinn Tranad0a0b02017-12-28 12:33:14 -08002989 if (!ha->fw_dump_len || dump_size != ha->fw_dump_len) {
2990 fw_dump = vmalloc(dump_size);
2991 if (!fw_dump) {
2992 ql_log(ql_log_warn, vha, 0x00c4,
2993 "Unable to allocate (%d KB) for firmware dump.\n",
2994 dump_size / 1024);
2995 } else {
2996 if (ha->fw_dump)
2997 vfree(ha->fw_dump);
2998 ha->fw_dump = fw_dump;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002999
Quinn Tranad0a0b02017-12-28 12:33:14 -08003000 ha->fw_dump_len = dump_size;
3001 ql_dbg(ql_dbg_init, vha, 0x00c5,
3002 "Allocated (%d KB) for firmware dump.\n",
3003 dump_size / 1024);
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07003004
Quinn Tranad0a0b02017-12-28 12:33:14 -08003005 if (IS_QLA27XX(ha))
3006 return;
3007
3008 ha->fw_dump->signature[0] = 'Q';
3009 ha->fw_dump->signature[1] = 'L';
3010 ha->fw_dump->signature[2] = 'G';
3011 ha->fw_dump->signature[3] = 'C';
3012 ha->fw_dump->version = htonl(1);
3013
3014 ha->fw_dump->fixed_size = htonl(fixed_size);
3015 ha->fw_dump->mem_size = htonl(mem_size);
3016 ha->fw_dump->req_q_size = htonl(req_q_size);
3017 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3018
3019 ha->fw_dump->eft_size = htonl(eft_size);
3020 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
3021 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
3022
3023 ha->fw_dump->header_size =
3024 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003025 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003026 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003027}
3028
Andrew Vasquez18e75552009-06-03 09:55:30 -07003029static int
3030qla81xx_mpi_sync(scsi_qla_host_t *vha)
3031{
3032#define MPS_MASK 0xe0
3033 int rval;
3034 uint16_t dc;
3035 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07003036
3037 if (!IS_QLA81XX(vha->hw))
3038 return QLA_SUCCESS;
3039
3040 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3041 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003042 ql_log(ql_log_warn, vha, 0x0105,
3043 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07003044 goto done;
3045 }
3046
3047 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3048 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3049 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003050 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07003051 goto done_release;
3052 }
3053
3054 dc &= MPS_MASK;
3055 if (dc == (dw & MPS_MASK))
3056 goto done_release;
3057
3058 dw &= ~MPS_MASK;
3059 dw |= dc;
3060 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3061 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003062 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07003063 }
3064
3065done_release:
3066 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3067 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003068 ql_log(ql_log_warn, vha, 0x006d,
3069 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07003070 }
3071
3072done:
3073 return rval;
3074}
3075
Chad Dupuis8d93f552013-01-30 03:34:37 -05003076int
3077qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3078{
3079 /* Don't try to reallocate the array */
3080 if (req->outstanding_cmds)
3081 return QLA_SUCCESS;
3082
Michael Hernandezd7459522016-12-12 14:40:07 -08003083 if (!IS_FWI2_CAPABLE(ha))
Chad Dupuis8d93f552013-01-30 03:34:37 -05003084 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3085 else {
Quinn Tran03e8c682015-12-17 14:56:59 -05003086 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3087 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05003088 else
Quinn Tran03e8c682015-12-17 14:56:59 -05003089 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05003090 }
3091
Kees Cook6396bb22018-06-12 14:03:40 -07003092 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3093 sizeof(srb_t *),
3094 GFP_KERNEL);
Chad Dupuis8d93f552013-01-30 03:34:37 -05003095
3096 if (!req->outstanding_cmds) {
3097 /*
3098 * Try to allocate a minimal size just so we can get through
3099 * initialization.
3100 */
3101 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
Kees Cook6396bb22018-06-12 14:03:40 -07003102 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3103 sizeof(srb_t *),
3104 GFP_KERNEL);
Chad Dupuis8d93f552013-01-30 03:34:37 -05003105
3106 if (!req->outstanding_cmds) {
3107 ql_log(ql_log_fatal, NULL, 0x0126,
3108 "Failed to allocate memory for "
3109 "outstanding_cmds for req_que %p.\n", req);
3110 req->num_outstanding_cmds = 0;
3111 return QLA_FUNCTION_FAILED;
3112 }
3113 }
3114
3115 return QLA_SUCCESS;
3116}
3117
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003118#define PRINT_FIELD(_field, _flag, _str) { \
3119 if (a0->_field & _flag) {\
3120 if (p) {\
3121 strcat(ptr, "|");\
3122 ptr++;\
3123 leftover--;\
3124 } \
3125 len = snprintf(ptr, leftover, "%s", _str); \
3126 p = 1;\
3127 leftover -= len;\
3128 ptr += len; \
3129 } \
3130}
3131
3132static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3133{
3134#define STR_LEN 64
3135 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3136 u8 str[STR_LEN], *ptr, p;
3137 int leftover, len;
3138
3139 memset(str, 0, STR_LEN);
3140 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3141 ql_dbg(ql_dbg_init, vha, 0x015a,
3142 "SFP MFG Name: %s\n", str);
3143
3144 memset(str, 0, STR_LEN);
3145 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3146 ql_dbg(ql_dbg_init, vha, 0x015c,
3147 "SFP Part Name: %s\n", str);
3148
3149 /* media */
3150 memset(str, 0, STR_LEN);
3151 ptr = str;
3152 leftover = STR_LEN;
3153 p = len = 0;
3154 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3155 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3156 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3157 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3158 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3159 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3160 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3161 ql_dbg(ql_dbg_init, vha, 0x0160,
3162 "SFP Media: %s\n", str);
3163
3164 /* link length */
3165 memset(str, 0, STR_LEN);
3166 ptr = str;
3167 leftover = STR_LEN;
3168 p = len = 0;
3169 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3170 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3171 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3172 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3173 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3174 ql_dbg(ql_dbg_init, vha, 0x0196,
3175 "SFP Link Length: %s\n", str);
3176
3177 memset(str, 0, STR_LEN);
3178 ptr = str;
3179 leftover = STR_LEN;
3180 p = len = 0;
3181 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3182 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3183 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3184 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3185 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3186 ql_dbg(ql_dbg_init, vha, 0x016e,
3187 "SFP FC Link Tech: %s\n", str);
3188
3189 if (a0->length_km)
3190 ql_dbg(ql_dbg_init, vha, 0x016f,
3191 "SFP Distant: %d km\n", a0->length_km);
3192 if (a0->length_100m)
3193 ql_dbg(ql_dbg_init, vha, 0x0170,
3194 "SFP Distant: %d m\n", a0->length_100m*100);
3195 if (a0->length_50um_10m)
3196 ql_dbg(ql_dbg_init, vha, 0x0189,
3197 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3198 if (a0->length_62um_10m)
3199 ql_dbg(ql_dbg_init, vha, 0x018a,
3200 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3201 if (a0->length_om4_10m)
3202 ql_dbg(ql_dbg_init, vha, 0x0194,
3203 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3204 if (a0->length_om3_10m)
3205 ql_dbg(ql_dbg_init, vha, 0x0195,
3206 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3207}
3208
3209
3210/*
3211 * Return Code:
3212 * QLA_SUCCESS: no action
3213 * QLA_INTERFACE_ERROR: SFP is not there.
3214 * QLA_FUNCTION_FAILED: detected New SFP
3215 */
3216int
3217qla24xx_detect_sfp(scsi_qla_host_t *vha)
3218{
3219 int rc = QLA_SUCCESS;
3220 struct sff_8247_a0 *a;
3221 struct qla_hw_data *ha = vha->hw;
3222
3223 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3224 goto out;
3225
3226 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3227 if (rc)
3228 goto out;
3229
3230 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3231 qla2xxx_print_sfp_info(vha);
3232
3233 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3234 /* long range */
3235 ha->flags.detected_lr_sfp = 1;
3236
3237 if (a->length_km > 5 || a->length_100m > 50)
3238 ha->long_range_distance = LR_DISTANCE_10K;
3239 else
3240 ha->long_range_distance = LR_DISTANCE_5K;
3241
3242 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3243 ql_dbg(ql_dbg_async, vha, 0x507b,
3244 "Detected Long Range SFP.\n");
3245 } else {
3246 /* short range */
3247 ha->flags.detected_lr_sfp = 0;
3248 if (ha->flags.using_lr_setting)
3249 ql_dbg(ql_dbg_async, vha, 0x5084,
3250 "Detected Short Range SFP.\n");
3251 }
3252
3253 if (!vha->flags.init_done)
3254 rc = QLA_SUCCESS;
3255out:
3256 return rc;
3257}
3258
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003259/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 * qla2x00_setup_chip() - Load and start RISC firmware.
Bart Van Assche2db62282018-01-23 16:33:51 -08003261 * @vha: HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 *
3263 * Returns 0 on success.
3264 */
3265static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003266qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003268 int rval;
3269 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003270 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08003271 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3272 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07003273 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08003274
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003275 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003276 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05003277 if (rval == QLA_SUCCESS) {
3278 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003279 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05003280 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07003281 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003282 }
3283
Andrew Vasquez3db06522008-01-31 12:33:49 -08003284 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3285 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3286 spin_lock_irqsave(&ha->hardware_lock, flags);
3287 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
3288 RD_REG_WORD(&reg->hccr);
3289 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3290 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291
Andrew Vasquez18e75552009-06-03 09:55:30 -07003292 qla81xx_mpi_sync(vha);
3293
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003295 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003296 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003297 ql_dbg(ql_dbg_init, vha, 0x00c9,
3298 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003300 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 if (rval == QLA_SUCCESS) {
3302 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003303 ql_dbg(ql_dbg_init, vha, 0x00ca,
3304 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003306 if (ql2xexlogins)
3307 ha->flags.exlogins_enabled = 1;
3308
Quinn Tran99e1b682017-06-02 09:12:03 -07003309 if (qla_is_exch_offld_enabled(vha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003310 ha->flags.exchoffld_enabled = 1;
3311
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003312 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07003314 if (rval == QLA_SUCCESS) {
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003315 qla24xx_detect_sfp(vha);
3316
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003317 rval = qla2x00_set_exlogins_buffer(vha);
3318 if (rval != QLA_SUCCESS)
3319 goto failed;
3320
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003321 rval = qla2x00_set_exchoffld_buffer(vha);
3322 if (rval != QLA_SUCCESS)
3323 goto failed;
3324
Giridhar Malavalia9083012010-04-12 17:59:55 -07003325enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07003326 fw_major_version = ha->fw_major_version;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003327 if (IS_P3P_TYPE(ha))
Giridhar Malavali31731672011-08-16 11:31:54 -07003328 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003329 else
3330 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07003331 if (rval != QLA_SUCCESS)
3332 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003333 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003334 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07003335 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003336 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003337 if ((!ha->max_npiv_vports) ||
3338 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003339 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003340 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003341 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003342 }
Quinn Tran03e8c682015-12-17 14:56:59 -05003343 qla2x00_get_resource_cnts(vha);
Andrew Vasquezd743de62009-03-24 09:08:15 -07003344
Chad Dupuis8d93f552013-01-30 03:34:37 -05003345 /*
3346 * Allocate the array of outstanding commands
3347 * now that we know the firmware resources.
3348 */
3349 rval = qla2x00_alloc_outstanding_cmds(ha,
3350 vha->req);
3351 if (rval != QLA_SUCCESS)
3352 goto failed;
3353
Quinn Tranad0a0b02017-12-28 12:33:14 -08003354 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3355 qla2x00_alloc_offload_mem(vha);
3356
3357 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
Giridhar Malavali08de2842011-08-16 11:31:44 -07003358 qla2x00_alloc_fw_dump(vha);
Quinn Tranad0a0b02017-12-28 12:33:14 -08003359
Chad Dupuis3b6e5b92013-10-30 03:38:09 -04003360 } else {
3361 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362 }
3363 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003364 ql_log(ql_log_fatal, vha, 0x00cd,
3365 "ISP Firmware failed checksum.\n");
3366 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04003368 } else
3369 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370
Andrew Vasquez3db06522008-01-31 12:33:49 -08003371 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3372 /* Enable proper parity. */
3373 spin_lock_irqsave(&ha->hardware_lock, flags);
3374 if (IS_QLA2300(ha))
3375 /* SRAM parity */
3376 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
3377 else
3378 /* SRAM, Instruction RAM and GP RAM parity */
3379 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
3380 RD_REG_WORD(&reg->hccr);
3381 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3382 }
3383
Chad Dupuisf3982d82014-09-25 05:16:57 -04003384 if (IS_QLA27XX(ha))
3385 ha->flags.fac_supported = 1;
3386 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003387 uint32_t size;
3388
3389 rval = qla81xx_fac_get_sector_size(vha, &size);
3390 if (rval == QLA_SUCCESS) {
3391 ha->flags.fac_supported = 1;
3392 ha->fdt_block_size = size << 2;
3393 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003394 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003395 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3396 ha->fw_major_version, ha->fw_minor_version,
3397 ha->fw_subminor_version);
Joe Carnuccio1ca60e32014-02-26 04:15:02 -05003398
Chad Dupuisf73cb692014-02-26 04:15:06 -05003399 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003400 ha->flags.fac_supported = 0;
3401 rval = QLA_SUCCESS;
3402 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003403 }
3404 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07003405failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003407 ql_log(ql_log_fatal, vha, 0x00cf,
3408 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 }
3410
3411 return (rval);
3412}
3413
3414/**
3415 * qla2x00_init_response_q_entries() - Initializes response queue entries.
Bart Van Assche2db62282018-01-23 16:33:51 -08003416 * @rsp: response queue
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417 *
3418 * Beginning of request ring has initialization control block already built
3419 * by nvram config routine.
3420 *
3421 * Returns 0 on success.
3422 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003423void
3424qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425{
3426 uint16_t cnt;
3427 response_t *pkt;
3428
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003429 rsp->ring_ptr = rsp->ring;
3430 rsp->ring_index = 0;
3431 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003432 pkt = rsp->ring_ptr;
3433 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 pkt->signature = RESPONSE_PROCESSED;
3435 pkt++;
3436 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437}
3438
3439/**
3440 * qla2x00_update_fw_options() - Read and process firmware options.
Bart Van Assche2db62282018-01-23 16:33:51 -08003441 * @vha: HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442 *
3443 * Returns 0 on success.
3444 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003445void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003446qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447{
3448 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003449 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450
3451 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003452 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453
3454 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3455 return;
3456
3457 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003458 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3459 "Serial link options.\n");
3460 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3461 (uint8_t *)&ha->fw_seriallink_options,
3462 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463
3464 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3465 if (ha->fw_seriallink_options[3] & BIT_2) {
3466 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3467
3468 /* 1G settings */
3469 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3470 emphasis = (ha->fw_seriallink_options[2] &
3471 (BIT_4 | BIT_3)) >> 3;
3472 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003473 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474 rx_sens = (ha->fw_seriallink_options[0] &
3475 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3476 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3477 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3478 if (rx_sens == 0x0)
3479 rx_sens = 0x3;
3480 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3481 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3482 ha->fw_options[10] |= BIT_5 |
3483 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3484 (tx_sens & (BIT_1 | BIT_0));
3485
3486 /* 2G settings */
3487 swing = (ha->fw_seriallink_options[2] &
3488 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3489 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3490 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003491 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 rx_sens = (ha->fw_seriallink_options[1] &
3493 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3494 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3495 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3496 if (rx_sens == 0x0)
3497 rx_sens = 0x3;
3498 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3499 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3500 ha->fw_options[11] |= BIT_5 |
3501 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3502 (tx_sens & (BIT_1 | BIT_0));
3503 }
3504
3505 /* FCP2 options. */
3506 /* Return command IOCBs without waiting for an ABTS to complete. */
3507 ha->fw_options[3] |= BIT_13;
3508
3509 /* LED scheme. */
3510 if (ha->flags.enable_led_scheme)
3511 ha->fw_options[2] |= BIT_12;
3512
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003513 /* Detect ISP6312. */
3514 if (IS_QLA6312(ha))
3515 ha->fw_options[2] |= BIT_13;
3516
Giridhar Malavali088d09d2016-07-06 11:14:20 -04003517 /* Set Retry FLOGI in case of P2P connection */
3518 if (ha->operating_mode == P2P) {
3519 ha->fw_options[2] |= BIT_3;
3520 ql_dbg(ql_dbg_disc, vha, 0x2100,
3521 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3522 __func__, ha->fw_options[2]);
3523 }
3524
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003526 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527}
3528
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003529void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003530qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003531{
3532 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003533 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003534
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003535 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07003536 return;
3537
Himanshu Madhanif198caf2016-01-27 12:03:30 -05003538 /* Hold status IOCBs until ABTS response received. */
3539 if (ql2xfwholdabts)
3540 ha->fw_options[3] |= BIT_12;
3541
Giridhar Malavali088d09d2016-07-06 11:14:20 -04003542 /* Set Retry FLOGI in case of P2P connection */
3543 if (ha->operating_mode == P2P) {
3544 ha->fw_options[2] |= BIT_3;
3545 ql_dbg(ql_dbg_disc, vha, 0x2101,
3546 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3547 __func__, ha->fw_options[2]);
3548 }
3549
Quinn Tran41dc5292017-01-19 22:28:03 -08003550 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
Quinn Tran3c4810f2017-06-02 09:11:53 -07003551 if (ql2xmvasynctoatio &&
3552 (IS_QLA83XX(ha) || IS_QLA27XX(ha))) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003553 if (qla_tgt_mode_enabled(vha) ||
3554 qla_dual_mode_enabled(vha))
3555 ha->fw_options[2] |= BIT_11;
3556 else
3557 ha->fw_options[2] &= ~BIT_11;
3558 }
3559
Quinn Tranf7e761f2017-06-02 09:12:02 -07003560 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3561 /*
3562 * Tell FW to track each exchange to prevent
3563 * driver from using stale exchange.
3564 */
3565 if (qla_tgt_mode_enabled(vha) ||
3566 qla_dual_mode_enabled(vha))
3567 ha->fw_options[2] |= BIT_4;
3568 else
3569 ha->fw_options[2] &= ~BIT_4;
Quinn Tran9ecf0b02017-12-28 12:33:19 -08003570
3571 /* Reserve 1/2 of emergency exchanges for ELS.*/
3572 if (qla2xuseresexchforels)
3573 ha->fw_options[2] |= BIT_8;
3574 else
3575 ha->fw_options[2] &= ~BIT_8;
Quinn Tranf7e761f2017-06-02 09:12:02 -07003576 }
3577
Quinn Tran83548fe2017-06-02 09:12:01 -07003578 ql_dbg(ql_dbg_init, vha, 0x00e8,
3579 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3580 __func__, ha->fw_options[1], ha->fw_options[2],
3581 ha->fw_options[3], vha->host->active_mode);
Quinn Tran3c4810f2017-06-02 09:11:53 -07003582
3583 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3584 qla2x00_set_fw_options(vha, ha->fw_options);
Quinn Tran41dc5292017-01-19 22:28:03 -08003585
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003586 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08003587 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003588 return;
3589
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003590 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08003591 le16_to_cpu(ha->fw_seriallink_options24[1]),
3592 le16_to_cpu(ha->fw_seriallink_options24[2]),
3593 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003594 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003595 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003596 "Unable to update Serial Link options (%x).\n", rval);
3597 }
3598}
3599
3600void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003601qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003602{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003603 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003604 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003605 struct req_que *req = ha->req_q_map[0];
3606 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003607
3608 /* Setup ring parameters in initialization control block. */
Bart Van Asschead950362015-07-09 07:24:08 -07003609 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3610 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003611 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3612 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3613 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3614 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3615 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3616 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003617
3618 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3619 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3620 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3621 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3622 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3623}
3624
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003625void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003626qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003627{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003628 struct qla_hw_data *ha = vha->hw;
Bart Van Assche118e2ef2015-07-09 07:24:27 -07003629 device_reg_t *reg = ISP_QUE_REG(ha, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003630 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3631 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003632 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003633 uint16_t rid = 0;
3634 struct req_que *req = ha->req_q_map[0];
3635 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003636
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003637 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003638 icb = (struct init_cb_24xx *)ha->init_cb;
Bart Van Asschead950362015-07-09 07:24:08 -07003639 icb->request_q_outpointer = cpu_to_le16(0);
3640 icb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003641 icb->request_q_length = cpu_to_le16(req->length);
3642 icb->response_q_length = cpu_to_le16(rsp->length);
3643 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3644 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3645 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3646 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003647
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003648 /* Setup ATIO queue dma pointers for target mode */
Bart Van Asschead950362015-07-09 07:24:08 -07003649 icb->atio_q_inpointer = cpu_to_le16(0);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003650 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3651 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
3652 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
3653
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003654 if (IS_SHADOW_REG_CAPABLE(ha))
Bart Van Asschead950362015-07-09 07:24:08 -07003655 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003656
Chad Dupuisf73cb692014-02-26 04:15:06 -05003657 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003658 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3659 icb->rid = cpu_to_le16(rid);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003660 if (ha->flags.msix_enabled) {
3661 msix = &ha->msix_entries[1];
Quinn Tran83548fe2017-06-02 09:12:01 -07003662 ql_dbg(ql_dbg_init, vha, 0x0019,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003663 "Registering vector 0x%x for base que.\n",
3664 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003665 icb->msix = cpu_to_le16(msix->entry);
3666 }
3667 /* Use alternate PCI bus number */
3668 if (MSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003669 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003670 /* Use alternate PCI devfn */
3671 if (LSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003672 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003673
Anirban Chakraborty31557542009-12-02 10:36:55 -08003674 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003675 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
3676 (ha->flags.msix_enabled)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003677 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003678 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003679 ql_dbg(ql_dbg_init, vha, 0x00fe,
3680 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08003681 } else {
Bart Van Asschead950362015-07-09 07:24:08 -07003682 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003683 }
Bart Van Asschead950362015-07-09 07:24:08 -07003684 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003685
3686 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
3687 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
3688 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
3689 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
3690 } else {
3691 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
3692 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
3693 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
3694 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
3695 }
Arun Easiaa230bc2013-01-30 03:34:39 -05003696 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003697
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003698 /* PCI posting */
3699 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003700}
3701
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702/**
3703 * qla2x00_init_rings() - Initializes firmware.
Bart Van Assche2db62282018-01-23 16:33:51 -08003704 * @vha: HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 *
3706 * Beginning of request ring has initialization control block already built
3707 * by nvram config routine.
3708 *
3709 * Returns 0 on success.
3710 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003711int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003712qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713{
3714 int rval;
3715 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003716 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003717 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003718 struct req_que *req;
3719 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003720 struct mid_init_cb_24xx *mid_init_cb =
3721 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722
3723 spin_lock_irqsave(&ha->hardware_lock, flags);
3724
3725 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003726 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003727 req = ha->req_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003728 if (!req || !test_bit(que, ha->req_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003729 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003730 req->out_ptr = (void *)(req->ring + req->length);
3731 *req->out_ptr = 0;
Chad Dupuis8d93f552013-01-30 03:34:37 -05003732 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003733 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003735 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003736
3737 /* Initialize firmware. */
3738 req->ring_ptr = req->ring;
3739 req->ring_index = 0;
3740 req->cnt = req->length;
3741 }
3742
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003743 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003744 rsp = ha->rsp_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003745 if (!rsp || !test_bit(que, ha->rsp_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003746 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003747 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
3748 *rsp->in_ptr = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003749 /* Initialize response queue entries */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003750 if (IS_QLAFX00(ha))
3751 qlafx00_init_response_q_entries(rsp);
3752 else
3753 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003754 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003756 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
3757 ha->tgt.atio_ring_index = 0;
3758 /* Initialize ATIO queue entries */
3759 qlt_init_atio_q_entries(vha);
3760
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003761 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762
3763 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3764
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003765 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
3766
3767 if (IS_QLAFX00(ha)) {
3768 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
3769 goto next_check;
3770 }
3771
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003773 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003775 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04003776 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003777 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08003778 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003779 }
3780
Andrew Vasquez24a08132009-03-24 09:08:16 -07003781 if (IS_FWI2_CAPABLE(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003782 mid_init_cb->options = cpu_to_le16(BIT_1);
Andrew Vasquez24a08132009-03-24 09:08:16 -07003783 mid_init_cb->init_cb.execution_throttle =
Quinn Tran03e8c682015-12-17 14:56:59 -05003784 cpu_to_le16(ha->cur_fw_xcb_count);
Joe Carnuccio40f38622016-07-06 11:14:28 -04003785 ha->flags.dport_enabled =
3786 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
3787 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
3788 (ha->flags.dport_enabled) ? "enabled" : "disabled");
3789 /* FA-WWPN Status */
Himanshu Madhani2486c622014-09-25 05:17:00 -04003790 ha->flags.fawwpn_enabled =
Joe Carnuccio40f38622016-07-06 11:14:28 -04003791 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
Quinn Tran83548fe2017-06-02 09:12:01 -07003792 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
Himanshu Madhani2486c622014-09-25 05:17:00 -04003793 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
Andrew Vasquez24a08132009-03-24 09:08:16 -07003794 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003795
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003796 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003797next_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003799 ql_log(ql_log_fatal, vha, 0x00d2,
3800 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003802 ql_dbg(ql_dbg_init, vha, 0x00d3,
3803 "Init Firmware -- success.\n");
Quinn Tran4b60c822017-06-13 20:47:21 -07003804 QLA_FW_STARTED(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 }
3806
3807 return (rval);
3808}
3809
3810/**
3811 * qla2x00_fw_ready() - Waits for firmware ready.
Bart Van Assche2db62282018-01-23 16:33:51 -08003812 * @vha: HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 *
3814 * Returns 0 on success.
3815 */
3816static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003817qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818{
3819 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003820 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821 uint16_t min_wait; /* Minimum wait time if loop is down */
3822 uint16_t wait_time; /* Wait time if loop is coming ready */
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003823 uint16_t state[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003824 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003826 if (IS_QLAFX00(vha->hw))
3827 return qlafx00_fw_ready(vha);
3828
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 rval = QLA_SUCCESS;
3830
Chad Dupuis334614912015-04-09 14:59:57 -04003831 /* Time to wait for loop down */
3832 if (IS_P3P_TYPE(ha))
3833 min_wait = 30;
3834 else
3835 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836
3837 /*
3838 * Firmware should take at most one RATOV to login, plus 5 seconds for
3839 * our own processing.
3840 */
3841 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
3842 wait_time = min_wait;
3843 }
3844
3845 /* Min wait time if loop down */
3846 mtime = jiffies + (min_wait * HZ);
3847
3848 /* wait time before firmware ready */
3849 wtime = jiffies + (wait_time * HZ);
3850
3851 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003852 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003853 ql_log(ql_log_info, vha, 0x801e,
3854 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855
3856 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05003857 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003858 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003860 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003861 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003863 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003864 ql_dbg(ql_dbg_taskm, vha, 0x801f,
3865 "fw_state=%x 84xx=%x.\n", state[0],
3866 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003867 if ((state[2] & FSTATE_LOGGED_IN) &&
3868 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003869 ql_dbg(ql_dbg_taskm, vha, 0x8028,
3870 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003871
3872 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003873 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003874 if (rval != QLA_SUCCESS) {
3875 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08003876 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003877 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003878 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003879 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003880
3881 /* Add time taken to initialize. */
3882 cs84xx_time = jiffies - cs84xx_time;
3883 wtime += cs84xx_time;
3884 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08003885 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003886 "Increasing wait time by %ld. "
3887 "New time %ld.\n", cs84xx_time,
3888 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003889 }
3890 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003891 ql_dbg(ql_dbg_taskm, vha, 0x8037,
3892 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003894 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895 &ha->login_timeout, &ha->r_a_tov);
3896
3897 rval = QLA_SUCCESS;
3898 break;
3899 }
3900
3901 rval = QLA_FUNCTION_FAILED;
3902
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003903 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003904 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003906 * other than Wait for Login.
3907 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003909 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910 "Cable is unplugged...\n");
3911
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003912 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 break;
3914 }
3915 }
3916 } else {
3917 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07003918 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08003919 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920 break;
3921 }
3922
3923 if (time_after_eq(jiffies, wtime))
3924 break;
3925
3926 /* Delay for a while */
3927 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928 } while (1);
3929
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003930 ql_dbg(ql_dbg_taskm, vha, 0x803a,
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003931 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
3932 state[1], state[2], state[3], state[4], state[5], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933
Chad Dupuiscfb09192011-11-18 09:03:07 -08003934 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003935 ql_log(ql_log_warn, vha, 0x803b,
3936 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 }
3938
3939 return (rval);
3940}
3941
3942/*
3943* qla2x00_configure_hba
3944* Setup adapter context.
3945*
3946* Input:
3947* ha = adapter state pointer.
3948*
3949* Returns:
3950* 0 = success
3951*
3952* Context:
3953* Kernel context.
3954*/
3955static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003956qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957{
3958 int rval;
3959 uint16_t loop_id;
3960 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003961 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962 uint8_t al_pa;
3963 uint8_t area;
3964 uint8_t domain;
3965 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003966 struct qla_hw_data *ha = vha->hw;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003967 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003968 port_id_t id;
Quinn Tran9d1aa4e2017-12-28 12:33:27 -08003969 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970
3971 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003972 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003973 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003975 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003976 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08003977 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003978 ql_dbg(ql_dbg_disc, vha, 0x2008,
3979 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08003980 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003981 ql_log(ql_log_warn, vha, 0x2009,
3982 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003983 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
3984 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
3985 ql_log(ql_log_warn, vha, 0x1151,
3986 "Doing link init.\n");
3987 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
3988 return rval;
3989 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003990 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08003991 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992 return (rval);
3993 }
3994
3995 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003996 ql_log(ql_log_info, vha, 0x200a,
3997 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 return (QLA_FUNCTION_FAILED);
3999 }
4000
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004001 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002
4003 /* initialize */
4004 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4005 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004006 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007
4008 switch (topo) {
4009 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004010 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 ha->current_topology = ISP_CFG_NL;
4012 strcpy(connect_type, "(Loop)");
4013 break;
4014
4015 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004016 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004017 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018 ha->current_topology = ISP_CFG_FL;
4019 strcpy(connect_type, "(FL_Port)");
4020 break;
4021
4022 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004023 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 ha->operating_mode = P2P;
4025 ha->current_topology = ISP_CFG_N;
4026 strcpy(connect_type, "(N_Port-to-N_Port)");
4027 break;
4028
4029 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004030 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004031 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032 ha->operating_mode = P2P;
4033 ha->current_topology = ISP_CFG_F;
4034 strcpy(connect_type, "(F_Port)");
4035 break;
4036
4037 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004038 ql_dbg(ql_dbg_disc, vha, 0x200f,
4039 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040 ha->current_topology = ISP_CFG_NL;
4041 strcpy(connect_type, "(Loop)");
4042 break;
4043 }
4044
4045 /* Save Host port and loop ID. */
4046 /* byte order - Big Endian */
Quinn Tran482c9dc2017-03-15 09:48:54 -07004047 id.b.domain = domain;
4048 id.b.area = area;
4049 id.b.al_pa = al_pa;
4050 id.b.rsvd_1 = 0;
Quinn Tran9d1aa4e2017-12-28 12:33:27 -08004051 spin_lock_irqsave(&ha->hardware_lock, flags);
Quinn Tran482c9dc2017-03-15 09:48:54 -07004052 qlt_update_host_map(vha, id);
Quinn Tran9d1aa4e2017-12-28 12:33:27 -08004053 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004054
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004055 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004056 ql_log(ql_log_info, vha, 0x2010,
4057 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004058 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 return(rval);
4061}
4062
Giridhar Malavalia9083012010-04-12 17:59:55 -07004063inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004064qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4065 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004066{
4067 char *st, *en;
4068 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004069 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07004070 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004071 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004072
4073 if (memcmp(model, BINZERO, len) != 0) {
4074 strncpy(ha->model_number, model, len);
4075 st = en = ha->model_number;
4076 en += len - 1;
4077 while (en > st) {
4078 if (*en != 0x20 && *en != 0x00)
4079 break;
4080 *en-- = '\0';
4081 }
4082
4083 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07004084 if (use_tbl &&
4085 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004086 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07004087 strncpy(ha->model_desc,
4088 qla2x00_model_name[index * 2 + 1],
4089 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004090 } else {
4091 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07004092 if (use_tbl &&
4093 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004094 index < QLA_MODEL_NAMES) {
4095 strcpy(ha->model_number,
4096 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07004097 strncpy(ha->model_desc,
4098 qla2x00_model_name[index * 2 + 1],
4099 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004100 } else {
4101 strcpy(ha->model_number, def);
4102 }
4103 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07004104 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004105 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07004106 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004107}
4108
David Miller4e08df32007-04-16 12:37:43 -07004109/* On sparc systems, obtain port and node WWN from firmware
4110 * properties.
4111 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004112static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07004113{
4114#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004115 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004116 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004117 struct device_node *dp = pci_device_to_OF_node(pdev);
4118 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004119 int len;
4120
4121 val = of_get_property(dp, "port-wwn", &len);
4122 if (val && len >= WWN_SIZE)
4123 memcpy(nv->port_name, val, WWN_SIZE);
4124
4125 val = of_get_property(dp, "node-wwn", &len);
4126 if (val && len >= WWN_SIZE)
4127 memcpy(nv->node_name, val, WWN_SIZE);
4128#endif
4129}
4130
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131/*
4132* NVRAM configuration for ISP 2xxx
4133*
4134* Input:
4135* ha = adapter block pointer.
4136*
4137* Output:
4138* initialization control block in response_ring
4139* host adapters parameters in host adapter block
4140*
4141* Returns:
4142* 0 = success.
4143*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004144int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004145qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146{
David Miller4e08df32007-04-16 12:37:43 -07004147 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004148 uint8_t chksum = 0;
4149 uint16_t cnt;
4150 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004151 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004152 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004153 nvram_t *nv = ha->nvram;
4154 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004155 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156
David Miller4e08df32007-04-16 12:37:43 -07004157 rval = QLA_SUCCESS;
4158
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004160 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161 ha->nvram_base = 0;
4162 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4163 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
4164 ha->nvram_base = 0x80;
4165
4166 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004167 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004168 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4169 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004171 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4172 "Contents of NVRAM.\n");
4173 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4174 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175
4176 /* Bad NVRAM data, set defaults parameters. */
4177 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
4178 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
4179 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004180 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04004181 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004182 "detected: checksum=0x%x id=%c version=0x%x.\n",
4183 chksum, nv->id[0], nv->nvram_version);
4184 ql_log(ql_log_warn, vha, 0x0065,
4185 "Falling back to "
4186 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07004187
4188 /*
4189 * Set default initialization control block.
4190 */
4191 memset(nv, 0, ha->nvram_size);
4192 nv->parameter_block_version = ICB_VERSION;
4193
4194 if (IS_QLA23XX(ha)) {
4195 nv->firmware_options[0] = BIT_2 | BIT_1;
4196 nv->firmware_options[1] = BIT_7 | BIT_5;
4197 nv->add_firmware_options[0] = BIT_5;
4198 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04004199 nv->frame_payload_size = 2048;
David Miller4e08df32007-04-16 12:37:43 -07004200 nv->special_options[1] = BIT_7;
4201 } else if (IS_QLA2200(ha)) {
4202 nv->firmware_options[0] = BIT_2 | BIT_1;
4203 nv->firmware_options[1] = BIT_7 | BIT_5;
4204 nv->add_firmware_options[0] = BIT_5;
4205 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04004206 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07004207 } else if (IS_QLA2100(ha)) {
4208 nv->firmware_options[0] = BIT_3 | BIT_1;
4209 nv->firmware_options[1] = BIT_5;
Joe Carnuccio98aee702014-09-25 05:16:38 -04004210 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07004211 }
4212
Bart Van Asschead950362015-07-09 07:24:08 -07004213 nv->max_iocb_allocation = cpu_to_le16(256);
4214 nv->execution_throttle = cpu_to_le16(16);
David Miller4e08df32007-04-16 12:37:43 -07004215 nv->retry_count = 8;
4216 nv->retry_delay = 1;
4217
4218 nv->port_name[0] = 33;
4219 nv->port_name[3] = 224;
4220 nv->port_name[4] = 139;
4221
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004222 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004223
4224 nv->login_timeout = 4;
4225
4226 /*
4227 * Set default host adapter parameters
4228 */
4229 nv->host_p[1] = BIT_2;
4230 nv->reset_delay = 5;
4231 nv->port_down_retry_count = 8;
Bart Van Asschead950362015-07-09 07:24:08 -07004232 nv->max_luns_per_target = cpu_to_le16(8);
David Miller4e08df32007-04-16 12:37:43 -07004233 nv->link_down_timeout = 60;
4234
4235 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004236 }
4237
4238#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4239 /*
4240 * The SN2 does not provide BIOS emulation which means you can't change
4241 * potentially bogus BIOS settings. Force the use of default settings
4242 * for link rate and frame size. Hope that the rest of the settings
4243 * are valid.
4244 */
4245 if (ia64_platform_is("sn2")) {
Joe Carnuccio98aee702014-09-25 05:16:38 -04004246 nv->frame_payload_size = 2048;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247 if (IS_QLA23XX(ha))
4248 nv->special_options[1] = BIT_7;
4249 }
4250#endif
4251
4252 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004253 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254
4255 /*
4256 * Setup driver NVRAM options.
4257 */
4258 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4259 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4260 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4261 nv->firmware_options[1] &= ~BIT_4;
4262
4263 if (IS_QLA23XX(ha)) {
4264 nv->firmware_options[0] |= BIT_2;
4265 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004266 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004267 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268
4269 if (IS_QLA2300(ha)) {
4270 if (ha->fb_rev == FPM_2310) {
4271 strcpy(ha->model_number, "QLA2310");
4272 } else {
4273 strcpy(ha->model_number, "QLA2300");
4274 }
4275 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004276 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004277 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278 }
4279 } else if (IS_QLA2200(ha)) {
4280 nv->firmware_options[0] |= BIT_2;
4281 /*
4282 * 'Point-to-point preferred, else loop' is not a safe
4283 * connection mode setting.
4284 */
4285 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4286 (BIT_5 | BIT_4)) {
4287 /* Force 'loop preferred, else point-to-point'. */
4288 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4289 nv->add_firmware_options[0] |= BIT_5;
4290 }
4291 strcpy(ha->model_number, "QLA22xx");
4292 } else /*if (IS_QLA2100(ha))*/ {
4293 strcpy(ha->model_number, "QLA2100");
4294 }
4295
4296 /*
4297 * Copy over NVRAM RISC parameter block to initialization control block.
4298 */
4299 dptr1 = (uint8_t *)icb;
4300 dptr2 = (uint8_t *)&nv->parameter_block_version;
4301 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4302 while (cnt--)
4303 *dptr1++ = *dptr2++;
4304
4305 /* Copy 2nd half. */
4306 dptr1 = (uint8_t *)icb->add_firmware_options;
4307 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4308 while (cnt--)
4309 *dptr1++ = *dptr2++;
4310
Andrew Vasquez5341e862006-05-17 15:09:16 -07004311 /* Use alternate WWN? */
4312 if (nv->host_p[1] & BIT_7) {
4313 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4314 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4315 }
4316
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317 /* Prepare nodename */
4318 if ((icb->firmware_options[1] & BIT_6) == 0) {
4319 /*
4320 * Firmware will apply the following mask if the nodename was
4321 * not provided.
4322 */
4323 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4324 icb->node_name[0] &= 0xF0;
4325 }
4326
4327 /*
4328 * Set host adapter parameters.
4329 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07004330
4331 /*
4332 * BIT_7 in the host-parameters section allows for modification to
4333 * internal driver logging.
4334 */
Andrew Vasquez01819442006-06-23 16:11:10 -07004335 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08004336 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004337 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4338 /* Always load RISC code on non ISP2[12]00 chips. */
4339 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4340 ha->flags.disable_risc_code_load = 0;
4341 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4342 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4343 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07004344 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004345 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346
4347 ha->operating_mode =
4348 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4349
4350 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4351 sizeof(ha->fw_seriallink_options));
4352
4353 /* save HBA serial number */
4354 ha->serial0 = icb->port_name[5];
4355 ha->serial1 = icb->port_name[6];
4356 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004357 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4358 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359
Bart Van Asschead950362015-07-09 07:24:08 -07004360 icb->execution_throttle = cpu_to_le16(0xFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361
4362 ha->retry_count = nv->retry_count;
4363
4364 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07004365 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366 nv->login_timeout = ql2xlogintimeout;
4367 if (nv->login_timeout < 4)
4368 nv->login_timeout = 4;
4369 ha->login_timeout = nv->login_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004370
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004371 /* Set minimum RATOV to 100 tenths of a second. */
4372 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373
Linus Torvalds1da177e2005-04-16 15:20:36 -07004374 ha->loop_reset_delay = nv->reset_delay;
4375
Linus Torvalds1da177e2005-04-16 15:20:36 -07004376 /* Link Down Timeout = 0:
4377 *
4378 * When Port Down timer expires we will start returning
4379 * I/O's to OS with "DID_NO_CONNECT".
4380 *
4381 * Link Down Timeout != 0:
4382 *
4383 * The driver waits for the link to come up after link down
4384 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004385 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386 if (nv->link_down_timeout == 0) {
4387 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004388 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 } else {
4390 ha->link_down_timeout = nv->link_down_timeout;
4391 ha->loop_down_abort_time =
4392 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395 /*
4396 * Need enough time to try and get the port back.
4397 */
4398 ha->port_down_retry_count = nv->port_down_retry_count;
4399 if (qlport_down_retry)
4400 ha->port_down_retry_count = qlport_down_retry;
4401 /* Set login_retry_count */
4402 ha->login_retry_count = nv->retry_count;
4403 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4404 ha->port_down_retry_count > 3)
4405 ha->login_retry_count = ha->port_down_retry_count;
4406 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4407 ha->login_retry_count = ha->port_down_retry_count;
4408 if (ql2xloginretrycount)
4409 ha->login_retry_count = ql2xloginretrycount;
4410
Bart Van Asschead950362015-07-09 07:24:08 -07004411 icb->lun_enables = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004412 icb->command_resource_count = 0;
4413 icb->immediate_notify_resource_count = 0;
Bart Van Asschead950362015-07-09 07:24:08 -07004414 icb->timeout = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415
4416 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4417 /* Enable RIO */
4418 icb->firmware_options[0] &= ~BIT_3;
4419 icb->add_firmware_options[0] &=
4420 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4421 icb->add_firmware_options[0] |= BIT_2;
4422 icb->response_accumulation_timer = 3;
4423 icb->interrupt_delay_timer = 5;
4424
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004425 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004426 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004427 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004428 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004429 ha->zio_mode = icb->add_firmware_options[0] &
4430 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4431 ha->zio_timer = icb->interrupt_delay_timer ?
4432 icb->interrupt_delay_timer: 2;
4433 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004434 icb->add_firmware_options[0] &=
4435 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004436 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004437 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004438 ha->zio_mode = QLA_ZIO_MODE_6;
4439
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004440 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004441 "ZIO mode %d enabled; timer delay (%d us).\n",
4442 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004444 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4445 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004446 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004447 }
4448 }
4449
David Miller4e08df32007-04-16 12:37:43 -07004450 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004451 ql_log(ql_log_warn, vha, 0x0069,
4452 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07004453 }
4454 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455}
4456
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004457static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004458qla2x00_rport_del(void *data)
4459{
4460 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004461 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004462 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004463
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004464 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004465 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004466 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004467 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004468 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004469 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4470 "%s %8phN. rport %p roles %x\n",
4471 __func__, fcport->port_name, rport,
4472 rport->roles);
Quinn Tran726b8542017-01-19 22:28:00 -08004473
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004474 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08004475 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004476}
4477
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478/**
4479 * qla2x00_alloc_fcport() - Allocate a generic fcport.
Bart Van Assche2db62282018-01-23 16:33:51 -08004480 * @vha: HA context
Linus Torvalds1da177e2005-04-16 15:20:36 -07004481 * @flags: allocation flags
4482 *
4483 * Returns a pointer to the allocated fcport, or NULL, if none available.
4484 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004485fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004486qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004487{
4488 fc_port_t *fcport;
4489
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004490 fcport = kzalloc(sizeof(fc_port_t), flags);
4491 if (!fcport)
4492 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004493
4494 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004495 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496 fcport->port_type = FCT_UNKNOWN;
4497 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07004498 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004499 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004500
Quinn Tran726b8542017-01-19 22:28:00 -08004501 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4502 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
Quinn Tran6cb32162017-02-13 12:18:29 -08004503 flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004504 fcport->disc_state = DSC_DELETED;
4505 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4506 fcport->deleted = QLA_SESS_DELETED;
4507 fcport->login_retry = vha->hw->login_retry_count;
Quinn Tran726b8542017-01-19 22:28:00 -08004508 fcport->logout_on_delete = 1;
4509
4510 if (!fcport->ct_desc.ct_sns) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004511 ql_log(ql_log_warn, vha, 0xd049,
Quinn Tran726b8542017-01-19 22:28:00 -08004512 "Failed to allocate ct_sns request.\n");
4513 kfree(fcport);
4514 fcport = NULL;
4515 }
4516 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4517 INIT_LIST_HEAD(&fcport->gnl_entry);
4518 INIT_LIST_HEAD(&fcport->list);
4519
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004520 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521}
4522
Quinn Tran726b8542017-01-19 22:28:00 -08004523void
4524qla2x00_free_fcport(fc_port_t *fcport)
4525{
4526 if (fcport->ct_desc.ct_sns) {
4527 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4528 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4529 fcport->ct_desc.ct_sns_dma);
4530
4531 fcport->ct_desc.ct_sns = NULL;
4532 }
4533 kfree(fcport);
4534}
4535
Linus Torvalds1da177e2005-04-16 15:20:36 -07004536/*
4537 * qla2x00_configure_loop
4538 * Updates Fibre Channel Device Database with what is actually on loop.
4539 *
4540 * Input:
4541 * ha = adapter block pointer.
4542 *
4543 * Returns:
4544 * 0 = success.
4545 * 1 = error.
4546 * 2 = database was full and device was not configured.
4547 */
4548static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004549qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004550{
4551 int rval;
4552 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004553 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004554 rval = QLA_SUCCESS;
4555
4556 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004557 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4558 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004559 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004560 ql_dbg(ql_dbg_disc, vha, 0x2013,
4561 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562 return (rval);
4563 }
4564 }
4565
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004566 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004567 ql_dbg(ql_dbg_disc, vha, 0x2014,
4568 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004569
4570 /*
4571 * If we have both an RSCN and PORT UPDATE pending then handle them
4572 * both at the same time.
4573 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004574 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4575 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576
Michael Hernandez3064ff32009-12-15 21:29:44 -08004577 qla2x00_get_data_rate(vha);
4578
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579 /* Determine what we need to do */
4580 if (ha->current_topology == ISP_CFG_FL &&
4581 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4582
Linus Torvalds1da177e2005-04-16 15:20:36 -07004583 set_bit(RSCN_UPDATE, &flags);
4584
4585 } else if (ha->current_topology == ISP_CFG_F &&
4586 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4587
Linus Torvalds1da177e2005-04-16 15:20:36 -07004588 set_bit(RSCN_UPDATE, &flags);
4589 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4590
Andrew Vasquez21333b42006-05-17 15:09:56 -07004591 } else if (ha->current_topology == ISP_CFG_N) {
4592 clear_bit(RSCN_UPDATE, &flags);
Quinn Tran9cd883f2017-12-28 12:33:24 -08004593 if (ha->flags.rida_fmt2) {
4594 /* With Rida Format 2, the login is already triggered.
4595 * We know who is on the other side of the wire.
4596 * No need to login to do login to find out or drop into
4597 * qla2x00_configure_local_loop().
4598 */
4599 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4600 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4601 } else {
4602 if (qla_tgt_mode_enabled(vha)) {
4603 /* allow the other side to start the login */
4604 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4605 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4606 }
4607 }
Quinn Tran41dc5292017-01-19 22:28:03 -08004608 } else if (ha->current_topology == ISP_CFG_NL) {
4609 clear_bit(RSCN_UPDATE, &flags);
4610 set_bit(LOCAL_LOOP_UPDATE, &flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004611 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004612 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613 set_bit(RSCN_UPDATE, &flags);
4614 set_bit(LOCAL_LOOP_UPDATE, &flags);
4615 }
4616
4617 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004618 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4619 ql_dbg(ql_dbg_disc, vha, 0x2015,
4620 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08004622 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004623 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624 }
4625
4626 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004627 if (LOOP_TRANSITION(vha)) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004628 ql_dbg(ql_dbg_disc, vha, 0x2099,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004629 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004631 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004632 else
4633 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634 }
4635
4636 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004637 if (atomic_read(&vha->loop_down_timer) ||
4638 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 rval = QLA_FUNCTION_FAILED;
4640 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004641 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004642 ql_dbg(ql_dbg_disc, vha, 0x2069,
4643 "LOOP READY.\n");
Quinn Tranec7193e2017-03-15 09:48:55 -07004644 ha->flags.fw_init_done = 1;
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05004645
4646 /*
4647 * Process any ATIO queue entries that came in
4648 * while we weren't online.
4649 */
Quinn Tranead03852017-01-19 22:28:01 -08004650 if (qla_tgt_mode_enabled(vha) ||
4651 qla_dual_mode_enabled(vha)) {
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05004652 if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) {
4653 spin_lock_irqsave(&ha->tgt.atio_lock,
4654 flags);
4655 qlt_24xx_process_atio_queue(vha, 0);
4656 spin_unlock_irqrestore(
4657 &ha->tgt.atio_lock, flags);
4658 } else {
4659 spin_lock_irqsave(&ha->hardware_lock,
4660 flags);
4661 qlt_24xx_process_atio_queue(vha, 1);
4662 spin_unlock_irqrestore(
4663 &ha->hardware_lock, flags);
4664 }
4665 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666 }
4667 }
4668
4669 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004670 ql_dbg(ql_dbg_disc, vha, 0x206a,
4671 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004672 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004673 ql_dbg(ql_dbg_disc, vha, 0x206b,
4674 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004675 }
4676
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07004677 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004678 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004679 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004680 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004681 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004682 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004683 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684 }
4685
4686 return (rval);
4687}
4688
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004689/*
4690 * N2N Login
4691 * Updates Fibre Channel Device Database with local loop devices.
4692 *
4693 * Input:
4694 * ha = adapter block pointer.
4695 *
4696 * Returns:
4697 */
4698static int qla24xx_n2n_handle_login(struct scsi_qla_host *vha,
4699 fc_port_t *fcport)
4700{
4701 struct qla_hw_data *ha = vha->hw;
4702 int res = QLA_SUCCESS, rval;
4703 int greater_wwpn = 0;
4704 int logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004705
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004706 if (ha->current_topology != ISP_CFG_N)
4707 return res;
4708
4709 if (wwn_to_u64(vha->port_name) >
4710 wwn_to_u64(vha->n2n_port_name)) {
4711 ql_dbg(ql_dbg_disc, vha, 0x2002,
4712 "HBA WWPN is greater %llx > target %llx\n",
4713 wwn_to_u64(vha->port_name),
4714 wwn_to_u64(vha->n2n_port_name));
4715 greater_wwpn = 1;
4716 fcport->d_id.b24 = vha->n2n_id;
4717 }
4718
4719 fcport->loop_id = vha->loop_id;
4720 fcport->fc4f_nvme = 0;
4721 fcport->query = 1;
4722
4723 ql_dbg(ql_dbg_disc, vha, 0x4001,
4724 "Initiate N2N login handler: HBA port_id=%06x loopid=%d\n",
4725 fcport->d_id.b24, vha->loop_id);
4726
4727 /* Fill in member data. */
4728 if (!greater_wwpn) {
4729 rval = qla2x00_get_port_database(vha, fcport, 0);
4730 ql_dbg(ql_dbg_disc, vha, 0x1051,
4731 "Remote login-state (%x/%x) port_id=%06x loop_id=%x, rval=%d\n",
4732 fcport->current_login_state, fcport->last_login_state,
4733 fcport->d_id.b24, fcport->loop_id, rval);
4734
4735 if (((fcport->current_login_state & 0xf) == 0x4) ||
4736 ((fcport->current_login_state & 0xf) == 0x6))
4737 logged_in = 1;
4738 }
4739
4740 if (logged_in || greater_wwpn) {
4741 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
4742 qla_nvme_register_hba(vha);
4743
4744 /* Set connected N_Port d_id */
4745 if (vha->flags.nvme_enabled)
4746 fcport->fc4f_nvme = 1;
4747
4748 fcport->scan_state = QLA_FCPORT_FOUND;
4749 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4750 fcport->disc_state = DSC_GNL;
4751 fcport->n2n_flag = 1;
4752 fcport->flags = 3;
4753 vha->hw->flags.gpsc_supported = 0;
4754
4755 if (greater_wwpn) {
4756 ql_dbg(ql_dbg_disc, vha, 0x20e5,
4757 "%s %d PLOGI ELS %8phC\n",
4758 __func__, __LINE__, fcport->port_name);
4759
4760 res = qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
4761 fcport, fcport->d_id);
4762 }
4763
4764 if (res != QLA_SUCCESS) {
4765 ql_log(ql_log_info, vha, 0xd04d,
4766 "PLOGI Failed: portid=%06x - retrying\n",
4767 fcport->d_id.b24);
4768 res = QLA_SUCCESS;
4769 } else {
4770 /* State 0x6 means FCP PRLI complete */
4771 if ((fcport->current_login_state & 0xf) == 0x6) {
4772 ql_dbg(ql_dbg_disc, vha, 0x2118,
4773 "%s %d %8phC post GPDB work\n",
4774 __func__, __LINE__, fcport->port_name);
4775 fcport->chip_reset =
4776 vha->hw->base_qpair->chip_reset;
4777 qla24xx_post_gpdb_work(vha, fcport, 0);
4778 } else {
4779 ql_dbg(ql_dbg_disc, vha, 0x2118,
4780 "%s %d %8phC post NVMe PRLI\n",
4781 __func__, __LINE__, fcport->port_name);
4782 qla24xx_post_prli_work(vha, fcport);
4783 }
4784 }
4785 } else {
4786 /* Wait for next database change */
4787 set_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags);
4788 }
4789
4790 return res;
4791}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792
4793/*
4794 * qla2x00_configure_local_loop
4795 * Updates Fibre Channel Device Database with local loop devices.
4796 *
4797 * Input:
4798 * ha = adapter block pointer.
4799 *
4800 * Returns:
4801 * 0 = success.
4802 */
4803static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004804qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004805{
4806 int rval, rval2;
4807 int found_devs;
4808 int found;
4809 fc_port_t *fcport, *new_fcport;
4810
4811 uint16_t index;
4812 uint16_t entries;
4813 char *id_iter;
4814 uint16_t loop_id;
4815 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004816 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08004817 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004818
4819 found_devs = 0;
4820 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08004821 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822
Linus Torvalds1da177e2005-04-16 15:20:36 -07004823 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08004824 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004825 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826 &entries);
4827 if (rval != QLA_SUCCESS)
4828 goto cleanup_allocation;
4829
Quinn Tran83548fe2017-06-02 09:12:01 -07004830 ql_dbg(ql_dbg_disc, vha, 0x2011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004831 "Entries in ID list (%d).\n", entries);
4832 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
4833 (uint8_t *)ha->gid_list,
4834 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835
Quinn Tran9cd883f2017-12-28 12:33:24 -08004836 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4837 fcport->scan_state = QLA_FCPORT_SCAN;
4838 }
4839
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004841 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004842 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004843 ql_log(ql_log_warn, vha, 0x2012,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004844 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845 rval = QLA_MEMORY_ALLOC_FAILED;
4846 goto cleanup_allocation;
4847 }
4848 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4849
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004850 /* Inititae N2N login. */
4851 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
4852 rval = qla24xx_n2n_handle_login(vha, new_fcport);
4853 if (rval != QLA_SUCCESS)
4854 goto cleanup_allocation;
4855 return QLA_SUCCESS;
4856 }
4857
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858 /* Add devices to port list. */
4859 id_iter = (char *)ha->gid_list;
4860 for (index = 0; index < entries; index++) {
4861 domain = ((struct gid_list_info *)id_iter)->domain;
4862 area = ((struct gid_list_info *)id_iter)->area;
4863 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004864 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004865 loop_id = (uint16_t)
4866 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004867 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868 loop_id = le16_to_cpu(
4869 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004870 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004871
4872 /* Bypass reserved domain fields. */
4873 if ((domain & 0xf0) == 0xf0)
4874 continue;
4875
4876 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004877 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004878 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879 continue;
4880
4881 /* Bypass invalid local loop ID. */
4882 if (loop_id > LAST_LOCAL_LOOP_ID)
4883 continue;
4884
Quinn Tran41dc5292017-01-19 22:28:03 -08004885 memset(new_fcport->port_name, 0, WWN_SIZE);
Arun Easi370d5502012-08-22 14:21:10 -04004886
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887 /* Fill in member data. */
4888 new_fcport->d_id.b.domain = domain;
4889 new_fcport->d_id.b.area = area;
4890 new_fcport->d_id.b.al_pa = al_pa;
4891 new_fcport->loop_id = loop_id;
Quinn Tran9cd883f2017-12-28 12:33:24 -08004892 new_fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tran41dc5292017-01-19 22:28:03 -08004893
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004894 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895 if (rval2 != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004896 ql_dbg(ql_dbg_disc, vha, 0x2097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004897 "Failed to retrieve fcport information "
4898 "-- get_port_database=%x, loop_id=0x%04x.\n",
4899 rval2, new_fcport->loop_id);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004900 /* Skip retry if N2N */
4901 if (ha->current_topology != ISP_CFG_N) {
4902 ql_dbg(ql_dbg_disc, vha, 0x2105,
4903 "Scheduling resync.\n");
4904 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4905 continue;
4906 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004907 }
4908
Quinn Tran41dc5292017-01-19 22:28:03 -08004909 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910 /* Check for matching device in port list. */
4911 found = 0;
4912 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004913 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004914 if (memcmp(new_fcport->port_name, fcport->port_name,
4915 WWN_SIZE))
4916 continue;
4917
Shyam Sundarddb9b122009-03-24 09:08:10 -07004918 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004919 fcport->loop_id = new_fcport->loop_id;
4920 fcport->port_type = new_fcport->port_type;
4921 fcport->d_id.b24 = new_fcport->d_id.b24;
4922 memcpy(fcport->node_name, new_fcport->node_name,
4923 WWN_SIZE);
Quinn Tran9cd883f2017-12-28 12:33:24 -08004924 fcport->scan_state = QLA_FCPORT_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925 found++;
4926 break;
4927 }
4928
4929 if (!found) {
4930 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004931 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004932
4933 /* Allocate a new replacement fcport. */
4934 fcport = new_fcport;
Quinn Tran41dc5292017-01-19 22:28:03 -08004935
4936 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4937
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004938 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Quinn Tran41dc5292017-01-19 22:28:03 -08004939
Linus Torvalds1da177e2005-04-16 15:20:36 -07004940 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004941 ql_log(ql_log_warn, vha, 0xd031,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004942 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004943 rval = QLA_MEMORY_ALLOC_FAILED;
4944 goto cleanup_allocation;
4945 }
Quinn Tran41dc5292017-01-19 22:28:03 -08004946 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4948 }
4949
Quinn Tran41dc5292017-01-19 22:28:03 -08004950 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4951
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004952 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004953 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004954
Linus Torvalds1da177e2005-04-16 15:20:36 -07004955 found_devs++;
4956 }
4957
Quinn Tran9cd883f2017-12-28 12:33:24 -08004958 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4959 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4960 break;
4961
4962 if (fcport->scan_state == QLA_FCPORT_SCAN) {
4963 if ((qla_dual_mode_enabled(vha) ||
4964 qla_ini_mode_enabled(vha)) &&
4965 atomic_read(&fcport->state) == FCS_ONLINE) {
4966 qla2x00_mark_device_lost(vha, fcport,
4967 ql2xplogiabsentdevice, 0);
4968 if (fcport->loop_id != FC_NO_LOOP_ID &&
4969 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
4970 fcport->port_type != FCT_INITIATOR &&
4971 fcport->port_type != FCT_BROADCAST) {
4972 ql_dbg(ql_dbg_disc, vha, 0x20f0,
4973 "%s %d %8phC post del sess\n",
4974 __func__, __LINE__,
4975 fcport->port_name);
4976
Quinn Trand8630bb2017-12-28 12:33:43 -08004977 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran9cd883f2017-12-28 12:33:24 -08004978 continue;
4979 }
4980 }
4981 }
4982
4983 if (fcport->scan_state == QLA_FCPORT_FOUND)
4984 qla24xx_fcport_handle_login(vha, fcport);
4985 }
4986
Linus Torvalds1da177e2005-04-16 15:20:36 -07004987cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08004988 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989
4990 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004991 ql_dbg(ql_dbg_disc, vha, 0x2098,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004992 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993 }
4994
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995 return (rval);
4996}
4997
4998static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004999qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005000{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005001 int rval;
Quinn Tran93f2bd62014-09-25 05:16:53 -04005002 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005003 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005004
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07005005 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005006 return;
5007
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07005008 if (atomic_read(&fcport->state) != FCS_ONLINE)
5009 return;
5010
Andrew Vasquez39bd9622007-09-20 14:07:34 -07005011 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
Himanshu Madhani413c2f32018-06-03 22:09:53 -07005012 fcport->fp_speed > ha->link_data_rate ||
5013 !ha->flags.gpsc_supported)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005014 return;
5015
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005016 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07005017 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005018 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005019 ql_dbg(ql_dbg_disc, vha, 0x2004,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04005020 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5021 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005022 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005023 ql_dbg(ql_dbg_disc, vha, 0x2005,
Quinn Tran33b28352018-03-20 23:09:40 -07005024 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -05005025 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Quinn Tran33b28352018-03-20 23:09:40 -07005026 fcport->fp_speed, fcport->port_name);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005027 }
5028}
5029
Quinn Trancc28e0a2018-05-01 09:01:48 -07005030void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5031{
5032 qla2x00_iidma_fcport(vha, fcport);
5033 qla24xx_update_fcport_fcp_prio(vha, fcport);
5034}
5035
5036int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5037{
5038 struct qla_work_evt *e;
5039
5040 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5041 if (!e)
5042 return QLA_FUNCTION_FAILED;
5043
5044 e->u.fcport.fcport = fcport;
5045 return qla2x00_post_work(vha, e);
5046}
5047
Quinn Tran726b8542017-01-19 22:28:00 -08005048/* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
Adrian Bunk23be3312006-11-24 02:46:01 +01005049static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005050qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05005051{
5052 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05005053 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08005054 unsigned long flags;
8482e1182005-04-17 15:04:54 -05005055
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07005056 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5057 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05005058 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5059 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5060 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005061 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07005062 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005063 ql_log(ql_log_warn, vha, 0x2006,
5064 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07005065 return;
5066 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005067
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08005068 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04005069 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08005070 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005071
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07005072 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07005073
5074 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05005075 if (fcport->port_type == FCT_INITIATOR)
5076 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
5077 if (fcport->port_type == FCT_TARGET)
5078 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Quinn Tran726b8542017-01-19 22:28:00 -08005079
Quinn Tran83548fe2017-06-02 09:12:01 -07005080 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5081 "%s %8phN. rport %p is %s mode\n",
5082 __func__, fcport->port_name, rport,
5083 (fcport->port_type == FCT_TARGET) ? "tgt" : "ini");
Quinn Tran726b8542017-01-19 22:28:00 -08005084
Andrew Vasquez77d74142005-07-08 18:00:36 -07005085 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05005086}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087
5088/*
Adrian Bunk23be3312006-11-24 02:46:01 +01005089 * qla2x00_update_fcport
5090 * Updates device on list.
5091 *
5092 * Input:
5093 * ha = adapter block pointer.
5094 * fcport = port structure pointer.
5095 *
5096 * Return:
5097 * 0 - Success
5098 * BIT_0 - error
5099 *
5100 * Context:
5101 * Kernel context.
5102 */
5103void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005104qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01005105{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005106 fcport->vha = vha;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005107
Quinn Tran726b8542017-01-19 22:28:00 -08005108 if (IS_SW_RESV_ADDR(fcport->d_id))
5109 return;
5110
Quinn Tran83548fe2017-06-02 09:12:01 -07005111 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
Quinn Tran726b8542017-01-19 22:28:00 -08005112 __func__, fcport->port_name);
5113
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005114 if (IS_QLAFX00(vha->hw)) {
5115 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Quinn Trancc28e0a2018-05-01 09:01:48 -07005116 } else {
5117 fcport->login_retry = 0;
5118 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5119 fcport->disc_state = DSC_LOGIN_COMPLETE;
5120 fcport->deleted = 0;
5121 fcport->logout_on_delete = 1;
5122 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005123 }
Adrian Bunk23be3312006-11-24 02:46:01 +01005124
Darren Trappdbe18012018-03-20 23:09:31 -07005125 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5126 qla2x00_iidma_fcport(vha, fcport);
5127
Duane Grigsbye84067d2017-06-21 13:48:43 -07005128 if (fcport->fc4f_nvme) {
5129 qla_nvme_register_remote(vha, fcport);
5130 return;
5131 }
5132
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005133 qla24xx_update_fcport_fcp_prio(vha, fcport);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04005134
Quinn Tran726b8542017-01-19 22:28:00 -08005135 switch (vha->host->active_mode) {
5136 case MODE_INITIATOR:
Alexei Potashnikd20ed912015-07-14 16:00:47 -04005137 qla2x00_reg_remote_port(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08005138 break;
5139 case MODE_TARGET:
5140 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5141 !vha->vha_tgt.qla_tgt->tgt_stopped)
5142 qlt_fc_port_added(vha, fcport);
5143 break;
5144 case MODE_DUAL:
5145 qla2x00_reg_remote_port(vha, fcport);
5146 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5147 !vha->vha_tgt.qla_tgt->tgt_stopped)
5148 qlt_fc_port_added(vha, fcport);
5149 break;
5150 default:
5151 break;
Alexei Potashnikd20ed912015-07-14 16:00:47 -04005152 }
Quinn Trancc28e0a2018-05-01 09:01:48 -07005153
5154 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5155 if (fcport->id_changed) {
5156 fcport->id_changed = 0;
5157 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5158 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5159 __func__, __LINE__, fcport->port_name,
5160 vha->fcport_count);
5161 qla24xx_post_gfpnid_work(vha, fcport);
5162 } else {
5163 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5164 "%s %d %8phC post gpsc fcp_cnt %d\n",
5165 __func__, __LINE__, fcport->port_name,
5166 vha->fcport_count);
5167 qla24xx_post_gpsc_work(vha, fcport);
5168 }
5169 }
Adrian Bunk23be3312006-11-24 02:46:01 +01005170}
5171
5172/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173 * qla2x00_configure_fabric
5174 * Setup SNS devices with loop ID's.
5175 *
5176 * Input:
5177 * ha = adapter block pointer.
5178 *
5179 * Returns:
5180 * 0 = success.
5181 * BIT_0 = error
5182 */
5183static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005184qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005185{
Arun Easib3b02e62012-02-09 11:15:39 -08005186 int rval;
Quinn Tran726b8542017-01-19 22:28:00 -08005187 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005188 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005189 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005190 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005191 struct qla_hw_data *ha = vha->hw;
Alexei Potashnikdf673272015-07-14 16:00:46 -04005192 int discovery_gen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005193
5194 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07005195 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005196 loop_id = NPH_F_PORT;
5197 else
5198 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005199 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005200 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005201 ql_dbg(ql_dbg_disc, vha, 0x20a0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005202 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005203
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005204 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205 return (QLA_SUCCESS);
5206 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005207 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005208
Quinn Tran41dc5292017-01-19 22:28:03 -08005209
5210 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5211 rval = qla2x00_send_change_request(vha, 0x3, 0);
5212 if (rval != QLA_SUCCESS)
5213 ql_log(ql_log_warn, vha, 0x121,
5214 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5215 rval);
5216 }
5217
5218
Linus Torvalds1da177e2005-04-16 15:20:36 -07005219 do {
Quinn Tran726b8542017-01-19 22:28:00 -08005220 qla2x00_mgmt_svr_login(vha);
5221
Andrew Vasquezcca53352005-08-26 19:08:30 -07005222 /* FDMI support. */
5223 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005224 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5225 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07005226
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227 /* Ensure we are logged into the SNS. */
Joe Carnuccioa14c7712017-08-23 15:05:12 -07005228 loop_id = NPH_SNS_LID(ha);
Chad Dupuis0b91d112012-02-09 11:15:42 -08005229 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5230 0xfc, mb, BIT_1|BIT_0);
Joe Carnuccioa14c7712017-08-23 15:05:12 -07005231 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5232 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5233 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5234 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
Chad Dupuis0b91d112012-02-09 11:15:42 -08005235 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05005236 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08005237 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005238 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5239 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07005241 ql_dbg(ql_dbg_disc, vha, 0x20a2,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005242 "Register FC-4 TYPE failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005243 if (test_bit(LOOP_RESYNC_NEEDED,
5244 &vha->dpc_flags))
5245 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005246 }
Duane Grigsbyd3bae932017-06-21 13:48:44 -07005247 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005248 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07005249 ql_dbg(ql_dbg_disc, vha, 0x209a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005250 "Register FC-4 Features failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005251 if (test_bit(LOOP_RESYNC_NEEDED,
5252 &vha->dpc_flags))
5253 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005254 }
Duane Grigsbyd3bae932017-06-21 13:48:44 -07005255 if (vha->flags.nvme_enabled) {
5256 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5257 ql_dbg(ql_dbg_disc, vha, 0x2049,
5258 "Register NVME FC Type Features failed.\n");
5259 }
5260 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005261 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07005263 ql_dbg(ql_dbg_disc, vha, 0x2104,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005264 "Register Node Name failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005265 if (test_bit(LOOP_RESYNC_NEEDED,
5266 &vha->dpc_flags))
5267 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005268 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07005270 ql_dbg(ql_dbg_disc, vha, 0x209b,
Colin Ian King0bf0efa2017-06-30 14:47:41 +01005271 "Register Symbolic Node Name failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005272 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5273 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274 }
5275 }
5276
Joe Carnuccio827210b2013-02-08 01:57:57 -05005277
Alexei Potashnikdf673272015-07-14 16:00:46 -04005278 /* Mark the time right before querying FW for connected ports.
5279 * This process is long, asynchronous and by the time it's done,
5280 * collected information might not be accurate anymore. E.g.
5281 * disconnected port might have re-connected and a brand new
5282 * session has been created. In this case session's generation
5283 * will be newer than discovery_gen. */
5284 qlt_do_generation_tick(vha, &discovery_gen);
5285
Quinn Trana4239942017-12-28 12:33:26 -08005286 if (USE_ASYNC_SCAN(ha)) {
Quinn Tran33b28352018-03-20 23:09:40 -07005287 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5288 NULL);
Quinn Trana4239942017-12-28 12:33:26 -08005289 if (rval)
5290 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5291 } else {
Quinn Tranf352eeb2017-12-28 12:33:35 -08005292 list_for_each_entry(fcport, &vha->vp_fcports, list)
5293 fcport->scan_state = QLA_FCPORT_SCAN;
5294
Quinn Trana4239942017-12-28 12:33:26 -08005295 rval = qla2x00_find_all_fabric_devs(vha);
5296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005297 if (rval != QLA_SUCCESS)
5298 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005299 } while (0);
5300
Duane Grigsbye84067d2017-06-21 13:48:43 -07005301 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5302 qla_nvme_register_hba(vha);
5303
Quinn Tran726b8542017-01-19 22:28:00 -08005304 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005305 ql_dbg(ql_dbg_disc, vha, 0x2068,
5306 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005307
5308 return (rval);
5309}
5310
Linus Torvalds1da177e2005-04-16 15:20:36 -07005311/*
5312 * qla2x00_find_all_fabric_devs
5313 *
5314 * Input:
5315 * ha = adapter block pointer.
5316 * dev = database device entry pointer.
5317 *
5318 * Returns:
5319 * 0 = success.
5320 *
5321 * Context:
5322 * Kernel context.
5323 */
5324static int
Quinn Tran726b8542017-01-19 22:28:00 -08005325qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005326{
5327 int rval;
5328 uint16_t loop_id;
Quinn Tran726b8542017-01-19 22:28:00 -08005329 fc_port_t *fcport, *new_fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005330 int found;
5331
5332 sw_info_t *swl;
5333 int swl_idx;
5334 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07005335 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005336 struct qla_hw_data *ha = vha->hw;
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05005337 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran726b8542017-01-19 22:28:00 -08005338 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005339
5340 rval = QLA_SUCCESS;
5341
5342 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08005343 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08005344 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08005345 GFP_KERNEL);
5346 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02005347 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005348 /*EMPTY*/
Quinn Tran83548fe2017-06-02 09:12:01 -07005349 ql_dbg(ql_dbg_disc, vha, 0x209c,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005350 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005351 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08005352 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005353 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005354 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005355 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5356 return rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005357 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005358 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005359 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5360 return rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005361 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005362 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005363 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5364 return rval;
Quinn Tran726b8542017-01-19 22:28:00 -08005365 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5366 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005367 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5368 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005369 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005370
5371 /* If other queries succeeded probe for FC-4 type */
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005372 if (swl) {
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005373 qla2x00_gff_id(vha, swl);
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005374 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5375 return rval;
5376 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005377 }
5378 swl_idx = 0;
5379
5380 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005381 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005382 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005383 ql_log(ql_log_warn, vha, 0x209d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005384 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005385 return (QLA_MEMORY_ALLOC_FAILED);
5386 }
5387 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005388 /* Set start port ID scan at adapter ID. */
5389 first_dev = 1;
5390 last_dev = 0;
5391
5392 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005393 loop_id = ha->min_external_loopid;
5394 for (; loop_id <= ha->max_loop_id; loop_id++) {
5395 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005396 continue;
5397
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07005398 if (ha->current_topology == ISP_CFG_FL &&
5399 (atomic_read(&vha->loop_down_timer) ||
5400 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08005401 atomic_set(&vha->loop_down_timer, 0);
5402 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5403 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005404 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08005405 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406
5407 if (swl != NULL) {
5408 if (last_dev) {
5409 wrap.b24 = new_fcport->d_id.b24;
5410 } else {
5411 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5412 memcpy(new_fcport->node_name,
5413 swl[swl_idx].node_name, WWN_SIZE);
5414 memcpy(new_fcport->port_name,
5415 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005416 memcpy(new_fcport->fabric_port_name,
5417 swl[swl_idx].fabric_port_name, WWN_SIZE);
5418 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005419 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005420
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005421 new_fcport->nvme_flag = 0;
Darren Trap1a28faa2017-08-30 10:16:48 -07005422 new_fcport->fc4f_nvme = 0;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005423 if (vha->flags.nvme_enabled &&
5424 swl[swl_idx].fc4f_nvme) {
5425 new_fcport->fc4f_nvme =
5426 swl[swl_idx].fc4f_nvme;
5427 ql_log(ql_log_info, vha, 0x2131,
5428 "FOUND: NVME port %8phC as FC Type 28h\n",
5429 new_fcport->port_name);
5430 }
5431
Linus Torvalds1da177e2005-04-16 15:20:36 -07005432 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5433 last_dev = 1;
5434 }
5435 swl_idx++;
5436 }
5437 } else {
5438 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005439 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005440 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005441 ql_log(ql_log_warn, vha, 0x209e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005442 "SNS scan failed -- assuming "
5443 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005444 rval = QLA_SUCCESS;
5445 break;
5446 }
5447 }
5448
5449 /* If wrap on switch device list, exit. */
5450 if (first_dev) {
5451 wrap.b24 = new_fcport->d_id.b24;
5452 first_dev = 0;
5453 } else if (new_fcport->d_id.b24 == wrap.b24) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005454 ql_dbg(ql_dbg_disc, vha, 0x209f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005455 "Device wrap (%02x%02x%02x).\n",
5456 new_fcport->d_id.b.domain,
5457 new_fcport->d_id.b.area,
5458 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005459 break;
5460 }
5461
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005462 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005463 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005464 continue;
5465
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005466 /* Bypass virtual ports of the same host. */
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05005467 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5468 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005469
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07005470 /* Bypass if same domain and area of adapter. */
5471 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005472 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07005473 ISP_CFG_FL)
5474 continue;
5475
Linus Torvalds1da177e2005-04-16 15:20:36 -07005476 /* Bypass reserved domain fields. */
5477 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5478 continue;
5479
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005480 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07005481 if (ql2xgffidenable &&
5482 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5483 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005484 continue;
5485
Quinn Tran726b8542017-01-19 22:28:00 -08005486 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5487
Linus Torvalds1da177e2005-04-16 15:20:36 -07005488 /* Locate matching device in database. */
5489 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005490 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005491 if (memcmp(new_fcport->port_name, fcport->port_name,
5492 WWN_SIZE))
5493 continue;
5494
Joe Carnuccio827210b2013-02-08 01:57:57 -05005495 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08005496
Linus Torvalds1da177e2005-04-16 15:20:36 -07005497 found++;
5498
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005499 /* Update port state. */
5500 memcpy(fcport->fabric_port_name,
5501 new_fcport->fabric_port_name, WWN_SIZE);
5502 fcport->fp_speed = new_fcport->fp_speed;
5503
Linus Torvalds1da177e2005-04-16 15:20:36 -07005504 /*
Roland Dreierb2032fd2015-07-14 16:00:42 -04005505 * If address the same and state FCS_ONLINE
5506 * (or in target mode), nothing changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005507 */
5508 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
Roland Dreierb2032fd2015-07-14 16:00:42 -04005509 (atomic_read(&fcport->state) == FCS_ONLINE ||
Quinn Tran726b8542017-01-19 22:28:00 -08005510 (vha->host->active_mode == MODE_TARGET))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005511 break;
5512 }
5513
5514 /*
5515 * If device was not a fabric device before.
5516 */
5517 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5518 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04005519 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005520 fcport->flags |= (FCF_FABRIC_DEVICE |
5521 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005522 break;
5523 }
5524
5525 /*
5526 * Port ID changed or device was marked to be updated;
5527 * Log it out if still logged in and mark it for
5528 * relogin later.
5529 */
Quinn Tran726b8542017-01-19 22:28:00 -08005530 if (qla_tgt_mode_enabled(base_vha)) {
Roland Dreierb2032fd2015-07-14 16:00:42 -04005531 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5532 "port changed FC ID, %8phC"
5533 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5534 fcport->port_name,
5535 fcport->d_id.b.domain,
5536 fcport->d_id.b.area,
5537 fcport->d_id.b.al_pa,
5538 fcport->loop_id,
5539 new_fcport->d_id.b.domain,
5540 new_fcport->d_id.b.area,
5541 new_fcport->d_id.b.al_pa);
5542 fcport->d_id.b24 = new_fcport->d_id.b24;
5543 break;
5544 }
5545
Linus Torvalds1da177e2005-04-16 15:20:36 -07005546 fcport->d_id.b24 = new_fcport->d_id.b24;
5547 fcport->flags |= FCF_LOGIN_NEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005548 break;
5549 }
5550
Darren Trapp9dd96862018-03-20 23:09:32 -07005551 if (fcport->fc4f_nvme) {
5552 if (fcport->disc_state == DSC_DELETE_PEND) {
5553 fcport->disc_state = DSC_GNL;
5554 vha->fcport_count--;
5555 fcport->login_succ = 0;
5556 }
5557 }
5558
Quinn Tran726b8542017-01-19 22:28:00 -08005559 if (found) {
5560 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005561 continue;
Quinn Tran726b8542017-01-19 22:28:00 -08005562 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005563 /* If device was not in our fcports list, then add it. */
Roland Dreierb2032fd2015-07-14 16:00:42 -04005564 new_fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tran726b8542017-01-19 22:28:00 -08005565 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5566
5567 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5568
Linus Torvalds1da177e2005-04-16 15:20:36 -07005569
5570 /* Allocate a new replacement fcport. */
5571 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005572 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005573 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005574 ql_log(ql_log_warn, vha, 0xd032,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005575 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005576 return (QLA_MEMORY_ALLOC_FAILED);
5577 }
5578 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5579 new_fcport->d_id.b24 = nxt_d_id.b24;
5580 }
5581
Quinn Tran726b8542017-01-19 22:28:00 -08005582 qla2x00_free_fcport(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005583
Quinn Tran726b8542017-01-19 22:28:00 -08005584 /*
5585 * Logout all previous fabric dev marked lost, except FCP2 devices.
5586 */
5587 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5588 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5589 break;
5590
5591 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5592 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5593 continue;
5594
5595 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5596 if ((qla_dual_mode_enabled(vha) ||
5597 qla_ini_mode_enabled(vha)) &&
5598 atomic_read(&fcport->state) == FCS_ONLINE) {
5599 qla2x00_mark_device_lost(vha, fcport,
5600 ql2xplogiabsentdevice, 0);
5601 if (fcport->loop_id != FC_NO_LOOP_ID &&
5602 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5603 fcport->port_type != FCT_INITIATOR &&
5604 fcport->port_type != FCT_BROADCAST) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005605 ql_dbg(ql_dbg_disc, vha, 0x20f0,
Quinn Tran726b8542017-01-19 22:28:00 -08005606 "%s %d %8phC post del sess\n",
5607 __func__, __LINE__,
5608 fcport->port_name);
Quinn Trand8630bb2017-12-28 12:33:43 -08005609 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08005610 continue;
5611 }
5612 }
5613 }
5614
5615 if (fcport->scan_state == QLA_FCPORT_FOUND)
5616 qla24xx_fcport_handle_login(vha, fcport);
5617 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005618 return (rval);
5619}
5620
5621/*
5622 * qla2x00_find_new_loop_id
5623 * Scan through our port list and find a new usable loop ID.
5624 *
5625 * Input:
5626 * ha: adapter state pointer.
5627 * dev: port structure pointer.
5628 *
5629 * Returns:
5630 * qla2x00 local function return status code.
5631 *
5632 * Context:
5633 * Kernel context.
5634 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07005635int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005636qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005637{
5638 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005639 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07005640 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005641
5642 rval = QLA_SUCCESS;
5643
Chad Dupuis5f16b332012-08-22 14:21:00 -04005644 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005645
Chad Dupuis5f16b332012-08-22 14:21:00 -04005646 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
5647 LOOPID_MAP_SIZE);
5648 if (dev->loop_id >= LOOPID_MAP_SIZE ||
5649 qla2x00_is_reserved_id(vha, dev->loop_id)) {
5650 dev->loop_id = FC_NO_LOOP_ID;
5651 rval = QLA_FUNCTION_FAILED;
5652 } else
5653 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005654
Chad Dupuis5f16b332012-08-22 14:21:00 -04005655 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005656
Chad Dupuis5f16b332012-08-22 14:21:00 -04005657 if (rval == QLA_SUCCESS)
5658 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
5659 "Assigning new loopid=%x, portid=%x.\n",
5660 dev->loop_id, dev->d_id.b24);
5661 else
5662 ql_log(ql_log_warn, dev->vha, 0x2087,
5663 "No loop_id's available, portid=%x.\n",
5664 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005665
5666 return (rval);
5667}
5668
Linus Torvalds1da177e2005-04-16 15:20:36 -07005669
5670/*
5671 * qla2x00_fabric_login
5672 * Issue fabric login command.
5673 *
5674 * Input:
5675 * ha = adapter block pointer.
5676 * device = pointer to FC device type structure.
5677 *
5678 * Returns:
5679 * 0 - Login successfully
5680 * 1 - Login failed
5681 * 2 - Initiator device
5682 * 3 - Fatal error
5683 */
5684int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005685qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005686 uint16_t *next_loopid)
5687{
5688 int rval;
5689 int retry;
5690 uint16_t tmp_loopid;
5691 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005692 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005693
5694 retry = 0;
5695 tmp_loopid = 0;
5696
5697 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005698 ql_dbg(ql_dbg_disc, vha, 0x2000,
5699 "Trying Fabric Login w/loop id 0x%04x for port "
5700 "%02x%02x%02x.\n",
5701 fcport->loop_id, fcport->d_id.b.domain,
5702 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005703
5704 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08005705 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005706 fcport->d_id.b.domain, fcport->d_id.b.area,
5707 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08005708 if (rval != QLA_SUCCESS) {
5709 return rval;
5710 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005711 if (mb[0] == MBS_PORT_ID_USED) {
5712 /*
5713 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005714 * recommends the driver perform an implicit login with
5715 * the specified ID again. The ID we just used is save
5716 * here so we return with an ID that can be tried by
5717 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005718 */
5719 retry++;
5720 tmp_loopid = fcport->loop_id;
5721 fcport->loop_id = mb[1];
5722
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005723 ql_dbg(ql_dbg_disc, vha, 0x2001,
5724 "Fabric Login: port in use - next loop "
5725 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07005726 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005727 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005728
5729 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
5730 /*
5731 * Login succeeded.
5732 */
5733 if (retry) {
5734 /* A retry occurred before. */
5735 *next_loopid = tmp_loopid;
5736 } else {
5737 /*
5738 * No retry occurred before. Just increment the
5739 * ID value for next login.
5740 */
5741 *next_loopid = (fcport->loop_id + 1);
5742 }
5743
5744 if (mb[1] & BIT_0) {
5745 fcport->port_type = FCT_INITIATOR;
5746 } else {
5747 fcport->port_type = FCT_TARGET;
5748 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07005749 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005750 }
5751 }
5752
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07005753 if (mb[10] & BIT_0)
5754 fcport->supported_classes |= FC_COS_CLASS2;
5755 if (mb[10] & BIT_1)
5756 fcport->supported_classes |= FC_COS_CLASS3;
5757
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005758 if (IS_FWI2_CAPABLE(ha)) {
5759 if (mb[10] & BIT_7)
5760 fcport->flags |=
5761 FCF_CONF_COMP_SUPPORTED;
5762 }
5763
Linus Torvalds1da177e2005-04-16 15:20:36 -07005764 rval = QLA_SUCCESS;
5765 break;
5766 } else if (mb[0] == MBS_LOOP_ID_USED) {
5767 /*
5768 * Loop ID already used, try next loop ID.
5769 */
5770 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005771 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005772 if (rval != QLA_SUCCESS) {
5773 /* Ran out of loop IDs to use */
5774 break;
5775 }
5776 } else if (mb[0] == MBS_COMMAND_ERROR) {
5777 /*
5778 * Firmware possibly timed out during login. If NO
5779 * retries are left to do then the device is declared
5780 * dead.
5781 */
5782 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005783 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07005784 fcport->d_id.b.domain, fcport->d_id.b.area,
5785 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005786 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005787
5788 rval = 1;
5789 break;
5790 } else {
5791 /*
5792 * unrecoverable / not handled error
5793 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005794 ql_dbg(ql_dbg_disc, vha, 0x2002,
5795 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
5796 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
5797 fcport->d_id.b.area, fcport->d_id.b.al_pa,
5798 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005799
5800 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005801 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07005802 fcport->d_id.b.domain, fcport->d_id.b.area,
5803 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04005804 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07005805 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005806
5807 rval = 3;
5808 break;
5809 }
5810 }
5811
5812 return (rval);
5813}
5814
5815/*
5816 * qla2x00_local_device_login
5817 * Issue local device login command.
5818 *
5819 * Input:
5820 * ha = adapter block pointer.
5821 * loop_id = loop id of device to login to.
5822 *
5823 * Returns (Where's the #define!!!!):
5824 * 0 - Login successfully
5825 * 1 - Login failed
5826 * 3 - Fatal error
5827 */
5828int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005829qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005830{
5831 int rval;
5832 uint16_t mb[MAILBOX_REGISTER_COUNT];
5833
5834 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005835 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836 if (rval == QLA_SUCCESS) {
5837 /* Interrogate mailbox registers for any errors */
5838 if (mb[0] == MBS_COMMAND_ERROR)
5839 rval = 1;
5840 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
5841 /* device not in PCB table */
5842 rval = 3;
5843 }
5844
5845 return (rval);
5846}
5847
5848/*
5849 * qla2x00_loop_resync
5850 * Resync with fibre channel devices.
5851 *
5852 * Input:
5853 * ha = adapter block pointer.
5854 *
5855 * Returns:
5856 * 0 = success
5857 */
5858int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005859qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005860{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005861 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005862 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005863 struct req_que *req;
5864 struct rsp_que *rsp;
5865
Michael Hernandezd7459522016-12-12 14:40:07 -08005866 req = vha->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005867 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005868
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005869 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5870 if (vha->flags.online) {
5871 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005872 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5873 wait_time = 256;
5874 do {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005875 if (!IS_QLAFX00(vha->hw)) {
5876 /*
5877 * Issue a marker after FW becomes
5878 * ready.
5879 */
5880 qla2x00_marker(vha, req, rsp, 0, 0,
5881 MK_SYNC_ALL);
5882 vha->marker_needed = 0;
5883 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005884
5885 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005886 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005887
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005888 if (IS_QLAFX00(vha->hw))
5889 qlafx00_configure_devices(vha);
5890 else
5891 qla2x00_configure_loop(vha);
5892
Linus Torvalds1da177e2005-04-16 15:20:36 -07005893 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005894 } while (!atomic_read(&vha->loop_down_timer) &&
5895 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5896 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
5897 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005898 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005899 }
5900
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005901 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005902 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005903
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005904 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005905 ql_dbg(ql_dbg_disc, vha, 0x206c,
5906 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005907
5908 return (rval);
5909}
5910
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005911/*
5912* qla2x00_perform_loop_resync
5913* Description: This function will set the appropriate flags and call
5914* qla2x00_loop_resync. If successful loop will be resynced
5915* Arguments : scsi_qla_host_t pointer
5916* returm : Success or Failure
5917*/
5918
5919int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
5920{
5921 int32_t rval = 0;
5922
5923 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
5924 /*Configure the flags so that resync happens properly*/
5925 atomic_set(&ha->loop_down_timer, 0);
5926 if (!(ha->device_flags & DFLG_NO_CABLE)) {
5927 atomic_set(&ha->loop_state, LOOP_UP);
5928 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
5929 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
5930 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
5931
5932 rval = qla2x00_loop_resync(ha);
5933 } else
5934 atomic_set(&ha->loop_state, LOOP_DEAD);
5935
5936 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
5937 }
5938
5939 return rval;
5940}
5941
Linus Torvalds1da177e2005-04-16 15:20:36 -07005942void
Andrew Vasquez67becc02009-08-25 11:36:20 -07005943qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005944{
5945 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07005946 struct scsi_qla_host *vha;
5947 struct qla_hw_data *ha = base_vha->hw;
5948 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005949
Arun Easifeafb7b2010-09-03 14:57:00 -07005950 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005951 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07005952 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
5953 atomic_inc(&vha->vref_count);
5954 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08005955 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07005956 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
5957 spin_unlock_irqrestore(&ha->vport_slock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07005958 qla2x00_rport_del(fcport);
Alexei Potashnikdf673272015-07-14 16:00:46 -04005959
Arun Easifeafb7b2010-09-03 14:57:00 -07005960 spin_lock_irqsave(&ha->vport_slock, flags);
5961 }
5962 }
5963 atomic_dec(&vha->vref_count);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07005964 wake_up(&vha->vref_waitq);
Arun Easifeafb7b2010-09-03 14:57:00 -07005965 }
5966 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005967}
5968
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005969/* Assumes idc_lock always held on entry */
5970void
5971qla83xx_reset_ownership(scsi_qla_host_t *vha)
5972{
5973 struct qla_hw_data *ha = vha->hw;
5974 uint32_t drv_presence, drv_presence_mask;
5975 uint32_t dev_part_info1, dev_part_info2, class_type;
5976 uint32_t class_type_mask = 0x3;
5977 uint16_t fcoe_other_function = 0xffff, i;
5978
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005979 if (IS_QLA8044(ha)) {
5980 drv_presence = qla8044_rd_direct(vha,
5981 QLA8044_CRB_DRV_ACTIVE_INDEX);
5982 dev_part_info1 = qla8044_rd_direct(vha,
5983 QLA8044_CRB_DEV_PART_INFO_INDEX);
5984 dev_part_info2 = qla8044_rd_direct(vha,
5985 QLA8044_CRB_DEV_PART_INFO2);
5986 } else {
5987 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5988 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
5989 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
5990 }
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005991 for (i = 0; i < 8; i++) {
5992 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
5993 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5994 (i != ha->portnum)) {
5995 fcoe_other_function = i;
5996 break;
5997 }
5998 }
5999 if (fcoe_other_function == 0xffff) {
6000 for (i = 0; i < 8; i++) {
6001 class_type = ((dev_part_info2 >> (i * 4)) &
6002 class_type_mask);
6003 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6004 ((i + 8) != ha->portnum)) {
6005 fcoe_other_function = i + 8;
6006 break;
6007 }
6008 }
6009 }
6010 /*
6011 * Prepare drv-presence mask based on fcoe functions present.
6012 * However consider only valid physical fcoe function numbers (0-15).
6013 */
6014 drv_presence_mask = ~((1 << (ha->portnum)) |
6015 ((fcoe_other_function == 0xffff) ?
6016 0 : (1 << (fcoe_other_function))));
6017
6018 /* We are the reset owner iff:
6019 * - No other protocol drivers present.
6020 * - This is the lowest among fcoe functions. */
6021 if (!(drv_presence & drv_presence_mask) &&
6022 (ha->portnum < fcoe_other_function)) {
6023 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6024 "This host is Reset owner.\n");
6025 ha->flags.nic_core_reset_owner = 1;
6026 }
6027}
6028
Saurav Kashyapfa492632012-11-21 02:40:29 -05006029static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006030__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6031{
6032 int rval = QLA_SUCCESS;
6033 struct qla_hw_data *ha = vha->hw;
6034 uint32_t drv_ack;
6035
6036 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6037 if (rval == QLA_SUCCESS) {
6038 drv_ack |= (1 << ha->portnum);
6039 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6040 }
6041
6042 return rval;
6043}
6044
Saurav Kashyapfa492632012-11-21 02:40:29 -05006045static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006046__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6047{
6048 int rval = QLA_SUCCESS;
6049 struct qla_hw_data *ha = vha->hw;
6050 uint32_t drv_ack;
6051
6052 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6053 if (rval == QLA_SUCCESS) {
6054 drv_ack &= ~(1 << ha->portnum);
6055 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6056 }
6057
6058 return rval;
6059}
6060
Saurav Kashyapfa492632012-11-21 02:40:29 -05006061static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006062qla83xx_dev_state_to_string(uint32_t dev_state)
6063{
6064 switch (dev_state) {
6065 case QLA8XXX_DEV_COLD:
6066 return "COLD/RE-INIT";
6067 case QLA8XXX_DEV_INITIALIZING:
6068 return "INITIALIZING";
6069 case QLA8XXX_DEV_READY:
6070 return "READY";
6071 case QLA8XXX_DEV_NEED_RESET:
6072 return "NEED RESET";
6073 case QLA8XXX_DEV_NEED_QUIESCENT:
6074 return "NEED QUIESCENT";
6075 case QLA8XXX_DEV_FAILED:
6076 return "FAILED";
6077 case QLA8XXX_DEV_QUIESCENT:
6078 return "QUIESCENT";
6079 default:
6080 return "Unknown";
6081 }
6082}
6083
6084/* Assumes idc-lock always held on entry */
6085void
6086qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6087{
6088 struct qla_hw_data *ha = vha->hw;
6089 uint32_t idc_audit_reg = 0, duration_secs = 0;
6090
6091 switch (audit_type) {
6092 case IDC_AUDIT_TIMESTAMP:
6093 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6094 idc_audit_reg = (ha->portnum) |
6095 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6096 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6097 break;
6098
6099 case IDC_AUDIT_COMPLETION:
6100 duration_secs = ((jiffies_to_msecs(jiffies) -
6101 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6102 idc_audit_reg = (ha->portnum) |
6103 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6104 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6105 break;
6106
6107 default:
6108 ql_log(ql_log_warn, vha, 0xb078,
6109 "Invalid audit type specified.\n");
6110 break;
6111 }
6112}
6113
6114/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05006115static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006116qla83xx_initiating_reset(scsi_qla_host_t *vha)
6117{
6118 struct qla_hw_data *ha = vha->hw;
6119 uint32_t idc_control, dev_state;
6120
6121 __qla83xx_get_idc_control(vha, &idc_control);
6122 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6123 ql_log(ql_log_info, vha, 0xb080,
6124 "NIC Core reset has been disabled. idc-control=0x%x\n",
6125 idc_control);
6126 return QLA_FUNCTION_FAILED;
6127 }
6128
6129 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6130 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6131 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6132 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6133 QLA8XXX_DEV_NEED_RESET);
6134 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6135 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6136 } else {
6137 const char *state = qla83xx_dev_state_to_string(dev_state);
6138 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6139
6140 /* SV: XXX: Is timeout required here? */
6141 /* Wait for IDC state change READY -> NEED_RESET */
6142 while (dev_state == QLA8XXX_DEV_READY) {
6143 qla83xx_idc_unlock(vha, 0);
6144 msleep(200);
6145 qla83xx_idc_lock(vha, 0);
6146 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6147 }
6148 }
6149
6150 /* Send IDC ack by writing to drv-ack register */
6151 __qla83xx_set_drv_ack(vha);
6152
6153 return QLA_SUCCESS;
6154}
6155
6156int
6157__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6158{
6159 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6160}
6161
6162int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006163__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6164{
6165 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6166}
6167
Saurav Kashyapfa492632012-11-21 02:40:29 -05006168static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006169qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6170{
6171 uint32_t drv_presence = 0;
6172 struct qla_hw_data *ha = vha->hw;
6173
6174 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6175 if (drv_presence & (1 << ha->portnum))
6176 return QLA_SUCCESS;
6177 else
6178 return QLA_TEST_FAILED;
6179}
6180
6181int
6182qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6183{
6184 int rval = QLA_SUCCESS;
6185 struct qla_hw_data *ha = vha->hw;
6186
6187 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6188 "Entered %s().\n", __func__);
6189
6190 if (vha->device_flags & DFLG_DEV_FAILED) {
6191 ql_log(ql_log_warn, vha, 0xb059,
6192 "Device in unrecoverable FAILED state.\n");
6193 return QLA_FUNCTION_FAILED;
6194 }
6195
6196 qla83xx_idc_lock(vha, 0);
6197
6198 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6199 ql_log(ql_log_warn, vha, 0xb05a,
6200 "Function=0x%x has been removed from IDC participation.\n",
6201 ha->portnum);
6202 rval = QLA_FUNCTION_FAILED;
6203 goto exit;
6204 }
6205
6206 qla83xx_reset_ownership(vha);
6207
6208 rval = qla83xx_initiating_reset(vha);
6209
6210 /*
6211 * Perform reset if we are the reset-owner,
6212 * else wait till IDC state changes to READY/FAILED.
6213 */
6214 if (rval == QLA_SUCCESS) {
6215 rval = qla83xx_idc_state_handler(vha);
6216
6217 if (rval == QLA_SUCCESS)
6218 ha->flags.nic_core_hung = 0;
6219 __qla83xx_clear_drv_ack(vha);
6220 }
6221
6222exit:
6223 qla83xx_idc_unlock(vha, 0);
6224
6225 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6226
6227 return rval;
6228}
6229
Saurav Kashyap81178772012-08-22 14:21:04 -04006230int
6231qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6232{
6233 struct qla_hw_data *ha = vha->hw;
6234 int rval = QLA_FUNCTION_FAILED;
6235
6236 if (!IS_MCTP_CAPABLE(ha)) {
6237 /* This message can be removed from the final version */
6238 ql_log(ql_log_info, vha, 0x506d,
6239 "This board is not MCTP capable\n");
6240 return rval;
6241 }
6242
6243 if (!ha->mctp_dump) {
6244 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6245 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6246
6247 if (!ha->mctp_dump) {
6248 ql_log(ql_log_warn, vha, 0x506e,
6249 "Failed to allocate memory for mctp dump\n");
6250 return rval;
6251 }
6252 }
6253
6254#define MCTP_DUMP_STR_ADDR 0x00000000
6255 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6256 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6257 if (rval != QLA_SUCCESS) {
6258 ql_log(ql_log_warn, vha, 0x506f,
6259 "Failed to capture mctp dump\n");
6260 } else {
6261 ql_log(ql_log_info, vha, 0x5070,
6262 "Mctp dump capture for host (%ld/%p).\n",
6263 vha->host_no, ha->mctp_dump);
6264 ha->mctp_dumped = 1;
6265 }
6266
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04006267 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04006268 ha->flags.nic_core_reset_hdlr_active = 1;
6269 rval = qla83xx_restart_nic_firmware(vha);
6270 if (rval)
6271 /* NIC Core reset failed. */
6272 ql_log(ql_log_warn, vha, 0x5071,
6273 "Failed to restart nic firmware\n");
6274 else
6275 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6276 "Restarted NIC firmware successfully.\n");
6277 ha->flags.nic_core_reset_hdlr_active = 0;
6278 }
6279
6280 return rval;
6281
6282}
6283
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006284/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006285* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006286* Description: This function will block the new I/Os
6287* Its not aborting any I/Os as context
6288* is not destroyed during quiescence
6289* Arguments: scsi_qla_host_t
6290* return : void
6291*/
6292void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006293qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006294{
6295 struct qla_hw_data *ha = vha->hw;
6296 struct scsi_qla_host *vp;
6297
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006298 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6299 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006300
6301 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6302 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6303 atomic_set(&vha->loop_state, LOOP_DOWN);
6304 qla2x00_mark_all_devices_lost(vha, 0);
6305 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04006306 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006307 } else {
6308 if (!atomic_read(&vha->loop_down_timer))
6309 atomic_set(&vha->loop_down_timer,
6310 LOOP_DOWN_TIME);
6311 }
6312 /* Wait for pending cmds to complete */
6313 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
6314}
6315
Giridhar Malavalia9083012010-04-12 17:59:55 -07006316void
6317qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6318{
6319 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006320 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07006321 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08006322 fc_port_t *fcport;
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07006323 u16 i;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006324
Saurav Kashyape46ef002011-02-23 15:27:16 -08006325 /* For ISP82XX, driver waits for completion of the commands.
6326 * online flag should be set.
6327 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006328 if (!(IS_P3P_TYPE(ha)))
Saurav Kashyape46ef002011-02-23 15:27:16 -08006329 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006330 ha->flags.chip_reset_done = 0;
6331 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04006332 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006333
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006334 ql_log(ql_log_info, vha, 0x00af,
6335 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006336
Saurav Kashyape46ef002011-02-23 15:27:16 -08006337 /* For ISP82XX, reset_chip is just disabling interrupts.
6338 * Driver waits for the completion of the commands.
6339 * the interrupts need to be enabled.
6340 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006341 if (!(IS_P3P_TYPE(ha)))
Giridhar Malavalia9083012010-04-12 17:59:55 -07006342 ha->isp_ops->reset_chip(vha);
6343
Quinn Tran9cd883f2017-12-28 12:33:24 -08006344 SAVE_TOPO(ha);
6345 ha->flags.rida_fmt2 = 0;
Quinn Tranec7193e2017-03-15 09:48:55 -07006346 ha->flags.n2n_ae = 0;
6347 ha->flags.lip_ae = 0;
6348 ha->current_topology = 0;
6349 ha->flags.fw_started = 0;
6350 ha->flags.fw_init_done = 0;
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07006351 ha->base_qpair->chip_reset++;
6352 for (i = 0; i < ha->max_qpairs; i++) {
6353 if (ha->queue_pair_map[i])
6354 ha->queue_pair_map[i]->chip_reset =
6355 ha->base_qpair->chip_reset;
6356 }
Quinn Tran726b8542017-01-19 22:28:00 -08006357
Giridhar Malavalia9083012010-04-12 17:59:55 -07006358 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6359 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6360 atomic_set(&vha->loop_state, LOOP_DOWN);
6361 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07006362
6363 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006364 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07006365 atomic_inc(&vp->vref_count);
6366 spin_unlock_irqrestore(&ha->vport_slock, flags);
6367
Giridhar Malavalia9083012010-04-12 17:59:55 -07006368 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07006369
6370 spin_lock_irqsave(&ha->vport_slock, flags);
6371 atomic_dec(&vp->vref_count);
6372 }
6373 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006374 } else {
6375 if (!atomic_read(&vha->loop_down_timer))
6376 atomic_set(&vha->loop_down_timer,
6377 LOOP_DOWN_TIME);
6378 }
6379
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08006380 /* Clear all async request states across all VPs. */
6381 list_for_each_entry(fcport, &vha->vp_fcports, list)
6382 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6383 spin_lock_irqsave(&ha->vport_slock, flags);
6384 list_for_each_entry(vp, &ha->vp_list, list) {
6385 atomic_inc(&vp->vref_count);
6386 spin_unlock_irqrestore(&ha->vport_slock, flags);
6387
6388 list_for_each_entry(fcport, &vp->vp_fcports, list)
6389 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6390
6391 spin_lock_irqsave(&ha->vport_slock, flags);
6392 atomic_dec(&vp->vref_count);
6393 }
6394 spin_unlock_irqrestore(&ha->vport_slock, flags);
6395
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006396 if (!ha->flags.eeh_busy) {
6397 /* Make sure for ISP 82XX IO DMA is complete */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006398 if (IS_P3P_TYPE(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006399 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006400 ql_log(ql_log_info, vha, 0x00b4,
6401 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006402
Saurav Kashyape46ef002011-02-23 15:27:16 -08006403 /* Done waiting for pending commands.
6404 * Reset the online flag.
6405 */
6406 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006407 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006408
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006409 /* Requeue all commands in outstanding command list. */
6410 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6411 }
Arun Easib6a029e2014-09-25 06:14:52 -04006412 /* memory barrier */
6413 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006414}
6415
6416/*
6417* qla2x00_abort_isp
6418* Resets ISP and aborts all outstanding commands.
6419*
6420* Input:
6421* ha = adapter block pointer.
6422*
6423* Returns:
6424* 0 = success
6425*/
6426int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006427qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006428{
Andrew Vasquez476e8972006-08-23 14:54:55 -07006429 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006430 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006431 struct qla_hw_data *ha = vha->hw;
6432 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006433 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07006434 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006436 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07006437 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006438
Santosh Vernekara61712972012-08-22 14:21:13 -04006439 if (IS_QLA8031(ha)) {
6440 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6441 "Clearing fcoe driver presence.\n");
6442 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6443 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6444 "Error while clearing DRV-Presence.\n");
6445 }
6446
Andrew Vasquez85880802009-12-15 21:29:46 -08006447 if (unlikely(pci_channel_offline(ha->pdev) &&
6448 ha->flags.pci_channel_io_perm_failure)) {
6449 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6450 status = 0;
6451 return status;
6452 }
6453
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006454 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08006455
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006456 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006457
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006458 if (!qla2x00_restart_isp(vha)) {
6459 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006460
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006461 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006462 /*
6463 * Issue marker command only when we are going
6464 * to start the I/O .
6465 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006466 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467 }
6468
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006469 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006470
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006471 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07006473 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006474 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07006475
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006476 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6477 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08006478 if (ha->fce) {
6479 ha->flags.fce_enabled = 1;
6480 memset(ha->fce, 0,
6481 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006482 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08006483 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6484 &ha->fce_bufs);
6485 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006486 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08006487 "Unable to reinitialize FCE "
6488 "(%d).\n", rval);
6489 ha->flags.fce_enabled = 0;
6490 }
6491 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006492
6493 if (ha->eft) {
6494 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006495 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006496 ha->eft_dma, EFT_NUM_BUFFERS);
6497 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006498 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006499 "Unable to reinitialize EFT "
6500 "(%d).\n", rval);
6501 }
6502 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006503 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006504 vha->flags.online = 1;
6505 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006506 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006507 ql_log(ql_log_fatal, vha, 0x8035,
6508 "ISP error recover failed - "
6509 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07006510 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006511 * The next call disables the board
6512 * completely.
6513 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006514 ha->isp_ops->reset_adapter(vha);
6515 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006517 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518 status = 0;
6519 } else { /* schedule another ISP abort */
6520 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006521 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6522 "ISP abort - retry remaining %d.\n",
6523 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006524 status = 1;
6525 }
6526 } else {
6527 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006528 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6529 "ISP error recovery - retrying (%d) "
6530 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006531 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006532 status = 1;
6533 }
6534 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07006535
Linus Torvalds1da177e2005-04-16 15:20:36 -07006536 }
6537
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006538 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006539 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Quinn Tran1608cc42017-08-23 15:05:03 -07006540 qla2x00_configure_hba(vha);
Arun Easifeafb7b2010-09-03 14:57:00 -07006541 spin_lock_irqsave(&ha->vport_slock, flags);
6542 list_for_each_entry(vp, &ha->vp_list, list) {
6543 if (vp->vp_idx) {
6544 atomic_inc(&vp->vref_count);
6545 spin_unlock_irqrestore(&ha->vport_slock, flags);
6546
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006547 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07006548
6549 spin_lock_irqsave(&ha->vport_slock, flags);
6550 atomic_dec(&vp->vref_count);
6551 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006552 }
Arun Easifeafb7b2010-09-03 14:57:00 -07006553 spin_unlock_irqrestore(&ha->vport_slock, flags);
6554
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006555 if (IS_QLA8031(ha)) {
6556 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6557 "Setting back fcoe driver presence.\n");
6558 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6559 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6560 "Error while setting DRV-Presence.\n");
6561 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006562 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08006563 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6564 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006565 }
6566
6567 return(status);
6568}
6569
6570/*
6571* qla2x00_restart_isp
6572* restarts the ISP after a reset
6573*
6574* Input:
6575* ha = adapter block pointer.
6576*
6577* Returns:
6578* 0 = success
6579*/
6580static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006581qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006582{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08006583 int status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006584 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006585 struct req_que *req = ha->req_q_map[0];
6586 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07006587
6588 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006589 if (qla2x00_isp_firmware(vha)) {
6590 vha->flags.online = 0;
6591 status = ha->isp_ops->chip_diag(vha);
6592 if (!status)
6593 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006594 }
6595
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006596 if (!status && !(status = qla2x00_init_rings(vha))) {
6597 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07006598 ha->flags.chip_reset_done = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04006599
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006600 /* Initialize the queues in use */
6601 qla25xx_init_queues(ha);
6602
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006603 status = qla2x00_fw_ready(vha);
6604 if (!status) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006605 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006606 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Chad Dupuis7108b762014-04-11 16:54:45 -04006607 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006608 }
6609
6610 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006611 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006612 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006613 }
6614 return (status);
6615}
6616
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006617static int
6618qla25xx_init_queues(struct qla_hw_data *ha)
6619{
6620 struct rsp_que *rsp = NULL;
6621 struct req_que *req = NULL;
6622 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6623 int ret = -1;
6624 int i;
6625
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07006626 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006627 rsp = ha->rsp_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05006628 if (rsp && test_bit(i, ha->rsp_qid_map)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006629 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08006630 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006631 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006632 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6633 "%s Rsp que: %d init failed.\n",
6634 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006635 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006636 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6637 "%s Rsp que: %d inited.\n",
6638 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006639 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07006640 }
6641 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006642 req = ha->req_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05006643 if (req && test_bit(i, ha->req_qid_map)) {
6644 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006645 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08006646 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006647 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006648 ql_dbg(ql_dbg_init, base_vha, 0x0101,
6649 "%s Req que: %d init failed.\n",
6650 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006651 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006652 ql_dbg(ql_dbg_init, base_vha, 0x0102,
6653 "%s Req que: %d inited.\n",
6654 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006655 }
6656 }
6657 return ret;
6658}
6659
Linus Torvalds1da177e2005-04-16 15:20:36 -07006660/*
6661* qla2x00_reset_adapter
6662* Reset adapter.
6663*
6664* Input:
6665* ha = adapter block pointer.
6666*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07006667void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006668qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006669{
6670 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006671 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07006672 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006673
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006674 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006675 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006676
Linus Torvalds1da177e2005-04-16 15:20:36 -07006677 spin_lock_irqsave(&ha->hardware_lock, flags);
6678 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
6679 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
6680 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
6681 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
6682 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6683}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006684
6685void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006686qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006687{
6688 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006689 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006690 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
6691
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006692 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07006693 return;
6694
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006695 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006696 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006697
6698 spin_lock_irqsave(&ha->hardware_lock, flags);
6699 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
6700 RD_REG_DWORD(&reg->hccr);
6701 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
6702 RD_REG_DWORD(&reg->hccr);
6703 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08006704
6705 if (IS_NOPOLLING_TYPE(ha))
6706 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006707}
6708
David Miller4e08df32007-04-16 12:37:43 -07006709/* On sparc systems, obtain port and node WWN from firmware
6710 * properties.
6711 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006712static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
6713 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07006714{
6715#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006716 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07006717 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07006718 struct device_node *dp = pci_device_to_OF_node(pdev);
6719 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07006720 int len;
6721
6722 val = of_get_property(dp, "port-wwn", &len);
6723 if (val && len >= WWN_SIZE)
6724 memcpy(nv->port_name, val, WWN_SIZE);
6725
6726 val = of_get_property(dp, "node-wwn", &len);
6727 if (val && len >= WWN_SIZE)
6728 memcpy(nv->node_name, val, WWN_SIZE);
6729#endif
6730}
6731
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006732int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006733qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006734{
David Miller4e08df32007-04-16 12:37:43 -07006735 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006736 struct init_cb_24xx *icb;
6737 struct nvram_24xx *nv;
6738 uint32_t *dptr;
6739 uint8_t *dptr1, *dptr2;
6740 uint32_t chksum;
6741 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006742 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006743
David Miller4e08df32007-04-16 12:37:43 -07006744 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006745 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07006746 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006747
6748 /* Determine NVRAM starting address. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05006749 if (ha->port_no == 0) {
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07006750 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
6751 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
6752 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006753 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08006754 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
6755 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05006756
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07006757 ha->nvram_size = sizeof(struct nvram_24xx);
6758 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006759
Seokmann Ju281afe12007-07-26 13:43:34 -07006760 /* Get VPD data into cache */
6761 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006762 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07006763 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
6764
6765 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006766 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006767 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006768 ha->nvram_size);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006769 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
6770 chksum += le32_to_cpu(*dptr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006771
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006772 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
6773 "Contents of NVRAM\n");
6774 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
6775 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006776
6777 /* Bad NVRAM data, set defaults parameters. */
6778 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6779 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07006780 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006781 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006782 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04006783 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006784 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
6785 ql_log(ql_log_warn, vha, 0x006c,
6786 "Falling back to functioning (yet invalid -- WWPN) "
6787 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07006788
6789 /*
6790 * Set default initialization control block.
6791 */
6792 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07006793 nv->nvram_version = cpu_to_le16(ICB_VERSION);
6794 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04006795 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07006796 nv->execution_throttle = cpu_to_le16(0xFFFF);
6797 nv->exchange_count = cpu_to_le16(0);
6798 nv->hard_address = cpu_to_le16(124);
David Miller4e08df32007-04-16 12:37:43 -07006799 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006800 nv->port_name[1] = 0x00 + ha->port_no + 1;
David Miller4e08df32007-04-16 12:37:43 -07006801 nv->port_name[2] = 0x00;
6802 nv->port_name[3] = 0xe0;
6803 nv->port_name[4] = 0x8b;
6804 nv->port_name[5] = 0x1c;
6805 nv->port_name[6] = 0x55;
6806 nv->port_name[7] = 0x86;
6807 nv->node_name[0] = 0x20;
6808 nv->node_name[1] = 0x00;
6809 nv->node_name[2] = 0x00;
6810 nv->node_name[3] = 0xe0;
6811 nv->node_name[4] = 0x8b;
6812 nv->node_name[5] = 0x1c;
6813 nv->node_name[6] = 0x55;
6814 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006815 qla24xx_nvram_wwn_from_ofw(vha, nv);
Bart Van Asschead950362015-07-09 07:24:08 -07006816 nv->login_retry_count = cpu_to_le16(8);
6817 nv->interrupt_delay_timer = cpu_to_le16(0);
6818 nv->login_timeout = cpu_to_le16(0);
David Miller4e08df32007-04-16 12:37:43 -07006819 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07006820 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6821 nv->firmware_options_2 = cpu_to_le32(2 << 4);
6822 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6823 nv->firmware_options_3 = cpu_to_le32(2 << 13);
6824 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6825 nv->efi_parameters = cpu_to_le32(0);
David Miller4e08df32007-04-16 12:37:43 -07006826 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07006827 nv->max_luns_per_target = cpu_to_le16(128);
6828 nv->port_down_retry_count = cpu_to_le16(30);
6829 nv->link_down_timeout = cpu_to_le16(30);
David Miller4e08df32007-04-16 12:37:43 -07006830
6831 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006832 }
6833
Quinn Tran726b8542017-01-19 22:28:00 -08006834 if (qla_tgt_mode_enabled(vha)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006835 /* Don't enable full login after initial LIP */
Bart Van Asschead950362015-07-09 07:24:08 -07006836 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006837 /* Don't enable LIP full login for initiator */
Bart Van Asschead950362015-07-09 07:24:08 -07006838 nv->host_p &= cpu_to_le32(~BIT_10);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006839 }
6840
6841 qlt_24xx_config_nvram_stage1(vha, nv);
6842
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006843 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006844 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006845
6846 /* Copy 1st segment. */
6847 dptr1 = (uint8_t *)icb;
6848 dptr2 = (uint8_t *)&nv->version;
6849 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6850 while (cnt--)
6851 *dptr1++ = *dptr2++;
6852
6853 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07006854 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006855
6856 /* Copy 2nd segment. */
6857 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6858 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6859 cnt = (uint8_t *)&icb->reserved_3 -
6860 (uint8_t *)&icb->interrupt_delay_timer;
6861 while (cnt--)
6862 *dptr1++ = *dptr2++;
6863
6864 /*
6865 * Setup driver NVRAM options.
6866 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006867 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08006868 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006869
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006870 qlt_24xx_config_nvram_stage2(vha, icb);
6871
Bart Van Asschead950362015-07-09 07:24:08 -07006872 if (nv->host_p & cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006873 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07006874 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6875 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6876 }
6877
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006878 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07006879 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006880 /*
6881 * Firmware will apply the following mask if the nodename was
6882 * not provided.
6883 */
6884 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6885 icb->node_name[0] &= 0xF0;
6886 }
6887
6888 /* Set host adapter parameters. */
6889 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08006890 ha->flags.enable_lip_reset = 0;
6891 ha->flags.enable_lip_full_login =
6892 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6893 ha->flags.enable_target_reset =
6894 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006895 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07006896 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006897
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07006898 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6899 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006900
6901 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
6902 sizeof(ha->fw_seriallink_options24));
6903
6904 /* save HBA serial number */
6905 ha->serial0 = icb->port_name[5];
6906 ha->serial1 = icb->port_name[6];
6907 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006908 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6909 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006910
Bart Van Asschead950362015-07-09 07:24:08 -07006911 icb->execution_throttle = cpu_to_le16(0xFFFF);
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08006912
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006913 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6914
6915 /* Set minimum login_timeout to 4 seconds. */
6916 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6917 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6918 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07006919 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006920 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006921
Andrew Vasquez00a537b2008-02-28 14:06:11 -08006922 /* Set minimum RATOV to 100 tenths of a second. */
6923 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006924
6925 ha->loop_reset_delay = nv->reset_delay;
6926
6927 /* Link Down Timeout = 0:
6928 *
6929 * When Port Down timer expires we will start returning
6930 * I/O's to OS with "DID_NO_CONNECT".
6931 *
6932 * Link Down Timeout != 0:
6933 *
6934 * The driver waits for the link to come up after link down
6935 * before returning I/Os to OS with "DID_NO_CONNECT".
6936 */
6937 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6938 ha->loop_down_abort_time =
6939 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6940 } else {
6941 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6942 ha->loop_down_abort_time =
6943 (LOOP_DOWN_TIME - ha->link_down_timeout);
6944 }
6945
6946 /* Need enough time to try and get the port back. */
6947 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6948 if (qlport_down_retry)
6949 ha->port_down_retry_count = qlport_down_retry;
6950
6951 /* Set login_retry_count */
6952 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6953 if (ha->port_down_retry_count ==
6954 le16_to_cpu(nv->port_down_retry_count) &&
6955 ha->port_down_retry_count > 3)
6956 ha->login_retry_count = ha->port_down_retry_count;
6957 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6958 ha->login_retry_count = ha->port_down_retry_count;
6959 if (ql2xloginretrycount)
6960 ha->login_retry_count = ql2xloginretrycount;
6961
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006962 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006963 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006964 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6965 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6966 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6967 le16_to_cpu(icb->interrupt_delay_timer): 2;
6968 }
Bart Van Asschead950362015-07-09 07:24:08 -07006969 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006970 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006971 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006972 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08006973 ha->zio_mode = QLA_ZIO_MODE_6;
6974
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006975 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006976 "ZIO mode %d enabled; timer delay (%d us).\n",
6977 ha->zio_mode, ha->zio_timer * 100);
6978
6979 icb->firmware_options_2 |= cpu_to_le32(
6980 (uint32_t)ha->zio_mode);
6981 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006982 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006983 }
6984
David Miller4e08df32007-04-16 12:37:43 -07006985 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006986 ql_log(ql_log_warn, vha, 0x0070,
6987 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07006988 }
6989 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006990}
6991
Sawan Chandak4243c112016-01-27 12:03:31 -05006992uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
6993{
6994 struct qla27xx_image_status pri_image_status, sec_image_status;
6995 uint8_t valid_pri_image, valid_sec_image;
6996 uint32_t *wptr;
6997 uint32_t cnt, chksum, size;
6998 struct qla_hw_data *ha = vha->hw;
6999
7000 valid_pri_image = valid_sec_image = 1;
7001 ha->active_image = 0;
7002 size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
7003
7004 if (!ha->flt_region_img_status_pri) {
7005 valid_pri_image = 0;
7006 goto check_sec_image;
7007 }
7008
7009 qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
7010 ha->flt_region_img_status_pri, size);
7011
7012 if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
7013 ql_dbg(ql_dbg_init, vha, 0x018b,
7014 "Primary image signature (0x%x) not valid\n",
7015 pri_image_status.signature);
7016 valid_pri_image = 0;
7017 goto check_sec_image;
7018 }
7019
7020 wptr = (uint32_t *)(&pri_image_status);
7021 cnt = size;
7022
Joe Carnuccioda08ef52016-01-27 12:03:34 -05007023 for (chksum = 0; cnt--; wptr++)
7024 chksum += le32_to_cpu(*wptr);
Quinn Tran41dc5292017-01-19 22:28:03 -08007025
Sawan Chandak4243c112016-01-27 12:03:31 -05007026 if (chksum) {
7027 ql_dbg(ql_dbg_init, vha, 0x018c,
7028 "Checksum validation failed for primary image (0x%x)\n",
7029 chksum);
7030 valid_pri_image = 0;
7031 }
7032
7033check_sec_image:
7034 if (!ha->flt_region_img_status_sec) {
7035 valid_sec_image = 0;
7036 goto check_valid_image;
7037 }
7038
7039 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7040 ha->flt_region_img_status_sec, size);
7041
7042 if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
7043 ql_dbg(ql_dbg_init, vha, 0x018d,
7044 "Secondary image signature(0x%x) not valid\n",
7045 sec_image_status.signature);
7046 valid_sec_image = 0;
7047 goto check_valid_image;
7048 }
7049
7050 wptr = (uint32_t *)(&sec_image_status);
7051 cnt = size;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05007052 for (chksum = 0; cnt--; wptr++)
7053 chksum += le32_to_cpu(*wptr);
Sawan Chandak4243c112016-01-27 12:03:31 -05007054 if (chksum) {
7055 ql_dbg(ql_dbg_init, vha, 0x018e,
7056 "Checksum validation failed for secondary image (0x%x)\n",
7057 chksum);
7058 valid_sec_image = 0;
7059 }
7060
7061check_valid_image:
7062 if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
7063 ha->active_image = QLA27XX_PRIMARY_IMAGE;
7064 if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
7065 if (!ha->active_image ||
7066 pri_image_status.generation_number <
7067 sec_image_status.generation_number)
7068 ha->active_image = QLA27XX_SECONDARY_IMAGE;
7069 }
7070
7071 ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n",
7072 ha->active_image == 0 ? "default bootld and fw" :
7073 ha->active_image == 1 ? "primary" :
7074 ha->active_image == 2 ? "secondary" :
7075 "Invalid");
7076
7077 return ha->active_image;
7078}
7079
Adrian Bunk413975a2006-06-30 02:33:06 -07007080static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007081qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7082 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007083{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007084 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007085 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007086 uint32_t *dcode, dlen;
7087 uint32_t risc_addr;
7088 uint32_t risc_size;
7089 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007090 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007091 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007092
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007093 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08007094 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007095
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007096 rval = QLA_SUCCESS;
7097
7098 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007099 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007100 *srisc_addr = 0;
7101
Sawan Chandak4243c112016-01-27 12:03:31 -05007102 if (IS_QLA27XX(ha) &&
7103 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
7104 faddr = ha->flt_region_fw_sec;
7105
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007106 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007107 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007108 for (i = 0; i < 4; i++)
7109 dcode[i] = be32_to_cpu(dcode[i]);
7110 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
7111 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
7112 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
7113 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007114 ql_log(ql_log_fatal, vha, 0x008c,
7115 "Unable to verify the integrity of flash firmware "
7116 "image.\n");
7117 ql_log(ql_log_fatal, vha, 0x008d,
7118 "Firmware data: %08x %08x %08x %08x.\n",
7119 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007120
7121 return QLA_FUNCTION_FAILED;
7122 }
7123
7124 while (segments && rval == QLA_SUCCESS) {
7125 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007126 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007127
7128 risc_addr = be32_to_cpu(dcode[2]);
7129 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
7130 risc_size = be32_to_cpu(dcode[3]);
7131
7132 fragment = 0;
7133 while (risc_size > 0 && rval == QLA_SUCCESS) {
7134 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
7135 if (dlen > risc_size)
7136 dlen = risc_size;
7137
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007138 ql_dbg(ql_dbg_init, vha, 0x008e,
7139 "Loading risc segment@ risc addr %x "
7140 "number of dwords 0x%x offset 0x%x.\n",
7141 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007142
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007143 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007144 for (i = 0; i < dlen; i++)
7145 dcode[i] = swab32(dcode[i]);
7146
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007147 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007148 dlen);
7149 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007150 ql_log(ql_log_fatal, vha, 0x008f,
7151 "Failed to load segment %d of firmware.\n",
7152 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04007153 return QLA_FUNCTION_FAILED;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007154 }
7155
7156 faddr += dlen;
7157 risc_addr += dlen;
7158 risc_size -= dlen;
7159 fragment++;
7160 }
7161
7162 /* Next segment. */
7163 segments--;
7164 }
7165
Chad Dupuisf73cb692014-02-26 04:15:06 -05007166 if (!IS_QLA27XX(ha))
7167 return rval;
7168
7169 if (ha->fw_dump_template)
7170 vfree(ha->fw_dump_template);
7171 ha->fw_dump_template = NULL;
7172 ha->fw_dump_template_len = 0;
7173
7174 ql_dbg(ql_dbg_init, vha, 0x0161,
7175 "Loading fwdump template from %x\n", faddr);
7176 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7177 risc_size = be32_to_cpu(dcode[2]);
7178 ql_dbg(ql_dbg_init, vha, 0x0162,
7179 "-> array size %x dwords\n", risc_size);
7180 if (risc_size == 0 || risc_size == ~0)
7181 goto default_template;
7182
7183 dlen = (risc_size - 8) * sizeof(*dcode);
7184 ql_dbg(ql_dbg_init, vha, 0x0163,
7185 "-> template allocating %x bytes...\n", dlen);
7186 ha->fw_dump_template = vmalloc(dlen);
7187 if (!ha->fw_dump_template) {
7188 ql_log(ql_log_warn, vha, 0x0164,
7189 "Failed fwdump template allocate %x bytes.\n", risc_size);
7190 goto default_template;
7191 }
7192
7193 faddr += 7;
7194 risc_size -= 8;
7195 dcode = ha->fw_dump_template;
7196 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7197 for (i = 0; i < risc_size; i++)
7198 dcode[i] = le32_to_cpu(dcode[i]);
7199
7200 if (!qla27xx_fwdt_template_valid(dcode)) {
7201 ql_log(ql_log_warn, vha, 0x0165,
7202 "Failed fwdump template validate\n");
7203 goto default_template;
7204 }
7205
7206 dlen = qla27xx_fwdt_template_size(dcode);
7207 ql_dbg(ql_dbg_init, vha, 0x0166,
7208 "-> template size %x bytes\n", dlen);
7209 if (dlen > risc_size * sizeof(*dcode)) {
7210 ql_log(ql_log_warn, vha, 0x0167,
Himanshu Madhani4fae52b2017-06-06 13:55:23 -07007211 "Failed fwdump template exceeds array by %zx bytes\n",
Joe Carnuccio383a2982017-06-02 09:11:55 -07007212 (size_t)(dlen - risc_size * sizeof(*dcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05007213 goto default_template;
7214 }
7215 ha->fw_dump_template_len = dlen;
7216 return rval;
7217
7218default_template:
7219 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
7220 if (ha->fw_dump_template)
7221 vfree(ha->fw_dump_template);
7222 ha->fw_dump_template = NULL;
7223 ha->fw_dump_template_len = 0;
7224
7225 dlen = qla27xx_fwdt_template_default_size();
7226 ql_dbg(ql_dbg_init, vha, 0x0169,
7227 "-> template allocating %x bytes...\n", dlen);
7228 ha->fw_dump_template = vmalloc(dlen);
7229 if (!ha->fw_dump_template) {
7230 ql_log(ql_log_warn, vha, 0x016a,
7231 "Failed fwdump template allocate %x bytes.\n", risc_size);
7232 goto failed_template;
7233 }
7234
7235 dcode = ha->fw_dump_template;
7236 risc_size = dlen / sizeof(*dcode);
7237 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
7238 for (i = 0; i < risc_size; i++)
7239 dcode[i] = be32_to_cpu(dcode[i]);
7240
7241 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7242 ql_log(ql_log_warn, vha, 0x016b,
7243 "Failed fwdump template validate\n");
7244 goto failed_template;
7245 }
7246
7247 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7248 ql_dbg(ql_dbg_init, vha, 0x016c,
7249 "-> template size %x bytes\n", dlen);
7250 ha->fw_dump_template_len = dlen;
7251 return rval;
7252
7253failed_template:
7254 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
7255 if (ha->fw_dump_template)
7256 vfree(ha->fw_dump_template);
7257 ha->fw_dump_template = NULL;
7258 ha->fw_dump_template_len = 0;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007259 return rval;
7260}
7261
Giridhar Malavalie9454a82013-02-08 01:57:47 -05007262#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007263
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007264int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007265qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08007266{
7267 int rval;
7268 int i, fragment;
7269 uint16_t *wcode, *fwcode;
7270 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7271 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007272 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007273 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08007274
7275 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007276 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08007277 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007278 ql_log(ql_log_info, vha, 0x0083,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01007279 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007280 ql_log(ql_log_info, vha, 0x0084,
7281 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08007282 return QLA_FUNCTION_FAILED;
7283 }
7284
7285 rval = QLA_SUCCESS;
7286
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007287 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08007288 *srisc_addr = 0;
7289 fwcode = (uint16_t *)blob->fw->data;
7290 fwclen = 0;
7291
7292 /* Validate firmware image by checking version. */
7293 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007294 ql_log(ql_log_fatal, vha, 0x0085,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007295 "Unable to verify integrity of firmware image (%zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08007296 blob->fw->size);
7297 goto fail_fw_integrity;
7298 }
7299 for (i = 0; i < 4; i++)
7300 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7301 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7302 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7303 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007304 ql_log(ql_log_fatal, vha, 0x0086,
7305 "Unable to verify integrity of firmware image.\n");
7306 ql_log(ql_log_fatal, vha, 0x0087,
7307 "Firmware data: %04x %04x %04x %04x.\n",
7308 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08007309 goto fail_fw_integrity;
7310 }
7311
7312 seg = blob->segs;
7313 while (*seg && rval == QLA_SUCCESS) {
7314 risc_addr = *seg;
7315 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7316 risc_size = be16_to_cpu(fwcode[3]);
7317
7318 /* Validate firmware image size. */
7319 fwclen += risc_size * sizeof(uint16_t);
7320 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007321 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08007322 "Unable to verify integrity of firmware image "
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007323 "(%zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08007324 goto fail_fw_integrity;
7325 }
7326
7327 fragment = 0;
7328 while (risc_size > 0 && rval == QLA_SUCCESS) {
7329 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7330 if (wlen > risc_size)
7331 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007332 ql_dbg(ql_dbg_init, vha, 0x0089,
7333 "Loading risc segment@ risc addr %x number of "
7334 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08007335
7336 for (i = 0; i < wlen; i++)
7337 wcode[i] = swab16(fwcode[i]);
7338
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007339 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08007340 wlen);
7341 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007342 ql_log(ql_log_fatal, vha, 0x008a,
7343 "Failed to load segment %d of firmware.\n",
7344 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08007345 break;
7346 }
7347
7348 fwcode += wlen;
7349 risc_addr += wlen;
7350 risc_size -= wlen;
7351 fragment++;
7352 }
7353
7354 /* Next segment. */
7355 seg++;
7356 }
7357 return rval;
7358
7359fail_fw_integrity:
7360 return QLA_FUNCTION_FAILED;
7361}
7362
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007363static int
7364qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007365{
7366 int rval;
7367 int segments, fragment;
7368 uint32_t *dcode, dlen;
7369 uint32_t risc_addr;
7370 uint32_t risc_size;
7371 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08007372 struct fw_blob *blob;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007373 const uint32_t *fwcode;
7374 uint32_t fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007375 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007376 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007377
Andrew Vasquez54333832005-11-09 15:49:04 -08007378 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007379 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08007380 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007381 ql_log(ql_log_warn, vha, 0x0090,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01007382 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007383 ql_log(ql_log_warn, vha, 0x0091,
7384 "Firmware images can be retrieved from: "
7385 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007386
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007387 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007388 }
7389
Chad Dupuiscfb09192011-11-18 09:03:07 -08007390 ql_dbg(ql_dbg_init, vha, 0x0092,
7391 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007392
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007393 rval = QLA_SUCCESS;
7394
7395 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007396 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007397 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08007398 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007399 fwclen = 0;
7400
7401 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08007402 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007403 ql_log(ql_log_fatal, vha, 0x0093,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007404 "Unable to verify integrity of firmware image (%zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08007405 blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05007406 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007407 }
7408 for (i = 0; i < 4; i++)
7409 dcode[i] = be32_to_cpu(fwcode[i + 4]);
7410 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
7411 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
7412 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
7413 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007414 ql_log(ql_log_fatal, vha, 0x0094,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007415 "Unable to verify integrity of firmware image (%zd).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007416 blob->fw->size);
7417 ql_log(ql_log_fatal, vha, 0x0095,
7418 "Firmware data: %08x %08x %08x %08x.\n",
7419 dcode[0], dcode[1], dcode[2], dcode[3]);
Chad Dupuisf73cb692014-02-26 04:15:06 -05007420 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007421 }
7422
7423 while (segments && rval == QLA_SUCCESS) {
7424 risc_addr = be32_to_cpu(fwcode[2]);
7425 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
7426 risc_size = be32_to_cpu(fwcode[3]);
7427
7428 /* Validate firmware image size. */
7429 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08007430 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007431 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08007432 "Unable to verify integrity of firmware image "
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007433 "(%zd).\n", blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05007434 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007435 }
7436
7437 fragment = 0;
7438 while (risc_size > 0 && rval == QLA_SUCCESS) {
7439 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
7440 if (dlen > risc_size)
7441 dlen = risc_size;
7442
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007443 ql_dbg(ql_dbg_init, vha, 0x0097,
7444 "Loading risc segment@ risc addr %x "
7445 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007446
7447 for (i = 0; i < dlen; i++)
7448 dcode[i] = swab32(fwcode[i]);
7449
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007450 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08007451 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007452 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007453 ql_log(ql_log_fatal, vha, 0x0098,
7454 "Failed to load segment %d of firmware.\n",
7455 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04007456 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007457 }
7458
7459 fwcode += dlen;
7460 risc_addr += dlen;
7461 risc_size -= dlen;
7462 fragment++;
7463 }
7464
7465 /* Next segment. */
7466 segments--;
7467 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05007468
7469 if (!IS_QLA27XX(ha))
7470 return rval;
7471
7472 if (ha->fw_dump_template)
7473 vfree(ha->fw_dump_template);
7474 ha->fw_dump_template = NULL;
7475 ha->fw_dump_template_len = 0;
7476
7477 ql_dbg(ql_dbg_init, vha, 0x171,
Chad Dupuis97ea7022014-03-13 14:16:40 -04007478 "Loading fwdump template from %x\n",
7479 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
Chad Dupuisf73cb692014-02-26 04:15:06 -05007480 risc_size = be32_to_cpu(fwcode[2]);
7481 ql_dbg(ql_dbg_init, vha, 0x172,
7482 "-> array size %x dwords\n", risc_size);
7483 if (risc_size == 0 || risc_size == ~0)
7484 goto default_template;
7485
7486 dlen = (risc_size - 8) * sizeof(*fwcode);
7487 ql_dbg(ql_dbg_init, vha, 0x0173,
7488 "-> template allocating %x bytes...\n", dlen);
7489 ha->fw_dump_template = vmalloc(dlen);
7490 if (!ha->fw_dump_template) {
7491 ql_log(ql_log_warn, vha, 0x0174,
7492 "Failed fwdump template allocate %x bytes.\n", risc_size);
7493 goto default_template;
7494 }
7495
7496 fwcode += 7;
7497 risc_size -= 8;
7498 dcode = ha->fw_dump_template;
7499 for (i = 0; i < risc_size; i++)
7500 dcode[i] = le32_to_cpu(fwcode[i]);
7501
7502 if (!qla27xx_fwdt_template_valid(dcode)) {
7503 ql_log(ql_log_warn, vha, 0x0175,
7504 "Failed fwdump template validate\n");
7505 goto default_template;
7506 }
7507
7508 dlen = qla27xx_fwdt_template_size(dcode);
7509 ql_dbg(ql_dbg_init, vha, 0x0176,
7510 "-> template size %x bytes\n", dlen);
7511 if (dlen > risc_size * sizeof(*fwcode)) {
7512 ql_log(ql_log_warn, vha, 0x0177,
Himanshu Madhani4fae52b2017-06-06 13:55:23 -07007513 "Failed fwdump template exceeds array by %zx bytes\n",
Joe Carnuccio383a2982017-06-02 09:11:55 -07007514 (size_t)(dlen - risc_size * sizeof(*fwcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05007515 goto default_template;
7516 }
7517 ha->fw_dump_template_len = dlen;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007518 return rval;
7519
Chad Dupuisf73cb692014-02-26 04:15:06 -05007520default_template:
7521 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
7522 if (ha->fw_dump_template)
7523 vfree(ha->fw_dump_template);
7524 ha->fw_dump_template = NULL;
7525 ha->fw_dump_template_len = 0;
7526
7527 dlen = qla27xx_fwdt_template_default_size();
7528 ql_dbg(ql_dbg_init, vha, 0x0179,
7529 "-> template allocating %x bytes...\n", dlen);
7530 ha->fw_dump_template = vmalloc(dlen);
7531 if (!ha->fw_dump_template) {
7532 ql_log(ql_log_warn, vha, 0x017a,
7533 "Failed fwdump template allocate %x bytes.\n", risc_size);
7534 goto failed_template;
7535 }
7536
7537 dcode = ha->fw_dump_template;
7538 risc_size = dlen / sizeof(*fwcode);
7539 fwcode = qla27xx_fwdt_template_default();
7540 for (i = 0; i < risc_size; i++)
7541 dcode[i] = be32_to_cpu(fwcode[i]);
7542
7543 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7544 ql_log(ql_log_warn, vha, 0x017b,
7545 "Failed fwdump template validate\n");
7546 goto failed_template;
7547 }
7548
7549 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7550 ql_dbg(ql_dbg_init, vha, 0x017c,
7551 "-> template size %x bytes\n", dlen);
7552 ha->fw_dump_template_len = dlen;
7553 return rval;
7554
7555failed_template:
7556 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
7557 if (ha->fw_dump_template)
7558 vfree(ha->fw_dump_template);
7559 ha->fw_dump_template = NULL;
7560 ha->fw_dump_template_len = 0;
7561 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007562}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007563
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007564int
7565qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7566{
7567 int rval;
7568
Andrew Vasqueze337d902009-04-06 22:33:49 -07007569 if (ql2xfwloadbin == 1)
7570 return qla81xx_load_risc(vha, srisc_addr);
7571
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007572 /*
7573 * FW Load priority:
7574 * 1) Firmware via request-firmware interface (.bin file).
7575 * 2) Firmware residing in flash.
7576 */
7577 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7578 if (rval == QLA_SUCCESS)
7579 return rval;
7580
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007581 return qla24xx_load_risc_flash(vha, srisc_addr,
7582 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007583}
7584
7585int
7586qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7587{
7588 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007589 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007590
Andrew Vasqueze337d902009-04-06 22:33:49 -07007591 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007592 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07007593
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007594 /*
7595 * FW Load priority:
7596 * 1) Firmware residing in flash.
7597 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007598 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007599 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007600 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007601 if (rval == QLA_SUCCESS)
7602 return rval;
7603
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007604try_blob_fw:
7605 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7606 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
7607 return rval;
7608
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007609 ql_log(ql_log_info, vha, 0x0099,
7610 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007611 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
7612 if (rval != QLA_SUCCESS)
7613 return rval;
7614
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007615 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007616 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007617 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007618}
7619
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007620void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007621qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007622{
7623 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007624 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007625
Andrew Vasquez85880802009-12-15 21:29:46 -08007626 if (ha->flags.pci_channel_io_perm_failure)
7627 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07007628 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007629 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07007630 if (!ha->fw_major_version)
7631 return;
Quinn Tranec7193e2017-03-15 09:48:55 -07007632 if (!ha->flags.fw_started)
7633 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007634
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007635 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08007636 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07007637 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007638 ha->isp_ops->reset_chip(vha);
7639 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007640 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007641 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007642 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007643 ql_log(ql_log_info, vha, 0x8015,
7644 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007645 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007646 }
Quinn Tranec7193e2017-03-15 09:48:55 -07007647
Quinn Tran4b60c822017-06-13 20:47:21 -07007648 QLA_FW_STOPPED(ha);
Quinn Tranec7193e2017-03-15 09:48:55 -07007649 ha->flags.fw_init_done = 0;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007650}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007651
7652int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007653qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007654{
7655 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08007656 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007657 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007658 struct qla_hw_data *ha = vha->hw;
7659 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007660 struct req_que *req;
7661 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007662
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007663 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007664 return -EINVAL;
7665
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007666 rval = qla2x00_fw_ready(base_vha);
Michael Hernandezd7459522016-12-12 14:40:07 -08007667 if (vha->qpair)
7668 req = vha->qpair->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007669 else
Michael Hernandezd7459522016-12-12 14:40:07 -08007670 req = ha->req_q_map[0];
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007671 rsp = req->rsp;
7672
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007673 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007674 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007675 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007676 }
7677
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007678 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007679
7680 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08007681 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
7682 BIT_1);
7683 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
7684 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
7685 ql_dbg(ql_dbg_init, vha, 0x0120,
7686 "Failed SNS login: loop_id=%x, rval2=%d\n",
7687 NPH_SNS, rval2);
7688 else
7689 ql_dbg(ql_dbg_init, vha, 0x0103,
7690 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7691 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7692 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007693 return (QLA_FUNCTION_FAILED);
7694 }
7695
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007696 atomic_set(&vha->loop_down_timer, 0);
7697 atomic_set(&vha->loop_state, LOOP_UP);
7698 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7699 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
7700 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007701
7702 return rval;
7703}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007704
7705/* 84XX Support **************************************************************/
7706
7707static LIST_HEAD(qla_cs84xx_list);
7708static DEFINE_MUTEX(qla_cs84xx_mutex);
7709
7710static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007711qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007712{
7713 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007714 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007715
7716 mutex_lock(&qla_cs84xx_mutex);
7717
7718 /* Find any shared 84xx chip. */
7719 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
7720 if (cs84xx->bus == ha->pdev->bus) {
7721 kref_get(&cs84xx->kref);
7722 goto done;
7723 }
7724 }
7725
7726 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
7727 if (!cs84xx)
7728 goto done;
7729
7730 kref_init(&cs84xx->kref);
7731 spin_lock_init(&cs84xx->access_lock);
7732 mutex_init(&cs84xx->fw_update_mutex);
7733 cs84xx->bus = ha->pdev->bus;
7734
7735 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
7736done:
7737 mutex_unlock(&qla_cs84xx_mutex);
7738 return cs84xx;
7739}
7740
7741static void
7742__qla84xx_chip_release(struct kref *kref)
7743{
7744 struct qla_chip_state_84xx *cs84xx =
7745 container_of(kref, struct qla_chip_state_84xx, kref);
7746
7747 mutex_lock(&qla_cs84xx_mutex);
7748 list_del(&cs84xx->list);
7749 mutex_unlock(&qla_cs84xx_mutex);
7750 kfree(cs84xx);
7751}
7752
7753void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007754qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007755{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007756 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007757 if (ha->cs84xx)
7758 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
7759}
7760
7761static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007762qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007763{
7764 int rval;
7765 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007766 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007767
7768 mutex_lock(&ha->cs84xx->fw_update_mutex);
7769
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007770 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007771
7772 mutex_unlock(&ha->cs84xx->fw_update_mutex);
7773
7774 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
7775 QLA_SUCCESS;
7776}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007777
7778/* 81XX Support **************************************************************/
7779
7780int
7781qla81xx_nvram_config(scsi_qla_host_t *vha)
7782{
7783 int rval;
7784 struct init_cb_81xx *icb;
7785 struct nvram_81xx *nv;
7786 uint32_t *dptr;
7787 uint8_t *dptr1, *dptr2;
7788 uint32_t chksum;
7789 uint16_t cnt;
7790 struct qla_hw_data *ha = vha->hw;
7791
7792 rval = QLA_SUCCESS;
7793 icb = (struct init_cb_81xx *)ha->init_cb;
7794 nv = ha->nvram;
7795
7796 /* Determine NVRAM starting address. */
7797 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007798 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007799 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
7800 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007801
7802 /* Get VPD data into cache */
7803 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007804 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
7805 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007806
7807 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007808 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007809 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007810 dptr = (uint32_t *)nv;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05007811 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7812 chksum += le32_to_cpu(*dptr);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007813
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007814 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
7815 "Contents of NVRAM:\n");
7816 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
7817 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007818
7819 /* Bad NVRAM data, set defaults parameters. */
7820 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
7821 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07007822 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007823 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007824 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04007825 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007826 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007827 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007828 ql_log(ql_log_info, vha, 0x0074,
7829 "Falling back to functioning (yet invalid -- WWPN) "
7830 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007831
7832 /*
7833 * Set default initialization control block.
7834 */
7835 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07007836 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7837 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04007838 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07007839 nv->execution_throttle = cpu_to_le16(0xFFFF);
7840 nv->exchange_count = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007841 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007842 nv->port_name[1] = 0x00 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007843 nv->port_name[2] = 0x00;
7844 nv->port_name[3] = 0xe0;
7845 nv->port_name[4] = 0x8b;
7846 nv->port_name[5] = 0x1c;
7847 nv->port_name[6] = 0x55;
7848 nv->port_name[7] = 0x86;
7849 nv->node_name[0] = 0x20;
7850 nv->node_name[1] = 0x00;
7851 nv->node_name[2] = 0x00;
7852 nv->node_name[3] = 0xe0;
7853 nv->node_name[4] = 0x8b;
7854 nv->node_name[5] = 0x1c;
7855 nv->node_name[6] = 0x55;
7856 nv->node_name[7] = 0x86;
Bart Van Asschead950362015-07-09 07:24:08 -07007857 nv->login_retry_count = cpu_to_le16(8);
7858 nv->interrupt_delay_timer = cpu_to_le16(0);
7859 nv->login_timeout = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007860 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07007861 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7862 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7863 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7864 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7865 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7866 nv->efi_parameters = cpu_to_le32(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007867 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07007868 nv->max_luns_per_target = cpu_to_le16(128);
7869 nv->port_down_retry_count = cpu_to_le16(30);
7870 nv->link_down_timeout = cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07007871 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007872 nv->enode_mac[1] = 0xC0;
7873 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007874 nv->enode_mac[3] = 0x04;
7875 nv->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007876 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007877
7878 rval = 1;
7879 }
7880
Arun Easi9e522cd2012-08-22 14:21:31 -04007881 if (IS_T10_PI_CAPABLE(ha))
7882 nv->frame_payload_size &= ~7;
7883
Arun Easiaa230bc2013-01-30 03:34:39 -05007884 qlt_81xx_config_nvram_stage1(vha, nv);
7885
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007886 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07007887 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007888
7889 /* Copy 1st segment. */
7890 dptr1 = (uint8_t *)icb;
7891 dptr2 = (uint8_t *)&nv->version;
7892 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7893 while (cnt--)
7894 *dptr1++ = *dptr2++;
7895
7896 icb->login_retry_count = nv->login_retry_count;
7897
7898 /* Copy 2nd segment. */
7899 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7900 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7901 cnt = (uint8_t *)&icb->reserved_5 -
7902 (uint8_t *)&icb->interrupt_delay_timer;
7903 while (cnt--)
7904 *dptr1++ = *dptr2++;
7905
7906 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
7907 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
7908 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08007909 icb->enode_mac[0] = 0x00;
7910 icb->enode_mac[1] = 0xC0;
7911 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007912 icb->enode_mac[3] = 0x04;
7913 icb->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007914 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007915 }
7916
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07007917 /* Use extended-initialization control block. */
7918 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
7919
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007920 /*
7921 * Setup driver NVRAM options.
7922 */
7923 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07007924 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007925
Arun Easiaa230bc2013-01-30 03:34:39 -05007926 qlt_81xx_config_nvram_stage2(vha, icb);
7927
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007928 /* Use alternate WWN? */
Bart Van Asschead950362015-07-09 07:24:08 -07007929 if (nv->host_p & cpu_to_le32(BIT_15)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007930 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7931 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7932 }
7933
7934 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07007935 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007936 /*
7937 * Firmware will apply the following mask if the nodename was
7938 * not provided.
7939 */
7940 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7941 icb->node_name[0] &= 0xF0;
7942 }
7943
7944 /* Set host adapter parameters. */
7945 ha->flags.disable_risc_code_load = 0;
7946 ha->flags.enable_lip_reset = 0;
7947 ha->flags.enable_lip_full_login =
7948 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
7949 ha->flags.enable_target_reset =
7950 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
7951 ha->flags.enable_led_scheme = 0;
7952 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
7953
7954 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7955 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7956
7957 /* save HBA serial number */
7958 ha->serial0 = icb->port_name[5];
7959 ha->serial1 = icb->port_name[6];
7960 ha->serial2 = icb->port_name[7];
7961 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7962 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7963
Bart Van Asschead950362015-07-09 07:24:08 -07007964 icb->execution_throttle = cpu_to_le16(0xFFFF);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007965
7966 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7967
7968 /* Set minimum login_timeout to 4 seconds. */
7969 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7970 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7971 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07007972 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007973 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007974
7975 /* Set minimum RATOV to 100 tenths of a second. */
7976 ha->r_a_tov = 100;
7977
7978 ha->loop_reset_delay = nv->reset_delay;
7979
7980 /* Link Down Timeout = 0:
7981 *
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007982 * When Port Down timer expires we will start returning
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007983 * I/O's to OS with "DID_NO_CONNECT".
7984 *
7985 * Link Down Timeout != 0:
7986 *
7987 * The driver waits for the link to come up after link down
7988 * before returning I/Os to OS with "DID_NO_CONNECT".
7989 */
7990 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7991 ha->loop_down_abort_time =
7992 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7993 } else {
7994 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7995 ha->loop_down_abort_time =
7996 (LOOP_DOWN_TIME - ha->link_down_timeout);
7997 }
7998
7999 /* Need enough time to try and get the port back. */
8000 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8001 if (qlport_down_retry)
8002 ha->port_down_retry_count = qlport_down_retry;
8003
8004 /* Set login_retry_count */
8005 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8006 if (ha->port_down_retry_count ==
8007 le16_to_cpu(nv->port_down_retry_count) &&
8008 ha->port_down_retry_count > 3)
8009 ha->login_retry_count = ha->port_down_retry_count;
8010 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8011 ha->login_retry_count = ha->port_down_retry_count;
8012 if (ql2xloginretrycount)
8013 ha->login_retry_count = ql2xloginretrycount;
8014
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08008015 /* if not running MSI-X we need handshaking on interrupts */
Chad Dupuisf73cb692014-02-26 04:15:06 -05008016 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
Bart Van Asschead950362015-07-09 07:24:08 -07008017 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08008018
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08008019 /* Enable ZIO. */
8020 if (!vha->flags.init_done) {
8021 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8022 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8023 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8024 le16_to_cpu(icb->interrupt_delay_timer): 2;
8025 }
Bart Van Asschead950362015-07-09 07:24:08 -07008026 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08008027 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8028 vha->flags.process_response_queue = 0;
8029 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8030 ha->zio_mode = QLA_ZIO_MODE_6;
8031
Saurav Kashyap7c3df132011-07-14 12:00:13 -07008032 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08008033 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07008034 ha->zio_mode,
8035 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08008036
8037 icb->firmware_options_2 |= cpu_to_le32(
8038 (uint32_t)ha->zio_mode);
8039 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8040 vha->flags.process_response_queue = 1;
8041 }
8042
Quinn Tran41dc5292017-01-19 22:28:03 -08008043 /* enable RIDA Format2 */
8044 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))
8045 icb->firmware_options_3 |= BIT_0;
8046
Duane Grigsbyedd05de2017-10-13 09:34:06 -07008047 if (IS_QLA27XX(ha)) {
8048 icb->firmware_options_3 |= BIT_8;
8049 ql_dbg(ql_log_info, vha, 0x0075,
8050 "Enabling direct connection.\n");
8051 }
8052
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08008053 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07008054 ql_log(ql_log_warn, vha, 0x0076,
8055 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08008056 }
8057 return (rval);
8058}
8059
Giridhar Malavalia9083012010-04-12 17:59:55 -07008060int
8061qla82xx_restart_isp(scsi_qla_host_t *vha)
8062{
8063 int status, rval;
Giridhar Malavalia9083012010-04-12 17:59:55 -07008064 struct qla_hw_data *ha = vha->hw;
8065 struct req_que *req = ha->req_q_map[0];
8066 struct rsp_que *rsp = ha->rsp_q_map[0];
8067 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07008068 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07008069
8070 status = qla2x00_init_rings(vha);
8071 if (!status) {
8072 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8073 ha->flags.chip_reset_done = 1;
8074
8075 status = qla2x00_fw_ready(vha);
8076 if (!status) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07008077 /* Issue a marker after FW becomes ready. */
8078 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Giridhar Malavalia9083012010-04-12 17:59:55 -07008079 vha->flags.online = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04008080 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07008081 }
8082
8083 /* if no cable then assume it's good */
8084 if ((vha->device_flags & DFLG_NO_CABLE))
8085 status = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07008086 }
8087
8088 if (!status) {
8089 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8090
8091 if (!atomic_read(&vha->loop_down_timer)) {
8092 /*
8093 * Issue marker command only when we are going
8094 * to start the I/O .
8095 */
8096 vha->marker_needed = 1;
8097 }
8098
Giridhar Malavalia9083012010-04-12 17:59:55 -07008099 ha->isp_ops->enable_intrs(ha);
8100
8101 ha->isp_abort_cnt = 0;
8102 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8103
Saurav Kashyap53296782011-05-10 11:30:06 -07008104 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07008105 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07008106
Giridhar Malavalia9083012010-04-12 17:59:55 -07008107 if (ha->fce) {
8108 ha->flags.fce_enabled = 1;
8109 memset(ha->fce, 0,
8110 fce_calc_size(ha->fce_bufs));
8111 rval = qla2x00_enable_fce_trace(vha,
8112 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8113 &ha->fce_bufs);
8114 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08008115 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07008116 "Unable to reinitialize FCE (%d).\n",
8117 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07008118 ha->flags.fce_enabled = 0;
8119 }
8120 }
8121
8122 if (ha->eft) {
8123 memset(ha->eft, 0, EFT_SIZE);
8124 rval = qla2x00_enable_eft_trace(vha,
8125 ha->eft_dma, EFT_NUM_BUFFERS);
8126 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08008127 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07008128 "Unable to reinitialize EFT (%d).\n",
8129 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07008130 }
8131 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07008132 }
8133
8134 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08008135 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07008136 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07008137
8138 spin_lock_irqsave(&ha->vport_slock, flags);
8139 list_for_each_entry(vp, &ha->vp_list, list) {
8140 if (vp->vp_idx) {
8141 atomic_inc(&vp->vref_count);
8142 spin_unlock_irqrestore(&ha->vport_slock, flags);
8143
Giridhar Malavalia9083012010-04-12 17:59:55 -07008144 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07008145
8146 spin_lock_irqsave(&ha->vport_slock, flags);
8147 atomic_dec(&vp->vref_count);
8148 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07008149 }
Arun Easifeafb7b2010-09-03 14:57:00 -07008150 spin_unlock_irqrestore(&ha->vport_slock, flags);
8151
Giridhar Malavalia9083012010-04-12 17:59:55 -07008152 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08008153 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07008154 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07008155 }
8156
8157 return status;
8158}
8159
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08008160void
Andrew Vasquezae97c912010-02-18 10:07:28 -08008161qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08008162{
Andrew Vasquezae97c912010-02-18 10:07:28 -08008163 struct qla_hw_data *ha = vha->hw;
8164
Himanshu Madhanif198caf2016-01-27 12:03:30 -05008165 /* Hold status IOCBs until ABTS response received. */
8166 if (ql2xfwholdabts)
8167 ha->fw_options[3] |= BIT_12;
8168
Giridhar Malavali088d09d2016-07-06 11:14:20 -04008169 /* Set Retry FLOGI in case of P2P connection */
8170 if (ha->operating_mode == P2P) {
8171 ha->fw_options[2] |= BIT_3;
8172 ql_dbg(ql_dbg_disc, vha, 0x2103,
8173 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8174 __func__, ha->fw_options[2]);
8175 }
8176
Quinn Tran41dc5292017-01-19 22:28:03 -08008177 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8178 if (ql2xmvasynctoatio) {
8179 if (qla_tgt_mode_enabled(vha) ||
8180 qla_dual_mode_enabled(vha))
8181 ha->fw_options[2] |= BIT_11;
8182 else
8183 ha->fw_options[2] &= ~BIT_11;
8184 }
Andrew Vasquezae97c912010-02-18 10:07:28 -08008185
Quinn Tranf7e761f2017-06-02 09:12:02 -07008186 if (qla_tgt_mode_enabled(vha) ||
Quinn Tran2da52732017-06-02 09:12:05 -07008187 qla_dual_mode_enabled(vha)) {
8188 /* FW auto send SCSI status during */
8189 ha->fw_options[1] |= BIT_8;
8190 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
8191
8192 /* FW perform Exchange validation */
Quinn Tranf7e761f2017-06-02 09:12:02 -07008193 ha->fw_options[2] |= BIT_4;
Quinn Tran2da52732017-06-02 09:12:05 -07008194 } else {
8195 ha->fw_options[1] &= ~BIT_8;
8196 ha->fw_options[10] &= 0x00ff;
8197
Quinn Tranf7e761f2017-06-02 09:12:02 -07008198 ha->fw_options[2] &= ~BIT_4;
Quinn Tran2da52732017-06-02 09:12:05 -07008199 }
Quinn Tranf7e761f2017-06-02 09:12:02 -07008200
Quinn Tran41dc5292017-01-19 22:28:03 -08008201 if (ql2xetsenable) {
8202 /* Enable ETS Burst. */
8203 memset(ha->fw_options, 0, sizeof(ha->fw_options));
8204 ha->fw_options[2] |= BIT_9;
8205 }
8206
Quinn Tran83548fe2017-06-02 09:12:01 -07008207 ql_dbg(ql_dbg_init, vha, 0x00e9,
8208 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8209 __func__, ha->fw_options[1], ha->fw_options[2],
8210 ha->fw_options[3], vha->host->active_mode);
Quinn Tran41dc5292017-01-19 22:28:03 -08008211
Andrew Vasquezae97c912010-02-18 10:07:28 -08008212 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08008213}
Sarang Radke09ff7012010-03-19 17:03:59 -07008214
8215/*
8216 * qla24xx_get_fcp_prio
8217 * Gets the fcp cmd priority value for the logged in port.
8218 * Looks for a match of the port descriptors within
8219 * each of the fcp prio config entries. If a match is found,
8220 * the tag (priority) value is returned.
8221 *
8222 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008223 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07008224 * fcport = port structure pointer.
8225 *
8226 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07008227 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008228 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07008229 *
8230 * Context:
8231 * Kernel context
8232 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008233static int
Sarang Radke09ff7012010-03-19 17:03:59 -07008234qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8235{
8236 int i, entries;
8237 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008238 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07008239 uint32_t pid1, pid2;
8240 uint64_t wwn1, wwn2;
8241 struct qla_fcp_prio_entry *pri_entry;
8242 struct qla_hw_data *ha = vha->hw;
8243
8244 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008245 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07008246
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008247 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07008248 entries = ha->fcp_prio_cfg->num_entries;
8249 pri_entry = &ha->fcp_prio_cfg->entry[0];
8250
8251 for (i = 0; i < entries; i++) {
8252 pid_match = wwn_match = 0;
8253
8254 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8255 pri_entry++;
8256 continue;
8257 }
8258
8259 /* check source pid for a match */
8260 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8261 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8262 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8263 if (pid1 == INVALID_PORT_ID)
8264 pid_match++;
8265 else if (pid1 == pid2)
8266 pid_match++;
8267 }
8268
8269 /* check destination pid for a match */
8270 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8271 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8272 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8273 if (pid1 == INVALID_PORT_ID)
8274 pid_match++;
8275 else if (pid1 == pid2)
8276 pid_match++;
8277 }
8278
8279 /* check source WWN for a match */
8280 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8281 wwn1 = wwn_to_u64(vha->port_name);
8282 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8283 if (wwn2 == (uint64_t)-1)
8284 wwn_match++;
8285 else if (wwn1 == wwn2)
8286 wwn_match++;
8287 }
8288
8289 /* check destination WWN for a match */
8290 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8291 wwn1 = wwn_to_u64(fcport->port_name);
8292 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8293 if (wwn2 == (uint64_t)-1)
8294 wwn_match++;
8295 else if (wwn1 == wwn2)
8296 wwn_match++;
8297 }
8298
8299 if (pid_match == 2 || wwn_match == 2) {
8300 /* Found a matching entry */
8301 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8302 priority = pri_entry->tag;
8303 break;
8304 }
8305
8306 pri_entry++;
8307 }
8308
8309 return priority;
8310}
8311
8312/*
8313 * qla24xx_update_fcport_fcp_prio
8314 * Activates fcp priority for the logged in fc port
8315 *
8316 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008317 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07008318 * fcp = port structure pointer.
8319 *
8320 * Return:
8321 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8322 *
8323 * Context:
8324 * Kernel context.
8325 */
8326int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008327qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07008328{
8329 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008330 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07008331 uint16_t mb[5];
8332
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008333 if (fcport->port_type != FCT_TARGET ||
8334 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07008335 return QLA_FUNCTION_FAILED;
8336
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008337 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008338 if (priority < 0)
8339 return QLA_FUNCTION_FAILED;
8340
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04008341 if (IS_P3P_TYPE(vha->hw)) {
Saurav Kashyapa00f6292011-11-18 09:03:19 -08008342 fcport->fcp_prio = priority & 0xf;
8343 return QLA_SUCCESS;
8344 }
8345
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008346 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08008347 if (ret == QLA_SUCCESS) {
8348 if (fcport->fcp_prio != priority)
8349 ql_dbg(ql_dbg_user, vha, 0x709e,
8350 "Updated FCP_CMND priority - value=%d loop_id=%d "
8351 "port_id=%02x%02x%02x.\n", priority,
8352 fcport->loop_id, fcport->d_id.b.domain,
8353 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08008354 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08008355 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07008356 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08008357 "Unable to update FCP_CMND priority - ret=0x%x for "
8358 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8359 fcport->d_id.b.domain, fcport->d_id.b.area,
8360 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07008361 return ret;
8362}
8363
8364/*
8365 * qla24xx_update_all_fcp_prio
8366 * Activates fcp priority for all the logged in ports
8367 *
8368 * Input:
8369 * ha = adapter block pointer.
8370 *
8371 * Return:
8372 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8373 *
8374 * Context:
8375 * Kernel context.
8376 */
8377int
8378qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8379{
8380 int ret;
8381 fc_port_t *fcport;
8382
8383 ret = QLA_FUNCTION_FAILED;
8384 /* We need to set priority for all logged in ports */
8385 list_for_each_entry(fcport, &vha->vp_fcports, list)
8386 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8387
8388 return ret;
8389}
Michael Hernandezd7459522016-12-12 14:40:07 -08008390
Quinn Tran82de8022017-06-13 20:47:17 -07008391struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8392 int vp_idx, bool startqp)
Michael Hernandezd7459522016-12-12 14:40:07 -08008393{
8394 int rsp_id = 0;
8395 int req_id = 0;
8396 int i;
8397 struct qla_hw_data *ha = vha->hw;
8398 uint16_t qpair_id = 0;
8399 struct qla_qpair *qpair = NULL;
8400 struct qla_msix_entry *msix;
8401
8402 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8403 ql_log(ql_log_warn, vha, 0x00181,
8404 "FW/Driver is not multi-queue capable.\n");
8405 return NULL;
8406 }
8407
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07008408 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08008409 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8410 if (qpair == NULL) {
8411 ql_log(ql_log_warn, vha, 0x0182,
8412 "Failed to allocate memory for queue pair.\n");
8413 return NULL;
8414 }
8415 memset(qpair, 0, sizeof(struct qla_qpair));
8416
8417 qpair->hw = vha->hw;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08008418 qpair->vha = vha;
Quinn Tran82de8022017-06-13 20:47:17 -07008419 qpair->qp_lock_ptr = &qpair->qp_lock;
8420 spin_lock_init(&qpair->qp_lock);
Quinn Tranaf7bb382017-06-13 20:47:23 -07008421 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
Michael Hernandezd7459522016-12-12 14:40:07 -08008422
8423 /* Assign available que pair id */
8424 mutex_lock(&ha->mq_lock);
8425 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
Sawan Chandakb95b9452017-05-24 18:06:20 -07008426 if (ha->num_qpairs >= ha->max_qpairs) {
Michael Hernandezd7459522016-12-12 14:40:07 -08008427 mutex_unlock(&ha->mq_lock);
8428 ql_log(ql_log_warn, vha, 0x0183,
8429 "No resources to create additional q pair.\n");
8430 goto fail_qid_map;
8431 }
Sawan Chandakb95b9452017-05-24 18:06:20 -07008432 ha->num_qpairs++;
Michael Hernandezd7459522016-12-12 14:40:07 -08008433 set_bit(qpair_id, ha->qpair_qid_map);
8434 ha->queue_pair_map[qpair_id] = qpair;
8435 qpair->id = qpair_id;
8436 qpair->vp_idx = vp_idx;
himanshu.madhani@cavium.come6373f332017-08-23 15:04:57 -07008437 qpair->fw_started = ha->flags.fw_started;
Quinn Trane326d222017-06-13 20:47:18 -07008438 INIT_LIST_HEAD(&qpair->hints_list);
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07008439 qpair->chip_reset = ha->base_qpair->chip_reset;
8440 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8441 qpair->enable_explicit_conf =
8442 ha->base_qpair->enable_explicit_conf;
Michael Hernandezd7459522016-12-12 14:40:07 -08008443
8444 for (i = 0; i < ha->msix_count; i++) {
Quinn Tran093df732016-12-12 14:40:09 -08008445 msix = &ha->msix_entries[i];
Michael Hernandezd7459522016-12-12 14:40:07 -08008446 if (msix->in_use)
8447 continue;
8448 qpair->msix = msix;
Quinn Tran83548fe2017-06-02 09:12:01 -07008449 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
Michael Hernandezd7459522016-12-12 14:40:07 -08008450 "Vector %x selected for qpair\n", msix->vector);
8451 break;
8452 }
8453 if (!qpair->msix) {
8454 ql_log(ql_log_warn, vha, 0x0184,
8455 "Out of MSI-X vectors!.\n");
8456 goto fail_msix;
8457 }
8458
8459 qpair->msix->in_use = 1;
8460 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
Quinn Tran8abfa9e2017-06-13 20:47:24 -07008461 qpair->pdev = ha->pdev;
8462 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
8463 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
Michael Hernandezd7459522016-12-12 14:40:07 -08008464
8465 mutex_unlock(&ha->mq_lock);
8466
8467 /* Create response queue first */
Quinn Tran82de8022017-06-13 20:47:17 -07008468 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
Michael Hernandezd7459522016-12-12 14:40:07 -08008469 if (!rsp_id) {
8470 ql_log(ql_log_warn, vha, 0x0185,
8471 "Failed to create response queue.\n");
8472 goto fail_rsp;
8473 }
8474
8475 qpair->rsp = ha->rsp_q_map[rsp_id];
8476
8477 /* Create request queue */
Quinn Tran82de8022017-06-13 20:47:17 -07008478 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
8479 startqp);
Michael Hernandezd7459522016-12-12 14:40:07 -08008480 if (!req_id) {
8481 ql_log(ql_log_warn, vha, 0x0186,
8482 "Failed to create request queue.\n");
8483 goto fail_req;
8484 }
8485
8486 qpair->req = ha->req_q_map[req_id];
8487 qpair->rsp->req = qpair->req;
Quinn Tran82de8022017-06-13 20:47:17 -07008488 qpair->rsp->qpair = qpair;
Quinn Trane326d222017-06-13 20:47:18 -07008489 /* init qpair to this cpu. Will adjust at run time. */
8490 qla_cpu_update(qpair, smp_processor_id());
Michael Hernandezd7459522016-12-12 14:40:07 -08008491
8492 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
8493 if (ha->fw_attributes & BIT_4)
8494 qpair->difdix_supported = 1;
8495 }
8496
8497 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
8498 if (!qpair->srb_mempool) {
Quinn Tran83548fe2017-06-02 09:12:01 -07008499 ql_log(ql_log_warn, vha, 0xd036,
Michael Hernandezd7459522016-12-12 14:40:07 -08008500 "Failed to create srb mempool for qpair %d\n",
8501 qpair->id);
8502 goto fail_mempool;
8503 }
8504
8505 /* Mark as online */
8506 qpair->online = 1;
8507
8508 if (!vha->flags.qpairs_available)
8509 vha->flags.qpairs_available = 1;
8510
8511 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
8512 "Request/Response queue pair created, id %d\n",
8513 qpair->id);
8514 ql_dbg(ql_dbg_init, vha, 0x0187,
8515 "Request/Response queue pair created, id %d\n",
8516 qpair->id);
8517 }
8518 return qpair;
8519
8520fail_mempool:
8521fail_req:
8522 qla25xx_delete_rsp_que(vha, qpair->rsp);
8523fail_rsp:
8524 mutex_lock(&ha->mq_lock);
8525 qpair->msix->in_use = 0;
8526 list_del(&qpair->qp_list_elem);
8527 if (list_empty(&vha->qp_list))
8528 vha->flags.qpairs_available = 0;
8529fail_msix:
8530 ha->queue_pair_map[qpair_id] = NULL;
8531 clear_bit(qpair_id, ha->qpair_qid_map);
Sawan Chandakb95b9452017-05-24 18:06:20 -07008532 ha->num_qpairs--;
Michael Hernandezd7459522016-12-12 14:40:07 -08008533 mutex_unlock(&ha->mq_lock);
8534fail_qid_map:
8535 kfree(qpair);
8536 return NULL;
8537}
8538
8539int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
8540{
Sawan Chandakd65237c2017-06-13 20:47:19 -07008541 int ret = QLA_FUNCTION_FAILED;
Michael Hernandezd7459522016-12-12 14:40:07 -08008542 struct qla_hw_data *ha = qpair->hw;
8543
8544 qpair->delete_in_progress = 1;
8545 while (atomic_read(&qpair->ref_count))
8546 msleep(500);
8547
8548 ret = qla25xx_delete_req_que(vha, qpair->req);
8549 if (ret != QLA_SUCCESS)
8550 goto fail;
himanshu.madhani@cavium.com7867b982017-12-04 14:45:16 -08008551
Michael Hernandezd7459522016-12-12 14:40:07 -08008552 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
8553 if (ret != QLA_SUCCESS)
8554 goto fail;
8555
8556 mutex_lock(&ha->mq_lock);
8557 ha->queue_pair_map[qpair->id] = NULL;
8558 clear_bit(qpair->id, ha->qpair_qid_map);
Sawan Chandakb95b9452017-05-24 18:06:20 -07008559 ha->num_qpairs--;
Michael Hernandezd7459522016-12-12 14:40:07 -08008560 list_del(&qpair->qp_list_elem);
Sawan Chandakd65237c2017-06-13 20:47:19 -07008561 if (list_empty(&vha->qp_list)) {
Michael Hernandezd7459522016-12-12 14:40:07 -08008562 vha->flags.qpairs_available = 0;
Sawan Chandakd65237c2017-06-13 20:47:19 -07008563 vha->flags.qpairs_req_created = 0;
8564 vha->flags.qpairs_rsp_created = 0;
8565 }
Michael Hernandezd7459522016-12-12 14:40:07 -08008566 mempool_destroy(qpair->srb_mempool);
8567 kfree(qpair);
8568 mutex_unlock(&ha->mq_lock);
8569
8570 return QLA_SUCCESS;
8571fail:
8572 return ret;
8573}