blob: 2f246996d3e27d94f26d298ac8da5367dd141578 [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 *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070044
Andrew Vasquezac280b62009-08-20 11:06:05 -070045/* SRB Extensions ---------------------------------------------------------- */
46
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080047void
Kees Cook8e5f4ba2017-09-03 13:23:32 -070048qla2x00_sp_timeout(struct timer_list *t)
Andrew Vasquezac280b62009-08-20 11:06:05 -070049{
Kees Cook8e5f4ba2017-09-03 13:23:32 -070050 srb_t *sp = from_timer(sp, t, u.iocb_cmd.timer);
Madhuranath Iyengar49163922010-05-04 15:01:28 -070051 struct srb_iocb *iocb;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080052 scsi_qla_host_t *vha = sp->vha;
Andrew Vasquezac280b62009-08-20 11:06:05 -070053 struct req_que *req;
54 unsigned long flags;
55
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080056 spin_lock_irqsave(&vha->hw->hardware_lock, flags);
57 req = vha->hw->req_q_map[0];
Andrew Vasquezac280b62009-08-20 11:06:05 -070058 req->outstanding_cmds[sp->handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080059 iocb = &sp->u.iocb_cmd;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070060 iocb->timeout(sp);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080061 sp->free(sp);
62 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;
103 struct event_arg ea;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700104
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700105 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
Quinn Tran726b8542017-01-19 22:28:00 -0800106 "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
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700109 fcport->flags &= ~FCF_ASYNC_SENT;
Quinn Tran726b8542017-01-19 22:28:00 -0800110
111 switch (sp->type) {
112 case SRB_LOGIN_CMD:
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700113 /* Retry as needed. */
114 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
115 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
116 QLA_LOGIO_LOGIN_RETRIED : 0;
Quinn Tran726b8542017-01-19 22:28:00 -0800117 memset(&ea, 0, sizeof(ea));
118 ea.event = FCME_PLOGI_DONE;
119 ea.fcport = sp->fcport;
120 ea.data[0] = lio->u.logio.data[0];
121 ea.data[1] = lio->u.logio.data[1];
122 ea.sp = sp;
123 qla24xx_handle_plogi_done_event(fcport->vha, &ea);
124 break;
125 case SRB_LOGOUT_CMD:
Alexei Potashnika6ca8872015-07-14 16:00:44 -0400126 qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT);
Quinn Tran726b8542017-01-19 22:28:00 -0800127 break;
128 case SRB_CT_PTHRU_CMD:
129 case SRB_MB_IOCB:
130 case SRB_NACK_PLOGI:
131 case SRB_NACK_PRLI:
132 case SRB_NACK_LOGO:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800133 sp->done(sp, QLA_FUNCTION_TIMEOUT);
Quinn Tran726b8542017-01-19 22:28:00 -0800134 break;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700135 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700136}
137
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700138static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800139qla2x00_async_login_sp_done(void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700140{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800141 srb_t *sp = ptr;
142 struct scsi_qla_host *vha = sp->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800143 struct srb_iocb *lio = &sp->u.iocb_cmd;
Quinn Tran726b8542017-01-19 22:28:00 -0800144 struct event_arg ea;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700145
Quinn Tran83548fe2017-06-02 09:12:01 -0700146 ql_dbg(ql_dbg_disc, vha, 0x20dd,
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800147 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
Quinn Tran726b8542017-01-19 22:28:00 -0800148
149 sp->fcport->flags &= ~FCF_ASYNC_SENT;
150 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
151 memset(&ea, 0, sizeof(ea));
152 ea.event = FCME_PLOGI_DONE;
153 ea.fcport = sp->fcport;
154 ea.data[0] = lio->u.logio.data[0];
155 ea.data[1] = lio->u.logio.data[1];
156 ea.iop[0] = lio->u.logio.iop[0];
157 ea.iop[1] = lio->u.logio.iop[1];
158 ea.sp = sp;
159 qla2x00_fcport_event_handler(vha, &ea);
160 }
161
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800162 sp->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700163}
164
Andrew Vasquezac280b62009-08-20 11:06:05 -0700165int
166qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
167 uint16_t *data)
168{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700169 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700170 struct srb_iocb *lio;
Quinn Tran726b8542017-01-19 22:28:00 -0800171 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700172
Quinn Tran726b8542017-01-19 22:28:00 -0800173 if (!vha->flags.online)
174 goto done;
175
176 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
177 (fcport->fw_login_state == DSC_LS_PLOGI_COMP) ||
178 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
179 goto done;
180
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800181 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700182 if (!sp)
183 goto done;
184
Quinn Tran726b8542017-01-19 22:28:00 -0800185 fcport->flags |= FCF_ASYNC_SENT;
186 fcport->logout_completed = 0;
187
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800188 sp->type = SRB_LOGIN_CMD;
189 sp->name = "login";
190 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
191
192 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700193 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800194 sp->done = qla2x00_async_login_sp_done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700195 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700196
197 if (fcport->fc4f_nvme)
198 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
199
Andrew Vasquezac280b62009-08-20 11:06:05 -0700200 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700201 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700202 rval = qla2x00_start_sp(sp);
Chad Dupuis080c9512016-01-27 12:03:37 -0500203 if (rval != QLA_SUCCESS) {
204 fcport->flags &= ~FCF_ASYNC_SENT;
205 fcport->flags |= FCF_LOGIN_NEEDED;
206 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700207 goto done_free_sp;
Chad Dupuis080c9512016-01-27 12:03:37 -0500208 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700209
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700210 ql_dbg(ql_dbg_disc, vha, 0x2072,
Quinn Tran726b8542017-01-19 22:28:00 -0800211 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
212 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800213 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
214 fcport->login_retry);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700215 return rval;
216
217done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800218 sp->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700219done:
Quinn Tran726b8542017-01-19 22:28:00 -0800220 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700221 return rval;
222}
223
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700224static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800225qla2x00_async_logout_sp_done(void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700226{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800227 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800228 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700229
Quinn Tran726b8542017-01-19 22:28:00 -0800230 sp->fcport->flags &= ~FCF_ASYNC_SENT;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800231 if (!test_bit(UNLOADING, &sp->vha->dpc_flags))
232 qla2x00_post_async_logout_done_work(sp->vha, sp->fcport,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800233 lio->u.logio.data);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800234 sp->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700235}
236
Andrew Vasquezac280b62009-08-20 11:06:05 -0700237int
238qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
239{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700240 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700241 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700242 int rval;
243
244 rval = QLA_FUNCTION_FAILED;
Quinn Tran726b8542017-01-19 22:28:00 -0800245 fcport->flags |= FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800246 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700247 if (!sp)
248 goto done;
249
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800250 sp->type = SRB_LOGOUT_CMD;
251 sp->name = "logout";
252 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
253
254 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700255 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800256 sp->done = qla2x00_async_logout_sp_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700257 rval = qla2x00_start_sp(sp);
258 if (rval != QLA_SUCCESS)
259 goto done_free_sp;
260
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700261 ql_dbg(ql_dbg_disc, vha, 0x2070,
Quinn Tran726b8542017-01-19 22:28:00 -0800262 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -0800263 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
Quinn Tran726b8542017-01-19 22:28:00 -0800264 fcport->d_id.b.area, fcport->d_id.b.al_pa,
265 fcport->port_name);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700266 return rval;
267
268done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800269 sp->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700270done:
Quinn Tran726b8542017-01-19 22:28:00 -0800271 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700272 return rval;
273}
274
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700275static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800276qla2x00_async_adisc_sp_done(void *ptr, int res)
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700277{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800278 srb_t *sp = ptr;
279 struct scsi_qla_host *vha = sp->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800280 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700281
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800282 if (!test_bit(UNLOADING, &vha->dpc_flags))
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800283 qla2x00_post_async_adisc_done_work(sp->vha, sp->fcport,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800284 lio->u.logio.data);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800285 sp->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700286}
287
288int
289qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
290 uint16_t *data)
291{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700292 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700293 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700294 int rval;
295
296 rval = QLA_FUNCTION_FAILED;
Quinn Tran726b8542017-01-19 22:28:00 -0800297 fcport->flags |= FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800298 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700299 if (!sp)
300 goto done;
301
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800302 sp->type = SRB_ADISC_CMD;
303 sp->name = "adisc";
304 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
305
306 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700307 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800308 sp->done = qla2x00_async_adisc_sp_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700309 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700310 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700311 rval = qla2x00_start_sp(sp);
312 if (rval != QLA_SUCCESS)
313 goto done_free_sp;
314
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700315 ql_dbg(ql_dbg_disc, vha, 0x206f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800316 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
317 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
318 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700319 return rval;
320
321done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800322 sp->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700323done:
Quinn Tran726b8542017-01-19 22:28:00 -0800324 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700325 return rval;
326}
327
Quinn Tran726b8542017-01-19 22:28:00 -0800328static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
329 struct event_arg *ea)
330{
331 fc_port_t *fcport, *conflict_fcport;
332 struct get_name_list_extended *e;
333 u16 i, n, found = 0, loop_id;
334 port_id_t id;
335 u64 wwn;
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700336 u8 opt = 0, current_login_state;
Quinn Tran726b8542017-01-19 22:28:00 -0800337
338 fcport = ea->fcport;
339
340 if (ea->rc) { /* rval */
341 if (fcport->login_retry == 0) {
342 fcport->login_retry = vha->hw->login_retry_count;
Quinn Tran83548fe2017-06-02 09:12:01 -0700343 ql_dbg(ql_dbg_disc, vha, 0x20de,
344 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
345 fcport->port_name, fcport->login_retry);
Quinn Tran726b8542017-01-19 22:28:00 -0800346 }
347 return;
348 }
349
350 if (fcport->last_rscn_gen != fcport->rscn_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700351 ql_dbg(ql_dbg_disc, vha, 0x20df,
Quinn Tran726b8542017-01-19 22:28:00 -0800352 "%s %8phC rscn gen changed rscn %d|%d \n",
353 __func__, fcport->port_name,
354 fcport->last_rscn_gen, fcport->rscn_gen);
355 qla24xx_post_gidpn_work(vha, fcport);
356 return;
357 } else if (fcport->last_login_gen != fcport->login_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700358 ql_dbg(ql_dbg_disc, vha, 0x20e0,
359 "%s %8phC login gen changed login %d|%d\n",
360 __func__, fcport->port_name,
361 fcport->last_login_gen, fcport->login_gen);
Quinn Tran726b8542017-01-19 22:28:00 -0800362 return;
363 }
364
365 n = ea->data[0] / sizeof(struct get_name_list_extended);
366
Quinn Tran83548fe2017-06-02 09:12:01 -0700367 ql_dbg(ql_dbg_disc, vha, 0x20e1,
Quinn Tran726b8542017-01-19 22:28:00 -0800368 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
369 __func__, __LINE__, fcport->port_name, n,
370 fcport->d_id.b.domain, fcport->d_id.b.area,
371 fcport->d_id.b.al_pa, fcport->loop_id);
372
373 for (i = 0; i < n; i++) {
374 e = &vha->gnl.l[i];
375 wwn = wwn_to_u64(e->port_name);
376
377 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
378 continue;
379
380 found = 1;
381 id.b.domain = e->port_id[2];
382 id.b.area = e->port_id[1];
383 id.b.al_pa = e->port_id[0];
384 id.b.rsvd_1 = 0;
385
386 loop_id = le16_to_cpu(e->nport_handle);
387 loop_id = (loop_id & 0x7fff);
388
Quinn Tran83548fe2017-06-02 09:12:01 -0700389 ql_dbg(ql_dbg_disc, vha, 0x20e2,
390 "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
391 __func__, fcport->port_name,
392 e->current_login_state, fcport->fw_login_state,
393 id.b.domain, id.b.area, id.b.al_pa,
394 fcport->d_id.b.domain, fcport->d_id.b.area,
395 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
Quinn Tran726b8542017-01-19 22:28:00 -0800396
397 if ((id.b24 != fcport->d_id.b24) ||
398 ((fcport->loop_id != FC_NO_LOOP_ID) &&
399 (fcport->loop_id != loop_id))) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700400 ql_dbg(ql_dbg_disc, vha, 0x20e3,
401 "%s %d %8phC post del sess\n",
402 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800403 qlt_schedule_sess_for_deletion(fcport, 1);
404 return;
405 }
406
407 fcport->loop_id = loop_id;
408
409 wwn = wwn_to_u64(fcport->port_name);
410 qlt_find_sess_invalidate_other(vha, wwn,
411 id, loop_id, &conflict_fcport);
412
413 if (conflict_fcport) {
414 /*
415 * Another share fcport share the same loop_id &
416 * nport id. Conflict fcport needs to finish
417 * cleanup before this fcport can proceed to login.
418 */
419 conflict_fcport->conflict = fcport;
420 fcport->login_pause = 1;
421 }
422
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700423 if (fcport->fc4f_nvme)
424 current_login_state = e->current_login_state >> 4;
425 else
426 current_login_state = e->current_login_state & 0xf;
427
428 switch (current_login_state) {
Quinn Tran726b8542017-01-19 22:28:00 -0800429 case DSC_LS_PRLI_COMP:
Quinn Tran83548fe2017-06-02 09:12:01 -0700430 ql_dbg(ql_dbg_disc, vha, 0x20e4,
431 "%s %d %8phC post gpdb\n",
432 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800433 opt = PDO_FORCE_ADISC;
434 qla24xx_post_gpdb_work(vha, fcport, opt);
435 break;
Quinn Tran726b8542017-01-19 22:28:00 -0800436 case DSC_LS_PORT_UNAVAIL:
437 default:
438 if (fcport->loop_id == FC_NO_LOOP_ID) {
439 qla2x00_find_new_loop_id(vha, fcport);
440 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
441 }
Quinn Tran83548fe2017-06-02 09:12:01 -0700442 ql_dbg(ql_dbg_disc, vha, 0x20e5,
443 "%s %d %8phC\n",
444 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800445 qla24xx_fcport_handle_login(vha, fcport);
446 break;
447 }
448 }
449
450 if (!found) {
451 /* fw has no record of this port */
452 if (fcport->loop_id == FC_NO_LOOP_ID) {
453 qla2x00_find_new_loop_id(vha, fcport);
454 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
455 } else {
456 for (i = 0; i < n; i++) {
457 e = &vha->gnl.l[i];
458 id.b.domain = e->port_id[0];
459 id.b.area = e->port_id[1];
460 id.b.al_pa = e->port_id[2];
461 id.b.rsvd_1 = 0;
462 loop_id = le16_to_cpu(e->nport_handle);
463
464 if (fcport->d_id.b24 == id.b24) {
465 conflict_fcport =
466 qla2x00_find_fcport_by_wwpn(vha,
467 e->port_name, 0);
468
Quinn Tran83548fe2017-06-02 09:12:01 -0700469 ql_dbg(ql_dbg_disc, vha, 0x20e6,
Quinn Tran726b8542017-01-19 22:28:00 -0800470 "%s %d %8phC post del sess\n",
471 __func__, __LINE__,
472 conflict_fcport->port_name);
473 qlt_schedule_sess_for_deletion
474 (conflict_fcport, 1);
475 }
476
477 if (fcport->loop_id == loop_id) {
478 /* FW already picked this loop id for another fcport */
479 qla2x00_find_new_loop_id(vha, fcport);
480 }
481 }
482 }
483 qla24xx_fcport_handle_login(vha, fcport);
484 }
485} /* gnl_event */
486
487static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800488qla24xx_async_gnl_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -0800489{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800490 struct srb *sp = s;
491 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -0800492 unsigned long flags;
493 struct fc_port *fcport = NULL, *tf;
494 u16 i, n = 0, loop_id;
495 struct event_arg ea;
496 struct get_name_list_extended *e;
497 u64 wwn;
498 struct list_head h;
499
Quinn Tran83548fe2017-06-02 09:12:01 -0700500 ql_dbg(ql_dbg_disc, vha, 0x20e7,
Quinn Tran726b8542017-01-19 22:28:00 -0800501 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
502 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
503 sp->u.iocb_cmd.u.mbx.in_mb[2]);
504
505 memset(&ea, 0, sizeof(ea));
506 ea.sp = sp;
507 ea.rc = res;
508 ea.event = FCME_GNL_DONE;
509
510 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
511 sizeof(struct get_name_list_extended)) {
512 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
513 sizeof(struct get_name_list_extended);
514 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
515 }
516
517 for (i = 0; i < n; i++) {
518 e = &vha->gnl.l[i];
519 loop_id = le16_to_cpu(e->nport_handle);
520 /* mask out reserve bit */
521 loop_id = (loop_id & 0x7fff);
522 set_bit(loop_id, vha->hw->loop_id_map);
523 wwn = wwn_to_u64(e->port_name);
524
Quinn Tran83548fe2017-06-02 09:12:01 -0700525 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
Quinn Tran726b8542017-01-19 22:28:00 -0800526 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
527 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
528 e->port_id[0], e->current_login_state, e->last_login_state,
529 (loop_id & 0x7fff));
530 }
531
532 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
533 vha->gnl.sent = 0;
534
535 INIT_LIST_HEAD(&h);
536 fcport = tf = NULL;
537 if (!list_empty(&vha->gnl.fcports))
538 list_splice_init(&vha->gnl.fcports, &h);
539
540 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
541 list_del_init(&fcport->gnl_entry);
542 fcport->flags &= ~FCF_ASYNC_SENT;
543 ea.fcport = fcport;
544
545 qla2x00_fcport_event_handler(vha, &ea);
546 }
547
548 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
549
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800550 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800551}
552
553int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
554{
555 srb_t *sp;
556 struct srb_iocb *mbx;
557 int rval = QLA_FUNCTION_FAILED;
558 unsigned long flags;
559 u16 *mb;
560
561 if (!vha->flags.online)
562 goto done;
563
Quinn Tran83548fe2017-06-02 09:12:01 -0700564 ql_dbg(ql_dbg_disc, vha, 0x20d9,
Quinn Tran726b8542017-01-19 22:28:00 -0800565 "Async-gnlist WWPN %8phC \n", fcport->port_name);
566
567 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
568 fcport->flags |= FCF_ASYNC_SENT;
569 fcport->disc_state = DSC_GNL;
570 fcport->last_rscn_gen = fcport->rscn_gen;
571 fcport->last_login_gen = fcport->login_gen;
572
573 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
574 if (vha->gnl.sent) {
575 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
576 rval = QLA_SUCCESS;
577 goto done;
578 }
579 vha->gnl.sent = 1;
580 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
581
582 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
583 if (!sp)
584 goto done;
585 sp->type = SRB_MB_IOCB;
586 sp->name = "gnlist";
587 sp->gen1 = fcport->rscn_gen;
588 sp->gen2 = fcport->login_gen;
589
590 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
591
592 mb = sp->u.iocb_cmd.u.mbx.out_mb;
593 mb[0] = MBC_PORT_NODE_NAME_LIST;
594 mb[1] = BIT_2 | BIT_3;
595 mb[2] = MSW(vha->gnl.ldma);
596 mb[3] = LSW(vha->gnl.ldma);
597 mb[6] = MSW(MSD(vha->gnl.ldma));
598 mb[7] = LSW(MSD(vha->gnl.ldma));
599 mb[8] = vha->gnl.size;
600 mb[9] = vha->vp_idx;
601
602 mbx = &sp->u.iocb_cmd;
603 mbx->timeout = qla2x00_async_iocb_timeout;
604
605 sp->done = qla24xx_async_gnl_sp_done;
606
607 rval = qla2x00_start_sp(sp);
608 if (rval != QLA_SUCCESS)
609 goto done_free_sp;
610
Quinn Tran83548fe2017-06-02 09:12:01 -0700611 ql_dbg(ql_dbg_disc, vha, 0x20da,
612 "Async-%s - OUT WWPN %8phC hndl %x\n",
613 sp->name, fcport->port_name, sp->handle);
Quinn Tran726b8542017-01-19 22:28:00 -0800614
615 return rval;
616
617done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800618 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800619done:
620 fcport->flags &= ~FCF_ASYNC_SENT;
621 return rval;
622}
623
624int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
625{
626 struct qla_work_evt *e;
627
628 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
629 if (!e)
630 return QLA_FUNCTION_FAILED;
631
632 e->u.fcport.fcport = fcport;
633 return qla2x00_post_work(vha, e);
634}
635
636static
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800637void qla24xx_async_gpdb_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -0800638{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800639 struct srb *sp = s;
640 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -0800641 struct qla_hw_data *ha = vha->hw;
Quinn Tran726b8542017-01-19 22:28:00 -0800642 struct port_database_24xx *pd;
643 fc_port_t *fcport = sp->fcport;
644 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
645 int rval = QLA_SUCCESS;
646 struct event_arg ea;
647
Quinn Tran83548fe2017-06-02 09:12:01 -0700648 ql_dbg(ql_dbg_disc, vha, 0x20db,
Quinn Tran726b8542017-01-19 22:28:00 -0800649 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
650 sp->name, res, fcport->port_name, mb[1], mb[2]);
651
652 fcport->flags &= ~FCF_ASYNC_SENT;
653
654 if (res) {
655 rval = res;
656 goto gpd_error_out;
657 }
658
659 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
660
Quinn Tran15f30a52017-03-15 09:48:52 -0700661 rval = __qla24xx_parse_gpdb(vha, fcport, pd);
Quinn Tran726b8542017-01-19 22:28:00 -0800662
663gpd_error_out:
664 memset(&ea, 0, sizeof(ea));
665 ea.event = FCME_GPDB_DONE;
666 ea.rc = rval;
667 ea.fcport = fcport;
668 ea.sp = sp;
669
670 qla2x00_fcport_event_handler(vha, &ea);
671
672 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
673 sp->u.iocb_cmd.u.mbx.in_dma);
674
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800675 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800676}
677
Duane Grigsbya5d42f42017-06-21 13:48:41 -0700678static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
679{
680 struct qla_work_evt *e;
681
682 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
683 if (!e)
684 return QLA_FUNCTION_FAILED;
685
686 e->u.fcport.fcport = fcport;
687
688 return qla2x00_post_work(vha, e);
689}
690
691static void
692qla2x00_async_prli_sp_done(void *ptr, int res)
693{
694 srb_t *sp = ptr;
695 struct scsi_qla_host *vha = sp->vha;
696 struct srb_iocb *lio = &sp->u.iocb_cmd;
697 struct event_arg ea;
698
699 ql_dbg(ql_dbg_disc, vha, 0x2129,
700 "%s %8phC res %d \n", __func__,
701 sp->fcport->port_name, res);
702
703 sp->fcport->flags &= ~FCF_ASYNC_SENT;
704
705 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
706 memset(&ea, 0, sizeof(ea));
707 ea.event = FCME_PRLI_DONE;
708 ea.fcport = sp->fcport;
709 ea.data[0] = lio->u.logio.data[0];
710 ea.data[1] = lio->u.logio.data[1];
711 ea.iop[0] = lio->u.logio.iop[0];
712 ea.iop[1] = lio->u.logio.iop[1];
713 ea.sp = sp;
714
715 qla2x00_fcport_event_handler(vha, &ea);
716 }
717
718 sp->free(sp);
719}
720
721int
722qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
723{
724 srb_t *sp;
725 struct srb_iocb *lio;
726 int rval = QLA_FUNCTION_FAILED;
727
728 if (!vha->flags.online)
729 return rval;
730
731 if (fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
732 fcport->fw_login_state == DSC_LS_PLOGI_COMP ||
733 fcport->fw_login_state == DSC_LS_PRLI_PEND)
734 return rval;
735
736 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
737 if (!sp)
738 return rval;
739
740 fcport->flags |= FCF_ASYNC_SENT;
741 fcport->logout_completed = 0;
742
743 sp->type = SRB_PRLI_CMD;
744 sp->name = "prli";
745 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
746
747 lio = &sp->u.iocb_cmd;
748 lio->timeout = qla2x00_async_iocb_timeout;
749 sp->done = qla2x00_async_prli_sp_done;
750 lio->u.logio.flags = 0;
751
752 if (fcport->fc4f_nvme)
753 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
754
755 rval = qla2x00_start_sp(sp);
756 if (rval != QLA_SUCCESS) {
757 fcport->flags &= ~FCF_ASYNC_SENT;
758 fcport->flags |= FCF_LOGIN_NEEDED;
759 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
760 goto done_free_sp;
761 }
762
763 ql_dbg(ql_dbg_disc, vha, 0x211b,
764 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n",
765 fcport->port_name, sp->handle, fcport->loop_id,
766 fcport->d_id.b24, fcport->login_retry);
767
768 return rval;
769
770done_free_sp:
771 sp->free(sp);
772 fcport->flags &= ~FCF_ASYNC_SENT;
773 return rval;
774}
775
Quinn Trana07fc0a2017-08-23 15:05:21 -0700776int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
Quinn Tran726b8542017-01-19 22:28:00 -0800777{
778 struct qla_work_evt *e;
779
780 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
781 if (!e)
782 return QLA_FUNCTION_FAILED;
783
784 e->u.fcport.fcport = fcport;
785 e->u.fcport.opt = opt;
786 return qla2x00_post_work(vha, e);
787}
788
789int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
790{
791 srb_t *sp;
792 struct srb_iocb *mbx;
793 int rval = QLA_FUNCTION_FAILED;
794 u16 *mb;
795 dma_addr_t pd_dma;
796 struct port_database_24xx *pd;
797 struct qla_hw_data *ha = vha->hw;
798
799 if (!vha->flags.online)
800 goto done;
801
802 fcport->flags |= FCF_ASYNC_SENT;
803 fcport->disc_state = DSC_GPDB;
804
805 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
806 if (!sp)
807 goto done;
808
Joe Carnuccioe0824e62017-08-23 15:05:08 -0700809 sp->type = SRB_MB_IOCB;
810 sp->name = "gpdb";
811 sp->gen1 = fcport->rscn_gen;
812 sp->gen2 = fcport->login_gen;
813 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
814
Thomas Meyer08eb7f42017-09-21 08:15:26 +0200815 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Quinn Tran726b8542017-01-19 22:28:00 -0800816 if (pd == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700817 ql_log(ql_log_warn, vha, 0xd043,
818 "Failed to allocate port database structure.\n");
Quinn Tran726b8542017-01-19 22:28:00 -0800819 goto done_free_sp;
820 }
Quinn Tran726b8542017-01-19 22:28:00 -0800821
Quinn Tran726b8542017-01-19 22:28:00 -0800822 mb = sp->u.iocb_cmd.u.mbx.out_mb;
823 mb[0] = MBC_GET_PORT_DATABASE;
824 mb[1] = fcport->loop_id;
825 mb[2] = MSW(pd_dma);
826 mb[3] = LSW(pd_dma);
827 mb[6] = MSW(MSD(pd_dma));
828 mb[7] = LSW(MSD(pd_dma));
829 mb[9] = vha->vp_idx;
830 mb[10] = opt;
831
832 mbx = &sp->u.iocb_cmd;
833 mbx->timeout = qla2x00_async_iocb_timeout;
834 mbx->u.mbx.in = (void *)pd;
835 mbx->u.mbx.in_dma = pd_dma;
836
837 sp->done = qla24xx_async_gpdb_sp_done;
838
839 rval = qla2x00_start_sp(sp);
840 if (rval != QLA_SUCCESS)
841 goto done_free_sp;
842
Quinn Tran83548fe2017-06-02 09:12:01 -0700843 ql_dbg(ql_dbg_disc, vha, 0x20dc,
844 "Async-%s %8phC hndl %x opt %x\n",
845 sp->name, fcport->port_name, sp->handle, opt);
Quinn Tran726b8542017-01-19 22:28:00 -0800846
847 return rval;
848
849done_free_sp:
850 if (pd)
851 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
852
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800853 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800854done:
855 fcport->flags &= ~FCF_ASYNC_SENT;
856 qla24xx_post_gpdb_work(vha, fcport, opt);
857 return rval;
858}
859
860static
861void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
862{
863 int rval = ea->rc;
864 fc_port_t *fcport = ea->fcport;
865 unsigned long flags;
Quinn Tran414d9ff2017-12-04 14:45:03 -0800866 u16 opt = ea->sp->u.iocb_cmd.u.mbx.out_mb[10];
Quinn Tran726b8542017-01-19 22:28:00 -0800867
868 fcport->flags &= ~FCF_ASYNC_SENT;
869
Quinn Tran83548fe2017-06-02 09:12:01 -0700870 ql_dbg(ql_dbg_disc, vha, 0x20d2,
Quinn Tran726b8542017-01-19 22:28:00 -0800871 "%s %8phC DS %d LS %d rval %d\n", __func__, fcport->port_name,
872 fcport->disc_state, fcport->fw_login_state, rval);
873
874 if (ea->sp->gen2 != fcport->login_gen) {
875 /* target side must have changed it. */
Quinn Tran83548fe2017-06-02 09:12:01 -0700876 ql_dbg(ql_dbg_disc, vha, 0x20d3,
Quinn Tran726b8542017-01-19 22:28:00 -0800877 "%s %8phC generation changed rscn %d|%d login %d|%d \n",
878 __func__, fcport->port_name, fcport->last_rscn_gen,
879 fcport->rscn_gen, fcport->last_login_gen,
880 fcport->login_gen);
881 return;
882 } else if (ea->sp->gen1 != fcport->rscn_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700883 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
Quinn Tran726b8542017-01-19 22:28:00 -0800884 __func__, __LINE__, fcport->port_name);
885 qla24xx_post_gidpn_work(vha, fcport);
886 return;
887 }
888
889 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700890 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
Quinn Tran726b8542017-01-19 22:28:00 -0800891 __func__, __LINE__, fcport->port_name);
892 qlt_schedule_sess_for_deletion_lock(fcport);
893 return;
894 }
895
896 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Tran414d9ff2017-12-04 14:45:03 -0800897 if (opt != PDO_FORCE_ADISC)
898 ea->fcport->login_gen++;
Quinn Tran726b8542017-01-19 22:28:00 -0800899 ea->fcport->deleted = 0;
900 ea->fcport->logout_on_delete = 1;
901
902 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
903 vha->fcport_count++;
904 ea->fcport->login_succ = 1;
905
906 if (!IS_IIDMA_CAPABLE(vha->hw) ||
907 !vha->hw->flags.gpsc_supported) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700908 ql_dbg(ql_dbg_disc, vha, 0x20d6,
Quinn Tran726b8542017-01-19 22:28:00 -0800909 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
910 __func__, __LINE__, fcport->port_name,
911 vha->fcport_count);
912
913 qla24xx_post_upd_fcport_work(vha, fcport);
914 } else {
Quinn Tran83548fe2017-06-02 09:12:01 -0700915 ql_dbg(ql_dbg_disc, vha, 0x20d7,
Quinn Tran726b8542017-01-19 22:28:00 -0800916 "%s %d %8phC post gpsc fcp_cnt %d\n",
917 __func__, __LINE__, fcport->port_name,
918 vha->fcport_count);
919
920 qla24xx_post_gpsc_work(vha, fcport);
921 }
Quinn Tran414d9ff2017-12-04 14:45:03 -0800922 } else if (ea->fcport->login_succ) {
923 /*
924 * We have an existing session. A late RSCN delivery
925 * must have triggered the session to be re-validate.
926 * session is still valid.
927 */
928 fcport->disc_state = DSC_LOGIN_COMPLETE;
Quinn Tran726b8542017-01-19 22:28:00 -0800929 }
930 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
931} /* gpdb event */
932
933int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
934{
935 if (fcport->login_retry == 0)
936 return 0;
937
938 if (fcport->scan_state != QLA_FCPORT_FOUND)
939 return 0;
940
Quinn Tran83548fe2017-06-02 09:12:01 -0700941 ql_dbg(ql_dbg_disc, vha, 0x20d8,
Quinn Tran726b8542017-01-19 22:28:00 -0800942 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d|%d retry %d lid %d\n",
943 __func__, fcport->port_name, fcport->disc_state,
944 fcport->fw_login_state, fcport->login_pause, fcport->flags,
945 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
946 fcport->last_login_gen, fcport->login_gen, fcport->login_retry,
947 fcport->loop_id);
948
949 fcport->login_retry--;
950
951 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
Quinn Tran726b8542017-01-19 22:28:00 -0800952 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
953 return 0;
954
Quinn Tran5b334692017-03-15 09:48:48 -0700955 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
956 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline))
957 return 0;
958 }
959
Quinn Tran726b8542017-01-19 22:28:00 -0800960 /* for pure Target Mode. Login will not be initiated */
961 if (vha->host->active_mode == MODE_TARGET)
962 return 0;
963
964 if (fcport->flags & FCF_ASYNC_SENT) {
965 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
966 return 0;
967 }
968
969 switch (fcport->disc_state) {
970 case DSC_DELETED:
971 if (fcport->loop_id == FC_NO_LOOP_ID) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700972 ql_dbg(ql_dbg_disc, vha, 0x20bd,
973 "%s %d %8phC post gnl\n",
974 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800975 qla24xx_async_gnl(vha, fcport);
976 } else {
Quinn Tran83548fe2017-06-02 09:12:01 -0700977 ql_dbg(ql_dbg_disc, vha, 0x20bf,
978 "%s %d %8phC post login\n",
979 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800980 fcport->disc_state = DSC_LOGIN_PEND;
981 qla2x00_post_async_login_work(vha, fcport, NULL);
982 }
983 break;
984
985 case DSC_GNL:
986 if (fcport->login_pause) {
987 fcport->last_rscn_gen = fcport->rscn_gen;
988 fcport->last_login_gen = fcport->login_gen;
989 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
990 break;
991 }
992
993 if (fcport->flags & FCF_FCP2_DEVICE) {
994 u8 opt = PDO_FORCE_ADISC;
995
Quinn Tran83548fe2017-06-02 09:12:01 -0700996 ql_dbg(ql_dbg_disc, vha, 0x20c9,
997 "%s %d %8phC post gpdb\n",
998 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800999
1000 fcport->disc_state = DSC_GPDB;
1001 qla24xx_post_gpdb_work(vha, fcport, opt);
1002 } else {
Quinn Tran83548fe2017-06-02 09:12:01 -07001003 ql_dbg(ql_dbg_disc, vha, 0x20cf,
1004 "%s %d %8phC post login\n",
1005 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -08001006 fcport->disc_state = DSC_LOGIN_PEND;
1007 qla2x00_post_async_login_work(vha, fcport, NULL);
1008 }
1009
1010 break;
1011
1012 case DSC_LOGIN_FAILED:
Quinn Tran83548fe2017-06-02 09:12:01 -07001013 ql_dbg(ql_dbg_disc, vha, 0x20d0,
1014 "%s %d %8phC post gidpn\n",
1015 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -08001016
1017 qla24xx_post_gidpn_work(vha, fcport);
1018 break;
1019
1020 case DSC_LOGIN_COMPLETE:
1021 /* recheck login state */
Quinn Tran83548fe2017-06-02 09:12:01 -07001022 ql_dbg(ql_dbg_disc, vha, 0x20d1,
1023 "%s %d %8phC post gpdb\n",
1024 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -08001025
1026 qla24xx_post_gpdb_work(vha, fcport, PDO_FORCE_ADISC);
1027 break;
1028
1029 default:
1030 break;
1031 }
1032
1033 return 0;
1034}
1035
1036static
1037void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea)
1038{
1039 fcport->rscn_gen++;
1040
Quinn Tran83548fe2017-06-02 09:12:01 -07001041 ql_dbg(ql_dbg_disc, fcport->vha, 0x210c,
1042 "%s %8phC DS %d LS %d\n",
1043 __func__, fcport->port_name, fcport->disc_state,
1044 fcport->fw_login_state);
Quinn Tran726b8542017-01-19 22:28:00 -08001045
1046 if (fcport->flags & FCF_ASYNC_SENT)
1047 return;
1048
1049 switch (fcport->disc_state) {
1050 case DSC_DELETED:
1051 case DSC_LOGIN_COMPLETE:
1052 qla24xx_post_gidpn_work(fcport->vha, fcport);
1053 break;
1054
1055 default:
1056 break;
1057 }
1058}
1059
1060int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1061 u8 *port_name, void *pla)
1062{
1063 struct qla_work_evt *e;
1064 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1065 if (!e)
1066 return QLA_FUNCTION_FAILED;
1067
1068 e->u.new_sess.id = *id;
1069 e->u.new_sess.pla = pla;
1070 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1071
1072 return qla2x00_post_work(vha, e);
1073}
1074
1075static
1076int qla24xx_handle_delete_done_event(scsi_qla_host_t *vha,
1077 struct event_arg *ea)
1078{
1079 fc_port_t *fcport = ea->fcport;
1080
1081 if (test_bit(UNLOADING, &vha->dpc_flags))
1082 return 0;
1083
1084 switch (vha->host->active_mode) {
1085 case MODE_INITIATOR:
1086 case MODE_DUAL:
1087 if (fcport->scan_state == QLA_FCPORT_FOUND)
1088 qla24xx_fcport_handle_login(vha, fcport);
1089 break;
1090
1091 case MODE_TARGET:
1092 default:
1093 /* no-op */
1094 break;
1095 }
1096
1097 return 0;
1098}
1099
1100static
1101void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1102 struct event_arg *ea)
1103{
1104 fc_port_t *fcport = ea->fcport;
1105
1106 if (fcport->scan_state != QLA_FCPORT_FOUND) {
1107 fcport->login_retry++;
1108 return;
1109 }
1110
Quinn Tran83548fe2017-06-02 09:12:01 -07001111 ql_dbg(ql_dbg_disc, vha, 0x2102,
1112 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1113 __func__, fcport->port_name, fcport->disc_state,
1114 fcport->fw_login_state, fcport->login_pause,
1115 fcport->deleted, fcport->conflict,
1116 fcport->last_rscn_gen, fcport->rscn_gen,
1117 fcport->last_login_gen, fcport->login_gen,
1118 fcport->flags);
Quinn Tran726b8542017-01-19 22:28:00 -08001119
1120 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
Quinn Tran726b8542017-01-19 22:28:00 -08001121 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1122 return;
1123
Quinn Tran5b334692017-03-15 09:48:48 -07001124 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1125 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline))
1126 return;
1127 }
1128
Quinn Tran726b8542017-01-19 22:28:00 -08001129 if (fcport->flags & FCF_ASYNC_SENT) {
1130 fcport->login_retry++;
1131 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1132 return;
1133 }
1134
1135 if (fcport->disc_state == DSC_DELETE_PEND) {
1136 fcport->login_retry++;
1137 return;
1138 }
1139
1140 if (fcport->last_rscn_gen != fcport->rscn_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -07001141 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n",
Quinn Tran726b8542017-01-19 22:28:00 -08001142 __func__, __LINE__, fcport->port_name);
1143
1144 qla24xx_async_gidpn(vha, fcport);
1145 return;
1146 }
1147
1148 qla24xx_fcport_handle_login(vha, fcport);
1149}
1150
Quinn Tran41dc5292017-01-19 22:28:03 -08001151void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
Quinn Tran726b8542017-01-19 22:28:00 -08001152{
Quinn Tran41dc5292017-01-19 22:28:03 -08001153 fc_port_t *fcport, *f, *tf;
1154 uint32_t id = 0, mask, rid;
Quinn Tran726b8542017-01-19 22:28:00 -08001155 int rc;
1156
1157 switch (ea->event) {
1158 case FCME_RELOGIN:
Quinn Tranb98ae0d2017-06-02 09:12:00 -07001159 case FCME_RSCN:
1160 case FCME_GIDPN_DONE:
1161 case FCME_GPSC_DONE:
1162 case FCME_GPNID_DONE:
1163 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
1164 test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))
1165 return;
1166 break;
1167 default:
1168 break;
1169 }
1170
1171 switch (ea->event) {
1172 case FCME_RELOGIN:
Quinn Tran726b8542017-01-19 22:28:00 -08001173 if (test_bit(UNLOADING, &vha->dpc_flags))
1174 return;
1175
1176 qla24xx_handle_relogin_event(vha, ea);
1177 break;
1178 case FCME_RSCN:
1179 if (test_bit(UNLOADING, &vha->dpc_flags))
1180 return;
Quinn Tran41dc5292017-01-19 22:28:03 -08001181 switch (ea->id.b.rsvd_1) {
1182 case RSCN_PORT_ADDR:
1183 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1184 if (!fcport) {
1185 /* cable moved */
1186 rc = qla24xx_post_gpnid_work(vha, &ea->id);
1187 if (rc) {
Quinn Tran83548fe2017-06-02 09:12:01 -07001188 ql_log(ql_log_warn, vha, 0xd044,
1189 "RSCN GPNID work failed %02x%02x%02x\n",
1190 ea->id.b.domain, ea->id.b.area,
1191 ea->id.b.al_pa);
Quinn Tran41dc5292017-01-19 22:28:03 -08001192 }
1193 } else {
1194 ea->fcport = fcport;
1195 qla24xx_handle_rscn_event(fcport, ea);
Quinn Tran726b8542017-01-19 22:28:00 -08001196 }
Quinn Tran41dc5292017-01-19 22:28:03 -08001197 break;
1198 case RSCN_AREA_ADDR:
1199 case RSCN_DOM_ADDR:
1200 if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) {
1201 mask = 0xffff00;
Quinn Tran83548fe2017-06-02 09:12:01 -07001202 ql_dbg(ql_dbg_async, vha, 0x5044,
1203 "RSCN: Area 0x%06x was affected\n",
1204 ea->id.b24);
Quinn Tran41dc5292017-01-19 22:28:03 -08001205 } else {
1206 mask = 0xff0000;
Quinn Tran83548fe2017-06-02 09:12:01 -07001207 ql_dbg(ql_dbg_async, vha, 0x507a,
1208 "RSCN: Domain 0x%06x was affected\n",
1209 ea->id.b24);
Quinn Tran41dc5292017-01-19 22:28:03 -08001210 }
1211
1212 rid = ea->id.b24 & mask;
1213 list_for_each_entry_safe(f, tf, &vha->vp_fcports,
1214 list) {
1215 id = f->d_id.b24 & mask;
1216 if (rid == id) {
1217 ea->fcport = f;
1218 qla24xx_handle_rscn_event(f, ea);
1219 }
1220 }
1221 break;
1222 case RSCN_FAB_ADDR:
1223 default:
Quinn Tran83548fe2017-06-02 09:12:01 -07001224 ql_log(ql_log_warn, vha, 0xd045,
1225 "RSCN: Fabric was affected. Addr format %d\n",
1226 ea->id.b.rsvd_1);
Quinn Tran41dc5292017-01-19 22:28:03 -08001227 qla2x00_mark_all_devices_lost(vha, 1);
1228 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1229 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Quinn Tran726b8542017-01-19 22:28:00 -08001230 }
1231 break;
1232 case FCME_GIDPN_DONE:
1233 qla24xx_handle_gidpn_event(vha, ea);
1234 break;
1235 case FCME_GNL_DONE:
1236 qla24xx_handle_gnl_done_event(vha, ea);
1237 break;
1238 case FCME_GPSC_DONE:
1239 qla24xx_post_upd_fcport_work(vha, ea->fcport);
1240 break;
1241 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1242 qla24xx_handle_plogi_done_event(vha, ea);
1243 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001244 case FCME_PRLI_DONE:
1245 qla24xx_handle_prli_done_event(vha, ea);
1246 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001247 case FCME_GPDB_DONE:
1248 qla24xx_handle_gpdb_event(vha, ea);
1249 break;
1250 case FCME_GPNID_DONE:
1251 qla24xx_handle_gpnid_event(vha, ea);
1252 break;
Duane Grigsbyd3bae932017-06-21 13:48:44 -07001253 case FCME_GFFID_DONE:
1254 qla24xx_handle_gffid_event(vha, ea);
1255 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001256 case FCME_DELETE_DONE:
1257 qla24xx_handle_delete_done_event(vha, ea);
1258 break;
1259 default:
1260 BUG_ON(1);
1261 break;
1262 }
1263}
1264
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001265static void
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001266qla2x00_tmf_iocb_timeout(void *data)
1267{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001268 srb_t *sp = data;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001269 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1270
1271 tmf->u.tmf.comp_status = CS_TIMEOUT;
1272 complete(&tmf->u.tmf.comp);
1273}
1274
1275static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001276qla2x00_tmf_sp_done(void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001277{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001278 srb_t *sp = ptr;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001279 struct srb_iocb *tmf = &sp->u.iocb_cmd;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001280
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001281 complete(&tmf->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001282}
1283
1284int
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001285qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001286 uint32_t tag)
1287{
1288 struct scsi_qla_host *vha = fcport->vha;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001289 struct srb_iocb *tm_iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001290 srb_t *sp;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001291 int rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001292
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001293 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001294 if (!sp)
1295 goto done;
1296
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001297 tm_iocb = &sp->u.iocb_cmd;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001298 sp->type = SRB_TM_CMD;
1299 sp->name = "tmf";
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001300 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1301 tm_iocb->u.tmf.flags = flags;
1302 tm_iocb->u.tmf.lun = lun;
1303 tm_iocb->u.tmf.data = tag;
1304 sp->done = qla2x00_tmf_sp_done;
1305 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1306 init_completion(&tm_iocb->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001307
1308 rval = qla2x00_start_sp(sp);
1309 if (rval != QLA_SUCCESS)
1310 goto done_free_sp;
1311
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001312 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001313 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1314 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1315 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001316
1317 wait_for_completion(&tm_iocb->u.tmf.comp);
1318
1319 rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
1320 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1321
1322 if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
1323 ql_dbg(ql_dbg_taskm, vha, 0x8030,
1324 "TM IOCB failed (%x).\n", rval);
1325 }
1326
1327 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1328 flags = tm_iocb->u.tmf.flags;
1329 lun = (uint16_t)tm_iocb->u.tmf.lun;
1330
1331 /* Issue Marker IOCB */
1332 qla2x00_marker(vha, vha->hw->req_q_map[0],
1333 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
1334 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1335 }
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001336
1337done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001338 sp->free(sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001339done:
1340 return rval;
1341}
1342
Armen Baloyan4440e462014-02-26 04:15:18 -05001343static void
1344qla24xx_abort_iocb_timeout(void *data)
1345{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001346 srb_t *sp = data;
Armen Baloyan4440e462014-02-26 04:15:18 -05001347 struct srb_iocb *abt = &sp->u.iocb_cmd;
1348
1349 abt->u.abt.comp_status = CS_TIMEOUT;
1350 complete(&abt->u.abt.comp);
1351}
1352
1353static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001354qla24xx_abort_sp_done(void *ptr, int res)
Armen Baloyan4440e462014-02-26 04:15:18 -05001355{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001356 srb_t *sp = ptr;
Armen Baloyan4440e462014-02-26 04:15:18 -05001357 struct srb_iocb *abt = &sp->u.iocb_cmd;
1358
1359 complete(&abt->u.abt.comp);
1360}
1361
Quinn Tran15f30a52017-03-15 09:48:52 -07001362int
Armen Baloyan4440e462014-02-26 04:15:18 -05001363qla24xx_async_abort_cmd(srb_t *cmd_sp)
1364{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001365 scsi_qla_host_t *vha = cmd_sp->vha;
Armen Baloyan4440e462014-02-26 04:15:18 -05001366 fc_port_t *fcport = cmd_sp->fcport;
1367 struct srb_iocb *abt_iocb;
1368 srb_t *sp;
1369 int rval = QLA_FUNCTION_FAILED;
1370
1371 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1372 if (!sp)
1373 goto done;
1374
1375 abt_iocb = &sp->u.iocb_cmd;
1376 sp->type = SRB_ABT_CMD;
1377 sp->name = "abort";
1378 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1379 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
1380 sp->done = qla24xx_abort_sp_done;
1381 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
1382 init_completion(&abt_iocb->u.abt.comp);
1383
1384 rval = qla2x00_start_sp(sp);
1385 if (rval != QLA_SUCCESS)
1386 goto done_free_sp;
1387
1388 ql_dbg(ql_dbg_async, vha, 0x507c,
1389 "Abort command issued - hdl=%x, target_id=%x\n",
1390 cmd_sp->handle, fcport->tgt_id);
1391
1392 wait_for_completion(&abt_iocb->u.abt.comp);
1393
1394 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
1395 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1396
1397done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001398 sp->free(sp);
Armen Baloyan4440e462014-02-26 04:15:18 -05001399done:
1400 return rval;
1401}
1402
1403int
1404qla24xx_async_abort_command(srb_t *sp)
1405{
1406 unsigned long flags = 0;
1407
1408 uint32_t handle;
1409 fc_port_t *fcport = sp->fcport;
1410 struct scsi_qla_host *vha = fcport->vha;
1411 struct qla_hw_data *ha = vha->hw;
1412 struct req_que *req = vha->req;
1413
1414 spin_lock_irqsave(&ha->hardware_lock, flags);
1415 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1416 if (req->outstanding_cmds[handle] == sp)
1417 break;
1418 }
1419 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1420 if (handle == req->num_outstanding_cmds) {
1421 /* Command not found. */
1422 return QLA_FUNCTION_FAILED;
1423 }
1424 if (sp->type == SRB_FXIOCB_DCMD)
1425 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1426 FXDISC_ABORT_IOCTL);
1427
1428 return qla24xx_async_abort_cmd(sp);
1429}
1430
Quinn Tran726b8542017-01-19 22:28:00 -08001431static void
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001432qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1433{
1434 switch (ea->data[0]) {
1435 case MBS_COMMAND_COMPLETE:
1436 ql_dbg(ql_dbg_disc, vha, 0x2118,
1437 "%s %d %8phC post gpdb\n",
1438 __func__, __LINE__, ea->fcport->port_name);
1439
1440 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1441 ea->fcport->logout_on_delete = 1;
1442 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1443 break;
1444 default:
Duane Grigsbyedd05de2017-10-13 09:34:06 -07001445 if (ea->fcport->n2n_flag) {
1446 ql_dbg(ql_dbg_disc, vha, 0x2118,
1447 "%s %d %8phC post fc4 prli\n",
1448 __func__, __LINE__, ea->fcport->port_name);
1449 ea->fcport->fc4f_nvme = 0;
1450 ea->fcport->n2n_flag = 0;
1451 qla24xx_post_prli_work(vha, ea->fcport);
1452 }
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001453 ql_dbg(ql_dbg_disc, vha, 0x2119,
1454 "%s %d %8phC unhandle event of %x\n",
1455 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1456 break;
1457 }
1458}
1459
1460static void
Quinn Tran726b8542017-01-19 22:28:00 -08001461qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001462{
Quinn Tran726b8542017-01-19 22:28:00 -08001463 port_id_t cid; /* conflict Nport id */
Quinn Trana084fd62017-12-04 14:45:00 -08001464 u16 lid;
1465 struct fc_port *conflict_fcport;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001466
Quinn Tran726b8542017-01-19 22:28:00 -08001467 switch (ea->data[0]) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07001468 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -07001469 /*
1470 * Driver must validate login state - If PRLI not complete,
1471 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1472 * requests.
1473 */
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001474 if (ea->fcport->fc4f_nvme) {
1475 ql_dbg(ql_dbg_disc, vha, 0x2117,
1476 "%s %d %8phC post prli\n",
1477 __func__, __LINE__, ea->fcport->port_name);
1478 qla24xx_post_prli_work(vha, ea->fcport);
1479 } else {
1480 ql_dbg(ql_dbg_disc, vha, 0x20ea,
Quinn Trana084fd62017-12-04 14:45:00 -08001481 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1482 __func__, __LINE__, ea->fcport->port_name,
1483 ea->fcport->loop_id, ea->fcport->d_id.b24);
1484
1485 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1486 ea->fcport->loop_id = FC_NO_LOOP_ID;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001487 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1488 ea->fcport->logout_on_delete = 1;
Quinn Tran35158322017-08-30 10:16:50 -07001489 ea->fcport->send_els_logo = 0;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001490 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1491 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001492 break;
1493 case MBS_COMMAND_ERROR:
Quinn Tran83548fe2017-06-02 09:12:01 -07001494 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
Quinn Tran726b8542017-01-19 22:28:00 -08001495 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
1496
1497 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1498 ea->fcport->disc_state = DSC_LOGIN_FAILED;
1499 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001500 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1501 else
Quinn Tran726b8542017-01-19 22:28:00 -08001502 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001503 break;
1504 case MBS_LOOP_ID_USED:
Quinn Tran726b8542017-01-19 22:28:00 -08001505 /* data[1] = IO PARAM 1 = nport ID */
1506 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
1507 cid.b.area = (ea->iop[1] >> 8) & 0xff;
1508 cid.b.al_pa = ea->iop[1] & 0xff;
1509 cid.b.rsvd_1 = 0;
1510
Quinn Tran83548fe2017-06-02 09:12:01 -07001511 ql_dbg(ql_dbg_disc, vha, 0x20ec,
1512 "%s %d %8phC LoopID 0x%x in use post gnl\n",
1513 __func__, __LINE__, ea->fcport->port_name,
1514 ea->fcport->loop_id);
Quinn Tran726b8542017-01-19 22:28:00 -08001515
1516 if (IS_SW_RESV_ADDR(cid)) {
1517 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1518 ea->fcport->loop_id = FC_NO_LOOP_ID;
1519 } else {
1520 qla2x00_clear_loop_id(ea->fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001521 }
Quinn Tran726b8542017-01-19 22:28:00 -08001522 qla24xx_post_gnl_work(vha, ea->fcport);
1523 break;
1524 case MBS_PORT_ID_USED:
Quinn Tran83548fe2017-06-02 09:12:01 -07001525 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1526 "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n",
1527 __func__, __LINE__, ea->fcport->port_name,
1528 ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area,
1529 ea->fcport->d_id.b.al_pa);
Quinn Tran726b8542017-01-19 22:28:00 -08001530
Quinn Trana084fd62017-12-04 14:45:00 -08001531 lid = ea->iop[1] & 0xffff;
1532 qlt_find_sess_invalidate_other(vha,
1533 wwn_to_u64(ea->fcport->port_name),
1534 ea->fcport->d_id, lid, &conflict_fcport);
1535
1536 if (conflict_fcport) {
1537 /*
1538 * Another fcport share the same loop_id/nport id.
1539 * Conflict fcport needs to finish cleanup before this
1540 * fcport can proceed to login.
1541 */
1542 conflict_fcport->conflict = ea->fcport;
1543 ea->fcport->login_pause = 1;
1544
1545 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1546 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
1547 __func__, __LINE__, ea->fcport->port_name,
1548 ea->fcport->d_id.b24, lid);
1549 qla2x00_clear_loop_id(ea->fcport);
1550 qla24xx_post_gidpn_work(vha, ea->fcport);
1551 } else {
1552 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1553 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
1554 __func__, __LINE__, ea->fcport->port_name,
1555 ea->fcport->d_id.b24, lid);
1556
1557 qla2x00_clear_loop_id(ea->fcport);
1558 set_bit(lid, vha->hw->loop_id_map);
1559 ea->fcport->loop_id = lid;
1560 ea->fcport->keep_nport_handle = 0;
1561 qlt_schedule_sess_for_deletion(ea->fcport, false);
1562 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001563 break;
1564 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001565 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001566}
1567
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001568void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001569qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1570 uint16_t *data)
1571{
Quinn Tran726b8542017-01-19 22:28:00 -08001572 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Alexei Potashnika6ca8872015-07-14 16:00:44 -04001573 qlt_logo_completion_handler(fcport, data[0]);
Quinn Tran726b8542017-01-19 22:28:00 -08001574 fcport->login_gen++;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001575 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001576}
1577
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001578void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001579qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1580 uint16_t *data)
1581{
1582 if (data[0] == MBS_COMMAND_COMPLETE) {
1583 qla2x00_update_fcport(vha, fcport);
1584
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001585 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001586 }
1587
1588 /* Retry login. */
1589 fcport->flags &= ~FCF_ASYNC_SENT;
1590 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
1591 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1592 else
Andrew Vasquez80d79442011-03-30 11:46:17 -07001593 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001594
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001595 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001596}
1597
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598/****************************************************************************/
1599/* QLogic ISP2x00 Hardware Support Functions. */
1600/****************************************************************************/
1601
Saurav Kashyapfa492632012-11-21 02:40:29 -05001602static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001603qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
1604{
1605 int rval = QLA_SUCCESS;
1606 struct qla_hw_data *ha = vha->hw;
1607 uint32_t idc_major_ver, idc_minor_ver;
Saurav Kashyap711aa7f2012-08-22 14:21:15 -04001608 uint16_t config[4];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001609
1610 qla83xx_idc_lock(vha, 0);
1611
1612 /* SV: TODO: Assign initialization timeout from
1613 * flash-info / other param
1614 */
1615 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
1616 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
1617
1618 /* Set our fcoe function presence */
1619 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
1620 ql_dbg(ql_dbg_p3p, vha, 0xb077,
1621 "Error while setting DRV-Presence.\n");
1622 rval = QLA_FUNCTION_FAILED;
1623 goto exit;
1624 }
1625
1626 /* Decide the reset ownership */
1627 qla83xx_reset_ownership(vha);
1628
1629 /*
1630 * On first protocol driver load:
1631 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
1632 * register.
1633 * Others: Check compatibility with current IDC Major version.
1634 */
1635 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
1636 if (ha->flags.nic_core_reset_owner) {
1637 /* Set IDC Major version */
1638 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
1639 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
1640
1641 /* Clearing IDC-Lock-Recovery register */
1642 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
1643 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
1644 /*
1645 * Clear further IDC participation if we are not compatible with
1646 * the current IDC Major Version.
1647 */
1648 ql_log(ql_log_warn, vha, 0xb07d,
1649 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
1650 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
1651 __qla83xx_clear_drv_presence(vha);
1652 rval = QLA_FUNCTION_FAILED;
1653 goto exit;
1654 }
1655 /* Each function sets its supported Minor version. */
1656 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
1657 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
1658 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
1659
Saurav Kashyap711aa7f2012-08-22 14:21:15 -04001660 if (ha->flags.nic_core_reset_owner) {
1661 memset(config, 0, sizeof(config));
1662 if (!qla81xx_get_port_config(vha, config))
1663 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
1664 QLA8XXX_DEV_READY);
1665 }
1666
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001667 rval = qla83xx_idc_state_handler(vha);
1668
1669exit:
1670 qla83xx_idc_unlock(vha, 0);
1671
1672 return rval;
1673}
1674
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675/*
1676* qla2x00_initialize_adapter
1677* Initialize board.
1678*
1679* Input:
1680* ha = adapter block pointer.
1681*
1682* Returns:
1683* 0 = success
1684*/
1685int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001686qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687{
1688 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001689 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001690 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001691
Joe Carnucciofc90ada2016-07-06 11:14:23 -04001692 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
1693 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
1694
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001696 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001697 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001698 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -08001699 ha->flags.pci_channel_io_perm_failure = 0;
1700 ha->flags.eeh_busy = 0;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -04001701 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001702 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1703 atomic_set(&vha->loop_state, LOOP_DOWN);
1704 vha->device_flags = DFLG_NO_CABLE;
1705 vha->dpc_flags = 0;
1706 vha->flags.management_server_logged_in = 0;
1707 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 ha->isp_abort_cnt = 0;
1709 ha->beacon_blink_led = 0;
1710
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001711 set_bit(0, ha->req_qid_map);
1712 set_bit(0, ha->rsp_qid_map);
1713
Chad Dupuiscfb09192011-11-18 09:03:07 -08001714 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001715 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001716 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001718 ql_log(ql_log_warn, vha, 0x0044,
1719 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 return (rval);
1721 }
1722
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001723 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001725 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001726 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001727 ql_log(ql_log_fatal, vha, 0x004f,
1728 "Unable to validate FLASH data.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001729 return rval;
1730 }
1731
1732 if (IS_QLA8044(ha)) {
1733 qla8044_read_reset_template(vha);
1734
1735 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
1736 * If DONRESET_BIT0 is set, drivers should not set dev_state
1737 * to NEED_RESET. But if NEED_RESET is set, drivers should
1738 * should honor the reset. */
1739 if (ql2xdontresethba == 1)
1740 qla8044_set_idc_dontreset(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001741 }
1742
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001743 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001744 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001745 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001746
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001747 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001749 if (ha->flags.disable_serdes) {
1750 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001751 ql_log(ql_log_info, vha, 0x0077,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001752 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001753 return QLA_FUNCTION_FAILED;
1754 }
1755
Chad Dupuiscfb09192011-11-18 09:03:07 -08001756 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001757 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001759 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
1760 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001761 if (rval)
1762 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001763 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001764 if (rval)
1765 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07001767
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001768 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001769 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001770 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001771 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001772 "Unable to configure ISP84XX.\n");
1773 return QLA_FUNCTION_FAILED;
1774 }
1775 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001776
Quinn Tranead03852017-01-19 22:28:01 -08001777 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001778 rval = qla2x00_init_rings(vha);
1779
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001780 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001782 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001783 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001784 rval = qla84xx_init_chip(vha);
1785 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001786 ql_log(ql_log_warn, vha, 0x00d4,
1787 "Unable to initialize ISP84XX.\n");
Bart Van Assche8d2b21d2015-06-04 15:58:09 -07001788 qla84xx_put_chip(vha);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001789 }
1790 }
1791
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001792 /* Load the NIC Core f/w if we are the first protocol driver. */
1793 if (IS_QLA8031(ha)) {
1794 rval = qla83xx_nic_core_fw_load(vha);
1795 if (rval)
1796 ql_log(ql_log_warn, vha, 0x0124,
1797 "Error in initializing NIC Core f/w.\n");
1798 }
1799
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +05001800 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
1801 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -07001802
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04001803 if (IS_P3P_TYPE(ha))
1804 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
1805 else
1806 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
1807
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 return (rval);
1809}
1810
1811/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001812 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 * @ha: HA context
1814 *
1815 * Returns 0 on success.
1816 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001817int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001818qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001820 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001821 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001822 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001823 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001826 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001829 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1831
Andrew Vasquez737faec2008-10-24 15:13:45 -07001832 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001834 /* Get PCI bus information. */
1835 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07001836 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001837 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1838
1839 return QLA_SUCCESS;
1840}
1841
1842/**
1843 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
1844 * @ha: HA context
1845 *
1846 * Returns 0 on success.
1847 */
1848int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001849qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001850{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001851 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001852 unsigned long flags = 0;
1853 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001854 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001855 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001856
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001857 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001858 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001859
1860 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001861 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001862
1863 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1864 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -07001865 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001866
1867 /*
1868 * If this is a 2300 card and not 2312, reset the
1869 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
1870 * the 2310 also reports itself as a 2300 so we need to get the
1871 * fb revision level -- a 6 indicates it really is a 2300 and
1872 * not a 2310.
1873 */
1874 if (IS_QLA2300(ha)) {
1875 spin_lock_irqsave(&ha->hardware_lock, flags);
1876
1877 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001878 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001879 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07001880 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001881 break;
1882
1883 udelay(10);
1884 }
1885
1886 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001887 WRT_REG_WORD(&reg->ctrl_status, 0x20);
1888 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001889
1890 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001891 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001892
1893 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -07001894 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001895
1896 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001897 WRT_REG_WORD(&reg->ctrl_status, 0x0);
1898 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001899
1900 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001901 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001902 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07001903 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001904 break;
1905
1906 udelay(10);
1907 }
1908
1909 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1910 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001911
1912 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
1913
Andrew Vasquez737faec2008-10-24 15:13:45 -07001914 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001915
1916 /* Get PCI bus information. */
1917 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07001918 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001919 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1920
1921 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922}
1923
1924/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001925 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
1926 * @ha: HA context
1927 *
1928 * Returns 0 on success.
1929 */
1930int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001931qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001932{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001933 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001934 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001935 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001936 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001937
1938 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001939 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001940
1941 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001942 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001943 w &= ~PCI_COMMAND_INTX_DISABLE;
1944 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1945
1946 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
1947
1948 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -07001949 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
1950 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001951
1952 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07001953 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04001954 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001955
Andrew Vasquez737faec2008-10-24 15:13:45 -07001956 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001957
Auke Kok44c10132007-06-08 15:46:36 -07001958 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001959
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001960 /* Get PCI bus information. */
1961 spin_lock_irqsave(&ha->hardware_lock, flags);
1962 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
1963 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1964
1965 return QLA_SUCCESS;
1966}
1967
1968/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001969 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
1970 * @ha: HA context
1971 *
1972 * Returns 0 on success.
1973 */
1974int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001975qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001976{
1977 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001978 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001979
1980 pci_set_master(ha->pdev);
1981 pci_try_set_mwi(ha->pdev);
1982
1983 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
1984 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
1985 w &= ~PCI_COMMAND_INTX_DISABLE;
1986 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1987
1988 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07001989 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04001990 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001991
Andrew Vasquez737faec2008-10-24 15:13:45 -07001992 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001993
1994 ha->chip_revision = ha->pdev->revision;
1995
1996 return QLA_SUCCESS;
1997}
1998
1999/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 * qla2x00_isp_firmware() - Choose firmware image.
2001 * @ha: HA context
2002 *
2003 * Returns 0 on success.
2004 */
2005static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002006qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007{
2008 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07002009 uint16_t loop_id, topo, sw_cap;
2010 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002011 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012
2013 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002014 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015
2016 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002017 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
2019 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002020 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -07002021 if (rval == QLA_SUCCESS) {
2022 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002023 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -07002024 &area, &domain, &topo, &sw_cap);
2025 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 }
2027
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002028 if (rval)
2029 ql_dbg(ql_dbg_init, vha, 0x007a,
2030 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
2032 return (rval);
2033}
2034
2035/**
2036 * qla2x00_reset_chip() - Reset ISP chip.
2037 * @ha: HA context
2038 *
2039 * Returns 0 on success.
2040 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002041void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002042qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043{
2044 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002045 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002046 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 uint16_t cmd;
2049
Andrew Vasquez85880802009-12-15 21:29:46 -08002050 if (unlikely(pci_channel_offline(ha->pdev)))
2051 return;
2052
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002053 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
2055 spin_lock_irqsave(&ha->hardware_lock, flags);
2056
2057 /* Turn off master enable */
2058 cmd = 0;
2059 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2060 cmd &= ~PCI_COMMAND_MASTER;
2061 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2062
2063 if (!IS_QLA2100(ha)) {
2064 /* Pause RISC. */
2065 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
2066 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2067 for (cnt = 0; cnt < 30000; cnt++) {
2068 if ((RD_REG_WORD(&reg->hccr) &
2069 HCCR_RISC_PAUSE) != 0)
2070 break;
2071 udelay(100);
2072 }
2073 } else {
2074 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2075 udelay(10);
2076 }
2077
2078 /* Select FPM registers. */
2079 WRT_REG_WORD(&reg->ctrl_status, 0x20);
2080 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2081
2082 /* FPM Soft Reset. */
2083 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
2084 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
2085
2086 /* Toggle Fpm Reset. */
2087 if (!IS_QLA2200(ha)) {
2088 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
2089 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
2090 }
2091
2092 /* Select frame buffer registers. */
2093 WRT_REG_WORD(&reg->ctrl_status, 0x10);
2094 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2095
2096 /* Reset frame buffer FIFOs. */
2097 if (IS_QLA2200(ha)) {
2098 WRT_FB_CMD_REG(ha, reg, 0xa000);
2099 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2100 } else {
2101 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2102
2103 /* Read back fb_cmd until zero or 3 seconds max */
2104 for (cnt = 0; cnt < 3000; cnt++) {
2105 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2106 break;
2107 udelay(100);
2108 }
2109 }
2110
2111 /* Select RISC module registers. */
2112 WRT_REG_WORD(&reg->ctrl_status, 0);
2113 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2114
2115 /* Reset RISC processor. */
2116 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2117 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2118
2119 /* Release RISC processor. */
2120 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2121 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2122 }
2123
2124 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
2125 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
2126
2127 /* Reset ISP chip. */
2128 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
2129
2130 /* Wait for RISC to recover from reset. */
2131 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2132 /*
2133 * It is necessary to for a delay here since the card doesn't
2134 * respond to PCI reads during a reset. On some architectures
2135 * this will result in an MCA.
2136 */
2137 udelay(20);
2138 for (cnt = 30000; cnt; cnt--) {
2139 if ((RD_REG_WORD(&reg->ctrl_status) &
2140 CSR_ISP_SOFT_RESET) == 0)
2141 break;
2142 udelay(100);
2143 }
2144 } else
2145 udelay(10);
2146
2147 /* Reset RISC processor. */
2148 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2149
2150 WRT_REG_WORD(&reg->semaphore, 0);
2151
2152 /* Release RISC processor. */
2153 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2154 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2155
2156 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2157 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -07002158 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160
2161 udelay(100);
2162 }
2163 } else
2164 udelay(100);
2165
2166 /* Turn on master enable */
2167 cmd |= PCI_COMMAND_MASTER;
2168 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2169
2170 /* Disable RISC pause on FPM parity error. */
2171 if (!IS_QLA2100(ha)) {
2172 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
2173 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2174 }
2175
2176 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2177}
2178
2179/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002180 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2181 *
2182 * Returns 0 on success.
2183 */
Saurav Kashyapfa492632012-11-21 02:40:29 -05002184static int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002185qla81xx_reset_mpi(scsi_qla_host_t *vha)
2186{
2187 uint16_t mb[4] = {0x1010, 0, 1, 0};
2188
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002189 if (!IS_QLA81XX(vha->hw))
2190 return QLA_SUCCESS;
2191
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002192 return qla81xx_write_mpi_register(vha, mb);
2193}
2194
2195/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002196 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002197 * @ha: HA context
2198 *
2199 * Returns 0 on success.
2200 */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002201static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002202qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002203{
2204 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002205 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002206 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Bart Van Assche52c82822015-07-09 07:23:26 -07002207 uint32_t cnt;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002208 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002209 static int abts_cnt; /* ISP abort retry counts */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002210 int rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002211
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002212 spin_lock_irqsave(&ha->hardware_lock, flags);
2213
2214 /* Reset RISC. */
2215 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2216 for (cnt = 0; cnt < 30000; cnt++) {
2217 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2218 break;
2219
2220 udelay(10);
2221 }
2222
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002223 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE))
2224 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2225
2226 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2227 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2228 RD_REG_DWORD(&reg->hccr),
2229 RD_REG_DWORD(&reg->ctrl_status),
2230 (RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE));
2231
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002232 WRT_REG_DWORD(&reg->ctrl_status,
2233 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002234 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002235
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002236 udelay(100);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002237
Andrew Vasquez88c26662005-07-08 17:59:26 -07002238 /* Wait for firmware to complete NVRAM accesses. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002239 RD_REG_WORD(&reg->mailbox0);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002240 for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
2241 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez88c26662005-07-08 17:59:26 -07002242 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002243 if (cnt)
2244 udelay(5);
2245 else
2246 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez88c26662005-07-08 17:59:26 -07002247 }
2248
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002249 if (rval == QLA_SUCCESS)
2250 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2251
2252 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2253 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2254 RD_REG_DWORD(&reg->hccr),
2255 RD_REG_DWORD(&reg->mailbox0));
2256
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002257 /* Wait for soft-reset to complete. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002258 RD_REG_DWORD(&reg->ctrl_status);
Quinn Tran200ffb12016-12-23 18:06:12 -08002259 for (cnt = 0; cnt < 60; cnt++) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002260 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002261 if ((RD_REG_DWORD(&reg->ctrl_status) &
2262 CSRX_ISP_SOFT_RESET) == 0)
2263 break;
2264
2265 udelay(5);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002266 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002267 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_ISP_SOFT_RESET))
2268 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2269
2270 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2271 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2272 RD_REG_DWORD(&reg->hccr),
2273 RD_REG_DWORD(&reg->ctrl_status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002274
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002275 /* If required, do an MPI FW reset now */
2276 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2277 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2278 if (++abts_cnt < 5) {
2279 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2280 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2281 } else {
2282 /*
2283 * We exhausted the ISP abort retries. We have to
2284 * set the board offline.
2285 */
2286 abts_cnt = 0;
2287 vha->flags.online = 0;
2288 }
2289 }
2290 }
2291
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002292 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
2293 RD_REG_DWORD(&reg->hccr);
2294
2295 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
2296 RD_REG_DWORD(&reg->hccr);
2297
2298 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
2299 RD_REG_DWORD(&reg->hccr);
2300
Bart Van Assche52c82822015-07-09 07:23:26 -07002301 RD_REG_WORD(&reg->mailbox0);
Quinn Tran200ffb12016-12-23 18:06:12 -08002302 for (cnt = 60; RD_REG_WORD(&reg->mailbox0) != 0 &&
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002303 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002304 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002305 if (cnt)
2306 udelay(5);
2307 else
2308 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002309 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002310 if (rval == QLA_SUCCESS)
2311 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2312
2313 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2314 "Host Risc 0x%x, mailbox0 0x%x\n",
2315 RD_REG_DWORD(&reg->hccr),
2316 RD_REG_WORD(&reg->mailbox0));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002317
2318 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002319
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002320 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2321 "Driver in %s mode\n",
2322 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2323
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002324 if (IS_NOPOLLING_TYPE(ha))
2325 ha->isp_ops->enable_intrs(ha);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002326
2327 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002328}
2329
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002330static void
2331qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2332{
2333 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2334
2335 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2336 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2337
2338}
2339
2340static void
2341qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2342{
2343 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2344
2345 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2346 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2347}
2348
2349static void
2350qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2351{
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002352 uint32_t wd32 = 0;
2353 uint delta_msec = 100;
2354 uint elapsed_msec = 0;
2355 uint timeout_msec;
2356 ulong n;
2357
Joe Carnucciocc790762015-08-04 13:37:53 -04002358 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2359 vha->hw->pdev->subsystem_device != 0x0240)
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002360 return;
2361
Joe Carnuccio8dd7e3a2015-08-04 13:37:54 -04002362 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2363 udelay(100);
2364
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002365attempt:
2366 timeout_msec = TIMEOUT_SEMAPHORE;
2367 n = timeout_msec / delta_msec;
2368 while (n--) {
2369 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2370 qla25xx_read_risc_sema_reg(vha, &wd32);
2371 if (wd32 & RISC_SEMAPHORE)
2372 break;
2373 msleep(delta_msec);
2374 elapsed_msec += delta_msec;
2375 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2376 goto force;
2377 }
2378
2379 if (!(wd32 & RISC_SEMAPHORE))
2380 goto force;
2381
2382 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2383 goto acquired;
2384
2385 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2386 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2387 n = timeout_msec / delta_msec;
2388 while (n--) {
2389 qla25xx_read_risc_sema_reg(vha, &wd32);
2390 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2391 break;
2392 msleep(delta_msec);
2393 elapsed_msec += delta_msec;
2394 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2395 goto force;
2396 }
2397
2398 if (wd32 & RISC_SEMAPHORE_FORCE)
2399 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2400
2401 goto attempt;
2402
2403force:
2404 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2405
2406acquired:
2407 return;
2408}
2409
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002410/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002411 * qla24xx_reset_chip() - Reset ISP24xx chip.
2412 * @ha: HA context
2413 *
2414 * Returns 0 on success.
2415 */
2416void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002417qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07002418{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002419 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08002420
2421 if (pci_channel_offline(ha->pdev) &&
2422 ha->flags.pci_channel_io_perm_failure) {
2423 return;
2424 }
2425
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002426 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002427
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002428 qla25xx_manipulate_risc_semaphore(vha);
2429
Andrew Vasquez88c26662005-07-08 17:59:26 -07002430 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002431 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002432}
2433
2434/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 * qla2x00_chip_diag() - Test chip for proper operation.
2436 * @ha: HA context
2437 *
2438 * Returns 0 on success.
2439 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002440int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002441qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442{
2443 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002444 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002445 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 unsigned long flags = 0;
2447 uint16_t data;
2448 uint32_t cnt;
2449 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002450 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451
2452 /* Assume a failed state */
2453 rval = QLA_FUNCTION_FAILED;
2454
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002455 ql_dbg(ql_dbg_init, vha, 0x007b,
2456 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457
2458 spin_lock_irqsave(&ha->hardware_lock, flags);
2459
2460 /* Reset ISP chip. */
2461 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
2462
2463 /*
2464 * We need to have a delay here since the card will not respond while
2465 * in reset causing an MCA on some architectures.
2466 */
2467 udelay(20);
2468 data = qla2x00_debounce_register(&reg->ctrl_status);
2469 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2470 udelay(5);
2471 data = RD_REG_WORD(&reg->ctrl_status);
2472 barrier();
2473 }
2474
2475 if (!cnt)
2476 goto chip_diag_failed;
2477
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002478 ql_dbg(ql_dbg_init, vha, 0x007c,
2479 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480
2481 /* Reset RISC processor. */
2482 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2483 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2484
2485 /* Workaround for QLA2312 PCI parity error */
2486 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2487 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2488 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2489 udelay(5);
2490 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002491 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 }
2493 } else
2494 udelay(10);
2495
2496 if (!cnt)
2497 goto chip_diag_failed;
2498
2499 /* Check product ID of chip */
Milan P Gandhi5a68a1c2017-03-31 14:37:04 -07002500 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501
2502 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
2503 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
2504 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
2505 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
2506 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
2507 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002508 ql_log(ql_log_warn, vha, 0x0062,
2509 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2510 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
2512 goto chip_diag_failed;
2513 }
2514 ha->product_id[0] = mb[1];
2515 ha->product_id[1] = mb[2];
2516 ha->product_id[2] = mb[3];
2517 ha->product_id[3] = mb[4];
2518
2519 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002520 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
2522 else
2523 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002524 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525
2526 if (IS_QLA2200(ha) &&
2527 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
2528 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002529 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002531 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 ha->fw_transfer_size = 128;
2533 }
2534
2535 /* Wrap Incoming Mailboxes Test. */
2536 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2537
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002538 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002539 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002540 if (rval)
2541 ql_log(ql_log_warn, vha, 0x0080,
2542 "Failed mailbox send register test.\n");
2543 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 /* Flag a successful rval */
2545 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 spin_lock_irqsave(&ha->hardware_lock, flags);
2547
2548chip_diag_failed:
2549 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002550 ql_log(ql_log_info, vha, 0x0081,
2551 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552
2553 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2554
2555 return (rval);
2556}
2557
2558/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002559 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2560 * @ha: HA context
2561 *
2562 * Returns 0 on success.
2563 */
2564int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002565qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002566{
2567 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002568 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002569 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002570
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002571 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07002572 return QLA_SUCCESS;
2573
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002574 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002575
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002576 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002577 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002578 ql_log(ql_log_warn, vha, 0x0082,
2579 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002580 } else {
2581 /* Flag a successful rval */
2582 rval = QLA_SUCCESS;
2583 }
2584
2585 return rval;
2586}
2587
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002588void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002589qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002590{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002591 int rval;
2592 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002593 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002594 dma_addr_t tc_dma;
2595 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002596 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002597 struct req_que *req = ha->req_q_map[0];
2598 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002599
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002600 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002601 ql_dbg(ql_dbg_init, vha, 0x00bd,
2602 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002603 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002604 }
2605
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002606 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04002607 ha->fw_dump_cap_flags = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002608 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
2609 req_q_size = rsp_q_size = 0;
2610
2611 if (IS_QLA27XX(ha))
2612 goto try_fce;
2613
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002614 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2615 fixed_size = sizeof(struct qla2100_fw_dump);
2616 } else if (IS_QLA23XX(ha)) {
2617 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
2618 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
2619 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07002620 } else if (IS_FWI2_CAPABLE(ha)) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002621 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002622 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
2623 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002624 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
2625 else if (IS_QLA25XX(ha))
2626 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
2627 else
2628 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002629
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002630 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
2631 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002632 if (ha->mqenable) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002633 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002634 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002635 /*
2636 * Allocate maximum buffer size for all queues.
2637 * Resizing must be done at end-of-dump processing.
2638 */
2639 mq_size += ha->max_req_queues *
2640 (req->length * sizeof(request_t));
2641 mq_size += ha->max_rsp_queues *
2642 (rsp->length * sizeof(response_t));
2643 }
Arun Easi00876ae2013-03-25 02:21:37 -04002644 if (ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002645 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002646 /* Allocate memory for Fibre Channel Event Buffer. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05002647 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2648 !IS_QLA27XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002649 goto try_eft;
2650
Chad Dupuisf73cb692014-02-26 04:15:06 -05002651try_fce:
2652 if (ha->fce)
2653 dma_free_coherent(&ha->pdev->dev,
2654 FCE_SIZE, ha->fce, ha->fce_dma);
2655
2656 /* Allocate memory for Fibre Channel Event Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07002657 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
2658 GFP_KERNEL);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002659 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002660 ql_log(ql_log_warn, vha, 0x00be,
2661 "Unable to allocate (%d KB) for FCE.\n",
2662 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002663 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002664 }
2665
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002666 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002667 ha->fce_mb, &ha->fce_bufs);
2668 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002669 ql_log(ql_log_warn, vha, 0x00bf,
2670 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002671 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
2672 tc_dma);
2673 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002674 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002675 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002676 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002677 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002678
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07002679 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002680 ha->flags.fce_enabled = 1;
2681 ha->fce_dma = tc_dma;
2682 ha->fce = tc;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002683
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002684try_eft:
Chad Dupuisf73cb692014-02-26 04:15:06 -05002685 if (ha->eft)
2686 dma_free_coherent(&ha->pdev->dev,
2687 EFT_SIZE, ha->eft, ha->eft_dma);
2688
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002689 /* Allocate memory for Extended Trace Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07002690 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
2691 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002692 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002693 ql_log(ql_log_warn, vha, 0x00c1,
2694 "Unable to allocate (%d KB) for EFT.\n",
2695 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002696 goto cont_alloc;
2697 }
2698
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002699 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002700 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002701 ql_log(ql_log_warn, vha, 0x00c2,
2702 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002703 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
2704 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002705 goto cont_alloc;
2706 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002707 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002708 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002709
2710 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002711 ha->eft_dma = tc_dma;
2712 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002713 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05002714
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002715cont_alloc:
Chad Dupuisf73cb692014-02-26 04:15:06 -05002716 if (IS_QLA27XX(ha)) {
2717 if (!ha->fw_dump_template) {
2718 ql_log(ql_log_warn, vha, 0x00ba,
2719 "Failed missing fwdump template\n");
2720 return;
2721 }
2722 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
2723 ql_dbg(ql_dbg_init, vha, 0x00fa,
2724 "-> allocating fwdump (%x bytes)...\n", dump_size);
2725 goto allocate;
2726 }
2727
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002728 req_q_size = req->length * sizeof(request_t);
2729 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002730 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002731 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08002732 ha->chain_offset = dump_size;
2733 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002734
Quinn Tranb945e772017-06-13 20:47:29 -07002735 if (ha->exchoffld_buf)
2736 dump_size += sizeof(struct qla2xxx_offld_chain) +
2737 ha->exchoffld_size;
2738 if (ha->exlogin_buf)
2739 dump_size += sizeof(struct qla2xxx_offld_chain) +
2740 ha->exlogin_size;
2741
Chad Dupuisf73cb692014-02-26 04:15:06 -05002742allocate:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002743 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002744 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002745 ql_log(ql_log_warn, vha, 0x00c4,
2746 "Unable to allocate (%d KB) for firmware dump.\n",
2747 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002748
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002749 if (ha->fce) {
2750 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2751 ha->fce_dma);
2752 ha->fce = NULL;
2753 ha->fce_dma = 0;
2754 }
2755
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002756 if (ha->eft) {
2757 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
2758 ha->eft_dma);
2759 ha->eft = NULL;
2760 ha->eft_dma = 0;
2761 }
2762 return;
2763 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05002764 ha->fw_dump_len = dump_size;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002765 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002766 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002767
Chad Dupuisf73cb692014-02-26 04:15:06 -05002768 if (IS_QLA27XX(ha))
2769 return;
2770
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002771 ha->fw_dump->signature[0] = 'Q';
2772 ha->fw_dump->signature[1] = 'L';
2773 ha->fw_dump->signature[2] = 'G';
2774 ha->fw_dump->signature[3] = 'C';
Bart Van Asschead950362015-07-09 07:24:08 -07002775 ha->fw_dump->version = htonl(1);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002776
2777 ha->fw_dump->fixed_size = htonl(fixed_size);
2778 ha->fw_dump->mem_size = htonl(mem_size);
2779 ha->fw_dump->req_q_size = htonl(req_q_size);
2780 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
2781
2782 ha->fw_dump->eft_size = htonl(eft_size);
2783 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
2784 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
2785
2786 ha->fw_dump->header_size =
2787 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002788}
2789
Andrew Vasquez18e75552009-06-03 09:55:30 -07002790static int
2791qla81xx_mpi_sync(scsi_qla_host_t *vha)
2792{
2793#define MPS_MASK 0xe0
2794 int rval;
2795 uint16_t dc;
2796 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07002797
2798 if (!IS_QLA81XX(vha->hw))
2799 return QLA_SUCCESS;
2800
2801 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
2802 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002803 ql_log(ql_log_warn, vha, 0x0105,
2804 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002805 goto done;
2806 }
2807
2808 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
2809 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
2810 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002811 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002812 goto done_release;
2813 }
2814
2815 dc &= MPS_MASK;
2816 if (dc == (dw & MPS_MASK))
2817 goto done_release;
2818
2819 dw &= ~MPS_MASK;
2820 dw |= dc;
2821 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
2822 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002823 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002824 }
2825
2826done_release:
2827 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
2828 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002829 ql_log(ql_log_warn, vha, 0x006d,
2830 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002831 }
2832
2833done:
2834 return rval;
2835}
2836
Chad Dupuis8d93f552013-01-30 03:34:37 -05002837int
2838qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
2839{
2840 /* Don't try to reallocate the array */
2841 if (req->outstanding_cmds)
2842 return QLA_SUCCESS;
2843
Michael Hernandezd7459522016-12-12 14:40:07 -08002844 if (!IS_FWI2_CAPABLE(ha))
Chad Dupuis8d93f552013-01-30 03:34:37 -05002845 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
2846 else {
Quinn Tran03e8c682015-12-17 14:56:59 -05002847 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
2848 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002849 else
Quinn Tran03e8c682015-12-17 14:56:59 -05002850 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002851 }
2852
2853 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
2854 req->num_outstanding_cmds, GFP_KERNEL);
2855
2856 if (!req->outstanding_cmds) {
2857 /*
2858 * Try to allocate a minimal size just so we can get through
2859 * initialization.
2860 */
2861 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
2862 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
2863 req->num_outstanding_cmds, GFP_KERNEL);
2864
2865 if (!req->outstanding_cmds) {
2866 ql_log(ql_log_fatal, NULL, 0x0126,
2867 "Failed to allocate memory for "
2868 "outstanding_cmds for req_que %p.\n", req);
2869 req->num_outstanding_cmds = 0;
2870 return QLA_FUNCTION_FAILED;
2871 }
2872 }
2873
2874 return QLA_SUCCESS;
2875}
2876
Quinn Trane4e3a2c2017-08-23 15:05:07 -07002877#define PRINT_FIELD(_field, _flag, _str) { \
2878 if (a0->_field & _flag) {\
2879 if (p) {\
2880 strcat(ptr, "|");\
2881 ptr++;\
2882 leftover--;\
2883 } \
2884 len = snprintf(ptr, leftover, "%s", _str); \
2885 p = 1;\
2886 leftover -= len;\
2887 ptr += len; \
2888 } \
2889}
2890
2891static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
2892{
2893#define STR_LEN 64
2894 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
2895 u8 str[STR_LEN], *ptr, p;
2896 int leftover, len;
2897
2898 memset(str, 0, STR_LEN);
2899 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
2900 ql_dbg(ql_dbg_init, vha, 0x015a,
2901 "SFP MFG Name: %s\n", str);
2902
2903 memset(str, 0, STR_LEN);
2904 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
2905 ql_dbg(ql_dbg_init, vha, 0x015c,
2906 "SFP Part Name: %s\n", str);
2907
2908 /* media */
2909 memset(str, 0, STR_LEN);
2910 ptr = str;
2911 leftover = STR_LEN;
2912 p = len = 0;
2913 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
2914 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
2915 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
2916 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
2917 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
2918 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
2919 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
2920 ql_dbg(ql_dbg_init, vha, 0x0160,
2921 "SFP Media: %s\n", str);
2922
2923 /* link length */
2924 memset(str, 0, STR_LEN);
2925 ptr = str;
2926 leftover = STR_LEN;
2927 p = len = 0;
2928 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
2929 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
2930 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
2931 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
2932 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
2933 ql_dbg(ql_dbg_init, vha, 0x0196,
2934 "SFP Link Length: %s\n", str);
2935
2936 memset(str, 0, STR_LEN);
2937 ptr = str;
2938 leftover = STR_LEN;
2939 p = len = 0;
2940 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
2941 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
2942 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
2943 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
2944 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
2945 ql_dbg(ql_dbg_init, vha, 0x016e,
2946 "SFP FC Link Tech: %s\n", str);
2947
2948 if (a0->length_km)
2949 ql_dbg(ql_dbg_init, vha, 0x016f,
2950 "SFP Distant: %d km\n", a0->length_km);
2951 if (a0->length_100m)
2952 ql_dbg(ql_dbg_init, vha, 0x0170,
2953 "SFP Distant: %d m\n", a0->length_100m*100);
2954 if (a0->length_50um_10m)
2955 ql_dbg(ql_dbg_init, vha, 0x0189,
2956 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
2957 if (a0->length_62um_10m)
2958 ql_dbg(ql_dbg_init, vha, 0x018a,
2959 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
2960 if (a0->length_om4_10m)
2961 ql_dbg(ql_dbg_init, vha, 0x0194,
2962 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
2963 if (a0->length_om3_10m)
2964 ql_dbg(ql_dbg_init, vha, 0x0195,
2965 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
2966}
2967
2968
2969/*
2970 * Return Code:
2971 * QLA_SUCCESS: no action
2972 * QLA_INTERFACE_ERROR: SFP is not there.
2973 * QLA_FUNCTION_FAILED: detected New SFP
2974 */
2975int
2976qla24xx_detect_sfp(scsi_qla_host_t *vha)
2977{
2978 int rc = QLA_SUCCESS;
2979 struct sff_8247_a0 *a;
2980 struct qla_hw_data *ha = vha->hw;
2981
2982 if (!AUTO_DETECT_SFP_SUPPORT(vha))
2983 goto out;
2984
2985 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
2986 if (rc)
2987 goto out;
2988
2989 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
2990 qla2xxx_print_sfp_info(vha);
2991
2992 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
2993 /* long range */
2994 ha->flags.detected_lr_sfp = 1;
2995
2996 if (a->length_km > 5 || a->length_100m > 50)
2997 ha->long_range_distance = LR_DISTANCE_10K;
2998 else
2999 ha->long_range_distance = LR_DISTANCE_5K;
3000
3001 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3002 ql_dbg(ql_dbg_async, vha, 0x507b,
3003 "Detected Long Range SFP.\n");
3004 } else {
3005 /* short range */
3006 ha->flags.detected_lr_sfp = 0;
3007 if (ha->flags.using_lr_setting)
3008 ql_dbg(ql_dbg_async, vha, 0x5084,
3009 "Detected Short Range SFP.\n");
3010 }
3011
3012 if (!vha->flags.init_done)
3013 rc = QLA_SUCCESS;
3014out:
3015 return rc;
3016}
3017
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003018/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 * qla2x00_setup_chip() - Load and start RISC firmware.
3020 * @ha: HA context
3021 *
3022 * Returns 0 on success.
3023 */
3024static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003025qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003027 int rval;
3028 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003029 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08003030 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3031 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07003032 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08003033
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003034 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003035 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05003036 if (rval == QLA_SUCCESS) {
3037 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003038 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05003039 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07003040 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003041 }
3042
Andrew Vasquez3db06522008-01-31 12:33:49 -08003043 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3044 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3045 spin_lock_irqsave(&ha->hardware_lock, flags);
3046 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
3047 RD_REG_WORD(&reg->hccr);
3048 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3049 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050
Andrew Vasquez18e75552009-06-03 09:55:30 -07003051 qla81xx_mpi_sync(vha);
3052
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003054 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003055 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003056 ql_dbg(ql_dbg_init, vha, 0x00c9,
3057 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003059 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 if (rval == QLA_SUCCESS) {
3061 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003062 ql_dbg(ql_dbg_init, vha, 0x00ca,
3063 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003065 if (ql2xexlogins)
3066 ha->flags.exlogins_enabled = 1;
3067
Quinn Tran99e1b682017-06-02 09:12:03 -07003068 if (qla_is_exch_offld_enabled(vha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003069 ha->flags.exchoffld_enabled = 1;
3070
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003071 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07003073 if (rval == QLA_SUCCESS) {
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003074 qla24xx_detect_sfp(vha);
3075
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003076 rval = qla2x00_set_exlogins_buffer(vha);
3077 if (rval != QLA_SUCCESS)
3078 goto failed;
3079
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003080 rval = qla2x00_set_exchoffld_buffer(vha);
3081 if (rval != QLA_SUCCESS)
3082 goto failed;
3083
Giridhar Malavalia9083012010-04-12 17:59:55 -07003084enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07003085 fw_major_version = ha->fw_major_version;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003086 if (IS_P3P_TYPE(ha))
Giridhar Malavali31731672011-08-16 11:31:54 -07003087 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003088 else
3089 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07003090 if (rval != QLA_SUCCESS)
3091 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003092 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003093 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07003094 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003095 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003096 if ((!ha->max_npiv_vports) ||
3097 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003098 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003099 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003100 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003101 }
Quinn Tran03e8c682015-12-17 14:56:59 -05003102 qla2x00_get_resource_cnts(vha);
Andrew Vasquezd743de62009-03-24 09:08:15 -07003103
Chad Dupuis8d93f552013-01-30 03:34:37 -05003104 /*
3105 * Allocate the array of outstanding commands
3106 * now that we know the firmware resources.
3107 */
3108 rval = qla2x00_alloc_outstanding_cmds(ha,
3109 vha->req);
3110 if (rval != QLA_SUCCESS)
3111 goto failed;
3112
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08003113 if (!fw_major_version && ql2xallocfwdump
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003114 && !(IS_P3P_TYPE(ha)))
Giridhar Malavali08de2842011-08-16 11:31:44 -07003115 qla2x00_alloc_fw_dump(vha);
Chad Dupuis3b6e5b92013-10-30 03:38:09 -04003116 } else {
3117 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 }
3119 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003120 ql_log(ql_log_fatal, vha, 0x00cd,
3121 "ISP Firmware failed checksum.\n");
3122 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04003124 } else
3125 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126
Andrew Vasquez3db06522008-01-31 12:33:49 -08003127 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3128 /* Enable proper parity. */
3129 spin_lock_irqsave(&ha->hardware_lock, flags);
3130 if (IS_QLA2300(ha))
3131 /* SRAM parity */
3132 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
3133 else
3134 /* SRAM, Instruction RAM and GP RAM parity */
3135 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
3136 RD_REG_WORD(&reg->hccr);
3137 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3138 }
3139
Chad Dupuisf3982d82014-09-25 05:16:57 -04003140 if (IS_QLA27XX(ha))
3141 ha->flags.fac_supported = 1;
3142 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003143 uint32_t size;
3144
3145 rval = qla81xx_fac_get_sector_size(vha, &size);
3146 if (rval == QLA_SUCCESS) {
3147 ha->flags.fac_supported = 1;
3148 ha->fdt_block_size = size << 2;
3149 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003150 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003151 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3152 ha->fw_major_version, ha->fw_minor_version,
3153 ha->fw_subminor_version);
Joe Carnuccio1ca60e32014-02-26 04:15:02 -05003154
Chad Dupuisf73cb692014-02-26 04:15:06 -05003155 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003156 ha->flags.fac_supported = 0;
3157 rval = QLA_SUCCESS;
3158 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003159 }
3160 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07003161failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003163 ql_log(ql_log_fatal, vha, 0x00cf,
3164 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 }
3166
3167 return (rval);
3168}
3169
3170/**
3171 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3172 * @ha: HA context
3173 *
3174 * Beginning of request ring has initialization control block already built
3175 * by nvram config routine.
3176 *
3177 * Returns 0 on success.
3178 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003179void
3180qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181{
3182 uint16_t cnt;
3183 response_t *pkt;
3184
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003185 rsp->ring_ptr = rsp->ring;
3186 rsp->ring_index = 0;
3187 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003188 pkt = rsp->ring_ptr;
3189 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 pkt->signature = RESPONSE_PROCESSED;
3191 pkt++;
3192 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193}
3194
3195/**
3196 * qla2x00_update_fw_options() - Read and process firmware options.
3197 * @ha: HA context
3198 *
3199 * Returns 0 on success.
3200 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003201void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003202qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203{
3204 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003205 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206
3207 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003208 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209
3210 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3211 return;
3212
3213 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003214 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3215 "Serial link options.\n");
3216 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3217 (uint8_t *)&ha->fw_seriallink_options,
3218 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219
3220 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3221 if (ha->fw_seriallink_options[3] & BIT_2) {
3222 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3223
3224 /* 1G settings */
3225 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3226 emphasis = (ha->fw_seriallink_options[2] &
3227 (BIT_4 | BIT_3)) >> 3;
3228 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003229 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 rx_sens = (ha->fw_seriallink_options[0] &
3231 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3232 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3233 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3234 if (rx_sens == 0x0)
3235 rx_sens = 0x3;
3236 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3237 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3238 ha->fw_options[10] |= BIT_5 |
3239 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3240 (tx_sens & (BIT_1 | BIT_0));
3241
3242 /* 2G settings */
3243 swing = (ha->fw_seriallink_options[2] &
3244 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3245 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3246 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003247 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 rx_sens = (ha->fw_seriallink_options[1] &
3249 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3250 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3251 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3252 if (rx_sens == 0x0)
3253 rx_sens = 0x3;
3254 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3255 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3256 ha->fw_options[11] |= BIT_5 |
3257 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3258 (tx_sens & (BIT_1 | BIT_0));
3259 }
3260
3261 /* FCP2 options. */
3262 /* Return command IOCBs without waiting for an ABTS to complete. */
3263 ha->fw_options[3] |= BIT_13;
3264
3265 /* LED scheme. */
3266 if (ha->flags.enable_led_scheme)
3267 ha->fw_options[2] |= BIT_12;
3268
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003269 /* Detect ISP6312. */
3270 if (IS_QLA6312(ha))
3271 ha->fw_options[2] |= BIT_13;
3272
Giridhar Malavali088d09d2016-07-06 11:14:20 -04003273 /* Set Retry FLOGI in case of P2P connection */
3274 if (ha->operating_mode == P2P) {
3275 ha->fw_options[2] |= BIT_3;
3276 ql_dbg(ql_dbg_disc, vha, 0x2100,
3277 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3278 __func__, ha->fw_options[2]);
3279 }
3280
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003282 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283}
3284
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003285void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003286qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003287{
3288 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003289 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003290
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003291 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07003292 return;
3293
Himanshu Madhanif198caf2016-01-27 12:03:30 -05003294 /* Hold status IOCBs until ABTS response received. */
3295 if (ql2xfwholdabts)
3296 ha->fw_options[3] |= BIT_12;
3297
Giridhar Malavali088d09d2016-07-06 11:14:20 -04003298 /* Set Retry FLOGI in case of P2P connection */
3299 if (ha->operating_mode == P2P) {
3300 ha->fw_options[2] |= BIT_3;
3301 ql_dbg(ql_dbg_disc, vha, 0x2101,
3302 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3303 __func__, ha->fw_options[2]);
3304 }
3305
Quinn Tran41dc5292017-01-19 22:28:03 -08003306 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
Quinn Tran3c4810f2017-06-02 09:11:53 -07003307 if (ql2xmvasynctoatio &&
3308 (IS_QLA83XX(ha) || IS_QLA27XX(ha))) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003309 if (qla_tgt_mode_enabled(vha) ||
3310 qla_dual_mode_enabled(vha))
3311 ha->fw_options[2] |= BIT_11;
3312 else
3313 ha->fw_options[2] &= ~BIT_11;
3314 }
3315
Quinn Tranf7e761f2017-06-02 09:12:02 -07003316 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3317 /*
3318 * Tell FW to track each exchange to prevent
3319 * driver from using stale exchange.
3320 */
3321 if (qla_tgt_mode_enabled(vha) ||
3322 qla_dual_mode_enabled(vha))
3323 ha->fw_options[2] |= BIT_4;
3324 else
3325 ha->fw_options[2] &= ~BIT_4;
3326 }
3327
Quinn Tran83548fe2017-06-02 09:12:01 -07003328 ql_dbg(ql_dbg_init, vha, 0x00e8,
3329 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3330 __func__, ha->fw_options[1], ha->fw_options[2],
3331 ha->fw_options[3], vha->host->active_mode);
Quinn Tran3c4810f2017-06-02 09:11:53 -07003332
3333 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3334 qla2x00_set_fw_options(vha, ha->fw_options);
Quinn Tran41dc5292017-01-19 22:28:03 -08003335
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003336 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08003337 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003338 return;
3339
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003340 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08003341 le16_to_cpu(ha->fw_seriallink_options24[1]),
3342 le16_to_cpu(ha->fw_seriallink_options24[2]),
3343 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003344 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003345 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003346 "Unable to update Serial Link options (%x).\n", rval);
3347 }
3348}
3349
3350void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003351qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003352{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003353 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003354 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003355 struct req_que *req = ha->req_q_map[0];
3356 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003357
3358 /* Setup ring parameters in initialization control block. */
Bart Van Asschead950362015-07-09 07:24:08 -07003359 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3360 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003361 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3362 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3363 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3364 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3365 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3366 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003367
3368 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3369 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3370 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3371 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3372 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3373}
3374
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003375void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003376qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003377{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003378 struct qla_hw_data *ha = vha->hw;
Bart Van Assche118e2ef2015-07-09 07:24:27 -07003379 device_reg_t *reg = ISP_QUE_REG(ha, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003380 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3381 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003382 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003383 uint16_t rid = 0;
3384 struct req_que *req = ha->req_q_map[0];
3385 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003386
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003387 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003388 icb = (struct init_cb_24xx *)ha->init_cb;
Bart Van Asschead950362015-07-09 07:24:08 -07003389 icb->request_q_outpointer = cpu_to_le16(0);
3390 icb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003391 icb->request_q_length = cpu_to_le16(req->length);
3392 icb->response_q_length = cpu_to_le16(rsp->length);
3393 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3394 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3395 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3396 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003397
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003398 /* Setup ATIO queue dma pointers for target mode */
Bart Van Asschead950362015-07-09 07:24:08 -07003399 icb->atio_q_inpointer = cpu_to_le16(0);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003400 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3401 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
3402 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
3403
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003404 if (IS_SHADOW_REG_CAPABLE(ha))
Bart Van Asschead950362015-07-09 07:24:08 -07003405 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003406
Chad Dupuisf73cb692014-02-26 04:15:06 -05003407 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003408 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3409 icb->rid = cpu_to_le16(rid);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003410 if (ha->flags.msix_enabled) {
3411 msix = &ha->msix_entries[1];
Quinn Tran83548fe2017-06-02 09:12:01 -07003412 ql_dbg(ql_dbg_init, vha, 0x0019,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003413 "Registering vector 0x%x for base que.\n",
3414 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003415 icb->msix = cpu_to_le16(msix->entry);
3416 }
3417 /* Use alternate PCI bus number */
3418 if (MSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003419 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003420 /* Use alternate PCI devfn */
3421 if (LSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003422 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003423
Anirban Chakraborty31557542009-12-02 10:36:55 -08003424 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003425 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
3426 (ha->flags.msix_enabled)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003427 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003428 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003429 ql_dbg(ql_dbg_init, vha, 0x00fe,
3430 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08003431 } else {
Bart Van Asschead950362015-07-09 07:24:08 -07003432 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003433 }
Bart Van Asschead950362015-07-09 07:24:08 -07003434 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003435
3436 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
3437 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
3438 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
3439 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
3440 } else {
3441 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
3442 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
3443 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
3444 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
3445 }
Arun Easiaa230bc2013-01-30 03:34:39 -05003446 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003447
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003448 /* PCI posting */
3449 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003450}
3451
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452/**
3453 * qla2x00_init_rings() - Initializes firmware.
3454 * @ha: HA context
3455 *
3456 * Beginning of request ring has initialization control block already built
3457 * by nvram config routine.
3458 *
3459 * Returns 0 on success.
3460 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003461int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003462qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463{
3464 int rval;
3465 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003466 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003467 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003468 struct req_que *req;
3469 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003470 struct mid_init_cb_24xx *mid_init_cb =
3471 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472
3473 spin_lock_irqsave(&ha->hardware_lock, flags);
3474
3475 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003476 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003477 req = ha->req_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003478 if (!req || !test_bit(que, ha->req_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003479 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003480 req->out_ptr = (void *)(req->ring + req->length);
3481 *req->out_ptr = 0;
Chad Dupuis8d93f552013-01-30 03:34:37 -05003482 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003483 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003485 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003486
3487 /* Initialize firmware. */
3488 req->ring_ptr = req->ring;
3489 req->ring_index = 0;
3490 req->cnt = req->length;
3491 }
3492
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003493 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003494 rsp = ha->rsp_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003495 if (!rsp || !test_bit(que, ha->rsp_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003496 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003497 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
3498 *rsp->in_ptr = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003499 /* Initialize response queue entries */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003500 if (IS_QLAFX00(ha))
3501 qlafx00_init_response_q_entries(rsp);
3502 else
3503 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003504 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003506 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
3507 ha->tgt.atio_ring_index = 0;
3508 /* Initialize ATIO queue entries */
3509 qlt_init_atio_q_entries(vha);
3510
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003511 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512
3513 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3514
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003515 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
3516
3517 if (IS_QLAFX00(ha)) {
3518 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
3519 goto next_check;
3520 }
3521
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003523 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003525 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04003526 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003527 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08003528 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003529 }
3530
Andrew Vasquez24a08132009-03-24 09:08:16 -07003531 if (IS_FWI2_CAPABLE(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003532 mid_init_cb->options = cpu_to_le16(BIT_1);
Andrew Vasquez24a08132009-03-24 09:08:16 -07003533 mid_init_cb->init_cb.execution_throttle =
Quinn Tran03e8c682015-12-17 14:56:59 -05003534 cpu_to_le16(ha->cur_fw_xcb_count);
Joe Carnuccio40f38622016-07-06 11:14:28 -04003535 ha->flags.dport_enabled =
3536 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
3537 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
3538 (ha->flags.dport_enabled) ? "enabled" : "disabled");
3539 /* FA-WWPN Status */
Himanshu Madhani2486c622014-09-25 05:17:00 -04003540 ha->flags.fawwpn_enabled =
Joe Carnuccio40f38622016-07-06 11:14:28 -04003541 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
Quinn Tran83548fe2017-06-02 09:12:01 -07003542 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
Himanshu Madhani2486c622014-09-25 05:17:00 -04003543 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
Andrew Vasquez24a08132009-03-24 09:08:16 -07003544 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003545
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003546 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003547next_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003549 ql_log(ql_log_fatal, vha, 0x00d2,
3550 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003552 ql_dbg(ql_dbg_init, vha, 0x00d3,
3553 "Init Firmware -- success.\n");
Quinn Tran4b60c822017-06-13 20:47:21 -07003554 QLA_FW_STARTED(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555 }
3556
3557 return (rval);
3558}
3559
3560/**
3561 * qla2x00_fw_ready() - Waits for firmware ready.
3562 * @ha: HA context
3563 *
3564 * Returns 0 on success.
3565 */
3566static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003567qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568{
3569 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003570 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571 uint16_t min_wait; /* Minimum wait time if loop is down */
3572 uint16_t wait_time; /* Wait time if loop is coming ready */
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003573 uint16_t state[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003574 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003576 if (IS_QLAFX00(vha->hw))
3577 return qlafx00_fw_ready(vha);
3578
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579 rval = QLA_SUCCESS;
3580
Chad Dupuis334614912015-04-09 14:59:57 -04003581 /* Time to wait for loop down */
3582 if (IS_P3P_TYPE(ha))
3583 min_wait = 30;
3584 else
3585 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586
3587 /*
3588 * Firmware should take at most one RATOV to login, plus 5 seconds for
3589 * our own processing.
3590 */
3591 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
3592 wait_time = min_wait;
3593 }
3594
3595 /* Min wait time if loop down */
3596 mtime = jiffies + (min_wait * HZ);
3597
3598 /* wait time before firmware ready */
3599 wtime = jiffies + (wait_time * HZ);
3600
3601 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003602 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003603 ql_log(ql_log_info, vha, 0x801e,
3604 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605
3606 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05003607 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003608 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003610 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003611 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003613 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003614 ql_dbg(ql_dbg_taskm, vha, 0x801f,
3615 "fw_state=%x 84xx=%x.\n", state[0],
3616 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003617 if ((state[2] & FSTATE_LOGGED_IN) &&
3618 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003619 ql_dbg(ql_dbg_taskm, vha, 0x8028,
3620 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003621
3622 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003623 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003624 if (rval != QLA_SUCCESS) {
3625 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08003626 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003627 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003628 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003629 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003630
3631 /* Add time taken to initialize. */
3632 cs84xx_time = jiffies - cs84xx_time;
3633 wtime += cs84xx_time;
3634 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08003635 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003636 "Increasing wait time by %ld. "
3637 "New time %ld.\n", cs84xx_time,
3638 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003639 }
3640 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003641 ql_dbg(ql_dbg_taskm, vha, 0x8037,
3642 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003644 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 &ha->login_timeout, &ha->r_a_tov);
3646
3647 rval = QLA_SUCCESS;
3648 break;
3649 }
3650
3651 rval = QLA_FUNCTION_FAILED;
3652
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003653 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003654 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003656 * other than Wait for Login.
3657 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003659 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660 "Cable is unplugged...\n");
3661
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003662 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663 break;
3664 }
3665 }
3666 } else {
3667 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07003668 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08003669 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 break;
3671 }
3672
3673 if (time_after_eq(jiffies, wtime))
3674 break;
3675
3676 /* Delay for a while */
3677 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 } while (1);
3679
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003680 ql_dbg(ql_dbg_taskm, vha, 0x803a,
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003681 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
3682 state[1], state[2], state[3], state[4], state[5], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683
Chad Dupuiscfb09192011-11-18 09:03:07 -08003684 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003685 ql_log(ql_log_warn, vha, 0x803b,
3686 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687 }
3688
3689 return (rval);
3690}
3691
3692/*
3693* qla2x00_configure_hba
3694* Setup adapter context.
3695*
3696* Input:
3697* ha = adapter state pointer.
3698*
3699* Returns:
3700* 0 = success
3701*
3702* Context:
3703* Kernel context.
3704*/
3705static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003706qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707{
3708 int rval;
3709 uint16_t loop_id;
3710 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003711 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 uint8_t al_pa;
3713 uint8_t area;
3714 uint8_t domain;
3715 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003716 struct qla_hw_data *ha = vha->hw;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003717 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003718 port_id_t id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719
3720 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003721 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003722 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003724 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003725 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08003726 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003727 ql_dbg(ql_dbg_disc, vha, 0x2008,
3728 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08003729 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003730 ql_log(ql_log_warn, vha, 0x2009,
3731 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003732 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
3733 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
3734 ql_log(ql_log_warn, vha, 0x1151,
3735 "Doing link init.\n");
3736 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
3737 return rval;
3738 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003739 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08003740 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741 return (rval);
3742 }
3743
3744 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003745 ql_log(ql_log_info, vha, 0x200a,
3746 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747 return (QLA_FUNCTION_FAILED);
3748 }
3749
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003750 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751
3752 /* initialize */
3753 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
3754 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003755 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756
3757 switch (topo) {
3758 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003759 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760 ha->current_topology = ISP_CFG_NL;
3761 strcpy(connect_type, "(Loop)");
3762 break;
3763
3764 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003765 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003766 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767 ha->current_topology = ISP_CFG_FL;
3768 strcpy(connect_type, "(FL_Port)");
3769 break;
3770
3771 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003772 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773 ha->operating_mode = P2P;
3774 ha->current_topology = ISP_CFG_N;
3775 strcpy(connect_type, "(N_Port-to-N_Port)");
3776 break;
3777
3778 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003779 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003780 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 ha->operating_mode = P2P;
3782 ha->current_topology = ISP_CFG_F;
3783 strcpy(connect_type, "(F_Port)");
3784 break;
3785
3786 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003787 ql_dbg(ql_dbg_disc, vha, 0x200f,
3788 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 ha->current_topology = ISP_CFG_NL;
3790 strcpy(connect_type, "(Loop)");
3791 break;
3792 }
3793
3794 /* Save Host port and loop ID. */
3795 /* byte order - Big Endian */
Quinn Tran482c9dc2017-03-15 09:48:54 -07003796 id.b.domain = domain;
3797 id.b.area = area;
3798 id.b.al_pa = al_pa;
3799 id.b.rsvd_1 = 0;
3800 qlt_update_host_map(vha, id);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003801
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003802 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003803 ql_log(ql_log_info, vha, 0x2010,
3804 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003805 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 return(rval);
3808}
3809
Giridhar Malavalia9083012010-04-12 17:59:55 -07003810inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003811qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
3812 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003813{
3814 char *st, *en;
3815 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003816 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07003817 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003818 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003819
3820 if (memcmp(model, BINZERO, len) != 0) {
3821 strncpy(ha->model_number, model, len);
3822 st = en = ha->model_number;
3823 en += len - 1;
3824 while (en > st) {
3825 if (*en != 0x20 && *en != 0x00)
3826 break;
3827 *en-- = '\0';
3828 }
3829
3830 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07003831 if (use_tbl &&
3832 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003833 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003834 strncpy(ha->model_desc,
3835 qla2x00_model_name[index * 2 + 1],
3836 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003837 } else {
3838 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07003839 if (use_tbl &&
3840 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003841 index < QLA_MODEL_NAMES) {
3842 strcpy(ha->model_number,
3843 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003844 strncpy(ha->model_desc,
3845 qla2x00_model_name[index * 2 + 1],
3846 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003847 } else {
3848 strcpy(ha->model_number, def);
3849 }
3850 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003851 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003852 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003853 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003854}
3855
David Miller4e08df32007-04-16 12:37:43 -07003856/* On sparc systems, obtain port and node WWN from firmware
3857 * properties.
3858 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003859static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07003860{
3861#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003862 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003863 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003864 struct device_node *dp = pci_device_to_OF_node(pdev);
3865 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003866 int len;
3867
3868 val = of_get_property(dp, "port-wwn", &len);
3869 if (val && len >= WWN_SIZE)
3870 memcpy(nv->port_name, val, WWN_SIZE);
3871
3872 val = of_get_property(dp, "node-wwn", &len);
3873 if (val && len >= WWN_SIZE)
3874 memcpy(nv->node_name, val, WWN_SIZE);
3875#endif
3876}
3877
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878/*
3879* NVRAM configuration for ISP 2xxx
3880*
3881* Input:
3882* ha = adapter block pointer.
3883*
3884* Output:
3885* initialization control block in response_ring
3886* host adapters parameters in host adapter block
3887*
3888* Returns:
3889* 0 = success.
3890*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003891int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003892qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893{
David Miller4e08df32007-04-16 12:37:43 -07003894 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003895 uint8_t chksum = 0;
3896 uint16_t cnt;
3897 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003898 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003899 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003900 nvram_t *nv = ha->nvram;
3901 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003902 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903
David Miller4e08df32007-04-16 12:37:43 -07003904 rval = QLA_SUCCESS;
3905
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003907 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 ha->nvram_base = 0;
3909 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
3910 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
3911 ha->nvram_base = 0x80;
3912
3913 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003914 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003915 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
3916 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003918 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
3919 "Contents of NVRAM.\n");
3920 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
3921 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922
3923 /* Bad NVRAM data, set defaults parameters. */
3924 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
3925 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
3926 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003927 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04003928 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003929 "detected: checksum=0x%x id=%c version=0x%x.\n",
3930 chksum, nv->id[0], nv->nvram_version);
3931 ql_log(ql_log_warn, vha, 0x0065,
3932 "Falling back to "
3933 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07003934
3935 /*
3936 * Set default initialization control block.
3937 */
3938 memset(nv, 0, ha->nvram_size);
3939 nv->parameter_block_version = ICB_VERSION;
3940
3941 if (IS_QLA23XX(ha)) {
3942 nv->firmware_options[0] = BIT_2 | BIT_1;
3943 nv->firmware_options[1] = BIT_7 | BIT_5;
3944 nv->add_firmware_options[0] = BIT_5;
3945 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04003946 nv->frame_payload_size = 2048;
David Miller4e08df32007-04-16 12:37:43 -07003947 nv->special_options[1] = BIT_7;
3948 } else if (IS_QLA2200(ha)) {
3949 nv->firmware_options[0] = BIT_2 | BIT_1;
3950 nv->firmware_options[1] = BIT_7 | BIT_5;
3951 nv->add_firmware_options[0] = BIT_5;
3952 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04003953 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07003954 } else if (IS_QLA2100(ha)) {
3955 nv->firmware_options[0] = BIT_3 | BIT_1;
3956 nv->firmware_options[1] = BIT_5;
Joe Carnuccio98aee702014-09-25 05:16:38 -04003957 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07003958 }
3959
Bart Van Asschead950362015-07-09 07:24:08 -07003960 nv->max_iocb_allocation = cpu_to_le16(256);
3961 nv->execution_throttle = cpu_to_le16(16);
David Miller4e08df32007-04-16 12:37:43 -07003962 nv->retry_count = 8;
3963 nv->retry_delay = 1;
3964
3965 nv->port_name[0] = 33;
3966 nv->port_name[3] = 224;
3967 nv->port_name[4] = 139;
3968
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003969 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003970
3971 nv->login_timeout = 4;
3972
3973 /*
3974 * Set default host adapter parameters
3975 */
3976 nv->host_p[1] = BIT_2;
3977 nv->reset_delay = 5;
3978 nv->port_down_retry_count = 8;
Bart Van Asschead950362015-07-09 07:24:08 -07003979 nv->max_luns_per_target = cpu_to_le16(8);
David Miller4e08df32007-04-16 12:37:43 -07003980 nv->link_down_timeout = 60;
3981
3982 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983 }
3984
3985#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3986 /*
3987 * The SN2 does not provide BIOS emulation which means you can't change
3988 * potentially bogus BIOS settings. Force the use of default settings
3989 * for link rate and frame size. Hope that the rest of the settings
3990 * are valid.
3991 */
3992 if (ia64_platform_is("sn2")) {
Joe Carnuccio98aee702014-09-25 05:16:38 -04003993 nv->frame_payload_size = 2048;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994 if (IS_QLA23XX(ha))
3995 nv->special_options[1] = BIT_7;
3996 }
3997#endif
3998
3999 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004000 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001
4002 /*
4003 * Setup driver NVRAM options.
4004 */
4005 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4006 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4007 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4008 nv->firmware_options[1] &= ~BIT_4;
4009
4010 if (IS_QLA23XX(ha)) {
4011 nv->firmware_options[0] |= BIT_2;
4012 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004013 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004014 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015
4016 if (IS_QLA2300(ha)) {
4017 if (ha->fb_rev == FPM_2310) {
4018 strcpy(ha->model_number, "QLA2310");
4019 } else {
4020 strcpy(ha->model_number, "QLA2300");
4021 }
4022 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004023 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004024 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025 }
4026 } else if (IS_QLA2200(ha)) {
4027 nv->firmware_options[0] |= BIT_2;
4028 /*
4029 * 'Point-to-point preferred, else loop' is not a safe
4030 * connection mode setting.
4031 */
4032 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4033 (BIT_5 | BIT_4)) {
4034 /* Force 'loop preferred, else point-to-point'. */
4035 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4036 nv->add_firmware_options[0] |= BIT_5;
4037 }
4038 strcpy(ha->model_number, "QLA22xx");
4039 } else /*if (IS_QLA2100(ha))*/ {
4040 strcpy(ha->model_number, "QLA2100");
4041 }
4042
4043 /*
4044 * Copy over NVRAM RISC parameter block to initialization control block.
4045 */
4046 dptr1 = (uint8_t *)icb;
4047 dptr2 = (uint8_t *)&nv->parameter_block_version;
4048 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4049 while (cnt--)
4050 *dptr1++ = *dptr2++;
4051
4052 /* Copy 2nd half. */
4053 dptr1 = (uint8_t *)icb->add_firmware_options;
4054 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4055 while (cnt--)
4056 *dptr1++ = *dptr2++;
4057
Andrew Vasquez5341e862006-05-17 15:09:16 -07004058 /* Use alternate WWN? */
4059 if (nv->host_p[1] & BIT_7) {
4060 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4061 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4062 }
4063
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 /* Prepare nodename */
4065 if ((icb->firmware_options[1] & BIT_6) == 0) {
4066 /*
4067 * Firmware will apply the following mask if the nodename was
4068 * not provided.
4069 */
4070 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4071 icb->node_name[0] &= 0xF0;
4072 }
4073
4074 /*
4075 * Set host adapter parameters.
4076 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07004077
4078 /*
4079 * BIT_7 in the host-parameters section allows for modification to
4080 * internal driver logging.
4081 */
Andrew Vasquez01819442006-06-23 16:11:10 -07004082 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08004083 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4085 /* Always load RISC code on non ISP2[12]00 chips. */
4086 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4087 ha->flags.disable_risc_code_load = 0;
4088 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4089 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4090 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07004091 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004092 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093
4094 ha->operating_mode =
4095 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4096
4097 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4098 sizeof(ha->fw_seriallink_options));
4099
4100 /* save HBA serial number */
4101 ha->serial0 = icb->port_name[5];
4102 ha->serial1 = icb->port_name[6];
4103 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004104 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4105 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106
Bart Van Asschead950362015-07-09 07:24:08 -07004107 icb->execution_throttle = cpu_to_le16(0xFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004108
4109 ha->retry_count = nv->retry_count;
4110
4111 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07004112 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113 nv->login_timeout = ql2xlogintimeout;
4114 if (nv->login_timeout < 4)
4115 nv->login_timeout = 4;
4116 ha->login_timeout = nv->login_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004118 /* Set minimum RATOV to 100 tenths of a second. */
4119 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 ha->loop_reset_delay = nv->reset_delay;
4122
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123 /* Link Down Timeout = 0:
4124 *
4125 * When Port Down timer expires we will start returning
4126 * I/O's to OS with "DID_NO_CONNECT".
4127 *
4128 * Link Down Timeout != 0:
4129 *
4130 * The driver waits for the link to come up after link down
4131 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004132 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133 if (nv->link_down_timeout == 0) {
4134 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004135 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 } else {
4137 ha->link_down_timeout = nv->link_down_timeout;
4138 ha->loop_down_abort_time =
4139 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004140 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 /*
4143 * Need enough time to try and get the port back.
4144 */
4145 ha->port_down_retry_count = nv->port_down_retry_count;
4146 if (qlport_down_retry)
4147 ha->port_down_retry_count = qlport_down_retry;
4148 /* Set login_retry_count */
4149 ha->login_retry_count = nv->retry_count;
4150 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4151 ha->port_down_retry_count > 3)
4152 ha->login_retry_count = ha->port_down_retry_count;
4153 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4154 ha->login_retry_count = ha->port_down_retry_count;
4155 if (ql2xloginretrycount)
4156 ha->login_retry_count = ql2xloginretrycount;
4157
Bart Van Asschead950362015-07-09 07:24:08 -07004158 icb->lun_enables = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 icb->command_resource_count = 0;
4160 icb->immediate_notify_resource_count = 0;
Bart Van Asschead950362015-07-09 07:24:08 -07004161 icb->timeout = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162
4163 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4164 /* Enable RIO */
4165 icb->firmware_options[0] &= ~BIT_3;
4166 icb->add_firmware_options[0] &=
4167 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4168 icb->add_firmware_options[0] |= BIT_2;
4169 icb->response_accumulation_timer = 3;
4170 icb->interrupt_delay_timer = 5;
4171
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004172 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004174 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004175 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004176 ha->zio_mode = icb->add_firmware_options[0] &
4177 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4178 ha->zio_timer = icb->interrupt_delay_timer ?
4179 icb->interrupt_delay_timer: 2;
4180 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181 icb->add_firmware_options[0] &=
4182 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004183 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004184 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004185 ha->zio_mode = QLA_ZIO_MODE_6;
4186
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004187 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004188 "ZIO mode %d enabled; timer delay (%d us).\n",
4189 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004191 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4192 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004193 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194 }
4195 }
4196
David Miller4e08df32007-04-16 12:37:43 -07004197 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004198 ql_log(ql_log_warn, vha, 0x0069,
4199 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07004200 }
4201 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202}
4203
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004204static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004205qla2x00_rport_del(void *data)
4206{
4207 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004208 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004209 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004210
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004211 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004212 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004213 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004214 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004215 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004216 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4217 "%s %8phN. rport %p roles %x\n",
4218 __func__, fcport->port_name, rport,
4219 rport->roles);
Quinn Tran726b8542017-01-19 22:28:00 -08004220
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004221 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08004222 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004223}
4224
Linus Torvalds1da177e2005-04-16 15:20:36 -07004225/**
4226 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4227 * @ha: HA context
4228 * @flags: allocation flags
4229 *
4230 * Returns a pointer to the allocated fcport, or NULL, if none available.
4231 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004232fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004233qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234{
4235 fc_port_t *fcport;
4236
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004237 fcport = kzalloc(sizeof(fc_port_t), flags);
4238 if (!fcport)
4239 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240
4241 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004242 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243 fcport->port_type = FCT_UNKNOWN;
4244 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07004245 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004246 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247
Quinn Tran726b8542017-01-19 22:28:00 -08004248 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4249 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
Quinn Tran6cb32162017-02-13 12:18:29 -08004250 flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004251 fcport->disc_state = DSC_DELETED;
4252 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4253 fcport->deleted = QLA_SESS_DELETED;
4254 fcport->login_retry = vha->hw->login_retry_count;
4255 fcport->login_retry = 5;
4256 fcport->logout_on_delete = 1;
4257
4258 if (!fcport->ct_desc.ct_sns) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004259 ql_log(ql_log_warn, vha, 0xd049,
Quinn Tran726b8542017-01-19 22:28:00 -08004260 "Failed to allocate ct_sns request.\n");
4261 kfree(fcport);
4262 fcport = NULL;
4263 }
4264 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4265 INIT_LIST_HEAD(&fcport->gnl_entry);
4266 INIT_LIST_HEAD(&fcport->list);
4267
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004268 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269}
4270
Quinn Tran726b8542017-01-19 22:28:00 -08004271void
4272qla2x00_free_fcport(fc_port_t *fcport)
4273{
4274 if (fcport->ct_desc.ct_sns) {
4275 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4276 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4277 fcport->ct_desc.ct_sns_dma);
4278
4279 fcport->ct_desc.ct_sns = NULL;
4280 }
4281 kfree(fcport);
4282}
4283
Linus Torvalds1da177e2005-04-16 15:20:36 -07004284/*
4285 * qla2x00_configure_loop
4286 * Updates Fibre Channel Device Database with what is actually on loop.
4287 *
4288 * Input:
4289 * ha = adapter block pointer.
4290 *
4291 * Returns:
4292 * 0 = success.
4293 * 1 = error.
4294 * 2 = database was full and device was not configured.
4295 */
4296static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004297qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298{
4299 int rval;
4300 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004301 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 rval = QLA_SUCCESS;
4303
4304 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004305 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4306 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004308 ql_dbg(ql_dbg_disc, vha, 0x2013,
4309 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310 return (rval);
4311 }
4312 }
4313
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004314 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004315 ql_dbg(ql_dbg_disc, vha, 0x2014,
4316 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317
4318 /*
4319 * If we have both an RSCN and PORT UPDATE pending then handle them
4320 * both at the same time.
4321 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004322 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4323 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324
Michael Hernandez3064ff32009-12-15 21:29:44 -08004325 qla2x00_get_data_rate(vha);
4326
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327 /* Determine what we need to do */
4328 if (ha->current_topology == ISP_CFG_FL &&
4329 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4330
Linus Torvalds1da177e2005-04-16 15:20:36 -07004331 set_bit(RSCN_UPDATE, &flags);
4332
4333 } else if (ha->current_topology == ISP_CFG_F &&
4334 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4335
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336 set_bit(RSCN_UPDATE, &flags);
4337 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4338
Andrew Vasquez21333b42006-05-17 15:09:56 -07004339 } else if (ha->current_topology == ISP_CFG_N) {
4340 clear_bit(RSCN_UPDATE, &flags);
Quinn Tran41dc5292017-01-19 22:28:03 -08004341 } else if (ha->current_topology == ISP_CFG_NL) {
4342 clear_bit(RSCN_UPDATE, &flags);
4343 set_bit(LOCAL_LOOP_UPDATE, &flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004344 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004345 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346 set_bit(RSCN_UPDATE, &flags);
4347 set_bit(LOCAL_LOOP_UPDATE, &flags);
4348 }
4349
4350 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004351 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4352 ql_dbg(ql_dbg_disc, vha, 0x2015,
4353 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08004355 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004356 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357 }
4358
4359 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004360 if (LOOP_TRANSITION(vha)) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004361 ql_dbg(ql_dbg_disc, vha, 0x2099,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004362 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004363 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004364 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004365 else
4366 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367 }
4368
4369 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004370 if (atomic_read(&vha->loop_down_timer) ||
4371 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004372 rval = QLA_FUNCTION_FAILED;
4373 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004374 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004375 ql_dbg(ql_dbg_disc, vha, 0x2069,
4376 "LOOP READY.\n");
Quinn Tranec7193e2017-03-15 09:48:55 -07004377 ha->flags.fw_init_done = 1;
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05004378
4379 /*
4380 * Process any ATIO queue entries that came in
4381 * while we weren't online.
4382 */
Quinn Tranead03852017-01-19 22:28:01 -08004383 if (qla_tgt_mode_enabled(vha) ||
4384 qla_dual_mode_enabled(vha)) {
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05004385 if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) {
4386 spin_lock_irqsave(&ha->tgt.atio_lock,
4387 flags);
4388 qlt_24xx_process_atio_queue(vha, 0);
4389 spin_unlock_irqrestore(
4390 &ha->tgt.atio_lock, flags);
4391 } else {
4392 spin_lock_irqsave(&ha->hardware_lock,
4393 flags);
4394 qlt_24xx_process_atio_queue(vha, 1);
4395 spin_unlock_irqrestore(
4396 &ha->hardware_lock, flags);
4397 }
4398 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399 }
4400 }
4401
4402 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004403 ql_dbg(ql_dbg_disc, vha, 0x206a,
4404 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004406 ql_dbg(ql_dbg_disc, vha, 0x206b,
4407 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408 }
4409
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07004410 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004411 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004412 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004413 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004414 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004415 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417 }
4418
4419 return (rval);
4420}
4421
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004422/*
4423 * N2N Login
4424 * Updates Fibre Channel Device Database with local loop devices.
4425 *
4426 * Input:
4427 * ha = adapter block pointer.
4428 *
4429 * Returns:
4430 */
4431static int qla24xx_n2n_handle_login(struct scsi_qla_host *vha,
4432 fc_port_t *fcport)
4433{
4434 struct qla_hw_data *ha = vha->hw;
4435 int res = QLA_SUCCESS, rval;
4436 int greater_wwpn = 0;
4437 int logged_in = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004439 if (ha->current_topology != ISP_CFG_N)
4440 return res;
4441
4442 if (wwn_to_u64(vha->port_name) >
4443 wwn_to_u64(vha->n2n_port_name)) {
4444 ql_dbg(ql_dbg_disc, vha, 0x2002,
4445 "HBA WWPN is greater %llx > target %llx\n",
4446 wwn_to_u64(vha->port_name),
4447 wwn_to_u64(vha->n2n_port_name));
4448 greater_wwpn = 1;
4449 fcport->d_id.b24 = vha->n2n_id;
4450 }
4451
4452 fcport->loop_id = vha->loop_id;
4453 fcport->fc4f_nvme = 0;
4454 fcport->query = 1;
4455
4456 ql_dbg(ql_dbg_disc, vha, 0x4001,
4457 "Initiate N2N login handler: HBA port_id=%06x loopid=%d\n",
4458 fcport->d_id.b24, vha->loop_id);
4459
4460 /* Fill in member data. */
4461 if (!greater_wwpn) {
4462 rval = qla2x00_get_port_database(vha, fcport, 0);
4463 ql_dbg(ql_dbg_disc, vha, 0x1051,
4464 "Remote login-state (%x/%x) port_id=%06x loop_id=%x, rval=%d\n",
4465 fcport->current_login_state, fcport->last_login_state,
4466 fcport->d_id.b24, fcport->loop_id, rval);
4467
4468 if (((fcport->current_login_state & 0xf) == 0x4) ||
4469 ((fcport->current_login_state & 0xf) == 0x6))
4470 logged_in = 1;
4471 }
4472
4473 if (logged_in || greater_wwpn) {
4474 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
4475 qla_nvme_register_hba(vha);
4476
4477 /* Set connected N_Port d_id */
4478 if (vha->flags.nvme_enabled)
4479 fcport->fc4f_nvme = 1;
4480
4481 fcport->scan_state = QLA_FCPORT_FOUND;
4482 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4483 fcport->disc_state = DSC_GNL;
4484 fcport->n2n_flag = 1;
4485 fcport->flags = 3;
4486 vha->hw->flags.gpsc_supported = 0;
4487
4488 if (greater_wwpn) {
4489 ql_dbg(ql_dbg_disc, vha, 0x20e5,
4490 "%s %d PLOGI ELS %8phC\n",
4491 __func__, __LINE__, fcport->port_name);
4492
4493 res = qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
4494 fcport, fcport->d_id);
4495 }
4496
4497 if (res != QLA_SUCCESS) {
4498 ql_log(ql_log_info, vha, 0xd04d,
4499 "PLOGI Failed: portid=%06x - retrying\n",
4500 fcport->d_id.b24);
4501 res = QLA_SUCCESS;
4502 } else {
4503 /* State 0x6 means FCP PRLI complete */
4504 if ((fcport->current_login_state & 0xf) == 0x6) {
4505 ql_dbg(ql_dbg_disc, vha, 0x2118,
4506 "%s %d %8phC post GPDB work\n",
4507 __func__, __LINE__, fcport->port_name);
4508 fcport->chip_reset =
4509 vha->hw->base_qpair->chip_reset;
4510 qla24xx_post_gpdb_work(vha, fcport, 0);
4511 } else {
4512 ql_dbg(ql_dbg_disc, vha, 0x2118,
4513 "%s %d %8phC post NVMe PRLI\n",
4514 __func__, __LINE__, fcport->port_name);
4515 qla24xx_post_prli_work(vha, fcport);
4516 }
4517 }
4518 } else {
4519 /* Wait for next database change */
4520 set_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags);
4521 }
4522
4523 return res;
4524}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525
4526/*
4527 * qla2x00_configure_local_loop
4528 * Updates Fibre Channel Device Database with local loop devices.
4529 *
4530 * Input:
4531 * ha = adapter block pointer.
4532 *
4533 * Returns:
4534 * 0 = success.
4535 */
4536static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004537qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004538{
4539 int rval, rval2;
4540 int found_devs;
4541 int found;
4542 fc_port_t *fcport, *new_fcport;
4543
4544 uint16_t index;
4545 uint16_t entries;
4546 char *id_iter;
4547 uint16_t loop_id;
4548 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004549 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08004550 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551
4552 found_devs = 0;
4553 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08004554 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004555
Linus Torvalds1da177e2005-04-16 15:20:36 -07004556 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08004557 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004558 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004559 &entries);
4560 if (rval != QLA_SUCCESS)
4561 goto cleanup_allocation;
4562
Quinn Tran83548fe2017-06-02 09:12:01 -07004563 ql_dbg(ql_dbg_disc, vha, 0x2011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004564 "Entries in ID list (%d).\n", entries);
4565 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
4566 (uint8_t *)ha->gid_list,
4567 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568
4569 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004570 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004571 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004572 ql_log(ql_log_warn, vha, 0x2012,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004573 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574 rval = QLA_MEMORY_ALLOC_FAILED;
4575 goto cleanup_allocation;
4576 }
4577 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4578
4579 /*
4580 * Mark local devices that were present with FCF_DEVICE_LOST for now.
4581 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004582 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004583 if (atomic_read(&fcport->state) == FCS_ONLINE &&
4584 fcport->port_type != FCT_BROADCAST &&
4585 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
4586
Quinn Tran83548fe2017-06-02 09:12:01 -07004587 ql_dbg(ql_dbg_disc, vha, 0x2096,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004588 "Marking port lost loop_id=0x%04x.\n",
4589 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590
Quinn Tran41dc5292017-01-19 22:28:03 -08004591 qla2x00_mark_device_lost(vha, fcport, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592 }
4593 }
4594
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004595 /* Inititae N2N login. */
4596 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
4597 rval = qla24xx_n2n_handle_login(vha, new_fcport);
4598 if (rval != QLA_SUCCESS)
4599 goto cleanup_allocation;
4600 return QLA_SUCCESS;
4601 }
4602
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603 /* Add devices to port list. */
4604 id_iter = (char *)ha->gid_list;
4605 for (index = 0; index < entries; index++) {
4606 domain = ((struct gid_list_info *)id_iter)->domain;
4607 area = ((struct gid_list_info *)id_iter)->area;
4608 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004609 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610 loop_id = (uint16_t)
4611 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004612 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613 loop_id = le16_to_cpu(
4614 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004615 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616
4617 /* Bypass reserved domain fields. */
4618 if ((domain & 0xf0) == 0xf0)
4619 continue;
4620
4621 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004622 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004623 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004624 continue;
4625
4626 /* Bypass invalid local loop ID. */
4627 if (loop_id > LAST_LOCAL_LOOP_ID)
4628 continue;
4629
Quinn Tran41dc5292017-01-19 22:28:03 -08004630 memset(new_fcport->port_name, 0, WWN_SIZE);
Arun Easi370d5502012-08-22 14:21:10 -04004631
Linus Torvalds1da177e2005-04-16 15:20:36 -07004632 /* Fill in member data. */
4633 new_fcport->d_id.b.domain = domain;
4634 new_fcport->d_id.b.area = area;
4635 new_fcport->d_id.b.al_pa = al_pa;
4636 new_fcport->loop_id = loop_id;
Quinn Tran41dc5292017-01-19 22:28:03 -08004637
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004638 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004639 if (rval2 != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004640 ql_dbg(ql_dbg_disc, vha, 0x2097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004641 "Failed to retrieve fcport information "
4642 "-- get_port_database=%x, loop_id=0x%04x.\n",
4643 rval2, new_fcport->loop_id);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004644 /* Skip retry if N2N */
4645 if (ha->current_topology != ISP_CFG_N) {
4646 ql_dbg(ql_dbg_disc, vha, 0x2105,
4647 "Scheduling resync.\n");
4648 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4649 continue;
4650 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651 }
4652
Quinn Tran41dc5292017-01-19 22:28:03 -08004653 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654 /* Check for matching device in port list. */
4655 found = 0;
4656 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004657 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004658 if (memcmp(new_fcport->port_name, fcport->port_name,
4659 WWN_SIZE))
4660 continue;
4661
Shyam Sundarddb9b122009-03-24 09:08:10 -07004662 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004663 fcport->loop_id = new_fcport->loop_id;
4664 fcport->port_type = new_fcport->port_type;
4665 fcport->d_id.b24 = new_fcport->d_id.b24;
4666 memcpy(fcport->node_name, new_fcport->node_name,
4667 WWN_SIZE);
4668
Quinn Tran41dc5292017-01-19 22:28:03 -08004669 if (!fcport->login_succ) {
4670 vha->fcport_count++;
4671 fcport->login_succ = 1;
4672 fcport->disc_state = DSC_LOGIN_COMPLETE;
4673 }
4674
Linus Torvalds1da177e2005-04-16 15:20:36 -07004675 found++;
4676 break;
4677 }
4678
4679 if (!found) {
4680 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004681 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682
4683 /* Allocate a new replacement fcport. */
4684 fcport = new_fcport;
Quinn Tran41dc5292017-01-19 22:28:03 -08004685 if (!fcport->login_succ) {
4686 vha->fcport_count++;
4687 fcport->login_succ = 1;
4688 fcport->disc_state = DSC_LOGIN_COMPLETE;
4689 }
4690
4691 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4692
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004693 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Quinn Tran41dc5292017-01-19 22:28:03 -08004694
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004696 ql_log(ql_log_warn, vha, 0xd031,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004697 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698 rval = QLA_MEMORY_ALLOC_FAILED;
4699 goto cleanup_allocation;
4700 }
Quinn Tran41dc5292017-01-19 22:28:03 -08004701 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004702 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4703 }
4704
Quinn Tran41dc5292017-01-19 22:28:03 -08004705 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4706
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004707 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004708 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004709
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004710 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711
4712 found_devs++;
4713 }
4714
4715cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08004716 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004717
4718 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004719 ql_dbg(ql_dbg_disc, vha, 0x2098,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004720 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721 }
4722
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723 return (rval);
4724}
4725
4726static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004727qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004728{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004729 int rval;
Quinn Tran93f2bd62014-09-25 05:16:53 -04004730 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004731 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004732
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07004733 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004734 return;
4735
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07004736 if (atomic_read(&fcport->state) != FCS_ONLINE)
4737 return;
4738
Andrew Vasquez39bd9622007-09-20 14:07:34 -07004739 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
4740 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004741 return;
4742
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004743 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004744 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004745 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004746 ql_dbg(ql_dbg_disc, vha, 0x2004,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004747 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
4748 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004749 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004750 ql_dbg(ql_dbg_disc, vha, 0x2005,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004751 "iIDMA adjusted to %s GB/s on %8phN.\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -05004752 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004753 fcport->port_name);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004754 }
4755}
4756
Quinn Tran726b8542017-01-19 22:28:00 -08004757/* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
Adrian Bunk23be3312006-11-24 02:46:01 +01004758static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004759qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05004760{
4761 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05004762 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004763 unsigned long flags;
8482e1182005-04-17 15:04:54 -05004764
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07004765 rport_ids.node_name = wwn_to_u64(fcport->node_name);
4766 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05004767 rport_ids.port_id = fcport->d_id.b.domain << 16 |
4768 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
4769 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004770 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07004771 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004772 ql_log(ql_log_warn, vha, 0x2006,
4773 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07004774 return;
4775 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004776
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004777 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004778 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004779 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004780
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004781 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07004782
4783 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05004784 if (fcport->port_type == FCT_INITIATOR)
4785 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
4786 if (fcport->port_type == FCT_TARGET)
4787 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Quinn Tran726b8542017-01-19 22:28:00 -08004788
Quinn Tran83548fe2017-06-02 09:12:01 -07004789 ql_dbg(ql_dbg_disc, vha, 0x20ee,
4790 "%s %8phN. rport %p is %s mode\n",
4791 __func__, fcport->port_name, rport,
4792 (fcport->port_type == FCT_TARGET) ? "tgt" : "ini");
Quinn Tran726b8542017-01-19 22:28:00 -08004793
Andrew Vasquez77d74142005-07-08 18:00:36 -07004794 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05004795}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004796
4797/*
Adrian Bunk23be3312006-11-24 02:46:01 +01004798 * qla2x00_update_fcport
4799 * Updates device on list.
4800 *
4801 * Input:
4802 * ha = adapter block pointer.
4803 * fcport = port structure pointer.
4804 *
4805 * Return:
4806 * 0 - Success
4807 * BIT_0 - error
4808 *
4809 * Context:
4810 * Kernel context.
4811 */
4812void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004813qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01004814{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004815 fcport->vha = vha;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004816
Quinn Tran726b8542017-01-19 22:28:00 -08004817 if (IS_SW_RESV_ADDR(fcport->d_id))
4818 return;
4819
Quinn Tran83548fe2017-06-02 09:12:01 -07004820 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
Quinn Tran726b8542017-01-19 22:28:00 -08004821 __func__, fcport->port_name);
4822
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004823 if (IS_QLAFX00(vha->hw)) {
4824 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004825 goto reg_port;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004826 }
Adrian Bunk23be3312006-11-24 02:46:01 +01004827 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004828 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Quinn Tran726b8542017-01-19 22:28:00 -08004829 fcport->disc_state = DSC_LOGIN_COMPLETE;
4830 fcport->deleted = 0;
4831 fcport->logout_on_delete = 1;
Adrian Bunk23be3312006-11-24 02:46:01 +01004832
Duane Grigsbye84067d2017-06-21 13:48:43 -07004833 if (fcport->fc4f_nvme) {
4834 qla_nvme_register_remote(vha, fcport);
4835 return;
4836 }
4837
Joe Carnuccio1f93da522012-11-21 02:40:38 -05004838 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004839 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08004840 qla24xx_update_fcport_fcp_prio(vha, fcport);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004841
4842reg_port:
Quinn Tran726b8542017-01-19 22:28:00 -08004843 switch (vha->host->active_mode) {
4844 case MODE_INITIATOR:
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004845 qla2x00_reg_remote_port(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08004846 break;
4847 case MODE_TARGET:
4848 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
4849 !vha->vha_tgt.qla_tgt->tgt_stopped)
4850 qlt_fc_port_added(vha, fcport);
4851 break;
4852 case MODE_DUAL:
4853 qla2x00_reg_remote_port(vha, fcport);
4854 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
4855 !vha->vha_tgt.qla_tgt->tgt_stopped)
4856 qlt_fc_port_added(vha, fcport);
4857 break;
4858 default:
4859 break;
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004860 }
Adrian Bunk23be3312006-11-24 02:46:01 +01004861}
4862
4863/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864 * qla2x00_configure_fabric
4865 * Setup SNS devices with loop ID's.
4866 *
4867 * Input:
4868 * ha = adapter block pointer.
4869 *
4870 * Returns:
4871 * 0 = success.
4872 * BIT_0 = error
4873 */
4874static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004875qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876{
Arun Easib3b02e62012-02-09 11:15:39 -08004877 int rval;
Quinn Tran726b8542017-01-19 22:28:00 -08004878 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004879 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004880 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004882 struct qla_hw_data *ha = vha->hw;
Alexei Potashnikdf673272015-07-14 16:00:46 -04004883 int discovery_gen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004884
4885 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07004886 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004887 loop_id = NPH_F_PORT;
4888 else
4889 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004890 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004891 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004892 ql_dbg(ql_dbg_disc, vha, 0x20a0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004893 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004894
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004895 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004896 return (QLA_SUCCESS);
4897 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004898 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899
Quinn Tran41dc5292017-01-19 22:28:03 -08004900
4901 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
4902 rval = qla2x00_send_change_request(vha, 0x3, 0);
4903 if (rval != QLA_SUCCESS)
4904 ql_log(ql_log_warn, vha, 0x121,
4905 "Failed to enable receiving of RSCN requests: 0x%x.\n",
4906 rval);
4907 }
4908
4909
Linus Torvalds1da177e2005-04-16 15:20:36 -07004910 do {
Quinn Tran726b8542017-01-19 22:28:00 -08004911 qla2x00_mgmt_svr_login(vha);
4912
Andrew Vasquezcca53352005-08-26 19:08:30 -07004913 /* FDMI support. */
4914 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004915 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
4916 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07004917
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918 /* Ensure we are logged into the SNS. */
Joe Carnuccioa14c7712017-08-23 15:05:12 -07004919 loop_id = NPH_SNS_LID(ha);
Chad Dupuis0b91d112012-02-09 11:15:42 -08004920 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
4921 0xfc, mb, BIT_1|BIT_0);
Joe Carnuccioa14c7712017-08-23 15:05:12 -07004922 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
4923 ql_dbg(ql_dbg_disc, vha, 0x20a1,
4924 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
4925 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
Chad Dupuis0b91d112012-02-09 11:15:42 -08004926 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05004927 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08004928 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004929 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
4930 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004931 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07004932 ql_dbg(ql_dbg_disc, vha, 0x20a2,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004933 "Register FC-4 TYPE failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004934 if (test_bit(LOOP_RESYNC_NEEDED,
4935 &vha->dpc_flags))
4936 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004937 }
Duane Grigsbyd3bae932017-06-21 13:48:44 -07004938 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004939 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07004940 ql_dbg(ql_dbg_disc, vha, 0x209a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004941 "Register FC-4 Features failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004942 if (test_bit(LOOP_RESYNC_NEEDED,
4943 &vha->dpc_flags))
4944 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945 }
Duane Grigsbyd3bae932017-06-21 13:48:44 -07004946 if (vha->flags.nvme_enabled) {
4947 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
4948 ql_dbg(ql_dbg_disc, vha, 0x2049,
4949 "Register NVME FC Type Features failed.\n");
4950 }
4951 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004952 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004953 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07004954 ql_dbg(ql_dbg_disc, vha, 0x2104,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004955 "Register Node Name failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004956 if (test_bit(LOOP_RESYNC_NEEDED,
4957 &vha->dpc_flags))
4958 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004959 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004960 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07004961 ql_dbg(ql_dbg_disc, vha, 0x209b,
Colin Ian King0bf0efa2017-06-30 14:47:41 +01004962 "Register Symbolic Node Name failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004963 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4964 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004965 }
4966 }
4967
Joe Carnuccio827210b2013-02-08 01:57:57 -05004968 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4969 fcport->scan_state = QLA_FCPORT_SCAN;
4970 }
4971
Alexei Potashnikdf673272015-07-14 16:00:46 -04004972 /* Mark the time right before querying FW for connected ports.
4973 * This process is long, asynchronous and by the time it's done,
4974 * collected information might not be accurate anymore. E.g.
4975 * disconnected port might have re-connected and a brand new
4976 * session has been created. In this case session's generation
4977 * will be newer than discovery_gen. */
4978 qlt_do_generation_tick(vha, &discovery_gen);
4979
Quinn Tran726b8542017-01-19 22:28:00 -08004980 rval = qla2x00_find_all_fabric_devs(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004981 if (rval != QLA_SUCCESS)
4982 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004983 } while (0);
4984
Duane Grigsbye84067d2017-06-21 13:48:43 -07004985 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
4986 qla_nvme_register_hba(vha);
4987
Quinn Tran726b8542017-01-19 22:28:00 -08004988 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004989 ql_dbg(ql_dbg_disc, vha, 0x2068,
4990 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004991
4992 return (rval);
4993}
4994
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995/*
4996 * qla2x00_find_all_fabric_devs
4997 *
4998 * Input:
4999 * ha = adapter block pointer.
5000 * dev = database device entry pointer.
5001 *
5002 * Returns:
5003 * 0 = success.
5004 *
5005 * Context:
5006 * Kernel context.
5007 */
5008static int
Quinn Tran726b8542017-01-19 22:28:00 -08005009qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010{
5011 int rval;
5012 uint16_t loop_id;
Quinn Tran726b8542017-01-19 22:28:00 -08005013 fc_port_t *fcport, *new_fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005014 int found;
5015
5016 sw_info_t *swl;
5017 int swl_idx;
5018 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07005019 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005020 struct qla_hw_data *ha = vha->hw;
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05005021 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran726b8542017-01-19 22:28:00 -08005022 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005023
5024 rval = QLA_SUCCESS;
5025
5026 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08005027 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08005028 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08005029 GFP_KERNEL);
5030 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02005031 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032 /*EMPTY*/
Quinn Tran83548fe2017-06-02 09:12:01 -07005033 ql_dbg(ql_dbg_disc, vha, 0x209c,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005034 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08005036 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005037 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005039 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5040 return rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005041 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005042 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005043 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5044 return rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005045 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005046 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005047 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5048 return rval;
Quinn Tran726b8542017-01-19 22:28:00 -08005049 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5050 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005051 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5052 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005053 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005054
5055 /* If other queries succeeded probe for FC-4 type */
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005056 if (swl) {
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005057 qla2x00_gff_id(vha, swl);
Quinn Tranb98ae0d2017-06-02 09:12:00 -07005058 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5059 return rval;
5060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061 }
5062 swl_idx = 0;
5063
5064 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005065 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005066 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005067 ql_log(ql_log_warn, vha, 0x209d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005068 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069 return (QLA_MEMORY_ALLOC_FAILED);
5070 }
5071 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005072 /* Set start port ID scan at adapter ID. */
5073 first_dev = 1;
5074 last_dev = 0;
5075
5076 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005077 loop_id = ha->min_external_loopid;
5078 for (; loop_id <= ha->max_loop_id; loop_id++) {
5079 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005080 continue;
5081
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07005082 if (ha->current_topology == ISP_CFG_FL &&
5083 (atomic_read(&vha->loop_down_timer) ||
5084 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08005085 atomic_set(&vha->loop_down_timer, 0);
5086 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5087 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08005089 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005090
5091 if (swl != NULL) {
5092 if (last_dev) {
5093 wrap.b24 = new_fcport->d_id.b24;
5094 } else {
5095 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5096 memcpy(new_fcport->node_name,
5097 swl[swl_idx].node_name, WWN_SIZE);
5098 memcpy(new_fcport->port_name,
5099 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005100 memcpy(new_fcport->fabric_port_name,
5101 swl[swl_idx].fabric_port_name, WWN_SIZE);
5102 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005103 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005105 new_fcport->nvme_flag = 0;
Darren Trap1a28faa2017-08-30 10:16:48 -07005106 new_fcport->fc4f_nvme = 0;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005107 if (vha->flags.nvme_enabled &&
5108 swl[swl_idx].fc4f_nvme) {
5109 new_fcport->fc4f_nvme =
5110 swl[swl_idx].fc4f_nvme;
5111 ql_log(ql_log_info, vha, 0x2131,
5112 "FOUND: NVME port %8phC as FC Type 28h\n",
5113 new_fcport->port_name);
5114 }
5115
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5117 last_dev = 1;
5118 }
5119 swl_idx++;
5120 }
5121 } else {
5122 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005123 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005124 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005125 ql_log(ql_log_warn, vha, 0x209e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005126 "SNS scan failed -- assuming "
5127 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128 rval = QLA_SUCCESS;
5129 break;
5130 }
5131 }
5132
5133 /* If wrap on switch device list, exit. */
5134 if (first_dev) {
5135 wrap.b24 = new_fcport->d_id.b24;
5136 first_dev = 0;
5137 } else if (new_fcport->d_id.b24 == wrap.b24) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005138 ql_dbg(ql_dbg_disc, vha, 0x209f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005139 "Device wrap (%02x%02x%02x).\n",
5140 new_fcport->d_id.b.domain,
5141 new_fcport->d_id.b.area,
5142 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143 break;
5144 }
5145
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005146 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005147 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005148 continue;
5149
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005150 /* Bypass virtual ports of the same host. */
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05005151 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5152 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005153
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07005154 /* Bypass if same domain and area of adapter. */
5155 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005156 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07005157 ISP_CFG_FL)
5158 continue;
5159
Linus Torvalds1da177e2005-04-16 15:20:36 -07005160 /* Bypass reserved domain fields. */
5161 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5162 continue;
5163
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005164 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07005165 if (ql2xgffidenable &&
5166 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5167 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005168 continue;
5169
Quinn Tran726b8542017-01-19 22:28:00 -08005170 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5171
Linus Torvalds1da177e2005-04-16 15:20:36 -07005172 /* Locate matching device in database. */
5173 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005174 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005175 if (memcmp(new_fcport->port_name, fcport->port_name,
5176 WWN_SIZE))
5177 continue;
5178
Joe Carnuccio827210b2013-02-08 01:57:57 -05005179 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08005180
Linus Torvalds1da177e2005-04-16 15:20:36 -07005181 found++;
5182
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005183 /* Update port state. */
5184 memcpy(fcport->fabric_port_name,
5185 new_fcport->fabric_port_name, WWN_SIZE);
5186 fcport->fp_speed = new_fcport->fp_speed;
5187
Linus Torvalds1da177e2005-04-16 15:20:36 -07005188 /*
Roland Dreierb2032fd2015-07-14 16:00:42 -04005189 * If address the same and state FCS_ONLINE
5190 * (or in target mode), nothing changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005191 */
5192 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
Roland Dreierb2032fd2015-07-14 16:00:42 -04005193 (atomic_read(&fcport->state) == FCS_ONLINE ||
Quinn Tran726b8542017-01-19 22:28:00 -08005194 (vha->host->active_mode == MODE_TARGET))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005195 break;
5196 }
5197
5198 /*
5199 * If device was not a fabric device before.
5200 */
5201 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5202 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04005203 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005204 fcport->flags |= (FCF_FABRIC_DEVICE |
5205 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005206 break;
5207 }
5208
5209 /*
5210 * Port ID changed or device was marked to be updated;
5211 * Log it out if still logged in and mark it for
5212 * relogin later.
5213 */
Quinn Tran726b8542017-01-19 22:28:00 -08005214 if (qla_tgt_mode_enabled(base_vha)) {
Roland Dreierb2032fd2015-07-14 16:00:42 -04005215 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5216 "port changed FC ID, %8phC"
5217 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5218 fcport->port_name,
5219 fcport->d_id.b.domain,
5220 fcport->d_id.b.area,
5221 fcport->d_id.b.al_pa,
5222 fcport->loop_id,
5223 new_fcport->d_id.b.domain,
5224 new_fcport->d_id.b.area,
5225 new_fcport->d_id.b.al_pa);
5226 fcport->d_id.b24 = new_fcport->d_id.b24;
5227 break;
5228 }
5229
Linus Torvalds1da177e2005-04-16 15:20:36 -07005230 fcport->d_id.b24 = new_fcport->d_id.b24;
5231 fcport->flags |= FCF_LOGIN_NEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005232 break;
5233 }
5234
Quinn Tran726b8542017-01-19 22:28:00 -08005235 if (found) {
5236 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005237 continue;
Quinn Tran726b8542017-01-19 22:28:00 -08005238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239 /* If device was not in our fcports list, then add it. */
Roland Dreierb2032fd2015-07-14 16:00:42 -04005240 new_fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tran726b8542017-01-19 22:28:00 -08005241 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5242
5243 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5244
Linus Torvalds1da177e2005-04-16 15:20:36 -07005245
5246 /* Allocate a new replacement fcport. */
5247 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005248 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005250 ql_log(ql_log_warn, vha, 0xd032,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005251 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005252 return (QLA_MEMORY_ALLOC_FAILED);
5253 }
5254 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5255 new_fcport->d_id.b24 = nxt_d_id.b24;
5256 }
5257
Quinn Tran726b8542017-01-19 22:28:00 -08005258 qla2x00_free_fcport(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005259
Quinn Tran726b8542017-01-19 22:28:00 -08005260 /*
5261 * Logout all previous fabric dev marked lost, except FCP2 devices.
5262 */
5263 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5264 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5265 break;
5266
5267 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5268 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5269 continue;
5270
5271 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5272 if ((qla_dual_mode_enabled(vha) ||
5273 qla_ini_mode_enabled(vha)) &&
5274 atomic_read(&fcport->state) == FCS_ONLINE) {
5275 qla2x00_mark_device_lost(vha, fcport,
5276 ql2xplogiabsentdevice, 0);
5277 if (fcport->loop_id != FC_NO_LOOP_ID &&
5278 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5279 fcport->port_type != FCT_INITIATOR &&
5280 fcport->port_type != FCT_BROADCAST) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005281 ql_dbg(ql_dbg_disc, vha, 0x20f0,
Quinn Tran726b8542017-01-19 22:28:00 -08005282 "%s %d %8phC post del sess\n",
5283 __func__, __LINE__,
5284 fcport->port_name);
5285
5286 qlt_schedule_sess_for_deletion_lock
5287 (fcport);
5288 continue;
5289 }
5290 }
5291 }
5292
5293 if (fcport->scan_state == QLA_FCPORT_FOUND)
5294 qla24xx_fcport_handle_login(vha, fcport);
5295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005296 return (rval);
5297}
5298
5299/*
5300 * qla2x00_find_new_loop_id
5301 * Scan through our port list and find a new usable loop ID.
5302 *
5303 * Input:
5304 * ha: adapter state pointer.
5305 * dev: port structure pointer.
5306 *
5307 * Returns:
5308 * qla2x00 local function return status code.
5309 *
5310 * Context:
5311 * Kernel context.
5312 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07005313int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005314qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005315{
5316 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005317 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07005318 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319
5320 rval = QLA_SUCCESS;
5321
Chad Dupuis5f16b332012-08-22 14:21:00 -04005322 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005323
Chad Dupuis5f16b332012-08-22 14:21:00 -04005324 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
5325 LOOPID_MAP_SIZE);
5326 if (dev->loop_id >= LOOPID_MAP_SIZE ||
5327 qla2x00_is_reserved_id(vha, dev->loop_id)) {
5328 dev->loop_id = FC_NO_LOOP_ID;
5329 rval = QLA_FUNCTION_FAILED;
5330 } else
5331 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005332
Chad Dupuis5f16b332012-08-22 14:21:00 -04005333 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005334
Chad Dupuis5f16b332012-08-22 14:21:00 -04005335 if (rval == QLA_SUCCESS)
5336 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
5337 "Assigning new loopid=%x, portid=%x.\n",
5338 dev->loop_id, dev->d_id.b24);
5339 else
5340 ql_log(ql_log_warn, dev->vha, 0x2087,
5341 "No loop_id's available, portid=%x.\n",
5342 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005343
5344 return (rval);
5345}
5346
Linus Torvalds1da177e2005-04-16 15:20:36 -07005347
5348/*
5349 * qla2x00_fabric_login
5350 * Issue fabric login command.
5351 *
5352 * Input:
5353 * ha = adapter block pointer.
5354 * device = pointer to FC device type structure.
5355 *
5356 * Returns:
5357 * 0 - Login successfully
5358 * 1 - Login failed
5359 * 2 - Initiator device
5360 * 3 - Fatal error
5361 */
5362int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005363qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005364 uint16_t *next_loopid)
5365{
5366 int rval;
5367 int retry;
5368 uint16_t tmp_loopid;
5369 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005370 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005371
5372 retry = 0;
5373 tmp_loopid = 0;
5374
5375 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005376 ql_dbg(ql_dbg_disc, vha, 0x2000,
5377 "Trying Fabric Login w/loop id 0x%04x for port "
5378 "%02x%02x%02x.\n",
5379 fcport->loop_id, fcport->d_id.b.domain,
5380 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005381
5382 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08005383 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005384 fcport->d_id.b.domain, fcport->d_id.b.area,
5385 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08005386 if (rval != QLA_SUCCESS) {
5387 return rval;
5388 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005389 if (mb[0] == MBS_PORT_ID_USED) {
5390 /*
5391 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005392 * recommends the driver perform an implicit login with
5393 * the specified ID again. The ID we just used is save
5394 * here so we return with an ID that can be tried by
5395 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005396 */
5397 retry++;
5398 tmp_loopid = fcport->loop_id;
5399 fcport->loop_id = mb[1];
5400
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005401 ql_dbg(ql_dbg_disc, vha, 0x2001,
5402 "Fabric Login: port in use - next loop "
5403 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07005404 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005405 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406
5407 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
5408 /*
5409 * Login succeeded.
5410 */
5411 if (retry) {
5412 /* A retry occurred before. */
5413 *next_loopid = tmp_loopid;
5414 } else {
5415 /*
5416 * No retry occurred before. Just increment the
5417 * ID value for next login.
5418 */
5419 *next_loopid = (fcport->loop_id + 1);
5420 }
5421
5422 if (mb[1] & BIT_0) {
5423 fcport->port_type = FCT_INITIATOR;
5424 } else {
5425 fcport->port_type = FCT_TARGET;
5426 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07005427 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005428 }
5429 }
5430
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07005431 if (mb[10] & BIT_0)
5432 fcport->supported_classes |= FC_COS_CLASS2;
5433 if (mb[10] & BIT_1)
5434 fcport->supported_classes |= FC_COS_CLASS3;
5435
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005436 if (IS_FWI2_CAPABLE(ha)) {
5437 if (mb[10] & BIT_7)
5438 fcport->flags |=
5439 FCF_CONF_COMP_SUPPORTED;
5440 }
5441
Linus Torvalds1da177e2005-04-16 15:20:36 -07005442 rval = QLA_SUCCESS;
5443 break;
5444 } else if (mb[0] == MBS_LOOP_ID_USED) {
5445 /*
5446 * Loop ID already used, try next loop ID.
5447 */
5448 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005449 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005450 if (rval != QLA_SUCCESS) {
5451 /* Ran out of loop IDs to use */
5452 break;
5453 }
5454 } else if (mb[0] == MBS_COMMAND_ERROR) {
5455 /*
5456 * Firmware possibly timed out during login. If NO
5457 * retries are left to do then the device is declared
5458 * dead.
5459 */
5460 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005461 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07005462 fcport->d_id.b.domain, fcport->d_id.b.area,
5463 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005464 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005465
5466 rval = 1;
5467 break;
5468 } else {
5469 /*
5470 * unrecoverable / not handled error
5471 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005472 ql_dbg(ql_dbg_disc, vha, 0x2002,
5473 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
5474 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
5475 fcport->d_id.b.area, fcport->d_id.b.al_pa,
5476 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005477
5478 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005479 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07005480 fcport->d_id.b.domain, fcport->d_id.b.area,
5481 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04005482 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07005483 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005484
5485 rval = 3;
5486 break;
5487 }
5488 }
5489
5490 return (rval);
5491}
5492
5493/*
5494 * qla2x00_local_device_login
5495 * Issue local device login command.
5496 *
5497 * Input:
5498 * ha = adapter block pointer.
5499 * loop_id = loop id of device to login to.
5500 *
5501 * Returns (Where's the #define!!!!):
5502 * 0 - Login successfully
5503 * 1 - Login failed
5504 * 3 - Fatal error
5505 */
5506int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005507qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005508{
5509 int rval;
5510 uint16_t mb[MAILBOX_REGISTER_COUNT];
5511
5512 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005513 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005514 if (rval == QLA_SUCCESS) {
5515 /* Interrogate mailbox registers for any errors */
5516 if (mb[0] == MBS_COMMAND_ERROR)
5517 rval = 1;
5518 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
5519 /* device not in PCB table */
5520 rval = 3;
5521 }
5522
5523 return (rval);
5524}
5525
5526/*
5527 * qla2x00_loop_resync
5528 * Resync with fibre channel devices.
5529 *
5530 * Input:
5531 * ha = adapter block pointer.
5532 *
5533 * Returns:
5534 * 0 = success
5535 */
5536int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005537qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005538{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005539 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005540 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005541 struct req_que *req;
5542 struct rsp_que *rsp;
5543
Michael Hernandezd7459522016-12-12 14:40:07 -08005544 req = vha->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005545 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005546
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005547 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5548 if (vha->flags.online) {
5549 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005550 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5551 wait_time = 256;
5552 do {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005553 if (!IS_QLAFX00(vha->hw)) {
5554 /*
5555 * Issue a marker after FW becomes
5556 * ready.
5557 */
5558 qla2x00_marker(vha, req, rsp, 0, 0,
5559 MK_SYNC_ALL);
5560 vha->marker_needed = 0;
5561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005562
5563 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005564 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005565
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005566 if (IS_QLAFX00(vha->hw))
5567 qlafx00_configure_devices(vha);
5568 else
5569 qla2x00_configure_loop(vha);
5570
Linus Torvalds1da177e2005-04-16 15:20:36 -07005571 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005572 } while (!atomic_read(&vha->loop_down_timer) &&
5573 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5574 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
5575 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005576 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005577 }
5578
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005579 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005580 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005581
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005582 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005583 ql_dbg(ql_dbg_disc, vha, 0x206c,
5584 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005585
5586 return (rval);
5587}
5588
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005589/*
5590* qla2x00_perform_loop_resync
5591* Description: This function will set the appropriate flags and call
5592* qla2x00_loop_resync. If successful loop will be resynced
5593* Arguments : scsi_qla_host_t pointer
5594* returm : Success or Failure
5595*/
5596
5597int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
5598{
5599 int32_t rval = 0;
5600
5601 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
5602 /*Configure the flags so that resync happens properly*/
5603 atomic_set(&ha->loop_down_timer, 0);
5604 if (!(ha->device_flags & DFLG_NO_CABLE)) {
5605 atomic_set(&ha->loop_state, LOOP_UP);
5606 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
5607 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
5608 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
5609
5610 rval = qla2x00_loop_resync(ha);
5611 } else
5612 atomic_set(&ha->loop_state, LOOP_DEAD);
5613
5614 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
5615 }
5616
5617 return rval;
5618}
5619
Linus Torvalds1da177e2005-04-16 15:20:36 -07005620void
Andrew Vasquez67becc02009-08-25 11:36:20 -07005621qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005622{
5623 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07005624 struct scsi_qla_host *vha;
5625 struct qla_hw_data *ha = base_vha->hw;
5626 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005627
Arun Easifeafb7b2010-09-03 14:57:00 -07005628 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005629 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07005630 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
5631 atomic_inc(&vha->vref_count);
5632 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08005633 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07005634 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
5635 spin_unlock_irqrestore(&ha->vport_slock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07005636 qla2x00_rport_del(fcport);
Alexei Potashnikdf673272015-07-14 16:00:46 -04005637
Arun Easifeafb7b2010-09-03 14:57:00 -07005638 spin_lock_irqsave(&ha->vport_slock, flags);
5639 }
5640 }
5641 atomic_dec(&vha->vref_count);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07005642 wake_up(&vha->vref_waitq);
Arun Easifeafb7b2010-09-03 14:57:00 -07005643 }
5644 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005645}
5646
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005647/* Assumes idc_lock always held on entry */
5648void
5649qla83xx_reset_ownership(scsi_qla_host_t *vha)
5650{
5651 struct qla_hw_data *ha = vha->hw;
5652 uint32_t drv_presence, drv_presence_mask;
5653 uint32_t dev_part_info1, dev_part_info2, class_type;
5654 uint32_t class_type_mask = 0x3;
5655 uint16_t fcoe_other_function = 0xffff, i;
5656
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005657 if (IS_QLA8044(ha)) {
5658 drv_presence = qla8044_rd_direct(vha,
5659 QLA8044_CRB_DRV_ACTIVE_INDEX);
5660 dev_part_info1 = qla8044_rd_direct(vha,
5661 QLA8044_CRB_DEV_PART_INFO_INDEX);
5662 dev_part_info2 = qla8044_rd_direct(vha,
5663 QLA8044_CRB_DEV_PART_INFO2);
5664 } else {
5665 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5666 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
5667 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
5668 }
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005669 for (i = 0; i < 8; i++) {
5670 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
5671 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5672 (i != ha->portnum)) {
5673 fcoe_other_function = i;
5674 break;
5675 }
5676 }
5677 if (fcoe_other_function == 0xffff) {
5678 for (i = 0; i < 8; i++) {
5679 class_type = ((dev_part_info2 >> (i * 4)) &
5680 class_type_mask);
5681 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5682 ((i + 8) != ha->portnum)) {
5683 fcoe_other_function = i + 8;
5684 break;
5685 }
5686 }
5687 }
5688 /*
5689 * Prepare drv-presence mask based on fcoe functions present.
5690 * However consider only valid physical fcoe function numbers (0-15).
5691 */
5692 drv_presence_mask = ~((1 << (ha->portnum)) |
5693 ((fcoe_other_function == 0xffff) ?
5694 0 : (1 << (fcoe_other_function))));
5695
5696 /* We are the reset owner iff:
5697 * - No other protocol drivers present.
5698 * - This is the lowest among fcoe functions. */
5699 if (!(drv_presence & drv_presence_mask) &&
5700 (ha->portnum < fcoe_other_function)) {
5701 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
5702 "This host is Reset owner.\n");
5703 ha->flags.nic_core_reset_owner = 1;
5704 }
5705}
5706
Saurav Kashyapfa492632012-11-21 02:40:29 -05005707static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005708__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
5709{
5710 int rval = QLA_SUCCESS;
5711 struct qla_hw_data *ha = vha->hw;
5712 uint32_t drv_ack;
5713
5714 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5715 if (rval == QLA_SUCCESS) {
5716 drv_ack |= (1 << ha->portnum);
5717 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5718 }
5719
5720 return rval;
5721}
5722
Saurav Kashyapfa492632012-11-21 02:40:29 -05005723static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005724__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
5725{
5726 int rval = QLA_SUCCESS;
5727 struct qla_hw_data *ha = vha->hw;
5728 uint32_t drv_ack;
5729
5730 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5731 if (rval == QLA_SUCCESS) {
5732 drv_ack &= ~(1 << ha->portnum);
5733 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5734 }
5735
5736 return rval;
5737}
5738
Saurav Kashyapfa492632012-11-21 02:40:29 -05005739static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005740qla83xx_dev_state_to_string(uint32_t dev_state)
5741{
5742 switch (dev_state) {
5743 case QLA8XXX_DEV_COLD:
5744 return "COLD/RE-INIT";
5745 case QLA8XXX_DEV_INITIALIZING:
5746 return "INITIALIZING";
5747 case QLA8XXX_DEV_READY:
5748 return "READY";
5749 case QLA8XXX_DEV_NEED_RESET:
5750 return "NEED RESET";
5751 case QLA8XXX_DEV_NEED_QUIESCENT:
5752 return "NEED QUIESCENT";
5753 case QLA8XXX_DEV_FAILED:
5754 return "FAILED";
5755 case QLA8XXX_DEV_QUIESCENT:
5756 return "QUIESCENT";
5757 default:
5758 return "Unknown";
5759 }
5760}
5761
5762/* Assumes idc-lock always held on entry */
5763void
5764qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
5765{
5766 struct qla_hw_data *ha = vha->hw;
5767 uint32_t idc_audit_reg = 0, duration_secs = 0;
5768
5769 switch (audit_type) {
5770 case IDC_AUDIT_TIMESTAMP:
5771 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
5772 idc_audit_reg = (ha->portnum) |
5773 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
5774 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5775 break;
5776
5777 case IDC_AUDIT_COMPLETION:
5778 duration_secs = ((jiffies_to_msecs(jiffies) -
5779 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
5780 idc_audit_reg = (ha->portnum) |
5781 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
5782 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5783 break;
5784
5785 default:
5786 ql_log(ql_log_warn, vha, 0xb078,
5787 "Invalid audit type specified.\n");
5788 break;
5789 }
5790}
5791
5792/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05005793static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005794qla83xx_initiating_reset(scsi_qla_host_t *vha)
5795{
5796 struct qla_hw_data *ha = vha->hw;
5797 uint32_t idc_control, dev_state;
5798
5799 __qla83xx_get_idc_control(vha, &idc_control);
5800 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
5801 ql_log(ql_log_info, vha, 0xb080,
5802 "NIC Core reset has been disabled. idc-control=0x%x\n",
5803 idc_control);
5804 return QLA_FUNCTION_FAILED;
5805 }
5806
5807 /* Set NEED-RESET iff in READY state and we are the reset-owner */
5808 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5809 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
5810 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
5811 QLA8XXX_DEV_NEED_RESET);
5812 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
5813 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
5814 } else {
5815 const char *state = qla83xx_dev_state_to_string(dev_state);
5816 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
5817
5818 /* SV: XXX: Is timeout required here? */
5819 /* Wait for IDC state change READY -> NEED_RESET */
5820 while (dev_state == QLA8XXX_DEV_READY) {
5821 qla83xx_idc_unlock(vha, 0);
5822 msleep(200);
5823 qla83xx_idc_lock(vha, 0);
5824 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5825 }
5826 }
5827
5828 /* Send IDC ack by writing to drv-ack register */
5829 __qla83xx_set_drv_ack(vha);
5830
5831 return QLA_SUCCESS;
5832}
5833
5834int
5835__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
5836{
5837 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5838}
5839
5840int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005841__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
5842{
5843 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5844}
5845
Saurav Kashyapfa492632012-11-21 02:40:29 -05005846static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005847qla83xx_check_driver_presence(scsi_qla_host_t *vha)
5848{
5849 uint32_t drv_presence = 0;
5850 struct qla_hw_data *ha = vha->hw;
5851
5852 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5853 if (drv_presence & (1 << ha->portnum))
5854 return QLA_SUCCESS;
5855 else
5856 return QLA_TEST_FAILED;
5857}
5858
5859int
5860qla83xx_nic_core_reset(scsi_qla_host_t *vha)
5861{
5862 int rval = QLA_SUCCESS;
5863 struct qla_hw_data *ha = vha->hw;
5864
5865 ql_dbg(ql_dbg_p3p, vha, 0xb058,
5866 "Entered %s().\n", __func__);
5867
5868 if (vha->device_flags & DFLG_DEV_FAILED) {
5869 ql_log(ql_log_warn, vha, 0xb059,
5870 "Device in unrecoverable FAILED state.\n");
5871 return QLA_FUNCTION_FAILED;
5872 }
5873
5874 qla83xx_idc_lock(vha, 0);
5875
5876 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
5877 ql_log(ql_log_warn, vha, 0xb05a,
5878 "Function=0x%x has been removed from IDC participation.\n",
5879 ha->portnum);
5880 rval = QLA_FUNCTION_FAILED;
5881 goto exit;
5882 }
5883
5884 qla83xx_reset_ownership(vha);
5885
5886 rval = qla83xx_initiating_reset(vha);
5887
5888 /*
5889 * Perform reset if we are the reset-owner,
5890 * else wait till IDC state changes to READY/FAILED.
5891 */
5892 if (rval == QLA_SUCCESS) {
5893 rval = qla83xx_idc_state_handler(vha);
5894
5895 if (rval == QLA_SUCCESS)
5896 ha->flags.nic_core_hung = 0;
5897 __qla83xx_clear_drv_ack(vha);
5898 }
5899
5900exit:
5901 qla83xx_idc_unlock(vha, 0);
5902
5903 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
5904
5905 return rval;
5906}
5907
Saurav Kashyap81178772012-08-22 14:21:04 -04005908int
5909qla2xxx_mctp_dump(scsi_qla_host_t *vha)
5910{
5911 struct qla_hw_data *ha = vha->hw;
5912 int rval = QLA_FUNCTION_FAILED;
5913
5914 if (!IS_MCTP_CAPABLE(ha)) {
5915 /* This message can be removed from the final version */
5916 ql_log(ql_log_info, vha, 0x506d,
5917 "This board is not MCTP capable\n");
5918 return rval;
5919 }
5920
5921 if (!ha->mctp_dump) {
5922 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
5923 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
5924
5925 if (!ha->mctp_dump) {
5926 ql_log(ql_log_warn, vha, 0x506e,
5927 "Failed to allocate memory for mctp dump\n");
5928 return rval;
5929 }
5930 }
5931
5932#define MCTP_DUMP_STR_ADDR 0x00000000
5933 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
5934 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
5935 if (rval != QLA_SUCCESS) {
5936 ql_log(ql_log_warn, vha, 0x506f,
5937 "Failed to capture mctp dump\n");
5938 } else {
5939 ql_log(ql_log_info, vha, 0x5070,
5940 "Mctp dump capture for host (%ld/%p).\n",
5941 vha->host_no, ha->mctp_dump);
5942 ha->mctp_dumped = 1;
5943 }
5944
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04005945 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04005946 ha->flags.nic_core_reset_hdlr_active = 1;
5947 rval = qla83xx_restart_nic_firmware(vha);
5948 if (rval)
5949 /* NIC Core reset failed. */
5950 ql_log(ql_log_warn, vha, 0x5071,
5951 "Failed to restart nic firmware\n");
5952 else
5953 ql_dbg(ql_dbg_p3p, vha, 0xb084,
5954 "Restarted NIC firmware successfully.\n");
5955 ha->flags.nic_core_reset_hdlr_active = 0;
5956 }
5957
5958 return rval;
5959
5960}
5961
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005962/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005963* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005964* Description: This function will block the new I/Os
5965* Its not aborting any I/Os as context
5966* is not destroyed during quiescence
5967* Arguments: scsi_qla_host_t
5968* return : void
5969*/
5970void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005971qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005972{
5973 struct qla_hw_data *ha = vha->hw;
5974 struct scsi_qla_host *vp;
5975
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005976 ql_dbg(ql_dbg_dpc, vha, 0x401d,
5977 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005978
5979 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
5980 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
5981 atomic_set(&vha->loop_state, LOOP_DOWN);
5982 qla2x00_mark_all_devices_lost(vha, 0);
5983 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005984 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005985 } else {
5986 if (!atomic_read(&vha->loop_down_timer))
5987 atomic_set(&vha->loop_down_timer,
5988 LOOP_DOWN_TIME);
5989 }
5990 /* Wait for pending cmds to complete */
5991 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
5992}
5993
Giridhar Malavalia9083012010-04-12 17:59:55 -07005994void
5995qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
5996{
5997 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005998 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005999 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08006000 fc_port_t *fcport;
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07006001 u16 i;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006002
Saurav Kashyape46ef002011-02-23 15:27:16 -08006003 /* For ISP82XX, driver waits for completion of the commands.
6004 * online flag should be set.
6005 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006006 if (!(IS_P3P_TYPE(ha)))
Saurav Kashyape46ef002011-02-23 15:27:16 -08006007 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006008 ha->flags.chip_reset_done = 0;
6009 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04006010 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006011
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006012 ql_log(ql_log_info, vha, 0x00af,
6013 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006014
Saurav Kashyape46ef002011-02-23 15:27:16 -08006015 /* For ISP82XX, reset_chip is just disabling interrupts.
6016 * Driver waits for the completion of the commands.
6017 * the interrupts need to be enabled.
6018 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006019 if (!(IS_P3P_TYPE(ha)))
Giridhar Malavalia9083012010-04-12 17:59:55 -07006020 ha->isp_ops->reset_chip(vha);
6021
Quinn Tranec7193e2017-03-15 09:48:55 -07006022 ha->flags.n2n_ae = 0;
6023 ha->flags.lip_ae = 0;
6024 ha->current_topology = 0;
6025 ha->flags.fw_started = 0;
6026 ha->flags.fw_init_done = 0;
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07006027 ha->base_qpair->chip_reset++;
6028 for (i = 0; i < ha->max_qpairs; i++) {
6029 if (ha->queue_pair_map[i])
6030 ha->queue_pair_map[i]->chip_reset =
6031 ha->base_qpair->chip_reset;
6032 }
Quinn Tran726b8542017-01-19 22:28:00 -08006033
Giridhar Malavalia9083012010-04-12 17:59:55 -07006034 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6035 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6036 atomic_set(&vha->loop_state, LOOP_DOWN);
6037 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07006038
6039 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08006040 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07006041 atomic_inc(&vp->vref_count);
6042 spin_unlock_irqrestore(&ha->vport_slock, flags);
6043
Giridhar Malavalia9083012010-04-12 17:59:55 -07006044 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07006045
6046 spin_lock_irqsave(&ha->vport_slock, flags);
6047 atomic_dec(&vp->vref_count);
6048 }
6049 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006050 } else {
6051 if (!atomic_read(&vha->loop_down_timer))
6052 atomic_set(&vha->loop_down_timer,
6053 LOOP_DOWN_TIME);
6054 }
6055
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08006056 /* Clear all async request states across all VPs. */
6057 list_for_each_entry(fcport, &vha->vp_fcports, list)
6058 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6059 spin_lock_irqsave(&ha->vport_slock, flags);
6060 list_for_each_entry(vp, &ha->vp_list, list) {
6061 atomic_inc(&vp->vref_count);
6062 spin_unlock_irqrestore(&ha->vport_slock, flags);
6063
6064 list_for_each_entry(fcport, &vp->vp_fcports, list)
6065 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6066
6067 spin_lock_irqsave(&ha->vport_slock, flags);
6068 atomic_dec(&vp->vref_count);
6069 }
6070 spin_unlock_irqrestore(&ha->vport_slock, flags);
6071
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006072 if (!ha->flags.eeh_busy) {
6073 /* Make sure for ISP 82XX IO DMA is complete */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006074 if (IS_P3P_TYPE(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08006075 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006076 ql_log(ql_log_info, vha, 0x00b4,
6077 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006078
Saurav Kashyape46ef002011-02-23 15:27:16 -08006079 /* Done waiting for pending commands.
6080 * Reset the online flag.
6081 */
6082 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006083 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006084
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07006085 /* Requeue all commands in outstanding command list. */
6086 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6087 }
Arun Easib6a029e2014-09-25 06:14:52 -04006088 /* memory barrier */
6089 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07006090}
6091
6092/*
6093* qla2x00_abort_isp
6094* Resets ISP and aborts all outstanding commands.
6095*
6096* Input:
6097* ha = adapter block pointer.
6098*
6099* Returns:
6100* 0 = success
6101*/
6102int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006103qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006104{
Andrew Vasquez476e8972006-08-23 14:54:55 -07006105 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006106 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006107 struct qla_hw_data *ha = vha->hw;
6108 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006109 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07006110 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006111
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006112 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07006113 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006114
Santosh Vernekara61712972012-08-22 14:21:13 -04006115 if (IS_QLA8031(ha)) {
6116 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6117 "Clearing fcoe driver presence.\n");
6118 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6119 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6120 "Error while clearing DRV-Presence.\n");
6121 }
6122
Andrew Vasquez85880802009-12-15 21:29:46 -08006123 if (unlikely(pci_channel_offline(ha->pdev) &&
6124 ha->flags.pci_channel_io_perm_failure)) {
6125 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6126 status = 0;
6127 return status;
6128 }
6129
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006130 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08006131
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006132 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006134 if (!qla2x00_restart_isp(vha)) {
6135 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006136
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006137 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006138 /*
6139 * Issue marker command only when we are going
6140 * to start the I/O .
6141 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006142 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006143 }
6144
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006145 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006147 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006148
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07006149 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006150 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07006151
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006152 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6153 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08006154 if (ha->fce) {
6155 ha->flags.fce_enabled = 1;
6156 memset(ha->fce, 0,
6157 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006158 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08006159 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6160 &ha->fce_bufs);
6161 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006162 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08006163 "Unable to reinitialize FCE "
6164 "(%d).\n", rval);
6165 ha->flags.fce_enabled = 0;
6166 }
6167 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006168
6169 if (ha->eft) {
6170 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006171 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006172 ha->eft_dma, EFT_NUM_BUFFERS);
6173 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006174 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006175 "Unable to reinitialize EFT "
6176 "(%d).\n", rval);
6177 }
6178 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006179 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006180 vha->flags.online = 1;
6181 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006182 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006183 ql_log(ql_log_fatal, vha, 0x8035,
6184 "ISP error recover failed - "
6185 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07006186 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187 * The next call disables the board
6188 * completely.
6189 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006190 ha->isp_ops->reset_adapter(vha);
6191 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006192 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006193 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194 status = 0;
6195 } else { /* schedule another ISP abort */
6196 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006197 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6198 "ISP abort - retry remaining %d.\n",
6199 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200 status = 1;
6201 }
6202 } else {
6203 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006204 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6205 "ISP error recovery - retrying (%d) "
6206 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006207 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006208 status = 1;
6209 }
6210 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07006211
Linus Torvalds1da177e2005-04-16 15:20:36 -07006212 }
6213
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006214 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006215 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Quinn Tran1608cc42017-08-23 15:05:03 -07006216 qla2x00_configure_hba(vha);
Arun Easifeafb7b2010-09-03 14:57:00 -07006217 spin_lock_irqsave(&ha->vport_slock, flags);
6218 list_for_each_entry(vp, &ha->vp_list, list) {
6219 if (vp->vp_idx) {
6220 atomic_inc(&vp->vref_count);
6221 spin_unlock_irqrestore(&ha->vport_slock, flags);
6222
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006223 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07006224
6225 spin_lock_irqsave(&ha->vport_slock, flags);
6226 atomic_dec(&vp->vref_count);
6227 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006228 }
Arun Easifeafb7b2010-09-03 14:57:00 -07006229 spin_unlock_irqrestore(&ha->vport_slock, flags);
6230
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006231 if (IS_QLA8031(ha)) {
6232 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6233 "Setting back fcoe driver presence.\n");
6234 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6235 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6236 "Error while setting DRV-Presence.\n");
6237 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006238 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08006239 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6240 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006241 }
6242
6243 return(status);
6244}
6245
6246/*
6247* qla2x00_restart_isp
6248* restarts the ISP after a reset
6249*
6250* Input:
6251* ha = adapter block pointer.
6252*
6253* Returns:
6254* 0 = success
6255*/
6256static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006257qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006258{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08006259 int status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006260 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006261 struct req_que *req = ha->req_q_map[0];
6262 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07006263
6264 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006265 if (qla2x00_isp_firmware(vha)) {
6266 vha->flags.online = 0;
6267 status = ha->isp_ops->chip_diag(vha);
6268 if (!status)
6269 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270 }
6271
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006272 if (!status && !(status = qla2x00_init_rings(vha))) {
6273 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07006274 ha->flags.chip_reset_done = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04006275
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006276 /* Initialize the queues in use */
6277 qla25xx_init_queues(ha);
6278
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006279 status = qla2x00_fw_ready(vha);
6280 if (!status) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006281 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006282 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Chad Dupuis7108b762014-04-11 16:54:45 -04006283 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006284 }
6285
6286 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006287 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006288 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006289 }
6290 return (status);
6291}
6292
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006293static int
6294qla25xx_init_queues(struct qla_hw_data *ha)
6295{
6296 struct rsp_que *rsp = NULL;
6297 struct req_que *req = NULL;
6298 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6299 int ret = -1;
6300 int i;
6301
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07006302 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006303 rsp = ha->rsp_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05006304 if (rsp && test_bit(i, ha->rsp_qid_map)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006305 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08006306 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006307 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006308 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6309 "%s Rsp que: %d init failed.\n",
6310 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006311 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006312 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6313 "%s Rsp que: %d inited.\n",
6314 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006315 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07006316 }
6317 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006318 req = ha->req_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05006319 if (req && test_bit(i, ha->req_qid_map)) {
6320 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006321 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08006322 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006323 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006324 ql_dbg(ql_dbg_init, base_vha, 0x0101,
6325 "%s Req que: %d init failed.\n",
6326 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006327 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006328 ql_dbg(ql_dbg_init, base_vha, 0x0102,
6329 "%s Req que: %d inited.\n",
6330 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006331 }
6332 }
6333 return ret;
6334}
6335
Linus Torvalds1da177e2005-04-16 15:20:36 -07006336/*
6337* qla2x00_reset_adapter
6338* Reset adapter.
6339*
6340* Input:
6341* ha = adapter block pointer.
6342*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07006343void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006344qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345{
6346 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006347 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07006348 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006349
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006350 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006351 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006352
Linus Torvalds1da177e2005-04-16 15:20:36 -07006353 spin_lock_irqsave(&ha->hardware_lock, flags);
6354 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
6355 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
6356 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
6357 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
6358 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6359}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006360
6361void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006362qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006363{
6364 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006365 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006366 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
6367
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006368 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07006369 return;
6370
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006371 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006372 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006373
6374 spin_lock_irqsave(&ha->hardware_lock, flags);
6375 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
6376 RD_REG_DWORD(&reg->hccr);
6377 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
6378 RD_REG_DWORD(&reg->hccr);
6379 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08006380
6381 if (IS_NOPOLLING_TYPE(ha))
6382 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006383}
6384
David Miller4e08df32007-04-16 12:37:43 -07006385/* On sparc systems, obtain port and node WWN from firmware
6386 * properties.
6387 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006388static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
6389 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07006390{
6391#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006392 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07006393 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07006394 struct device_node *dp = pci_device_to_OF_node(pdev);
6395 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07006396 int len;
6397
6398 val = of_get_property(dp, "port-wwn", &len);
6399 if (val && len >= WWN_SIZE)
6400 memcpy(nv->port_name, val, WWN_SIZE);
6401
6402 val = of_get_property(dp, "node-wwn", &len);
6403 if (val && len >= WWN_SIZE)
6404 memcpy(nv->node_name, val, WWN_SIZE);
6405#endif
6406}
6407
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006408int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006409qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006410{
David Miller4e08df32007-04-16 12:37:43 -07006411 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006412 struct init_cb_24xx *icb;
6413 struct nvram_24xx *nv;
6414 uint32_t *dptr;
6415 uint8_t *dptr1, *dptr2;
6416 uint32_t chksum;
6417 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006418 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006419
David Miller4e08df32007-04-16 12:37:43 -07006420 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006421 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07006422 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006423
6424 /* Determine NVRAM starting address. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05006425 if (ha->port_no == 0) {
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07006426 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
6427 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
6428 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006429 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08006430 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
6431 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05006432
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07006433 ha->nvram_size = sizeof(struct nvram_24xx);
6434 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006435
Seokmann Ju281afe12007-07-26 13:43:34 -07006436 /* Get VPD data into cache */
6437 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006438 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07006439 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
6440
6441 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006442 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006443 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006444 ha->nvram_size);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006445 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
6446 chksum += le32_to_cpu(*dptr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006447
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006448 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
6449 "Contents of NVRAM\n");
6450 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
6451 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006452
6453 /* Bad NVRAM data, set defaults parameters. */
6454 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6455 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07006456 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006457 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006458 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04006459 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006460 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
6461 ql_log(ql_log_warn, vha, 0x006c,
6462 "Falling back to functioning (yet invalid -- WWPN) "
6463 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07006464
6465 /*
6466 * Set default initialization control block.
6467 */
6468 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07006469 nv->nvram_version = cpu_to_le16(ICB_VERSION);
6470 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04006471 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07006472 nv->execution_throttle = cpu_to_le16(0xFFFF);
6473 nv->exchange_count = cpu_to_le16(0);
6474 nv->hard_address = cpu_to_le16(124);
David Miller4e08df32007-04-16 12:37:43 -07006475 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006476 nv->port_name[1] = 0x00 + ha->port_no + 1;
David Miller4e08df32007-04-16 12:37:43 -07006477 nv->port_name[2] = 0x00;
6478 nv->port_name[3] = 0xe0;
6479 nv->port_name[4] = 0x8b;
6480 nv->port_name[5] = 0x1c;
6481 nv->port_name[6] = 0x55;
6482 nv->port_name[7] = 0x86;
6483 nv->node_name[0] = 0x20;
6484 nv->node_name[1] = 0x00;
6485 nv->node_name[2] = 0x00;
6486 nv->node_name[3] = 0xe0;
6487 nv->node_name[4] = 0x8b;
6488 nv->node_name[5] = 0x1c;
6489 nv->node_name[6] = 0x55;
6490 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006491 qla24xx_nvram_wwn_from_ofw(vha, nv);
Bart Van Asschead950362015-07-09 07:24:08 -07006492 nv->login_retry_count = cpu_to_le16(8);
6493 nv->interrupt_delay_timer = cpu_to_le16(0);
6494 nv->login_timeout = cpu_to_le16(0);
David Miller4e08df32007-04-16 12:37:43 -07006495 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07006496 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6497 nv->firmware_options_2 = cpu_to_le32(2 << 4);
6498 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6499 nv->firmware_options_3 = cpu_to_le32(2 << 13);
6500 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6501 nv->efi_parameters = cpu_to_le32(0);
David Miller4e08df32007-04-16 12:37:43 -07006502 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07006503 nv->max_luns_per_target = cpu_to_le16(128);
6504 nv->port_down_retry_count = cpu_to_le16(30);
6505 nv->link_down_timeout = cpu_to_le16(30);
David Miller4e08df32007-04-16 12:37:43 -07006506
6507 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006508 }
6509
Quinn Tran726b8542017-01-19 22:28:00 -08006510 if (qla_tgt_mode_enabled(vha)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006511 /* Don't enable full login after initial LIP */
Bart Van Asschead950362015-07-09 07:24:08 -07006512 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006513 /* Don't enable LIP full login for initiator */
Bart Van Asschead950362015-07-09 07:24:08 -07006514 nv->host_p &= cpu_to_le32(~BIT_10);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006515 }
6516
6517 qlt_24xx_config_nvram_stage1(vha, nv);
6518
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006519 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006520 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006521
6522 /* Copy 1st segment. */
6523 dptr1 = (uint8_t *)icb;
6524 dptr2 = (uint8_t *)&nv->version;
6525 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6526 while (cnt--)
6527 *dptr1++ = *dptr2++;
6528
6529 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07006530 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006531
6532 /* Copy 2nd segment. */
6533 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6534 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6535 cnt = (uint8_t *)&icb->reserved_3 -
6536 (uint8_t *)&icb->interrupt_delay_timer;
6537 while (cnt--)
6538 *dptr1++ = *dptr2++;
6539
6540 /*
6541 * Setup driver NVRAM options.
6542 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006543 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08006544 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006545
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006546 qlt_24xx_config_nvram_stage2(vha, icb);
6547
Bart Van Asschead950362015-07-09 07:24:08 -07006548 if (nv->host_p & cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006549 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07006550 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6551 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6552 }
6553
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006554 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07006555 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006556 /*
6557 * Firmware will apply the following mask if the nodename was
6558 * not provided.
6559 */
6560 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6561 icb->node_name[0] &= 0xF0;
6562 }
6563
6564 /* Set host adapter parameters. */
6565 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08006566 ha->flags.enable_lip_reset = 0;
6567 ha->flags.enable_lip_full_login =
6568 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6569 ha->flags.enable_target_reset =
6570 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006571 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07006572 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006573
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07006574 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6575 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006576
6577 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
6578 sizeof(ha->fw_seriallink_options24));
6579
6580 /* save HBA serial number */
6581 ha->serial0 = icb->port_name[5];
6582 ha->serial1 = icb->port_name[6];
6583 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006584 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6585 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006586
Bart Van Asschead950362015-07-09 07:24:08 -07006587 icb->execution_throttle = cpu_to_le16(0xFFFF);
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08006588
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006589 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6590
6591 /* Set minimum login_timeout to 4 seconds. */
6592 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6593 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6594 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07006595 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006596 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006597
Andrew Vasquez00a537b2008-02-28 14:06:11 -08006598 /* Set minimum RATOV to 100 tenths of a second. */
6599 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006600
6601 ha->loop_reset_delay = nv->reset_delay;
6602
6603 /* Link Down Timeout = 0:
6604 *
6605 * When Port Down timer expires we will start returning
6606 * I/O's to OS with "DID_NO_CONNECT".
6607 *
6608 * Link Down Timeout != 0:
6609 *
6610 * The driver waits for the link to come up after link down
6611 * before returning I/Os to OS with "DID_NO_CONNECT".
6612 */
6613 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6614 ha->loop_down_abort_time =
6615 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6616 } else {
6617 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6618 ha->loop_down_abort_time =
6619 (LOOP_DOWN_TIME - ha->link_down_timeout);
6620 }
6621
6622 /* Need enough time to try and get the port back. */
6623 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6624 if (qlport_down_retry)
6625 ha->port_down_retry_count = qlport_down_retry;
6626
6627 /* Set login_retry_count */
6628 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6629 if (ha->port_down_retry_count ==
6630 le16_to_cpu(nv->port_down_retry_count) &&
6631 ha->port_down_retry_count > 3)
6632 ha->login_retry_count = ha->port_down_retry_count;
6633 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6634 ha->login_retry_count = ha->port_down_retry_count;
6635 if (ql2xloginretrycount)
6636 ha->login_retry_count = ql2xloginretrycount;
6637
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006638 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006639 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006640 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6641 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6642 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6643 le16_to_cpu(icb->interrupt_delay_timer): 2;
6644 }
Bart Van Asschead950362015-07-09 07:24:08 -07006645 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006646 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006647 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006648 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08006649 ha->zio_mode = QLA_ZIO_MODE_6;
6650
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006651 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006652 "ZIO mode %d enabled; timer delay (%d us).\n",
6653 ha->zio_mode, ha->zio_timer * 100);
6654
6655 icb->firmware_options_2 |= cpu_to_le32(
6656 (uint32_t)ha->zio_mode);
6657 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006658 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006659 }
6660
David Miller4e08df32007-04-16 12:37:43 -07006661 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006662 ql_log(ql_log_warn, vha, 0x0070,
6663 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07006664 }
6665 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006666}
6667
Sawan Chandak4243c112016-01-27 12:03:31 -05006668uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
6669{
6670 struct qla27xx_image_status pri_image_status, sec_image_status;
6671 uint8_t valid_pri_image, valid_sec_image;
6672 uint32_t *wptr;
6673 uint32_t cnt, chksum, size;
6674 struct qla_hw_data *ha = vha->hw;
6675
6676 valid_pri_image = valid_sec_image = 1;
6677 ha->active_image = 0;
6678 size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
6679
6680 if (!ha->flt_region_img_status_pri) {
6681 valid_pri_image = 0;
6682 goto check_sec_image;
6683 }
6684
6685 qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
6686 ha->flt_region_img_status_pri, size);
6687
6688 if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6689 ql_dbg(ql_dbg_init, vha, 0x018b,
6690 "Primary image signature (0x%x) not valid\n",
6691 pri_image_status.signature);
6692 valid_pri_image = 0;
6693 goto check_sec_image;
6694 }
6695
6696 wptr = (uint32_t *)(&pri_image_status);
6697 cnt = size;
6698
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006699 for (chksum = 0; cnt--; wptr++)
6700 chksum += le32_to_cpu(*wptr);
Quinn Tran41dc5292017-01-19 22:28:03 -08006701
Sawan Chandak4243c112016-01-27 12:03:31 -05006702 if (chksum) {
6703 ql_dbg(ql_dbg_init, vha, 0x018c,
6704 "Checksum validation failed for primary image (0x%x)\n",
6705 chksum);
6706 valid_pri_image = 0;
6707 }
6708
6709check_sec_image:
6710 if (!ha->flt_region_img_status_sec) {
6711 valid_sec_image = 0;
6712 goto check_valid_image;
6713 }
6714
6715 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
6716 ha->flt_region_img_status_sec, size);
6717
6718 if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6719 ql_dbg(ql_dbg_init, vha, 0x018d,
6720 "Secondary image signature(0x%x) not valid\n",
6721 sec_image_status.signature);
6722 valid_sec_image = 0;
6723 goto check_valid_image;
6724 }
6725
6726 wptr = (uint32_t *)(&sec_image_status);
6727 cnt = size;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006728 for (chksum = 0; cnt--; wptr++)
6729 chksum += le32_to_cpu(*wptr);
Sawan Chandak4243c112016-01-27 12:03:31 -05006730 if (chksum) {
6731 ql_dbg(ql_dbg_init, vha, 0x018e,
6732 "Checksum validation failed for secondary image (0x%x)\n",
6733 chksum);
6734 valid_sec_image = 0;
6735 }
6736
6737check_valid_image:
6738 if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
6739 ha->active_image = QLA27XX_PRIMARY_IMAGE;
6740 if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
6741 if (!ha->active_image ||
6742 pri_image_status.generation_number <
6743 sec_image_status.generation_number)
6744 ha->active_image = QLA27XX_SECONDARY_IMAGE;
6745 }
6746
6747 ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n",
6748 ha->active_image == 0 ? "default bootld and fw" :
6749 ha->active_image == 1 ? "primary" :
6750 ha->active_image == 2 ? "secondary" :
6751 "Invalid");
6752
6753 return ha->active_image;
6754}
6755
Adrian Bunk413975a2006-06-30 02:33:06 -07006756static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006757qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
6758 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006759{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006760 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006761 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006762 uint32_t *dcode, dlen;
6763 uint32_t risc_addr;
6764 uint32_t risc_size;
6765 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006766 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006767 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006768
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006769 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006770 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006771
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006772 rval = QLA_SUCCESS;
6773
6774 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006775 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006776 *srisc_addr = 0;
6777
Sawan Chandak4243c112016-01-27 12:03:31 -05006778 if (IS_QLA27XX(ha) &&
6779 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
6780 faddr = ha->flt_region_fw_sec;
6781
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006782 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006783 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006784 for (i = 0; i < 4; i++)
6785 dcode[i] = be32_to_cpu(dcode[i]);
6786 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
6787 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
6788 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
6789 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006790 ql_log(ql_log_fatal, vha, 0x008c,
6791 "Unable to verify the integrity of flash firmware "
6792 "image.\n");
6793 ql_log(ql_log_fatal, vha, 0x008d,
6794 "Firmware data: %08x %08x %08x %08x.\n",
6795 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006796
6797 return QLA_FUNCTION_FAILED;
6798 }
6799
6800 while (segments && rval == QLA_SUCCESS) {
6801 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006802 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006803
6804 risc_addr = be32_to_cpu(dcode[2]);
6805 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
6806 risc_size = be32_to_cpu(dcode[3]);
6807
6808 fragment = 0;
6809 while (risc_size > 0 && rval == QLA_SUCCESS) {
6810 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
6811 if (dlen > risc_size)
6812 dlen = risc_size;
6813
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006814 ql_dbg(ql_dbg_init, vha, 0x008e,
6815 "Loading risc segment@ risc addr %x "
6816 "number of dwords 0x%x offset 0x%x.\n",
6817 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006818
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006819 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006820 for (i = 0; i < dlen; i++)
6821 dcode[i] = swab32(dcode[i]);
6822
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006823 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006824 dlen);
6825 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006826 ql_log(ql_log_fatal, vha, 0x008f,
6827 "Failed to load segment %d of firmware.\n",
6828 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04006829 return QLA_FUNCTION_FAILED;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006830 }
6831
6832 faddr += dlen;
6833 risc_addr += dlen;
6834 risc_size -= dlen;
6835 fragment++;
6836 }
6837
6838 /* Next segment. */
6839 segments--;
6840 }
6841
Chad Dupuisf73cb692014-02-26 04:15:06 -05006842 if (!IS_QLA27XX(ha))
6843 return rval;
6844
6845 if (ha->fw_dump_template)
6846 vfree(ha->fw_dump_template);
6847 ha->fw_dump_template = NULL;
6848 ha->fw_dump_template_len = 0;
6849
6850 ql_dbg(ql_dbg_init, vha, 0x0161,
6851 "Loading fwdump template from %x\n", faddr);
6852 qla24xx_read_flash_data(vha, dcode, faddr, 7);
6853 risc_size = be32_to_cpu(dcode[2]);
6854 ql_dbg(ql_dbg_init, vha, 0x0162,
6855 "-> array size %x dwords\n", risc_size);
6856 if (risc_size == 0 || risc_size == ~0)
6857 goto default_template;
6858
6859 dlen = (risc_size - 8) * sizeof(*dcode);
6860 ql_dbg(ql_dbg_init, vha, 0x0163,
6861 "-> template allocating %x bytes...\n", dlen);
6862 ha->fw_dump_template = vmalloc(dlen);
6863 if (!ha->fw_dump_template) {
6864 ql_log(ql_log_warn, vha, 0x0164,
6865 "Failed fwdump template allocate %x bytes.\n", risc_size);
6866 goto default_template;
6867 }
6868
6869 faddr += 7;
6870 risc_size -= 8;
6871 dcode = ha->fw_dump_template;
6872 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
6873 for (i = 0; i < risc_size; i++)
6874 dcode[i] = le32_to_cpu(dcode[i]);
6875
6876 if (!qla27xx_fwdt_template_valid(dcode)) {
6877 ql_log(ql_log_warn, vha, 0x0165,
6878 "Failed fwdump template validate\n");
6879 goto default_template;
6880 }
6881
6882 dlen = qla27xx_fwdt_template_size(dcode);
6883 ql_dbg(ql_dbg_init, vha, 0x0166,
6884 "-> template size %x bytes\n", dlen);
6885 if (dlen > risc_size * sizeof(*dcode)) {
6886 ql_log(ql_log_warn, vha, 0x0167,
Himanshu Madhani4fae52b2017-06-06 13:55:23 -07006887 "Failed fwdump template exceeds array by %zx bytes\n",
Joe Carnuccio383a2982017-06-02 09:11:55 -07006888 (size_t)(dlen - risc_size * sizeof(*dcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05006889 goto default_template;
6890 }
6891 ha->fw_dump_template_len = dlen;
6892 return rval;
6893
6894default_template:
6895 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
6896 if (ha->fw_dump_template)
6897 vfree(ha->fw_dump_template);
6898 ha->fw_dump_template = NULL;
6899 ha->fw_dump_template_len = 0;
6900
6901 dlen = qla27xx_fwdt_template_default_size();
6902 ql_dbg(ql_dbg_init, vha, 0x0169,
6903 "-> template allocating %x bytes...\n", dlen);
6904 ha->fw_dump_template = vmalloc(dlen);
6905 if (!ha->fw_dump_template) {
6906 ql_log(ql_log_warn, vha, 0x016a,
6907 "Failed fwdump template allocate %x bytes.\n", risc_size);
6908 goto failed_template;
6909 }
6910
6911 dcode = ha->fw_dump_template;
6912 risc_size = dlen / sizeof(*dcode);
6913 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
6914 for (i = 0; i < risc_size; i++)
6915 dcode[i] = be32_to_cpu(dcode[i]);
6916
6917 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
6918 ql_log(ql_log_warn, vha, 0x016b,
6919 "Failed fwdump template validate\n");
6920 goto failed_template;
6921 }
6922
6923 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
6924 ql_dbg(ql_dbg_init, vha, 0x016c,
6925 "-> template size %x bytes\n", dlen);
6926 ha->fw_dump_template_len = dlen;
6927 return rval;
6928
6929failed_template:
6930 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
6931 if (ha->fw_dump_template)
6932 vfree(ha->fw_dump_template);
6933 ha->fw_dump_template = NULL;
6934 ha->fw_dump_template_len = 0;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006935 return rval;
6936}
6937
Giridhar Malavalie9454a82013-02-08 01:57:47 -05006938#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006939
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006940int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006941qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08006942{
6943 int rval;
6944 int i, fragment;
6945 uint16_t *wcode, *fwcode;
6946 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
6947 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006948 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006949 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08006950
6951 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006952 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08006953 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006954 ql_log(ql_log_info, vha, 0x0083,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01006955 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006956 ql_log(ql_log_info, vha, 0x0084,
6957 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08006958 return QLA_FUNCTION_FAILED;
6959 }
6960
6961 rval = QLA_SUCCESS;
6962
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006963 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08006964 *srisc_addr = 0;
6965 fwcode = (uint16_t *)blob->fw->data;
6966 fwclen = 0;
6967
6968 /* Validate firmware image by checking version. */
6969 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006970 ql_log(ql_log_fatal, vha, 0x0085,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006971 "Unable to verify integrity of firmware image (%zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08006972 blob->fw->size);
6973 goto fail_fw_integrity;
6974 }
6975 for (i = 0; i < 4; i++)
6976 wcode[i] = be16_to_cpu(fwcode[i + 4]);
6977 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
6978 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
6979 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006980 ql_log(ql_log_fatal, vha, 0x0086,
6981 "Unable to verify integrity of firmware image.\n");
6982 ql_log(ql_log_fatal, vha, 0x0087,
6983 "Firmware data: %04x %04x %04x %04x.\n",
6984 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08006985 goto fail_fw_integrity;
6986 }
6987
6988 seg = blob->segs;
6989 while (*seg && rval == QLA_SUCCESS) {
6990 risc_addr = *seg;
6991 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
6992 risc_size = be16_to_cpu(fwcode[3]);
6993
6994 /* Validate firmware image size. */
6995 fwclen += risc_size * sizeof(uint16_t);
6996 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006997 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08006998 "Unable to verify integrity of firmware image "
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006999 "(%zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08007000 goto fail_fw_integrity;
7001 }
7002
7003 fragment = 0;
7004 while (risc_size > 0 && rval == QLA_SUCCESS) {
7005 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7006 if (wlen > risc_size)
7007 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007008 ql_dbg(ql_dbg_init, vha, 0x0089,
7009 "Loading risc segment@ risc addr %x number of "
7010 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08007011
7012 for (i = 0; i < wlen; i++)
7013 wcode[i] = swab16(fwcode[i]);
7014
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007015 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08007016 wlen);
7017 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007018 ql_log(ql_log_fatal, vha, 0x008a,
7019 "Failed to load segment %d of firmware.\n",
7020 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08007021 break;
7022 }
7023
7024 fwcode += wlen;
7025 risc_addr += wlen;
7026 risc_size -= wlen;
7027 fragment++;
7028 }
7029
7030 /* Next segment. */
7031 seg++;
7032 }
7033 return rval;
7034
7035fail_fw_integrity:
7036 return QLA_FUNCTION_FAILED;
7037}
7038
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007039static int
7040qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007041{
7042 int rval;
7043 int segments, fragment;
7044 uint32_t *dcode, dlen;
7045 uint32_t risc_addr;
7046 uint32_t risc_size;
7047 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08007048 struct fw_blob *blob;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007049 const uint32_t *fwcode;
7050 uint32_t fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007051 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007052 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007053
Andrew Vasquez54333832005-11-09 15:49:04 -08007054 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007055 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08007056 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007057 ql_log(ql_log_warn, vha, 0x0090,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01007058 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007059 ql_log(ql_log_warn, vha, 0x0091,
7060 "Firmware images can be retrieved from: "
7061 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07007062
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007063 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007064 }
7065
Chad Dupuiscfb09192011-11-18 09:03:07 -08007066 ql_dbg(ql_dbg_init, vha, 0x0092,
7067 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007068
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007069 rval = QLA_SUCCESS;
7070
7071 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007072 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007073 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08007074 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007075 fwclen = 0;
7076
7077 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08007078 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007079 ql_log(ql_log_fatal, vha, 0x0093,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007080 "Unable to verify integrity of firmware image (%zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08007081 blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05007082 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007083 }
7084 for (i = 0; i < 4; i++)
7085 dcode[i] = be32_to_cpu(fwcode[i + 4]);
7086 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
7087 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
7088 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
7089 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007090 ql_log(ql_log_fatal, vha, 0x0094,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007091 "Unable to verify integrity of firmware image (%zd).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007092 blob->fw->size);
7093 ql_log(ql_log_fatal, vha, 0x0095,
7094 "Firmware data: %08x %08x %08x %08x.\n",
7095 dcode[0], dcode[1], dcode[2], dcode[3]);
Chad Dupuisf73cb692014-02-26 04:15:06 -05007096 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007097 }
7098
7099 while (segments && rval == QLA_SUCCESS) {
7100 risc_addr = be32_to_cpu(fwcode[2]);
7101 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
7102 risc_size = be32_to_cpu(fwcode[3]);
7103
7104 /* Validate firmware image size. */
7105 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08007106 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007107 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08007108 "Unable to verify integrity of firmware image "
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08007109 "(%zd).\n", blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05007110 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007111 }
7112
7113 fragment = 0;
7114 while (risc_size > 0 && rval == QLA_SUCCESS) {
7115 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
7116 if (dlen > risc_size)
7117 dlen = risc_size;
7118
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007119 ql_dbg(ql_dbg_init, vha, 0x0097,
7120 "Loading risc segment@ risc addr %x "
7121 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007122
7123 for (i = 0; i < dlen; i++)
7124 dcode[i] = swab32(fwcode[i]);
7125
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007126 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08007127 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007128 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007129 ql_log(ql_log_fatal, vha, 0x0098,
7130 "Failed to load segment %d of firmware.\n",
7131 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04007132 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007133 }
7134
7135 fwcode += dlen;
7136 risc_addr += dlen;
7137 risc_size -= dlen;
7138 fragment++;
7139 }
7140
7141 /* Next segment. */
7142 segments--;
7143 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05007144
7145 if (!IS_QLA27XX(ha))
7146 return rval;
7147
7148 if (ha->fw_dump_template)
7149 vfree(ha->fw_dump_template);
7150 ha->fw_dump_template = NULL;
7151 ha->fw_dump_template_len = 0;
7152
7153 ql_dbg(ql_dbg_init, vha, 0x171,
Chad Dupuis97ea7022014-03-13 14:16:40 -04007154 "Loading fwdump template from %x\n",
7155 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
Chad Dupuisf73cb692014-02-26 04:15:06 -05007156 risc_size = be32_to_cpu(fwcode[2]);
7157 ql_dbg(ql_dbg_init, vha, 0x172,
7158 "-> array size %x dwords\n", risc_size);
7159 if (risc_size == 0 || risc_size == ~0)
7160 goto default_template;
7161
7162 dlen = (risc_size - 8) * sizeof(*fwcode);
7163 ql_dbg(ql_dbg_init, vha, 0x0173,
7164 "-> template allocating %x bytes...\n", dlen);
7165 ha->fw_dump_template = vmalloc(dlen);
7166 if (!ha->fw_dump_template) {
7167 ql_log(ql_log_warn, vha, 0x0174,
7168 "Failed fwdump template allocate %x bytes.\n", risc_size);
7169 goto default_template;
7170 }
7171
7172 fwcode += 7;
7173 risc_size -= 8;
7174 dcode = ha->fw_dump_template;
7175 for (i = 0; i < risc_size; i++)
7176 dcode[i] = le32_to_cpu(fwcode[i]);
7177
7178 if (!qla27xx_fwdt_template_valid(dcode)) {
7179 ql_log(ql_log_warn, vha, 0x0175,
7180 "Failed fwdump template validate\n");
7181 goto default_template;
7182 }
7183
7184 dlen = qla27xx_fwdt_template_size(dcode);
7185 ql_dbg(ql_dbg_init, vha, 0x0176,
7186 "-> template size %x bytes\n", dlen);
7187 if (dlen > risc_size * sizeof(*fwcode)) {
7188 ql_log(ql_log_warn, vha, 0x0177,
Himanshu Madhani4fae52b2017-06-06 13:55:23 -07007189 "Failed fwdump template exceeds array by %zx bytes\n",
Joe Carnuccio383a2982017-06-02 09:11:55 -07007190 (size_t)(dlen - risc_size * sizeof(*fwcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05007191 goto default_template;
7192 }
7193 ha->fw_dump_template_len = dlen;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007194 return rval;
7195
Chad Dupuisf73cb692014-02-26 04:15:06 -05007196default_template:
7197 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
7198 if (ha->fw_dump_template)
7199 vfree(ha->fw_dump_template);
7200 ha->fw_dump_template = NULL;
7201 ha->fw_dump_template_len = 0;
7202
7203 dlen = qla27xx_fwdt_template_default_size();
7204 ql_dbg(ql_dbg_init, vha, 0x0179,
7205 "-> template allocating %x bytes...\n", dlen);
7206 ha->fw_dump_template = vmalloc(dlen);
7207 if (!ha->fw_dump_template) {
7208 ql_log(ql_log_warn, vha, 0x017a,
7209 "Failed fwdump template allocate %x bytes.\n", risc_size);
7210 goto failed_template;
7211 }
7212
7213 dcode = ha->fw_dump_template;
7214 risc_size = dlen / sizeof(*fwcode);
7215 fwcode = qla27xx_fwdt_template_default();
7216 for (i = 0; i < risc_size; i++)
7217 dcode[i] = be32_to_cpu(fwcode[i]);
7218
7219 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7220 ql_log(ql_log_warn, vha, 0x017b,
7221 "Failed fwdump template validate\n");
7222 goto failed_template;
7223 }
7224
7225 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7226 ql_dbg(ql_dbg_init, vha, 0x017c,
7227 "-> template size %x bytes\n", dlen);
7228 ha->fw_dump_template_len = dlen;
7229 return rval;
7230
7231failed_template:
7232 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
7233 if (ha->fw_dump_template)
7234 vfree(ha->fw_dump_template);
7235 ha->fw_dump_template = NULL;
7236 ha->fw_dump_template_len = 0;
7237 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007238}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007239
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007240int
7241qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7242{
7243 int rval;
7244
Andrew Vasqueze337d902009-04-06 22:33:49 -07007245 if (ql2xfwloadbin == 1)
7246 return qla81xx_load_risc(vha, srisc_addr);
7247
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007248 /*
7249 * FW Load priority:
7250 * 1) Firmware via request-firmware interface (.bin file).
7251 * 2) Firmware residing in flash.
7252 */
7253 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7254 if (rval == QLA_SUCCESS)
7255 return rval;
7256
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007257 return qla24xx_load_risc_flash(vha, srisc_addr,
7258 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007259}
7260
7261int
7262qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7263{
7264 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007265 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007266
Andrew Vasqueze337d902009-04-06 22:33:49 -07007267 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007268 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07007269
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007270 /*
7271 * FW Load priority:
7272 * 1) Firmware residing in flash.
7273 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007274 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007275 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007276 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007277 if (rval == QLA_SUCCESS)
7278 return rval;
7279
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007280try_blob_fw:
7281 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7282 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
7283 return rval;
7284
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007285 ql_log(ql_log_info, vha, 0x0099,
7286 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007287 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
7288 if (rval != QLA_SUCCESS)
7289 return rval;
7290
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007291 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007292 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007293 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007294}
7295
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007296void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007297qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007298{
7299 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007300 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007301
Andrew Vasquez85880802009-12-15 21:29:46 -08007302 if (ha->flags.pci_channel_io_perm_failure)
7303 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07007304 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007305 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07007306 if (!ha->fw_major_version)
7307 return;
Quinn Tranec7193e2017-03-15 09:48:55 -07007308 if (!ha->flags.fw_started)
7309 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007310
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007311 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08007312 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07007313 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007314 ha->isp_ops->reset_chip(vha);
7315 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007316 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007317 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007318 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007319 ql_log(ql_log_info, vha, 0x8015,
7320 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007321 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007322 }
Quinn Tranec7193e2017-03-15 09:48:55 -07007323
Quinn Tran4b60c822017-06-13 20:47:21 -07007324 QLA_FW_STOPPED(ha);
Quinn Tranec7193e2017-03-15 09:48:55 -07007325 ha->flags.fw_init_done = 0;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007326}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007327
7328int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007329qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007330{
7331 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08007332 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007333 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007334 struct qla_hw_data *ha = vha->hw;
7335 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007336 struct req_que *req;
7337 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007338
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007339 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007340 return -EINVAL;
7341
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007342 rval = qla2x00_fw_ready(base_vha);
Michael Hernandezd7459522016-12-12 14:40:07 -08007343 if (vha->qpair)
7344 req = vha->qpair->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007345 else
Michael Hernandezd7459522016-12-12 14:40:07 -08007346 req = ha->req_q_map[0];
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007347 rsp = req->rsp;
7348
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007349 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007350 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007351 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007352 }
7353
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007354 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007355
7356 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08007357 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
7358 BIT_1);
7359 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
7360 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
7361 ql_dbg(ql_dbg_init, vha, 0x0120,
7362 "Failed SNS login: loop_id=%x, rval2=%d\n",
7363 NPH_SNS, rval2);
7364 else
7365 ql_dbg(ql_dbg_init, vha, 0x0103,
7366 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7367 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7368 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007369 return (QLA_FUNCTION_FAILED);
7370 }
7371
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007372 atomic_set(&vha->loop_down_timer, 0);
7373 atomic_set(&vha->loop_state, LOOP_UP);
7374 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7375 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
7376 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007377
7378 return rval;
7379}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007380
7381/* 84XX Support **************************************************************/
7382
7383static LIST_HEAD(qla_cs84xx_list);
7384static DEFINE_MUTEX(qla_cs84xx_mutex);
7385
7386static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007387qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007388{
7389 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007390 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007391
7392 mutex_lock(&qla_cs84xx_mutex);
7393
7394 /* Find any shared 84xx chip. */
7395 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
7396 if (cs84xx->bus == ha->pdev->bus) {
7397 kref_get(&cs84xx->kref);
7398 goto done;
7399 }
7400 }
7401
7402 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
7403 if (!cs84xx)
7404 goto done;
7405
7406 kref_init(&cs84xx->kref);
7407 spin_lock_init(&cs84xx->access_lock);
7408 mutex_init(&cs84xx->fw_update_mutex);
7409 cs84xx->bus = ha->pdev->bus;
7410
7411 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
7412done:
7413 mutex_unlock(&qla_cs84xx_mutex);
7414 return cs84xx;
7415}
7416
7417static void
7418__qla84xx_chip_release(struct kref *kref)
7419{
7420 struct qla_chip_state_84xx *cs84xx =
7421 container_of(kref, struct qla_chip_state_84xx, kref);
7422
7423 mutex_lock(&qla_cs84xx_mutex);
7424 list_del(&cs84xx->list);
7425 mutex_unlock(&qla_cs84xx_mutex);
7426 kfree(cs84xx);
7427}
7428
7429void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007430qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007431{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007432 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007433 if (ha->cs84xx)
7434 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
7435}
7436
7437static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007438qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007439{
7440 int rval;
7441 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007442 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007443
7444 mutex_lock(&ha->cs84xx->fw_update_mutex);
7445
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007446 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007447
7448 mutex_unlock(&ha->cs84xx->fw_update_mutex);
7449
7450 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
7451 QLA_SUCCESS;
7452}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007453
7454/* 81XX Support **************************************************************/
7455
7456int
7457qla81xx_nvram_config(scsi_qla_host_t *vha)
7458{
7459 int rval;
7460 struct init_cb_81xx *icb;
7461 struct nvram_81xx *nv;
7462 uint32_t *dptr;
7463 uint8_t *dptr1, *dptr2;
7464 uint32_t chksum;
7465 uint16_t cnt;
7466 struct qla_hw_data *ha = vha->hw;
7467
7468 rval = QLA_SUCCESS;
7469 icb = (struct init_cb_81xx *)ha->init_cb;
7470 nv = ha->nvram;
7471
7472 /* Determine NVRAM starting address. */
7473 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007474 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007475 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
7476 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007477
7478 /* Get VPD data into cache */
7479 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007480 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
7481 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007482
7483 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007484 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007485 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007486 dptr = (uint32_t *)nv;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05007487 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7488 chksum += le32_to_cpu(*dptr);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007489
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007490 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
7491 "Contents of NVRAM:\n");
7492 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
7493 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007494
7495 /* Bad NVRAM data, set defaults parameters. */
7496 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
7497 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07007498 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007499 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007500 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04007501 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007502 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007503 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007504 ql_log(ql_log_info, vha, 0x0074,
7505 "Falling back to functioning (yet invalid -- WWPN) "
7506 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007507
7508 /*
7509 * Set default initialization control block.
7510 */
7511 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07007512 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7513 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04007514 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07007515 nv->execution_throttle = cpu_to_le16(0xFFFF);
7516 nv->exchange_count = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007517 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007518 nv->port_name[1] = 0x00 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007519 nv->port_name[2] = 0x00;
7520 nv->port_name[3] = 0xe0;
7521 nv->port_name[4] = 0x8b;
7522 nv->port_name[5] = 0x1c;
7523 nv->port_name[6] = 0x55;
7524 nv->port_name[7] = 0x86;
7525 nv->node_name[0] = 0x20;
7526 nv->node_name[1] = 0x00;
7527 nv->node_name[2] = 0x00;
7528 nv->node_name[3] = 0xe0;
7529 nv->node_name[4] = 0x8b;
7530 nv->node_name[5] = 0x1c;
7531 nv->node_name[6] = 0x55;
7532 nv->node_name[7] = 0x86;
Bart Van Asschead950362015-07-09 07:24:08 -07007533 nv->login_retry_count = cpu_to_le16(8);
7534 nv->interrupt_delay_timer = cpu_to_le16(0);
7535 nv->login_timeout = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007536 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07007537 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7538 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7539 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7540 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7541 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7542 nv->efi_parameters = cpu_to_le32(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007543 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07007544 nv->max_luns_per_target = cpu_to_le16(128);
7545 nv->port_down_retry_count = cpu_to_le16(30);
7546 nv->link_down_timeout = cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07007547 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007548 nv->enode_mac[1] = 0xC0;
7549 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007550 nv->enode_mac[3] = 0x04;
7551 nv->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007552 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007553
7554 rval = 1;
7555 }
7556
Arun Easi9e522cd2012-08-22 14:21:31 -04007557 if (IS_T10_PI_CAPABLE(ha))
7558 nv->frame_payload_size &= ~7;
7559
Arun Easiaa230bc2013-01-30 03:34:39 -05007560 qlt_81xx_config_nvram_stage1(vha, nv);
7561
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007562 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07007563 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007564
7565 /* Copy 1st segment. */
7566 dptr1 = (uint8_t *)icb;
7567 dptr2 = (uint8_t *)&nv->version;
7568 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7569 while (cnt--)
7570 *dptr1++ = *dptr2++;
7571
7572 icb->login_retry_count = nv->login_retry_count;
7573
7574 /* Copy 2nd segment. */
7575 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7576 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7577 cnt = (uint8_t *)&icb->reserved_5 -
7578 (uint8_t *)&icb->interrupt_delay_timer;
7579 while (cnt--)
7580 *dptr1++ = *dptr2++;
7581
7582 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
7583 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
7584 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08007585 icb->enode_mac[0] = 0x00;
7586 icb->enode_mac[1] = 0xC0;
7587 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007588 icb->enode_mac[3] = 0x04;
7589 icb->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007590 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007591 }
7592
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07007593 /* Use extended-initialization control block. */
7594 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
7595
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007596 /*
7597 * Setup driver NVRAM options.
7598 */
7599 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07007600 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007601
Arun Easiaa230bc2013-01-30 03:34:39 -05007602 qlt_81xx_config_nvram_stage2(vha, icb);
7603
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007604 /* Use alternate WWN? */
Bart Van Asschead950362015-07-09 07:24:08 -07007605 if (nv->host_p & cpu_to_le32(BIT_15)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007606 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7607 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7608 }
7609
7610 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07007611 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007612 /*
7613 * Firmware will apply the following mask if the nodename was
7614 * not provided.
7615 */
7616 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7617 icb->node_name[0] &= 0xF0;
7618 }
7619
7620 /* Set host adapter parameters. */
7621 ha->flags.disable_risc_code_load = 0;
7622 ha->flags.enable_lip_reset = 0;
7623 ha->flags.enable_lip_full_login =
7624 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
7625 ha->flags.enable_target_reset =
7626 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
7627 ha->flags.enable_led_scheme = 0;
7628 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
7629
7630 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7631 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7632
7633 /* save HBA serial number */
7634 ha->serial0 = icb->port_name[5];
7635 ha->serial1 = icb->port_name[6];
7636 ha->serial2 = icb->port_name[7];
7637 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7638 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7639
Bart Van Asschead950362015-07-09 07:24:08 -07007640 icb->execution_throttle = cpu_to_le16(0xFFFF);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007641
7642 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7643
7644 /* Set minimum login_timeout to 4 seconds. */
7645 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7646 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7647 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07007648 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007649 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007650
7651 /* Set minimum RATOV to 100 tenths of a second. */
7652 ha->r_a_tov = 100;
7653
7654 ha->loop_reset_delay = nv->reset_delay;
7655
7656 /* Link Down Timeout = 0:
7657 *
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007658 * When Port Down timer expires we will start returning
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007659 * I/O's to OS with "DID_NO_CONNECT".
7660 *
7661 * Link Down Timeout != 0:
7662 *
7663 * The driver waits for the link to come up after link down
7664 * before returning I/Os to OS with "DID_NO_CONNECT".
7665 */
7666 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7667 ha->loop_down_abort_time =
7668 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7669 } else {
7670 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7671 ha->loop_down_abort_time =
7672 (LOOP_DOWN_TIME - ha->link_down_timeout);
7673 }
7674
7675 /* Need enough time to try and get the port back. */
7676 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7677 if (qlport_down_retry)
7678 ha->port_down_retry_count = qlport_down_retry;
7679
7680 /* Set login_retry_count */
7681 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7682 if (ha->port_down_retry_count ==
7683 le16_to_cpu(nv->port_down_retry_count) &&
7684 ha->port_down_retry_count > 3)
7685 ha->login_retry_count = ha->port_down_retry_count;
7686 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7687 ha->login_retry_count = ha->port_down_retry_count;
7688 if (ql2xloginretrycount)
7689 ha->login_retry_count = ql2xloginretrycount;
7690
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007691 /* if not running MSI-X we need handshaking on interrupts */
Chad Dupuisf73cb692014-02-26 04:15:06 -05007692 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
Bart Van Asschead950362015-07-09 07:24:08 -07007693 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007694
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007695 /* Enable ZIO. */
7696 if (!vha->flags.init_done) {
7697 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7698 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7699 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7700 le16_to_cpu(icb->interrupt_delay_timer): 2;
7701 }
Bart Van Asschead950362015-07-09 07:24:08 -07007702 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007703 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7704 vha->flags.process_response_queue = 0;
7705 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7706 ha->zio_mode = QLA_ZIO_MODE_6;
7707
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007708 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007709 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007710 ha->zio_mode,
7711 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007712
7713 icb->firmware_options_2 |= cpu_to_le32(
7714 (uint32_t)ha->zio_mode);
7715 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7716 vha->flags.process_response_queue = 1;
7717 }
7718
Quinn Tran41dc5292017-01-19 22:28:03 -08007719 /* enable RIDA Format2 */
7720 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))
7721 icb->firmware_options_3 |= BIT_0;
7722
Duane Grigsbyedd05de2017-10-13 09:34:06 -07007723 if (IS_QLA27XX(ha)) {
7724 icb->firmware_options_3 |= BIT_8;
7725 ql_dbg(ql_log_info, vha, 0x0075,
7726 "Enabling direct connection.\n");
7727 }
7728
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007729 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007730 ql_log(ql_log_warn, vha, 0x0076,
7731 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007732 }
7733 return (rval);
7734}
7735
Giridhar Malavalia9083012010-04-12 17:59:55 -07007736int
7737qla82xx_restart_isp(scsi_qla_host_t *vha)
7738{
7739 int status, rval;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007740 struct qla_hw_data *ha = vha->hw;
7741 struct req_que *req = ha->req_q_map[0];
7742 struct rsp_que *rsp = ha->rsp_q_map[0];
7743 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07007744 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007745
7746 status = qla2x00_init_rings(vha);
7747 if (!status) {
7748 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7749 ha->flags.chip_reset_done = 1;
7750
7751 status = qla2x00_fw_ready(vha);
7752 if (!status) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07007753 /* Issue a marker after FW becomes ready. */
7754 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007755 vha->flags.online = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04007756 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007757 }
7758
7759 /* if no cable then assume it's good */
7760 if ((vha->device_flags & DFLG_NO_CABLE))
7761 status = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007762 }
7763
7764 if (!status) {
7765 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7766
7767 if (!atomic_read(&vha->loop_down_timer)) {
7768 /*
7769 * Issue marker command only when we are going
7770 * to start the I/O .
7771 */
7772 vha->marker_needed = 1;
7773 }
7774
Giridhar Malavalia9083012010-04-12 17:59:55 -07007775 ha->isp_ops->enable_intrs(ha);
7776
7777 ha->isp_abort_cnt = 0;
7778 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7779
Saurav Kashyap53296782011-05-10 11:30:06 -07007780 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07007781 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07007782
Giridhar Malavalia9083012010-04-12 17:59:55 -07007783 if (ha->fce) {
7784 ha->flags.fce_enabled = 1;
7785 memset(ha->fce, 0,
7786 fce_calc_size(ha->fce_bufs));
7787 rval = qla2x00_enable_fce_trace(vha,
7788 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
7789 &ha->fce_bufs);
7790 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007791 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007792 "Unable to reinitialize FCE (%d).\n",
7793 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007794 ha->flags.fce_enabled = 0;
7795 }
7796 }
7797
7798 if (ha->eft) {
7799 memset(ha->eft, 0, EFT_SIZE);
7800 rval = qla2x00_enable_eft_trace(vha,
7801 ha->eft_dma, EFT_NUM_BUFFERS);
7802 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007803 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007804 "Unable to reinitialize EFT (%d).\n",
7805 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007806 }
7807 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07007808 }
7809
7810 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007811 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007812 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07007813
7814 spin_lock_irqsave(&ha->vport_slock, flags);
7815 list_for_each_entry(vp, &ha->vp_list, list) {
7816 if (vp->vp_idx) {
7817 atomic_inc(&vp->vref_count);
7818 spin_unlock_irqrestore(&ha->vport_slock, flags);
7819
Giridhar Malavalia9083012010-04-12 17:59:55 -07007820 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07007821
7822 spin_lock_irqsave(&ha->vport_slock, flags);
7823 atomic_dec(&vp->vref_count);
7824 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07007825 }
Arun Easifeafb7b2010-09-03 14:57:00 -07007826 spin_unlock_irqrestore(&ha->vport_slock, flags);
7827
Giridhar Malavalia9083012010-04-12 17:59:55 -07007828 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007829 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007830 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07007831 }
7832
7833 return status;
7834}
7835
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007836void
Andrew Vasquezae97c912010-02-18 10:07:28 -08007837qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007838{
Andrew Vasquezae97c912010-02-18 10:07:28 -08007839 struct qla_hw_data *ha = vha->hw;
7840
Himanshu Madhanif198caf2016-01-27 12:03:30 -05007841 /* Hold status IOCBs until ABTS response received. */
7842 if (ql2xfwholdabts)
7843 ha->fw_options[3] |= BIT_12;
7844
Giridhar Malavali088d09d2016-07-06 11:14:20 -04007845 /* Set Retry FLOGI in case of P2P connection */
7846 if (ha->operating_mode == P2P) {
7847 ha->fw_options[2] |= BIT_3;
7848 ql_dbg(ql_dbg_disc, vha, 0x2103,
7849 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
7850 __func__, ha->fw_options[2]);
7851 }
7852
Quinn Tran41dc5292017-01-19 22:28:03 -08007853 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
7854 if (ql2xmvasynctoatio) {
7855 if (qla_tgt_mode_enabled(vha) ||
7856 qla_dual_mode_enabled(vha))
7857 ha->fw_options[2] |= BIT_11;
7858 else
7859 ha->fw_options[2] &= ~BIT_11;
7860 }
Andrew Vasquezae97c912010-02-18 10:07:28 -08007861
Quinn Tranf7e761f2017-06-02 09:12:02 -07007862 if (qla_tgt_mode_enabled(vha) ||
Quinn Tran2da52732017-06-02 09:12:05 -07007863 qla_dual_mode_enabled(vha)) {
7864 /* FW auto send SCSI status during */
7865 ha->fw_options[1] |= BIT_8;
7866 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
7867
7868 /* FW perform Exchange validation */
Quinn Tranf7e761f2017-06-02 09:12:02 -07007869 ha->fw_options[2] |= BIT_4;
Quinn Tran2da52732017-06-02 09:12:05 -07007870 } else {
7871 ha->fw_options[1] &= ~BIT_8;
7872 ha->fw_options[10] &= 0x00ff;
7873
Quinn Tranf7e761f2017-06-02 09:12:02 -07007874 ha->fw_options[2] &= ~BIT_4;
Quinn Tran2da52732017-06-02 09:12:05 -07007875 }
Quinn Tranf7e761f2017-06-02 09:12:02 -07007876
Quinn Tran41dc5292017-01-19 22:28:03 -08007877 if (ql2xetsenable) {
7878 /* Enable ETS Burst. */
7879 memset(ha->fw_options, 0, sizeof(ha->fw_options));
7880 ha->fw_options[2] |= BIT_9;
7881 }
7882
Quinn Tran83548fe2017-06-02 09:12:01 -07007883 ql_dbg(ql_dbg_init, vha, 0x00e9,
7884 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
7885 __func__, ha->fw_options[1], ha->fw_options[2],
7886 ha->fw_options[3], vha->host->active_mode);
Quinn Tran41dc5292017-01-19 22:28:03 -08007887
Andrew Vasquezae97c912010-02-18 10:07:28 -08007888 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007889}
Sarang Radke09ff7012010-03-19 17:03:59 -07007890
7891/*
7892 * qla24xx_get_fcp_prio
7893 * Gets the fcp cmd priority value for the logged in port.
7894 * Looks for a match of the port descriptors within
7895 * each of the fcp prio config entries. If a match is found,
7896 * the tag (priority) value is returned.
7897 *
7898 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007899 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07007900 * fcport = port structure pointer.
7901 *
7902 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07007903 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007904 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07007905 *
7906 * Context:
7907 * Kernel context
7908 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007909static int
Sarang Radke09ff7012010-03-19 17:03:59 -07007910qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
7911{
7912 int i, entries;
7913 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007914 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07007915 uint32_t pid1, pid2;
7916 uint64_t wwn1, wwn2;
7917 struct qla_fcp_prio_entry *pri_entry;
7918 struct qla_hw_data *ha = vha->hw;
7919
7920 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007921 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07007922
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007923 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07007924 entries = ha->fcp_prio_cfg->num_entries;
7925 pri_entry = &ha->fcp_prio_cfg->entry[0];
7926
7927 for (i = 0; i < entries; i++) {
7928 pid_match = wwn_match = 0;
7929
7930 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
7931 pri_entry++;
7932 continue;
7933 }
7934
7935 /* check source pid for a match */
7936 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
7937 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
7938 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
7939 if (pid1 == INVALID_PORT_ID)
7940 pid_match++;
7941 else if (pid1 == pid2)
7942 pid_match++;
7943 }
7944
7945 /* check destination pid for a match */
7946 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
7947 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
7948 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
7949 if (pid1 == INVALID_PORT_ID)
7950 pid_match++;
7951 else if (pid1 == pid2)
7952 pid_match++;
7953 }
7954
7955 /* check source WWN for a match */
7956 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
7957 wwn1 = wwn_to_u64(vha->port_name);
7958 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
7959 if (wwn2 == (uint64_t)-1)
7960 wwn_match++;
7961 else if (wwn1 == wwn2)
7962 wwn_match++;
7963 }
7964
7965 /* check destination WWN for a match */
7966 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
7967 wwn1 = wwn_to_u64(fcport->port_name);
7968 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
7969 if (wwn2 == (uint64_t)-1)
7970 wwn_match++;
7971 else if (wwn1 == wwn2)
7972 wwn_match++;
7973 }
7974
7975 if (pid_match == 2 || wwn_match == 2) {
7976 /* Found a matching entry */
7977 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
7978 priority = pri_entry->tag;
7979 break;
7980 }
7981
7982 pri_entry++;
7983 }
7984
7985 return priority;
7986}
7987
7988/*
7989 * qla24xx_update_fcport_fcp_prio
7990 * Activates fcp priority for the logged in fc port
7991 *
7992 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007993 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07007994 * fcp = port structure pointer.
7995 *
7996 * Return:
7997 * QLA_SUCCESS or QLA_FUNCTION_FAILED
7998 *
7999 * Context:
8000 * Kernel context.
8001 */
8002int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008003qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07008004{
8005 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008006 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07008007 uint16_t mb[5];
8008
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008009 if (fcport->port_type != FCT_TARGET ||
8010 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07008011 return QLA_FUNCTION_FAILED;
8012
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008013 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07008014 if (priority < 0)
8015 return QLA_FUNCTION_FAILED;
8016
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04008017 if (IS_P3P_TYPE(vha->hw)) {
Saurav Kashyapa00f6292011-11-18 09:03:19 -08008018 fcport->fcp_prio = priority & 0xf;
8019 return QLA_SUCCESS;
8020 }
8021
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08008022 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08008023 if (ret == QLA_SUCCESS) {
8024 if (fcport->fcp_prio != priority)
8025 ql_dbg(ql_dbg_user, vha, 0x709e,
8026 "Updated FCP_CMND priority - value=%d loop_id=%d "
8027 "port_id=%02x%02x%02x.\n", priority,
8028 fcport->loop_id, fcport->d_id.b.domain,
8029 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08008030 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08008031 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07008032 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08008033 "Unable to update FCP_CMND priority - ret=0x%x for "
8034 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8035 fcport->d_id.b.domain, fcport->d_id.b.area,
8036 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07008037 return ret;
8038}
8039
8040/*
8041 * qla24xx_update_all_fcp_prio
8042 * Activates fcp priority for all the logged in ports
8043 *
8044 * Input:
8045 * ha = adapter block pointer.
8046 *
8047 * Return:
8048 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8049 *
8050 * Context:
8051 * Kernel context.
8052 */
8053int
8054qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8055{
8056 int ret;
8057 fc_port_t *fcport;
8058
8059 ret = QLA_FUNCTION_FAILED;
8060 /* We need to set priority for all logged in ports */
8061 list_for_each_entry(fcport, &vha->vp_fcports, list)
8062 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8063
8064 return ret;
8065}
Michael Hernandezd7459522016-12-12 14:40:07 -08008066
Quinn Tran82de8022017-06-13 20:47:17 -07008067struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8068 int vp_idx, bool startqp)
Michael Hernandezd7459522016-12-12 14:40:07 -08008069{
8070 int rsp_id = 0;
8071 int req_id = 0;
8072 int i;
8073 struct qla_hw_data *ha = vha->hw;
8074 uint16_t qpair_id = 0;
8075 struct qla_qpair *qpair = NULL;
8076 struct qla_msix_entry *msix;
8077
8078 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8079 ql_log(ql_log_warn, vha, 0x00181,
8080 "FW/Driver is not multi-queue capable.\n");
8081 return NULL;
8082 }
8083
Himanshu Madhanic38d1ba2017-10-13 15:43:22 -07008084 if (ql2xmqsupport || ql2xnvmeenable) {
Michael Hernandezd7459522016-12-12 14:40:07 -08008085 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8086 if (qpair == NULL) {
8087 ql_log(ql_log_warn, vha, 0x0182,
8088 "Failed to allocate memory for queue pair.\n");
8089 return NULL;
8090 }
8091 memset(qpair, 0, sizeof(struct qla_qpair));
8092
8093 qpair->hw = vha->hw;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08008094 qpair->vha = vha;
Quinn Tran82de8022017-06-13 20:47:17 -07008095 qpair->qp_lock_ptr = &qpair->qp_lock;
8096 spin_lock_init(&qpair->qp_lock);
Quinn Tranaf7bb382017-06-13 20:47:23 -07008097 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
Michael Hernandezd7459522016-12-12 14:40:07 -08008098
8099 /* Assign available que pair id */
8100 mutex_lock(&ha->mq_lock);
8101 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
Sawan Chandakb95b9452017-05-24 18:06:20 -07008102 if (ha->num_qpairs >= ha->max_qpairs) {
Michael Hernandezd7459522016-12-12 14:40:07 -08008103 mutex_unlock(&ha->mq_lock);
8104 ql_log(ql_log_warn, vha, 0x0183,
8105 "No resources to create additional q pair.\n");
8106 goto fail_qid_map;
8107 }
Sawan Chandakb95b9452017-05-24 18:06:20 -07008108 ha->num_qpairs++;
Michael Hernandezd7459522016-12-12 14:40:07 -08008109 set_bit(qpair_id, ha->qpair_qid_map);
8110 ha->queue_pair_map[qpair_id] = qpair;
8111 qpair->id = qpair_id;
8112 qpair->vp_idx = vp_idx;
himanshu.madhani@cavium.come6373f332017-08-23 15:04:57 -07008113 qpair->fw_started = ha->flags.fw_started;
Quinn Trane326d222017-06-13 20:47:18 -07008114 INIT_LIST_HEAD(&qpair->hints_list);
Duane Grigsbycf19c452017-08-23 15:04:58 -07008115 INIT_LIST_HEAD(&qpair->nvme_done_list);
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07008116 qpair->chip_reset = ha->base_qpair->chip_reset;
8117 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8118 qpair->enable_explicit_conf =
8119 ha->base_qpair->enable_explicit_conf;
Michael Hernandezd7459522016-12-12 14:40:07 -08008120
8121 for (i = 0; i < ha->msix_count; i++) {
Quinn Tran093df732016-12-12 14:40:09 -08008122 msix = &ha->msix_entries[i];
Michael Hernandezd7459522016-12-12 14:40:07 -08008123 if (msix->in_use)
8124 continue;
8125 qpair->msix = msix;
Quinn Tran83548fe2017-06-02 09:12:01 -07008126 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
Michael Hernandezd7459522016-12-12 14:40:07 -08008127 "Vector %x selected for qpair\n", msix->vector);
8128 break;
8129 }
8130 if (!qpair->msix) {
8131 ql_log(ql_log_warn, vha, 0x0184,
8132 "Out of MSI-X vectors!.\n");
8133 goto fail_msix;
8134 }
8135
8136 qpair->msix->in_use = 1;
8137 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
Quinn Tran8abfa9e2017-06-13 20:47:24 -07008138 qpair->pdev = ha->pdev;
8139 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
8140 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
Michael Hernandezd7459522016-12-12 14:40:07 -08008141
8142 mutex_unlock(&ha->mq_lock);
8143
8144 /* Create response queue first */
Quinn Tran82de8022017-06-13 20:47:17 -07008145 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
Michael Hernandezd7459522016-12-12 14:40:07 -08008146 if (!rsp_id) {
8147 ql_log(ql_log_warn, vha, 0x0185,
8148 "Failed to create response queue.\n");
8149 goto fail_rsp;
8150 }
8151
8152 qpair->rsp = ha->rsp_q_map[rsp_id];
8153
8154 /* Create request queue */
Quinn Tran82de8022017-06-13 20:47:17 -07008155 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
8156 startqp);
Michael Hernandezd7459522016-12-12 14:40:07 -08008157 if (!req_id) {
8158 ql_log(ql_log_warn, vha, 0x0186,
8159 "Failed to create request queue.\n");
8160 goto fail_req;
8161 }
8162
8163 qpair->req = ha->req_q_map[req_id];
8164 qpair->rsp->req = qpair->req;
Quinn Tran82de8022017-06-13 20:47:17 -07008165 qpair->rsp->qpair = qpair;
Quinn Trane326d222017-06-13 20:47:18 -07008166 /* init qpair to this cpu. Will adjust at run time. */
8167 qla_cpu_update(qpair, smp_processor_id());
Michael Hernandezd7459522016-12-12 14:40:07 -08008168
8169 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
8170 if (ha->fw_attributes & BIT_4)
8171 qpair->difdix_supported = 1;
8172 }
8173
8174 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
8175 if (!qpair->srb_mempool) {
Quinn Tran83548fe2017-06-02 09:12:01 -07008176 ql_log(ql_log_warn, vha, 0xd036,
Michael Hernandezd7459522016-12-12 14:40:07 -08008177 "Failed to create srb mempool for qpair %d\n",
8178 qpair->id);
8179 goto fail_mempool;
8180 }
8181
8182 /* Mark as online */
8183 qpair->online = 1;
8184
8185 if (!vha->flags.qpairs_available)
8186 vha->flags.qpairs_available = 1;
8187
8188 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
8189 "Request/Response queue pair created, id %d\n",
8190 qpair->id);
8191 ql_dbg(ql_dbg_init, vha, 0x0187,
8192 "Request/Response queue pair created, id %d\n",
8193 qpair->id);
8194 }
8195 return qpair;
8196
8197fail_mempool:
8198fail_req:
8199 qla25xx_delete_rsp_que(vha, qpair->rsp);
8200fail_rsp:
8201 mutex_lock(&ha->mq_lock);
8202 qpair->msix->in_use = 0;
8203 list_del(&qpair->qp_list_elem);
8204 if (list_empty(&vha->qp_list))
8205 vha->flags.qpairs_available = 0;
8206fail_msix:
8207 ha->queue_pair_map[qpair_id] = NULL;
8208 clear_bit(qpair_id, ha->qpair_qid_map);
Sawan Chandakb95b9452017-05-24 18:06:20 -07008209 ha->num_qpairs--;
Michael Hernandezd7459522016-12-12 14:40:07 -08008210 mutex_unlock(&ha->mq_lock);
8211fail_qid_map:
8212 kfree(qpair);
8213 return NULL;
8214}
8215
8216int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
8217{
Sawan Chandakd65237c2017-06-13 20:47:19 -07008218 int ret = QLA_FUNCTION_FAILED;
Michael Hernandezd7459522016-12-12 14:40:07 -08008219 struct qla_hw_data *ha = qpair->hw;
8220
Sawan Chandakd65237c2017-06-13 20:47:19 -07008221 if (!vha->flags.qpairs_req_created && !vha->flags.qpairs_rsp_created)
8222 goto fail;
8223
Michael Hernandezd7459522016-12-12 14:40:07 -08008224 qpair->delete_in_progress = 1;
8225 while (atomic_read(&qpair->ref_count))
8226 msleep(500);
8227
8228 ret = qla25xx_delete_req_que(vha, qpair->req);
8229 if (ret != QLA_SUCCESS)
8230 goto fail;
8231 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
8232 if (ret != QLA_SUCCESS)
8233 goto fail;
8234
8235 mutex_lock(&ha->mq_lock);
8236 ha->queue_pair_map[qpair->id] = NULL;
8237 clear_bit(qpair->id, ha->qpair_qid_map);
Sawan Chandakb95b9452017-05-24 18:06:20 -07008238 ha->num_qpairs--;
Michael Hernandezd7459522016-12-12 14:40:07 -08008239 list_del(&qpair->qp_list_elem);
Sawan Chandakd65237c2017-06-13 20:47:19 -07008240 if (list_empty(&vha->qp_list)) {
Michael Hernandezd7459522016-12-12 14:40:07 -08008241 vha->flags.qpairs_available = 0;
Sawan Chandakd65237c2017-06-13 20:47:19 -07008242 vha->flags.qpairs_req_created = 0;
8243 vha->flags.qpairs_rsp_created = 0;
8244 }
Michael Hernandezd7459522016-12-12 14:40:07 -08008245 mempool_destroy(qpair->srb_mempool);
8246 kfree(qpair);
8247 mutex_unlock(&ha->mq_lock);
8248
8249 return QLA_SUCCESS;
8250fail:
8251 return ret;
8252}