blob: 4c53199db371f933b2ce7800689724449fd49574 [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
48qla2x00_sp_timeout(unsigned long __data)
Andrew Vasquezac280b62009-08-20 11:06:05 -070049{
50 srb_t *sp = (srb_t *)__data;
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;
866
867 fcport->flags &= ~FCF_ASYNC_SENT;
868
Quinn Tran83548fe2017-06-02 09:12:01 -0700869 ql_dbg(ql_dbg_disc, vha, 0x20d2,
Quinn Tran726b8542017-01-19 22:28:00 -0800870 "%s %8phC DS %d LS %d rval %d\n", __func__, fcport->port_name,
871 fcport->disc_state, fcport->fw_login_state, rval);
872
873 if (ea->sp->gen2 != fcport->login_gen) {
874 /* target side must have changed it. */
Quinn Tran83548fe2017-06-02 09:12:01 -0700875 ql_dbg(ql_dbg_disc, vha, 0x20d3,
Quinn Tran726b8542017-01-19 22:28:00 -0800876 "%s %8phC generation changed rscn %d|%d login %d|%d \n",
877 __func__, fcport->port_name, fcport->last_rscn_gen,
878 fcport->rscn_gen, fcport->last_login_gen,
879 fcport->login_gen);
880 return;
881 } else if (ea->sp->gen1 != fcport->rscn_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700882 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
Quinn Tran726b8542017-01-19 22:28:00 -0800883 __func__, __LINE__, fcport->port_name);
884 qla24xx_post_gidpn_work(vha, fcport);
885 return;
886 }
887
888 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700889 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
Quinn Tran726b8542017-01-19 22:28:00 -0800890 __func__, __LINE__, fcport->port_name);
891 qlt_schedule_sess_for_deletion_lock(fcport);
892 return;
893 }
894
895 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
896 ea->fcport->login_gen++;
897 ea->fcport->deleted = 0;
898 ea->fcport->logout_on_delete = 1;
899
900 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
901 vha->fcport_count++;
902 ea->fcport->login_succ = 1;
903
904 if (!IS_IIDMA_CAPABLE(vha->hw) ||
905 !vha->hw->flags.gpsc_supported) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700906 ql_dbg(ql_dbg_disc, vha, 0x20d6,
Quinn Tran726b8542017-01-19 22:28:00 -0800907 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
908 __func__, __LINE__, fcport->port_name,
909 vha->fcport_count);
910
911 qla24xx_post_upd_fcport_work(vha, fcport);
912 } else {
Quinn Tran83548fe2017-06-02 09:12:01 -0700913 ql_dbg(ql_dbg_disc, vha, 0x20d7,
Quinn Tran726b8542017-01-19 22:28:00 -0800914 "%s %d %8phC post gpsc fcp_cnt %d\n",
915 __func__, __LINE__, fcport->port_name,
916 vha->fcport_count);
917
918 qla24xx_post_gpsc_work(vha, fcport);
919 }
920 }
921 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
922} /* gpdb event */
923
924int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
925{
926 if (fcport->login_retry == 0)
927 return 0;
928
929 if (fcport->scan_state != QLA_FCPORT_FOUND)
930 return 0;
931
Quinn Tran83548fe2017-06-02 09:12:01 -0700932 ql_dbg(ql_dbg_disc, vha, 0x20d8,
Quinn Tran726b8542017-01-19 22:28:00 -0800933 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d|%d retry %d lid %d\n",
934 __func__, fcport->port_name, fcport->disc_state,
935 fcport->fw_login_state, fcport->login_pause, fcport->flags,
936 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
937 fcport->last_login_gen, fcport->login_gen, fcport->login_retry,
938 fcport->loop_id);
939
940 fcport->login_retry--;
941
942 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
Quinn Tran726b8542017-01-19 22:28:00 -0800943 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
944 return 0;
945
Quinn Tran5b334692017-03-15 09:48:48 -0700946 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
947 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline))
948 return 0;
949 }
950
Quinn Tran726b8542017-01-19 22:28:00 -0800951 /* for pure Target Mode. Login will not be initiated */
952 if (vha->host->active_mode == MODE_TARGET)
953 return 0;
954
955 if (fcport->flags & FCF_ASYNC_SENT) {
956 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
957 return 0;
958 }
959
960 switch (fcport->disc_state) {
961 case DSC_DELETED:
962 if (fcport->loop_id == FC_NO_LOOP_ID) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700963 ql_dbg(ql_dbg_disc, vha, 0x20bd,
964 "%s %d %8phC post gnl\n",
965 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800966 qla24xx_async_gnl(vha, fcport);
967 } else {
Quinn Tran83548fe2017-06-02 09:12:01 -0700968 ql_dbg(ql_dbg_disc, vha, 0x20bf,
969 "%s %d %8phC post login\n",
970 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800971 fcport->disc_state = DSC_LOGIN_PEND;
972 qla2x00_post_async_login_work(vha, fcport, NULL);
973 }
974 break;
975
976 case DSC_GNL:
977 if (fcport->login_pause) {
978 fcport->last_rscn_gen = fcport->rscn_gen;
979 fcport->last_login_gen = fcport->login_gen;
980 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
981 break;
982 }
983
984 if (fcport->flags & FCF_FCP2_DEVICE) {
985 u8 opt = PDO_FORCE_ADISC;
986
Quinn Tran83548fe2017-06-02 09:12:01 -0700987 ql_dbg(ql_dbg_disc, vha, 0x20c9,
988 "%s %d %8phC post gpdb\n",
989 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800990
991 fcport->disc_state = DSC_GPDB;
992 qla24xx_post_gpdb_work(vha, fcport, opt);
993 } else {
Quinn Tran83548fe2017-06-02 09:12:01 -0700994 ql_dbg(ql_dbg_disc, vha, 0x20cf,
995 "%s %d %8phC post login\n",
996 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -0800997 fcport->disc_state = DSC_LOGIN_PEND;
998 qla2x00_post_async_login_work(vha, fcport, NULL);
999 }
1000
1001 break;
1002
1003 case DSC_LOGIN_FAILED:
Quinn Tran83548fe2017-06-02 09:12:01 -07001004 ql_dbg(ql_dbg_disc, vha, 0x20d0,
1005 "%s %d %8phC post gidpn\n",
1006 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -08001007
1008 qla24xx_post_gidpn_work(vha, fcport);
1009 break;
1010
1011 case DSC_LOGIN_COMPLETE:
1012 /* recheck login state */
Quinn Tran83548fe2017-06-02 09:12:01 -07001013 ql_dbg(ql_dbg_disc, vha, 0x20d1,
1014 "%s %d %8phC post gpdb\n",
1015 __func__, __LINE__, fcport->port_name);
Quinn Tran726b8542017-01-19 22:28:00 -08001016
1017 qla24xx_post_gpdb_work(vha, fcport, PDO_FORCE_ADISC);
1018 break;
1019
1020 default:
1021 break;
1022 }
1023
1024 return 0;
1025}
1026
1027static
1028void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea)
1029{
1030 fcport->rscn_gen++;
1031
Quinn Tran83548fe2017-06-02 09:12:01 -07001032 ql_dbg(ql_dbg_disc, fcport->vha, 0x210c,
1033 "%s %8phC DS %d LS %d\n",
1034 __func__, fcport->port_name, fcport->disc_state,
1035 fcport->fw_login_state);
Quinn Tran726b8542017-01-19 22:28:00 -08001036
1037 if (fcport->flags & FCF_ASYNC_SENT)
1038 return;
1039
1040 switch (fcport->disc_state) {
1041 case DSC_DELETED:
1042 case DSC_LOGIN_COMPLETE:
1043 qla24xx_post_gidpn_work(fcport->vha, fcport);
1044 break;
1045
1046 default:
1047 break;
1048 }
1049}
1050
1051int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1052 u8 *port_name, void *pla)
1053{
1054 struct qla_work_evt *e;
1055 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1056 if (!e)
1057 return QLA_FUNCTION_FAILED;
1058
1059 e->u.new_sess.id = *id;
1060 e->u.new_sess.pla = pla;
1061 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1062
1063 return qla2x00_post_work(vha, e);
1064}
1065
1066static
1067int qla24xx_handle_delete_done_event(scsi_qla_host_t *vha,
1068 struct event_arg *ea)
1069{
1070 fc_port_t *fcport = ea->fcport;
1071
1072 if (test_bit(UNLOADING, &vha->dpc_flags))
1073 return 0;
1074
1075 switch (vha->host->active_mode) {
1076 case MODE_INITIATOR:
1077 case MODE_DUAL:
1078 if (fcport->scan_state == QLA_FCPORT_FOUND)
1079 qla24xx_fcport_handle_login(vha, fcport);
1080 break;
1081
1082 case MODE_TARGET:
1083 default:
1084 /* no-op */
1085 break;
1086 }
1087
1088 return 0;
1089}
1090
1091static
1092void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1093 struct event_arg *ea)
1094{
1095 fc_port_t *fcport = ea->fcport;
1096
1097 if (fcport->scan_state != QLA_FCPORT_FOUND) {
1098 fcport->login_retry++;
1099 return;
1100 }
1101
Quinn Tran83548fe2017-06-02 09:12:01 -07001102 ql_dbg(ql_dbg_disc, vha, 0x2102,
1103 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1104 __func__, fcport->port_name, fcport->disc_state,
1105 fcport->fw_login_state, fcport->login_pause,
1106 fcport->deleted, fcport->conflict,
1107 fcport->last_rscn_gen, fcport->rscn_gen,
1108 fcport->last_login_gen, fcport->login_gen,
1109 fcport->flags);
Quinn Tran726b8542017-01-19 22:28:00 -08001110
1111 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
Quinn Tran726b8542017-01-19 22:28:00 -08001112 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1113 return;
1114
Quinn Tran5b334692017-03-15 09:48:48 -07001115 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1116 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline))
1117 return;
1118 }
1119
Quinn Tran726b8542017-01-19 22:28:00 -08001120 if (fcport->flags & FCF_ASYNC_SENT) {
1121 fcport->login_retry++;
1122 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1123 return;
1124 }
1125
1126 if (fcport->disc_state == DSC_DELETE_PEND) {
1127 fcport->login_retry++;
1128 return;
1129 }
1130
1131 if (fcport->last_rscn_gen != fcport->rscn_gen) {
Quinn Tran83548fe2017-06-02 09:12:01 -07001132 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n",
Quinn Tran726b8542017-01-19 22:28:00 -08001133 __func__, __LINE__, fcport->port_name);
1134
1135 qla24xx_async_gidpn(vha, fcport);
1136 return;
1137 }
1138
1139 qla24xx_fcport_handle_login(vha, fcport);
1140}
1141
Quinn Tran41dc5292017-01-19 22:28:03 -08001142void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
Quinn Tran726b8542017-01-19 22:28:00 -08001143{
Quinn Tran41dc5292017-01-19 22:28:03 -08001144 fc_port_t *fcport, *f, *tf;
1145 uint32_t id = 0, mask, rid;
Quinn Tran726b8542017-01-19 22:28:00 -08001146 int rc;
1147
1148 switch (ea->event) {
1149 case FCME_RELOGIN:
Quinn Tranb98ae0d2017-06-02 09:12:00 -07001150 case FCME_RSCN:
1151 case FCME_GIDPN_DONE:
1152 case FCME_GPSC_DONE:
1153 case FCME_GPNID_DONE:
1154 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
1155 test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))
1156 return;
1157 break;
1158 default:
1159 break;
1160 }
1161
1162 switch (ea->event) {
1163 case FCME_RELOGIN:
Quinn Tran726b8542017-01-19 22:28:00 -08001164 if (test_bit(UNLOADING, &vha->dpc_flags))
1165 return;
1166
1167 qla24xx_handle_relogin_event(vha, ea);
1168 break;
1169 case FCME_RSCN:
1170 if (test_bit(UNLOADING, &vha->dpc_flags))
1171 return;
Quinn Tran41dc5292017-01-19 22:28:03 -08001172 switch (ea->id.b.rsvd_1) {
1173 case RSCN_PORT_ADDR:
1174 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1175 if (!fcport) {
1176 /* cable moved */
1177 rc = qla24xx_post_gpnid_work(vha, &ea->id);
1178 if (rc) {
Quinn Tran83548fe2017-06-02 09:12:01 -07001179 ql_log(ql_log_warn, vha, 0xd044,
1180 "RSCN GPNID work failed %02x%02x%02x\n",
1181 ea->id.b.domain, ea->id.b.area,
1182 ea->id.b.al_pa);
Quinn Tran41dc5292017-01-19 22:28:03 -08001183 }
1184 } else {
1185 ea->fcport = fcport;
1186 qla24xx_handle_rscn_event(fcport, ea);
Quinn Tran726b8542017-01-19 22:28:00 -08001187 }
Quinn Tran41dc5292017-01-19 22:28:03 -08001188 break;
1189 case RSCN_AREA_ADDR:
1190 case RSCN_DOM_ADDR:
1191 if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) {
1192 mask = 0xffff00;
Quinn Tran83548fe2017-06-02 09:12:01 -07001193 ql_dbg(ql_dbg_async, vha, 0x5044,
1194 "RSCN: Area 0x%06x was affected\n",
1195 ea->id.b24);
Quinn Tran41dc5292017-01-19 22:28:03 -08001196 } else {
1197 mask = 0xff0000;
Quinn Tran83548fe2017-06-02 09:12:01 -07001198 ql_dbg(ql_dbg_async, vha, 0x507a,
1199 "RSCN: Domain 0x%06x was affected\n",
1200 ea->id.b24);
Quinn Tran41dc5292017-01-19 22:28:03 -08001201 }
1202
1203 rid = ea->id.b24 & mask;
1204 list_for_each_entry_safe(f, tf, &vha->vp_fcports,
1205 list) {
1206 id = f->d_id.b24 & mask;
1207 if (rid == id) {
1208 ea->fcport = f;
1209 qla24xx_handle_rscn_event(f, ea);
1210 }
1211 }
1212 break;
1213 case RSCN_FAB_ADDR:
1214 default:
Quinn Tran83548fe2017-06-02 09:12:01 -07001215 ql_log(ql_log_warn, vha, 0xd045,
1216 "RSCN: Fabric was affected. Addr format %d\n",
1217 ea->id.b.rsvd_1);
Quinn Tran41dc5292017-01-19 22:28:03 -08001218 qla2x00_mark_all_devices_lost(vha, 1);
1219 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1220 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Quinn Tran726b8542017-01-19 22:28:00 -08001221 }
1222 break;
1223 case FCME_GIDPN_DONE:
1224 qla24xx_handle_gidpn_event(vha, ea);
1225 break;
1226 case FCME_GNL_DONE:
1227 qla24xx_handle_gnl_done_event(vha, ea);
1228 break;
1229 case FCME_GPSC_DONE:
1230 qla24xx_post_upd_fcport_work(vha, ea->fcport);
1231 break;
1232 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1233 qla24xx_handle_plogi_done_event(vha, ea);
1234 break;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001235 case FCME_PRLI_DONE:
1236 qla24xx_handle_prli_done_event(vha, ea);
1237 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001238 case FCME_GPDB_DONE:
1239 qla24xx_handle_gpdb_event(vha, ea);
1240 break;
1241 case FCME_GPNID_DONE:
1242 qla24xx_handle_gpnid_event(vha, ea);
1243 break;
Duane Grigsbyd3bae932017-06-21 13:48:44 -07001244 case FCME_GFFID_DONE:
1245 qla24xx_handle_gffid_event(vha, ea);
1246 break;
Quinn Tran726b8542017-01-19 22:28:00 -08001247 case FCME_DELETE_DONE:
1248 qla24xx_handle_delete_done_event(vha, ea);
1249 break;
1250 default:
1251 BUG_ON(1);
1252 break;
1253 }
1254}
1255
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001256static void
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001257qla2x00_tmf_iocb_timeout(void *data)
1258{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001259 srb_t *sp = data;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001260 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1261
1262 tmf->u.tmf.comp_status = CS_TIMEOUT;
1263 complete(&tmf->u.tmf.comp);
1264}
1265
1266static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001267qla2x00_tmf_sp_done(void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001268{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001269 srb_t *sp = ptr;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001270 struct srb_iocb *tmf = &sp->u.iocb_cmd;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001271
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001272 complete(&tmf->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001273}
1274
1275int
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001276qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001277 uint32_t tag)
1278{
1279 struct scsi_qla_host *vha = fcport->vha;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001280 struct srb_iocb *tm_iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001281 srb_t *sp;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001282 int rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001283
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001284 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001285 if (!sp)
1286 goto done;
1287
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001288 tm_iocb = &sp->u.iocb_cmd;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001289 sp->type = SRB_TM_CMD;
1290 sp->name = "tmf";
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001291 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1292 tm_iocb->u.tmf.flags = flags;
1293 tm_iocb->u.tmf.lun = lun;
1294 tm_iocb->u.tmf.data = tag;
1295 sp->done = qla2x00_tmf_sp_done;
1296 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1297 init_completion(&tm_iocb->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001298
1299 rval = qla2x00_start_sp(sp);
1300 if (rval != QLA_SUCCESS)
1301 goto done_free_sp;
1302
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001303 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001304 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1305 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1306 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001307
1308 wait_for_completion(&tm_iocb->u.tmf.comp);
1309
1310 rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
1311 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1312
1313 if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
1314 ql_dbg(ql_dbg_taskm, vha, 0x8030,
1315 "TM IOCB failed (%x).\n", rval);
1316 }
1317
1318 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1319 flags = tm_iocb->u.tmf.flags;
1320 lun = (uint16_t)tm_iocb->u.tmf.lun;
1321
1322 /* Issue Marker IOCB */
1323 qla2x00_marker(vha, vha->hw->req_q_map[0],
1324 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
1325 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1326 }
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001327
1328done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001329 sp->free(sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001330done:
1331 return rval;
1332}
1333
Armen Baloyan4440e462014-02-26 04:15:18 -05001334static void
1335qla24xx_abort_iocb_timeout(void *data)
1336{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001337 srb_t *sp = data;
Armen Baloyan4440e462014-02-26 04:15:18 -05001338 struct srb_iocb *abt = &sp->u.iocb_cmd;
1339
1340 abt->u.abt.comp_status = CS_TIMEOUT;
1341 complete(&abt->u.abt.comp);
1342}
1343
1344static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001345qla24xx_abort_sp_done(void *ptr, int res)
Armen Baloyan4440e462014-02-26 04:15:18 -05001346{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001347 srb_t *sp = ptr;
Armen Baloyan4440e462014-02-26 04:15:18 -05001348 struct srb_iocb *abt = &sp->u.iocb_cmd;
1349
1350 complete(&abt->u.abt.comp);
1351}
1352
Quinn Tran15f30a52017-03-15 09:48:52 -07001353int
Armen Baloyan4440e462014-02-26 04:15:18 -05001354qla24xx_async_abort_cmd(srb_t *cmd_sp)
1355{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001356 scsi_qla_host_t *vha = cmd_sp->vha;
Armen Baloyan4440e462014-02-26 04:15:18 -05001357 fc_port_t *fcport = cmd_sp->fcport;
1358 struct srb_iocb *abt_iocb;
1359 srb_t *sp;
1360 int rval = QLA_FUNCTION_FAILED;
1361
1362 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1363 if (!sp)
1364 goto done;
1365
1366 abt_iocb = &sp->u.iocb_cmd;
1367 sp->type = SRB_ABT_CMD;
1368 sp->name = "abort";
1369 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1370 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
1371 sp->done = qla24xx_abort_sp_done;
1372 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
1373 init_completion(&abt_iocb->u.abt.comp);
1374
1375 rval = qla2x00_start_sp(sp);
1376 if (rval != QLA_SUCCESS)
1377 goto done_free_sp;
1378
1379 ql_dbg(ql_dbg_async, vha, 0x507c,
1380 "Abort command issued - hdl=%x, target_id=%x\n",
1381 cmd_sp->handle, fcport->tgt_id);
1382
1383 wait_for_completion(&abt_iocb->u.abt.comp);
1384
1385 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
1386 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1387
1388done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001389 sp->free(sp);
Armen Baloyan4440e462014-02-26 04:15:18 -05001390done:
1391 return rval;
1392}
1393
1394int
1395qla24xx_async_abort_command(srb_t *sp)
1396{
1397 unsigned long flags = 0;
1398
1399 uint32_t handle;
1400 fc_port_t *fcport = sp->fcport;
1401 struct scsi_qla_host *vha = fcport->vha;
1402 struct qla_hw_data *ha = vha->hw;
1403 struct req_que *req = vha->req;
1404
1405 spin_lock_irqsave(&ha->hardware_lock, flags);
1406 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1407 if (req->outstanding_cmds[handle] == sp)
1408 break;
1409 }
1410 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1411 if (handle == req->num_outstanding_cmds) {
1412 /* Command not found. */
1413 return QLA_FUNCTION_FAILED;
1414 }
1415 if (sp->type == SRB_FXIOCB_DCMD)
1416 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1417 FXDISC_ABORT_IOCTL);
1418
1419 return qla24xx_async_abort_cmd(sp);
1420}
1421
Quinn Tran726b8542017-01-19 22:28:00 -08001422static void
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001423qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1424{
1425 switch (ea->data[0]) {
1426 case MBS_COMMAND_COMPLETE:
1427 ql_dbg(ql_dbg_disc, vha, 0x2118,
1428 "%s %d %8phC post gpdb\n",
1429 __func__, __LINE__, ea->fcport->port_name);
1430
1431 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1432 ea->fcport->logout_on_delete = 1;
1433 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1434 break;
1435 default:
1436 ql_dbg(ql_dbg_disc, vha, 0x2119,
1437 "%s %d %8phC unhandle event of %x\n",
1438 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1439 break;
1440 }
1441}
1442
1443static void
Quinn Tran726b8542017-01-19 22:28:00 -08001444qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001445{
Quinn Tran726b8542017-01-19 22:28:00 -08001446 port_id_t cid; /* conflict Nport id */
Andrew Vasquezac280b62009-08-20 11:06:05 -07001447
Quinn Tran726b8542017-01-19 22:28:00 -08001448 switch (ea->data[0]) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07001449 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -07001450 /*
1451 * Driver must validate login state - If PRLI not complete,
1452 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1453 * requests.
1454 */
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001455 if (ea->fcport->fc4f_nvme) {
1456 ql_dbg(ql_dbg_disc, vha, 0x2117,
1457 "%s %d %8phC post prli\n",
1458 __func__, __LINE__, ea->fcport->port_name);
1459 qla24xx_post_prli_work(vha, ea->fcport);
1460 } else {
1461 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1462 "%s %d %8phC post gpdb\n",
1463 __func__, __LINE__, ea->fcport->port_name);
1464 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1465 ea->fcport->logout_on_delete = 1;
Quinn Tran35158322017-08-30 10:16:50 -07001466 ea->fcport->send_els_logo = 0;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07001467 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1468 }
Andrew Vasquezac280b62009-08-20 11:06:05 -07001469 break;
1470 case MBS_COMMAND_ERROR:
Quinn Tran83548fe2017-06-02 09:12:01 -07001471 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
Quinn Tran726b8542017-01-19 22:28:00 -08001472 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
1473
1474 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1475 ea->fcport->disc_state = DSC_LOGIN_FAILED;
1476 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001477 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1478 else
Quinn Tran726b8542017-01-19 22:28:00 -08001479 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001480 break;
1481 case MBS_LOOP_ID_USED:
Quinn Tran726b8542017-01-19 22:28:00 -08001482 /* data[1] = IO PARAM 1 = nport ID */
1483 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
1484 cid.b.area = (ea->iop[1] >> 8) & 0xff;
1485 cid.b.al_pa = ea->iop[1] & 0xff;
1486 cid.b.rsvd_1 = 0;
1487
Quinn Tran83548fe2017-06-02 09:12:01 -07001488 ql_dbg(ql_dbg_disc, vha, 0x20ec,
1489 "%s %d %8phC LoopID 0x%x in use post gnl\n",
1490 __func__, __LINE__, ea->fcport->port_name,
1491 ea->fcport->loop_id);
Quinn Tran726b8542017-01-19 22:28:00 -08001492
1493 if (IS_SW_RESV_ADDR(cid)) {
1494 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1495 ea->fcport->loop_id = FC_NO_LOOP_ID;
1496 } else {
1497 qla2x00_clear_loop_id(ea->fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001498 }
Quinn Tran726b8542017-01-19 22:28:00 -08001499 qla24xx_post_gnl_work(vha, ea->fcport);
1500 break;
1501 case MBS_PORT_ID_USED:
Quinn Tran83548fe2017-06-02 09:12:01 -07001502 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1503 "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n",
1504 __func__, __LINE__, ea->fcport->port_name,
1505 ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area,
1506 ea->fcport->d_id.b.al_pa);
Quinn Tran726b8542017-01-19 22:28:00 -08001507
1508 qla2x00_clear_loop_id(ea->fcport);
1509 qla24xx_post_gidpn_work(vha, ea->fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001510 break;
1511 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001512 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001513}
1514
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001515void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001516qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1517 uint16_t *data)
1518{
Quinn Tran726b8542017-01-19 22:28:00 -08001519 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Alexei Potashnika6ca8872015-07-14 16:00:44 -04001520 qlt_logo_completion_handler(fcport, data[0]);
Quinn Tran726b8542017-01-19 22:28:00 -08001521 fcport->login_gen++;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001522 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001523}
1524
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001525void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001526qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1527 uint16_t *data)
1528{
1529 if (data[0] == MBS_COMMAND_COMPLETE) {
1530 qla2x00_update_fcport(vha, fcport);
1531
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001532 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001533 }
1534
1535 /* Retry login. */
1536 fcport->flags &= ~FCF_ASYNC_SENT;
1537 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
1538 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1539 else
Andrew Vasquez80d79442011-03-30 11:46:17 -07001540 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001541
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001542 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001543}
1544
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545/****************************************************************************/
1546/* QLogic ISP2x00 Hardware Support Functions. */
1547/****************************************************************************/
1548
Saurav Kashyapfa492632012-11-21 02:40:29 -05001549static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001550qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
1551{
1552 int rval = QLA_SUCCESS;
1553 struct qla_hw_data *ha = vha->hw;
1554 uint32_t idc_major_ver, idc_minor_ver;
Saurav Kashyap711aa7f2012-08-22 14:21:15 -04001555 uint16_t config[4];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001556
1557 qla83xx_idc_lock(vha, 0);
1558
1559 /* SV: TODO: Assign initialization timeout from
1560 * flash-info / other param
1561 */
1562 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
1563 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
1564
1565 /* Set our fcoe function presence */
1566 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
1567 ql_dbg(ql_dbg_p3p, vha, 0xb077,
1568 "Error while setting DRV-Presence.\n");
1569 rval = QLA_FUNCTION_FAILED;
1570 goto exit;
1571 }
1572
1573 /* Decide the reset ownership */
1574 qla83xx_reset_ownership(vha);
1575
1576 /*
1577 * On first protocol driver load:
1578 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
1579 * register.
1580 * Others: Check compatibility with current IDC Major version.
1581 */
1582 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
1583 if (ha->flags.nic_core_reset_owner) {
1584 /* Set IDC Major version */
1585 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
1586 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
1587
1588 /* Clearing IDC-Lock-Recovery register */
1589 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
1590 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
1591 /*
1592 * Clear further IDC participation if we are not compatible with
1593 * the current IDC Major Version.
1594 */
1595 ql_log(ql_log_warn, vha, 0xb07d,
1596 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
1597 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
1598 __qla83xx_clear_drv_presence(vha);
1599 rval = QLA_FUNCTION_FAILED;
1600 goto exit;
1601 }
1602 /* Each function sets its supported Minor version. */
1603 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
1604 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
1605 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
1606
Saurav Kashyap711aa7f2012-08-22 14:21:15 -04001607 if (ha->flags.nic_core_reset_owner) {
1608 memset(config, 0, sizeof(config));
1609 if (!qla81xx_get_port_config(vha, config))
1610 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
1611 QLA8XXX_DEV_READY);
1612 }
1613
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001614 rval = qla83xx_idc_state_handler(vha);
1615
1616exit:
1617 qla83xx_idc_unlock(vha, 0);
1618
1619 return rval;
1620}
1621
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622/*
1623* qla2x00_initialize_adapter
1624* Initialize board.
1625*
1626* Input:
1627* ha = adapter block pointer.
1628*
1629* Returns:
1630* 0 = success
1631*/
1632int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001633qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634{
1635 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001636 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001637 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001638
Joe Carnucciofc90ada2016-07-06 11:14:23 -04001639 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
1640 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
1641
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001643 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001644 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001645 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -08001646 ha->flags.pci_channel_io_perm_failure = 0;
1647 ha->flags.eeh_busy = 0;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -04001648 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001649 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1650 atomic_set(&vha->loop_state, LOOP_DOWN);
1651 vha->device_flags = DFLG_NO_CABLE;
1652 vha->dpc_flags = 0;
1653 vha->flags.management_server_logged_in = 0;
1654 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 ha->isp_abort_cnt = 0;
1656 ha->beacon_blink_led = 0;
1657
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001658 set_bit(0, ha->req_qid_map);
1659 set_bit(0, ha->rsp_qid_map);
1660
Chad Dupuiscfb09192011-11-18 09:03:07 -08001661 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001662 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001663 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001665 ql_log(ql_log_warn, vha, 0x0044,
1666 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 return (rval);
1668 }
1669
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001670 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001672 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001673 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001674 ql_log(ql_log_fatal, vha, 0x004f,
1675 "Unable to validate FLASH data.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001676 return rval;
1677 }
1678
1679 if (IS_QLA8044(ha)) {
1680 qla8044_read_reset_template(vha);
1681
1682 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
1683 * If DONRESET_BIT0 is set, drivers should not set dev_state
1684 * to NEED_RESET. But if NEED_RESET is set, drivers should
1685 * should honor the reset. */
1686 if (ql2xdontresethba == 1)
1687 qla8044_set_idc_dontreset(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001688 }
1689
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001690 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001691 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001692 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001693
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001694 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001696 if (ha->flags.disable_serdes) {
1697 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001698 ql_log(ql_log_info, vha, 0x0077,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001699 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001700 return QLA_FUNCTION_FAILED;
1701 }
1702
Chad Dupuiscfb09192011-11-18 09:03:07 -08001703 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001704 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001706 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
1707 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001708 if (rval)
1709 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001710 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001711 if (rval)
1712 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07001714
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001715 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001716 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001717 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001718 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001719 "Unable to configure ISP84XX.\n");
1720 return QLA_FUNCTION_FAILED;
1721 }
1722 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001723
Quinn Tranead03852017-01-19 22:28:01 -08001724 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001725 rval = qla2x00_init_rings(vha);
1726
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001727 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001729 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001730 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001731 rval = qla84xx_init_chip(vha);
1732 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001733 ql_log(ql_log_warn, vha, 0x00d4,
1734 "Unable to initialize ISP84XX.\n");
Bart Van Assche8d2b21d2015-06-04 15:58:09 -07001735 qla84xx_put_chip(vha);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001736 }
1737 }
1738
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001739 /* Load the NIC Core f/w if we are the first protocol driver. */
1740 if (IS_QLA8031(ha)) {
1741 rval = qla83xx_nic_core_fw_load(vha);
1742 if (rval)
1743 ql_log(ql_log_warn, vha, 0x0124,
1744 "Error in initializing NIC Core f/w.\n");
1745 }
1746
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +05001747 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
1748 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -07001749
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04001750 if (IS_P3P_TYPE(ha))
1751 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
1752 else
1753 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
1754
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 return (rval);
1756}
1757
1758/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001759 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 * @ha: HA context
1761 *
1762 * Returns 0 on success.
1763 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001764int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001765qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001767 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001768 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001769 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001770 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001773 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001776 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1778
Andrew Vasquez737faec2008-10-24 15:13:45 -07001779 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001781 /* Get PCI bus information. */
1782 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07001783 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001784 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1785
1786 return QLA_SUCCESS;
1787}
1788
1789/**
1790 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
1791 * @ha: HA context
1792 *
1793 * Returns 0 on success.
1794 */
1795int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001796qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001797{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001798 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001799 unsigned long flags = 0;
1800 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001801 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001802 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001803
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001804 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001805 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001806
1807 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001808 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001809
1810 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1811 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -07001812 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001813
1814 /*
1815 * If this is a 2300 card and not 2312, reset the
1816 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
1817 * the 2310 also reports itself as a 2300 so we need to get the
1818 * fb revision level -- a 6 indicates it really is a 2300 and
1819 * not a 2310.
1820 */
1821 if (IS_QLA2300(ha)) {
1822 spin_lock_irqsave(&ha->hardware_lock, flags);
1823
1824 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001825 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001826 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07001827 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001828 break;
1829
1830 udelay(10);
1831 }
1832
1833 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001834 WRT_REG_WORD(&reg->ctrl_status, 0x20);
1835 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001836
1837 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001838 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001839
1840 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -07001841 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001842
1843 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001844 WRT_REG_WORD(&reg->ctrl_status, 0x0);
1845 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001846
1847 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001848 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001849 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07001850 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001851 break;
1852
1853 udelay(10);
1854 }
1855
1856 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1857 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001858
1859 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
1860
Andrew Vasquez737faec2008-10-24 15:13:45 -07001861 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001862
1863 /* Get PCI bus information. */
1864 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07001865 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001866 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1867
1868 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869}
1870
1871/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001872 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
1873 * @ha: HA context
1874 *
1875 * Returns 0 on success.
1876 */
1877int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001878qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001879{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001880 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001881 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001882 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001883 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001884
1885 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001886 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001887
1888 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001889 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001890 w &= ~PCI_COMMAND_INTX_DISABLE;
1891 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1892
1893 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
1894
1895 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -07001896 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
1897 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001898
1899 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07001900 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04001901 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001902
Andrew Vasquez737faec2008-10-24 15:13:45 -07001903 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001904
Auke Kok44c10132007-06-08 15:46:36 -07001905 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001906
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001907 /* Get PCI bus information. */
1908 spin_lock_irqsave(&ha->hardware_lock, flags);
1909 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
1910 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1911
1912 return QLA_SUCCESS;
1913}
1914
1915/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001916 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
1917 * @ha: HA context
1918 *
1919 * Returns 0 on success.
1920 */
1921int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001922qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001923{
1924 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001925 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001926
1927 pci_set_master(ha->pdev);
1928 pci_try_set_mwi(ha->pdev);
1929
1930 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
1931 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
1932 w &= ~PCI_COMMAND_INTX_DISABLE;
1933 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1934
1935 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07001936 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04001937 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001938
Andrew Vasquez737faec2008-10-24 15:13:45 -07001939 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001940
1941 ha->chip_revision = ha->pdev->revision;
1942
1943 return QLA_SUCCESS;
1944}
1945
1946/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 * qla2x00_isp_firmware() - Choose firmware image.
1948 * @ha: HA context
1949 *
1950 * Returns 0 on success.
1951 */
1952static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001953qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954{
1955 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001956 uint16_t loop_id, topo, sw_cap;
1957 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001958 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959
1960 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001961 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962
1963 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001964 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965
1966 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001967 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001968 if (rval == QLA_SUCCESS) {
1969 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001970 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001971 &area, &domain, &topo, &sw_cap);
1972 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 }
1974
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001975 if (rval)
1976 ql_dbg(ql_dbg_init, vha, 0x007a,
1977 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
1979 return (rval);
1980}
1981
1982/**
1983 * qla2x00_reset_chip() - Reset ISP chip.
1984 * @ha: HA context
1985 *
1986 * Returns 0 on success.
1987 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001988void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001989qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990{
1991 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001992 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001993 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 uint16_t cmd;
1996
Andrew Vasquez85880802009-12-15 21:29:46 -08001997 if (unlikely(pci_channel_offline(ha->pdev)))
1998 return;
1999
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002000 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
2002 spin_lock_irqsave(&ha->hardware_lock, flags);
2003
2004 /* Turn off master enable */
2005 cmd = 0;
2006 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2007 cmd &= ~PCI_COMMAND_MASTER;
2008 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2009
2010 if (!IS_QLA2100(ha)) {
2011 /* Pause RISC. */
2012 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
2013 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2014 for (cnt = 0; cnt < 30000; cnt++) {
2015 if ((RD_REG_WORD(&reg->hccr) &
2016 HCCR_RISC_PAUSE) != 0)
2017 break;
2018 udelay(100);
2019 }
2020 } else {
2021 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2022 udelay(10);
2023 }
2024
2025 /* Select FPM registers. */
2026 WRT_REG_WORD(&reg->ctrl_status, 0x20);
2027 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2028
2029 /* FPM Soft Reset. */
2030 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
2031 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
2032
2033 /* Toggle Fpm Reset. */
2034 if (!IS_QLA2200(ha)) {
2035 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
2036 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
2037 }
2038
2039 /* Select frame buffer registers. */
2040 WRT_REG_WORD(&reg->ctrl_status, 0x10);
2041 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2042
2043 /* Reset frame buffer FIFOs. */
2044 if (IS_QLA2200(ha)) {
2045 WRT_FB_CMD_REG(ha, reg, 0xa000);
2046 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2047 } else {
2048 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2049
2050 /* Read back fb_cmd until zero or 3 seconds max */
2051 for (cnt = 0; cnt < 3000; cnt++) {
2052 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2053 break;
2054 udelay(100);
2055 }
2056 }
2057
2058 /* Select RISC module registers. */
2059 WRT_REG_WORD(&reg->ctrl_status, 0);
2060 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
2061
2062 /* Reset RISC processor. */
2063 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2064 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2065
2066 /* Release RISC processor. */
2067 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2068 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2069 }
2070
2071 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
2072 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
2073
2074 /* Reset ISP chip. */
2075 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
2076
2077 /* Wait for RISC to recover from reset. */
2078 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2079 /*
2080 * It is necessary to for a delay here since the card doesn't
2081 * respond to PCI reads during a reset. On some architectures
2082 * this will result in an MCA.
2083 */
2084 udelay(20);
2085 for (cnt = 30000; cnt; cnt--) {
2086 if ((RD_REG_WORD(&reg->ctrl_status) &
2087 CSR_ISP_SOFT_RESET) == 0)
2088 break;
2089 udelay(100);
2090 }
2091 } else
2092 udelay(10);
2093
2094 /* Reset RISC processor. */
2095 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2096
2097 WRT_REG_WORD(&reg->semaphore, 0);
2098
2099 /* Release RISC processor. */
2100 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2101 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2102
2103 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2104 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -07002105 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
2108 udelay(100);
2109 }
2110 } else
2111 udelay(100);
2112
2113 /* Turn on master enable */
2114 cmd |= PCI_COMMAND_MASTER;
2115 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2116
2117 /* Disable RISC pause on FPM parity error. */
2118 if (!IS_QLA2100(ha)) {
2119 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
2120 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2121 }
2122
2123 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2124}
2125
2126/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002127 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2128 *
2129 * Returns 0 on success.
2130 */
Saurav Kashyapfa492632012-11-21 02:40:29 -05002131static int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002132qla81xx_reset_mpi(scsi_qla_host_t *vha)
2133{
2134 uint16_t mb[4] = {0x1010, 0, 1, 0};
2135
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002136 if (!IS_QLA81XX(vha->hw))
2137 return QLA_SUCCESS;
2138
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002139 return qla81xx_write_mpi_register(vha, mb);
2140}
2141
2142/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002143 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002144 * @ha: HA context
2145 *
2146 * Returns 0 on success.
2147 */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002148static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002149qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002150{
2151 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002152 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002153 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Bart Van Assche52c82822015-07-09 07:23:26 -07002154 uint32_t cnt;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002155 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002156 static int abts_cnt; /* ISP abort retry counts */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002157 int rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002158
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002159 spin_lock_irqsave(&ha->hardware_lock, flags);
2160
2161 /* Reset RISC. */
2162 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2163 for (cnt = 0; cnt < 30000; cnt++) {
2164 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2165 break;
2166
2167 udelay(10);
2168 }
2169
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002170 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE))
2171 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2172
2173 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2174 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2175 RD_REG_DWORD(&reg->hccr),
2176 RD_REG_DWORD(&reg->ctrl_status),
2177 (RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE));
2178
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002179 WRT_REG_DWORD(&reg->ctrl_status,
2180 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002181 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002182
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002183 udelay(100);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002184
Andrew Vasquez88c26662005-07-08 17:59:26 -07002185 /* Wait for firmware to complete NVRAM accesses. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002186 RD_REG_WORD(&reg->mailbox0);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002187 for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
2188 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez88c26662005-07-08 17:59:26 -07002189 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002190 if (cnt)
2191 udelay(5);
2192 else
2193 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez88c26662005-07-08 17:59:26 -07002194 }
2195
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002196 if (rval == QLA_SUCCESS)
2197 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2198
2199 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2200 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2201 RD_REG_DWORD(&reg->hccr),
2202 RD_REG_DWORD(&reg->mailbox0));
2203
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002204 /* Wait for soft-reset to complete. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002205 RD_REG_DWORD(&reg->ctrl_status);
Quinn Tran200ffb12016-12-23 18:06:12 -08002206 for (cnt = 0; cnt < 60; cnt++) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002207 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002208 if ((RD_REG_DWORD(&reg->ctrl_status) &
2209 CSRX_ISP_SOFT_RESET) == 0)
2210 break;
2211
2212 udelay(5);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002213 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002214 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_ISP_SOFT_RESET))
2215 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2216
2217 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2218 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2219 RD_REG_DWORD(&reg->hccr),
2220 RD_REG_DWORD(&reg->ctrl_status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002221
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002222 /* If required, do an MPI FW reset now */
2223 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2224 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2225 if (++abts_cnt < 5) {
2226 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2227 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2228 } else {
2229 /*
2230 * We exhausted the ISP abort retries. We have to
2231 * set the board offline.
2232 */
2233 abts_cnt = 0;
2234 vha->flags.online = 0;
2235 }
2236 }
2237 }
2238
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002239 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
2240 RD_REG_DWORD(&reg->hccr);
2241
2242 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
2243 RD_REG_DWORD(&reg->hccr);
2244
2245 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
2246 RD_REG_DWORD(&reg->hccr);
2247
Bart Van Assche52c82822015-07-09 07:23:26 -07002248 RD_REG_WORD(&reg->mailbox0);
Quinn Tran200ffb12016-12-23 18:06:12 -08002249 for (cnt = 60; RD_REG_WORD(&reg->mailbox0) != 0 &&
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002250 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002251 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002252 if (cnt)
2253 udelay(5);
2254 else
2255 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002256 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002257 if (rval == QLA_SUCCESS)
2258 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2259
2260 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2261 "Host Risc 0x%x, mailbox0 0x%x\n",
2262 RD_REG_DWORD(&reg->hccr),
2263 RD_REG_WORD(&reg->mailbox0));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002264
2265 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002266
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002267 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2268 "Driver in %s mode\n",
2269 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2270
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002271 if (IS_NOPOLLING_TYPE(ha))
2272 ha->isp_ops->enable_intrs(ha);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002273
2274 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002275}
2276
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002277static void
2278qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2279{
2280 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2281
2282 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2283 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2284
2285}
2286
2287static void
2288qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2289{
2290 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2291
2292 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2293 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2294}
2295
2296static void
2297qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2298{
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002299 uint32_t wd32 = 0;
2300 uint delta_msec = 100;
2301 uint elapsed_msec = 0;
2302 uint timeout_msec;
2303 ulong n;
2304
Joe Carnucciocc790762015-08-04 13:37:53 -04002305 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2306 vha->hw->pdev->subsystem_device != 0x0240)
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002307 return;
2308
Joe Carnuccio8dd7e3a2015-08-04 13:37:54 -04002309 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2310 udelay(100);
2311
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002312attempt:
2313 timeout_msec = TIMEOUT_SEMAPHORE;
2314 n = timeout_msec / delta_msec;
2315 while (n--) {
2316 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2317 qla25xx_read_risc_sema_reg(vha, &wd32);
2318 if (wd32 & RISC_SEMAPHORE)
2319 break;
2320 msleep(delta_msec);
2321 elapsed_msec += delta_msec;
2322 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2323 goto force;
2324 }
2325
2326 if (!(wd32 & RISC_SEMAPHORE))
2327 goto force;
2328
2329 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2330 goto acquired;
2331
2332 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2333 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2334 n = timeout_msec / delta_msec;
2335 while (n--) {
2336 qla25xx_read_risc_sema_reg(vha, &wd32);
2337 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2338 break;
2339 msleep(delta_msec);
2340 elapsed_msec += delta_msec;
2341 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2342 goto force;
2343 }
2344
2345 if (wd32 & RISC_SEMAPHORE_FORCE)
2346 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2347
2348 goto attempt;
2349
2350force:
2351 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2352
2353acquired:
2354 return;
2355}
2356
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002357/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002358 * qla24xx_reset_chip() - Reset ISP24xx chip.
2359 * @ha: HA context
2360 *
2361 * Returns 0 on success.
2362 */
2363void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002364qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07002365{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002366 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08002367
2368 if (pci_channel_offline(ha->pdev) &&
2369 ha->flags.pci_channel_io_perm_failure) {
2370 return;
2371 }
2372
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002373 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002374
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002375 qla25xx_manipulate_risc_semaphore(vha);
2376
Andrew Vasquez88c26662005-07-08 17:59:26 -07002377 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002378 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002379}
2380
2381/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 * qla2x00_chip_diag() - Test chip for proper operation.
2383 * @ha: HA context
2384 *
2385 * Returns 0 on success.
2386 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002387int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002388qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389{
2390 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002391 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002392 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 unsigned long flags = 0;
2394 uint16_t data;
2395 uint32_t cnt;
2396 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002397 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398
2399 /* Assume a failed state */
2400 rval = QLA_FUNCTION_FAILED;
2401
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002402 ql_dbg(ql_dbg_init, vha, 0x007b,
2403 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404
2405 spin_lock_irqsave(&ha->hardware_lock, flags);
2406
2407 /* Reset ISP chip. */
2408 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
2409
2410 /*
2411 * We need to have a delay here since the card will not respond while
2412 * in reset causing an MCA on some architectures.
2413 */
2414 udelay(20);
2415 data = qla2x00_debounce_register(&reg->ctrl_status);
2416 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2417 udelay(5);
2418 data = RD_REG_WORD(&reg->ctrl_status);
2419 barrier();
2420 }
2421
2422 if (!cnt)
2423 goto chip_diag_failed;
2424
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002425 ql_dbg(ql_dbg_init, vha, 0x007c,
2426 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
2428 /* Reset RISC processor. */
2429 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2430 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2431
2432 /* Workaround for QLA2312 PCI parity error */
2433 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2434 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2435 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2436 udelay(5);
2437 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002438 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 }
2440 } else
2441 udelay(10);
2442
2443 if (!cnt)
2444 goto chip_diag_failed;
2445
2446 /* Check product ID of chip */
Milan P Gandhi5a68a1c2017-03-31 14:37:04 -07002447 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448
2449 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
2450 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
2451 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
2452 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
2453 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
2454 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002455 ql_log(ql_log_warn, vha, 0x0062,
2456 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2457 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458
2459 goto chip_diag_failed;
2460 }
2461 ha->product_id[0] = mb[1];
2462 ha->product_id[1] = mb[2];
2463 ha->product_id[2] = mb[3];
2464 ha->product_id[3] = mb[4];
2465
2466 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002467 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
2469 else
2470 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002471 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472
2473 if (IS_QLA2200(ha) &&
2474 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
2475 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002476 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002478 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 ha->fw_transfer_size = 128;
2480 }
2481
2482 /* Wrap Incoming Mailboxes Test. */
2483 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2484
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002485 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002486 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002487 if (rval)
2488 ql_log(ql_log_warn, vha, 0x0080,
2489 "Failed mailbox send register test.\n");
2490 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 /* Flag a successful rval */
2492 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 spin_lock_irqsave(&ha->hardware_lock, flags);
2494
2495chip_diag_failed:
2496 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002497 ql_log(ql_log_info, vha, 0x0081,
2498 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499
2500 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2501
2502 return (rval);
2503}
2504
2505/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002506 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2507 * @ha: HA context
2508 *
2509 * Returns 0 on success.
2510 */
2511int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002512qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002513{
2514 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002515 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002516 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002517
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002518 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07002519 return QLA_SUCCESS;
2520
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002521 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002522
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002523 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002524 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002525 ql_log(ql_log_warn, vha, 0x0082,
2526 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002527 } else {
2528 /* Flag a successful rval */
2529 rval = QLA_SUCCESS;
2530 }
2531
2532 return rval;
2533}
2534
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002535void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002536qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002537{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002538 int rval;
2539 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002540 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002541 dma_addr_t tc_dma;
2542 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002543 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002544 struct req_que *req = ha->req_q_map[0];
2545 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002546
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002547 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002548 ql_dbg(ql_dbg_init, vha, 0x00bd,
2549 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002550 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002551 }
2552
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002553 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04002554 ha->fw_dump_cap_flags = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002555 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
2556 req_q_size = rsp_q_size = 0;
2557
2558 if (IS_QLA27XX(ha))
2559 goto try_fce;
2560
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002561 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2562 fixed_size = sizeof(struct qla2100_fw_dump);
2563 } else if (IS_QLA23XX(ha)) {
2564 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
2565 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
2566 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07002567 } else if (IS_FWI2_CAPABLE(ha)) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002568 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002569 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
2570 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002571 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
2572 else if (IS_QLA25XX(ha))
2573 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
2574 else
2575 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002576
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002577 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
2578 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002579 if (ha->mqenable) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002580 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002581 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002582 /*
2583 * Allocate maximum buffer size for all queues.
2584 * Resizing must be done at end-of-dump processing.
2585 */
2586 mq_size += ha->max_req_queues *
2587 (req->length * sizeof(request_t));
2588 mq_size += ha->max_rsp_queues *
2589 (rsp->length * sizeof(response_t));
2590 }
Arun Easi00876ae2013-03-25 02:21:37 -04002591 if (ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002592 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002593 /* Allocate memory for Fibre Channel Event Buffer. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05002594 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2595 !IS_QLA27XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002596 goto try_eft;
2597
Chad Dupuisf73cb692014-02-26 04:15:06 -05002598try_fce:
2599 if (ha->fce)
2600 dma_free_coherent(&ha->pdev->dev,
2601 FCE_SIZE, ha->fce, ha->fce_dma);
2602
2603 /* Allocate memory for Fibre Channel Event Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07002604 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
2605 GFP_KERNEL);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002606 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002607 ql_log(ql_log_warn, vha, 0x00be,
2608 "Unable to allocate (%d KB) for FCE.\n",
2609 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002610 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002611 }
2612
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002613 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002614 ha->fce_mb, &ha->fce_bufs);
2615 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002616 ql_log(ql_log_warn, vha, 0x00bf,
2617 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002618 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
2619 tc_dma);
2620 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002621 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002622 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002623 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002624 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002625
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07002626 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002627 ha->flags.fce_enabled = 1;
2628 ha->fce_dma = tc_dma;
2629 ha->fce = tc;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002630
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002631try_eft:
Chad Dupuisf73cb692014-02-26 04:15:06 -05002632 if (ha->eft)
2633 dma_free_coherent(&ha->pdev->dev,
2634 EFT_SIZE, ha->eft, ha->eft_dma);
2635
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002636 /* Allocate memory for Extended Trace Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07002637 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
2638 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002639 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002640 ql_log(ql_log_warn, vha, 0x00c1,
2641 "Unable to allocate (%d KB) for EFT.\n",
2642 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002643 goto cont_alloc;
2644 }
2645
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002646 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002647 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002648 ql_log(ql_log_warn, vha, 0x00c2,
2649 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002650 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
2651 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002652 goto cont_alloc;
2653 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002654 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002655 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002656
2657 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002658 ha->eft_dma = tc_dma;
2659 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002660 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05002661
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002662cont_alloc:
Chad Dupuisf73cb692014-02-26 04:15:06 -05002663 if (IS_QLA27XX(ha)) {
2664 if (!ha->fw_dump_template) {
2665 ql_log(ql_log_warn, vha, 0x00ba,
2666 "Failed missing fwdump template\n");
2667 return;
2668 }
2669 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
2670 ql_dbg(ql_dbg_init, vha, 0x00fa,
2671 "-> allocating fwdump (%x bytes)...\n", dump_size);
2672 goto allocate;
2673 }
2674
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002675 req_q_size = req->length * sizeof(request_t);
2676 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002677 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002678 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08002679 ha->chain_offset = dump_size;
2680 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002681
Quinn Tranb945e772017-06-13 20:47:29 -07002682 if (ha->exchoffld_buf)
2683 dump_size += sizeof(struct qla2xxx_offld_chain) +
2684 ha->exchoffld_size;
2685 if (ha->exlogin_buf)
2686 dump_size += sizeof(struct qla2xxx_offld_chain) +
2687 ha->exlogin_size;
2688
Chad Dupuisf73cb692014-02-26 04:15:06 -05002689allocate:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002690 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002691 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002692 ql_log(ql_log_warn, vha, 0x00c4,
2693 "Unable to allocate (%d KB) for firmware dump.\n",
2694 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002695
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002696 if (ha->fce) {
2697 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2698 ha->fce_dma);
2699 ha->fce = NULL;
2700 ha->fce_dma = 0;
2701 }
2702
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002703 if (ha->eft) {
2704 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
2705 ha->eft_dma);
2706 ha->eft = NULL;
2707 ha->eft_dma = 0;
2708 }
2709 return;
2710 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05002711 ha->fw_dump_len = dump_size;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002712 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002713 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002714
Chad Dupuisf73cb692014-02-26 04:15:06 -05002715 if (IS_QLA27XX(ha))
2716 return;
2717
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002718 ha->fw_dump->signature[0] = 'Q';
2719 ha->fw_dump->signature[1] = 'L';
2720 ha->fw_dump->signature[2] = 'G';
2721 ha->fw_dump->signature[3] = 'C';
Bart Van Asschead950362015-07-09 07:24:08 -07002722 ha->fw_dump->version = htonl(1);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002723
2724 ha->fw_dump->fixed_size = htonl(fixed_size);
2725 ha->fw_dump->mem_size = htonl(mem_size);
2726 ha->fw_dump->req_q_size = htonl(req_q_size);
2727 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
2728
2729 ha->fw_dump->eft_size = htonl(eft_size);
2730 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
2731 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
2732
2733 ha->fw_dump->header_size =
2734 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002735}
2736
Andrew Vasquez18e75552009-06-03 09:55:30 -07002737static int
2738qla81xx_mpi_sync(scsi_qla_host_t *vha)
2739{
2740#define MPS_MASK 0xe0
2741 int rval;
2742 uint16_t dc;
2743 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07002744
2745 if (!IS_QLA81XX(vha->hw))
2746 return QLA_SUCCESS;
2747
2748 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
2749 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002750 ql_log(ql_log_warn, vha, 0x0105,
2751 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002752 goto done;
2753 }
2754
2755 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
2756 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
2757 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002758 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002759 goto done_release;
2760 }
2761
2762 dc &= MPS_MASK;
2763 if (dc == (dw & MPS_MASK))
2764 goto done_release;
2765
2766 dw &= ~MPS_MASK;
2767 dw |= dc;
2768 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
2769 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002770 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002771 }
2772
2773done_release:
2774 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
2775 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002776 ql_log(ql_log_warn, vha, 0x006d,
2777 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002778 }
2779
2780done:
2781 return rval;
2782}
2783
Chad Dupuis8d93f552013-01-30 03:34:37 -05002784int
2785qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
2786{
2787 /* Don't try to reallocate the array */
2788 if (req->outstanding_cmds)
2789 return QLA_SUCCESS;
2790
Michael Hernandezd7459522016-12-12 14:40:07 -08002791 if (!IS_FWI2_CAPABLE(ha))
Chad Dupuis8d93f552013-01-30 03:34:37 -05002792 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
2793 else {
Quinn Tran03e8c682015-12-17 14:56:59 -05002794 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
2795 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002796 else
Quinn Tran03e8c682015-12-17 14:56:59 -05002797 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002798 }
2799
2800 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
2801 req->num_outstanding_cmds, GFP_KERNEL);
2802
2803 if (!req->outstanding_cmds) {
2804 /*
2805 * Try to allocate a minimal size just so we can get through
2806 * initialization.
2807 */
2808 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
2809 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
2810 req->num_outstanding_cmds, GFP_KERNEL);
2811
2812 if (!req->outstanding_cmds) {
2813 ql_log(ql_log_fatal, NULL, 0x0126,
2814 "Failed to allocate memory for "
2815 "outstanding_cmds for req_que %p.\n", req);
2816 req->num_outstanding_cmds = 0;
2817 return QLA_FUNCTION_FAILED;
2818 }
2819 }
2820
2821 return QLA_SUCCESS;
2822}
2823
Quinn Trane4e3a2c2017-08-23 15:05:07 -07002824#define PRINT_FIELD(_field, _flag, _str) { \
2825 if (a0->_field & _flag) {\
2826 if (p) {\
2827 strcat(ptr, "|");\
2828 ptr++;\
2829 leftover--;\
2830 } \
2831 len = snprintf(ptr, leftover, "%s", _str); \
2832 p = 1;\
2833 leftover -= len;\
2834 ptr += len; \
2835 } \
2836}
2837
2838static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
2839{
2840#define STR_LEN 64
2841 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
2842 u8 str[STR_LEN], *ptr, p;
2843 int leftover, len;
2844
2845 memset(str, 0, STR_LEN);
2846 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
2847 ql_dbg(ql_dbg_init, vha, 0x015a,
2848 "SFP MFG Name: %s\n", str);
2849
2850 memset(str, 0, STR_LEN);
2851 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
2852 ql_dbg(ql_dbg_init, vha, 0x015c,
2853 "SFP Part Name: %s\n", str);
2854
2855 /* media */
2856 memset(str, 0, STR_LEN);
2857 ptr = str;
2858 leftover = STR_LEN;
2859 p = len = 0;
2860 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
2861 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
2862 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
2863 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
2864 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
2865 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
2866 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
2867 ql_dbg(ql_dbg_init, vha, 0x0160,
2868 "SFP Media: %s\n", str);
2869
2870 /* link length */
2871 memset(str, 0, STR_LEN);
2872 ptr = str;
2873 leftover = STR_LEN;
2874 p = len = 0;
2875 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
2876 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
2877 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
2878 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
2879 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
2880 ql_dbg(ql_dbg_init, vha, 0x0196,
2881 "SFP Link Length: %s\n", str);
2882
2883 memset(str, 0, STR_LEN);
2884 ptr = str;
2885 leftover = STR_LEN;
2886 p = len = 0;
2887 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
2888 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
2889 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
2890 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
2891 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
2892 ql_dbg(ql_dbg_init, vha, 0x016e,
2893 "SFP FC Link Tech: %s\n", str);
2894
2895 if (a0->length_km)
2896 ql_dbg(ql_dbg_init, vha, 0x016f,
2897 "SFP Distant: %d km\n", a0->length_km);
2898 if (a0->length_100m)
2899 ql_dbg(ql_dbg_init, vha, 0x0170,
2900 "SFP Distant: %d m\n", a0->length_100m*100);
2901 if (a0->length_50um_10m)
2902 ql_dbg(ql_dbg_init, vha, 0x0189,
2903 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
2904 if (a0->length_62um_10m)
2905 ql_dbg(ql_dbg_init, vha, 0x018a,
2906 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
2907 if (a0->length_om4_10m)
2908 ql_dbg(ql_dbg_init, vha, 0x0194,
2909 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
2910 if (a0->length_om3_10m)
2911 ql_dbg(ql_dbg_init, vha, 0x0195,
2912 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
2913}
2914
2915
2916/*
2917 * Return Code:
2918 * QLA_SUCCESS: no action
2919 * QLA_INTERFACE_ERROR: SFP is not there.
2920 * QLA_FUNCTION_FAILED: detected New SFP
2921 */
2922int
2923qla24xx_detect_sfp(scsi_qla_host_t *vha)
2924{
2925 int rc = QLA_SUCCESS;
2926 struct sff_8247_a0 *a;
2927 struct qla_hw_data *ha = vha->hw;
2928
2929 if (!AUTO_DETECT_SFP_SUPPORT(vha))
2930 goto out;
2931
2932 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
2933 if (rc)
2934 goto out;
2935
2936 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
2937 qla2xxx_print_sfp_info(vha);
2938
2939 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
2940 /* long range */
2941 ha->flags.detected_lr_sfp = 1;
2942
2943 if (a->length_km > 5 || a->length_100m > 50)
2944 ha->long_range_distance = LR_DISTANCE_10K;
2945 else
2946 ha->long_range_distance = LR_DISTANCE_5K;
2947
2948 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
2949 ql_dbg(ql_dbg_async, vha, 0x507b,
2950 "Detected Long Range SFP.\n");
2951 } else {
2952 /* short range */
2953 ha->flags.detected_lr_sfp = 0;
2954 if (ha->flags.using_lr_setting)
2955 ql_dbg(ql_dbg_async, vha, 0x5084,
2956 "Detected Short Range SFP.\n");
2957 }
2958
2959 if (!vha->flags.init_done)
2960 rc = QLA_SUCCESS;
2961out:
2962 return rc;
2963}
2964
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002965/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 * qla2x00_setup_chip() - Load and start RISC firmware.
2967 * @ha: HA context
2968 *
2969 * Returns 0 on success.
2970 */
2971static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002972qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002974 int rval;
2975 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002976 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08002977 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2978 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07002979 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08002980
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002981 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002982 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05002983 if (rval == QLA_SUCCESS) {
2984 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002985 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05002986 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07002987 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002988 }
2989
Andrew Vasquez3db06522008-01-31 12:33:49 -08002990 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
2991 /* Disable SRAM, Instruction RAM and GP RAM parity. */
2992 spin_lock_irqsave(&ha->hardware_lock, flags);
2993 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
2994 RD_REG_WORD(&reg->hccr);
2995 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2996 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997
Andrew Vasquez18e75552009-06-03 09:55:30 -07002998 qla81xx_mpi_sync(vha);
2999
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003001 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003002 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003003 ql_dbg(ql_dbg_init, vha, 0x00c9,
3004 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003006 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 if (rval == QLA_SUCCESS) {
3008 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003009 ql_dbg(ql_dbg_init, vha, 0x00ca,
3010 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003012 if (ql2xexlogins)
3013 ha->flags.exlogins_enabled = 1;
3014
Quinn Tran99e1b682017-06-02 09:12:03 -07003015 if (qla_is_exch_offld_enabled(vha))
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003016 ha->flags.exchoffld_enabled = 1;
3017
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003018 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07003020 if (rval == QLA_SUCCESS) {
Quinn Trane4e3a2c2017-08-23 15:05:07 -07003021 qla24xx_detect_sfp(vha);
3022
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05003023 rval = qla2x00_set_exlogins_buffer(vha);
3024 if (rval != QLA_SUCCESS)
3025 goto failed;
3026
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05003027 rval = qla2x00_set_exchoffld_buffer(vha);
3028 if (rval != QLA_SUCCESS)
3029 goto failed;
3030
Giridhar Malavalia9083012010-04-12 17:59:55 -07003031enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07003032 fw_major_version = ha->fw_major_version;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003033 if (IS_P3P_TYPE(ha))
Giridhar Malavali31731672011-08-16 11:31:54 -07003034 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003035 else
3036 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07003037 if (rval != QLA_SUCCESS)
3038 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003039 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003040 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07003041 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003042 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003043 if ((!ha->max_npiv_vports) ||
3044 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003045 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003046 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003047 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07003048 }
Quinn Tran03e8c682015-12-17 14:56:59 -05003049 qla2x00_get_resource_cnts(vha);
Andrew Vasquezd743de62009-03-24 09:08:15 -07003050
Chad Dupuis8d93f552013-01-30 03:34:37 -05003051 /*
3052 * Allocate the array of outstanding commands
3053 * now that we know the firmware resources.
3054 */
3055 rval = qla2x00_alloc_outstanding_cmds(ha,
3056 vha->req);
3057 if (rval != QLA_SUCCESS)
3058 goto failed;
3059
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08003060 if (!fw_major_version && ql2xallocfwdump
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003061 && !(IS_P3P_TYPE(ha)))
Giridhar Malavali08de2842011-08-16 11:31:44 -07003062 qla2x00_alloc_fw_dump(vha);
Chad Dupuis3b6e5b92013-10-30 03:38:09 -04003063 } else {
3064 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 }
3066 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003067 ql_log(ql_log_fatal, vha, 0x00cd,
3068 "ISP Firmware failed checksum.\n");
3069 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04003071 } else
3072 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073
Andrew Vasquez3db06522008-01-31 12:33:49 -08003074 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3075 /* Enable proper parity. */
3076 spin_lock_irqsave(&ha->hardware_lock, flags);
3077 if (IS_QLA2300(ha))
3078 /* SRAM parity */
3079 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
3080 else
3081 /* SRAM, Instruction RAM and GP RAM parity */
3082 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
3083 RD_REG_WORD(&reg->hccr);
3084 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3085 }
3086
Chad Dupuisf3982d82014-09-25 05:16:57 -04003087 if (IS_QLA27XX(ha))
3088 ha->flags.fac_supported = 1;
3089 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003090 uint32_t size;
3091
3092 rval = qla81xx_fac_get_sector_size(vha, &size);
3093 if (rval == QLA_SUCCESS) {
3094 ha->flags.fac_supported = 1;
3095 ha->fdt_block_size = size << 2;
3096 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003097 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003098 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3099 ha->fw_major_version, ha->fw_minor_version,
3100 ha->fw_subminor_version);
Joe Carnuccio1ca60e32014-02-26 04:15:02 -05003101
Chad Dupuisf73cb692014-02-26 04:15:06 -05003102 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003103 ha->flags.fac_supported = 0;
3104 rval = QLA_SUCCESS;
3105 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003106 }
3107 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07003108failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003110 ql_log(ql_log_fatal, vha, 0x00cf,
3111 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 }
3113
3114 return (rval);
3115}
3116
3117/**
3118 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3119 * @ha: HA context
3120 *
3121 * Beginning of request ring has initialization control block already built
3122 * by nvram config routine.
3123 *
3124 * Returns 0 on success.
3125 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003126void
3127qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128{
3129 uint16_t cnt;
3130 response_t *pkt;
3131
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003132 rsp->ring_ptr = rsp->ring;
3133 rsp->ring_index = 0;
3134 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003135 pkt = rsp->ring_ptr;
3136 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 pkt->signature = RESPONSE_PROCESSED;
3138 pkt++;
3139 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140}
3141
3142/**
3143 * qla2x00_update_fw_options() - Read and process firmware options.
3144 * @ha: HA context
3145 *
3146 * Returns 0 on success.
3147 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003148void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003149qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150{
3151 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003152 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153
3154 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003155 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156
3157 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3158 return;
3159
3160 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003161 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3162 "Serial link options.\n");
3163 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3164 (uint8_t *)&ha->fw_seriallink_options,
3165 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166
3167 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3168 if (ha->fw_seriallink_options[3] & BIT_2) {
3169 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3170
3171 /* 1G settings */
3172 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3173 emphasis = (ha->fw_seriallink_options[2] &
3174 (BIT_4 | BIT_3)) >> 3;
3175 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003176 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 rx_sens = (ha->fw_seriallink_options[0] &
3178 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3179 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3180 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3181 if (rx_sens == 0x0)
3182 rx_sens = 0x3;
3183 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3184 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3185 ha->fw_options[10] |= BIT_5 |
3186 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3187 (tx_sens & (BIT_1 | BIT_0));
3188
3189 /* 2G settings */
3190 swing = (ha->fw_seriallink_options[2] &
3191 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3192 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3193 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003194 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 rx_sens = (ha->fw_seriallink_options[1] &
3196 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3197 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3198 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3199 if (rx_sens == 0x0)
3200 rx_sens = 0x3;
3201 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3202 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3203 ha->fw_options[11] |= BIT_5 |
3204 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3205 (tx_sens & (BIT_1 | BIT_0));
3206 }
3207
3208 /* FCP2 options. */
3209 /* Return command IOCBs without waiting for an ABTS to complete. */
3210 ha->fw_options[3] |= BIT_13;
3211
3212 /* LED scheme. */
3213 if (ha->flags.enable_led_scheme)
3214 ha->fw_options[2] |= BIT_12;
3215
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003216 /* Detect ISP6312. */
3217 if (IS_QLA6312(ha))
3218 ha->fw_options[2] |= BIT_13;
3219
Giridhar Malavali088d09d2016-07-06 11:14:20 -04003220 /* Set Retry FLOGI in case of P2P connection */
3221 if (ha->operating_mode == P2P) {
3222 ha->fw_options[2] |= BIT_3;
3223 ql_dbg(ql_dbg_disc, vha, 0x2100,
3224 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3225 __func__, ha->fw_options[2]);
3226 }
3227
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003229 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230}
3231
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003232void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003233qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003234{
3235 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003236 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003237
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04003238 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07003239 return;
3240
Himanshu Madhanif198caf2016-01-27 12:03:30 -05003241 /* Hold status IOCBs until ABTS response received. */
3242 if (ql2xfwholdabts)
3243 ha->fw_options[3] |= BIT_12;
3244
Giridhar Malavali088d09d2016-07-06 11:14:20 -04003245 /* Set Retry FLOGI in case of P2P connection */
3246 if (ha->operating_mode == P2P) {
3247 ha->fw_options[2] |= BIT_3;
3248 ql_dbg(ql_dbg_disc, vha, 0x2101,
3249 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3250 __func__, ha->fw_options[2]);
3251 }
3252
Quinn Tran41dc5292017-01-19 22:28:03 -08003253 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
Quinn Tran3c4810f2017-06-02 09:11:53 -07003254 if (ql2xmvasynctoatio &&
3255 (IS_QLA83XX(ha) || IS_QLA27XX(ha))) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003256 if (qla_tgt_mode_enabled(vha) ||
3257 qla_dual_mode_enabled(vha))
3258 ha->fw_options[2] |= BIT_11;
3259 else
3260 ha->fw_options[2] &= ~BIT_11;
3261 }
3262
Quinn Tranf7e761f2017-06-02 09:12:02 -07003263 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3264 /*
3265 * Tell FW to track each exchange to prevent
3266 * driver from using stale exchange.
3267 */
3268 if (qla_tgt_mode_enabled(vha) ||
3269 qla_dual_mode_enabled(vha))
3270 ha->fw_options[2] |= BIT_4;
3271 else
3272 ha->fw_options[2] &= ~BIT_4;
3273 }
3274
Quinn Tran83548fe2017-06-02 09:12:01 -07003275 ql_dbg(ql_dbg_init, vha, 0x00e8,
3276 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3277 __func__, ha->fw_options[1], ha->fw_options[2],
3278 ha->fw_options[3], vha->host->active_mode);
Quinn Tran3c4810f2017-06-02 09:11:53 -07003279
3280 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3281 qla2x00_set_fw_options(vha, ha->fw_options);
Quinn Tran41dc5292017-01-19 22:28:03 -08003282
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003283 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08003284 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003285 return;
3286
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003287 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08003288 le16_to_cpu(ha->fw_seriallink_options24[1]),
3289 le16_to_cpu(ha->fw_seriallink_options24[2]),
3290 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003291 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003292 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003293 "Unable to update Serial Link options (%x).\n", rval);
3294 }
3295}
3296
3297void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003298qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003299{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003300 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003301 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003302 struct req_que *req = ha->req_q_map[0];
3303 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003304
3305 /* Setup ring parameters in initialization control block. */
Bart Van Asschead950362015-07-09 07:24:08 -07003306 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3307 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003308 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3309 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3310 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3311 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3312 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3313 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003314
3315 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3316 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3317 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3318 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3319 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3320}
3321
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003322void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003323qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003324{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003325 struct qla_hw_data *ha = vha->hw;
Bart Van Assche118e2ef2015-07-09 07:24:27 -07003326 device_reg_t *reg = ISP_QUE_REG(ha, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003327 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3328 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003329 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003330 uint16_t rid = 0;
3331 struct req_que *req = ha->req_q_map[0];
3332 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003333
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003334 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003335 icb = (struct init_cb_24xx *)ha->init_cb;
Bart Van Asschead950362015-07-09 07:24:08 -07003336 icb->request_q_outpointer = cpu_to_le16(0);
3337 icb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003338 icb->request_q_length = cpu_to_le16(req->length);
3339 icb->response_q_length = cpu_to_le16(rsp->length);
3340 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3341 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3342 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3343 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003344
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003345 /* Setup ATIO queue dma pointers for target mode */
Bart Van Asschead950362015-07-09 07:24:08 -07003346 icb->atio_q_inpointer = cpu_to_le16(0);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003347 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3348 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
3349 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
3350
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003351 if (IS_SHADOW_REG_CAPABLE(ha))
Bart Van Asschead950362015-07-09 07:24:08 -07003352 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003353
Chad Dupuisf73cb692014-02-26 04:15:06 -05003354 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003355 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3356 icb->rid = cpu_to_le16(rid);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003357 if (ha->flags.msix_enabled) {
3358 msix = &ha->msix_entries[1];
Quinn Tran83548fe2017-06-02 09:12:01 -07003359 ql_dbg(ql_dbg_init, vha, 0x0019,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003360 "Registering vector 0x%x for base que.\n",
3361 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003362 icb->msix = cpu_to_le16(msix->entry);
3363 }
3364 /* Use alternate PCI bus number */
3365 if (MSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003366 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003367 /* Use alternate PCI devfn */
3368 if (LSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003369 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003370
Anirban Chakraborty31557542009-12-02 10:36:55 -08003371 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003372 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
3373 (ha->flags.msix_enabled)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003374 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003375 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003376 ql_dbg(ql_dbg_init, vha, 0x00fe,
3377 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08003378 } else {
Bart Van Asschead950362015-07-09 07:24:08 -07003379 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003380 }
Bart Van Asschead950362015-07-09 07:24:08 -07003381 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003382
3383 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
3384 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
3385 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
3386 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
3387 } else {
3388 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
3389 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
3390 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
3391 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
3392 }
Arun Easiaa230bc2013-01-30 03:34:39 -05003393 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003394
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003395 /* PCI posting */
3396 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003397}
3398
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399/**
3400 * qla2x00_init_rings() - Initializes firmware.
3401 * @ha: HA context
3402 *
3403 * Beginning of request ring has initialization control block already built
3404 * by nvram config routine.
3405 *
3406 * Returns 0 on success.
3407 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003408int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003409qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410{
3411 int rval;
3412 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003413 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003414 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003415 struct req_que *req;
3416 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003417 struct mid_init_cb_24xx *mid_init_cb =
3418 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419
3420 spin_lock_irqsave(&ha->hardware_lock, flags);
3421
3422 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003423 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003424 req = ha->req_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003425 if (!req || !test_bit(que, ha->req_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003426 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003427 req->out_ptr = (void *)(req->ring + req->length);
3428 *req->out_ptr = 0;
Chad Dupuis8d93f552013-01-30 03:34:37 -05003429 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003430 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003432 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003433
3434 /* Initialize firmware. */
3435 req->ring_ptr = req->ring;
3436 req->ring_index = 0;
3437 req->cnt = req->length;
3438 }
3439
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003440 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003441 rsp = ha->rsp_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003442 if (!rsp || !test_bit(que, ha->rsp_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003443 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003444 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
3445 *rsp->in_ptr = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003446 /* Initialize response queue entries */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003447 if (IS_QLAFX00(ha))
3448 qlafx00_init_response_q_entries(rsp);
3449 else
3450 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003451 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003453 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
3454 ha->tgt.atio_ring_index = 0;
3455 /* Initialize ATIO queue entries */
3456 qlt_init_atio_q_entries(vha);
3457
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003458 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459
3460 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3461
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003462 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
3463
3464 if (IS_QLAFX00(ha)) {
3465 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
3466 goto next_check;
3467 }
3468
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003470 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003472 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04003473 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003474 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08003475 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003476 }
3477
Andrew Vasquez24a08132009-03-24 09:08:16 -07003478 if (IS_FWI2_CAPABLE(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003479 mid_init_cb->options = cpu_to_le16(BIT_1);
Andrew Vasquez24a08132009-03-24 09:08:16 -07003480 mid_init_cb->init_cb.execution_throttle =
Quinn Tran03e8c682015-12-17 14:56:59 -05003481 cpu_to_le16(ha->cur_fw_xcb_count);
Joe Carnuccio40f38622016-07-06 11:14:28 -04003482 ha->flags.dport_enabled =
3483 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
3484 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
3485 (ha->flags.dport_enabled) ? "enabled" : "disabled");
3486 /* FA-WWPN Status */
Himanshu Madhani2486c622014-09-25 05:17:00 -04003487 ha->flags.fawwpn_enabled =
Joe Carnuccio40f38622016-07-06 11:14:28 -04003488 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
Quinn Tran83548fe2017-06-02 09:12:01 -07003489 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
Himanshu Madhani2486c622014-09-25 05:17:00 -04003490 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
Andrew Vasquez24a08132009-03-24 09:08:16 -07003491 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003492
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003493 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003494next_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003496 ql_log(ql_log_fatal, vha, 0x00d2,
3497 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003499 ql_dbg(ql_dbg_init, vha, 0x00d3,
3500 "Init Firmware -- success.\n");
Quinn Tran4b60c822017-06-13 20:47:21 -07003501 QLA_FW_STARTED(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502 }
3503
3504 return (rval);
3505}
3506
3507/**
3508 * qla2x00_fw_ready() - Waits for firmware ready.
3509 * @ha: HA context
3510 *
3511 * Returns 0 on success.
3512 */
3513static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003514qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515{
3516 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003517 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 uint16_t min_wait; /* Minimum wait time if loop is down */
3519 uint16_t wait_time; /* Wait time if loop is coming ready */
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003520 uint16_t state[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003521 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003523 if (IS_QLAFX00(vha->hw))
3524 return qlafx00_fw_ready(vha);
3525
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 rval = QLA_SUCCESS;
3527
Chad Dupuis334614912015-04-09 14:59:57 -04003528 /* Time to wait for loop down */
3529 if (IS_P3P_TYPE(ha))
3530 min_wait = 30;
3531 else
3532 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533
3534 /*
3535 * Firmware should take at most one RATOV to login, plus 5 seconds for
3536 * our own processing.
3537 */
3538 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
3539 wait_time = min_wait;
3540 }
3541
3542 /* Min wait time if loop down */
3543 mtime = jiffies + (min_wait * HZ);
3544
3545 /* wait time before firmware ready */
3546 wtime = jiffies + (wait_time * HZ);
3547
3548 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003549 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003550 ql_log(ql_log_info, vha, 0x801e,
3551 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552
3553 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05003554 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003555 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003557 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003558 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003560 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003561 ql_dbg(ql_dbg_taskm, vha, 0x801f,
3562 "fw_state=%x 84xx=%x.\n", state[0],
3563 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003564 if ((state[2] & FSTATE_LOGGED_IN) &&
3565 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003566 ql_dbg(ql_dbg_taskm, vha, 0x8028,
3567 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003568
3569 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003570 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003571 if (rval != QLA_SUCCESS) {
3572 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08003573 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003574 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003575 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003576 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003577
3578 /* Add time taken to initialize. */
3579 cs84xx_time = jiffies - cs84xx_time;
3580 wtime += cs84xx_time;
3581 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08003582 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003583 "Increasing wait time by %ld. "
3584 "New time %ld.\n", cs84xx_time,
3585 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003586 }
3587 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003588 ql_dbg(ql_dbg_taskm, vha, 0x8037,
3589 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003591 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592 &ha->login_timeout, &ha->r_a_tov);
3593
3594 rval = QLA_SUCCESS;
3595 break;
3596 }
3597
3598 rval = QLA_FUNCTION_FAILED;
3599
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003600 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003601 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003603 * other than Wait for Login.
3604 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003606 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607 "Cable is unplugged...\n");
3608
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003609 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 break;
3611 }
3612 }
3613 } else {
3614 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07003615 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08003616 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 break;
3618 }
3619
3620 if (time_after_eq(jiffies, wtime))
3621 break;
3622
3623 /* Delay for a while */
3624 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 } while (1);
3626
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003627 ql_dbg(ql_dbg_taskm, vha, 0x803a,
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003628 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
3629 state[1], state[2], state[3], state[4], state[5], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630
Chad Dupuiscfb09192011-11-18 09:03:07 -08003631 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003632 ql_log(ql_log_warn, vha, 0x803b,
3633 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 }
3635
3636 return (rval);
3637}
3638
3639/*
3640* qla2x00_configure_hba
3641* Setup adapter context.
3642*
3643* Input:
3644* ha = adapter state pointer.
3645*
3646* Returns:
3647* 0 = success
3648*
3649* Context:
3650* Kernel context.
3651*/
3652static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003653qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654{
3655 int rval;
3656 uint16_t loop_id;
3657 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003658 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659 uint8_t al_pa;
3660 uint8_t area;
3661 uint8_t domain;
3662 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003663 struct qla_hw_data *ha = vha->hw;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003664 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran482c9dc2017-03-15 09:48:54 -07003665 port_id_t id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666
3667 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003668 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003669 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003671 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003672 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08003673 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003674 ql_dbg(ql_dbg_disc, vha, 0x2008,
3675 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08003676 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003677 ql_log(ql_log_warn, vha, 0x2009,
3678 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003679 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
3680 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
3681 ql_log(ql_log_warn, vha, 0x1151,
3682 "Doing link init.\n");
3683 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
3684 return rval;
3685 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003686 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08003687 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 return (rval);
3689 }
3690
3691 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003692 ql_log(ql_log_info, vha, 0x200a,
3693 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694 return (QLA_FUNCTION_FAILED);
3695 }
3696
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003697 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698
3699 /* initialize */
3700 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
3701 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003702 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703
3704 switch (topo) {
3705 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003706 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 ha->current_topology = ISP_CFG_NL;
3708 strcpy(connect_type, "(Loop)");
3709 break;
3710
3711 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003712 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003713 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 ha->current_topology = ISP_CFG_FL;
3715 strcpy(connect_type, "(FL_Port)");
3716 break;
3717
3718 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003719 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 ha->operating_mode = P2P;
3721 ha->current_topology = ISP_CFG_N;
3722 strcpy(connect_type, "(N_Port-to-N_Port)");
3723 break;
3724
3725 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003726 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003727 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728 ha->operating_mode = P2P;
3729 ha->current_topology = ISP_CFG_F;
3730 strcpy(connect_type, "(F_Port)");
3731 break;
3732
3733 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003734 ql_dbg(ql_dbg_disc, vha, 0x200f,
3735 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736 ha->current_topology = ISP_CFG_NL;
3737 strcpy(connect_type, "(Loop)");
3738 break;
3739 }
3740
3741 /* Save Host port and loop ID. */
3742 /* byte order - Big Endian */
Quinn Tran482c9dc2017-03-15 09:48:54 -07003743 id.b.domain = domain;
3744 id.b.area = area;
3745 id.b.al_pa = al_pa;
3746 id.b.rsvd_1 = 0;
3747 qlt_update_host_map(vha, id);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003748
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003749 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003750 ql_log(ql_log_info, vha, 0x2010,
3751 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003752 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 return(rval);
3755}
3756
Giridhar Malavalia9083012010-04-12 17:59:55 -07003757inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003758qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
3759 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003760{
3761 char *st, *en;
3762 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003763 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07003764 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003765 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003766
3767 if (memcmp(model, BINZERO, len) != 0) {
3768 strncpy(ha->model_number, model, len);
3769 st = en = ha->model_number;
3770 en += len - 1;
3771 while (en > st) {
3772 if (*en != 0x20 && *en != 0x00)
3773 break;
3774 *en-- = '\0';
3775 }
3776
3777 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07003778 if (use_tbl &&
3779 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003780 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003781 strncpy(ha->model_desc,
3782 qla2x00_model_name[index * 2 + 1],
3783 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003784 } else {
3785 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07003786 if (use_tbl &&
3787 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003788 index < QLA_MODEL_NAMES) {
3789 strcpy(ha->model_number,
3790 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003791 strncpy(ha->model_desc,
3792 qla2x00_model_name[index * 2 + 1],
3793 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003794 } else {
3795 strcpy(ha->model_number, def);
3796 }
3797 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003798 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003799 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003800 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003801}
3802
David Miller4e08df32007-04-16 12:37:43 -07003803/* On sparc systems, obtain port and node WWN from firmware
3804 * properties.
3805 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003806static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07003807{
3808#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003809 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003810 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003811 struct device_node *dp = pci_device_to_OF_node(pdev);
3812 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003813 int len;
3814
3815 val = of_get_property(dp, "port-wwn", &len);
3816 if (val && len >= WWN_SIZE)
3817 memcpy(nv->port_name, val, WWN_SIZE);
3818
3819 val = of_get_property(dp, "node-wwn", &len);
3820 if (val && len >= WWN_SIZE)
3821 memcpy(nv->node_name, val, WWN_SIZE);
3822#endif
3823}
3824
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825/*
3826* NVRAM configuration for ISP 2xxx
3827*
3828* Input:
3829* ha = adapter block pointer.
3830*
3831* Output:
3832* initialization control block in response_ring
3833* host adapters parameters in host adapter block
3834*
3835* Returns:
3836* 0 = success.
3837*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003838int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003839qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840{
David Miller4e08df32007-04-16 12:37:43 -07003841 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003842 uint8_t chksum = 0;
3843 uint16_t cnt;
3844 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003845 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003846 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003847 nvram_t *nv = ha->nvram;
3848 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003849 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850
David Miller4e08df32007-04-16 12:37:43 -07003851 rval = QLA_SUCCESS;
3852
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003854 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855 ha->nvram_base = 0;
3856 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
3857 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
3858 ha->nvram_base = 0x80;
3859
3860 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003861 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003862 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
3863 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003865 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
3866 "Contents of NVRAM.\n");
3867 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
3868 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869
3870 /* Bad NVRAM data, set defaults parameters. */
3871 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
3872 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
3873 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003874 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04003875 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003876 "detected: checksum=0x%x id=%c version=0x%x.\n",
3877 chksum, nv->id[0], nv->nvram_version);
3878 ql_log(ql_log_warn, vha, 0x0065,
3879 "Falling back to "
3880 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07003881
3882 /*
3883 * Set default initialization control block.
3884 */
3885 memset(nv, 0, ha->nvram_size);
3886 nv->parameter_block_version = ICB_VERSION;
3887
3888 if (IS_QLA23XX(ha)) {
3889 nv->firmware_options[0] = BIT_2 | BIT_1;
3890 nv->firmware_options[1] = BIT_7 | BIT_5;
3891 nv->add_firmware_options[0] = BIT_5;
3892 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04003893 nv->frame_payload_size = 2048;
David Miller4e08df32007-04-16 12:37:43 -07003894 nv->special_options[1] = BIT_7;
3895 } else if (IS_QLA2200(ha)) {
3896 nv->firmware_options[0] = BIT_2 | BIT_1;
3897 nv->firmware_options[1] = BIT_7 | BIT_5;
3898 nv->add_firmware_options[0] = BIT_5;
3899 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04003900 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07003901 } else if (IS_QLA2100(ha)) {
3902 nv->firmware_options[0] = BIT_3 | BIT_1;
3903 nv->firmware_options[1] = BIT_5;
Joe Carnuccio98aee702014-09-25 05:16:38 -04003904 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07003905 }
3906
Bart Van Asschead950362015-07-09 07:24:08 -07003907 nv->max_iocb_allocation = cpu_to_le16(256);
3908 nv->execution_throttle = cpu_to_le16(16);
David Miller4e08df32007-04-16 12:37:43 -07003909 nv->retry_count = 8;
3910 nv->retry_delay = 1;
3911
3912 nv->port_name[0] = 33;
3913 nv->port_name[3] = 224;
3914 nv->port_name[4] = 139;
3915
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003916 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003917
3918 nv->login_timeout = 4;
3919
3920 /*
3921 * Set default host adapter parameters
3922 */
3923 nv->host_p[1] = BIT_2;
3924 nv->reset_delay = 5;
3925 nv->port_down_retry_count = 8;
Bart Van Asschead950362015-07-09 07:24:08 -07003926 nv->max_luns_per_target = cpu_to_le16(8);
David Miller4e08df32007-04-16 12:37:43 -07003927 nv->link_down_timeout = 60;
3928
3929 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930 }
3931
3932#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3933 /*
3934 * The SN2 does not provide BIOS emulation which means you can't change
3935 * potentially bogus BIOS settings. Force the use of default settings
3936 * for link rate and frame size. Hope that the rest of the settings
3937 * are valid.
3938 */
3939 if (ia64_platform_is("sn2")) {
Joe Carnuccio98aee702014-09-25 05:16:38 -04003940 nv->frame_payload_size = 2048;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941 if (IS_QLA23XX(ha))
3942 nv->special_options[1] = BIT_7;
3943 }
3944#endif
3945
3946 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003947 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948
3949 /*
3950 * Setup driver NVRAM options.
3951 */
3952 nv->firmware_options[0] |= (BIT_6 | BIT_1);
3953 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
3954 nv->firmware_options[1] |= (BIT_5 | BIT_0);
3955 nv->firmware_options[1] &= ~BIT_4;
3956
3957 if (IS_QLA23XX(ha)) {
3958 nv->firmware_options[0] |= BIT_2;
3959 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003960 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003961 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962
3963 if (IS_QLA2300(ha)) {
3964 if (ha->fb_rev == FPM_2310) {
3965 strcpy(ha->model_number, "QLA2310");
3966 } else {
3967 strcpy(ha->model_number, "QLA2300");
3968 }
3969 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003970 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003971 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 }
3973 } else if (IS_QLA2200(ha)) {
3974 nv->firmware_options[0] |= BIT_2;
3975 /*
3976 * 'Point-to-point preferred, else loop' is not a safe
3977 * connection mode setting.
3978 */
3979 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
3980 (BIT_5 | BIT_4)) {
3981 /* Force 'loop preferred, else point-to-point'. */
3982 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
3983 nv->add_firmware_options[0] |= BIT_5;
3984 }
3985 strcpy(ha->model_number, "QLA22xx");
3986 } else /*if (IS_QLA2100(ha))*/ {
3987 strcpy(ha->model_number, "QLA2100");
3988 }
3989
3990 /*
3991 * Copy over NVRAM RISC parameter block to initialization control block.
3992 */
3993 dptr1 = (uint8_t *)icb;
3994 dptr2 = (uint8_t *)&nv->parameter_block_version;
3995 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
3996 while (cnt--)
3997 *dptr1++ = *dptr2++;
3998
3999 /* Copy 2nd half. */
4000 dptr1 = (uint8_t *)icb->add_firmware_options;
4001 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4002 while (cnt--)
4003 *dptr1++ = *dptr2++;
4004
Andrew Vasquez5341e862006-05-17 15:09:16 -07004005 /* Use alternate WWN? */
4006 if (nv->host_p[1] & BIT_7) {
4007 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4008 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4009 }
4010
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 /* Prepare nodename */
4012 if ((icb->firmware_options[1] & BIT_6) == 0) {
4013 /*
4014 * Firmware will apply the following mask if the nodename was
4015 * not provided.
4016 */
4017 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4018 icb->node_name[0] &= 0xF0;
4019 }
4020
4021 /*
4022 * Set host adapter parameters.
4023 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07004024
4025 /*
4026 * BIT_7 in the host-parameters section allows for modification to
4027 * internal driver logging.
4028 */
Andrew Vasquez01819442006-06-23 16:11:10 -07004029 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08004030 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4032 /* Always load RISC code on non ISP2[12]00 chips. */
4033 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4034 ha->flags.disable_risc_code_load = 0;
4035 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4036 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4037 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07004038 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004039 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040
4041 ha->operating_mode =
4042 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4043
4044 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4045 sizeof(ha->fw_seriallink_options));
4046
4047 /* save HBA serial number */
4048 ha->serial0 = icb->port_name[5];
4049 ha->serial1 = icb->port_name[6];
4050 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004051 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4052 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053
Bart Van Asschead950362015-07-09 07:24:08 -07004054 icb->execution_throttle = cpu_to_le16(0xFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055
4056 ha->retry_count = nv->retry_count;
4057
4058 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07004059 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 nv->login_timeout = ql2xlogintimeout;
4061 if (nv->login_timeout < 4)
4062 nv->login_timeout = 4;
4063 ha->login_timeout = nv->login_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004065 /* Set minimum RATOV to 100 tenths of a second. */
4066 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 ha->loop_reset_delay = nv->reset_delay;
4069
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 /* Link Down Timeout = 0:
4071 *
4072 * When Port Down timer expires we will start returning
4073 * I/O's to OS with "DID_NO_CONNECT".
4074 *
4075 * Link Down Timeout != 0:
4076 *
4077 * The driver waits for the link to come up after link down
4078 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004079 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 if (nv->link_down_timeout == 0) {
4081 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04004082 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083 } else {
4084 ha->link_down_timeout = nv->link_down_timeout;
4085 ha->loop_down_abort_time =
4086 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004087 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 /*
4090 * Need enough time to try and get the port back.
4091 */
4092 ha->port_down_retry_count = nv->port_down_retry_count;
4093 if (qlport_down_retry)
4094 ha->port_down_retry_count = qlport_down_retry;
4095 /* Set login_retry_count */
4096 ha->login_retry_count = nv->retry_count;
4097 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4098 ha->port_down_retry_count > 3)
4099 ha->login_retry_count = ha->port_down_retry_count;
4100 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4101 ha->login_retry_count = ha->port_down_retry_count;
4102 if (ql2xloginretrycount)
4103 ha->login_retry_count = ql2xloginretrycount;
4104
Bart Van Asschead950362015-07-09 07:24:08 -07004105 icb->lun_enables = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 icb->command_resource_count = 0;
4107 icb->immediate_notify_resource_count = 0;
Bart Van Asschead950362015-07-09 07:24:08 -07004108 icb->timeout = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109
4110 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4111 /* Enable RIO */
4112 icb->firmware_options[0] &= ~BIT_3;
4113 icb->add_firmware_options[0] &=
4114 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4115 icb->add_firmware_options[0] |= BIT_2;
4116 icb->response_accumulation_timer = 3;
4117 icb->interrupt_delay_timer = 5;
4118
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004119 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004121 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004122 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004123 ha->zio_mode = icb->add_firmware_options[0] &
4124 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4125 ha->zio_timer = icb->interrupt_delay_timer ?
4126 icb->interrupt_delay_timer: 2;
4127 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128 icb->add_firmware_options[0] &=
4129 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004130 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004131 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004132 ha->zio_mode = QLA_ZIO_MODE_6;
4133
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004134 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004135 "ZIO mode %d enabled; timer delay (%d us).\n",
4136 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004138 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4139 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004140 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141 }
4142 }
4143
David Miller4e08df32007-04-16 12:37:43 -07004144 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004145 ql_log(ql_log_warn, vha, 0x0069,
4146 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07004147 }
4148 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149}
4150
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004151static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004152qla2x00_rport_del(void *data)
4153{
4154 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004155 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004156 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004157
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004158 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07004159 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004160 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004161 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004162 if (rport) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004163 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4164 "%s %8phN. rport %p roles %x\n",
4165 __func__, fcport->port_name, rport,
4166 rport->roles);
Quinn Tran726b8542017-01-19 22:28:00 -08004167
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004168 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08004169 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004170}
4171
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172/**
4173 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4174 * @ha: HA context
4175 * @flags: allocation flags
4176 *
4177 * Returns a pointer to the allocated fcport, or NULL, if none available.
4178 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004179fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004180qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181{
4182 fc_port_t *fcport;
4183
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004184 fcport = kzalloc(sizeof(fc_port_t), flags);
4185 if (!fcport)
4186 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187
4188 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004189 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190 fcport->port_type = FCT_UNKNOWN;
4191 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07004192 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004193 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194
Quinn Tran726b8542017-01-19 22:28:00 -08004195 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4196 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
Quinn Tran6cb32162017-02-13 12:18:29 -08004197 flags);
Quinn Tran726b8542017-01-19 22:28:00 -08004198 fcport->disc_state = DSC_DELETED;
4199 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4200 fcport->deleted = QLA_SESS_DELETED;
4201 fcport->login_retry = vha->hw->login_retry_count;
4202 fcport->login_retry = 5;
4203 fcport->logout_on_delete = 1;
4204
4205 if (!fcport->ct_desc.ct_sns) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004206 ql_log(ql_log_warn, vha, 0xd049,
Quinn Tran726b8542017-01-19 22:28:00 -08004207 "Failed to allocate ct_sns request.\n");
4208 kfree(fcport);
4209 fcport = NULL;
4210 }
4211 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4212 INIT_LIST_HEAD(&fcport->gnl_entry);
4213 INIT_LIST_HEAD(&fcport->list);
4214
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004215 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216}
4217
Quinn Tran726b8542017-01-19 22:28:00 -08004218void
4219qla2x00_free_fcport(fc_port_t *fcport)
4220{
4221 if (fcport->ct_desc.ct_sns) {
4222 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4223 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4224 fcport->ct_desc.ct_sns_dma);
4225
4226 fcport->ct_desc.ct_sns = NULL;
4227 }
4228 kfree(fcport);
4229}
4230
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231/*
4232 * qla2x00_configure_loop
4233 * Updates Fibre Channel Device Database with what is actually on loop.
4234 *
4235 * Input:
4236 * ha = adapter block pointer.
4237 *
4238 * Returns:
4239 * 0 = success.
4240 * 1 = error.
4241 * 2 = database was full and device was not configured.
4242 */
4243static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004244qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245{
4246 int rval;
4247 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004248 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249 rval = QLA_SUCCESS;
4250
4251 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004252 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4253 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004255 ql_dbg(ql_dbg_disc, vha, 0x2013,
4256 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257 return (rval);
4258 }
4259 }
4260
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004261 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004262 ql_dbg(ql_dbg_disc, vha, 0x2014,
4263 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264
4265 /*
4266 * If we have both an RSCN and PORT UPDATE pending then handle them
4267 * both at the same time.
4268 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004269 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4270 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271
Michael Hernandez3064ff32009-12-15 21:29:44 -08004272 qla2x00_get_data_rate(vha);
4273
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274 /* Determine what we need to do */
4275 if (ha->current_topology == ISP_CFG_FL &&
4276 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4277
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278 set_bit(RSCN_UPDATE, &flags);
4279
4280 } else if (ha->current_topology == ISP_CFG_F &&
4281 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4282
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 set_bit(RSCN_UPDATE, &flags);
4284 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4285
Andrew Vasquez21333b42006-05-17 15:09:56 -07004286 } else if (ha->current_topology == ISP_CFG_N) {
4287 clear_bit(RSCN_UPDATE, &flags);
Quinn Tran41dc5292017-01-19 22:28:03 -08004288 } else if (ha->current_topology == ISP_CFG_NL) {
4289 clear_bit(RSCN_UPDATE, &flags);
4290 set_bit(LOCAL_LOOP_UPDATE, &flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004291 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293 set_bit(RSCN_UPDATE, &flags);
4294 set_bit(LOCAL_LOOP_UPDATE, &flags);
4295 }
4296
4297 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004298 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4299 ql_dbg(ql_dbg_disc, vha, 0x2015,
4300 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08004302 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004303 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304 }
4305
4306 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004307 if (LOOP_TRANSITION(vha)) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004308 ql_dbg(ql_dbg_disc, vha, 0x2099,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004309 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004310 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004311 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004312 else
4313 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314 }
4315
4316 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004317 if (atomic_read(&vha->loop_down_timer) ||
4318 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319 rval = QLA_FUNCTION_FAILED;
4320 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004321 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004322 ql_dbg(ql_dbg_disc, vha, 0x2069,
4323 "LOOP READY.\n");
Quinn Tranec7193e2017-03-15 09:48:55 -07004324 ha->flags.fw_init_done = 1;
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05004325
4326 /*
4327 * Process any ATIO queue entries that came in
4328 * while we weren't online.
4329 */
Quinn Tranead03852017-01-19 22:28:01 -08004330 if (qla_tgt_mode_enabled(vha) ||
4331 qla_dual_mode_enabled(vha)) {
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05004332 if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) {
4333 spin_lock_irqsave(&ha->tgt.atio_lock,
4334 flags);
4335 qlt_24xx_process_atio_queue(vha, 0);
4336 spin_unlock_irqrestore(
4337 &ha->tgt.atio_lock, flags);
4338 } else {
4339 spin_lock_irqsave(&ha->hardware_lock,
4340 flags);
4341 qlt_24xx_process_atio_queue(vha, 1);
4342 spin_unlock_irqrestore(
4343 &ha->hardware_lock, flags);
4344 }
4345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346 }
4347 }
4348
4349 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004350 ql_dbg(ql_dbg_disc, vha, 0x206a,
4351 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004353 ql_dbg(ql_dbg_disc, vha, 0x206b,
4354 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355 }
4356
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07004357 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004358 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004360 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004361 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004362 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004363 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004364 }
4365
4366 return (rval);
4367}
4368
4369
4370
4371/*
4372 * qla2x00_configure_local_loop
4373 * Updates Fibre Channel Device Database with local loop devices.
4374 *
4375 * Input:
4376 * ha = adapter block pointer.
4377 *
4378 * Returns:
4379 * 0 = success.
4380 */
4381static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004382qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004383{
4384 int rval, rval2;
4385 int found_devs;
4386 int found;
4387 fc_port_t *fcport, *new_fcport;
4388
4389 uint16_t index;
4390 uint16_t entries;
4391 char *id_iter;
4392 uint16_t loop_id;
4393 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004394 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08004395 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396
4397 found_devs = 0;
4398 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08004399 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004400
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08004402 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004403 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 &entries);
4405 if (rval != QLA_SUCCESS)
4406 goto cleanup_allocation;
4407
Quinn Tran83548fe2017-06-02 09:12:01 -07004408 ql_dbg(ql_dbg_disc, vha, 0x2011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004409 "Entries in ID list (%d).\n", entries);
4410 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
4411 (uint8_t *)ha->gid_list,
4412 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413
4414 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004415 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004416 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004417 ql_log(ql_log_warn, vha, 0x2012,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004418 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419 rval = QLA_MEMORY_ALLOC_FAILED;
4420 goto cleanup_allocation;
4421 }
4422 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4423
4424 /*
4425 * Mark local devices that were present with FCF_DEVICE_LOST for now.
4426 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004427 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004428 if (atomic_read(&fcport->state) == FCS_ONLINE &&
4429 fcport->port_type != FCT_BROADCAST &&
4430 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
4431
Quinn Tran83548fe2017-06-02 09:12:01 -07004432 ql_dbg(ql_dbg_disc, vha, 0x2096,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004433 "Marking port lost loop_id=0x%04x.\n",
4434 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435
Quinn Tran41dc5292017-01-19 22:28:03 -08004436 qla2x00_mark_device_lost(vha, fcport, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004437 }
4438 }
4439
4440 /* Add devices to port list. */
4441 id_iter = (char *)ha->gid_list;
4442 for (index = 0; index < entries; index++) {
4443 domain = ((struct gid_list_info *)id_iter)->domain;
4444 area = ((struct gid_list_info *)id_iter)->area;
4445 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004446 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004447 loop_id = (uint16_t)
4448 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004449 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450 loop_id = le16_to_cpu(
4451 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004452 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453
4454 /* Bypass reserved domain fields. */
4455 if ((domain & 0xf0) == 0xf0)
4456 continue;
4457
4458 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004459 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004460 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004461 continue;
4462
4463 /* Bypass invalid local loop ID. */
4464 if (loop_id > LAST_LOCAL_LOOP_ID)
4465 continue;
4466
Quinn Tran41dc5292017-01-19 22:28:03 -08004467 memset(new_fcport->port_name, 0, WWN_SIZE);
Arun Easi370d5502012-08-22 14:21:10 -04004468
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469 /* Fill in member data. */
4470 new_fcport->d_id.b.domain = domain;
4471 new_fcport->d_id.b.area = area;
4472 new_fcport->d_id.b.al_pa = al_pa;
4473 new_fcport->loop_id = loop_id;
Quinn Tran41dc5292017-01-19 22:28:03 -08004474
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004475 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004476 if (rval2 != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004477 ql_dbg(ql_dbg_disc, vha, 0x2097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004478 "Failed to retrieve fcport information "
4479 "-- get_port_database=%x, loop_id=0x%04x.\n",
4480 rval2, new_fcport->loop_id);
Quinn Tran83548fe2017-06-02 09:12:01 -07004481 ql_dbg(ql_dbg_disc, vha, 0x2105,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004482 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004483 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004484 continue;
4485 }
4486
Quinn Tran41dc5292017-01-19 22:28:03 -08004487 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488 /* Check for matching device in port list. */
4489 found = 0;
4490 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004491 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004492 if (memcmp(new_fcport->port_name, fcport->port_name,
4493 WWN_SIZE))
4494 continue;
4495
Shyam Sundarddb9b122009-03-24 09:08:10 -07004496 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497 fcport->loop_id = new_fcport->loop_id;
4498 fcport->port_type = new_fcport->port_type;
4499 fcport->d_id.b24 = new_fcport->d_id.b24;
4500 memcpy(fcport->node_name, new_fcport->node_name,
4501 WWN_SIZE);
4502
Quinn Tran41dc5292017-01-19 22:28:03 -08004503 if (!fcport->login_succ) {
4504 vha->fcport_count++;
4505 fcport->login_succ = 1;
4506 fcport->disc_state = DSC_LOGIN_COMPLETE;
4507 }
4508
Linus Torvalds1da177e2005-04-16 15:20:36 -07004509 found++;
4510 break;
4511 }
4512
4513 if (!found) {
4514 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004515 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516
4517 /* Allocate a new replacement fcport. */
4518 fcport = new_fcport;
Quinn Tran41dc5292017-01-19 22:28:03 -08004519 if (!fcport->login_succ) {
4520 vha->fcport_count++;
4521 fcport->login_succ = 1;
4522 fcport->disc_state = DSC_LOGIN_COMPLETE;
4523 }
4524
4525 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4526
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004527 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Quinn Tran41dc5292017-01-19 22:28:03 -08004528
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004530 ql_log(ql_log_warn, vha, 0xd031,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004531 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004532 rval = QLA_MEMORY_ALLOC_FAILED;
4533 goto cleanup_allocation;
4534 }
Quinn Tran41dc5292017-01-19 22:28:03 -08004535 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004536 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4537 }
4538
Quinn Tran41dc5292017-01-19 22:28:03 -08004539 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4540
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004541 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004542 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004543
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004544 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545
4546 found_devs++;
4547 }
4548
4549cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08004550 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004551
4552 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004553 ql_dbg(ql_dbg_disc, vha, 0x2098,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004554 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004555 }
4556
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 return (rval);
4558}
4559
4560static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004561qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004562{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004563 int rval;
Quinn Tran93f2bd62014-09-25 05:16:53 -04004564 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004565 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004566
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07004567 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004568 return;
4569
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07004570 if (atomic_read(&fcport->state) != FCS_ONLINE)
4571 return;
4572
Andrew Vasquez39bd9622007-09-20 14:07:34 -07004573 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
4574 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004575 return;
4576
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004577 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004578 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004579 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004580 ql_dbg(ql_dbg_disc, vha, 0x2004,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004581 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
4582 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004583 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004584 ql_dbg(ql_dbg_disc, vha, 0x2005,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004585 "iIDMA adjusted to %s GB/s on %8phN.\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -05004586 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004587 fcport->port_name);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004588 }
4589}
4590
Quinn Tran726b8542017-01-19 22:28:00 -08004591/* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
Adrian Bunk23be3312006-11-24 02:46:01 +01004592static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004593qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05004594{
4595 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05004596 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004597 unsigned long flags;
8482e1182005-04-17 15:04:54 -05004598
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07004599 rport_ids.node_name = wwn_to_u64(fcport->node_name);
4600 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05004601 rport_ids.port_id = fcport->d_id.b.domain << 16 |
4602 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
4603 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004604 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07004605 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004606 ql_log(ql_log_warn, vha, 0x2006,
4607 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07004608 return;
4609 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004610
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004611 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004612 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004613 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004614
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004615 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07004616
4617 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05004618 if (fcport->port_type == FCT_INITIATOR)
4619 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
4620 if (fcport->port_type == FCT_TARGET)
4621 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Quinn Tran726b8542017-01-19 22:28:00 -08004622
Quinn Tran83548fe2017-06-02 09:12:01 -07004623 ql_dbg(ql_dbg_disc, vha, 0x20ee,
4624 "%s %8phN. rport %p is %s mode\n",
4625 __func__, fcport->port_name, rport,
4626 (fcport->port_type == FCT_TARGET) ? "tgt" : "ini");
Quinn Tran726b8542017-01-19 22:28:00 -08004627
Andrew Vasquez77d74142005-07-08 18:00:36 -07004628 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05004629}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630
4631/*
Adrian Bunk23be3312006-11-24 02:46:01 +01004632 * qla2x00_update_fcport
4633 * Updates device on list.
4634 *
4635 * Input:
4636 * ha = adapter block pointer.
4637 * fcport = port structure pointer.
4638 *
4639 * Return:
4640 * 0 - Success
4641 * BIT_0 - error
4642 *
4643 * Context:
4644 * Kernel context.
4645 */
4646void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004647qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01004648{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004649 fcport->vha = vha;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004650
Quinn Tran726b8542017-01-19 22:28:00 -08004651 if (IS_SW_RESV_ADDR(fcport->d_id))
4652 return;
4653
Quinn Tran83548fe2017-06-02 09:12:01 -07004654 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
Quinn Tran726b8542017-01-19 22:28:00 -08004655 __func__, fcport->port_name);
4656
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004657 if (IS_QLAFX00(vha->hw)) {
4658 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004659 goto reg_port;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004660 }
Adrian Bunk23be3312006-11-24 02:46:01 +01004661 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004662 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Quinn Tran726b8542017-01-19 22:28:00 -08004663 fcport->disc_state = DSC_LOGIN_COMPLETE;
4664 fcport->deleted = 0;
4665 fcport->logout_on_delete = 1;
Adrian Bunk23be3312006-11-24 02:46:01 +01004666
Duane Grigsbye84067d2017-06-21 13:48:43 -07004667 if (fcport->fc4f_nvme) {
4668 qla_nvme_register_remote(vha, fcport);
4669 return;
4670 }
4671
Joe Carnuccio1f93da522012-11-21 02:40:38 -05004672 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004673 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08004674 qla24xx_update_fcport_fcp_prio(vha, fcport);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004675
4676reg_port:
Quinn Tran726b8542017-01-19 22:28:00 -08004677 switch (vha->host->active_mode) {
4678 case MODE_INITIATOR:
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004679 qla2x00_reg_remote_port(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08004680 break;
4681 case MODE_TARGET:
4682 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
4683 !vha->vha_tgt.qla_tgt->tgt_stopped)
4684 qlt_fc_port_added(vha, fcport);
4685 break;
4686 case MODE_DUAL:
4687 qla2x00_reg_remote_port(vha, fcport);
4688 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
4689 !vha->vha_tgt.qla_tgt->tgt_stopped)
4690 qlt_fc_port_added(vha, fcport);
4691 break;
4692 default:
4693 break;
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004694 }
Adrian Bunk23be3312006-11-24 02:46:01 +01004695}
4696
4697/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698 * qla2x00_configure_fabric
4699 * Setup SNS devices with loop ID's.
4700 *
4701 * Input:
4702 * ha = adapter block pointer.
4703 *
4704 * Returns:
4705 * 0 = success.
4706 * BIT_0 = error
4707 */
4708static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004709qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004710{
Arun Easib3b02e62012-02-09 11:15:39 -08004711 int rval;
Quinn Tran726b8542017-01-19 22:28:00 -08004712 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004713 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004714 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004716 struct qla_hw_data *ha = vha->hw;
Alexei Potashnikdf673272015-07-14 16:00:46 -04004717 int discovery_gen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718
4719 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07004720 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004721 loop_id = NPH_F_PORT;
4722 else
4723 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004724 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004726 ql_dbg(ql_dbg_disc, vha, 0x20a0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004727 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004729 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730 return (QLA_SUCCESS);
4731 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004732 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004733
Quinn Tran41dc5292017-01-19 22:28:03 -08004734
4735 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
4736 rval = qla2x00_send_change_request(vha, 0x3, 0);
4737 if (rval != QLA_SUCCESS)
4738 ql_log(ql_log_warn, vha, 0x121,
4739 "Failed to enable receiving of RSCN requests: 0x%x.\n",
4740 rval);
4741 }
4742
4743
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744 do {
Quinn Tran726b8542017-01-19 22:28:00 -08004745 qla2x00_mgmt_svr_login(vha);
4746
Andrew Vasquezcca53352005-08-26 19:08:30 -07004747 /* FDMI support. */
4748 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004749 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
4750 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07004751
Linus Torvalds1da177e2005-04-16 15:20:36 -07004752 /* Ensure we are logged into the SNS. */
Joe Carnuccioa14c7712017-08-23 15:05:12 -07004753 loop_id = NPH_SNS_LID(ha);
Chad Dupuis0b91d112012-02-09 11:15:42 -08004754 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
4755 0xfc, mb, BIT_1|BIT_0);
Joe Carnuccioa14c7712017-08-23 15:05:12 -07004756 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
4757 ql_dbg(ql_dbg_disc, vha, 0x20a1,
4758 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
4759 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
Chad Dupuis0b91d112012-02-09 11:15:42 -08004760 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05004761 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08004762 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004763 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
4764 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07004766 ql_dbg(ql_dbg_disc, vha, 0x20a2,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004767 "Register FC-4 TYPE failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004768 if (test_bit(LOOP_RESYNC_NEEDED,
4769 &vha->dpc_flags))
4770 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771 }
Duane Grigsbyd3bae932017-06-21 13:48:44 -07004772 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07004774 ql_dbg(ql_dbg_disc, vha, 0x209a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004775 "Register FC-4 Features failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004776 if (test_bit(LOOP_RESYNC_NEEDED,
4777 &vha->dpc_flags))
4778 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004779 }
Duane Grigsbyd3bae932017-06-21 13:48:44 -07004780 if (vha->flags.nvme_enabled) {
4781 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
4782 ql_dbg(ql_dbg_disc, vha, 0x2049,
4783 "Register NVME FC Type Features failed.\n");
4784 }
4785 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004786 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07004788 ql_dbg(ql_dbg_disc, vha, 0x2104,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004789 "Register Node Name failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004790 if (test_bit(LOOP_RESYNC_NEEDED,
4791 &vha->dpc_flags))
4792 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004793 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794 /* EMPTY */
Quinn Tran83548fe2017-06-02 09:12:01 -07004795 ql_dbg(ql_dbg_disc, vha, 0x209b,
Colin Ian King0bf0efa2017-06-30 14:47:41 +01004796 "Register Symbolic Node Name failed.\n");
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004797 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4798 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799 }
4800 }
4801
Joe Carnuccio827210b2013-02-08 01:57:57 -05004802 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4803 fcport->scan_state = QLA_FCPORT_SCAN;
4804 }
4805
Alexei Potashnikdf673272015-07-14 16:00:46 -04004806 /* Mark the time right before querying FW for connected ports.
4807 * This process is long, asynchronous and by the time it's done,
4808 * collected information might not be accurate anymore. E.g.
4809 * disconnected port might have re-connected and a brand new
4810 * session has been created. In this case session's generation
4811 * will be newer than discovery_gen. */
4812 qlt_do_generation_tick(vha, &discovery_gen);
4813
Quinn Tran726b8542017-01-19 22:28:00 -08004814 rval = qla2x00_find_all_fabric_devs(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815 if (rval != QLA_SUCCESS)
4816 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004817 } while (0);
4818
Duane Grigsbye84067d2017-06-21 13:48:43 -07004819 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
4820 qla_nvme_register_hba(vha);
4821
Quinn Tran726b8542017-01-19 22:28:00 -08004822 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004823 ql_dbg(ql_dbg_disc, vha, 0x2068,
4824 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004825
4826 return (rval);
4827}
4828
Linus Torvalds1da177e2005-04-16 15:20:36 -07004829/*
4830 * qla2x00_find_all_fabric_devs
4831 *
4832 * Input:
4833 * ha = adapter block pointer.
4834 * dev = database device entry pointer.
4835 *
4836 * Returns:
4837 * 0 = success.
4838 *
4839 * Context:
4840 * Kernel context.
4841 */
4842static int
Quinn Tran726b8542017-01-19 22:28:00 -08004843qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844{
4845 int rval;
4846 uint16_t loop_id;
Quinn Tran726b8542017-01-19 22:28:00 -08004847 fc_port_t *fcport, *new_fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848 int found;
4849
4850 sw_info_t *swl;
4851 int swl_idx;
4852 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07004853 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004854 struct qla_hw_data *ha = vha->hw;
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05004855 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran726b8542017-01-19 22:28:00 -08004856 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857
4858 rval = QLA_SUCCESS;
4859
4860 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08004861 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08004862 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08004863 GFP_KERNEL);
4864 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004865 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866 /*EMPTY*/
Quinn Tran83548fe2017-06-02 09:12:01 -07004867 ql_dbg(ql_dbg_disc, vha, 0x209c,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004868 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004869 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08004870 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004871 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004873 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4874 return rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004875 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004877 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4878 return rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004879 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004881 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4882 return rval;
Quinn Tran726b8542017-01-19 22:28:00 -08004883 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
4884 swl = NULL;
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004885 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4886 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004888
4889 /* If other queries succeeded probe for FC-4 type */
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004890 if (swl) {
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004891 qla2x00_gff_id(vha, swl);
Quinn Tranb98ae0d2017-06-02 09:12:00 -07004892 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4893 return rval;
4894 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895 }
4896 swl_idx = 0;
4897
4898 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004899 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004901 ql_log(ql_log_warn, vha, 0x209d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004902 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903 return (QLA_MEMORY_ALLOC_FAILED);
4904 }
4905 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906 /* Set start port ID scan at adapter ID. */
4907 first_dev = 1;
4908 last_dev = 0;
4909
4910 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004911 loop_id = ha->min_external_loopid;
4912 for (; loop_id <= ha->max_loop_id; loop_id++) {
4913 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004914 continue;
4915
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07004916 if (ha->current_topology == ISP_CFG_FL &&
4917 (atomic_read(&vha->loop_down_timer) ||
4918 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08004919 atomic_set(&vha->loop_down_timer, 0);
4920 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4921 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004922 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08004923 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004924
4925 if (swl != NULL) {
4926 if (last_dev) {
4927 wrap.b24 = new_fcport->d_id.b24;
4928 } else {
4929 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
4930 memcpy(new_fcport->node_name,
4931 swl[swl_idx].node_name, WWN_SIZE);
4932 memcpy(new_fcport->port_name,
4933 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004934 memcpy(new_fcport->fabric_port_name,
4935 swl[swl_idx].fabric_port_name, WWN_SIZE);
4936 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004937 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004938
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004939 new_fcport->nvme_flag = 0;
Darren Trap1a28faa2017-08-30 10:16:48 -07004940 new_fcport->fc4f_nvme = 0;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07004941 if (vha->flags.nvme_enabled &&
4942 swl[swl_idx].fc4f_nvme) {
4943 new_fcport->fc4f_nvme =
4944 swl[swl_idx].fc4f_nvme;
4945 ql_log(ql_log_info, vha, 0x2131,
4946 "FOUND: NVME port %8phC as FC Type 28h\n",
4947 new_fcport->port_name);
4948 }
4949
Linus Torvalds1da177e2005-04-16 15:20:36 -07004950 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
4951 last_dev = 1;
4952 }
4953 swl_idx++;
4954 }
4955 } else {
4956 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004957 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004959 ql_log(ql_log_warn, vha, 0x209e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004960 "SNS scan failed -- assuming "
4961 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962 rval = QLA_SUCCESS;
4963 break;
4964 }
4965 }
4966
4967 /* If wrap on switch device list, exit. */
4968 if (first_dev) {
4969 wrap.b24 = new_fcport->d_id.b24;
4970 first_dev = 0;
4971 } else if (new_fcport->d_id.b24 == wrap.b24) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004972 ql_dbg(ql_dbg_disc, vha, 0x209f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004973 "Device wrap (%02x%02x%02x).\n",
4974 new_fcport->d_id.b.domain,
4975 new_fcport->d_id.b.area,
4976 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977 break;
4978 }
4979
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004980 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004981 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982 continue;
4983
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004984 /* Bypass virtual ports of the same host. */
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05004985 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
4986 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004987
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004988 /* Bypass if same domain and area of adapter. */
4989 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004990 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004991 ISP_CFG_FL)
4992 continue;
4993
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994 /* Bypass reserved domain fields. */
4995 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
4996 continue;
4997
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004998 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07004999 if (ql2xgffidenable &&
5000 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5001 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05005002 continue;
5003
Quinn Tran726b8542017-01-19 22:28:00 -08005004 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5005
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006 /* Locate matching device in database. */
5007 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005008 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009 if (memcmp(new_fcport->port_name, fcport->port_name,
5010 WWN_SIZE))
5011 continue;
5012
Joe Carnuccio827210b2013-02-08 01:57:57 -05005013 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08005014
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015 found++;
5016
Andrew Vasquezd8b45212006-10-02 12:00:43 -07005017 /* Update port state. */
5018 memcpy(fcport->fabric_port_name,
5019 new_fcport->fabric_port_name, WWN_SIZE);
5020 fcport->fp_speed = new_fcport->fp_speed;
5021
Linus Torvalds1da177e2005-04-16 15:20:36 -07005022 /*
Roland Dreierb2032fd2015-07-14 16:00:42 -04005023 * If address the same and state FCS_ONLINE
5024 * (or in target mode), nothing changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025 */
5026 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
Roland Dreierb2032fd2015-07-14 16:00:42 -04005027 (atomic_read(&fcport->state) == FCS_ONLINE ||
Quinn Tran726b8542017-01-19 22:28:00 -08005028 (vha->host->active_mode == MODE_TARGET))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029 break;
5030 }
5031
5032 /*
5033 * If device was not a fabric device before.
5034 */
5035 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5036 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04005037 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005038 fcport->flags |= (FCF_FABRIC_DEVICE |
5039 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005040 break;
5041 }
5042
5043 /*
5044 * Port ID changed or device was marked to be updated;
5045 * Log it out if still logged in and mark it for
5046 * relogin later.
5047 */
Quinn Tran726b8542017-01-19 22:28:00 -08005048 if (qla_tgt_mode_enabled(base_vha)) {
Roland Dreierb2032fd2015-07-14 16:00:42 -04005049 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5050 "port changed FC ID, %8phC"
5051 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5052 fcport->port_name,
5053 fcport->d_id.b.domain,
5054 fcport->d_id.b.area,
5055 fcport->d_id.b.al_pa,
5056 fcport->loop_id,
5057 new_fcport->d_id.b.domain,
5058 new_fcport->d_id.b.area,
5059 new_fcport->d_id.b.al_pa);
5060 fcport->d_id.b24 = new_fcport->d_id.b24;
5061 break;
5062 }
5063
Linus Torvalds1da177e2005-04-16 15:20:36 -07005064 fcport->d_id.b24 = new_fcport->d_id.b24;
5065 fcport->flags |= FCF_LOGIN_NEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005066 break;
5067 }
5068
Quinn Tran726b8542017-01-19 22:28:00 -08005069 if (found) {
5070 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071 continue;
Quinn Tran726b8542017-01-19 22:28:00 -08005072 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073 /* If device was not in our fcports list, then add it. */
Roland Dreierb2032fd2015-07-14 16:00:42 -04005074 new_fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tran726b8542017-01-19 22:28:00 -08005075 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5076
5077 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5078
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079
5080 /* Allocate a new replacement fcport. */
5081 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005082 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083 if (new_fcport == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005084 ql_log(ql_log_warn, vha, 0xd032,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005085 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086 return (QLA_MEMORY_ALLOC_FAILED);
5087 }
5088 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5089 new_fcport->d_id.b24 = nxt_d_id.b24;
5090 }
5091
Quinn Tran726b8542017-01-19 22:28:00 -08005092 qla2x00_free_fcport(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093
Quinn Tran726b8542017-01-19 22:28:00 -08005094 /*
5095 * Logout all previous fabric dev marked lost, except FCP2 devices.
5096 */
5097 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5098 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5099 break;
5100
5101 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5102 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5103 continue;
5104
5105 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5106 if ((qla_dual_mode_enabled(vha) ||
5107 qla_ini_mode_enabled(vha)) &&
5108 atomic_read(&fcport->state) == FCS_ONLINE) {
5109 qla2x00_mark_device_lost(vha, fcport,
5110 ql2xplogiabsentdevice, 0);
5111 if (fcport->loop_id != FC_NO_LOOP_ID &&
5112 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5113 fcport->port_type != FCT_INITIATOR &&
5114 fcport->port_type != FCT_BROADCAST) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005115 ql_dbg(ql_dbg_disc, vha, 0x20f0,
Quinn Tran726b8542017-01-19 22:28:00 -08005116 "%s %d %8phC post del sess\n",
5117 __func__, __LINE__,
5118 fcport->port_name);
5119
5120 qlt_schedule_sess_for_deletion_lock
5121 (fcport);
5122 continue;
5123 }
5124 }
5125 }
5126
5127 if (fcport->scan_state == QLA_FCPORT_FOUND)
5128 qla24xx_fcport_handle_login(vha, fcport);
5129 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005130 return (rval);
5131}
5132
5133/*
5134 * qla2x00_find_new_loop_id
5135 * Scan through our port list and find a new usable loop ID.
5136 *
5137 * Input:
5138 * ha: adapter state pointer.
5139 * dev: port structure pointer.
5140 *
5141 * Returns:
5142 * qla2x00 local function return status code.
5143 *
5144 * Context:
5145 * Kernel context.
5146 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07005147int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005148qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005149{
5150 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005151 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07005152 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153
5154 rval = QLA_SUCCESS;
5155
Chad Dupuis5f16b332012-08-22 14:21:00 -04005156 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157
Chad Dupuis5f16b332012-08-22 14:21:00 -04005158 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
5159 LOOPID_MAP_SIZE);
5160 if (dev->loop_id >= LOOPID_MAP_SIZE ||
5161 qla2x00_is_reserved_id(vha, dev->loop_id)) {
5162 dev->loop_id = FC_NO_LOOP_ID;
5163 rval = QLA_FUNCTION_FAILED;
5164 } else
5165 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005166
Chad Dupuis5f16b332012-08-22 14:21:00 -04005167 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168
Chad Dupuis5f16b332012-08-22 14:21:00 -04005169 if (rval == QLA_SUCCESS)
5170 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
5171 "Assigning new loopid=%x, portid=%x.\n",
5172 dev->loop_id, dev->d_id.b24);
5173 else
5174 ql_log(ql_log_warn, dev->vha, 0x2087,
5175 "No loop_id's available, portid=%x.\n",
5176 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005177
5178 return (rval);
5179}
5180
Linus Torvalds1da177e2005-04-16 15:20:36 -07005181
5182/*
5183 * qla2x00_fabric_login
5184 * Issue fabric login command.
5185 *
5186 * Input:
5187 * ha = adapter block pointer.
5188 * device = pointer to FC device type structure.
5189 *
5190 * Returns:
5191 * 0 - Login successfully
5192 * 1 - Login failed
5193 * 2 - Initiator device
5194 * 3 - Fatal error
5195 */
5196int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005197qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005198 uint16_t *next_loopid)
5199{
5200 int rval;
5201 int retry;
5202 uint16_t tmp_loopid;
5203 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005204 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205
5206 retry = 0;
5207 tmp_loopid = 0;
5208
5209 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005210 ql_dbg(ql_dbg_disc, vha, 0x2000,
5211 "Trying Fabric Login w/loop id 0x%04x for port "
5212 "%02x%02x%02x.\n",
5213 fcport->loop_id, fcport->d_id.b.domain,
5214 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215
5216 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08005217 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218 fcport->d_id.b.domain, fcport->d_id.b.area,
5219 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08005220 if (rval != QLA_SUCCESS) {
5221 return rval;
5222 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223 if (mb[0] == MBS_PORT_ID_USED) {
5224 /*
5225 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005226 * recommends the driver perform an implicit login with
5227 * the specified ID again. The ID we just used is save
5228 * here so we return with an ID that can be tried by
5229 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005230 */
5231 retry++;
5232 tmp_loopid = fcport->loop_id;
5233 fcport->loop_id = mb[1];
5234
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005235 ql_dbg(ql_dbg_disc, vha, 0x2001,
5236 "Fabric Login: port in use - next loop "
5237 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005239 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240
5241 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
5242 /*
5243 * Login succeeded.
5244 */
5245 if (retry) {
5246 /* A retry occurred before. */
5247 *next_loopid = tmp_loopid;
5248 } else {
5249 /*
5250 * No retry occurred before. Just increment the
5251 * ID value for next login.
5252 */
5253 *next_loopid = (fcport->loop_id + 1);
5254 }
5255
5256 if (mb[1] & BIT_0) {
5257 fcport->port_type = FCT_INITIATOR;
5258 } else {
5259 fcport->port_type = FCT_TARGET;
5260 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07005261 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262 }
5263 }
5264
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07005265 if (mb[10] & BIT_0)
5266 fcport->supported_classes |= FC_COS_CLASS2;
5267 if (mb[10] & BIT_1)
5268 fcport->supported_classes |= FC_COS_CLASS3;
5269
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005270 if (IS_FWI2_CAPABLE(ha)) {
5271 if (mb[10] & BIT_7)
5272 fcport->flags |=
5273 FCF_CONF_COMP_SUPPORTED;
5274 }
5275
Linus Torvalds1da177e2005-04-16 15:20:36 -07005276 rval = QLA_SUCCESS;
5277 break;
5278 } else if (mb[0] == MBS_LOOP_ID_USED) {
5279 /*
5280 * Loop ID already used, try next loop ID.
5281 */
5282 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005283 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005284 if (rval != QLA_SUCCESS) {
5285 /* Ran out of loop IDs to use */
5286 break;
5287 }
5288 } else if (mb[0] == MBS_COMMAND_ERROR) {
5289 /*
5290 * Firmware possibly timed out during login. If NO
5291 * retries are left to do then the device is declared
5292 * dead.
5293 */
5294 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005295 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07005296 fcport->d_id.b.domain, fcport->d_id.b.area,
5297 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005298 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005299
5300 rval = 1;
5301 break;
5302 } else {
5303 /*
5304 * unrecoverable / not handled error
5305 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005306 ql_dbg(ql_dbg_disc, vha, 0x2002,
5307 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
5308 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
5309 fcport->d_id.b.area, fcport->d_id.b.al_pa,
5310 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005311
5312 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005313 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07005314 fcport->d_id.b.domain, fcport->d_id.b.area,
5315 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04005316 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07005317 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005318
5319 rval = 3;
5320 break;
5321 }
5322 }
5323
5324 return (rval);
5325}
5326
5327/*
5328 * qla2x00_local_device_login
5329 * Issue local device login command.
5330 *
5331 * Input:
5332 * ha = adapter block pointer.
5333 * loop_id = loop id of device to login to.
5334 *
5335 * Returns (Where's the #define!!!!):
5336 * 0 - Login successfully
5337 * 1 - Login failed
5338 * 3 - Fatal error
5339 */
5340int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005341qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005342{
5343 int rval;
5344 uint16_t mb[MAILBOX_REGISTER_COUNT];
5345
5346 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005347 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005348 if (rval == QLA_SUCCESS) {
5349 /* Interrogate mailbox registers for any errors */
5350 if (mb[0] == MBS_COMMAND_ERROR)
5351 rval = 1;
5352 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
5353 /* device not in PCB table */
5354 rval = 3;
5355 }
5356
5357 return (rval);
5358}
5359
5360/*
5361 * qla2x00_loop_resync
5362 * Resync with fibre channel devices.
5363 *
5364 * Input:
5365 * ha = adapter block pointer.
5366 *
5367 * Returns:
5368 * 0 = success
5369 */
5370int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005371qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005372{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005373 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005374 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005375 struct req_que *req;
5376 struct rsp_que *rsp;
5377
Michael Hernandezd7459522016-12-12 14:40:07 -08005378 req = vha->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005379 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005380
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005381 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5382 if (vha->flags.online) {
5383 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005384 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5385 wait_time = 256;
5386 do {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005387 if (!IS_QLAFX00(vha->hw)) {
5388 /*
5389 * Issue a marker after FW becomes
5390 * ready.
5391 */
5392 qla2x00_marker(vha, req, rsp, 0, 0,
5393 MK_SYNC_ALL);
5394 vha->marker_needed = 0;
5395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005396
5397 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005398 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005399
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005400 if (IS_QLAFX00(vha->hw))
5401 qlafx00_configure_devices(vha);
5402 else
5403 qla2x00_configure_loop(vha);
5404
Linus Torvalds1da177e2005-04-16 15:20:36 -07005405 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005406 } while (!atomic_read(&vha->loop_down_timer) &&
5407 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5408 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
5409 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005410 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005411 }
5412
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005413 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005414 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005415
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005416 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005417 ql_dbg(ql_dbg_disc, vha, 0x206c,
5418 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005419
5420 return (rval);
5421}
5422
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005423/*
5424* qla2x00_perform_loop_resync
5425* Description: This function will set the appropriate flags and call
5426* qla2x00_loop_resync. If successful loop will be resynced
5427* Arguments : scsi_qla_host_t pointer
5428* returm : Success or Failure
5429*/
5430
5431int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
5432{
5433 int32_t rval = 0;
5434
5435 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
5436 /*Configure the flags so that resync happens properly*/
5437 atomic_set(&ha->loop_down_timer, 0);
5438 if (!(ha->device_flags & DFLG_NO_CABLE)) {
5439 atomic_set(&ha->loop_state, LOOP_UP);
5440 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
5441 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
5442 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
5443
5444 rval = qla2x00_loop_resync(ha);
5445 } else
5446 atomic_set(&ha->loop_state, LOOP_DEAD);
5447
5448 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
5449 }
5450
5451 return rval;
5452}
5453
Linus Torvalds1da177e2005-04-16 15:20:36 -07005454void
Andrew Vasquez67becc02009-08-25 11:36:20 -07005455qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005456{
5457 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07005458 struct scsi_qla_host *vha;
5459 struct qla_hw_data *ha = base_vha->hw;
5460 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005461
Arun Easifeafb7b2010-09-03 14:57:00 -07005462 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005463 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07005464 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
5465 atomic_inc(&vha->vref_count);
5466 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08005467 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07005468 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
5469 spin_unlock_irqrestore(&ha->vport_slock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07005470 qla2x00_rport_del(fcport);
Alexei Potashnikdf673272015-07-14 16:00:46 -04005471
Arun Easifeafb7b2010-09-03 14:57:00 -07005472 spin_lock_irqsave(&ha->vport_slock, flags);
5473 }
5474 }
5475 atomic_dec(&vha->vref_count);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07005476 wake_up(&vha->vref_waitq);
Arun Easifeafb7b2010-09-03 14:57:00 -07005477 }
5478 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005479}
5480
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005481/* Assumes idc_lock always held on entry */
5482void
5483qla83xx_reset_ownership(scsi_qla_host_t *vha)
5484{
5485 struct qla_hw_data *ha = vha->hw;
5486 uint32_t drv_presence, drv_presence_mask;
5487 uint32_t dev_part_info1, dev_part_info2, class_type;
5488 uint32_t class_type_mask = 0x3;
5489 uint16_t fcoe_other_function = 0xffff, i;
5490
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005491 if (IS_QLA8044(ha)) {
5492 drv_presence = qla8044_rd_direct(vha,
5493 QLA8044_CRB_DRV_ACTIVE_INDEX);
5494 dev_part_info1 = qla8044_rd_direct(vha,
5495 QLA8044_CRB_DEV_PART_INFO_INDEX);
5496 dev_part_info2 = qla8044_rd_direct(vha,
5497 QLA8044_CRB_DEV_PART_INFO2);
5498 } else {
5499 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5500 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
5501 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
5502 }
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005503 for (i = 0; i < 8; i++) {
5504 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
5505 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5506 (i != ha->portnum)) {
5507 fcoe_other_function = i;
5508 break;
5509 }
5510 }
5511 if (fcoe_other_function == 0xffff) {
5512 for (i = 0; i < 8; i++) {
5513 class_type = ((dev_part_info2 >> (i * 4)) &
5514 class_type_mask);
5515 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5516 ((i + 8) != ha->portnum)) {
5517 fcoe_other_function = i + 8;
5518 break;
5519 }
5520 }
5521 }
5522 /*
5523 * Prepare drv-presence mask based on fcoe functions present.
5524 * However consider only valid physical fcoe function numbers (0-15).
5525 */
5526 drv_presence_mask = ~((1 << (ha->portnum)) |
5527 ((fcoe_other_function == 0xffff) ?
5528 0 : (1 << (fcoe_other_function))));
5529
5530 /* We are the reset owner iff:
5531 * - No other protocol drivers present.
5532 * - This is the lowest among fcoe functions. */
5533 if (!(drv_presence & drv_presence_mask) &&
5534 (ha->portnum < fcoe_other_function)) {
5535 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
5536 "This host is Reset owner.\n");
5537 ha->flags.nic_core_reset_owner = 1;
5538 }
5539}
5540
Saurav Kashyapfa492632012-11-21 02:40:29 -05005541static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005542__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
5543{
5544 int rval = QLA_SUCCESS;
5545 struct qla_hw_data *ha = vha->hw;
5546 uint32_t drv_ack;
5547
5548 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5549 if (rval == QLA_SUCCESS) {
5550 drv_ack |= (1 << ha->portnum);
5551 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5552 }
5553
5554 return rval;
5555}
5556
Saurav Kashyapfa492632012-11-21 02:40:29 -05005557static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005558__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
5559{
5560 int rval = QLA_SUCCESS;
5561 struct qla_hw_data *ha = vha->hw;
5562 uint32_t drv_ack;
5563
5564 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5565 if (rval == QLA_SUCCESS) {
5566 drv_ack &= ~(1 << ha->portnum);
5567 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5568 }
5569
5570 return rval;
5571}
5572
Saurav Kashyapfa492632012-11-21 02:40:29 -05005573static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005574qla83xx_dev_state_to_string(uint32_t dev_state)
5575{
5576 switch (dev_state) {
5577 case QLA8XXX_DEV_COLD:
5578 return "COLD/RE-INIT";
5579 case QLA8XXX_DEV_INITIALIZING:
5580 return "INITIALIZING";
5581 case QLA8XXX_DEV_READY:
5582 return "READY";
5583 case QLA8XXX_DEV_NEED_RESET:
5584 return "NEED RESET";
5585 case QLA8XXX_DEV_NEED_QUIESCENT:
5586 return "NEED QUIESCENT";
5587 case QLA8XXX_DEV_FAILED:
5588 return "FAILED";
5589 case QLA8XXX_DEV_QUIESCENT:
5590 return "QUIESCENT";
5591 default:
5592 return "Unknown";
5593 }
5594}
5595
5596/* Assumes idc-lock always held on entry */
5597void
5598qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
5599{
5600 struct qla_hw_data *ha = vha->hw;
5601 uint32_t idc_audit_reg = 0, duration_secs = 0;
5602
5603 switch (audit_type) {
5604 case IDC_AUDIT_TIMESTAMP:
5605 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
5606 idc_audit_reg = (ha->portnum) |
5607 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
5608 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5609 break;
5610
5611 case IDC_AUDIT_COMPLETION:
5612 duration_secs = ((jiffies_to_msecs(jiffies) -
5613 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
5614 idc_audit_reg = (ha->portnum) |
5615 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
5616 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5617 break;
5618
5619 default:
5620 ql_log(ql_log_warn, vha, 0xb078,
5621 "Invalid audit type specified.\n");
5622 break;
5623 }
5624}
5625
5626/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05005627static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005628qla83xx_initiating_reset(scsi_qla_host_t *vha)
5629{
5630 struct qla_hw_data *ha = vha->hw;
5631 uint32_t idc_control, dev_state;
5632
5633 __qla83xx_get_idc_control(vha, &idc_control);
5634 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
5635 ql_log(ql_log_info, vha, 0xb080,
5636 "NIC Core reset has been disabled. idc-control=0x%x\n",
5637 idc_control);
5638 return QLA_FUNCTION_FAILED;
5639 }
5640
5641 /* Set NEED-RESET iff in READY state and we are the reset-owner */
5642 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5643 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
5644 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
5645 QLA8XXX_DEV_NEED_RESET);
5646 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
5647 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
5648 } else {
5649 const char *state = qla83xx_dev_state_to_string(dev_state);
5650 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
5651
5652 /* SV: XXX: Is timeout required here? */
5653 /* Wait for IDC state change READY -> NEED_RESET */
5654 while (dev_state == QLA8XXX_DEV_READY) {
5655 qla83xx_idc_unlock(vha, 0);
5656 msleep(200);
5657 qla83xx_idc_lock(vha, 0);
5658 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5659 }
5660 }
5661
5662 /* Send IDC ack by writing to drv-ack register */
5663 __qla83xx_set_drv_ack(vha);
5664
5665 return QLA_SUCCESS;
5666}
5667
5668int
5669__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
5670{
5671 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5672}
5673
5674int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005675__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
5676{
5677 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5678}
5679
Saurav Kashyapfa492632012-11-21 02:40:29 -05005680static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005681qla83xx_check_driver_presence(scsi_qla_host_t *vha)
5682{
5683 uint32_t drv_presence = 0;
5684 struct qla_hw_data *ha = vha->hw;
5685
5686 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5687 if (drv_presence & (1 << ha->portnum))
5688 return QLA_SUCCESS;
5689 else
5690 return QLA_TEST_FAILED;
5691}
5692
5693int
5694qla83xx_nic_core_reset(scsi_qla_host_t *vha)
5695{
5696 int rval = QLA_SUCCESS;
5697 struct qla_hw_data *ha = vha->hw;
5698
5699 ql_dbg(ql_dbg_p3p, vha, 0xb058,
5700 "Entered %s().\n", __func__);
5701
5702 if (vha->device_flags & DFLG_DEV_FAILED) {
5703 ql_log(ql_log_warn, vha, 0xb059,
5704 "Device in unrecoverable FAILED state.\n");
5705 return QLA_FUNCTION_FAILED;
5706 }
5707
5708 qla83xx_idc_lock(vha, 0);
5709
5710 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
5711 ql_log(ql_log_warn, vha, 0xb05a,
5712 "Function=0x%x has been removed from IDC participation.\n",
5713 ha->portnum);
5714 rval = QLA_FUNCTION_FAILED;
5715 goto exit;
5716 }
5717
5718 qla83xx_reset_ownership(vha);
5719
5720 rval = qla83xx_initiating_reset(vha);
5721
5722 /*
5723 * Perform reset if we are the reset-owner,
5724 * else wait till IDC state changes to READY/FAILED.
5725 */
5726 if (rval == QLA_SUCCESS) {
5727 rval = qla83xx_idc_state_handler(vha);
5728
5729 if (rval == QLA_SUCCESS)
5730 ha->flags.nic_core_hung = 0;
5731 __qla83xx_clear_drv_ack(vha);
5732 }
5733
5734exit:
5735 qla83xx_idc_unlock(vha, 0);
5736
5737 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
5738
5739 return rval;
5740}
5741
Saurav Kashyap81178772012-08-22 14:21:04 -04005742int
5743qla2xxx_mctp_dump(scsi_qla_host_t *vha)
5744{
5745 struct qla_hw_data *ha = vha->hw;
5746 int rval = QLA_FUNCTION_FAILED;
5747
5748 if (!IS_MCTP_CAPABLE(ha)) {
5749 /* This message can be removed from the final version */
5750 ql_log(ql_log_info, vha, 0x506d,
5751 "This board is not MCTP capable\n");
5752 return rval;
5753 }
5754
5755 if (!ha->mctp_dump) {
5756 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
5757 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
5758
5759 if (!ha->mctp_dump) {
5760 ql_log(ql_log_warn, vha, 0x506e,
5761 "Failed to allocate memory for mctp dump\n");
5762 return rval;
5763 }
5764 }
5765
5766#define MCTP_DUMP_STR_ADDR 0x00000000
5767 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
5768 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
5769 if (rval != QLA_SUCCESS) {
5770 ql_log(ql_log_warn, vha, 0x506f,
5771 "Failed to capture mctp dump\n");
5772 } else {
5773 ql_log(ql_log_info, vha, 0x5070,
5774 "Mctp dump capture for host (%ld/%p).\n",
5775 vha->host_no, ha->mctp_dump);
5776 ha->mctp_dumped = 1;
5777 }
5778
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04005779 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04005780 ha->flags.nic_core_reset_hdlr_active = 1;
5781 rval = qla83xx_restart_nic_firmware(vha);
5782 if (rval)
5783 /* NIC Core reset failed. */
5784 ql_log(ql_log_warn, vha, 0x5071,
5785 "Failed to restart nic firmware\n");
5786 else
5787 ql_dbg(ql_dbg_p3p, vha, 0xb084,
5788 "Restarted NIC firmware successfully.\n");
5789 ha->flags.nic_core_reset_hdlr_active = 0;
5790 }
5791
5792 return rval;
5793
5794}
5795
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005796/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005797* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005798* Description: This function will block the new I/Os
5799* Its not aborting any I/Os as context
5800* is not destroyed during quiescence
5801* Arguments: scsi_qla_host_t
5802* return : void
5803*/
5804void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005805qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005806{
5807 struct qla_hw_data *ha = vha->hw;
5808 struct scsi_qla_host *vp;
5809
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005810 ql_dbg(ql_dbg_dpc, vha, 0x401d,
5811 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005812
5813 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
5814 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
5815 atomic_set(&vha->loop_state, LOOP_DOWN);
5816 qla2x00_mark_all_devices_lost(vha, 0);
5817 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005818 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005819 } else {
5820 if (!atomic_read(&vha->loop_down_timer))
5821 atomic_set(&vha->loop_down_timer,
5822 LOOP_DOWN_TIME);
5823 }
5824 /* Wait for pending cmds to complete */
5825 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
5826}
5827
Giridhar Malavalia9083012010-04-12 17:59:55 -07005828void
5829qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
5830{
5831 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005832 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005833 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08005834 fc_port_t *fcport;
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07005835 u16 i;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005836
Saurav Kashyape46ef002011-02-23 15:27:16 -08005837 /* For ISP82XX, driver waits for completion of the commands.
5838 * online flag should be set.
5839 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005840 if (!(IS_P3P_TYPE(ha)))
Saurav Kashyape46ef002011-02-23 15:27:16 -08005841 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005842 ha->flags.chip_reset_done = 0;
5843 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04005844 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005845
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005846 ql_log(ql_log_info, vha, 0x00af,
5847 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005848
Saurav Kashyape46ef002011-02-23 15:27:16 -08005849 /* For ISP82XX, reset_chip is just disabling interrupts.
5850 * Driver waits for the completion of the commands.
5851 * the interrupts need to be enabled.
5852 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005853 if (!(IS_P3P_TYPE(ha)))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005854 ha->isp_ops->reset_chip(vha);
5855
Quinn Tranec7193e2017-03-15 09:48:55 -07005856 ha->flags.n2n_ae = 0;
5857 ha->flags.lip_ae = 0;
5858 ha->current_topology = 0;
5859 ha->flags.fw_started = 0;
5860 ha->flags.fw_init_done = 0;
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07005861 ha->base_qpair->chip_reset++;
5862 for (i = 0; i < ha->max_qpairs; i++) {
5863 if (ha->queue_pair_map[i])
5864 ha->queue_pair_map[i]->chip_reset =
5865 ha->base_qpair->chip_reset;
5866 }
Quinn Tran726b8542017-01-19 22:28:00 -08005867
Giridhar Malavalia9083012010-04-12 17:59:55 -07005868 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
5869 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
5870 atomic_set(&vha->loop_state, LOOP_DOWN);
5871 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07005872
5873 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005874 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07005875 atomic_inc(&vp->vref_count);
5876 spin_unlock_irqrestore(&ha->vport_slock, flags);
5877
Giridhar Malavalia9083012010-04-12 17:59:55 -07005878 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07005879
5880 spin_lock_irqsave(&ha->vport_slock, flags);
5881 atomic_dec(&vp->vref_count);
5882 }
5883 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005884 } else {
5885 if (!atomic_read(&vha->loop_down_timer))
5886 atomic_set(&vha->loop_down_timer,
5887 LOOP_DOWN_TIME);
5888 }
5889
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08005890 /* Clear all async request states across all VPs. */
5891 list_for_each_entry(fcport, &vha->vp_fcports, list)
5892 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5893 spin_lock_irqsave(&ha->vport_slock, flags);
5894 list_for_each_entry(vp, &ha->vp_list, list) {
5895 atomic_inc(&vp->vref_count);
5896 spin_unlock_irqrestore(&ha->vport_slock, flags);
5897
5898 list_for_each_entry(fcport, &vp->vp_fcports, list)
5899 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5900
5901 spin_lock_irqsave(&ha->vport_slock, flags);
5902 atomic_dec(&vp->vref_count);
5903 }
5904 spin_unlock_irqrestore(&ha->vport_slock, flags);
5905
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005906 if (!ha->flags.eeh_busy) {
5907 /* Make sure for ISP 82XX IO DMA is complete */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005908 if (IS_P3P_TYPE(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005909 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005910 ql_log(ql_log_info, vha, 0x00b4,
5911 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005912
Saurav Kashyape46ef002011-02-23 15:27:16 -08005913 /* Done waiting for pending commands.
5914 * Reset the online flag.
5915 */
5916 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005917 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005918
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005919 /* Requeue all commands in outstanding command list. */
5920 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
5921 }
Arun Easib6a029e2014-09-25 06:14:52 -04005922 /* memory barrier */
5923 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005924}
5925
5926/*
5927* qla2x00_abort_isp
5928* Resets ISP and aborts all outstanding commands.
5929*
5930* Input:
5931* ha = adapter block pointer.
5932*
5933* Returns:
5934* 0 = success
5935*/
5936int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005937qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005938{
Andrew Vasquez476e8972006-08-23 14:54:55 -07005939 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005941 struct qla_hw_data *ha = vha->hw;
5942 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005943 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07005944 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005945
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005946 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07005947 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005948
Santosh Vernekara61712972012-08-22 14:21:13 -04005949 if (IS_QLA8031(ha)) {
5950 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
5951 "Clearing fcoe driver presence.\n");
5952 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
5953 ql_dbg(ql_dbg_p3p, vha, 0xb073,
5954 "Error while clearing DRV-Presence.\n");
5955 }
5956
Andrew Vasquez85880802009-12-15 21:29:46 -08005957 if (unlikely(pci_channel_offline(ha->pdev) &&
5958 ha->flags.pci_channel_io_perm_failure)) {
5959 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5960 status = 0;
5961 return status;
5962 }
5963
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005964 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08005965
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005966 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005967
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005968 if (!qla2x00_restart_isp(vha)) {
5969 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005970
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005971 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005972 /*
5973 * Issue marker command only when we are going
5974 * to start the I/O .
5975 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005976 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005977 }
5978
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005979 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005980
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005981 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005982
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07005983 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005984 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07005985
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005986 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
5987 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08005988 if (ha->fce) {
5989 ha->flags.fce_enabled = 1;
5990 memset(ha->fce, 0,
5991 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005992 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08005993 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5994 &ha->fce_bufs);
5995 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005996 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08005997 "Unable to reinitialize FCE "
5998 "(%d).\n", rval);
5999 ha->flags.fce_enabled = 0;
6000 }
6001 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006002
6003 if (ha->eft) {
6004 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006005 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006006 ha->eft_dma, EFT_NUM_BUFFERS);
6007 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006008 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07006009 "Unable to reinitialize EFT "
6010 "(%d).\n", rval);
6011 }
6012 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006014 vha->flags.online = 1;
6015 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006016 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006017 ql_log(ql_log_fatal, vha, 0x8035,
6018 "ISP error recover failed - "
6019 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07006020 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006021 * The next call disables the board
6022 * completely.
6023 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006024 ha->isp_ops->reset_adapter(vha);
6025 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006026 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006027 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006028 status = 0;
6029 } else { /* schedule another ISP abort */
6030 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006031 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6032 "ISP abort - retry remaining %d.\n",
6033 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006034 status = 1;
6035 }
6036 } else {
6037 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006038 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6039 "ISP error recovery - retrying (%d) "
6040 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006041 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006042 status = 1;
6043 }
6044 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07006045
Linus Torvalds1da177e2005-04-16 15:20:36 -07006046 }
6047
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006048 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006049 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Quinn Tran1608cc42017-08-23 15:05:03 -07006050 qla2x00_configure_hba(vha);
Arun Easifeafb7b2010-09-03 14:57:00 -07006051 spin_lock_irqsave(&ha->vport_slock, flags);
6052 list_for_each_entry(vp, &ha->vp_list, list) {
6053 if (vp->vp_idx) {
6054 atomic_inc(&vp->vref_count);
6055 spin_unlock_irqrestore(&ha->vport_slock, flags);
6056
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006057 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07006058
6059 spin_lock_irqsave(&ha->vport_slock, flags);
6060 atomic_dec(&vp->vref_count);
6061 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006062 }
Arun Easifeafb7b2010-09-03 14:57:00 -07006063 spin_unlock_irqrestore(&ha->vport_slock, flags);
6064
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006065 if (IS_QLA8031(ha)) {
6066 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6067 "Setting back fcoe driver presence.\n");
6068 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6069 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6070 "Error while setting DRV-Presence.\n");
6071 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006072 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08006073 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6074 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006075 }
6076
6077 return(status);
6078}
6079
6080/*
6081* qla2x00_restart_isp
6082* restarts the ISP after a reset
6083*
6084* Input:
6085* ha = adapter block pointer.
6086*
6087* Returns:
6088* 0 = success
6089*/
6090static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006091qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006092{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08006093 int status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006094 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006095 struct req_que *req = ha->req_q_map[0];
6096 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07006097
6098 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006099 if (qla2x00_isp_firmware(vha)) {
6100 vha->flags.online = 0;
6101 status = ha->isp_ops->chip_diag(vha);
6102 if (!status)
6103 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006104 }
6105
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006106 if (!status && !(status = qla2x00_init_rings(vha))) {
6107 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07006108 ha->flags.chip_reset_done = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04006109
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006110 /* Initialize the queues in use */
6111 qla25xx_init_queues(ha);
6112
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006113 status = qla2x00_fw_ready(vha);
6114 if (!status) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006115 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006116 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Chad Dupuis7108b762014-04-11 16:54:45 -04006117 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006118 }
6119
6120 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006121 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07006122 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006123 }
6124 return (status);
6125}
6126
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006127static int
6128qla25xx_init_queues(struct qla_hw_data *ha)
6129{
6130 struct rsp_que *rsp = NULL;
6131 struct req_que *req = NULL;
6132 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6133 int ret = -1;
6134 int i;
6135
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07006136 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006137 rsp = ha->rsp_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05006138 if (rsp && test_bit(i, ha->rsp_qid_map)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006139 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08006140 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006141 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006142 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6143 "%s Rsp que: %d init failed.\n",
6144 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006145 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006146 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6147 "%s Rsp que: %d inited.\n",
6148 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006149 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07006150 }
6151 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006152 req = ha->req_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05006153 if (req && test_bit(i, ha->req_qid_map)) {
6154 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006155 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08006156 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006157 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006158 ql_dbg(ql_dbg_init, base_vha, 0x0101,
6159 "%s Req que: %d init failed.\n",
6160 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006161 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006162 ql_dbg(ql_dbg_init, base_vha, 0x0102,
6163 "%s Req que: %d inited.\n",
6164 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006165 }
6166 }
6167 return ret;
6168}
6169
Linus Torvalds1da177e2005-04-16 15:20:36 -07006170/*
6171* qla2x00_reset_adapter
6172* Reset adapter.
6173*
6174* Input:
6175* ha = adapter block pointer.
6176*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07006177void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006178qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006179{
6180 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006181 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07006182 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006184 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006185 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006186
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187 spin_lock_irqsave(&ha->hardware_lock, flags);
6188 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
6189 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
6190 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
6191 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
6192 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6193}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006194
6195void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006196qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006197{
6198 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006199 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006200 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
6201
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006202 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07006203 return;
6204
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006205 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07006206 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006207
6208 spin_lock_irqsave(&ha->hardware_lock, flags);
6209 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
6210 RD_REG_DWORD(&reg->hccr);
6211 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
6212 RD_REG_DWORD(&reg->hccr);
6213 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08006214
6215 if (IS_NOPOLLING_TYPE(ha))
6216 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006217}
6218
David Miller4e08df32007-04-16 12:37:43 -07006219/* On sparc systems, obtain port and node WWN from firmware
6220 * properties.
6221 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006222static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
6223 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07006224{
6225#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006226 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07006227 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07006228 struct device_node *dp = pci_device_to_OF_node(pdev);
6229 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07006230 int len;
6231
6232 val = of_get_property(dp, "port-wwn", &len);
6233 if (val && len >= WWN_SIZE)
6234 memcpy(nv->port_name, val, WWN_SIZE);
6235
6236 val = of_get_property(dp, "node-wwn", &len);
6237 if (val && len >= WWN_SIZE)
6238 memcpy(nv->node_name, val, WWN_SIZE);
6239#endif
6240}
6241
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006242int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006243qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006244{
David Miller4e08df32007-04-16 12:37:43 -07006245 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006246 struct init_cb_24xx *icb;
6247 struct nvram_24xx *nv;
6248 uint32_t *dptr;
6249 uint8_t *dptr1, *dptr2;
6250 uint32_t chksum;
6251 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006252 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006253
David Miller4e08df32007-04-16 12:37:43 -07006254 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006255 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07006256 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006257
6258 /* Determine NVRAM starting address. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05006259 if (ha->port_no == 0) {
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07006260 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
6261 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
6262 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006263 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08006264 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
6265 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05006266
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07006267 ha->nvram_size = sizeof(struct nvram_24xx);
6268 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006269
Seokmann Ju281afe12007-07-26 13:43:34 -07006270 /* Get VPD data into cache */
6271 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006272 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07006273 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
6274
6275 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006276 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006277 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006278 ha->nvram_size);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006279 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
6280 chksum += le32_to_cpu(*dptr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006281
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006282 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
6283 "Contents of NVRAM\n");
6284 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
6285 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006286
6287 /* Bad NVRAM data, set defaults parameters. */
6288 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6289 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07006290 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006291 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006292 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04006293 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006294 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
6295 ql_log(ql_log_warn, vha, 0x006c,
6296 "Falling back to functioning (yet invalid -- WWPN) "
6297 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07006298
6299 /*
6300 * Set default initialization control block.
6301 */
6302 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07006303 nv->nvram_version = cpu_to_le16(ICB_VERSION);
6304 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04006305 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07006306 nv->execution_throttle = cpu_to_le16(0xFFFF);
6307 nv->exchange_count = cpu_to_le16(0);
6308 nv->hard_address = cpu_to_le16(124);
David Miller4e08df32007-04-16 12:37:43 -07006309 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006310 nv->port_name[1] = 0x00 + ha->port_no + 1;
David Miller4e08df32007-04-16 12:37:43 -07006311 nv->port_name[2] = 0x00;
6312 nv->port_name[3] = 0xe0;
6313 nv->port_name[4] = 0x8b;
6314 nv->port_name[5] = 0x1c;
6315 nv->port_name[6] = 0x55;
6316 nv->port_name[7] = 0x86;
6317 nv->node_name[0] = 0x20;
6318 nv->node_name[1] = 0x00;
6319 nv->node_name[2] = 0x00;
6320 nv->node_name[3] = 0xe0;
6321 nv->node_name[4] = 0x8b;
6322 nv->node_name[5] = 0x1c;
6323 nv->node_name[6] = 0x55;
6324 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006325 qla24xx_nvram_wwn_from_ofw(vha, nv);
Bart Van Asschead950362015-07-09 07:24:08 -07006326 nv->login_retry_count = cpu_to_le16(8);
6327 nv->interrupt_delay_timer = cpu_to_le16(0);
6328 nv->login_timeout = cpu_to_le16(0);
David Miller4e08df32007-04-16 12:37:43 -07006329 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07006330 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6331 nv->firmware_options_2 = cpu_to_le32(2 << 4);
6332 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6333 nv->firmware_options_3 = cpu_to_le32(2 << 13);
6334 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6335 nv->efi_parameters = cpu_to_le32(0);
David Miller4e08df32007-04-16 12:37:43 -07006336 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07006337 nv->max_luns_per_target = cpu_to_le16(128);
6338 nv->port_down_retry_count = cpu_to_le16(30);
6339 nv->link_down_timeout = cpu_to_le16(30);
David Miller4e08df32007-04-16 12:37:43 -07006340
6341 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006342 }
6343
Quinn Tran726b8542017-01-19 22:28:00 -08006344 if (qla_tgt_mode_enabled(vha)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006345 /* Don't enable full login after initial LIP */
Bart Van Asschead950362015-07-09 07:24:08 -07006346 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006347 /* Don't enable LIP full login for initiator */
Bart Van Asschead950362015-07-09 07:24:08 -07006348 nv->host_p &= cpu_to_le32(~BIT_10);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006349 }
6350
6351 qlt_24xx_config_nvram_stage1(vha, nv);
6352
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006353 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006354 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006355
6356 /* Copy 1st segment. */
6357 dptr1 = (uint8_t *)icb;
6358 dptr2 = (uint8_t *)&nv->version;
6359 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6360 while (cnt--)
6361 *dptr1++ = *dptr2++;
6362
6363 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07006364 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006365
6366 /* Copy 2nd segment. */
6367 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6368 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6369 cnt = (uint8_t *)&icb->reserved_3 -
6370 (uint8_t *)&icb->interrupt_delay_timer;
6371 while (cnt--)
6372 *dptr1++ = *dptr2++;
6373
6374 /*
6375 * Setup driver NVRAM options.
6376 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006377 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08006378 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006379
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006380 qlt_24xx_config_nvram_stage2(vha, icb);
6381
Bart Van Asschead950362015-07-09 07:24:08 -07006382 if (nv->host_p & cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006383 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07006384 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6385 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6386 }
6387
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006388 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07006389 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006390 /*
6391 * Firmware will apply the following mask if the nodename was
6392 * not provided.
6393 */
6394 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6395 icb->node_name[0] &= 0xF0;
6396 }
6397
6398 /* Set host adapter parameters. */
6399 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08006400 ha->flags.enable_lip_reset = 0;
6401 ha->flags.enable_lip_full_login =
6402 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6403 ha->flags.enable_target_reset =
6404 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006405 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07006406 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006407
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07006408 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6409 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006410
6411 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
6412 sizeof(ha->fw_seriallink_options24));
6413
6414 /* save HBA serial number */
6415 ha->serial0 = icb->port_name[5];
6416 ha->serial1 = icb->port_name[6];
6417 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006418 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6419 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006420
Bart Van Asschead950362015-07-09 07:24:08 -07006421 icb->execution_throttle = cpu_to_le16(0xFFFF);
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08006422
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006423 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6424
6425 /* Set minimum login_timeout to 4 seconds. */
6426 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6427 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6428 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07006429 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006430 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006431
Andrew Vasquez00a537b2008-02-28 14:06:11 -08006432 /* Set minimum RATOV to 100 tenths of a second. */
6433 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006434
6435 ha->loop_reset_delay = nv->reset_delay;
6436
6437 /* Link Down Timeout = 0:
6438 *
6439 * When Port Down timer expires we will start returning
6440 * I/O's to OS with "DID_NO_CONNECT".
6441 *
6442 * Link Down Timeout != 0:
6443 *
6444 * The driver waits for the link to come up after link down
6445 * before returning I/Os to OS with "DID_NO_CONNECT".
6446 */
6447 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6448 ha->loop_down_abort_time =
6449 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6450 } else {
6451 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6452 ha->loop_down_abort_time =
6453 (LOOP_DOWN_TIME - ha->link_down_timeout);
6454 }
6455
6456 /* Need enough time to try and get the port back. */
6457 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6458 if (qlport_down_retry)
6459 ha->port_down_retry_count = qlport_down_retry;
6460
6461 /* Set login_retry_count */
6462 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6463 if (ha->port_down_retry_count ==
6464 le16_to_cpu(nv->port_down_retry_count) &&
6465 ha->port_down_retry_count > 3)
6466 ha->login_retry_count = ha->port_down_retry_count;
6467 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6468 ha->login_retry_count = ha->port_down_retry_count;
6469 if (ql2xloginretrycount)
6470 ha->login_retry_count = ql2xloginretrycount;
6471
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006472 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006473 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006474 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6475 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6476 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6477 le16_to_cpu(icb->interrupt_delay_timer): 2;
6478 }
Bart Van Asschead950362015-07-09 07:24:08 -07006479 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006480 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006481 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006482 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08006483 ha->zio_mode = QLA_ZIO_MODE_6;
6484
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006485 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006486 "ZIO mode %d enabled; timer delay (%d us).\n",
6487 ha->zio_mode, ha->zio_timer * 100);
6488
6489 icb->firmware_options_2 |= cpu_to_le32(
6490 (uint32_t)ha->zio_mode);
6491 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006492 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006493 }
6494
David Miller4e08df32007-04-16 12:37:43 -07006495 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006496 ql_log(ql_log_warn, vha, 0x0070,
6497 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07006498 }
6499 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006500}
6501
Sawan Chandak4243c112016-01-27 12:03:31 -05006502uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
6503{
6504 struct qla27xx_image_status pri_image_status, sec_image_status;
6505 uint8_t valid_pri_image, valid_sec_image;
6506 uint32_t *wptr;
6507 uint32_t cnt, chksum, size;
6508 struct qla_hw_data *ha = vha->hw;
6509
6510 valid_pri_image = valid_sec_image = 1;
6511 ha->active_image = 0;
6512 size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
6513
6514 if (!ha->flt_region_img_status_pri) {
6515 valid_pri_image = 0;
6516 goto check_sec_image;
6517 }
6518
6519 qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
6520 ha->flt_region_img_status_pri, size);
6521
6522 if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6523 ql_dbg(ql_dbg_init, vha, 0x018b,
6524 "Primary image signature (0x%x) not valid\n",
6525 pri_image_status.signature);
6526 valid_pri_image = 0;
6527 goto check_sec_image;
6528 }
6529
6530 wptr = (uint32_t *)(&pri_image_status);
6531 cnt = size;
6532
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006533 for (chksum = 0; cnt--; wptr++)
6534 chksum += le32_to_cpu(*wptr);
Quinn Tran41dc5292017-01-19 22:28:03 -08006535
Sawan Chandak4243c112016-01-27 12:03:31 -05006536 if (chksum) {
6537 ql_dbg(ql_dbg_init, vha, 0x018c,
6538 "Checksum validation failed for primary image (0x%x)\n",
6539 chksum);
6540 valid_pri_image = 0;
6541 }
6542
6543check_sec_image:
6544 if (!ha->flt_region_img_status_sec) {
6545 valid_sec_image = 0;
6546 goto check_valid_image;
6547 }
6548
6549 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
6550 ha->flt_region_img_status_sec, size);
6551
6552 if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6553 ql_dbg(ql_dbg_init, vha, 0x018d,
6554 "Secondary image signature(0x%x) not valid\n",
6555 sec_image_status.signature);
6556 valid_sec_image = 0;
6557 goto check_valid_image;
6558 }
6559
6560 wptr = (uint32_t *)(&sec_image_status);
6561 cnt = size;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006562 for (chksum = 0; cnt--; wptr++)
6563 chksum += le32_to_cpu(*wptr);
Sawan Chandak4243c112016-01-27 12:03:31 -05006564 if (chksum) {
6565 ql_dbg(ql_dbg_init, vha, 0x018e,
6566 "Checksum validation failed for secondary image (0x%x)\n",
6567 chksum);
6568 valid_sec_image = 0;
6569 }
6570
6571check_valid_image:
6572 if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
6573 ha->active_image = QLA27XX_PRIMARY_IMAGE;
6574 if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
6575 if (!ha->active_image ||
6576 pri_image_status.generation_number <
6577 sec_image_status.generation_number)
6578 ha->active_image = QLA27XX_SECONDARY_IMAGE;
6579 }
6580
6581 ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n",
6582 ha->active_image == 0 ? "default bootld and fw" :
6583 ha->active_image == 1 ? "primary" :
6584 ha->active_image == 2 ? "secondary" :
6585 "Invalid");
6586
6587 return ha->active_image;
6588}
6589
Adrian Bunk413975a2006-06-30 02:33:06 -07006590static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006591qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
6592 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006593{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006594 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006595 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006596 uint32_t *dcode, dlen;
6597 uint32_t risc_addr;
6598 uint32_t risc_size;
6599 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006600 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006601 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006602
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006603 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006604 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006605
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006606 rval = QLA_SUCCESS;
6607
6608 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006609 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006610 *srisc_addr = 0;
6611
Sawan Chandak4243c112016-01-27 12:03:31 -05006612 if (IS_QLA27XX(ha) &&
6613 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
6614 faddr = ha->flt_region_fw_sec;
6615
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006616 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006617 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006618 for (i = 0; i < 4; i++)
6619 dcode[i] = be32_to_cpu(dcode[i]);
6620 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
6621 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
6622 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
6623 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006624 ql_log(ql_log_fatal, vha, 0x008c,
6625 "Unable to verify the integrity of flash firmware "
6626 "image.\n");
6627 ql_log(ql_log_fatal, vha, 0x008d,
6628 "Firmware data: %08x %08x %08x %08x.\n",
6629 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006630
6631 return QLA_FUNCTION_FAILED;
6632 }
6633
6634 while (segments && rval == QLA_SUCCESS) {
6635 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006636 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006637
6638 risc_addr = be32_to_cpu(dcode[2]);
6639 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
6640 risc_size = be32_to_cpu(dcode[3]);
6641
6642 fragment = 0;
6643 while (risc_size > 0 && rval == QLA_SUCCESS) {
6644 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
6645 if (dlen > risc_size)
6646 dlen = risc_size;
6647
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006648 ql_dbg(ql_dbg_init, vha, 0x008e,
6649 "Loading risc segment@ risc addr %x "
6650 "number of dwords 0x%x offset 0x%x.\n",
6651 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006652
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006653 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006654 for (i = 0; i < dlen; i++)
6655 dcode[i] = swab32(dcode[i]);
6656
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006657 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006658 dlen);
6659 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006660 ql_log(ql_log_fatal, vha, 0x008f,
6661 "Failed to load segment %d of firmware.\n",
6662 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04006663 return QLA_FUNCTION_FAILED;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006664 }
6665
6666 faddr += dlen;
6667 risc_addr += dlen;
6668 risc_size -= dlen;
6669 fragment++;
6670 }
6671
6672 /* Next segment. */
6673 segments--;
6674 }
6675
Chad Dupuisf73cb692014-02-26 04:15:06 -05006676 if (!IS_QLA27XX(ha))
6677 return rval;
6678
6679 if (ha->fw_dump_template)
6680 vfree(ha->fw_dump_template);
6681 ha->fw_dump_template = NULL;
6682 ha->fw_dump_template_len = 0;
6683
6684 ql_dbg(ql_dbg_init, vha, 0x0161,
6685 "Loading fwdump template from %x\n", faddr);
6686 qla24xx_read_flash_data(vha, dcode, faddr, 7);
6687 risc_size = be32_to_cpu(dcode[2]);
6688 ql_dbg(ql_dbg_init, vha, 0x0162,
6689 "-> array size %x dwords\n", risc_size);
6690 if (risc_size == 0 || risc_size == ~0)
6691 goto default_template;
6692
6693 dlen = (risc_size - 8) * sizeof(*dcode);
6694 ql_dbg(ql_dbg_init, vha, 0x0163,
6695 "-> template allocating %x bytes...\n", dlen);
6696 ha->fw_dump_template = vmalloc(dlen);
6697 if (!ha->fw_dump_template) {
6698 ql_log(ql_log_warn, vha, 0x0164,
6699 "Failed fwdump template allocate %x bytes.\n", risc_size);
6700 goto default_template;
6701 }
6702
6703 faddr += 7;
6704 risc_size -= 8;
6705 dcode = ha->fw_dump_template;
6706 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
6707 for (i = 0; i < risc_size; i++)
6708 dcode[i] = le32_to_cpu(dcode[i]);
6709
6710 if (!qla27xx_fwdt_template_valid(dcode)) {
6711 ql_log(ql_log_warn, vha, 0x0165,
6712 "Failed fwdump template validate\n");
6713 goto default_template;
6714 }
6715
6716 dlen = qla27xx_fwdt_template_size(dcode);
6717 ql_dbg(ql_dbg_init, vha, 0x0166,
6718 "-> template size %x bytes\n", dlen);
6719 if (dlen > risc_size * sizeof(*dcode)) {
6720 ql_log(ql_log_warn, vha, 0x0167,
Himanshu Madhani4fae52b2017-06-06 13:55:23 -07006721 "Failed fwdump template exceeds array by %zx bytes\n",
Joe Carnuccio383a2982017-06-02 09:11:55 -07006722 (size_t)(dlen - risc_size * sizeof(*dcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05006723 goto default_template;
6724 }
6725 ha->fw_dump_template_len = dlen;
6726 return rval;
6727
6728default_template:
6729 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
6730 if (ha->fw_dump_template)
6731 vfree(ha->fw_dump_template);
6732 ha->fw_dump_template = NULL;
6733 ha->fw_dump_template_len = 0;
6734
6735 dlen = qla27xx_fwdt_template_default_size();
6736 ql_dbg(ql_dbg_init, vha, 0x0169,
6737 "-> template allocating %x bytes...\n", dlen);
6738 ha->fw_dump_template = vmalloc(dlen);
6739 if (!ha->fw_dump_template) {
6740 ql_log(ql_log_warn, vha, 0x016a,
6741 "Failed fwdump template allocate %x bytes.\n", risc_size);
6742 goto failed_template;
6743 }
6744
6745 dcode = ha->fw_dump_template;
6746 risc_size = dlen / sizeof(*dcode);
6747 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
6748 for (i = 0; i < risc_size; i++)
6749 dcode[i] = be32_to_cpu(dcode[i]);
6750
6751 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
6752 ql_log(ql_log_warn, vha, 0x016b,
6753 "Failed fwdump template validate\n");
6754 goto failed_template;
6755 }
6756
6757 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
6758 ql_dbg(ql_dbg_init, vha, 0x016c,
6759 "-> template size %x bytes\n", dlen);
6760 ha->fw_dump_template_len = dlen;
6761 return rval;
6762
6763failed_template:
6764 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
6765 if (ha->fw_dump_template)
6766 vfree(ha->fw_dump_template);
6767 ha->fw_dump_template = NULL;
6768 ha->fw_dump_template_len = 0;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006769 return rval;
6770}
6771
Giridhar Malavalie9454a82013-02-08 01:57:47 -05006772#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006773
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006774int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006775qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08006776{
6777 int rval;
6778 int i, fragment;
6779 uint16_t *wcode, *fwcode;
6780 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
6781 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006782 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006783 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08006784
6785 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006786 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08006787 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006788 ql_log(ql_log_info, vha, 0x0083,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01006789 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006790 ql_log(ql_log_info, vha, 0x0084,
6791 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08006792 return QLA_FUNCTION_FAILED;
6793 }
6794
6795 rval = QLA_SUCCESS;
6796
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006797 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08006798 *srisc_addr = 0;
6799 fwcode = (uint16_t *)blob->fw->data;
6800 fwclen = 0;
6801
6802 /* Validate firmware image by checking version. */
6803 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006804 ql_log(ql_log_fatal, vha, 0x0085,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006805 "Unable to verify integrity of firmware image (%zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08006806 blob->fw->size);
6807 goto fail_fw_integrity;
6808 }
6809 for (i = 0; i < 4; i++)
6810 wcode[i] = be16_to_cpu(fwcode[i + 4]);
6811 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
6812 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
6813 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006814 ql_log(ql_log_fatal, vha, 0x0086,
6815 "Unable to verify integrity of firmware image.\n");
6816 ql_log(ql_log_fatal, vha, 0x0087,
6817 "Firmware data: %04x %04x %04x %04x.\n",
6818 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08006819 goto fail_fw_integrity;
6820 }
6821
6822 seg = blob->segs;
6823 while (*seg && rval == QLA_SUCCESS) {
6824 risc_addr = *seg;
6825 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
6826 risc_size = be16_to_cpu(fwcode[3]);
6827
6828 /* Validate firmware image size. */
6829 fwclen += risc_size * sizeof(uint16_t);
6830 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006831 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08006832 "Unable to verify integrity of firmware image "
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006833 "(%zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08006834 goto fail_fw_integrity;
6835 }
6836
6837 fragment = 0;
6838 while (risc_size > 0 && rval == QLA_SUCCESS) {
6839 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
6840 if (wlen > risc_size)
6841 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006842 ql_dbg(ql_dbg_init, vha, 0x0089,
6843 "Loading risc segment@ risc addr %x number of "
6844 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08006845
6846 for (i = 0; i < wlen; i++)
6847 wcode[i] = swab16(fwcode[i]);
6848
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006849 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08006850 wlen);
6851 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006852 ql_log(ql_log_fatal, vha, 0x008a,
6853 "Failed to load segment %d of firmware.\n",
6854 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08006855 break;
6856 }
6857
6858 fwcode += wlen;
6859 risc_addr += wlen;
6860 risc_size -= wlen;
6861 fragment++;
6862 }
6863
6864 /* Next segment. */
6865 seg++;
6866 }
6867 return rval;
6868
6869fail_fw_integrity:
6870 return QLA_FUNCTION_FAILED;
6871}
6872
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006873static int
6874qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006875{
6876 int rval;
6877 int segments, fragment;
6878 uint32_t *dcode, dlen;
6879 uint32_t risc_addr;
6880 uint32_t risc_size;
6881 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08006882 struct fw_blob *blob;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006883 const uint32_t *fwcode;
6884 uint32_t fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006885 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006886 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006887
Andrew Vasquez54333832005-11-09 15:49:04 -08006888 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006889 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08006890 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006891 ql_log(ql_log_warn, vha, 0x0090,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01006892 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006893 ql_log(ql_log_warn, vha, 0x0091,
6894 "Firmware images can be retrieved from: "
6895 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006896
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006897 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006898 }
6899
Chad Dupuiscfb09192011-11-18 09:03:07 -08006900 ql_dbg(ql_dbg_init, vha, 0x0092,
6901 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006902
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006903 rval = QLA_SUCCESS;
6904
6905 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006906 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006907 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08006908 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006909 fwclen = 0;
6910
6911 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08006912 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006913 ql_log(ql_log_fatal, vha, 0x0093,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006914 "Unable to verify integrity of firmware image (%zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08006915 blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05006916 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006917 }
6918 for (i = 0; i < 4; i++)
6919 dcode[i] = be32_to_cpu(fwcode[i + 4]);
6920 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
6921 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
6922 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
6923 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006924 ql_log(ql_log_fatal, vha, 0x0094,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006925 "Unable to verify integrity of firmware image (%zd).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006926 blob->fw->size);
6927 ql_log(ql_log_fatal, vha, 0x0095,
6928 "Firmware data: %08x %08x %08x %08x.\n",
6929 dcode[0], dcode[1], dcode[2], dcode[3]);
Chad Dupuisf73cb692014-02-26 04:15:06 -05006930 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006931 }
6932
6933 while (segments && rval == QLA_SUCCESS) {
6934 risc_addr = be32_to_cpu(fwcode[2]);
6935 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
6936 risc_size = be32_to_cpu(fwcode[3]);
6937
6938 /* Validate firmware image size. */
6939 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08006940 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006941 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08006942 "Unable to verify integrity of firmware image "
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006943 "(%zd).\n", blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05006944 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006945 }
6946
6947 fragment = 0;
6948 while (risc_size > 0 && rval == QLA_SUCCESS) {
6949 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
6950 if (dlen > risc_size)
6951 dlen = risc_size;
6952
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006953 ql_dbg(ql_dbg_init, vha, 0x0097,
6954 "Loading risc segment@ risc addr %x "
6955 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006956
6957 for (i = 0; i < dlen; i++)
6958 dcode[i] = swab32(fwcode[i]);
6959
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006960 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08006961 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006962 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006963 ql_log(ql_log_fatal, vha, 0x0098,
6964 "Failed to load segment %d of firmware.\n",
6965 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04006966 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006967 }
6968
6969 fwcode += dlen;
6970 risc_addr += dlen;
6971 risc_size -= dlen;
6972 fragment++;
6973 }
6974
6975 /* Next segment. */
6976 segments--;
6977 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05006978
6979 if (!IS_QLA27XX(ha))
6980 return rval;
6981
6982 if (ha->fw_dump_template)
6983 vfree(ha->fw_dump_template);
6984 ha->fw_dump_template = NULL;
6985 ha->fw_dump_template_len = 0;
6986
6987 ql_dbg(ql_dbg_init, vha, 0x171,
Chad Dupuis97ea7022014-03-13 14:16:40 -04006988 "Loading fwdump template from %x\n",
6989 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
Chad Dupuisf73cb692014-02-26 04:15:06 -05006990 risc_size = be32_to_cpu(fwcode[2]);
6991 ql_dbg(ql_dbg_init, vha, 0x172,
6992 "-> array size %x dwords\n", risc_size);
6993 if (risc_size == 0 || risc_size == ~0)
6994 goto default_template;
6995
6996 dlen = (risc_size - 8) * sizeof(*fwcode);
6997 ql_dbg(ql_dbg_init, vha, 0x0173,
6998 "-> template allocating %x bytes...\n", dlen);
6999 ha->fw_dump_template = vmalloc(dlen);
7000 if (!ha->fw_dump_template) {
7001 ql_log(ql_log_warn, vha, 0x0174,
7002 "Failed fwdump template allocate %x bytes.\n", risc_size);
7003 goto default_template;
7004 }
7005
7006 fwcode += 7;
7007 risc_size -= 8;
7008 dcode = ha->fw_dump_template;
7009 for (i = 0; i < risc_size; i++)
7010 dcode[i] = le32_to_cpu(fwcode[i]);
7011
7012 if (!qla27xx_fwdt_template_valid(dcode)) {
7013 ql_log(ql_log_warn, vha, 0x0175,
7014 "Failed fwdump template validate\n");
7015 goto default_template;
7016 }
7017
7018 dlen = qla27xx_fwdt_template_size(dcode);
7019 ql_dbg(ql_dbg_init, vha, 0x0176,
7020 "-> template size %x bytes\n", dlen);
7021 if (dlen > risc_size * sizeof(*fwcode)) {
7022 ql_log(ql_log_warn, vha, 0x0177,
Himanshu Madhani4fae52b2017-06-06 13:55:23 -07007023 "Failed fwdump template exceeds array by %zx bytes\n",
Joe Carnuccio383a2982017-06-02 09:11:55 -07007024 (size_t)(dlen - risc_size * sizeof(*fwcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05007025 goto default_template;
7026 }
7027 ha->fw_dump_template_len = dlen;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007028 return rval;
7029
Chad Dupuisf73cb692014-02-26 04:15:06 -05007030default_template:
7031 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
7032 if (ha->fw_dump_template)
7033 vfree(ha->fw_dump_template);
7034 ha->fw_dump_template = NULL;
7035 ha->fw_dump_template_len = 0;
7036
7037 dlen = qla27xx_fwdt_template_default_size();
7038 ql_dbg(ql_dbg_init, vha, 0x0179,
7039 "-> template allocating %x bytes...\n", dlen);
7040 ha->fw_dump_template = vmalloc(dlen);
7041 if (!ha->fw_dump_template) {
7042 ql_log(ql_log_warn, vha, 0x017a,
7043 "Failed fwdump template allocate %x bytes.\n", risc_size);
7044 goto failed_template;
7045 }
7046
7047 dcode = ha->fw_dump_template;
7048 risc_size = dlen / sizeof(*fwcode);
7049 fwcode = qla27xx_fwdt_template_default();
7050 for (i = 0; i < risc_size; i++)
7051 dcode[i] = be32_to_cpu(fwcode[i]);
7052
7053 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7054 ql_log(ql_log_warn, vha, 0x017b,
7055 "Failed fwdump template validate\n");
7056 goto failed_template;
7057 }
7058
7059 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7060 ql_dbg(ql_dbg_init, vha, 0x017c,
7061 "-> template size %x bytes\n", dlen);
7062 ha->fw_dump_template_len = dlen;
7063 return rval;
7064
7065failed_template:
7066 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
7067 if (ha->fw_dump_template)
7068 vfree(ha->fw_dump_template);
7069 ha->fw_dump_template = NULL;
7070 ha->fw_dump_template_len = 0;
7071 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07007072}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007073
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007074int
7075qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7076{
7077 int rval;
7078
Andrew Vasqueze337d902009-04-06 22:33:49 -07007079 if (ql2xfwloadbin == 1)
7080 return qla81xx_load_risc(vha, srisc_addr);
7081
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007082 /*
7083 * FW Load priority:
7084 * 1) Firmware via request-firmware interface (.bin file).
7085 * 2) Firmware residing in flash.
7086 */
7087 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7088 if (rval == QLA_SUCCESS)
7089 return rval;
7090
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007091 return qla24xx_load_risc_flash(vha, srisc_addr,
7092 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007093}
7094
7095int
7096qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7097{
7098 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007099 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007100
Andrew Vasqueze337d902009-04-06 22:33:49 -07007101 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007102 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07007103
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007104 /*
7105 * FW Load priority:
7106 * 1) Firmware residing in flash.
7107 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007108 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007109 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007110 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007111 if (rval == QLA_SUCCESS)
7112 return rval;
7113
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007114try_blob_fw:
7115 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7116 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
7117 return rval;
7118
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007119 ql_log(ql_log_info, vha, 0x0099,
7120 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007121 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
7122 if (rval != QLA_SUCCESS)
7123 return rval;
7124
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007125 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007126 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07007127 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08007128}
7129
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007130void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007131qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007132{
7133 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007134 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007135
Andrew Vasquez85880802009-12-15 21:29:46 -08007136 if (ha->flags.pci_channel_io_perm_failure)
7137 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07007138 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007139 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07007140 if (!ha->fw_major_version)
7141 return;
Quinn Tranec7193e2017-03-15 09:48:55 -07007142 if (!ha->flags.fw_started)
7143 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007144
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007145 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08007146 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07007147 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007148 ha->isp_ops->reset_chip(vha);
7149 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007150 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007151 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007152 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007153 ql_log(ql_log_info, vha, 0x8015,
7154 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007155 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007156 }
Quinn Tranec7193e2017-03-15 09:48:55 -07007157
Quinn Tran4b60c822017-06-13 20:47:21 -07007158 QLA_FW_STOPPED(ha);
Quinn Tranec7193e2017-03-15 09:48:55 -07007159 ha->flags.fw_init_done = 0;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07007160}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007161
7162int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007163qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007164{
7165 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08007166 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007167 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007168 struct qla_hw_data *ha = vha->hw;
7169 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007170 struct req_que *req;
7171 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007172
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007173 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007174 return -EINVAL;
7175
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007176 rval = qla2x00_fw_ready(base_vha);
Michael Hernandezd7459522016-12-12 14:40:07 -08007177 if (vha->qpair)
7178 req = vha->qpair->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007179 else
Michael Hernandezd7459522016-12-12 14:40:07 -08007180 req = ha->req_q_map[0];
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07007181 rsp = req->rsp;
7182
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007183 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007184 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08007185 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007186 }
7187
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007188 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007189
7190 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08007191 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
7192 BIT_1);
7193 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
7194 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
7195 ql_dbg(ql_dbg_init, vha, 0x0120,
7196 "Failed SNS login: loop_id=%x, rval2=%d\n",
7197 NPH_SNS, rval2);
7198 else
7199 ql_dbg(ql_dbg_init, vha, 0x0103,
7200 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7201 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7202 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007203 return (QLA_FUNCTION_FAILED);
7204 }
7205
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007206 atomic_set(&vha->loop_down_timer, 0);
7207 atomic_set(&vha->loop_state, LOOP_UP);
7208 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7209 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
7210 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07007211
7212 return rval;
7213}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007214
7215/* 84XX Support **************************************************************/
7216
7217static LIST_HEAD(qla_cs84xx_list);
7218static DEFINE_MUTEX(qla_cs84xx_mutex);
7219
7220static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007221qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007222{
7223 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007224 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007225
7226 mutex_lock(&qla_cs84xx_mutex);
7227
7228 /* Find any shared 84xx chip. */
7229 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
7230 if (cs84xx->bus == ha->pdev->bus) {
7231 kref_get(&cs84xx->kref);
7232 goto done;
7233 }
7234 }
7235
7236 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
7237 if (!cs84xx)
7238 goto done;
7239
7240 kref_init(&cs84xx->kref);
7241 spin_lock_init(&cs84xx->access_lock);
7242 mutex_init(&cs84xx->fw_update_mutex);
7243 cs84xx->bus = ha->pdev->bus;
7244
7245 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
7246done:
7247 mutex_unlock(&qla_cs84xx_mutex);
7248 return cs84xx;
7249}
7250
7251static void
7252__qla84xx_chip_release(struct kref *kref)
7253{
7254 struct qla_chip_state_84xx *cs84xx =
7255 container_of(kref, struct qla_chip_state_84xx, kref);
7256
7257 mutex_lock(&qla_cs84xx_mutex);
7258 list_del(&cs84xx->list);
7259 mutex_unlock(&qla_cs84xx_mutex);
7260 kfree(cs84xx);
7261}
7262
7263void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007264qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007265{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007266 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007267 if (ha->cs84xx)
7268 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
7269}
7270
7271static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007272qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007273{
7274 int rval;
7275 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007276 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007277
7278 mutex_lock(&ha->cs84xx->fw_update_mutex);
7279
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08007280 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07007281
7282 mutex_unlock(&ha->cs84xx->fw_update_mutex);
7283
7284 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
7285 QLA_SUCCESS;
7286}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007287
7288/* 81XX Support **************************************************************/
7289
7290int
7291qla81xx_nvram_config(scsi_qla_host_t *vha)
7292{
7293 int rval;
7294 struct init_cb_81xx *icb;
7295 struct nvram_81xx *nv;
7296 uint32_t *dptr;
7297 uint8_t *dptr1, *dptr2;
7298 uint32_t chksum;
7299 uint16_t cnt;
7300 struct qla_hw_data *ha = vha->hw;
7301
7302 rval = QLA_SUCCESS;
7303 icb = (struct init_cb_81xx *)ha->init_cb;
7304 nv = ha->nvram;
7305
7306 /* Determine NVRAM starting address. */
7307 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007308 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007309 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
7310 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007311
7312 /* Get VPD data into cache */
7313 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007314 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
7315 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007316
7317 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007318 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007319 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07007320 dptr = (uint32_t *)nv;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05007321 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7322 chksum += le32_to_cpu(*dptr);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007323
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007324 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
7325 "Contents of NVRAM:\n");
7326 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
7327 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007328
7329 /* Bad NVRAM data, set defaults parameters. */
7330 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
7331 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07007332 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007333 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007334 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04007335 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007336 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007337 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007338 ql_log(ql_log_info, vha, 0x0074,
7339 "Falling back to functioning (yet invalid -- WWPN) "
7340 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007341
7342 /*
7343 * Set default initialization control block.
7344 */
7345 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07007346 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7347 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04007348 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07007349 nv->execution_throttle = cpu_to_le16(0xFFFF);
7350 nv->exchange_count = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007351 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007352 nv->port_name[1] = 0x00 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007353 nv->port_name[2] = 0x00;
7354 nv->port_name[3] = 0xe0;
7355 nv->port_name[4] = 0x8b;
7356 nv->port_name[5] = 0x1c;
7357 nv->port_name[6] = 0x55;
7358 nv->port_name[7] = 0x86;
7359 nv->node_name[0] = 0x20;
7360 nv->node_name[1] = 0x00;
7361 nv->node_name[2] = 0x00;
7362 nv->node_name[3] = 0xe0;
7363 nv->node_name[4] = 0x8b;
7364 nv->node_name[5] = 0x1c;
7365 nv->node_name[6] = 0x55;
7366 nv->node_name[7] = 0x86;
Bart Van Asschead950362015-07-09 07:24:08 -07007367 nv->login_retry_count = cpu_to_le16(8);
7368 nv->interrupt_delay_timer = cpu_to_le16(0);
7369 nv->login_timeout = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007370 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07007371 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7372 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7373 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7374 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7375 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7376 nv->efi_parameters = cpu_to_le32(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007377 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07007378 nv->max_luns_per_target = cpu_to_le16(128);
7379 nv->port_down_retry_count = cpu_to_le16(30);
7380 nv->link_down_timeout = cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07007381 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007382 nv->enode_mac[1] = 0xC0;
7383 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007384 nv->enode_mac[3] = 0x04;
7385 nv->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007386 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007387
7388 rval = 1;
7389 }
7390
Arun Easi9e522cd2012-08-22 14:21:31 -04007391 if (IS_T10_PI_CAPABLE(ha))
7392 nv->frame_payload_size &= ~7;
7393
Arun Easiaa230bc2013-01-30 03:34:39 -05007394 qlt_81xx_config_nvram_stage1(vha, nv);
7395
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007396 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07007397 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007398
7399 /* Copy 1st segment. */
7400 dptr1 = (uint8_t *)icb;
7401 dptr2 = (uint8_t *)&nv->version;
7402 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7403 while (cnt--)
7404 *dptr1++ = *dptr2++;
7405
7406 icb->login_retry_count = nv->login_retry_count;
7407
7408 /* Copy 2nd segment. */
7409 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7410 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7411 cnt = (uint8_t *)&icb->reserved_5 -
7412 (uint8_t *)&icb->interrupt_delay_timer;
7413 while (cnt--)
7414 *dptr1++ = *dptr2++;
7415
7416 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
7417 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
7418 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08007419 icb->enode_mac[0] = 0x00;
7420 icb->enode_mac[1] = 0xC0;
7421 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007422 icb->enode_mac[3] = 0x04;
7423 icb->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007424 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007425 }
7426
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07007427 /* Use extended-initialization control block. */
7428 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
7429
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007430 /*
7431 * Setup driver NVRAM options.
7432 */
7433 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07007434 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007435
Arun Easiaa230bc2013-01-30 03:34:39 -05007436 qlt_81xx_config_nvram_stage2(vha, icb);
7437
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007438 /* Use alternate WWN? */
Bart Van Asschead950362015-07-09 07:24:08 -07007439 if (nv->host_p & cpu_to_le32(BIT_15)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007440 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7441 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7442 }
7443
7444 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07007445 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007446 /*
7447 * Firmware will apply the following mask if the nodename was
7448 * not provided.
7449 */
7450 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7451 icb->node_name[0] &= 0xF0;
7452 }
7453
7454 /* Set host adapter parameters. */
7455 ha->flags.disable_risc_code_load = 0;
7456 ha->flags.enable_lip_reset = 0;
7457 ha->flags.enable_lip_full_login =
7458 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
7459 ha->flags.enable_target_reset =
7460 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
7461 ha->flags.enable_led_scheme = 0;
7462 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
7463
7464 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7465 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7466
7467 /* save HBA serial number */
7468 ha->serial0 = icb->port_name[5];
7469 ha->serial1 = icb->port_name[6];
7470 ha->serial2 = icb->port_name[7];
7471 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7472 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7473
Bart Van Asschead950362015-07-09 07:24:08 -07007474 icb->execution_throttle = cpu_to_le16(0xFFFF);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007475
7476 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7477
7478 /* Set minimum login_timeout to 4 seconds. */
7479 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7480 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7481 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07007482 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007483 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007484
7485 /* Set minimum RATOV to 100 tenths of a second. */
7486 ha->r_a_tov = 100;
7487
7488 ha->loop_reset_delay = nv->reset_delay;
7489
7490 /* Link Down Timeout = 0:
7491 *
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007492 * When Port Down timer expires we will start returning
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007493 * I/O's to OS with "DID_NO_CONNECT".
7494 *
7495 * Link Down Timeout != 0:
7496 *
7497 * The driver waits for the link to come up after link down
7498 * before returning I/Os to OS with "DID_NO_CONNECT".
7499 */
7500 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7501 ha->loop_down_abort_time =
7502 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7503 } else {
7504 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7505 ha->loop_down_abort_time =
7506 (LOOP_DOWN_TIME - ha->link_down_timeout);
7507 }
7508
7509 /* Need enough time to try and get the port back. */
7510 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7511 if (qlport_down_retry)
7512 ha->port_down_retry_count = qlport_down_retry;
7513
7514 /* Set login_retry_count */
7515 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7516 if (ha->port_down_retry_count ==
7517 le16_to_cpu(nv->port_down_retry_count) &&
7518 ha->port_down_retry_count > 3)
7519 ha->login_retry_count = ha->port_down_retry_count;
7520 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7521 ha->login_retry_count = ha->port_down_retry_count;
7522 if (ql2xloginretrycount)
7523 ha->login_retry_count = ql2xloginretrycount;
7524
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007525 /* if not running MSI-X we need handshaking on interrupts */
Chad Dupuisf73cb692014-02-26 04:15:06 -05007526 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
Bart Van Asschead950362015-07-09 07:24:08 -07007527 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007528
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007529 /* Enable ZIO. */
7530 if (!vha->flags.init_done) {
7531 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7532 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7533 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7534 le16_to_cpu(icb->interrupt_delay_timer): 2;
7535 }
Bart Van Asschead950362015-07-09 07:24:08 -07007536 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007537 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7538 vha->flags.process_response_queue = 0;
7539 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7540 ha->zio_mode = QLA_ZIO_MODE_6;
7541
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007542 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007543 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007544 ha->zio_mode,
7545 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007546
7547 icb->firmware_options_2 |= cpu_to_le32(
7548 (uint32_t)ha->zio_mode);
7549 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7550 vha->flags.process_response_queue = 1;
7551 }
7552
Quinn Tran41dc5292017-01-19 22:28:03 -08007553 /* enable RIDA Format2 */
7554 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))
7555 icb->firmware_options_3 |= BIT_0;
7556
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007557 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007558 ql_log(ql_log_warn, vha, 0x0076,
7559 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007560 }
7561 return (rval);
7562}
7563
Giridhar Malavalia9083012010-04-12 17:59:55 -07007564int
7565qla82xx_restart_isp(scsi_qla_host_t *vha)
7566{
7567 int status, rval;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007568 struct qla_hw_data *ha = vha->hw;
7569 struct req_que *req = ha->req_q_map[0];
7570 struct rsp_que *rsp = ha->rsp_q_map[0];
7571 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07007572 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007573
7574 status = qla2x00_init_rings(vha);
7575 if (!status) {
7576 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7577 ha->flags.chip_reset_done = 1;
7578
7579 status = qla2x00_fw_ready(vha);
7580 if (!status) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07007581 /* Issue a marker after FW becomes ready. */
7582 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007583 vha->flags.online = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04007584 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007585 }
7586
7587 /* if no cable then assume it's good */
7588 if ((vha->device_flags & DFLG_NO_CABLE))
7589 status = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007590 }
7591
7592 if (!status) {
7593 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7594
7595 if (!atomic_read(&vha->loop_down_timer)) {
7596 /*
7597 * Issue marker command only when we are going
7598 * to start the I/O .
7599 */
7600 vha->marker_needed = 1;
7601 }
7602
Giridhar Malavalia9083012010-04-12 17:59:55 -07007603 ha->isp_ops->enable_intrs(ha);
7604
7605 ha->isp_abort_cnt = 0;
7606 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7607
Saurav Kashyap53296782011-05-10 11:30:06 -07007608 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07007609 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07007610
Giridhar Malavalia9083012010-04-12 17:59:55 -07007611 if (ha->fce) {
7612 ha->flags.fce_enabled = 1;
7613 memset(ha->fce, 0,
7614 fce_calc_size(ha->fce_bufs));
7615 rval = qla2x00_enable_fce_trace(vha,
7616 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
7617 &ha->fce_bufs);
7618 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007619 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007620 "Unable to reinitialize FCE (%d).\n",
7621 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007622 ha->flags.fce_enabled = 0;
7623 }
7624 }
7625
7626 if (ha->eft) {
7627 memset(ha->eft, 0, EFT_SIZE);
7628 rval = qla2x00_enable_eft_trace(vha,
7629 ha->eft_dma, EFT_NUM_BUFFERS);
7630 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007631 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007632 "Unable to reinitialize EFT (%d).\n",
7633 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007634 }
7635 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07007636 }
7637
7638 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007639 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007640 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07007641
7642 spin_lock_irqsave(&ha->vport_slock, flags);
7643 list_for_each_entry(vp, &ha->vp_list, list) {
7644 if (vp->vp_idx) {
7645 atomic_inc(&vp->vref_count);
7646 spin_unlock_irqrestore(&ha->vport_slock, flags);
7647
Giridhar Malavalia9083012010-04-12 17:59:55 -07007648 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07007649
7650 spin_lock_irqsave(&ha->vport_slock, flags);
7651 atomic_dec(&vp->vref_count);
7652 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07007653 }
Arun Easifeafb7b2010-09-03 14:57:00 -07007654 spin_unlock_irqrestore(&ha->vport_slock, flags);
7655
Giridhar Malavalia9083012010-04-12 17:59:55 -07007656 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007657 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007658 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07007659 }
7660
7661 return status;
7662}
7663
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007664void
Andrew Vasquezae97c912010-02-18 10:07:28 -08007665qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007666{
Andrew Vasquezae97c912010-02-18 10:07:28 -08007667 struct qla_hw_data *ha = vha->hw;
7668
Himanshu Madhanif198caf2016-01-27 12:03:30 -05007669 /* Hold status IOCBs until ABTS response received. */
7670 if (ql2xfwholdabts)
7671 ha->fw_options[3] |= BIT_12;
7672
Giridhar Malavali088d09d2016-07-06 11:14:20 -04007673 /* Set Retry FLOGI in case of P2P connection */
7674 if (ha->operating_mode == P2P) {
7675 ha->fw_options[2] |= BIT_3;
7676 ql_dbg(ql_dbg_disc, vha, 0x2103,
7677 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
7678 __func__, ha->fw_options[2]);
7679 }
7680
Quinn Tran41dc5292017-01-19 22:28:03 -08007681 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
7682 if (ql2xmvasynctoatio) {
7683 if (qla_tgt_mode_enabled(vha) ||
7684 qla_dual_mode_enabled(vha))
7685 ha->fw_options[2] |= BIT_11;
7686 else
7687 ha->fw_options[2] &= ~BIT_11;
7688 }
Andrew Vasquezae97c912010-02-18 10:07:28 -08007689
Quinn Tranf7e761f2017-06-02 09:12:02 -07007690 if (qla_tgt_mode_enabled(vha) ||
Quinn Tran2da52732017-06-02 09:12:05 -07007691 qla_dual_mode_enabled(vha)) {
7692 /* FW auto send SCSI status during */
7693 ha->fw_options[1] |= BIT_8;
7694 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
7695
7696 /* FW perform Exchange validation */
Quinn Tranf7e761f2017-06-02 09:12:02 -07007697 ha->fw_options[2] |= BIT_4;
Quinn Tran2da52732017-06-02 09:12:05 -07007698 } else {
7699 ha->fw_options[1] &= ~BIT_8;
7700 ha->fw_options[10] &= 0x00ff;
7701
Quinn Tranf7e761f2017-06-02 09:12:02 -07007702 ha->fw_options[2] &= ~BIT_4;
Quinn Tran2da52732017-06-02 09:12:05 -07007703 }
Quinn Tranf7e761f2017-06-02 09:12:02 -07007704
Quinn Tran41dc5292017-01-19 22:28:03 -08007705 if (ql2xetsenable) {
7706 /* Enable ETS Burst. */
7707 memset(ha->fw_options, 0, sizeof(ha->fw_options));
7708 ha->fw_options[2] |= BIT_9;
7709 }
7710
Quinn Tran83548fe2017-06-02 09:12:01 -07007711 ql_dbg(ql_dbg_init, vha, 0x00e9,
7712 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
7713 __func__, ha->fw_options[1], ha->fw_options[2],
7714 ha->fw_options[3], vha->host->active_mode);
Quinn Tran41dc5292017-01-19 22:28:03 -08007715
Andrew Vasquezae97c912010-02-18 10:07:28 -08007716 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007717}
Sarang Radke09ff7012010-03-19 17:03:59 -07007718
7719/*
7720 * qla24xx_get_fcp_prio
7721 * Gets the fcp cmd priority value for the logged in port.
7722 * Looks for a match of the port descriptors within
7723 * each of the fcp prio config entries. If a match is found,
7724 * the tag (priority) value is returned.
7725 *
7726 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007727 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07007728 * fcport = port structure pointer.
7729 *
7730 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07007731 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007732 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07007733 *
7734 * Context:
7735 * Kernel context
7736 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007737static int
Sarang Radke09ff7012010-03-19 17:03:59 -07007738qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
7739{
7740 int i, entries;
7741 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007742 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07007743 uint32_t pid1, pid2;
7744 uint64_t wwn1, wwn2;
7745 struct qla_fcp_prio_entry *pri_entry;
7746 struct qla_hw_data *ha = vha->hw;
7747
7748 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007749 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07007750
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007751 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07007752 entries = ha->fcp_prio_cfg->num_entries;
7753 pri_entry = &ha->fcp_prio_cfg->entry[0];
7754
7755 for (i = 0; i < entries; i++) {
7756 pid_match = wwn_match = 0;
7757
7758 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
7759 pri_entry++;
7760 continue;
7761 }
7762
7763 /* check source pid for a match */
7764 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
7765 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
7766 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
7767 if (pid1 == INVALID_PORT_ID)
7768 pid_match++;
7769 else if (pid1 == pid2)
7770 pid_match++;
7771 }
7772
7773 /* check destination pid for a match */
7774 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
7775 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
7776 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
7777 if (pid1 == INVALID_PORT_ID)
7778 pid_match++;
7779 else if (pid1 == pid2)
7780 pid_match++;
7781 }
7782
7783 /* check source WWN for a match */
7784 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
7785 wwn1 = wwn_to_u64(vha->port_name);
7786 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
7787 if (wwn2 == (uint64_t)-1)
7788 wwn_match++;
7789 else if (wwn1 == wwn2)
7790 wwn_match++;
7791 }
7792
7793 /* check destination WWN for a match */
7794 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
7795 wwn1 = wwn_to_u64(fcport->port_name);
7796 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
7797 if (wwn2 == (uint64_t)-1)
7798 wwn_match++;
7799 else if (wwn1 == wwn2)
7800 wwn_match++;
7801 }
7802
7803 if (pid_match == 2 || wwn_match == 2) {
7804 /* Found a matching entry */
7805 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
7806 priority = pri_entry->tag;
7807 break;
7808 }
7809
7810 pri_entry++;
7811 }
7812
7813 return priority;
7814}
7815
7816/*
7817 * qla24xx_update_fcport_fcp_prio
7818 * Activates fcp priority for the logged in fc port
7819 *
7820 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007821 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07007822 * fcp = port structure pointer.
7823 *
7824 * Return:
7825 * QLA_SUCCESS or QLA_FUNCTION_FAILED
7826 *
7827 * Context:
7828 * Kernel context.
7829 */
7830int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007831qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07007832{
7833 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007834 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07007835 uint16_t mb[5];
7836
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007837 if (fcport->port_type != FCT_TARGET ||
7838 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07007839 return QLA_FUNCTION_FAILED;
7840
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007841 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007842 if (priority < 0)
7843 return QLA_FUNCTION_FAILED;
7844
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007845 if (IS_P3P_TYPE(vha->hw)) {
Saurav Kashyapa00f6292011-11-18 09:03:19 -08007846 fcport->fcp_prio = priority & 0xf;
7847 return QLA_SUCCESS;
7848 }
7849
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007850 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08007851 if (ret == QLA_SUCCESS) {
7852 if (fcport->fcp_prio != priority)
7853 ql_dbg(ql_dbg_user, vha, 0x709e,
7854 "Updated FCP_CMND priority - value=%d loop_id=%d "
7855 "port_id=%02x%02x%02x.\n", priority,
7856 fcport->loop_id, fcport->d_id.b.domain,
7857 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08007858 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08007859 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007860 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08007861 "Unable to update FCP_CMND priority - ret=0x%x for "
7862 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
7863 fcport->d_id.b.domain, fcport->d_id.b.area,
7864 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07007865 return ret;
7866}
7867
7868/*
7869 * qla24xx_update_all_fcp_prio
7870 * Activates fcp priority for all the logged in ports
7871 *
7872 * Input:
7873 * ha = adapter block pointer.
7874 *
7875 * Return:
7876 * QLA_SUCCESS or QLA_FUNCTION_FAILED
7877 *
7878 * Context:
7879 * Kernel context.
7880 */
7881int
7882qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
7883{
7884 int ret;
7885 fc_port_t *fcport;
7886
7887 ret = QLA_FUNCTION_FAILED;
7888 /* We need to set priority for all logged in ports */
7889 list_for_each_entry(fcport, &vha->vp_fcports, list)
7890 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
7891
7892 return ret;
7893}
Michael Hernandezd7459522016-12-12 14:40:07 -08007894
Quinn Tran82de8022017-06-13 20:47:17 -07007895struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
7896 int vp_idx, bool startqp)
Michael Hernandezd7459522016-12-12 14:40:07 -08007897{
7898 int rsp_id = 0;
7899 int req_id = 0;
7900 int i;
7901 struct qla_hw_data *ha = vha->hw;
7902 uint16_t qpair_id = 0;
7903 struct qla_qpair *qpair = NULL;
7904 struct qla_msix_entry *msix;
7905
7906 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
7907 ql_log(ql_log_warn, vha, 0x00181,
7908 "FW/Driver is not multi-queue capable.\n");
7909 return NULL;
7910 }
7911
7912 if (ql2xmqsupport) {
7913 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
7914 if (qpair == NULL) {
7915 ql_log(ql_log_warn, vha, 0x0182,
7916 "Failed to allocate memory for queue pair.\n");
7917 return NULL;
7918 }
7919 memset(qpair, 0, sizeof(struct qla_qpair));
7920
7921 qpair->hw = vha->hw;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08007922 qpair->vha = vha;
Quinn Tran82de8022017-06-13 20:47:17 -07007923 qpair->qp_lock_ptr = &qpair->qp_lock;
7924 spin_lock_init(&qpair->qp_lock);
Quinn Tranaf7bb382017-06-13 20:47:23 -07007925 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
Michael Hernandezd7459522016-12-12 14:40:07 -08007926
7927 /* Assign available que pair id */
7928 mutex_lock(&ha->mq_lock);
7929 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
Sawan Chandakb95b9452017-05-24 18:06:20 -07007930 if (ha->num_qpairs >= ha->max_qpairs) {
Michael Hernandezd7459522016-12-12 14:40:07 -08007931 mutex_unlock(&ha->mq_lock);
7932 ql_log(ql_log_warn, vha, 0x0183,
7933 "No resources to create additional q pair.\n");
7934 goto fail_qid_map;
7935 }
Sawan Chandakb95b9452017-05-24 18:06:20 -07007936 ha->num_qpairs++;
Michael Hernandezd7459522016-12-12 14:40:07 -08007937 set_bit(qpair_id, ha->qpair_qid_map);
7938 ha->queue_pair_map[qpair_id] = qpair;
7939 qpair->id = qpair_id;
7940 qpair->vp_idx = vp_idx;
himanshu.madhani@cavium.come6373f332017-08-23 15:04:57 -07007941 qpair->fw_started = ha->flags.fw_started;
Quinn Trane326d222017-06-13 20:47:18 -07007942 INIT_LIST_HEAD(&qpair->hints_list);
Duane Grigsbycf19c452017-08-23 15:04:58 -07007943 INIT_LIST_HEAD(&qpair->nvme_done_list);
Quinn Tran7c3f8fd2017-06-13 20:47:22 -07007944 qpair->chip_reset = ha->base_qpair->chip_reset;
7945 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
7946 qpair->enable_explicit_conf =
7947 ha->base_qpair->enable_explicit_conf;
Michael Hernandezd7459522016-12-12 14:40:07 -08007948
7949 for (i = 0; i < ha->msix_count; i++) {
Quinn Tran093df732016-12-12 14:40:09 -08007950 msix = &ha->msix_entries[i];
Michael Hernandezd7459522016-12-12 14:40:07 -08007951 if (msix->in_use)
7952 continue;
7953 qpair->msix = msix;
Quinn Tran83548fe2017-06-02 09:12:01 -07007954 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
Michael Hernandezd7459522016-12-12 14:40:07 -08007955 "Vector %x selected for qpair\n", msix->vector);
7956 break;
7957 }
7958 if (!qpair->msix) {
7959 ql_log(ql_log_warn, vha, 0x0184,
7960 "Out of MSI-X vectors!.\n");
7961 goto fail_msix;
7962 }
7963
7964 qpair->msix->in_use = 1;
7965 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
Quinn Tran8abfa9e2017-06-13 20:47:24 -07007966 qpair->pdev = ha->pdev;
7967 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
7968 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
Michael Hernandezd7459522016-12-12 14:40:07 -08007969
7970 mutex_unlock(&ha->mq_lock);
7971
7972 /* Create response queue first */
Quinn Tran82de8022017-06-13 20:47:17 -07007973 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
Michael Hernandezd7459522016-12-12 14:40:07 -08007974 if (!rsp_id) {
7975 ql_log(ql_log_warn, vha, 0x0185,
7976 "Failed to create response queue.\n");
7977 goto fail_rsp;
7978 }
7979
7980 qpair->rsp = ha->rsp_q_map[rsp_id];
7981
7982 /* Create request queue */
Quinn Tran82de8022017-06-13 20:47:17 -07007983 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
7984 startqp);
Michael Hernandezd7459522016-12-12 14:40:07 -08007985 if (!req_id) {
7986 ql_log(ql_log_warn, vha, 0x0186,
7987 "Failed to create request queue.\n");
7988 goto fail_req;
7989 }
7990
7991 qpair->req = ha->req_q_map[req_id];
7992 qpair->rsp->req = qpair->req;
Quinn Tran82de8022017-06-13 20:47:17 -07007993 qpair->rsp->qpair = qpair;
Quinn Trane326d222017-06-13 20:47:18 -07007994 /* init qpair to this cpu. Will adjust at run time. */
7995 qla_cpu_update(qpair, smp_processor_id());
Michael Hernandezd7459522016-12-12 14:40:07 -08007996
7997 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
7998 if (ha->fw_attributes & BIT_4)
7999 qpair->difdix_supported = 1;
8000 }
8001
8002 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
8003 if (!qpair->srb_mempool) {
Quinn Tran83548fe2017-06-02 09:12:01 -07008004 ql_log(ql_log_warn, vha, 0xd036,
Michael Hernandezd7459522016-12-12 14:40:07 -08008005 "Failed to create srb mempool for qpair %d\n",
8006 qpair->id);
8007 goto fail_mempool;
8008 }
8009
8010 /* Mark as online */
8011 qpair->online = 1;
8012
8013 if (!vha->flags.qpairs_available)
8014 vha->flags.qpairs_available = 1;
8015
8016 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
8017 "Request/Response queue pair created, id %d\n",
8018 qpair->id);
8019 ql_dbg(ql_dbg_init, vha, 0x0187,
8020 "Request/Response queue pair created, id %d\n",
8021 qpair->id);
8022 }
8023 return qpair;
8024
8025fail_mempool:
8026fail_req:
8027 qla25xx_delete_rsp_que(vha, qpair->rsp);
8028fail_rsp:
8029 mutex_lock(&ha->mq_lock);
8030 qpair->msix->in_use = 0;
8031 list_del(&qpair->qp_list_elem);
8032 if (list_empty(&vha->qp_list))
8033 vha->flags.qpairs_available = 0;
8034fail_msix:
8035 ha->queue_pair_map[qpair_id] = NULL;
8036 clear_bit(qpair_id, ha->qpair_qid_map);
Sawan Chandakb95b9452017-05-24 18:06:20 -07008037 ha->num_qpairs--;
Michael Hernandezd7459522016-12-12 14:40:07 -08008038 mutex_unlock(&ha->mq_lock);
8039fail_qid_map:
8040 kfree(qpair);
8041 return NULL;
8042}
8043
8044int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
8045{
Sawan Chandakd65237c2017-06-13 20:47:19 -07008046 int ret = QLA_FUNCTION_FAILED;
Michael Hernandezd7459522016-12-12 14:40:07 -08008047 struct qla_hw_data *ha = qpair->hw;
8048
Sawan Chandakd65237c2017-06-13 20:47:19 -07008049 if (!vha->flags.qpairs_req_created && !vha->flags.qpairs_rsp_created)
8050 goto fail;
8051
Michael Hernandezd7459522016-12-12 14:40:07 -08008052 qpair->delete_in_progress = 1;
8053 while (atomic_read(&qpair->ref_count))
8054 msleep(500);
8055
8056 ret = qla25xx_delete_req_que(vha, qpair->req);
8057 if (ret != QLA_SUCCESS)
8058 goto fail;
8059 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
8060 if (ret != QLA_SUCCESS)
8061 goto fail;
8062
8063 mutex_lock(&ha->mq_lock);
8064 ha->queue_pair_map[qpair->id] = NULL;
8065 clear_bit(qpair->id, ha->qpair_qid_map);
Sawan Chandakb95b9452017-05-24 18:06:20 -07008066 ha->num_qpairs--;
Michael Hernandezd7459522016-12-12 14:40:07 -08008067 list_del(&qpair->qp_list_elem);
Sawan Chandakd65237c2017-06-13 20:47:19 -07008068 if (list_empty(&vha->qp_list)) {
Michael Hernandezd7459522016-12-12 14:40:07 -08008069 vha->flags.qpairs_available = 0;
Sawan Chandakd65237c2017-06-13 20:47:19 -07008070 vha->flags.qpairs_req_created = 0;
8071 vha->flags.qpairs_rsp_created = 0;
8072 }
Michael Hernandezd7459522016-12-12 14:40:07 -08008073 mempool_destroy(qpair->srb_mempool);
8074 kfree(qpair);
8075 mutex_unlock(&ha->mq_lock);
8076
8077 return QLA_SUCCESS;
8078fail:
8079 return ret;
8080}