blob: 68430934fa8d61190b8252a240d27487abb29e0e [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 *);
Quinn Tran726b8542017-01-19 22:28:00 -080039static int qla24xx_post_gpdb_work(struct scsi_qla_host *, fc_port_t *, u8);
40static void qla24xx_handle_plogi_done_event(struct scsi_qla_host *,
41 struct event_arg *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070042
Andrew Vasquezac280b62009-08-20 11:06:05 -070043/* SRB Extensions ---------------------------------------------------------- */
44
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080045void
46qla2x00_sp_timeout(unsigned long __data)
Andrew Vasquezac280b62009-08-20 11:06:05 -070047{
48 srb_t *sp = (srb_t *)__data;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070049 struct srb_iocb *iocb;
Quinn Tran726b8542017-01-19 22:28:00 -080050 scsi_qla_host_t *vha = (scsi_qla_host_t *)sp->vha;
51 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezac280b62009-08-20 11:06:05 -070052 struct req_que *req;
53 unsigned long flags;
54
55 spin_lock_irqsave(&ha->hardware_lock, flags);
56 req = ha->req_q_map[0];
57 req->outstanding_cmds[sp->handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080058 iocb = &sp->u.iocb_cmd;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070059 iocb->timeout(sp);
Quinn Tran726b8542017-01-19 22:28:00 -080060 sp->free(vha, sp);
Andrew Vasquez6ac52602010-05-28 15:08:19 -070061 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -070062}
63
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080064void
65qla2x00_sp_free(void *data, void *ptr)
Andrew Vasquezac280b62009-08-20 11:06:05 -070066{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080067 srb_t *sp = (srb_t *)ptr;
68 struct srb_iocb *iocb = &sp->u.iocb_cmd;
69 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquezac280b62009-08-20 11:06:05 -070070
Chad Dupuis4d97cc52010-10-15 11:27:41 -070071 del_timer(&iocb->timer);
Chad Dupuisb00ee7d2013-02-08 01:57:50 -050072 qla2x00_rel_sp(vha, 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{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800100 srb_t *sp = (srb_t *)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:
133 sp->done(sp->vha, sp, QLA_FUNCTION_TIMEOUT);
134 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
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800139qla2x00_async_login_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700140{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800141 srb_t *sp = (srb_t *)ptr;
142 struct srb_iocb *lio = &sp->u.iocb_cmd;
143 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Quinn Tran726b8542017-01-19 22:28:00 -0800144 struct event_arg ea;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700145
Quinn Tran726b8542017-01-19 22:28:00 -0800146 ql_dbg(ql_dbg_disc, vha, 0xffff,
147 "%s %8phC res %d \n",
148 __func__, sp->fcport->port_name, res);
149
150 sp->fcport->flags &= ~FCF_ASYNC_SENT;
151 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
152 memset(&ea, 0, sizeof(ea));
153 ea.event = FCME_PLOGI_DONE;
154 ea.fcport = sp->fcport;
155 ea.data[0] = lio->u.logio.data[0];
156 ea.data[1] = lio->u.logio.data[1];
157 ea.iop[0] = lio->u.logio.iop[0];
158 ea.iop[1] = lio->u.logio.iop[1];
159 ea.sp = sp;
160 qla2x00_fcport_event_handler(vha, &ea);
161 }
162
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800163 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700164}
165
Andrew Vasquezac280b62009-08-20 11:06:05 -0700166int
167qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
168 uint16_t *data)
169{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700170 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700171 struct srb_iocb *lio;
Quinn Tran726b8542017-01-19 22:28:00 -0800172 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700173
Quinn Tran726b8542017-01-19 22:28:00 -0800174 if (!vha->flags.online)
175 goto done;
176
177 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
178 (fcport->fw_login_state == DSC_LS_PLOGI_COMP) ||
179 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
180 goto done;
181
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800182 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700183 if (!sp)
184 goto done;
185
Quinn Tran726b8542017-01-19 22:28:00 -0800186 fcport->flags |= FCF_ASYNC_SENT;
187 fcport->logout_completed = 0;
188
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800189 sp->type = SRB_LOGIN_CMD;
190 sp->name = "login";
191 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
192
193 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700194 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800195 sp->done = qla2x00_async_login_sp_done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700196 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700197 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700198 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700199 rval = qla2x00_start_sp(sp);
Chad Dupuis080c9512016-01-27 12:03:37 -0500200 if (rval != QLA_SUCCESS) {
201 fcport->flags &= ~FCF_ASYNC_SENT;
202 fcport->flags |= FCF_LOGIN_NEEDED;
203 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700204 goto done_free_sp;
Chad Dupuis080c9512016-01-27 12:03:37 -0500205 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700206
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700207 ql_dbg(ql_dbg_disc, vha, 0x2072,
Quinn Tran726b8542017-01-19 22:28:00 -0800208 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
209 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800210 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
211 fcport->login_retry);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700212 return rval;
213
214done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800215 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700216done:
Quinn Tran726b8542017-01-19 22:28:00 -0800217 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700218 return rval;
219}
220
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700221static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800222qla2x00_async_logout_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700223{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800224 srb_t *sp = (srb_t *)ptr;
225 struct srb_iocb *lio = &sp->u.iocb_cmd;
226 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700227
Quinn Tran726b8542017-01-19 22:28:00 -0800228 sp->fcport->flags &= ~FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800229 if (!test_bit(UNLOADING, &vha->dpc_flags))
230 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
231 lio->u.logio.data);
232 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700233}
234
Andrew Vasquezac280b62009-08-20 11:06:05 -0700235int
236qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
237{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700238 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700239 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700240 int rval;
241
242 rval = QLA_FUNCTION_FAILED;
Quinn Tran726b8542017-01-19 22:28:00 -0800243 fcport->flags |= FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800244 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700245 if (!sp)
246 goto done;
247
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800248 sp->type = SRB_LOGOUT_CMD;
249 sp->name = "logout";
250 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
251
252 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700253 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800254 sp->done = qla2x00_async_logout_sp_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700255 rval = qla2x00_start_sp(sp);
256 if (rval != QLA_SUCCESS)
257 goto done_free_sp;
258
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700259 ql_dbg(ql_dbg_disc, vha, 0x2070,
Quinn Tran726b8542017-01-19 22:28:00 -0800260 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -0800261 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
Quinn Tran726b8542017-01-19 22:28:00 -0800262 fcport->d_id.b.area, fcport->d_id.b.al_pa,
263 fcport->port_name);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700264 return rval;
265
266done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800267 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700268done:
Quinn Tran726b8542017-01-19 22:28:00 -0800269 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700270 return rval;
271}
272
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700273static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800274qla2x00_async_adisc_sp_done(void *data, void *ptr, int res)
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700275{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800276 srb_t *sp = (srb_t *)ptr;
277 struct srb_iocb *lio = &sp->u.iocb_cmd;
278 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700279
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800280 if (!test_bit(UNLOADING, &vha->dpc_flags))
281 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
282 lio->u.logio.data);
283 sp->free(sp->fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700284}
285
286int
287qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
288 uint16_t *data)
289{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700290 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700291 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700292 int rval;
293
294 rval = QLA_FUNCTION_FAILED;
Quinn Tran726b8542017-01-19 22:28:00 -0800295 fcport->flags |= FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800296 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700297 if (!sp)
298 goto done;
299
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800300 sp->type = SRB_ADISC_CMD;
301 sp->name = "adisc";
302 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
303
304 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700305 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800306 sp->done = qla2x00_async_adisc_sp_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700307 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700308 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700309 rval = qla2x00_start_sp(sp);
310 if (rval != QLA_SUCCESS)
311 goto done_free_sp;
312
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700313 ql_dbg(ql_dbg_disc, vha, 0x206f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800314 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
315 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
316 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700317 return rval;
318
319done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800320 sp->free(fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700321done:
Quinn Tran726b8542017-01-19 22:28:00 -0800322 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700323 return rval;
324}
325
Quinn Tran726b8542017-01-19 22:28:00 -0800326static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
327 struct event_arg *ea)
328{
329 fc_port_t *fcport, *conflict_fcport;
330 struct get_name_list_extended *e;
331 u16 i, n, found = 0, loop_id;
332 port_id_t id;
333 u64 wwn;
334 u8 opt = 0;
335
336 fcport = ea->fcport;
337
338 if (ea->rc) { /* rval */
339 if (fcport->login_retry == 0) {
340 fcport->login_retry = vha->hw->login_retry_count;
341 ql_dbg(ql_dbg_disc, vha, 0xffff,
342 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
343 fcport->port_name, fcport->login_retry);
344 }
345 return;
346 }
347
348 if (fcport->last_rscn_gen != fcport->rscn_gen) {
349 ql_dbg(ql_dbg_disc, vha, 0xffff,
350 "%s %8phC rscn gen changed rscn %d|%d \n",
351 __func__, fcport->port_name,
352 fcport->last_rscn_gen, fcport->rscn_gen);
353 qla24xx_post_gidpn_work(vha, fcport);
354 return;
355 } else if (fcport->last_login_gen != fcport->login_gen) {
356 ql_dbg(ql_dbg_disc, vha, 0xffff,
357 "%s %8phC login gen changed login %d|%d \n",
358 __func__, fcport->port_name,
359 fcport->last_login_gen, fcport->login_gen);
360 return;
361 }
362
363 n = ea->data[0] / sizeof(struct get_name_list_extended);
364
365 ql_dbg(ql_dbg_disc, vha, 0xffff,
366 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
367 __func__, __LINE__, fcport->port_name, n,
368 fcport->d_id.b.domain, fcport->d_id.b.area,
369 fcport->d_id.b.al_pa, fcport->loop_id);
370
371 for (i = 0; i < n; i++) {
372 e = &vha->gnl.l[i];
373 wwn = wwn_to_u64(e->port_name);
374
375 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
376 continue;
377
378 found = 1;
379 id.b.domain = e->port_id[2];
380 id.b.area = e->port_id[1];
381 id.b.al_pa = e->port_id[0];
382 id.b.rsvd_1 = 0;
383
384 loop_id = le16_to_cpu(e->nport_handle);
385 loop_id = (loop_id & 0x7fff);
386
387 ql_dbg(ql_dbg_disc, vha, 0xffff,
388 "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
389 __func__, fcport->port_name,
390 e->current_login_state, fcport->fw_login_state,
391 id.b.domain, id.b.area, id.b.al_pa,
392 fcport->d_id.b.domain, fcport->d_id.b.area,
393 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
394
395 if ((id.b24 != fcport->d_id.b24) ||
396 ((fcport->loop_id != FC_NO_LOOP_ID) &&
397 (fcport->loop_id != loop_id))) {
398 ql_dbg(ql_dbg_disc, vha, 0xffff,
399 "%s %d %8phC post del sess\n",
400 __func__, __LINE__, fcport->port_name);
401 qlt_schedule_sess_for_deletion(fcport, 1);
402 return;
403 }
404
405 fcport->loop_id = loop_id;
406
407 wwn = wwn_to_u64(fcport->port_name);
408 qlt_find_sess_invalidate_other(vha, wwn,
409 id, loop_id, &conflict_fcport);
410
411 if (conflict_fcport) {
412 /*
413 * Another share fcport share the same loop_id &
414 * nport id. Conflict fcport needs to finish
415 * cleanup before this fcport can proceed to login.
416 */
417 conflict_fcport->conflict = fcport;
418 fcport->login_pause = 1;
419 }
420
421 switch (e->current_login_state) {
422 case DSC_LS_PRLI_COMP:
423 ql_dbg(ql_dbg_disc, vha, 0xffff,
424 "%s %d %8phC post gpdb\n",
425 __func__, __LINE__, fcport->port_name);
426 opt = PDO_FORCE_ADISC;
427 qla24xx_post_gpdb_work(vha, fcport, opt);
428 break;
429
430 case DSC_LS_PORT_UNAVAIL:
431 default:
432 if (fcport->loop_id == FC_NO_LOOP_ID) {
433 qla2x00_find_new_loop_id(vha, fcport);
434 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
435 }
436 ql_dbg(ql_dbg_disc, vha, 0xffff,
437 "%s %d %8phC \n",
438 __func__, __LINE__, fcport->port_name);
439 qla24xx_fcport_handle_login(vha, fcport);
440 break;
441 }
442 }
443
444 if (!found) {
445 /* fw has no record of this port */
446 if (fcport->loop_id == FC_NO_LOOP_ID) {
447 qla2x00_find_new_loop_id(vha, fcport);
448 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
449 } else {
450 for (i = 0; i < n; i++) {
451 e = &vha->gnl.l[i];
452 id.b.domain = e->port_id[0];
453 id.b.area = e->port_id[1];
454 id.b.al_pa = e->port_id[2];
455 id.b.rsvd_1 = 0;
456 loop_id = le16_to_cpu(e->nport_handle);
457
458 if (fcport->d_id.b24 == id.b24) {
459 conflict_fcport =
460 qla2x00_find_fcport_by_wwpn(vha,
461 e->port_name, 0);
462
463 ql_dbg(ql_dbg_disc, vha, 0xffff,
464 "%s %d %8phC post del sess\n",
465 __func__, __LINE__,
466 conflict_fcport->port_name);
467 qlt_schedule_sess_for_deletion
468 (conflict_fcport, 1);
469 }
470
471 if (fcport->loop_id == loop_id) {
472 /* FW already picked this loop id for another fcport */
473 qla2x00_find_new_loop_id(vha, fcport);
474 }
475 }
476 }
477 qla24xx_fcport_handle_login(vha, fcport);
478 }
479} /* gnl_event */
480
481static void
482qla24xx_async_gnl_sp_done(void *v, void *s, int res)
483{
484 struct scsi_qla_host *vha = (struct scsi_qla_host *)v;
485 struct srb *sp = (struct srb *)s;
486 unsigned long flags;
487 struct fc_port *fcport = NULL, *tf;
488 u16 i, n = 0, loop_id;
489 struct event_arg ea;
490 struct get_name_list_extended *e;
491 u64 wwn;
492 struct list_head h;
493
494 ql_dbg(ql_dbg_disc, vha, 0xffff,
495 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
496 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
497 sp->u.iocb_cmd.u.mbx.in_mb[2]);
498
499 memset(&ea, 0, sizeof(ea));
500 ea.sp = sp;
501 ea.rc = res;
502 ea.event = FCME_GNL_DONE;
503
504 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
505 sizeof(struct get_name_list_extended)) {
506 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
507 sizeof(struct get_name_list_extended);
508 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
509 }
510
511 for (i = 0; i < n; i++) {
512 e = &vha->gnl.l[i];
513 loop_id = le16_to_cpu(e->nport_handle);
514 /* mask out reserve bit */
515 loop_id = (loop_id & 0x7fff);
516 set_bit(loop_id, vha->hw->loop_id_map);
517 wwn = wwn_to_u64(e->port_name);
518
519 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff,
520 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
521 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
522 e->port_id[0], e->current_login_state, e->last_login_state,
523 (loop_id & 0x7fff));
524 }
525
526 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
527 vha->gnl.sent = 0;
528
529 INIT_LIST_HEAD(&h);
530 fcport = tf = NULL;
531 if (!list_empty(&vha->gnl.fcports))
532 list_splice_init(&vha->gnl.fcports, &h);
533
534 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
535 list_del_init(&fcport->gnl_entry);
536 fcport->flags &= ~FCF_ASYNC_SENT;
537 ea.fcport = fcport;
538
539 qla2x00_fcport_event_handler(vha, &ea);
540 }
541
542 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
543
544 sp->free(vha, sp);
545}
546
547int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
548{
549 srb_t *sp;
550 struct srb_iocb *mbx;
551 int rval = QLA_FUNCTION_FAILED;
552 unsigned long flags;
553 u16 *mb;
554
555 if (!vha->flags.online)
556 goto done;
557
558 ql_dbg(ql_dbg_disc, vha, 0xffff,
559 "Async-gnlist WWPN %8phC \n", fcport->port_name);
560
561 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
562 fcport->flags |= FCF_ASYNC_SENT;
563 fcport->disc_state = DSC_GNL;
564 fcport->last_rscn_gen = fcport->rscn_gen;
565 fcport->last_login_gen = fcport->login_gen;
566
567 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
568 if (vha->gnl.sent) {
569 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
570 rval = QLA_SUCCESS;
571 goto done;
572 }
573 vha->gnl.sent = 1;
574 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
575
576 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
577 if (!sp)
578 goto done;
579 sp->type = SRB_MB_IOCB;
580 sp->name = "gnlist";
581 sp->gen1 = fcport->rscn_gen;
582 sp->gen2 = fcport->login_gen;
583
584 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
585
586 mb = sp->u.iocb_cmd.u.mbx.out_mb;
587 mb[0] = MBC_PORT_NODE_NAME_LIST;
588 mb[1] = BIT_2 | BIT_3;
589 mb[2] = MSW(vha->gnl.ldma);
590 mb[3] = LSW(vha->gnl.ldma);
591 mb[6] = MSW(MSD(vha->gnl.ldma));
592 mb[7] = LSW(MSD(vha->gnl.ldma));
593 mb[8] = vha->gnl.size;
594 mb[9] = vha->vp_idx;
595
596 mbx = &sp->u.iocb_cmd;
597 mbx->timeout = qla2x00_async_iocb_timeout;
598
599 sp->done = qla24xx_async_gnl_sp_done;
600
601 rval = qla2x00_start_sp(sp);
602 if (rval != QLA_SUCCESS)
603 goto done_free_sp;
604
605 ql_dbg(ql_dbg_disc, vha, 0xffff,
606 "Async-%s - OUT WWPN %8phC hndl %x\n",
607 sp->name, fcport->port_name, sp->handle);
608
609 return rval;
610
611done_free_sp:
612 sp->free(fcport->vha, sp);
613done:
614 fcport->flags &= ~FCF_ASYNC_SENT;
615 return rval;
616}
617
618int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
619{
620 struct qla_work_evt *e;
621
622 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
623 if (!e)
624 return QLA_FUNCTION_FAILED;
625
626 e->u.fcport.fcport = fcport;
627 return qla2x00_post_work(vha, e);
628}
629
630static
631void qla24xx_async_gpdb_sp_done(void *v, void *s, int res)
632{
633 struct scsi_qla_host *vha = (struct scsi_qla_host *)v;
634 struct srb *sp = (struct srb *)s;
635 struct qla_hw_data *ha = vha->hw;
636 uint64_t zero = 0;
637 struct port_database_24xx *pd;
638 fc_port_t *fcport = sp->fcport;
639 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
640 int rval = QLA_SUCCESS;
641 struct event_arg ea;
642
643 ql_dbg(ql_dbg_disc, vha, 0xffff,
644 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
645 sp->name, res, fcport->port_name, mb[1], mb[2]);
646
647 fcport->flags &= ~FCF_ASYNC_SENT;
648
649 if (res) {
650 rval = res;
651 goto gpd_error_out;
652 }
653
654 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
655
656 /* Check for logged in state. */
657 if (pd->current_login_state != PDS_PRLI_COMPLETE &&
658 pd->last_login_state != PDS_PRLI_COMPLETE) {
659 ql_dbg(ql_dbg_mbx, vha, 0xffff,
660 "Unable to verify login-state (%x/%x) for "
661 "loop_id %x.\n", pd->current_login_state,
662 pd->last_login_state, fcport->loop_id);
663 rval = QLA_FUNCTION_FAILED;
664 goto gpd_error_out;
665 }
666
667 if (fcport->loop_id == FC_NO_LOOP_ID ||
668 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
669 memcmp(fcport->port_name, pd->port_name, 8))) {
670 /* We lost the device mid way. */
671 rval = QLA_NOT_LOGGED_IN;
672 goto gpd_error_out;
673 }
674
675 /* Names are little-endian. */
676 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
677
678 /* Get port_id of device. */
679 fcport->d_id.b.domain = pd->port_id[0];
680 fcport->d_id.b.area = pd->port_id[1];
681 fcport->d_id.b.al_pa = pd->port_id[2];
682 fcport->d_id.b.rsvd_1 = 0;
683
684 /* If not target must be initiator or unknown type. */
685 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
686 fcport->port_type = FCT_INITIATOR;
687 else
688 fcport->port_type = FCT_TARGET;
689
690 /* Passback COS information. */
691 fcport->supported_classes = (pd->flags & PDF_CLASS_2) ?
692 FC_COS_CLASS2 : FC_COS_CLASS3;
693
694 if (pd->prli_svc_param_word_3[0] & BIT_7) {
695 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
696 fcport->conf_compl_supported = 1;
697 }
698
699gpd_error_out:
700 memset(&ea, 0, sizeof(ea));
701 ea.event = FCME_GPDB_DONE;
702 ea.rc = rval;
703 ea.fcport = fcport;
704 ea.sp = sp;
705
706 qla2x00_fcport_event_handler(vha, &ea);
707
708 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
709 sp->u.iocb_cmd.u.mbx.in_dma);
710
711 sp->free(vha, sp);
712}
713
714static int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport,
715 u8 opt)
716{
717 struct qla_work_evt *e;
718
719 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
720 if (!e)
721 return QLA_FUNCTION_FAILED;
722
723 e->u.fcport.fcport = fcport;
724 e->u.fcport.opt = opt;
725 return qla2x00_post_work(vha, e);
726}
727
728int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
729{
730 srb_t *sp;
731 struct srb_iocb *mbx;
732 int rval = QLA_FUNCTION_FAILED;
733 u16 *mb;
734 dma_addr_t pd_dma;
735 struct port_database_24xx *pd;
736 struct qla_hw_data *ha = vha->hw;
737
738 if (!vha->flags.online)
739 goto done;
740
741 fcport->flags |= FCF_ASYNC_SENT;
742 fcport->disc_state = DSC_GPDB;
743
744 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
745 if (!sp)
746 goto done;
747
748 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
749 if (pd == NULL) {
750 ql_log(ql_log_warn, vha, 0xffff,
751 "Failed to allocate port database structure.\n");
752 goto done_free_sp;
753 }
754 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
755
756 sp->type = SRB_MB_IOCB;
757 sp->name = "gpdb";
758 sp->gen1 = fcport->rscn_gen;
759 sp->gen2 = fcport->login_gen;
760 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
761
762 mb = sp->u.iocb_cmd.u.mbx.out_mb;
763 mb[0] = MBC_GET_PORT_DATABASE;
764 mb[1] = fcport->loop_id;
765 mb[2] = MSW(pd_dma);
766 mb[3] = LSW(pd_dma);
767 mb[6] = MSW(MSD(pd_dma));
768 mb[7] = LSW(MSD(pd_dma));
769 mb[9] = vha->vp_idx;
770 mb[10] = opt;
771
772 mbx = &sp->u.iocb_cmd;
773 mbx->timeout = qla2x00_async_iocb_timeout;
774 mbx->u.mbx.in = (void *)pd;
775 mbx->u.mbx.in_dma = pd_dma;
776
777 sp->done = qla24xx_async_gpdb_sp_done;
778
779 rval = qla2x00_start_sp(sp);
780 if (rval != QLA_SUCCESS)
781 goto done_free_sp;
782
783 ql_dbg(ql_dbg_disc, vha, 0xffff,
784 "Async-%s %8phC hndl %x opt %x\n",
785 sp->name, fcport->port_name, sp->handle, opt);
786
787 return rval;
788
789done_free_sp:
790 if (pd)
791 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
792
793 sp->free(vha, sp);
794done:
795 fcport->flags &= ~FCF_ASYNC_SENT;
796 qla24xx_post_gpdb_work(vha, fcport, opt);
797 return rval;
798}
799
800static
801void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
802{
803 int rval = ea->rc;
804 fc_port_t *fcport = ea->fcport;
805 unsigned long flags;
806
807 fcport->flags &= ~FCF_ASYNC_SENT;
808
809 ql_dbg(ql_dbg_disc, vha, 0xffff,
810 "%s %8phC DS %d LS %d rval %d\n", __func__, fcport->port_name,
811 fcport->disc_state, fcport->fw_login_state, rval);
812
813 if (ea->sp->gen2 != fcport->login_gen) {
814 /* target side must have changed it. */
815 ql_dbg(ql_dbg_disc, vha, 0xffff,
816 "%s %8phC generation changed rscn %d|%d login %d|%d \n",
817 __func__, fcport->port_name, fcport->last_rscn_gen,
818 fcport->rscn_gen, fcport->last_login_gen,
819 fcport->login_gen);
820 return;
821 } else if (ea->sp->gen1 != fcport->rscn_gen) {
822 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC post gidpn\n",
823 __func__, __LINE__, fcport->port_name);
824 qla24xx_post_gidpn_work(vha, fcport);
825 return;
826 }
827
828 if (rval != QLA_SUCCESS) {
829 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC post del sess\n",
830 __func__, __LINE__, fcport->port_name);
831 qlt_schedule_sess_for_deletion_lock(fcport);
832 return;
833 }
834
835 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
836 ea->fcport->login_gen++;
837 ea->fcport->deleted = 0;
838 ea->fcport->logout_on_delete = 1;
839
840 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
841 vha->fcport_count++;
842 ea->fcport->login_succ = 1;
843
844 if (!IS_IIDMA_CAPABLE(vha->hw) ||
845 !vha->hw->flags.gpsc_supported) {
846 ql_dbg(ql_dbg_disc, vha, 0xffff,
847 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
848 __func__, __LINE__, fcport->port_name,
849 vha->fcport_count);
850
851 qla24xx_post_upd_fcport_work(vha, fcport);
852 } else {
853 ql_dbg(ql_dbg_disc, vha, 0xffff,
854 "%s %d %8phC post gpsc fcp_cnt %d\n",
855 __func__, __LINE__, fcport->port_name,
856 vha->fcport_count);
857
858 qla24xx_post_gpsc_work(vha, fcport);
859 }
860 }
861 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
862} /* gpdb event */
863
864int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
865{
866 if (fcport->login_retry == 0)
867 return 0;
868
869 if (fcport->scan_state != QLA_FCPORT_FOUND)
870 return 0;
871
872 ql_dbg(ql_dbg_disc, vha, 0xffff,
873 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d|%d retry %d lid %d\n",
874 __func__, fcport->port_name, fcport->disc_state,
875 fcport->fw_login_state, fcport->login_pause, fcport->flags,
876 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
877 fcport->last_login_gen, fcport->login_gen, fcport->login_retry,
878 fcport->loop_id);
879
880 fcport->login_retry--;
881
882 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
883 (fcport->fw_login_state == DSC_LS_PLOGI_COMP) ||
884 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
885 return 0;
886
887 /* for pure Target Mode. Login will not be initiated */
888 if (vha->host->active_mode == MODE_TARGET)
889 return 0;
890
891 if (fcport->flags & FCF_ASYNC_SENT) {
892 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
893 return 0;
894 }
895
896 switch (fcport->disc_state) {
897 case DSC_DELETED:
898 if (fcport->loop_id == FC_NO_LOOP_ID) {
899 ql_dbg(ql_dbg_disc, vha, 0xffff,
900 "%s %d %8phC post gnl\n",
901 __func__, __LINE__, fcport->port_name);
902 qla24xx_async_gnl(vha, fcport);
903 } else {
904 ql_dbg(ql_dbg_disc, vha, 0xffff,
905 "%s %d %8phC post login\n",
906 __func__, __LINE__, fcport->port_name);
907 fcport->disc_state = DSC_LOGIN_PEND;
908 qla2x00_post_async_login_work(vha, fcport, NULL);
909 }
910 break;
911
912 case DSC_GNL:
913 if (fcport->login_pause) {
914 fcport->last_rscn_gen = fcport->rscn_gen;
915 fcport->last_login_gen = fcport->login_gen;
916 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
917 break;
918 }
919
920 if (fcport->flags & FCF_FCP2_DEVICE) {
921 u8 opt = PDO_FORCE_ADISC;
922
923 ql_dbg(ql_dbg_disc, vha, 0xffff,
924 "%s %d %8phC post gpdb\n",
925 __func__, __LINE__, fcport->port_name);
926
927 fcport->disc_state = DSC_GPDB;
928 qla24xx_post_gpdb_work(vha, fcport, opt);
929 } else {
930 ql_dbg(ql_dbg_disc, vha, 0xffff,
931 "%s %d %8phC post login \n",
932 __func__, __LINE__, fcport->port_name);
933 fcport->disc_state = DSC_LOGIN_PEND;
934 qla2x00_post_async_login_work(vha, fcport, NULL);
935 }
936
937 break;
938
939 case DSC_LOGIN_FAILED:
940 ql_dbg(ql_dbg_disc, vha, 0xffff,
941 "%s %d %8phC post gidpn \n",
942 __func__, __LINE__, fcport->port_name);
943
944 qla24xx_post_gidpn_work(vha, fcport);
945 break;
946
947 case DSC_LOGIN_COMPLETE:
948 /* recheck login state */
949 ql_dbg(ql_dbg_disc, vha, 0xffff,
950 "%s %d %8phC post gpdb \n",
951 __func__, __LINE__, fcport->port_name);
952
953 qla24xx_post_gpdb_work(vha, fcport, PDO_FORCE_ADISC);
954 break;
955
956 default:
957 break;
958 }
959
960 return 0;
961}
962
963static
964void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea)
965{
966 fcport->rscn_gen++;
967
968 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
969 "%s %8phC DS %d LS %d\n",
970 __func__, fcport->port_name, fcport->disc_state,
971 fcport->fw_login_state);
972
973 if (fcport->flags & FCF_ASYNC_SENT)
974 return;
975
976 switch (fcport->disc_state) {
977 case DSC_DELETED:
978 case DSC_LOGIN_COMPLETE:
979 qla24xx_post_gidpn_work(fcport->vha, fcport);
980 break;
981
982 default:
983 break;
984 }
985}
986
987int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
988 u8 *port_name, void *pla)
989{
990 struct qla_work_evt *e;
991 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
992 if (!e)
993 return QLA_FUNCTION_FAILED;
994
995 e->u.new_sess.id = *id;
996 e->u.new_sess.pla = pla;
997 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
998
999 return qla2x00_post_work(vha, e);
1000}
1001
1002static
1003int qla24xx_handle_delete_done_event(scsi_qla_host_t *vha,
1004 struct event_arg *ea)
1005{
1006 fc_port_t *fcport = ea->fcport;
1007
1008 if (test_bit(UNLOADING, &vha->dpc_flags))
1009 return 0;
1010
1011 switch (vha->host->active_mode) {
1012 case MODE_INITIATOR:
1013 case MODE_DUAL:
1014 if (fcport->scan_state == QLA_FCPORT_FOUND)
1015 qla24xx_fcport_handle_login(vha, fcport);
1016 break;
1017
1018 case MODE_TARGET:
1019 default:
1020 /* no-op */
1021 break;
1022 }
1023
1024 return 0;
1025}
1026
1027static
1028void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1029 struct event_arg *ea)
1030{
1031 fc_port_t *fcport = ea->fcport;
1032
1033 if (fcport->scan_state != QLA_FCPORT_FOUND) {
1034 fcport->login_retry++;
1035 return;
1036 }
1037
1038 ql_dbg(ql_dbg_disc, vha, 0xffff,
1039 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1040 __func__, fcport->port_name, fcport->disc_state,
1041 fcport->fw_login_state, fcport->login_pause,
1042 fcport->deleted, fcport->conflict,
1043 fcport->last_rscn_gen, fcport->rscn_gen,
1044 fcport->last_login_gen, fcport->login_gen,
1045 fcport->flags);
1046
1047 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1048 (fcport->fw_login_state == DSC_LS_PLOGI_COMP) ||
1049 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1050 return;
1051
1052 if (fcport->flags & FCF_ASYNC_SENT) {
1053 fcport->login_retry++;
1054 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1055 return;
1056 }
1057
1058 if (fcport->disc_state == DSC_DELETE_PEND) {
1059 fcport->login_retry++;
1060 return;
1061 }
1062
1063 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1064 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC post gidpn\n",
1065 __func__, __LINE__, fcport->port_name);
1066
1067 qla24xx_async_gidpn(vha, fcport);
1068 return;
1069 }
1070
1071 qla24xx_fcport_handle_login(vha, fcport);
1072}
1073
Quinn Tran41dc5292017-01-19 22:28:03 -08001074void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
Quinn Tran726b8542017-01-19 22:28:00 -08001075{
Quinn Tran41dc5292017-01-19 22:28:03 -08001076 fc_port_t *fcport, *f, *tf;
1077 uint32_t id = 0, mask, rid;
Quinn Tran726b8542017-01-19 22:28:00 -08001078 int rc;
1079
1080 switch (ea->event) {
1081 case FCME_RELOGIN:
1082 if (test_bit(UNLOADING, &vha->dpc_flags))
1083 return;
1084
1085 qla24xx_handle_relogin_event(vha, ea);
1086 break;
1087 case FCME_RSCN:
1088 if (test_bit(UNLOADING, &vha->dpc_flags))
1089 return;
Quinn Tran41dc5292017-01-19 22:28:03 -08001090 switch (ea->id.b.rsvd_1) {
1091 case RSCN_PORT_ADDR:
1092 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1093 if (!fcport) {
1094 /* cable moved */
1095 rc = qla24xx_post_gpnid_work(vha, &ea->id);
1096 if (rc) {
1097 ql_log(ql_log_warn, vha, 0xffff,
1098 "RSCN GPNID work failed %02x%02x%02x\n",
1099 ea->id.b.domain, ea->id.b.area,
1100 ea->id.b.al_pa);
1101 }
1102 } else {
1103 ea->fcport = fcport;
1104 qla24xx_handle_rscn_event(fcport, ea);
Quinn Tran726b8542017-01-19 22:28:00 -08001105 }
Quinn Tran41dc5292017-01-19 22:28:03 -08001106 break;
1107 case RSCN_AREA_ADDR:
1108 case RSCN_DOM_ADDR:
1109 if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) {
1110 mask = 0xffff00;
1111 ql_log(ql_dbg_async, vha, 0xffff,
1112 "RSCN: Area 0x%06x was affected\n",
1113 ea->id.b24);
1114 } else {
1115 mask = 0xff0000;
1116 ql_log(ql_dbg_async, vha, 0xffff,
1117 "RSCN: Domain 0x%06x was affected\n",
1118 ea->id.b24);
1119 }
1120
1121 rid = ea->id.b24 & mask;
1122 list_for_each_entry_safe(f, tf, &vha->vp_fcports,
1123 list) {
1124 id = f->d_id.b24 & mask;
1125 if (rid == id) {
1126 ea->fcport = f;
1127 qla24xx_handle_rscn_event(f, ea);
1128 }
1129 }
1130 break;
1131 case RSCN_FAB_ADDR:
1132 default:
1133 ql_log(ql_log_warn, vha, 0xffff,
1134 "RSCN: Fabric was affected. Addr format %d\n",
1135 ea->id.b.rsvd_1);
1136 qla2x00_mark_all_devices_lost(vha, 1);
1137 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1138 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Quinn Tran726b8542017-01-19 22:28:00 -08001139 }
1140 break;
1141 case FCME_GIDPN_DONE:
1142 qla24xx_handle_gidpn_event(vha, ea);
1143 break;
1144 case FCME_GNL_DONE:
1145 qla24xx_handle_gnl_done_event(vha, ea);
1146 break;
1147 case FCME_GPSC_DONE:
1148 qla24xx_post_upd_fcport_work(vha, ea->fcport);
1149 break;
1150 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1151 qla24xx_handle_plogi_done_event(vha, ea);
1152 break;
1153 case FCME_GPDB_DONE:
1154 qla24xx_handle_gpdb_event(vha, ea);
1155 break;
1156 case FCME_GPNID_DONE:
1157 qla24xx_handle_gpnid_event(vha, ea);
1158 break;
1159 case FCME_DELETE_DONE:
1160 qla24xx_handle_delete_done_event(vha, ea);
1161 break;
1162 default:
1163 BUG_ON(1);
1164 break;
1165 }
1166}
1167
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001168static void
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001169qla2x00_tmf_iocb_timeout(void *data)
1170{
1171 srb_t *sp = (srb_t *)data;
1172 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1173
1174 tmf->u.tmf.comp_status = CS_TIMEOUT;
1175 complete(&tmf->u.tmf.comp);
1176}
1177
1178static void
1179qla2x00_tmf_sp_done(void *data, void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001180{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001181 srb_t *sp = (srb_t *)ptr;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001182 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1183 complete(&tmf->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001184}
1185
1186int
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001187qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001188 uint32_t tag)
1189{
1190 struct scsi_qla_host *vha = fcport->vha;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001191 struct srb_iocb *tm_iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001192 srb_t *sp;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001193 int rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001194
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001195 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001196 if (!sp)
1197 goto done;
1198
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001199 tm_iocb = &sp->u.iocb_cmd;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001200 sp->type = SRB_TM_CMD;
1201 sp->name = "tmf";
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001202 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1203 tm_iocb->u.tmf.flags = flags;
1204 tm_iocb->u.tmf.lun = lun;
1205 tm_iocb->u.tmf.data = tag;
1206 sp->done = qla2x00_tmf_sp_done;
1207 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1208 init_completion(&tm_iocb->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001209
1210 rval = qla2x00_start_sp(sp);
1211 if (rval != QLA_SUCCESS)
1212 goto done_free_sp;
1213
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001214 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001215 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1216 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1217 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001218
1219 wait_for_completion(&tm_iocb->u.tmf.comp);
1220
1221 rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
1222 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1223
1224 if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
1225 ql_dbg(ql_dbg_taskm, vha, 0x8030,
1226 "TM IOCB failed (%x).\n", rval);
1227 }
1228
1229 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1230 flags = tm_iocb->u.tmf.flags;
1231 lun = (uint16_t)tm_iocb->u.tmf.lun;
1232
1233 /* Issue Marker IOCB */
1234 qla2x00_marker(vha, vha->hw->req_q_map[0],
1235 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
1236 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1237 }
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001238
1239done_free_sp:
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001240 sp->free(vha, sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001241done:
1242 return rval;
1243}
1244
Armen Baloyan4440e462014-02-26 04:15:18 -05001245static void
1246qla24xx_abort_iocb_timeout(void *data)
1247{
1248 srb_t *sp = (srb_t *)data;
1249 struct srb_iocb *abt = &sp->u.iocb_cmd;
1250
1251 abt->u.abt.comp_status = CS_TIMEOUT;
1252 complete(&abt->u.abt.comp);
1253}
1254
1255static void
1256qla24xx_abort_sp_done(void *data, void *ptr, int res)
1257{
1258 srb_t *sp = (srb_t *)ptr;
1259 struct srb_iocb *abt = &sp->u.iocb_cmd;
1260
1261 complete(&abt->u.abt.comp);
1262}
1263
1264static int
1265qla24xx_async_abort_cmd(srb_t *cmd_sp)
1266{
1267 scsi_qla_host_t *vha = cmd_sp->fcport->vha;
1268 fc_port_t *fcport = cmd_sp->fcport;
1269 struct srb_iocb *abt_iocb;
1270 srb_t *sp;
1271 int rval = QLA_FUNCTION_FAILED;
1272
1273 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1274 if (!sp)
1275 goto done;
1276
1277 abt_iocb = &sp->u.iocb_cmd;
1278 sp->type = SRB_ABT_CMD;
1279 sp->name = "abort";
1280 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1281 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
1282 sp->done = qla24xx_abort_sp_done;
1283 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
1284 init_completion(&abt_iocb->u.abt.comp);
1285
1286 rval = qla2x00_start_sp(sp);
1287 if (rval != QLA_SUCCESS)
1288 goto done_free_sp;
1289
1290 ql_dbg(ql_dbg_async, vha, 0x507c,
1291 "Abort command issued - hdl=%x, target_id=%x\n",
1292 cmd_sp->handle, fcport->tgt_id);
1293
1294 wait_for_completion(&abt_iocb->u.abt.comp);
1295
1296 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
1297 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1298
1299done_free_sp:
1300 sp->free(vha, sp);
1301done:
1302 return rval;
1303}
1304
1305int
1306qla24xx_async_abort_command(srb_t *sp)
1307{
1308 unsigned long flags = 0;
1309
1310 uint32_t handle;
1311 fc_port_t *fcport = sp->fcport;
1312 struct scsi_qla_host *vha = fcport->vha;
1313 struct qla_hw_data *ha = vha->hw;
1314 struct req_que *req = vha->req;
1315
1316 spin_lock_irqsave(&ha->hardware_lock, flags);
1317 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1318 if (req->outstanding_cmds[handle] == sp)
1319 break;
1320 }
1321 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1322 if (handle == req->num_outstanding_cmds) {
1323 /* Command not found. */
1324 return QLA_FUNCTION_FAILED;
1325 }
1326 if (sp->type == SRB_FXIOCB_DCMD)
1327 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1328 FXDISC_ABORT_IOCTL);
1329
1330 return qla24xx_async_abort_cmd(sp);
1331}
1332
Quinn Tran726b8542017-01-19 22:28:00 -08001333static void
1334qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001335{
Quinn Tran726b8542017-01-19 22:28:00 -08001336 port_id_t cid; /* conflict Nport id */
Andrew Vasquezac280b62009-08-20 11:06:05 -07001337
Quinn Tran726b8542017-01-19 22:28:00 -08001338 switch (ea->data[0]) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07001339 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -07001340 /*
1341 * Driver must validate login state - If PRLI not complete,
1342 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1343 * requests.
1344 */
Quinn Tran726b8542017-01-19 22:28:00 -08001345 ql_dbg(ql_dbg_disc, vha, 0xffff,
1346 "%s %d %8phC post gpdb\n",
1347 __func__, __LINE__, ea->fcport->port_name);
1348 ea->fcport->chip_reset = vha->hw->chip_reset;
1349 ea->fcport->logout_on_delete = 1;
1350 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001351 break;
1352 case MBS_COMMAND_ERROR:
Quinn Tran726b8542017-01-19 22:28:00 -08001353 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC cmd error %x\n",
1354 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
1355
1356 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1357 ea->fcport->disc_state = DSC_LOGIN_FAILED;
1358 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001359 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1360 else
Quinn Tran726b8542017-01-19 22:28:00 -08001361 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001362 break;
1363 case MBS_LOOP_ID_USED:
Quinn Tran726b8542017-01-19 22:28:00 -08001364 /* data[1] = IO PARAM 1 = nport ID */
1365 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
1366 cid.b.area = (ea->iop[1] >> 8) & 0xff;
1367 cid.b.al_pa = ea->iop[1] & 0xff;
1368 cid.b.rsvd_1 = 0;
1369
1370 ql_dbg(ql_dbg_disc, vha, 0xffff,
1371 "%s %d %8phC LoopID 0x%x in use post gnl\n",
1372 __func__, __LINE__, ea->fcport->port_name,
1373 ea->fcport->loop_id);
1374
1375 if (IS_SW_RESV_ADDR(cid)) {
1376 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1377 ea->fcport->loop_id = FC_NO_LOOP_ID;
1378 } else {
1379 qla2x00_clear_loop_id(ea->fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001380 }
Quinn Tran726b8542017-01-19 22:28:00 -08001381 qla24xx_post_gnl_work(vha, ea->fcport);
1382 break;
1383 case MBS_PORT_ID_USED:
1384 ql_dbg(ql_dbg_disc, vha, 0xffff,
1385 "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n",
1386 __func__, __LINE__, ea->fcport->port_name,
1387 ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area,
1388 ea->fcport->d_id.b.al_pa);
1389
1390 qla2x00_clear_loop_id(ea->fcport);
1391 qla24xx_post_gidpn_work(vha, ea->fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001392 break;
1393 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001394 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001395}
1396
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001397void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001398qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1399 uint16_t *data)
1400{
Quinn Tran726b8542017-01-19 22:28:00 -08001401 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Alexei Potashnika6ca8872015-07-14 16:00:44 -04001402 qlt_logo_completion_handler(fcport, data[0]);
Quinn Tran726b8542017-01-19 22:28:00 -08001403 fcport->login_gen++;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001404 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001405}
1406
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001407void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001408qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1409 uint16_t *data)
1410{
1411 if (data[0] == MBS_COMMAND_COMPLETE) {
1412 qla2x00_update_fcport(vha, fcport);
1413
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001414 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001415 }
1416
1417 /* Retry login. */
1418 fcport->flags &= ~FCF_ASYNC_SENT;
1419 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
1420 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1421 else
Andrew Vasquez80d79442011-03-30 11:46:17 -07001422 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001423
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001424 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001425}
1426
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427/****************************************************************************/
1428/* QLogic ISP2x00 Hardware Support Functions. */
1429/****************************************************************************/
1430
Saurav Kashyapfa492632012-11-21 02:40:29 -05001431static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001432qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
1433{
1434 int rval = QLA_SUCCESS;
1435 struct qla_hw_data *ha = vha->hw;
1436 uint32_t idc_major_ver, idc_minor_ver;
Saurav Kashyap711aa7f2012-08-22 14:21:15 -04001437 uint16_t config[4];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001438
1439 qla83xx_idc_lock(vha, 0);
1440
1441 /* SV: TODO: Assign initialization timeout from
1442 * flash-info / other param
1443 */
1444 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
1445 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
1446
1447 /* Set our fcoe function presence */
1448 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
1449 ql_dbg(ql_dbg_p3p, vha, 0xb077,
1450 "Error while setting DRV-Presence.\n");
1451 rval = QLA_FUNCTION_FAILED;
1452 goto exit;
1453 }
1454
1455 /* Decide the reset ownership */
1456 qla83xx_reset_ownership(vha);
1457
1458 /*
1459 * On first protocol driver load:
1460 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
1461 * register.
1462 * Others: Check compatibility with current IDC Major version.
1463 */
1464 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
1465 if (ha->flags.nic_core_reset_owner) {
1466 /* Set IDC Major version */
1467 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
1468 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
1469
1470 /* Clearing IDC-Lock-Recovery register */
1471 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
1472 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
1473 /*
1474 * Clear further IDC participation if we are not compatible with
1475 * the current IDC Major Version.
1476 */
1477 ql_log(ql_log_warn, vha, 0xb07d,
1478 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
1479 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
1480 __qla83xx_clear_drv_presence(vha);
1481 rval = QLA_FUNCTION_FAILED;
1482 goto exit;
1483 }
1484 /* Each function sets its supported Minor version. */
1485 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
1486 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
1487 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
1488
Saurav Kashyap711aa7f2012-08-22 14:21:15 -04001489 if (ha->flags.nic_core_reset_owner) {
1490 memset(config, 0, sizeof(config));
1491 if (!qla81xx_get_port_config(vha, config))
1492 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
1493 QLA8XXX_DEV_READY);
1494 }
1495
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001496 rval = qla83xx_idc_state_handler(vha);
1497
1498exit:
1499 qla83xx_idc_unlock(vha, 0);
1500
1501 return rval;
1502}
1503
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504/*
1505* qla2x00_initialize_adapter
1506* Initialize board.
1507*
1508* Input:
1509* ha = adapter block pointer.
1510*
1511* Returns:
1512* 0 = success
1513*/
1514int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001515qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516{
1517 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001518 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001519 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001520
Joe Carnucciofc90ada2016-07-06 11:14:23 -04001521 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
1522 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
1523
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001525 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001526 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001527 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -08001528 ha->flags.pci_channel_io_perm_failure = 0;
1529 ha->flags.eeh_busy = 0;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -04001530 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001531 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1532 atomic_set(&vha->loop_state, LOOP_DOWN);
1533 vha->device_flags = DFLG_NO_CABLE;
1534 vha->dpc_flags = 0;
1535 vha->flags.management_server_logged_in = 0;
1536 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 ha->isp_abort_cnt = 0;
1538 ha->beacon_blink_led = 0;
1539
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001540 set_bit(0, ha->req_qid_map);
1541 set_bit(0, ha->rsp_qid_map);
1542
Chad Dupuiscfb09192011-11-18 09:03:07 -08001543 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001544 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001545 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001547 ql_log(ql_log_warn, vha, 0x0044,
1548 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 return (rval);
1550 }
1551
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001552 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001554 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001555 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001556 ql_log(ql_log_fatal, vha, 0x004f,
1557 "Unable to validate FLASH data.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001558 return rval;
1559 }
1560
1561 if (IS_QLA8044(ha)) {
1562 qla8044_read_reset_template(vha);
1563
1564 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
1565 * If DONRESET_BIT0 is set, drivers should not set dev_state
1566 * to NEED_RESET. But if NEED_RESET is set, drivers should
1567 * should honor the reset. */
1568 if (ql2xdontresethba == 1)
1569 qla8044_set_idc_dontreset(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001570 }
1571
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001572 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001573 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001574 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001575
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001576 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001578 if (ha->flags.disable_serdes) {
1579 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001580 ql_log(ql_log_info, vha, 0x0077,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001581 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001582 return QLA_FUNCTION_FAILED;
1583 }
1584
Chad Dupuiscfb09192011-11-18 09:03:07 -08001585 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001586 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001588 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
1589 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001590 if (rval)
1591 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001592 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001593 if (rval)
1594 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07001596
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001597 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001598 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001599 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001600 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001601 "Unable to configure ISP84XX.\n");
1602 return QLA_FUNCTION_FAILED;
1603 }
1604 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001605
Quinn Tranead03852017-01-19 22:28:01 -08001606 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001607 rval = qla2x00_init_rings(vha);
1608
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001609 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001611 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001612 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001613 rval = qla84xx_init_chip(vha);
1614 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001615 ql_log(ql_log_warn, vha, 0x00d4,
1616 "Unable to initialize ISP84XX.\n");
Bart Van Assche8d2b21d2015-06-04 15:58:09 -07001617 qla84xx_put_chip(vha);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001618 }
1619 }
1620
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001621 /* Load the NIC Core f/w if we are the first protocol driver. */
1622 if (IS_QLA8031(ha)) {
1623 rval = qla83xx_nic_core_fw_load(vha);
1624 if (rval)
1625 ql_log(ql_log_warn, vha, 0x0124,
1626 "Error in initializing NIC Core f/w.\n");
1627 }
1628
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +05001629 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
1630 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -07001631
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04001632 if (IS_P3P_TYPE(ha))
1633 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
1634 else
1635 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
1636
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 return (rval);
1638}
1639
1640/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001641 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 * @ha: HA context
1643 *
1644 * Returns 0 on success.
1645 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001646int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001647qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001649 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001650 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001651 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001652 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001655 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001658 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1660
Andrew Vasquez737faec2008-10-24 15:13:45 -07001661 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001663 /* Get PCI bus information. */
1664 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07001665 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001666 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1667
1668 return QLA_SUCCESS;
1669}
1670
1671/**
1672 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
1673 * @ha: HA context
1674 *
1675 * Returns 0 on success.
1676 */
1677int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001678qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001679{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001680 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001681 unsigned long flags = 0;
1682 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001683 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001684 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001685
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001686 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001687 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001688
1689 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001690 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001691
1692 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1693 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -07001694 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001695
1696 /*
1697 * If this is a 2300 card and not 2312, reset the
1698 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
1699 * the 2310 also reports itself as a 2300 so we need to get the
1700 * fb revision level -- a 6 indicates it really is a 2300 and
1701 * not a 2310.
1702 */
1703 if (IS_QLA2300(ha)) {
1704 spin_lock_irqsave(&ha->hardware_lock, flags);
1705
1706 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001707 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001708 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07001709 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001710 break;
1711
1712 udelay(10);
1713 }
1714
1715 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001716 WRT_REG_WORD(&reg->ctrl_status, 0x20);
1717 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001718
1719 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001720 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001721
1722 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -07001723 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001724
1725 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001726 WRT_REG_WORD(&reg->ctrl_status, 0x0);
1727 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001728
1729 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001730 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001731 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07001732 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001733 break;
1734
1735 udelay(10);
1736 }
1737
1738 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1739 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001740
1741 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
1742
Andrew Vasquez737faec2008-10-24 15:13:45 -07001743 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001744
1745 /* Get PCI bus information. */
1746 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07001747 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001748 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1749
1750 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751}
1752
1753/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001754 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
1755 * @ha: HA context
1756 *
1757 * Returns 0 on success.
1758 */
1759int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001760qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001761{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001762 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001763 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001764 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001765 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001766
1767 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001768 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001769
1770 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001771 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001772 w &= ~PCI_COMMAND_INTX_DISABLE;
1773 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1774
1775 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
1776
1777 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -07001778 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
1779 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001780
1781 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07001782 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04001783 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001784
Andrew Vasquez737faec2008-10-24 15:13:45 -07001785 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001786
Auke Kok44c10132007-06-08 15:46:36 -07001787 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001788
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001789 /* Get PCI bus information. */
1790 spin_lock_irqsave(&ha->hardware_lock, flags);
1791 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
1792 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1793
1794 return QLA_SUCCESS;
1795}
1796
1797/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001798 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
1799 * @ha: HA context
1800 *
1801 * Returns 0 on success.
1802 */
1803int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001804qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001805{
1806 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001807 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001808
1809 pci_set_master(ha->pdev);
1810 pci_try_set_mwi(ha->pdev);
1811
1812 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
1813 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
1814 w &= ~PCI_COMMAND_INTX_DISABLE;
1815 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1816
1817 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07001818 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04001819 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001820
Andrew Vasquez737faec2008-10-24 15:13:45 -07001821 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001822
1823 ha->chip_revision = ha->pdev->revision;
1824
1825 return QLA_SUCCESS;
1826}
1827
1828/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 * qla2x00_isp_firmware() - Choose firmware image.
1830 * @ha: HA context
1831 *
1832 * Returns 0 on success.
1833 */
1834static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001835qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836{
1837 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001838 uint16_t loop_id, topo, sw_cap;
1839 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001840 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841
1842 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001843 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
1845 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001846 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
1848 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001849 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001850 if (rval == QLA_SUCCESS) {
1851 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001852 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001853 &area, &domain, &topo, &sw_cap);
1854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 }
1856
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001857 if (rval)
1858 ql_dbg(ql_dbg_init, vha, 0x007a,
1859 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860
1861 return (rval);
1862}
1863
1864/**
1865 * qla2x00_reset_chip() - Reset ISP chip.
1866 * @ha: HA context
1867 *
1868 * Returns 0 on success.
1869 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001870void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001871qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872{
1873 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001874 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001875 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 uint16_t cmd;
1878
Andrew Vasquez85880802009-12-15 21:29:46 -08001879 if (unlikely(pci_channel_offline(ha->pdev)))
1880 return;
1881
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001882 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
1884 spin_lock_irqsave(&ha->hardware_lock, flags);
1885
1886 /* Turn off master enable */
1887 cmd = 0;
1888 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
1889 cmd &= ~PCI_COMMAND_MASTER;
1890 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
1891
1892 if (!IS_QLA2100(ha)) {
1893 /* Pause RISC. */
1894 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
1895 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
1896 for (cnt = 0; cnt < 30000; cnt++) {
1897 if ((RD_REG_WORD(&reg->hccr) &
1898 HCCR_RISC_PAUSE) != 0)
1899 break;
1900 udelay(100);
1901 }
1902 } else {
1903 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1904 udelay(10);
1905 }
1906
1907 /* Select FPM registers. */
1908 WRT_REG_WORD(&reg->ctrl_status, 0x20);
1909 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1910
1911 /* FPM Soft Reset. */
1912 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
1913 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
1914
1915 /* Toggle Fpm Reset. */
1916 if (!IS_QLA2200(ha)) {
1917 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
1918 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
1919 }
1920
1921 /* Select frame buffer registers. */
1922 WRT_REG_WORD(&reg->ctrl_status, 0x10);
1923 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1924
1925 /* Reset frame buffer FIFOs. */
1926 if (IS_QLA2200(ha)) {
1927 WRT_FB_CMD_REG(ha, reg, 0xa000);
1928 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
1929 } else {
1930 WRT_FB_CMD_REG(ha, reg, 0x00fc);
1931
1932 /* Read back fb_cmd until zero or 3 seconds max */
1933 for (cnt = 0; cnt < 3000; cnt++) {
1934 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
1935 break;
1936 udelay(100);
1937 }
1938 }
1939
1940 /* Select RISC module registers. */
1941 WRT_REG_WORD(&reg->ctrl_status, 0);
1942 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1943
1944 /* Reset RISC processor. */
1945 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1946 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1947
1948 /* Release RISC processor. */
1949 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1950 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1951 }
1952
1953 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
1954 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
1955
1956 /* Reset ISP chip. */
1957 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1958
1959 /* Wait for RISC to recover from reset. */
1960 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1961 /*
1962 * It is necessary to for a delay here since the card doesn't
1963 * respond to PCI reads during a reset. On some architectures
1964 * this will result in an MCA.
1965 */
1966 udelay(20);
1967 for (cnt = 30000; cnt; cnt--) {
1968 if ((RD_REG_WORD(&reg->ctrl_status) &
1969 CSR_ISP_SOFT_RESET) == 0)
1970 break;
1971 udelay(100);
1972 }
1973 } else
1974 udelay(10);
1975
1976 /* Reset RISC processor. */
1977 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1978
1979 WRT_REG_WORD(&reg->semaphore, 0);
1980
1981 /* Release RISC processor. */
1982 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1983 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1984
1985 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1986 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -07001987 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
1990 udelay(100);
1991 }
1992 } else
1993 udelay(100);
1994
1995 /* Turn on master enable */
1996 cmd |= PCI_COMMAND_MASTER;
1997 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
1998
1999 /* Disable RISC pause on FPM parity error. */
2000 if (!IS_QLA2100(ha)) {
2001 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
2002 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2003 }
2004
2005 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2006}
2007
2008/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002009 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2010 *
2011 * Returns 0 on success.
2012 */
Saurav Kashyapfa492632012-11-21 02:40:29 -05002013static int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002014qla81xx_reset_mpi(scsi_qla_host_t *vha)
2015{
2016 uint16_t mb[4] = {0x1010, 0, 1, 0};
2017
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002018 if (!IS_QLA81XX(vha->hw))
2019 return QLA_SUCCESS;
2020
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002021 return qla81xx_write_mpi_register(vha, mb);
2022}
2023
2024/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002025 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002026 * @ha: HA context
2027 *
2028 * Returns 0 on success.
2029 */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002030static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002031qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002032{
2033 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002034 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002035 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Bart Van Assche52c82822015-07-09 07:23:26 -07002036 uint32_t cnt;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002037 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002038 static int abts_cnt; /* ISP abort retry counts */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002039 int rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002040
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002041 spin_lock_irqsave(&ha->hardware_lock, flags);
2042
2043 /* Reset RISC. */
2044 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2045 for (cnt = 0; cnt < 30000; cnt++) {
2046 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2047 break;
2048
2049 udelay(10);
2050 }
2051
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002052 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE))
2053 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2054
2055 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2056 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2057 RD_REG_DWORD(&reg->hccr),
2058 RD_REG_DWORD(&reg->ctrl_status),
2059 (RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE));
2060
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002061 WRT_REG_DWORD(&reg->ctrl_status,
2062 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002063 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002064
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002065 udelay(100);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002066
Andrew Vasquez88c26662005-07-08 17:59:26 -07002067 /* Wait for firmware to complete NVRAM accesses. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002068 RD_REG_WORD(&reg->mailbox0);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002069 for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
2070 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez88c26662005-07-08 17:59:26 -07002071 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002072 if (cnt)
2073 udelay(5);
2074 else
2075 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez88c26662005-07-08 17:59:26 -07002076 }
2077
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002078 if (rval == QLA_SUCCESS)
2079 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2080
2081 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2082 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2083 RD_REG_DWORD(&reg->hccr),
2084 RD_REG_DWORD(&reg->mailbox0));
2085
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002086 /* Wait for soft-reset to complete. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002087 RD_REG_DWORD(&reg->ctrl_status);
Quinn Tran200ffb12016-12-23 18:06:12 -08002088 for (cnt = 0; cnt < 60; cnt++) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002089 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002090 if ((RD_REG_DWORD(&reg->ctrl_status) &
2091 CSRX_ISP_SOFT_RESET) == 0)
2092 break;
2093
2094 udelay(5);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002095 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002096 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_ISP_SOFT_RESET))
2097 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2098
2099 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2100 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2101 RD_REG_DWORD(&reg->hccr),
2102 RD_REG_DWORD(&reg->ctrl_status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002103
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002104 /* If required, do an MPI FW reset now */
2105 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2106 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2107 if (++abts_cnt < 5) {
2108 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2109 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2110 } else {
2111 /*
2112 * We exhausted the ISP abort retries. We have to
2113 * set the board offline.
2114 */
2115 abts_cnt = 0;
2116 vha->flags.online = 0;
2117 }
2118 }
2119 }
2120
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002121 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
2122 RD_REG_DWORD(&reg->hccr);
2123
2124 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
2125 RD_REG_DWORD(&reg->hccr);
2126
2127 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
2128 RD_REG_DWORD(&reg->hccr);
2129
Bart Van Assche52c82822015-07-09 07:23:26 -07002130 RD_REG_WORD(&reg->mailbox0);
Quinn Tran200ffb12016-12-23 18:06:12 -08002131 for (cnt = 60; RD_REG_WORD(&reg->mailbox0) != 0 &&
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002132 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002133 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002134 if (cnt)
2135 udelay(5);
2136 else
2137 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002138 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002139 if (rval == QLA_SUCCESS)
2140 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2141
2142 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2143 "Host Risc 0x%x, mailbox0 0x%x\n",
2144 RD_REG_DWORD(&reg->hccr),
2145 RD_REG_WORD(&reg->mailbox0));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002146
2147 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002148
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002149 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2150 "Driver in %s mode\n",
2151 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2152
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002153 if (IS_NOPOLLING_TYPE(ha))
2154 ha->isp_ops->enable_intrs(ha);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002155
2156 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002157}
2158
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002159static void
2160qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2161{
2162 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2163
2164 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2165 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2166
2167}
2168
2169static void
2170qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2171{
2172 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2173
2174 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2175 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2176}
2177
2178static void
2179qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2180{
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002181 uint32_t wd32 = 0;
2182 uint delta_msec = 100;
2183 uint elapsed_msec = 0;
2184 uint timeout_msec;
2185 ulong n;
2186
Joe Carnucciocc790762015-08-04 13:37:53 -04002187 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2188 vha->hw->pdev->subsystem_device != 0x0240)
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002189 return;
2190
Joe Carnuccio8dd7e3a2015-08-04 13:37:54 -04002191 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2192 udelay(100);
2193
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002194attempt:
2195 timeout_msec = TIMEOUT_SEMAPHORE;
2196 n = timeout_msec / delta_msec;
2197 while (n--) {
2198 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2199 qla25xx_read_risc_sema_reg(vha, &wd32);
2200 if (wd32 & RISC_SEMAPHORE)
2201 break;
2202 msleep(delta_msec);
2203 elapsed_msec += delta_msec;
2204 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2205 goto force;
2206 }
2207
2208 if (!(wd32 & RISC_SEMAPHORE))
2209 goto force;
2210
2211 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2212 goto acquired;
2213
2214 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2215 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2216 n = timeout_msec / delta_msec;
2217 while (n--) {
2218 qla25xx_read_risc_sema_reg(vha, &wd32);
2219 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2220 break;
2221 msleep(delta_msec);
2222 elapsed_msec += delta_msec;
2223 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2224 goto force;
2225 }
2226
2227 if (wd32 & RISC_SEMAPHORE_FORCE)
2228 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2229
2230 goto attempt;
2231
2232force:
2233 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2234
2235acquired:
2236 return;
2237}
2238
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002239/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002240 * qla24xx_reset_chip() - Reset ISP24xx chip.
2241 * @ha: HA context
2242 *
2243 * Returns 0 on success.
2244 */
2245void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002246qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07002247{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002248 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08002249
2250 if (pci_channel_offline(ha->pdev) &&
2251 ha->flags.pci_channel_io_perm_failure) {
2252 return;
2253 }
2254
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002255 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002256
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002257 qla25xx_manipulate_risc_semaphore(vha);
2258
Andrew Vasquez88c26662005-07-08 17:59:26 -07002259 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002260 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002261}
2262
2263/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 * qla2x00_chip_diag() - Test chip for proper operation.
2265 * @ha: HA context
2266 *
2267 * Returns 0 on success.
2268 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002269int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002270qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271{
2272 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002273 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002274 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 unsigned long flags = 0;
2276 uint16_t data;
2277 uint32_t cnt;
2278 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002279 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
2281 /* Assume a failed state */
2282 rval = QLA_FUNCTION_FAILED;
2283
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002284 ql_dbg(ql_dbg_init, vha, 0x007b,
2285 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286
2287 spin_lock_irqsave(&ha->hardware_lock, flags);
2288
2289 /* Reset ISP chip. */
2290 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
2291
2292 /*
2293 * We need to have a delay here since the card will not respond while
2294 * in reset causing an MCA on some architectures.
2295 */
2296 udelay(20);
2297 data = qla2x00_debounce_register(&reg->ctrl_status);
2298 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2299 udelay(5);
2300 data = RD_REG_WORD(&reg->ctrl_status);
2301 barrier();
2302 }
2303
2304 if (!cnt)
2305 goto chip_diag_failed;
2306
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002307 ql_dbg(ql_dbg_init, vha, 0x007c,
2308 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309
2310 /* Reset RISC processor. */
2311 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2312 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2313
2314 /* Workaround for QLA2312 PCI parity error */
2315 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2316 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2317 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2318 udelay(5);
2319 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002320 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 }
2322 } else
2323 udelay(10);
2324
2325 if (!cnt)
2326 goto chip_diag_failed;
2327
2328 /* Check product ID of chip */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002329 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
2331 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
2332 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
2333 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
2334 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
2335 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
2336 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002337 ql_log(ql_log_warn, vha, 0x0062,
2338 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2339 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340
2341 goto chip_diag_failed;
2342 }
2343 ha->product_id[0] = mb[1];
2344 ha->product_id[1] = mb[2];
2345 ha->product_id[2] = mb[3];
2346 ha->product_id[3] = mb[4];
2347
2348 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002349 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
2351 else
2352 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002353 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
2355 if (IS_QLA2200(ha) &&
2356 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
2357 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002358 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002360 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 ha->fw_transfer_size = 128;
2362 }
2363
2364 /* Wrap Incoming Mailboxes Test. */
2365 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2366
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002367 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002368 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002369 if (rval)
2370 ql_log(ql_log_warn, vha, 0x0080,
2371 "Failed mailbox send register test.\n");
2372 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 /* Flag a successful rval */
2374 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 spin_lock_irqsave(&ha->hardware_lock, flags);
2376
2377chip_diag_failed:
2378 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002379 ql_log(ql_log_info, vha, 0x0081,
2380 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
2382 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2383
2384 return (rval);
2385}
2386
2387/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002388 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2389 * @ha: HA context
2390 *
2391 * Returns 0 on success.
2392 */
2393int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002394qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002395{
2396 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002397 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002398 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002399
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002400 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07002401 return QLA_SUCCESS;
2402
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002403 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002404
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002405 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002406 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002407 ql_log(ql_log_warn, vha, 0x0082,
2408 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002409 } else {
2410 /* Flag a successful rval */
2411 rval = QLA_SUCCESS;
2412 }
2413
2414 return rval;
2415}
2416
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002417void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002418qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002419{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002420 int rval;
2421 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002422 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002423 dma_addr_t tc_dma;
2424 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002425 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002426 struct req_que *req = ha->req_q_map[0];
2427 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002428
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002429 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002430 ql_dbg(ql_dbg_init, vha, 0x00bd,
2431 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002432 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002433 }
2434
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002435 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04002436 ha->fw_dump_cap_flags = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002437 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
2438 req_q_size = rsp_q_size = 0;
2439
2440 if (IS_QLA27XX(ha))
2441 goto try_fce;
2442
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002443 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2444 fixed_size = sizeof(struct qla2100_fw_dump);
2445 } else if (IS_QLA23XX(ha)) {
2446 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
2447 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
2448 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07002449 } else if (IS_FWI2_CAPABLE(ha)) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002450 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002451 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
2452 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002453 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
2454 else if (IS_QLA25XX(ha))
2455 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
2456 else
2457 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002458
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002459 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
2460 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002461 if (ha->mqenable) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002462 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002463 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002464 /*
2465 * Allocate maximum buffer size for all queues.
2466 * Resizing must be done at end-of-dump processing.
2467 */
2468 mq_size += ha->max_req_queues *
2469 (req->length * sizeof(request_t));
2470 mq_size += ha->max_rsp_queues *
2471 (rsp->length * sizeof(response_t));
2472 }
Arun Easi00876ae2013-03-25 02:21:37 -04002473 if (ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002474 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002475 /* Allocate memory for Fibre Channel Event Buffer. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05002476 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2477 !IS_QLA27XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002478 goto try_eft;
2479
Chad Dupuisf73cb692014-02-26 04:15:06 -05002480try_fce:
2481 if (ha->fce)
2482 dma_free_coherent(&ha->pdev->dev,
2483 FCE_SIZE, ha->fce, ha->fce_dma);
2484
2485 /* Allocate memory for Fibre Channel Event Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07002486 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
2487 GFP_KERNEL);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002488 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002489 ql_log(ql_log_warn, vha, 0x00be,
2490 "Unable to allocate (%d KB) for FCE.\n",
2491 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002492 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002493 }
2494
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002495 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002496 ha->fce_mb, &ha->fce_bufs);
2497 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002498 ql_log(ql_log_warn, vha, 0x00bf,
2499 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002500 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
2501 tc_dma);
2502 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002503 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002504 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002505 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002506 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002507
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07002508 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002509 ha->flags.fce_enabled = 1;
2510 ha->fce_dma = tc_dma;
2511 ha->fce = tc;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002512
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002513try_eft:
Chad Dupuisf73cb692014-02-26 04:15:06 -05002514 if (ha->eft)
2515 dma_free_coherent(&ha->pdev->dev,
2516 EFT_SIZE, ha->eft, ha->eft_dma);
2517
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002518 /* Allocate memory for Extended Trace Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07002519 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
2520 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002521 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002522 ql_log(ql_log_warn, vha, 0x00c1,
2523 "Unable to allocate (%d KB) for EFT.\n",
2524 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002525 goto cont_alloc;
2526 }
2527
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002528 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002529 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002530 ql_log(ql_log_warn, vha, 0x00c2,
2531 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002532 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
2533 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002534 goto cont_alloc;
2535 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002536 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002537 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002538
2539 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002540 ha->eft_dma = tc_dma;
2541 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002542 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05002543
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002544cont_alloc:
Chad Dupuisf73cb692014-02-26 04:15:06 -05002545 if (IS_QLA27XX(ha)) {
2546 if (!ha->fw_dump_template) {
2547 ql_log(ql_log_warn, vha, 0x00ba,
2548 "Failed missing fwdump template\n");
2549 return;
2550 }
2551 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
2552 ql_dbg(ql_dbg_init, vha, 0x00fa,
2553 "-> allocating fwdump (%x bytes)...\n", dump_size);
2554 goto allocate;
2555 }
2556
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002557 req_q_size = req->length * sizeof(request_t);
2558 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002559 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002560 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08002561 ha->chain_offset = dump_size;
2562 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002563
Chad Dupuisf73cb692014-02-26 04:15:06 -05002564allocate:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002565 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002566 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002567 ql_log(ql_log_warn, vha, 0x00c4,
2568 "Unable to allocate (%d KB) for firmware dump.\n",
2569 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002570
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002571 if (ha->fce) {
2572 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2573 ha->fce_dma);
2574 ha->fce = NULL;
2575 ha->fce_dma = 0;
2576 }
2577
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002578 if (ha->eft) {
2579 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
2580 ha->eft_dma);
2581 ha->eft = NULL;
2582 ha->eft_dma = 0;
2583 }
2584 return;
2585 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05002586 ha->fw_dump_len = dump_size;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002587 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002588 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002589
Chad Dupuisf73cb692014-02-26 04:15:06 -05002590 if (IS_QLA27XX(ha))
2591 return;
2592
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002593 ha->fw_dump->signature[0] = 'Q';
2594 ha->fw_dump->signature[1] = 'L';
2595 ha->fw_dump->signature[2] = 'G';
2596 ha->fw_dump->signature[3] = 'C';
Bart Van Asschead950362015-07-09 07:24:08 -07002597 ha->fw_dump->version = htonl(1);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002598
2599 ha->fw_dump->fixed_size = htonl(fixed_size);
2600 ha->fw_dump->mem_size = htonl(mem_size);
2601 ha->fw_dump->req_q_size = htonl(req_q_size);
2602 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
2603
2604 ha->fw_dump->eft_size = htonl(eft_size);
2605 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
2606 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
2607
2608 ha->fw_dump->header_size =
2609 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002610}
2611
Andrew Vasquez18e75552009-06-03 09:55:30 -07002612static int
2613qla81xx_mpi_sync(scsi_qla_host_t *vha)
2614{
2615#define MPS_MASK 0xe0
2616 int rval;
2617 uint16_t dc;
2618 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07002619
2620 if (!IS_QLA81XX(vha->hw))
2621 return QLA_SUCCESS;
2622
2623 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
2624 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002625 ql_log(ql_log_warn, vha, 0x0105,
2626 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002627 goto done;
2628 }
2629
2630 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
2631 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
2632 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002633 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002634 goto done_release;
2635 }
2636
2637 dc &= MPS_MASK;
2638 if (dc == (dw & MPS_MASK))
2639 goto done_release;
2640
2641 dw &= ~MPS_MASK;
2642 dw |= dc;
2643 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
2644 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002645 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002646 }
2647
2648done_release:
2649 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
2650 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002651 ql_log(ql_log_warn, vha, 0x006d,
2652 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002653 }
2654
2655done:
2656 return rval;
2657}
2658
Chad Dupuis8d93f552013-01-30 03:34:37 -05002659int
2660qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
2661{
2662 /* Don't try to reallocate the array */
2663 if (req->outstanding_cmds)
2664 return QLA_SUCCESS;
2665
Michael Hernandezd7459522016-12-12 14:40:07 -08002666 if (!IS_FWI2_CAPABLE(ha))
Chad Dupuis8d93f552013-01-30 03:34:37 -05002667 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
2668 else {
Quinn Tran03e8c682015-12-17 14:56:59 -05002669 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
2670 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002671 else
Quinn Tran03e8c682015-12-17 14:56:59 -05002672 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002673 }
2674
2675 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
2676 req->num_outstanding_cmds, GFP_KERNEL);
2677
2678 if (!req->outstanding_cmds) {
2679 /*
2680 * Try to allocate a minimal size just so we can get through
2681 * initialization.
2682 */
2683 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
2684 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
2685 req->num_outstanding_cmds, GFP_KERNEL);
2686
2687 if (!req->outstanding_cmds) {
2688 ql_log(ql_log_fatal, NULL, 0x0126,
2689 "Failed to allocate memory for "
2690 "outstanding_cmds for req_que %p.\n", req);
2691 req->num_outstanding_cmds = 0;
2692 return QLA_FUNCTION_FAILED;
2693 }
2694 }
2695
2696 return QLA_SUCCESS;
2697}
2698
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002699/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 * qla2x00_setup_chip() - Load and start RISC firmware.
2701 * @ha: HA context
2702 *
2703 * Returns 0 on success.
2704 */
2705static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002706qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002708 int rval;
2709 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002710 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08002711 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2712 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07002713 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08002714
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002715 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002716 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05002717 if (rval == QLA_SUCCESS) {
2718 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002719 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05002720 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07002721 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002722 }
2723
Andrew Vasquez3db06522008-01-31 12:33:49 -08002724 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
2725 /* Disable SRAM, Instruction RAM and GP RAM parity. */
2726 spin_lock_irqsave(&ha->hardware_lock, flags);
2727 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
2728 RD_REG_WORD(&reg->hccr);
2729 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2730 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731
Andrew Vasquez18e75552009-06-03 09:55:30 -07002732 qla81xx_mpi_sync(vha);
2733
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002735 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002736 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002737 ql_dbg(ql_dbg_init, vha, 0x00c9,
2738 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002740 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 if (rval == QLA_SUCCESS) {
2742 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002743 ql_dbg(ql_dbg_init, vha, 0x00ca,
2744 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05002746 if (ql2xexlogins)
2747 ha->flags.exlogins_enabled = 1;
2748
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05002749 if (ql2xexchoffld)
2750 ha->flags.exchoffld_enabled = 1;
2751
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002752 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07002754 if (rval == QLA_SUCCESS) {
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05002755 rval = qla2x00_set_exlogins_buffer(vha);
2756 if (rval != QLA_SUCCESS)
2757 goto failed;
2758
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05002759 rval = qla2x00_set_exchoffld_buffer(vha);
2760 if (rval != QLA_SUCCESS)
2761 goto failed;
2762
Giridhar Malavalia9083012010-04-12 17:59:55 -07002763enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07002764 fw_major_version = ha->fw_major_version;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002765 if (IS_P3P_TYPE(ha))
Giridhar Malavali31731672011-08-16 11:31:54 -07002766 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002767 else
2768 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07002769 if (rval != QLA_SUCCESS)
2770 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002771 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002772 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07002773 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002774 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002775 if ((!ha->max_npiv_vports) ||
2776 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002777 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002778 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002779 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002780 }
Quinn Tran03e8c682015-12-17 14:56:59 -05002781 qla2x00_get_resource_cnts(vha);
Andrew Vasquezd743de62009-03-24 09:08:15 -07002782
Chad Dupuis8d93f552013-01-30 03:34:37 -05002783 /*
2784 * Allocate the array of outstanding commands
2785 * now that we know the firmware resources.
2786 */
2787 rval = qla2x00_alloc_outstanding_cmds(ha,
2788 vha->req);
2789 if (rval != QLA_SUCCESS)
2790 goto failed;
2791
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08002792 if (!fw_major_version && ql2xallocfwdump
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002793 && !(IS_P3P_TYPE(ha)))
Giridhar Malavali08de2842011-08-16 11:31:44 -07002794 qla2x00_alloc_fw_dump(vha);
Chad Dupuis3b6e5b92013-10-30 03:38:09 -04002795 } else {
2796 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 }
2798 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002799 ql_log(ql_log_fatal, vha, 0x00cd,
2800 "ISP Firmware failed checksum.\n");
2801 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04002803 } else
2804 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
Andrew Vasquez3db06522008-01-31 12:33:49 -08002806 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
2807 /* Enable proper parity. */
2808 spin_lock_irqsave(&ha->hardware_lock, flags);
2809 if (IS_QLA2300(ha))
2810 /* SRAM parity */
2811 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
2812 else
2813 /* SRAM, Instruction RAM and GP RAM parity */
2814 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
2815 RD_REG_WORD(&reg->hccr);
2816 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2817 }
2818
Chad Dupuisf3982d82014-09-25 05:16:57 -04002819 if (IS_QLA27XX(ha))
2820 ha->flags.fac_supported = 1;
2821 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07002822 uint32_t size;
2823
2824 rval = qla81xx_fac_get_sector_size(vha, &size);
2825 if (rval == QLA_SUCCESS) {
2826 ha->flags.fac_supported = 1;
2827 ha->fdt_block_size = size << 2;
2828 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002829 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07002830 "Unsupported FAC firmware (%d.%02d.%02d).\n",
2831 ha->fw_major_version, ha->fw_minor_version,
2832 ha->fw_subminor_version);
Joe Carnuccio1ca60e32014-02-26 04:15:02 -05002833
Chad Dupuisf73cb692014-02-26 04:15:06 -05002834 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002835 ha->flags.fac_supported = 0;
2836 rval = QLA_SUCCESS;
2837 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07002838 }
2839 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07002840failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002842 ql_log(ql_log_fatal, vha, 0x00cf,
2843 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 }
2845
2846 return (rval);
2847}
2848
2849/**
2850 * qla2x00_init_response_q_entries() - Initializes response queue entries.
2851 * @ha: HA context
2852 *
2853 * Beginning of request ring has initialization control block already built
2854 * by nvram config routine.
2855 *
2856 * Returns 0 on success.
2857 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002858void
2859qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860{
2861 uint16_t cnt;
2862 response_t *pkt;
2863
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002864 rsp->ring_ptr = rsp->ring;
2865 rsp->ring_index = 0;
2866 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002867 pkt = rsp->ring_ptr;
2868 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 pkt->signature = RESPONSE_PROCESSED;
2870 pkt++;
2871 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872}
2873
2874/**
2875 * qla2x00_update_fw_options() - Read and process firmware options.
2876 * @ha: HA context
2877 *
2878 * Returns 0 on success.
2879 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002880void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002881qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882{
2883 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002884 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885
2886 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002887 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888
2889 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2890 return;
2891
2892 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002893 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
2894 "Serial link options.\n");
2895 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
2896 (uint8_t *)&ha->fw_seriallink_options,
2897 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898
2899 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
2900 if (ha->fw_seriallink_options[3] & BIT_2) {
2901 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
2902
2903 /* 1G settings */
2904 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
2905 emphasis = (ha->fw_seriallink_options[2] &
2906 (BIT_4 | BIT_3)) >> 3;
2907 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002908 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 rx_sens = (ha->fw_seriallink_options[0] &
2910 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
2911 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
2912 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2913 if (rx_sens == 0x0)
2914 rx_sens = 0x3;
2915 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
2916 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2917 ha->fw_options[10] |= BIT_5 |
2918 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2919 (tx_sens & (BIT_1 | BIT_0));
2920
2921 /* 2G settings */
2922 swing = (ha->fw_seriallink_options[2] &
2923 (BIT_7 | BIT_6 | BIT_5)) >> 5;
2924 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
2925 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002926 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 rx_sens = (ha->fw_seriallink_options[1] &
2928 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
2929 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
2930 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2931 if (rx_sens == 0x0)
2932 rx_sens = 0x3;
2933 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
2934 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2935 ha->fw_options[11] |= BIT_5 |
2936 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2937 (tx_sens & (BIT_1 | BIT_0));
2938 }
2939
2940 /* FCP2 options. */
2941 /* Return command IOCBs without waiting for an ABTS to complete. */
2942 ha->fw_options[3] |= BIT_13;
2943
2944 /* LED scheme. */
2945 if (ha->flags.enable_led_scheme)
2946 ha->fw_options[2] |= BIT_12;
2947
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002948 /* Detect ISP6312. */
2949 if (IS_QLA6312(ha))
2950 ha->fw_options[2] |= BIT_13;
2951
Giridhar Malavali088d09d2016-07-06 11:14:20 -04002952 /* Set Retry FLOGI in case of P2P connection */
2953 if (ha->operating_mode == P2P) {
2954 ha->fw_options[2] |= BIT_3;
2955 ql_dbg(ql_dbg_disc, vha, 0x2100,
2956 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
2957 __func__, ha->fw_options[2]);
2958 }
2959
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002961 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962}
2963
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002964void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002965qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002966{
2967 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002968 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002969
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002970 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07002971 return;
2972
Himanshu Madhanif198caf2016-01-27 12:03:30 -05002973 /* Hold status IOCBs until ABTS response received. */
2974 if (ql2xfwholdabts)
2975 ha->fw_options[3] |= BIT_12;
2976
Giridhar Malavali088d09d2016-07-06 11:14:20 -04002977 /* Set Retry FLOGI in case of P2P connection */
2978 if (ha->operating_mode == P2P) {
2979 ha->fw_options[2] |= BIT_3;
2980 ql_dbg(ql_dbg_disc, vha, 0x2101,
2981 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
2982 __func__, ha->fw_options[2]);
2983 }
2984
Quinn Tran41dc5292017-01-19 22:28:03 -08002985 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
2986 if (ql2xmvasynctoatio) {
2987 if (qla_tgt_mode_enabled(vha) ||
2988 qla_dual_mode_enabled(vha))
2989 ha->fw_options[2] |= BIT_11;
2990 else
2991 ha->fw_options[2] &= ~BIT_11;
2992 }
2993
2994 ql_dbg(ql_dbg_init, vha, 0xffff,
2995 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
2996 __func__, ha->fw_options[1], ha->fw_options[2],
2997 ha->fw_options[3], vha->host->active_mode);
2998 qla2x00_set_fw_options(vha, ha->fw_options);
2999
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003000 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08003001 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003002 return;
3003
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003004 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08003005 le16_to_cpu(ha->fw_seriallink_options24[1]),
3006 le16_to_cpu(ha->fw_seriallink_options24[2]),
3007 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003008 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003009 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003010 "Unable to update Serial Link options (%x).\n", rval);
3011 }
3012}
3013
3014void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003015qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003016{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003017 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003018 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003019 struct req_que *req = ha->req_q_map[0];
3020 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003021
3022 /* Setup ring parameters in initialization control block. */
Bart Van Asschead950362015-07-09 07:24:08 -07003023 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3024 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003025 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3026 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3027 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3028 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3029 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3030 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003031
3032 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3033 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3034 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3035 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3036 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3037}
3038
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003039void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003040qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003041{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003042 struct qla_hw_data *ha = vha->hw;
Bart Van Assche118e2ef2015-07-09 07:24:27 -07003043 device_reg_t *reg = ISP_QUE_REG(ha, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003044 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3045 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003046 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003047 uint16_t rid = 0;
3048 struct req_que *req = ha->req_q_map[0];
3049 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003050
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003051 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003052 icb = (struct init_cb_24xx *)ha->init_cb;
Bart Van Asschead950362015-07-09 07:24:08 -07003053 icb->request_q_outpointer = cpu_to_le16(0);
3054 icb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003055 icb->request_q_length = cpu_to_le16(req->length);
3056 icb->response_q_length = cpu_to_le16(rsp->length);
3057 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3058 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3059 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3060 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003061
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003062 /* Setup ATIO queue dma pointers for target mode */
Bart Van Asschead950362015-07-09 07:24:08 -07003063 icb->atio_q_inpointer = cpu_to_le16(0);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003064 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3065 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
3066 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
3067
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003068 if (IS_SHADOW_REG_CAPABLE(ha))
Bart Van Asschead950362015-07-09 07:24:08 -07003069 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003070
Chad Dupuisf73cb692014-02-26 04:15:06 -05003071 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003072 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3073 icb->rid = cpu_to_le16(rid);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003074 if (ha->flags.msix_enabled) {
3075 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003076 ql_dbg(ql_dbg_init, vha, 0x00fd,
3077 "Registering vector 0x%x for base que.\n",
3078 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003079 icb->msix = cpu_to_le16(msix->entry);
3080 }
3081 /* Use alternate PCI bus number */
3082 if (MSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003083 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003084 /* Use alternate PCI devfn */
3085 if (LSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003086 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003087
Anirban Chakraborty31557542009-12-02 10:36:55 -08003088 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003089 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
3090 (ha->flags.msix_enabled)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003091 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003092 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003093 ql_dbg(ql_dbg_init, vha, 0x00fe,
3094 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08003095 } else {
Bart Van Asschead950362015-07-09 07:24:08 -07003096 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003097 }
Bart Van Asschead950362015-07-09 07:24:08 -07003098 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003099
3100 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
3101 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
3102 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
3103 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
3104 } else {
3105 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
3106 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
3107 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
3108 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
3109 }
Arun Easiaa230bc2013-01-30 03:34:39 -05003110 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003111
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003112 /* PCI posting */
3113 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003114}
3115
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116/**
3117 * qla2x00_init_rings() - Initializes firmware.
3118 * @ha: HA context
3119 *
3120 * Beginning of request ring has initialization control block already built
3121 * by nvram config routine.
3122 *
3123 * Returns 0 on success.
3124 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003125int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003126qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127{
3128 int rval;
3129 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003130 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003131 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003132 struct req_que *req;
3133 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003134 struct mid_init_cb_24xx *mid_init_cb =
3135 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136
3137 spin_lock_irqsave(&ha->hardware_lock, flags);
3138
3139 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003140 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003141 req = ha->req_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003142 if (!req || !test_bit(que, ha->req_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003143 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003144 req->out_ptr = (void *)(req->ring + req->length);
3145 *req->out_ptr = 0;
Chad Dupuis8d93f552013-01-30 03:34:37 -05003146 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003147 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003149 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003150
3151 /* Initialize firmware. */
3152 req->ring_ptr = req->ring;
3153 req->ring_index = 0;
3154 req->cnt = req->length;
3155 }
3156
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003157 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003158 rsp = ha->rsp_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003159 if (!rsp || !test_bit(que, ha->rsp_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003160 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003161 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
3162 *rsp->in_ptr = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003163 /* Initialize response queue entries */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003164 if (IS_QLAFX00(ha))
3165 qlafx00_init_response_q_entries(rsp);
3166 else
3167 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003168 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003170 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
3171 ha->tgt.atio_ring_index = 0;
3172 /* Initialize ATIO queue entries */
3173 qlt_init_atio_q_entries(vha);
3174
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003175 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176
3177 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3178
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003179 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
3180
3181 if (IS_QLAFX00(ha)) {
3182 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
3183 goto next_check;
3184 }
3185
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003187 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003189 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04003190 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003191 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08003192 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003193 }
3194
Andrew Vasquez24a08132009-03-24 09:08:16 -07003195 if (IS_FWI2_CAPABLE(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003196 mid_init_cb->options = cpu_to_le16(BIT_1);
Andrew Vasquez24a08132009-03-24 09:08:16 -07003197 mid_init_cb->init_cb.execution_throttle =
Quinn Tran03e8c682015-12-17 14:56:59 -05003198 cpu_to_le16(ha->cur_fw_xcb_count);
Joe Carnuccio40f38622016-07-06 11:14:28 -04003199 ha->flags.dport_enabled =
3200 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
3201 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
3202 (ha->flags.dport_enabled) ? "enabled" : "disabled");
3203 /* FA-WWPN Status */
Himanshu Madhani2486c622014-09-25 05:17:00 -04003204 ha->flags.fawwpn_enabled =
Joe Carnuccio40f38622016-07-06 11:14:28 -04003205 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
Himanshu Madhani2486c622014-09-25 05:17:00 -04003206 ql_dbg(ql_dbg_init, vha, 0x0141, "FA-WWPN Support: %s.\n",
3207 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
Andrew Vasquez24a08132009-03-24 09:08:16 -07003208 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003209
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003210 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003211next_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003213 ql_log(ql_log_fatal, vha, 0x00d2,
3214 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003216 ql_dbg(ql_dbg_init, vha, 0x00d3,
3217 "Init Firmware -- success.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 }
3219
3220 return (rval);
3221}
3222
3223/**
3224 * qla2x00_fw_ready() - Waits for firmware ready.
3225 * @ha: HA context
3226 *
3227 * Returns 0 on success.
3228 */
3229static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003230qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231{
3232 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003233 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 uint16_t min_wait; /* Minimum wait time if loop is down */
3235 uint16_t wait_time; /* Wait time if loop is coming ready */
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003236 uint16_t state[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003237 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003239 if (IS_QLAFX00(vha->hw))
3240 return qlafx00_fw_ready(vha);
3241
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 rval = QLA_SUCCESS;
3243
Chad Dupuis334614912015-04-09 14:59:57 -04003244 /* Time to wait for loop down */
3245 if (IS_P3P_TYPE(ha))
3246 min_wait = 30;
3247 else
3248 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249
3250 /*
3251 * Firmware should take at most one RATOV to login, plus 5 seconds for
3252 * our own processing.
3253 */
3254 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
3255 wait_time = min_wait;
3256 }
3257
3258 /* Min wait time if loop down */
3259 mtime = jiffies + (min_wait * HZ);
3260
3261 /* wait time before firmware ready */
3262 wtime = jiffies + (wait_time * HZ);
3263
3264 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003265 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003266 ql_log(ql_log_info, vha, 0x801e,
3267 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268
3269 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05003270 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003271 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003273 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003274 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003276 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003277 ql_dbg(ql_dbg_taskm, vha, 0x801f,
3278 "fw_state=%x 84xx=%x.\n", state[0],
3279 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003280 if ((state[2] & FSTATE_LOGGED_IN) &&
3281 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003282 ql_dbg(ql_dbg_taskm, vha, 0x8028,
3283 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003284
3285 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003286 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003287 if (rval != QLA_SUCCESS) {
3288 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08003289 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003290 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003291 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003292 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003293
3294 /* Add time taken to initialize. */
3295 cs84xx_time = jiffies - cs84xx_time;
3296 wtime += cs84xx_time;
3297 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08003298 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003299 "Increasing wait time by %ld. "
3300 "New time %ld.\n", cs84xx_time,
3301 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003302 }
3303 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003304 ql_dbg(ql_dbg_taskm, vha, 0x8037,
3305 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003307 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 &ha->login_timeout, &ha->r_a_tov);
3309
3310 rval = QLA_SUCCESS;
3311 break;
3312 }
3313
3314 rval = QLA_FUNCTION_FAILED;
3315
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003316 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003317 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003319 * other than Wait for Login.
3320 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003322 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 "Cable is unplugged...\n");
3324
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003325 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 break;
3327 }
3328 }
3329 } else {
3330 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07003331 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08003332 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 break;
3334 }
3335
3336 if (time_after_eq(jiffies, wtime))
3337 break;
3338
3339 /* Delay for a while */
3340 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 } while (1);
3342
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003343 ql_dbg(ql_dbg_taskm, vha, 0x803a,
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003344 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
3345 state[1], state[2], state[3], state[4], state[5], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346
Chad Dupuiscfb09192011-11-18 09:03:07 -08003347 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003348 ql_log(ql_log_warn, vha, 0x803b,
3349 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 }
3351
3352 return (rval);
3353}
3354
3355/*
3356* qla2x00_configure_hba
3357* Setup adapter context.
3358*
3359* Input:
3360* ha = adapter state pointer.
3361*
3362* Returns:
3363* 0 = success
3364*
3365* Context:
3366* Kernel context.
3367*/
3368static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003369qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370{
3371 int rval;
3372 uint16_t loop_id;
3373 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003374 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 uint8_t al_pa;
3376 uint8_t area;
3377 uint8_t domain;
3378 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003379 struct qla_hw_data *ha = vha->hw;
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02003380 unsigned long flags;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003381 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382
3383 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003384 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003385 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003387 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003388 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08003389 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003390 ql_dbg(ql_dbg_disc, vha, 0x2008,
3391 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08003392 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003393 ql_log(ql_log_warn, vha, 0x2009,
3394 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003395 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
3396 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
3397 ql_log(ql_log_warn, vha, 0x1151,
3398 "Doing link init.\n");
3399 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
3400 return rval;
3401 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003402 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08003403 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404 return (rval);
3405 }
3406
3407 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003408 ql_log(ql_log_info, vha, 0x200a,
3409 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 return (QLA_FUNCTION_FAILED);
3411 }
3412
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003413 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414
3415 /* initialize */
3416 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
3417 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003418 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419
3420 switch (topo) {
3421 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003422 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 ha->current_topology = ISP_CFG_NL;
3424 strcpy(connect_type, "(Loop)");
3425 break;
3426
3427 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003428 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003429 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 ha->current_topology = ISP_CFG_FL;
3431 strcpy(connect_type, "(FL_Port)");
3432 break;
3433
3434 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003435 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 ha->operating_mode = P2P;
3437 ha->current_topology = ISP_CFG_N;
3438 strcpy(connect_type, "(N_Port-to-N_Port)");
3439 break;
3440
3441 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003442 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003443 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 ha->operating_mode = P2P;
3445 ha->current_topology = ISP_CFG_F;
3446 strcpy(connect_type, "(F_Port)");
3447 break;
3448
3449 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003450 ql_dbg(ql_dbg_disc, vha, 0x200f,
3451 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 ha->current_topology = ISP_CFG_NL;
3453 strcpy(connect_type, "(Loop)");
3454 break;
3455 }
3456
3457 /* Save Host port and loop ID. */
3458 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003459 vha->d_id.b.domain = domain;
3460 vha->d_id.b.area = area;
3461 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02003463 spin_lock_irqsave(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003464 qlt_update_vp_map(vha, SET_AL_PA);
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02003465 spin_unlock_irqrestore(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003466
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003467 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003468 ql_log(ql_log_info, vha, 0x2010,
3469 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003470 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 return(rval);
3473}
3474
Giridhar Malavalia9083012010-04-12 17:59:55 -07003475inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003476qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
3477 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003478{
3479 char *st, *en;
3480 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003481 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07003482 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003483 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003484
3485 if (memcmp(model, BINZERO, len) != 0) {
3486 strncpy(ha->model_number, model, len);
3487 st = en = ha->model_number;
3488 en += len - 1;
3489 while (en > st) {
3490 if (*en != 0x20 && *en != 0x00)
3491 break;
3492 *en-- = '\0';
3493 }
3494
3495 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07003496 if (use_tbl &&
3497 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003498 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003499 strncpy(ha->model_desc,
3500 qla2x00_model_name[index * 2 + 1],
3501 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003502 } else {
3503 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07003504 if (use_tbl &&
3505 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003506 index < QLA_MODEL_NAMES) {
3507 strcpy(ha->model_number,
3508 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003509 strncpy(ha->model_desc,
3510 qla2x00_model_name[index * 2 + 1],
3511 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003512 } else {
3513 strcpy(ha->model_number, def);
3514 }
3515 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003516 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003517 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003518 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003519}
3520
David Miller4e08df32007-04-16 12:37:43 -07003521/* On sparc systems, obtain port and node WWN from firmware
3522 * properties.
3523 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003524static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07003525{
3526#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003527 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003528 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003529 struct device_node *dp = pci_device_to_OF_node(pdev);
3530 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003531 int len;
3532
3533 val = of_get_property(dp, "port-wwn", &len);
3534 if (val && len >= WWN_SIZE)
3535 memcpy(nv->port_name, val, WWN_SIZE);
3536
3537 val = of_get_property(dp, "node-wwn", &len);
3538 if (val && len >= WWN_SIZE)
3539 memcpy(nv->node_name, val, WWN_SIZE);
3540#endif
3541}
3542
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543/*
3544* NVRAM configuration for ISP 2xxx
3545*
3546* Input:
3547* ha = adapter block pointer.
3548*
3549* Output:
3550* initialization control block in response_ring
3551* host adapters parameters in host adapter block
3552*
3553* Returns:
3554* 0 = success.
3555*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003556int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003557qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558{
David Miller4e08df32007-04-16 12:37:43 -07003559 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003560 uint8_t chksum = 0;
3561 uint16_t cnt;
3562 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003563 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003564 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003565 nvram_t *nv = ha->nvram;
3566 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003567 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568
David Miller4e08df32007-04-16 12:37:43 -07003569 rval = QLA_SUCCESS;
3570
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003572 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573 ha->nvram_base = 0;
3574 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
3575 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
3576 ha->nvram_base = 0x80;
3577
3578 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003579 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003580 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
3581 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003583 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
3584 "Contents of NVRAM.\n");
3585 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
3586 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587
3588 /* Bad NVRAM data, set defaults parameters. */
3589 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
3590 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
3591 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003592 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04003593 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003594 "detected: checksum=0x%x id=%c version=0x%x.\n",
3595 chksum, nv->id[0], nv->nvram_version);
3596 ql_log(ql_log_warn, vha, 0x0065,
3597 "Falling back to "
3598 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07003599
3600 /*
3601 * Set default initialization control block.
3602 */
3603 memset(nv, 0, ha->nvram_size);
3604 nv->parameter_block_version = ICB_VERSION;
3605
3606 if (IS_QLA23XX(ha)) {
3607 nv->firmware_options[0] = BIT_2 | BIT_1;
3608 nv->firmware_options[1] = BIT_7 | BIT_5;
3609 nv->add_firmware_options[0] = BIT_5;
3610 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04003611 nv->frame_payload_size = 2048;
David Miller4e08df32007-04-16 12:37:43 -07003612 nv->special_options[1] = BIT_7;
3613 } else if (IS_QLA2200(ha)) {
3614 nv->firmware_options[0] = BIT_2 | BIT_1;
3615 nv->firmware_options[1] = BIT_7 | BIT_5;
3616 nv->add_firmware_options[0] = BIT_5;
3617 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04003618 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07003619 } else if (IS_QLA2100(ha)) {
3620 nv->firmware_options[0] = BIT_3 | BIT_1;
3621 nv->firmware_options[1] = BIT_5;
Joe Carnuccio98aee702014-09-25 05:16:38 -04003622 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07003623 }
3624
Bart Van Asschead950362015-07-09 07:24:08 -07003625 nv->max_iocb_allocation = cpu_to_le16(256);
3626 nv->execution_throttle = cpu_to_le16(16);
David Miller4e08df32007-04-16 12:37:43 -07003627 nv->retry_count = 8;
3628 nv->retry_delay = 1;
3629
3630 nv->port_name[0] = 33;
3631 nv->port_name[3] = 224;
3632 nv->port_name[4] = 139;
3633
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003634 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003635
3636 nv->login_timeout = 4;
3637
3638 /*
3639 * Set default host adapter parameters
3640 */
3641 nv->host_p[1] = BIT_2;
3642 nv->reset_delay = 5;
3643 nv->port_down_retry_count = 8;
Bart Van Asschead950362015-07-09 07:24:08 -07003644 nv->max_luns_per_target = cpu_to_le16(8);
David Miller4e08df32007-04-16 12:37:43 -07003645 nv->link_down_timeout = 60;
3646
3647 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 }
3649
3650#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3651 /*
3652 * The SN2 does not provide BIOS emulation which means you can't change
3653 * potentially bogus BIOS settings. Force the use of default settings
3654 * for link rate and frame size. Hope that the rest of the settings
3655 * are valid.
3656 */
3657 if (ia64_platform_is("sn2")) {
Joe Carnuccio98aee702014-09-25 05:16:38 -04003658 nv->frame_payload_size = 2048;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659 if (IS_QLA23XX(ha))
3660 nv->special_options[1] = BIT_7;
3661 }
3662#endif
3663
3664 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003665 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666
3667 /*
3668 * Setup driver NVRAM options.
3669 */
3670 nv->firmware_options[0] |= (BIT_6 | BIT_1);
3671 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
3672 nv->firmware_options[1] |= (BIT_5 | BIT_0);
3673 nv->firmware_options[1] &= ~BIT_4;
3674
3675 if (IS_QLA23XX(ha)) {
3676 nv->firmware_options[0] |= BIT_2;
3677 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003678 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003679 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680
3681 if (IS_QLA2300(ha)) {
3682 if (ha->fb_rev == FPM_2310) {
3683 strcpy(ha->model_number, "QLA2310");
3684 } else {
3685 strcpy(ha->model_number, "QLA2300");
3686 }
3687 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003688 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003689 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690 }
3691 } else if (IS_QLA2200(ha)) {
3692 nv->firmware_options[0] |= BIT_2;
3693 /*
3694 * 'Point-to-point preferred, else loop' is not a safe
3695 * connection mode setting.
3696 */
3697 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
3698 (BIT_5 | BIT_4)) {
3699 /* Force 'loop preferred, else point-to-point'. */
3700 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
3701 nv->add_firmware_options[0] |= BIT_5;
3702 }
3703 strcpy(ha->model_number, "QLA22xx");
3704 } else /*if (IS_QLA2100(ha))*/ {
3705 strcpy(ha->model_number, "QLA2100");
3706 }
3707
3708 /*
3709 * Copy over NVRAM RISC parameter block to initialization control block.
3710 */
3711 dptr1 = (uint8_t *)icb;
3712 dptr2 = (uint8_t *)&nv->parameter_block_version;
3713 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
3714 while (cnt--)
3715 *dptr1++ = *dptr2++;
3716
3717 /* Copy 2nd half. */
3718 dptr1 = (uint8_t *)icb->add_firmware_options;
3719 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
3720 while (cnt--)
3721 *dptr1++ = *dptr2++;
3722
Andrew Vasquez5341e862006-05-17 15:09:16 -07003723 /* Use alternate WWN? */
3724 if (nv->host_p[1] & BIT_7) {
3725 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3726 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3727 }
3728
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729 /* Prepare nodename */
3730 if ((icb->firmware_options[1] & BIT_6) == 0) {
3731 /*
3732 * Firmware will apply the following mask if the nodename was
3733 * not provided.
3734 */
3735 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3736 icb->node_name[0] &= 0xF0;
3737 }
3738
3739 /*
3740 * Set host adapter parameters.
3741 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07003742
3743 /*
3744 * BIT_7 in the host-parameters section allows for modification to
3745 * internal driver logging.
3746 */
Andrew Vasquez01819442006-06-23 16:11:10 -07003747 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08003748 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
3750 /* Always load RISC code on non ISP2[12]00 chips. */
3751 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
3752 ha->flags.disable_risc_code_load = 0;
3753 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
3754 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
3755 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07003756 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003757 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758
3759 ha->operating_mode =
3760 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
3761
3762 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
3763 sizeof(ha->fw_seriallink_options));
3764
3765 /* save HBA serial number */
3766 ha->serial0 = icb->port_name[5];
3767 ha->serial1 = icb->port_name[6];
3768 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003769 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3770 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771
Bart Van Asschead950362015-07-09 07:24:08 -07003772 icb->execution_throttle = cpu_to_le16(0xFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773
3774 ha->retry_count = nv->retry_count;
3775
3776 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07003777 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778 nv->login_timeout = ql2xlogintimeout;
3779 if (nv->login_timeout < 4)
3780 nv->login_timeout = 4;
3781 ha->login_timeout = nv->login_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003783 /* Set minimum RATOV to 100 tenths of a second. */
3784 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786 ha->loop_reset_delay = nv->reset_delay;
3787
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788 /* Link Down Timeout = 0:
3789 *
3790 * When Port Down timer expires we will start returning
3791 * I/O's to OS with "DID_NO_CONNECT".
3792 *
3793 * Link Down Timeout != 0:
3794 *
3795 * The driver waits for the link to come up after link down
3796 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003797 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798 if (nv->link_down_timeout == 0) {
3799 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003800 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 } else {
3802 ha->link_down_timeout = nv->link_down_timeout;
3803 ha->loop_down_abort_time =
3804 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003805 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 /*
3808 * Need enough time to try and get the port back.
3809 */
3810 ha->port_down_retry_count = nv->port_down_retry_count;
3811 if (qlport_down_retry)
3812 ha->port_down_retry_count = qlport_down_retry;
3813 /* Set login_retry_count */
3814 ha->login_retry_count = nv->retry_count;
3815 if (ha->port_down_retry_count == nv->port_down_retry_count &&
3816 ha->port_down_retry_count > 3)
3817 ha->login_retry_count = ha->port_down_retry_count;
3818 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3819 ha->login_retry_count = ha->port_down_retry_count;
3820 if (ql2xloginretrycount)
3821 ha->login_retry_count = ql2xloginretrycount;
3822
Bart Van Asschead950362015-07-09 07:24:08 -07003823 icb->lun_enables = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 icb->command_resource_count = 0;
3825 icb->immediate_notify_resource_count = 0;
Bart Van Asschead950362015-07-09 07:24:08 -07003826 icb->timeout = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827
3828 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3829 /* Enable RIO */
3830 icb->firmware_options[0] &= ~BIT_3;
3831 icb->add_firmware_options[0] &=
3832 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
3833 icb->add_firmware_options[0] |= BIT_2;
3834 icb->response_accumulation_timer = 3;
3835 icb->interrupt_delay_timer = 5;
3836
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003837 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003839 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003840 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003841 ha->zio_mode = icb->add_firmware_options[0] &
3842 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3843 ha->zio_timer = icb->interrupt_delay_timer ?
3844 icb->interrupt_delay_timer: 2;
3845 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846 icb->add_firmware_options[0] &=
3847 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003848 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003849 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003850 ha->zio_mode = QLA_ZIO_MODE_6;
3851
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003852 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003853 "ZIO mode %d enabled; timer delay (%d us).\n",
3854 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003856 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
3857 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003858 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 }
3860 }
3861
David Miller4e08df32007-04-16 12:37:43 -07003862 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003863 ql_log(ql_log_warn, vha, 0x0069,
3864 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07003865 }
3866 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867}
3868
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003869static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003870qla2x00_rport_del(void *data)
3871{
3872 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003873 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003874 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003875
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003876 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07003877 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003878 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003879 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08003880 if (rport) {
3881 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
3882 "%s %8phN. rport %p roles %x \n",
3883 __func__, fcport->port_name, rport,
3884 rport->roles);
3885
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003886 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08003887 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003888}
3889
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890/**
3891 * qla2x00_alloc_fcport() - Allocate a generic fcport.
3892 * @ha: HA context
3893 * @flags: allocation flags
3894 *
3895 * Returns a pointer to the allocated fcport, or NULL, if none available.
3896 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003897fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003898qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899{
3900 fc_port_t *fcport;
3901
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003902 fcport = kzalloc(sizeof(fc_port_t), flags);
3903 if (!fcport)
3904 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905
3906 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003907 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908 fcport->port_type = FCT_UNKNOWN;
3909 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07003910 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003911 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912
Quinn Tran726b8542017-01-19 22:28:00 -08003913 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
3914 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
3915 GFP_ATOMIC);
3916 fcport->disc_state = DSC_DELETED;
3917 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
3918 fcport->deleted = QLA_SESS_DELETED;
3919 fcport->login_retry = vha->hw->login_retry_count;
3920 fcport->login_retry = 5;
3921 fcport->logout_on_delete = 1;
3922
3923 if (!fcport->ct_desc.ct_sns) {
3924 ql_log(ql_log_warn, vha, 0xffff,
3925 "Failed to allocate ct_sns request.\n");
3926 kfree(fcport);
3927 fcport = NULL;
3928 }
3929 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
3930 INIT_LIST_HEAD(&fcport->gnl_entry);
3931 INIT_LIST_HEAD(&fcport->list);
3932
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003933 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934}
3935
Quinn Tran726b8542017-01-19 22:28:00 -08003936void
3937qla2x00_free_fcport(fc_port_t *fcport)
3938{
3939 if (fcport->ct_desc.ct_sns) {
3940 dma_free_coherent(&fcport->vha->hw->pdev->dev,
3941 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
3942 fcport->ct_desc.ct_sns_dma);
3943
3944 fcport->ct_desc.ct_sns = NULL;
3945 }
3946 kfree(fcport);
3947}
3948
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949/*
3950 * qla2x00_configure_loop
3951 * Updates Fibre Channel Device Database with what is actually on loop.
3952 *
3953 * Input:
3954 * ha = adapter block pointer.
3955 *
3956 * Returns:
3957 * 0 = success.
3958 * 1 = error.
3959 * 2 = database was full and device was not configured.
3960 */
3961static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003962qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963{
3964 int rval;
3965 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003966 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 rval = QLA_SUCCESS;
3968
3969 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003970 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
3971 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003973 ql_dbg(ql_dbg_disc, vha, 0x2013,
3974 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975 return (rval);
3976 }
3977 }
3978
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003979 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003980 ql_dbg(ql_dbg_disc, vha, 0x2014,
3981 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982
3983 /*
3984 * If we have both an RSCN and PORT UPDATE pending then handle them
3985 * both at the same time.
3986 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003987 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3988 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989
Michael Hernandez3064ff32009-12-15 21:29:44 -08003990 qla2x00_get_data_rate(vha);
3991
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992 /* Determine what we need to do */
3993 if (ha->current_topology == ISP_CFG_FL &&
3994 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
3995
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996 set_bit(RSCN_UPDATE, &flags);
3997
3998 } else if (ha->current_topology == ISP_CFG_F &&
3999 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4000
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001 set_bit(RSCN_UPDATE, &flags);
4002 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4003
Andrew Vasquez21333b42006-05-17 15:09:56 -07004004 } else if (ha->current_topology == ISP_CFG_N) {
4005 clear_bit(RSCN_UPDATE, &flags);
Quinn Tran41dc5292017-01-19 22:28:03 -08004006 } else if (ha->current_topology == ISP_CFG_NL) {
4007 clear_bit(RSCN_UPDATE, &flags);
4008 set_bit(LOCAL_LOOP_UPDATE, &flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004009 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 set_bit(RSCN_UPDATE, &flags);
4012 set_bit(LOCAL_LOOP_UPDATE, &flags);
4013 }
4014
4015 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004016 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4017 ql_dbg(ql_dbg_disc, vha, 0x2015,
4018 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08004020 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004021 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 }
4023
4024 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004025 if (LOOP_TRANSITION(vha)) {
4026 ql_dbg(ql_dbg_disc, vha, 0x201e,
4027 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004029 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004030 else
4031 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032 }
4033
4034 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004035 if (atomic_read(&vha->loop_down_timer) ||
4036 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 rval = QLA_FUNCTION_FAILED;
4038 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004039 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004040 ql_dbg(ql_dbg_disc, vha, 0x2069,
4041 "LOOP READY.\n");
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05004042
4043 /*
4044 * Process any ATIO queue entries that came in
4045 * while we weren't online.
4046 */
Quinn Tranead03852017-01-19 22:28:01 -08004047 if (qla_tgt_mode_enabled(vha) ||
4048 qla_dual_mode_enabled(vha)) {
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05004049 if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) {
4050 spin_lock_irqsave(&ha->tgt.atio_lock,
4051 flags);
4052 qlt_24xx_process_atio_queue(vha, 0);
4053 spin_unlock_irqrestore(
4054 &ha->tgt.atio_lock, flags);
4055 } else {
4056 spin_lock_irqsave(&ha->hardware_lock,
4057 flags);
4058 qlt_24xx_process_atio_queue(vha, 1);
4059 spin_unlock_irqrestore(
4060 &ha->hardware_lock, flags);
4061 }
4062 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063 }
4064 }
4065
4066 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004067 ql_dbg(ql_dbg_disc, vha, 0x206a,
4068 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004070 ql_dbg(ql_dbg_disc, vha, 0x206b,
4071 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072 }
4073
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07004074 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004075 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004077 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004078 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004079 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004080 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 }
4082
4083 return (rval);
4084}
4085
4086
4087
4088/*
4089 * qla2x00_configure_local_loop
4090 * Updates Fibre Channel Device Database with local loop devices.
4091 *
4092 * Input:
4093 * ha = adapter block pointer.
4094 *
4095 * Returns:
4096 * 0 = success.
4097 */
4098static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004099qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100{
4101 int rval, rval2;
4102 int found_devs;
4103 int found;
4104 fc_port_t *fcport, *new_fcport;
4105
4106 uint16_t index;
4107 uint16_t entries;
4108 char *id_iter;
4109 uint16_t loop_id;
4110 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004111 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08004112 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113
4114 found_devs = 0;
4115 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08004116 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08004119 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004120 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 &entries);
4122 if (rval != QLA_SUCCESS)
4123 goto cleanup_allocation;
4124
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004125 ql_dbg(ql_dbg_disc, vha, 0x2017,
4126 "Entries in ID list (%d).\n", entries);
4127 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
4128 (uint8_t *)ha->gid_list,
4129 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130
4131 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004132 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004134 ql_log(ql_log_warn, vha, 0x2018,
4135 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 rval = QLA_MEMORY_ALLOC_FAILED;
4137 goto cleanup_allocation;
4138 }
4139 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4140
4141 /*
4142 * Mark local devices that were present with FCF_DEVICE_LOST for now.
4143 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004144 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145 if (atomic_read(&fcport->state) == FCS_ONLINE &&
4146 fcport->port_type != FCT_BROADCAST &&
4147 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
4148
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004149 ql_dbg(ql_dbg_disc, vha, 0x2019,
4150 "Marking port lost loop_id=0x%04x.\n",
4151 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152
Quinn Tran41dc5292017-01-19 22:28:03 -08004153 qla2x00_mark_device_lost(vha, fcport, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154 }
4155 }
4156
4157 /* Add devices to port list. */
4158 id_iter = (char *)ha->gid_list;
4159 for (index = 0; index < entries; index++) {
4160 domain = ((struct gid_list_info *)id_iter)->domain;
4161 area = ((struct gid_list_info *)id_iter)->area;
4162 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004163 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164 loop_id = (uint16_t)
4165 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004166 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167 loop_id = le16_to_cpu(
4168 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004169 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170
4171 /* Bypass reserved domain fields. */
4172 if ((domain & 0xf0) == 0xf0)
4173 continue;
4174
4175 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004176 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004177 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178 continue;
4179
4180 /* Bypass invalid local loop ID. */
4181 if (loop_id > LAST_LOCAL_LOOP_ID)
4182 continue;
4183
Quinn Tran41dc5292017-01-19 22:28:03 -08004184 memset(new_fcport->port_name, 0, WWN_SIZE);
Arun Easi370d5502012-08-22 14:21:10 -04004185
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186 /* Fill in member data. */
4187 new_fcport->d_id.b.domain = domain;
4188 new_fcport->d_id.b.area = area;
4189 new_fcport->d_id.b.al_pa = al_pa;
4190 new_fcport->loop_id = loop_id;
Quinn Tran41dc5292017-01-19 22:28:03 -08004191
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004192 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004194 ql_dbg(ql_dbg_disc, vha, 0x201a,
4195 "Failed to retrieve fcport information "
4196 "-- get_port_database=%x, loop_id=0x%04x.\n",
4197 rval2, new_fcport->loop_id);
4198 ql_dbg(ql_dbg_disc, vha, 0x201b,
4199 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004200 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201 continue;
4202 }
4203
Quinn Tran41dc5292017-01-19 22:28:03 -08004204 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205 /* Check for matching device in port list. */
4206 found = 0;
4207 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004208 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209 if (memcmp(new_fcport->port_name, fcport->port_name,
4210 WWN_SIZE))
4211 continue;
4212
Shyam Sundarddb9b122009-03-24 09:08:10 -07004213 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214 fcport->loop_id = new_fcport->loop_id;
4215 fcport->port_type = new_fcport->port_type;
4216 fcport->d_id.b24 = new_fcport->d_id.b24;
4217 memcpy(fcport->node_name, new_fcport->node_name,
4218 WWN_SIZE);
4219
Quinn Tran41dc5292017-01-19 22:28:03 -08004220 if (!fcport->login_succ) {
4221 vha->fcport_count++;
4222 fcport->login_succ = 1;
4223 fcport->disc_state = DSC_LOGIN_COMPLETE;
4224 }
4225
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226 found++;
4227 break;
4228 }
4229
4230 if (!found) {
4231 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004232 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233
4234 /* Allocate a new replacement fcport. */
4235 fcport = new_fcport;
Quinn Tran41dc5292017-01-19 22:28:03 -08004236 if (!fcport->login_succ) {
4237 vha->fcport_count++;
4238 fcport->login_succ = 1;
4239 fcport->disc_state = DSC_LOGIN_COMPLETE;
4240 }
4241
4242 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4243
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004244 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Quinn Tran41dc5292017-01-19 22:28:03 -08004245
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004247 ql_log(ql_log_warn, vha, 0x201c,
4248 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249 rval = QLA_MEMORY_ALLOC_FAILED;
4250 goto cleanup_allocation;
4251 }
Quinn Tran41dc5292017-01-19 22:28:03 -08004252 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4254 }
4255
Quinn Tran41dc5292017-01-19 22:28:03 -08004256 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4257
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004258 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004259 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004260
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004261 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262
4263 found_devs++;
4264 }
4265
4266cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08004267 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268
4269 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004270 ql_dbg(ql_dbg_disc, vha, 0x201d,
4271 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272 }
4273
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274 return (rval);
4275}
4276
4277static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004278qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004279{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004280 int rval;
Quinn Tran93f2bd62014-09-25 05:16:53 -04004281 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004282 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004283
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07004284 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004285 return;
4286
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07004287 if (atomic_read(&fcport->state) != FCS_ONLINE)
4288 return;
4289
Andrew Vasquez39bd9622007-09-20 14:07:34 -07004290 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
4291 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004292 return;
4293
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004294 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004295 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004296 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004297 ql_dbg(ql_dbg_disc, vha, 0x2004,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004298 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
4299 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004300 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004301 ql_dbg(ql_dbg_disc, vha, 0x2005,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004302 "iIDMA adjusted to %s GB/s on %8phN.\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -05004303 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004304 fcport->port_name);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004305 }
4306}
4307
Quinn Tran726b8542017-01-19 22:28:00 -08004308/* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
Adrian Bunk23be3312006-11-24 02:46:01 +01004309static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004310qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05004311{
4312 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05004313 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004314 unsigned long flags;
8482e1182005-04-17 15:04:54 -05004315
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07004316 rport_ids.node_name = wwn_to_u64(fcport->node_name);
4317 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05004318 rport_ids.port_id = fcport->d_id.b.domain << 16 |
4319 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
4320 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004321 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07004322 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004323 ql_log(ql_log_warn, vha, 0x2006,
4324 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07004325 return;
4326 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004327
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004328 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004329 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004330 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004331
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004332 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07004333
4334 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05004335 if (fcport->port_type == FCT_INITIATOR)
4336 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
4337 if (fcport->port_type == FCT_TARGET)
4338 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Quinn Tran726b8542017-01-19 22:28:00 -08004339
4340 ql_dbg(ql_dbg_disc, vha, 0xffff,
4341 "%s %8phN. rport %p is %s mode \n",
4342 __func__, fcport->port_name, rport,
4343 (fcport->port_type == FCT_TARGET) ? "tgt" : "ini");
4344
Andrew Vasquez77d74142005-07-08 18:00:36 -07004345 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05004346}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347
4348/*
Adrian Bunk23be3312006-11-24 02:46:01 +01004349 * qla2x00_update_fcport
4350 * Updates device on list.
4351 *
4352 * Input:
4353 * ha = adapter block pointer.
4354 * fcport = port structure pointer.
4355 *
4356 * Return:
4357 * 0 - Success
4358 * BIT_0 - error
4359 *
4360 * Context:
4361 * Kernel context.
4362 */
4363void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004364qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01004365{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004366 fcport->vha = vha;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004367
Quinn Tran726b8542017-01-19 22:28:00 -08004368 if (IS_SW_RESV_ADDR(fcport->d_id))
4369 return;
4370
4371 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %8phC \n",
4372 __func__, fcport->port_name);
4373
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004374 if (IS_QLAFX00(vha->hw)) {
4375 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004376 goto reg_port;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004377 }
Adrian Bunk23be3312006-11-24 02:46:01 +01004378 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004379 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Quinn Tran726b8542017-01-19 22:28:00 -08004380 fcport->disc_state = DSC_LOGIN_COMPLETE;
4381 fcport->deleted = 0;
4382 fcport->logout_on_delete = 1;
Adrian Bunk23be3312006-11-24 02:46:01 +01004383
Joe Carnuccio1f93da522012-11-21 02:40:38 -05004384 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004385 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08004386 qla24xx_update_fcport_fcp_prio(vha, fcport);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004387
4388reg_port:
Quinn Tran726b8542017-01-19 22:28:00 -08004389 switch (vha->host->active_mode) {
4390 case MODE_INITIATOR:
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004391 qla2x00_reg_remote_port(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08004392 break;
4393 case MODE_TARGET:
4394 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
4395 !vha->vha_tgt.qla_tgt->tgt_stopped)
4396 qlt_fc_port_added(vha, fcport);
4397 break;
4398 case MODE_DUAL:
4399 qla2x00_reg_remote_port(vha, fcport);
4400 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
4401 !vha->vha_tgt.qla_tgt->tgt_stopped)
4402 qlt_fc_port_added(vha, fcport);
4403 break;
4404 default:
4405 break;
4406 }
Adrian Bunk23be3312006-11-24 02:46:01 +01004407}
4408
4409/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004410 * qla2x00_configure_fabric
4411 * Setup SNS devices with loop ID's.
4412 *
4413 * Input:
4414 * ha = adapter block pointer.
4415 *
4416 * Returns:
4417 * 0 = success.
4418 * BIT_0 = error
4419 */
4420static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004421qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422{
Arun Easib3b02e62012-02-09 11:15:39 -08004423 int rval;
Quinn Tran726b8542017-01-19 22:28:00 -08004424 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004426 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004428 struct qla_hw_data *ha = vha->hw;
Alexei Potashnikdf673272015-07-14 16:00:46 -04004429 int discovery_gen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430
4431 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07004432 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004433 loop_id = NPH_F_PORT;
4434 else
4435 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004436 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004437 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004438 ql_dbg(ql_dbg_disc, vha, 0x201f,
4439 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004441 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442 return (QLA_SUCCESS);
4443 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004444 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445
Quinn Tran41dc5292017-01-19 22:28:03 -08004446
4447 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
4448 rval = qla2x00_send_change_request(vha, 0x3, 0);
4449 if (rval != QLA_SUCCESS)
4450 ql_log(ql_log_warn, vha, 0x121,
4451 "Failed to enable receiving of RSCN requests: 0x%x.\n",
4452 rval);
4453 }
4454
4455
Linus Torvalds1da177e2005-04-16 15:20:36 -07004456 do {
Quinn Tran726b8542017-01-19 22:28:00 -08004457 qla2x00_mgmt_svr_login(vha);
4458
Andrew Vasquezcca53352005-08-26 19:08:30 -07004459 /* FDMI support. */
4460 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004461 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
4462 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07004463
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07004465 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004466 loop_id = NPH_SNS;
4467 else
4468 loop_id = SIMPLE_NAME_SERVER;
Chad Dupuis0b91d112012-02-09 11:15:42 -08004469 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
4470 0xfc, mb, BIT_1|BIT_0);
4471 if (rval != QLA_SUCCESS) {
4472 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05004473 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08004474 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004475 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004476 ql_dbg(ql_dbg_disc, vha, 0x2042,
4477 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
4478 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
4479 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480 return (QLA_SUCCESS);
4481 }
4482
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004483 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
4484 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004485 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004486 ql_dbg(ql_dbg_disc, vha, 0x2045,
4487 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004489 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004491 ql_dbg(ql_dbg_disc, vha, 0x2049,
4492 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004493 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004494 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004496 ql_dbg(ql_dbg_disc, vha, 0x204f,
4497 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004498 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004500 ql_dbg(ql_dbg_disc, vha, 0x2053,
4501 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502 }
4503 }
4504
Joe Carnuccio827210b2013-02-08 01:57:57 -05004505 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4506 fcport->scan_state = QLA_FCPORT_SCAN;
4507 }
4508
Alexei Potashnikdf673272015-07-14 16:00:46 -04004509 /* Mark the time right before querying FW for connected ports.
4510 * This process is long, asynchronous and by the time it's done,
4511 * collected information might not be accurate anymore. E.g.
4512 * disconnected port might have re-connected and a brand new
4513 * session has been created. In this case session's generation
4514 * will be newer than discovery_gen. */
4515 qlt_do_generation_tick(vha, &discovery_gen);
4516
Quinn Tran726b8542017-01-19 22:28:00 -08004517 rval = qla2x00_find_all_fabric_devs(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004518 if (rval != QLA_SUCCESS)
4519 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004520 } while (0);
4521
Quinn Tran726b8542017-01-19 22:28:00 -08004522 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004523 ql_dbg(ql_dbg_disc, vha, 0x2068,
4524 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525
4526 return (rval);
4527}
4528
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529/*
4530 * qla2x00_find_all_fabric_devs
4531 *
4532 * Input:
4533 * ha = adapter block pointer.
4534 * dev = database device entry pointer.
4535 *
4536 * Returns:
4537 * 0 = success.
4538 *
4539 * Context:
4540 * Kernel context.
4541 */
4542static int
Quinn Tran726b8542017-01-19 22:28:00 -08004543qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004544{
4545 int rval;
4546 uint16_t loop_id;
Quinn Tran726b8542017-01-19 22:28:00 -08004547 fc_port_t *fcport, *new_fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004548 int found;
4549
4550 sw_info_t *swl;
4551 int swl_idx;
4552 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07004553 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004554 struct qla_hw_data *ha = vha->hw;
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05004555 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran726b8542017-01-19 22:28:00 -08004556 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557
4558 rval = QLA_SUCCESS;
4559
4560 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08004561 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08004562 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08004563 GFP_KERNEL);
4564 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004565 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004566 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004567 ql_dbg(ql_dbg_disc, vha, 0x2054,
4568 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004569 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08004570 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004571 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004572 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004573 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004575 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576 swl = NULL;
Quinn Tran726b8542017-01-19 22:28:00 -08004577 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
4578 swl = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004580
4581 /* If other queries succeeded probe for FC-4 type */
4582 if (swl)
4583 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004584 }
4585 swl_idx = 0;
4586
4587 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004588 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004589 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004590 ql_log(ql_log_warn, vha, 0x205e,
4591 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592 return (QLA_MEMORY_ALLOC_FAILED);
4593 }
4594 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595 /* Set start port ID scan at adapter ID. */
4596 first_dev = 1;
4597 last_dev = 0;
4598
4599 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004600 loop_id = ha->min_external_loopid;
4601 for (; loop_id <= ha->max_loop_id; loop_id++) {
4602 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603 continue;
4604
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07004605 if (ha->current_topology == ISP_CFG_FL &&
4606 (atomic_read(&vha->loop_down_timer) ||
4607 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08004608 atomic_set(&vha->loop_down_timer, 0);
4609 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4610 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08004612 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613
4614 if (swl != NULL) {
4615 if (last_dev) {
4616 wrap.b24 = new_fcport->d_id.b24;
4617 } else {
4618 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
4619 memcpy(new_fcport->node_name,
4620 swl[swl_idx].node_name, WWN_SIZE);
4621 memcpy(new_fcport->port_name,
4622 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004623 memcpy(new_fcport->fabric_port_name,
4624 swl[swl_idx].fabric_port_name, WWN_SIZE);
4625 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004626 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004627
4628 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
4629 last_dev = 1;
4630 }
4631 swl_idx++;
4632 }
4633 } else {
4634 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004635 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004636 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004637 ql_log(ql_log_warn, vha, 0x2064,
4638 "SNS scan failed -- assuming "
4639 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640 rval = QLA_SUCCESS;
4641 break;
4642 }
4643 }
4644
4645 /* If wrap on switch device list, exit. */
4646 if (first_dev) {
4647 wrap.b24 = new_fcport->d_id.b24;
4648 first_dev = 0;
4649 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004650 ql_dbg(ql_dbg_disc, vha, 0x2065,
4651 "Device wrap (%02x%02x%02x).\n",
4652 new_fcport->d_id.b.domain,
4653 new_fcport->d_id.b.area,
4654 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655 break;
4656 }
4657
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004658 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004659 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 continue;
4661
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004662 /* Bypass virtual ports of the same host. */
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05004663 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
4664 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004665
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004666 /* Bypass if same domain and area of adapter. */
4667 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004668 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004669 ISP_CFG_FL)
4670 continue;
4671
Linus Torvalds1da177e2005-04-16 15:20:36 -07004672 /* Bypass reserved domain fields. */
4673 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
4674 continue;
4675
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004676 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07004677 if (ql2xgffidenable &&
4678 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
4679 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004680 continue;
4681
Quinn Tran726b8542017-01-19 22:28:00 -08004682 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4683
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684 /* Locate matching device in database. */
4685 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004686 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004687 if (memcmp(new_fcport->port_name, fcport->port_name,
4688 WWN_SIZE))
4689 continue;
4690
Joe Carnuccio827210b2013-02-08 01:57:57 -05004691 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08004692
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693 found++;
4694
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004695 /* Update port state. */
4696 memcpy(fcport->fabric_port_name,
4697 new_fcport->fabric_port_name, WWN_SIZE);
4698 fcport->fp_speed = new_fcport->fp_speed;
4699
Linus Torvalds1da177e2005-04-16 15:20:36 -07004700 /*
Roland Dreierb2032fd2015-07-14 16:00:42 -04004701 * If address the same and state FCS_ONLINE
4702 * (or in target mode), nothing changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703 */
4704 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
Roland Dreierb2032fd2015-07-14 16:00:42 -04004705 (atomic_read(&fcport->state) == FCS_ONLINE ||
Quinn Tran726b8542017-01-19 22:28:00 -08004706 (vha->host->active_mode == MODE_TARGET))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004707 break;
4708 }
4709
4710 /*
4711 * If device was not a fabric device before.
4712 */
4713 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
4714 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04004715 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716 fcport->flags |= (FCF_FABRIC_DEVICE |
4717 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718 break;
4719 }
4720
4721 /*
4722 * Port ID changed or device was marked to be updated;
4723 * Log it out if still logged in and mark it for
4724 * relogin later.
4725 */
Quinn Tran726b8542017-01-19 22:28:00 -08004726 if (qla_tgt_mode_enabled(base_vha)) {
Roland Dreierb2032fd2015-07-14 16:00:42 -04004727 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
4728 "port changed FC ID, %8phC"
4729 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
4730 fcport->port_name,
4731 fcport->d_id.b.domain,
4732 fcport->d_id.b.area,
4733 fcport->d_id.b.al_pa,
4734 fcport->loop_id,
4735 new_fcport->d_id.b.domain,
4736 new_fcport->d_id.b.area,
4737 new_fcport->d_id.b.al_pa);
4738 fcport->d_id.b24 = new_fcport->d_id.b24;
4739 break;
4740 }
4741
Linus Torvalds1da177e2005-04-16 15:20:36 -07004742 fcport->d_id.b24 = new_fcport->d_id.b24;
4743 fcport->flags |= FCF_LOGIN_NEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744 break;
4745 }
4746
Quinn Tran726b8542017-01-19 22:28:00 -08004747 if (found) {
4748 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749 continue;
Quinn Tran726b8542017-01-19 22:28:00 -08004750 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751 /* If device was not in our fcports list, then add it. */
Roland Dreierb2032fd2015-07-14 16:00:42 -04004752 new_fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tran726b8542017-01-19 22:28:00 -08004753 list_add_tail(&new_fcport->list, &vha->vp_fcports);
4754
4755 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4756
Linus Torvalds1da177e2005-04-16 15:20:36 -07004757
4758 /* Allocate a new replacement fcport. */
4759 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004760 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004761 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004762 ql_log(ql_log_warn, vha, 0x2066,
4763 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004764 return (QLA_MEMORY_ALLOC_FAILED);
4765 }
4766 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
4767 new_fcport->d_id.b24 = nxt_d_id.b24;
4768 }
4769
Quinn Tran726b8542017-01-19 22:28:00 -08004770 qla2x00_free_fcport(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004771
Quinn Tran726b8542017-01-19 22:28:00 -08004772 /*
4773 * Logout all previous fabric dev marked lost, except FCP2 devices.
4774 */
4775 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4776 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4777 break;
4778
4779 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
4780 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
4781 continue;
4782
4783 if (fcport->scan_state == QLA_FCPORT_SCAN) {
4784 if ((qla_dual_mode_enabled(vha) ||
4785 qla_ini_mode_enabled(vha)) &&
4786 atomic_read(&fcport->state) == FCS_ONLINE) {
4787 qla2x00_mark_device_lost(vha, fcport,
4788 ql2xplogiabsentdevice, 0);
4789 if (fcport->loop_id != FC_NO_LOOP_ID &&
4790 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
4791 fcport->port_type != FCT_INITIATOR &&
4792 fcport->port_type != FCT_BROADCAST) {
4793 ql_dbg(ql_dbg_disc, vha, 0xffff,
4794 "%s %d %8phC post del sess\n",
4795 __func__, __LINE__,
4796 fcport->port_name);
4797
4798 qlt_schedule_sess_for_deletion_lock
4799 (fcport);
4800 continue;
4801 }
4802 }
4803 }
4804
4805 if (fcport->scan_state == QLA_FCPORT_FOUND)
4806 qla24xx_fcport_handle_login(vha, fcport);
4807 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808 return (rval);
4809}
4810
4811/*
4812 * qla2x00_find_new_loop_id
4813 * Scan through our port list and find a new usable loop ID.
4814 *
4815 * Input:
4816 * ha: adapter state pointer.
4817 * dev: port structure pointer.
4818 *
4819 * Returns:
4820 * qla2x00 local function return status code.
4821 *
4822 * Context:
4823 * Kernel context.
4824 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07004825int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004826qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004827{
4828 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004829 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07004830 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004831
4832 rval = QLA_SUCCESS;
4833
Chad Dupuis5f16b332012-08-22 14:21:00 -04004834 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004835
Chad Dupuis5f16b332012-08-22 14:21:00 -04004836 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
4837 LOOPID_MAP_SIZE);
4838 if (dev->loop_id >= LOOPID_MAP_SIZE ||
4839 qla2x00_is_reserved_id(vha, dev->loop_id)) {
4840 dev->loop_id = FC_NO_LOOP_ID;
4841 rval = QLA_FUNCTION_FAILED;
4842 } else
4843 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844
Chad Dupuis5f16b332012-08-22 14:21:00 -04004845 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846
Chad Dupuis5f16b332012-08-22 14:21:00 -04004847 if (rval == QLA_SUCCESS)
4848 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
4849 "Assigning new loopid=%x, portid=%x.\n",
4850 dev->loop_id, dev->d_id.b24);
4851 else
4852 ql_log(ql_log_warn, dev->vha, 0x2087,
4853 "No loop_id's available, portid=%x.\n",
4854 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855
4856 return (rval);
4857}
4858
Linus Torvalds1da177e2005-04-16 15:20:36 -07004859
4860/*
4861 * qla2x00_fabric_login
4862 * Issue fabric login command.
4863 *
4864 * Input:
4865 * ha = adapter block pointer.
4866 * device = pointer to FC device type structure.
4867 *
4868 * Returns:
4869 * 0 - Login successfully
4870 * 1 - Login failed
4871 * 2 - Initiator device
4872 * 3 - Fatal error
4873 */
4874int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004875qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876 uint16_t *next_loopid)
4877{
4878 int rval;
4879 int retry;
4880 uint16_t tmp_loopid;
4881 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004882 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004883
4884 retry = 0;
4885 tmp_loopid = 0;
4886
4887 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004888 ql_dbg(ql_dbg_disc, vha, 0x2000,
4889 "Trying Fabric Login w/loop id 0x%04x for port "
4890 "%02x%02x%02x.\n",
4891 fcport->loop_id, fcport->d_id.b.domain,
4892 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004893
4894 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08004895 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004896 fcport->d_id.b.domain, fcport->d_id.b.area,
4897 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08004898 if (rval != QLA_SUCCESS) {
4899 return rval;
4900 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004901 if (mb[0] == MBS_PORT_ID_USED) {
4902 /*
4903 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004904 * recommends the driver perform an implicit login with
4905 * the specified ID again. The ID we just used is save
4906 * here so we return with an ID that can be tried by
4907 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908 */
4909 retry++;
4910 tmp_loopid = fcport->loop_id;
4911 fcport->loop_id = mb[1];
4912
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004913 ql_dbg(ql_dbg_disc, vha, 0x2001,
4914 "Fabric Login: port in use - next loop "
4915 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004917 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918
4919 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
4920 /*
4921 * Login succeeded.
4922 */
4923 if (retry) {
4924 /* A retry occurred before. */
4925 *next_loopid = tmp_loopid;
4926 } else {
4927 /*
4928 * No retry occurred before. Just increment the
4929 * ID value for next login.
4930 */
4931 *next_loopid = (fcport->loop_id + 1);
4932 }
4933
4934 if (mb[1] & BIT_0) {
4935 fcport->port_type = FCT_INITIATOR;
4936 } else {
4937 fcport->port_type = FCT_TARGET;
4938 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07004939 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004940 }
4941 }
4942
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004943 if (mb[10] & BIT_0)
4944 fcport->supported_classes |= FC_COS_CLASS2;
4945 if (mb[10] & BIT_1)
4946 fcport->supported_classes |= FC_COS_CLASS3;
4947
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004948 if (IS_FWI2_CAPABLE(ha)) {
4949 if (mb[10] & BIT_7)
4950 fcport->flags |=
4951 FCF_CONF_COMP_SUPPORTED;
4952 }
4953
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 rval = QLA_SUCCESS;
4955 break;
4956 } else if (mb[0] == MBS_LOOP_ID_USED) {
4957 /*
4958 * Loop ID already used, try next loop ID.
4959 */
4960 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004961 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962 if (rval != QLA_SUCCESS) {
4963 /* Ran out of loop IDs to use */
4964 break;
4965 }
4966 } else if (mb[0] == MBS_COMMAND_ERROR) {
4967 /*
4968 * Firmware possibly timed out during login. If NO
4969 * retries are left to do then the device is declared
4970 * dead.
4971 */
4972 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004973 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07004974 fcport->d_id.b.domain, fcport->d_id.b.area,
4975 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004976 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977
4978 rval = 1;
4979 break;
4980 } else {
4981 /*
4982 * unrecoverable / not handled error
4983 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004984 ql_dbg(ql_dbg_disc, vha, 0x2002,
4985 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
4986 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
4987 fcport->d_id.b.area, fcport->d_id.b.al_pa,
4988 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989
4990 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004991 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07004992 fcport->d_id.b.domain, fcport->d_id.b.area,
4993 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004994 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07004995 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004996
4997 rval = 3;
4998 break;
4999 }
5000 }
5001
5002 return (rval);
5003}
5004
5005/*
5006 * qla2x00_local_device_login
5007 * Issue local device login command.
5008 *
5009 * Input:
5010 * ha = adapter block pointer.
5011 * loop_id = loop id of device to login to.
5012 *
5013 * Returns (Where's the #define!!!!):
5014 * 0 - Login successfully
5015 * 1 - Login failed
5016 * 3 - Fatal error
5017 */
5018int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005019qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005020{
5021 int rval;
5022 uint16_t mb[MAILBOX_REGISTER_COUNT];
5023
5024 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005025 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026 if (rval == QLA_SUCCESS) {
5027 /* Interrogate mailbox registers for any errors */
5028 if (mb[0] == MBS_COMMAND_ERROR)
5029 rval = 1;
5030 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
5031 /* device not in PCB table */
5032 rval = 3;
5033 }
5034
5035 return (rval);
5036}
5037
5038/*
5039 * qla2x00_loop_resync
5040 * Resync with fibre channel devices.
5041 *
5042 * Input:
5043 * ha = adapter block pointer.
5044 *
5045 * Returns:
5046 * 0 = success
5047 */
5048int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005049qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005051 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005052 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005053 struct req_que *req;
5054 struct rsp_que *rsp;
5055
Michael Hernandezd7459522016-12-12 14:40:07 -08005056 req = vha->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005057 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005059 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5060 if (vha->flags.online) {
5061 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005062 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5063 wait_time = 256;
5064 do {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005065 if (!IS_QLAFX00(vha->hw)) {
5066 /*
5067 * Issue a marker after FW becomes
5068 * ready.
5069 */
5070 qla2x00_marker(vha, req, rsp, 0, 0,
5071 MK_SYNC_ALL);
5072 vha->marker_needed = 0;
5073 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074
5075 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005076 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005078 if (IS_QLAFX00(vha->hw))
5079 qlafx00_configure_devices(vha);
5080 else
5081 qla2x00_configure_loop(vha);
5082
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005084 } while (!atomic_read(&vha->loop_down_timer) &&
5085 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5086 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
5087 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005089 }
5090
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005091 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005092 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005094 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005095 ql_dbg(ql_dbg_disc, vha, 0x206c,
5096 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005097
5098 return (rval);
5099}
5100
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005101/*
5102* qla2x00_perform_loop_resync
5103* Description: This function will set the appropriate flags and call
5104* qla2x00_loop_resync. If successful loop will be resynced
5105* Arguments : scsi_qla_host_t pointer
5106* returm : Success or Failure
5107*/
5108
5109int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
5110{
5111 int32_t rval = 0;
5112
5113 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
5114 /*Configure the flags so that resync happens properly*/
5115 atomic_set(&ha->loop_down_timer, 0);
5116 if (!(ha->device_flags & DFLG_NO_CABLE)) {
5117 atomic_set(&ha->loop_state, LOOP_UP);
5118 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
5119 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
5120 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
5121
5122 rval = qla2x00_loop_resync(ha);
5123 } else
5124 atomic_set(&ha->loop_state, LOOP_DEAD);
5125
5126 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
5127 }
5128
5129 return rval;
5130}
5131
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132void
Andrew Vasquez67becc02009-08-25 11:36:20 -07005133qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005134{
5135 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07005136 struct scsi_qla_host *vha;
5137 struct qla_hw_data *ha = base_vha->hw;
5138 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005139
Arun Easifeafb7b2010-09-03 14:57:00 -07005140 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005141 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07005142 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
5143 atomic_inc(&vha->vref_count);
5144 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08005145 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07005146 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
5147 spin_unlock_irqrestore(&ha->vport_slock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07005148 qla2x00_rport_del(fcport);
Alexei Potashnikdf673272015-07-14 16:00:46 -04005149
Arun Easifeafb7b2010-09-03 14:57:00 -07005150 spin_lock_irqsave(&ha->vport_slock, flags);
5151 }
5152 }
5153 atomic_dec(&vha->vref_count);
5154 }
5155 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005156}
5157
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005158/* Assumes idc_lock always held on entry */
5159void
5160qla83xx_reset_ownership(scsi_qla_host_t *vha)
5161{
5162 struct qla_hw_data *ha = vha->hw;
5163 uint32_t drv_presence, drv_presence_mask;
5164 uint32_t dev_part_info1, dev_part_info2, class_type;
5165 uint32_t class_type_mask = 0x3;
5166 uint16_t fcoe_other_function = 0xffff, i;
5167
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005168 if (IS_QLA8044(ha)) {
5169 drv_presence = qla8044_rd_direct(vha,
5170 QLA8044_CRB_DRV_ACTIVE_INDEX);
5171 dev_part_info1 = qla8044_rd_direct(vha,
5172 QLA8044_CRB_DEV_PART_INFO_INDEX);
5173 dev_part_info2 = qla8044_rd_direct(vha,
5174 QLA8044_CRB_DEV_PART_INFO2);
5175 } else {
5176 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5177 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
5178 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
5179 }
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005180 for (i = 0; i < 8; i++) {
5181 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
5182 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5183 (i != ha->portnum)) {
5184 fcoe_other_function = i;
5185 break;
5186 }
5187 }
5188 if (fcoe_other_function == 0xffff) {
5189 for (i = 0; i < 8; i++) {
5190 class_type = ((dev_part_info2 >> (i * 4)) &
5191 class_type_mask);
5192 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5193 ((i + 8) != ha->portnum)) {
5194 fcoe_other_function = i + 8;
5195 break;
5196 }
5197 }
5198 }
5199 /*
5200 * Prepare drv-presence mask based on fcoe functions present.
5201 * However consider only valid physical fcoe function numbers (0-15).
5202 */
5203 drv_presence_mask = ~((1 << (ha->portnum)) |
5204 ((fcoe_other_function == 0xffff) ?
5205 0 : (1 << (fcoe_other_function))));
5206
5207 /* We are the reset owner iff:
5208 * - No other protocol drivers present.
5209 * - This is the lowest among fcoe functions. */
5210 if (!(drv_presence & drv_presence_mask) &&
5211 (ha->portnum < fcoe_other_function)) {
5212 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
5213 "This host is Reset owner.\n");
5214 ha->flags.nic_core_reset_owner = 1;
5215 }
5216}
5217
Saurav Kashyapfa492632012-11-21 02:40:29 -05005218static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005219__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
5220{
5221 int rval = QLA_SUCCESS;
5222 struct qla_hw_data *ha = vha->hw;
5223 uint32_t drv_ack;
5224
5225 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5226 if (rval == QLA_SUCCESS) {
5227 drv_ack |= (1 << ha->portnum);
5228 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5229 }
5230
5231 return rval;
5232}
5233
Saurav Kashyapfa492632012-11-21 02:40:29 -05005234static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005235__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
5236{
5237 int rval = QLA_SUCCESS;
5238 struct qla_hw_data *ha = vha->hw;
5239 uint32_t drv_ack;
5240
5241 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5242 if (rval == QLA_SUCCESS) {
5243 drv_ack &= ~(1 << ha->portnum);
5244 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5245 }
5246
5247 return rval;
5248}
5249
Saurav Kashyapfa492632012-11-21 02:40:29 -05005250static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005251qla83xx_dev_state_to_string(uint32_t dev_state)
5252{
5253 switch (dev_state) {
5254 case QLA8XXX_DEV_COLD:
5255 return "COLD/RE-INIT";
5256 case QLA8XXX_DEV_INITIALIZING:
5257 return "INITIALIZING";
5258 case QLA8XXX_DEV_READY:
5259 return "READY";
5260 case QLA8XXX_DEV_NEED_RESET:
5261 return "NEED RESET";
5262 case QLA8XXX_DEV_NEED_QUIESCENT:
5263 return "NEED QUIESCENT";
5264 case QLA8XXX_DEV_FAILED:
5265 return "FAILED";
5266 case QLA8XXX_DEV_QUIESCENT:
5267 return "QUIESCENT";
5268 default:
5269 return "Unknown";
5270 }
5271}
5272
5273/* Assumes idc-lock always held on entry */
5274void
5275qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
5276{
5277 struct qla_hw_data *ha = vha->hw;
5278 uint32_t idc_audit_reg = 0, duration_secs = 0;
5279
5280 switch (audit_type) {
5281 case IDC_AUDIT_TIMESTAMP:
5282 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
5283 idc_audit_reg = (ha->portnum) |
5284 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
5285 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5286 break;
5287
5288 case IDC_AUDIT_COMPLETION:
5289 duration_secs = ((jiffies_to_msecs(jiffies) -
5290 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
5291 idc_audit_reg = (ha->portnum) |
5292 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
5293 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5294 break;
5295
5296 default:
5297 ql_log(ql_log_warn, vha, 0xb078,
5298 "Invalid audit type specified.\n");
5299 break;
5300 }
5301}
5302
5303/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05005304static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005305qla83xx_initiating_reset(scsi_qla_host_t *vha)
5306{
5307 struct qla_hw_data *ha = vha->hw;
5308 uint32_t idc_control, dev_state;
5309
5310 __qla83xx_get_idc_control(vha, &idc_control);
5311 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
5312 ql_log(ql_log_info, vha, 0xb080,
5313 "NIC Core reset has been disabled. idc-control=0x%x\n",
5314 idc_control);
5315 return QLA_FUNCTION_FAILED;
5316 }
5317
5318 /* Set NEED-RESET iff in READY state and we are the reset-owner */
5319 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5320 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
5321 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
5322 QLA8XXX_DEV_NEED_RESET);
5323 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
5324 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
5325 } else {
5326 const char *state = qla83xx_dev_state_to_string(dev_state);
5327 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
5328
5329 /* SV: XXX: Is timeout required here? */
5330 /* Wait for IDC state change READY -> NEED_RESET */
5331 while (dev_state == QLA8XXX_DEV_READY) {
5332 qla83xx_idc_unlock(vha, 0);
5333 msleep(200);
5334 qla83xx_idc_lock(vha, 0);
5335 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5336 }
5337 }
5338
5339 /* Send IDC ack by writing to drv-ack register */
5340 __qla83xx_set_drv_ack(vha);
5341
5342 return QLA_SUCCESS;
5343}
5344
5345int
5346__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
5347{
5348 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5349}
5350
5351int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005352__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
5353{
5354 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5355}
5356
Saurav Kashyapfa492632012-11-21 02:40:29 -05005357static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005358qla83xx_check_driver_presence(scsi_qla_host_t *vha)
5359{
5360 uint32_t drv_presence = 0;
5361 struct qla_hw_data *ha = vha->hw;
5362
5363 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5364 if (drv_presence & (1 << ha->portnum))
5365 return QLA_SUCCESS;
5366 else
5367 return QLA_TEST_FAILED;
5368}
5369
5370int
5371qla83xx_nic_core_reset(scsi_qla_host_t *vha)
5372{
5373 int rval = QLA_SUCCESS;
5374 struct qla_hw_data *ha = vha->hw;
5375
5376 ql_dbg(ql_dbg_p3p, vha, 0xb058,
5377 "Entered %s().\n", __func__);
5378
5379 if (vha->device_flags & DFLG_DEV_FAILED) {
5380 ql_log(ql_log_warn, vha, 0xb059,
5381 "Device in unrecoverable FAILED state.\n");
5382 return QLA_FUNCTION_FAILED;
5383 }
5384
5385 qla83xx_idc_lock(vha, 0);
5386
5387 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
5388 ql_log(ql_log_warn, vha, 0xb05a,
5389 "Function=0x%x has been removed from IDC participation.\n",
5390 ha->portnum);
5391 rval = QLA_FUNCTION_FAILED;
5392 goto exit;
5393 }
5394
5395 qla83xx_reset_ownership(vha);
5396
5397 rval = qla83xx_initiating_reset(vha);
5398
5399 /*
5400 * Perform reset if we are the reset-owner,
5401 * else wait till IDC state changes to READY/FAILED.
5402 */
5403 if (rval == QLA_SUCCESS) {
5404 rval = qla83xx_idc_state_handler(vha);
5405
5406 if (rval == QLA_SUCCESS)
5407 ha->flags.nic_core_hung = 0;
5408 __qla83xx_clear_drv_ack(vha);
5409 }
5410
5411exit:
5412 qla83xx_idc_unlock(vha, 0);
5413
5414 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
5415
5416 return rval;
5417}
5418
Saurav Kashyap81178772012-08-22 14:21:04 -04005419int
5420qla2xxx_mctp_dump(scsi_qla_host_t *vha)
5421{
5422 struct qla_hw_data *ha = vha->hw;
5423 int rval = QLA_FUNCTION_FAILED;
5424
5425 if (!IS_MCTP_CAPABLE(ha)) {
5426 /* This message can be removed from the final version */
5427 ql_log(ql_log_info, vha, 0x506d,
5428 "This board is not MCTP capable\n");
5429 return rval;
5430 }
5431
5432 if (!ha->mctp_dump) {
5433 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
5434 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
5435
5436 if (!ha->mctp_dump) {
5437 ql_log(ql_log_warn, vha, 0x506e,
5438 "Failed to allocate memory for mctp dump\n");
5439 return rval;
5440 }
5441 }
5442
5443#define MCTP_DUMP_STR_ADDR 0x00000000
5444 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
5445 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
5446 if (rval != QLA_SUCCESS) {
5447 ql_log(ql_log_warn, vha, 0x506f,
5448 "Failed to capture mctp dump\n");
5449 } else {
5450 ql_log(ql_log_info, vha, 0x5070,
5451 "Mctp dump capture for host (%ld/%p).\n",
5452 vha->host_no, ha->mctp_dump);
5453 ha->mctp_dumped = 1;
5454 }
5455
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04005456 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04005457 ha->flags.nic_core_reset_hdlr_active = 1;
5458 rval = qla83xx_restart_nic_firmware(vha);
5459 if (rval)
5460 /* NIC Core reset failed. */
5461 ql_log(ql_log_warn, vha, 0x5071,
5462 "Failed to restart nic firmware\n");
5463 else
5464 ql_dbg(ql_dbg_p3p, vha, 0xb084,
5465 "Restarted NIC firmware successfully.\n");
5466 ha->flags.nic_core_reset_hdlr_active = 0;
5467 }
5468
5469 return rval;
5470
5471}
5472
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005473/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005474* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005475* Description: This function will block the new I/Os
5476* Its not aborting any I/Os as context
5477* is not destroyed during quiescence
5478* Arguments: scsi_qla_host_t
5479* return : void
5480*/
5481void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005482qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005483{
5484 struct qla_hw_data *ha = vha->hw;
5485 struct scsi_qla_host *vp;
5486
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005487 ql_dbg(ql_dbg_dpc, vha, 0x401d,
5488 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005489
5490 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
5491 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
5492 atomic_set(&vha->loop_state, LOOP_DOWN);
5493 qla2x00_mark_all_devices_lost(vha, 0);
5494 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005495 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005496 } else {
5497 if (!atomic_read(&vha->loop_down_timer))
5498 atomic_set(&vha->loop_down_timer,
5499 LOOP_DOWN_TIME);
5500 }
5501 /* Wait for pending cmds to complete */
5502 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
5503}
5504
Giridhar Malavalia9083012010-04-12 17:59:55 -07005505void
5506qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
5507{
5508 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005509 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005510 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08005511 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005512
Saurav Kashyape46ef002011-02-23 15:27:16 -08005513 /* For ISP82XX, driver waits for completion of the commands.
5514 * online flag should be set.
5515 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005516 if (!(IS_P3P_TYPE(ha)))
Saurav Kashyape46ef002011-02-23 15:27:16 -08005517 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005518 ha->flags.chip_reset_done = 0;
5519 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04005520 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005521
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005522 ql_log(ql_log_info, vha, 0x00af,
5523 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005524
Saurav Kashyape46ef002011-02-23 15:27:16 -08005525 /* For ISP82XX, reset_chip is just disabling interrupts.
5526 * Driver waits for the completion of the commands.
5527 * the interrupts need to be enabled.
5528 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005529 if (!(IS_P3P_TYPE(ha)))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005530 ha->isp_ops->reset_chip(vha);
5531
Quinn Tran726b8542017-01-19 22:28:00 -08005532 ha->chip_reset++;
5533
Giridhar Malavalia9083012010-04-12 17:59:55 -07005534 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
5535 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
5536 atomic_set(&vha->loop_state, LOOP_DOWN);
5537 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07005538
5539 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005540 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07005541 atomic_inc(&vp->vref_count);
5542 spin_unlock_irqrestore(&ha->vport_slock, flags);
5543
Giridhar Malavalia9083012010-04-12 17:59:55 -07005544 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07005545
5546 spin_lock_irqsave(&ha->vport_slock, flags);
5547 atomic_dec(&vp->vref_count);
5548 }
5549 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005550 } else {
5551 if (!atomic_read(&vha->loop_down_timer))
5552 atomic_set(&vha->loop_down_timer,
5553 LOOP_DOWN_TIME);
5554 }
5555
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08005556 /* Clear all async request states across all VPs. */
5557 list_for_each_entry(fcport, &vha->vp_fcports, list)
5558 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5559 spin_lock_irqsave(&ha->vport_slock, flags);
5560 list_for_each_entry(vp, &ha->vp_list, list) {
5561 atomic_inc(&vp->vref_count);
5562 spin_unlock_irqrestore(&ha->vport_slock, flags);
5563
5564 list_for_each_entry(fcport, &vp->vp_fcports, list)
5565 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5566
5567 spin_lock_irqsave(&ha->vport_slock, flags);
5568 atomic_dec(&vp->vref_count);
5569 }
5570 spin_unlock_irqrestore(&ha->vport_slock, flags);
5571
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005572 if (!ha->flags.eeh_busy) {
5573 /* Make sure for ISP 82XX IO DMA is complete */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005574 if (IS_P3P_TYPE(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005575 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005576 ql_log(ql_log_info, vha, 0x00b4,
5577 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005578
Saurav Kashyape46ef002011-02-23 15:27:16 -08005579 /* Done waiting for pending commands.
5580 * Reset the online flag.
5581 */
5582 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005583 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005584
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005585 /* Requeue all commands in outstanding command list. */
5586 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
5587 }
Arun Easib6a029e2014-09-25 06:14:52 -04005588 /* memory barrier */
5589 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005590}
5591
5592/*
5593* qla2x00_abort_isp
5594* Resets ISP and aborts all outstanding commands.
5595*
5596* Input:
5597* ha = adapter block pointer.
5598*
5599* Returns:
5600* 0 = success
5601*/
5602int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005603qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005604{
Andrew Vasquez476e8972006-08-23 14:54:55 -07005605 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005606 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005607 struct qla_hw_data *ha = vha->hw;
5608 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005609 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07005610 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005611
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005612 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07005613 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005614
Santosh Vernekara61712972012-08-22 14:21:13 -04005615 if (IS_QLA8031(ha)) {
5616 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
5617 "Clearing fcoe driver presence.\n");
5618 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
5619 ql_dbg(ql_dbg_p3p, vha, 0xb073,
5620 "Error while clearing DRV-Presence.\n");
5621 }
5622
Andrew Vasquez85880802009-12-15 21:29:46 -08005623 if (unlikely(pci_channel_offline(ha->pdev) &&
5624 ha->flags.pci_channel_io_perm_failure)) {
5625 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5626 status = 0;
5627 return status;
5628 }
5629
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005630 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08005631
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005632 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005633
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005634 if (!qla2x00_restart_isp(vha)) {
5635 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005636
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005637 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005638 /*
5639 * Issue marker command only when we are going
5640 * to start the I/O .
5641 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005642 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005643 }
5644
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005645 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005646
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005647 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005648
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07005649 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005650 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07005651
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005652 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
5653 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08005654 if (ha->fce) {
5655 ha->flags.fce_enabled = 1;
5656 memset(ha->fce, 0,
5657 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005658 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08005659 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5660 &ha->fce_bufs);
5661 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005662 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08005663 "Unable to reinitialize FCE "
5664 "(%d).\n", rval);
5665 ha->flags.fce_enabled = 0;
5666 }
5667 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07005668
5669 if (ha->eft) {
5670 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005671 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07005672 ha->eft_dma, EFT_NUM_BUFFERS);
5673 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005674 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07005675 "Unable to reinitialize EFT "
5676 "(%d).\n", rval);
5677 }
5678 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005679 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005680 vha->flags.online = 1;
5681 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005682 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005683 ql_log(ql_log_fatal, vha, 0x8035,
5684 "ISP error recover failed - "
5685 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07005686 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005687 * The next call disables the board
5688 * completely.
5689 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005690 ha->isp_ops->reset_adapter(vha);
5691 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005692 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005693 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005694 status = 0;
5695 } else { /* schedule another ISP abort */
5696 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005697 ql_dbg(ql_dbg_taskm, vha, 0x8020,
5698 "ISP abort - retry remaining %d.\n",
5699 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005700 status = 1;
5701 }
5702 } else {
5703 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005704 ql_dbg(ql_dbg_taskm, vha, 0x8021,
5705 "ISP error recovery - retrying (%d) "
5706 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005707 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005708 status = 1;
5709 }
5710 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07005711
Linus Torvalds1da177e2005-04-16 15:20:36 -07005712 }
5713
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005714 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005715 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07005716
5717 spin_lock_irqsave(&ha->vport_slock, flags);
5718 list_for_each_entry(vp, &ha->vp_list, list) {
5719 if (vp->vp_idx) {
5720 atomic_inc(&vp->vref_count);
5721 spin_unlock_irqrestore(&ha->vport_slock, flags);
5722
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005723 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07005724
5725 spin_lock_irqsave(&ha->vport_slock, flags);
5726 atomic_dec(&vp->vref_count);
5727 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005728 }
Arun Easifeafb7b2010-09-03 14:57:00 -07005729 spin_unlock_irqrestore(&ha->vport_slock, flags);
5730
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005731 if (IS_QLA8031(ha)) {
5732 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
5733 "Setting back fcoe driver presence.\n");
5734 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
5735 ql_dbg(ql_dbg_p3p, vha, 0xb074,
5736 "Error while setting DRV-Presence.\n");
5737 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005738 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08005739 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
5740 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005741 }
5742
5743 return(status);
5744}
5745
5746/*
5747* qla2x00_restart_isp
5748* restarts the ISP after a reset
5749*
5750* Input:
5751* ha = adapter block pointer.
5752*
5753* Returns:
5754* 0 = success
5755*/
5756static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005757qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08005759 int status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005760 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005761 struct req_que *req = ha->req_q_map[0];
5762 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005763
5764 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005765 if (qla2x00_isp_firmware(vha)) {
5766 vha->flags.online = 0;
5767 status = ha->isp_ops->chip_diag(vha);
5768 if (!status)
5769 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005770 }
5771
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005772 if (!status && !(status = qla2x00_init_rings(vha))) {
5773 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07005774 ha->flags.chip_reset_done = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04005775
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005776 /* Initialize the queues in use */
5777 qla25xx_init_queues(ha);
5778
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005779 status = qla2x00_fw_ready(vha);
5780 if (!status) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005781 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005782 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Chad Dupuis7108b762014-04-11 16:54:45 -04005783 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005784 }
5785
5786 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005787 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005788 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005789 }
5790 return (status);
5791}
5792
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005793static int
5794qla25xx_init_queues(struct qla_hw_data *ha)
5795{
5796 struct rsp_que *rsp = NULL;
5797 struct req_que *req = NULL;
5798 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5799 int ret = -1;
5800 int i;
5801
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07005802 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005803 rsp = ha->rsp_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05005804 if (rsp && test_bit(i, ha->rsp_qid_map)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005805 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08005806 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005807 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005808 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
5809 "%s Rsp que: %d init failed.\n",
5810 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005811 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005812 ql_dbg(ql_dbg_init, base_vha, 0x0100,
5813 "%s Rsp que: %d inited.\n",
5814 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005815 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07005816 }
5817 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005818 req = ha->req_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05005819 if (req && test_bit(i, ha->req_qid_map)) {
5820 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005821 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08005822 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005823 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005824 ql_dbg(ql_dbg_init, base_vha, 0x0101,
5825 "%s Req que: %d init failed.\n",
5826 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005827 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005828 ql_dbg(ql_dbg_init, base_vha, 0x0102,
5829 "%s Req que: %d inited.\n",
5830 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005831 }
5832 }
5833 return ret;
5834}
5835
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836/*
5837* qla2x00_reset_adapter
5838* Reset adapter.
5839*
5840* Input:
5841* ha = adapter block pointer.
5842*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07005843void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005844qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005845{
5846 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005847 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07005848 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005849
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005850 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005851 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005852
Linus Torvalds1da177e2005-04-16 15:20:36 -07005853 spin_lock_irqsave(&ha->hardware_lock, flags);
5854 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
5855 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
5856 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
5857 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
5858 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5859}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005860
5861void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005862qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005863{
5864 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005865 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005866 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
5867
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005868 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005869 return;
5870
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005871 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005872 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005873
5874 spin_lock_irqsave(&ha->hardware_lock, flags);
5875 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
5876 RD_REG_DWORD(&reg->hccr);
5877 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
5878 RD_REG_DWORD(&reg->hccr);
5879 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08005880
5881 if (IS_NOPOLLING_TYPE(ha))
5882 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005883}
5884
David Miller4e08df32007-04-16 12:37:43 -07005885/* On sparc systems, obtain port and node WWN from firmware
5886 * properties.
5887 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005888static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
5889 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07005890{
5891#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005892 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07005893 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07005894 struct device_node *dp = pci_device_to_OF_node(pdev);
5895 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07005896 int len;
5897
5898 val = of_get_property(dp, "port-wwn", &len);
5899 if (val && len >= WWN_SIZE)
5900 memcpy(nv->port_name, val, WWN_SIZE);
5901
5902 val = of_get_property(dp, "node-wwn", &len);
5903 if (val && len >= WWN_SIZE)
5904 memcpy(nv->node_name, val, WWN_SIZE);
5905#endif
5906}
5907
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005908int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005909qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005910{
David Miller4e08df32007-04-16 12:37:43 -07005911 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005912 struct init_cb_24xx *icb;
5913 struct nvram_24xx *nv;
5914 uint32_t *dptr;
5915 uint8_t *dptr1, *dptr2;
5916 uint32_t chksum;
5917 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005918 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005919
David Miller4e08df32007-04-16 12:37:43 -07005920 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005921 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07005922 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005923
5924 /* Determine NVRAM starting address. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05005925 if (ha->port_no == 0) {
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005926 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
5927 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
5928 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005929 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08005930 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
5931 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05005932
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005933 ha->nvram_size = sizeof(struct nvram_24xx);
5934 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005935
Seokmann Ju281afe12007-07-26 13:43:34 -07005936 /* Get VPD data into cache */
5937 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005938 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07005939 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
5940
5941 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005942 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005943 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005944 ha->nvram_size);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05005945 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
5946 chksum += le32_to_cpu(*dptr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005947
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005948 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
5949 "Contents of NVRAM\n");
5950 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
5951 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005952
5953 /* Bad NVRAM data, set defaults parameters. */
5954 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5955 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07005956 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005957 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005958 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04005959 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005960 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
5961 ql_log(ql_log_warn, vha, 0x006c,
5962 "Falling back to functioning (yet invalid -- WWPN) "
5963 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07005964
5965 /*
5966 * Set default initialization control block.
5967 */
5968 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07005969 nv->nvram_version = cpu_to_le16(ICB_VERSION);
5970 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04005971 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07005972 nv->execution_throttle = cpu_to_le16(0xFFFF);
5973 nv->exchange_count = cpu_to_le16(0);
5974 nv->hard_address = cpu_to_le16(124);
David Miller4e08df32007-04-16 12:37:43 -07005975 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005976 nv->port_name[1] = 0x00 + ha->port_no + 1;
David Miller4e08df32007-04-16 12:37:43 -07005977 nv->port_name[2] = 0x00;
5978 nv->port_name[3] = 0xe0;
5979 nv->port_name[4] = 0x8b;
5980 nv->port_name[5] = 0x1c;
5981 nv->port_name[6] = 0x55;
5982 nv->port_name[7] = 0x86;
5983 nv->node_name[0] = 0x20;
5984 nv->node_name[1] = 0x00;
5985 nv->node_name[2] = 0x00;
5986 nv->node_name[3] = 0xe0;
5987 nv->node_name[4] = 0x8b;
5988 nv->node_name[5] = 0x1c;
5989 nv->node_name[6] = 0x55;
5990 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005991 qla24xx_nvram_wwn_from_ofw(vha, nv);
Bart Van Asschead950362015-07-09 07:24:08 -07005992 nv->login_retry_count = cpu_to_le16(8);
5993 nv->interrupt_delay_timer = cpu_to_le16(0);
5994 nv->login_timeout = cpu_to_le16(0);
David Miller4e08df32007-04-16 12:37:43 -07005995 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07005996 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5997 nv->firmware_options_2 = cpu_to_le32(2 << 4);
5998 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
5999 nv->firmware_options_3 = cpu_to_le32(2 << 13);
6000 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6001 nv->efi_parameters = cpu_to_le32(0);
David Miller4e08df32007-04-16 12:37:43 -07006002 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07006003 nv->max_luns_per_target = cpu_to_le16(128);
6004 nv->port_down_retry_count = cpu_to_le16(30);
6005 nv->link_down_timeout = cpu_to_le16(30);
David Miller4e08df32007-04-16 12:37:43 -07006006
6007 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006008 }
6009
Quinn Tran726b8542017-01-19 22:28:00 -08006010 if (qla_tgt_mode_enabled(vha)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006011 /* Don't enable full login after initial LIP */
Bart Van Asschead950362015-07-09 07:24:08 -07006012 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006013 /* Don't enable LIP full login for initiator */
Bart Van Asschead950362015-07-09 07:24:08 -07006014 nv->host_p &= cpu_to_le32(~BIT_10);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006015 }
6016
6017 qlt_24xx_config_nvram_stage1(vha, nv);
6018
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006019 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006020 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006021
6022 /* Copy 1st segment. */
6023 dptr1 = (uint8_t *)icb;
6024 dptr2 = (uint8_t *)&nv->version;
6025 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6026 while (cnt--)
6027 *dptr1++ = *dptr2++;
6028
6029 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07006030 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006031
6032 /* Copy 2nd segment. */
6033 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6034 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6035 cnt = (uint8_t *)&icb->reserved_3 -
6036 (uint8_t *)&icb->interrupt_delay_timer;
6037 while (cnt--)
6038 *dptr1++ = *dptr2++;
6039
6040 /*
6041 * Setup driver NVRAM options.
6042 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006043 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08006044 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006045
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006046 qlt_24xx_config_nvram_stage2(vha, icb);
6047
Bart Van Asschead950362015-07-09 07:24:08 -07006048 if (nv->host_p & cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006049 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07006050 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6051 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6052 }
6053
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006054 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07006055 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006056 /*
6057 * Firmware will apply the following mask if the nodename was
6058 * not provided.
6059 */
6060 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6061 icb->node_name[0] &= 0xF0;
6062 }
6063
6064 /* Set host adapter parameters. */
6065 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08006066 ha->flags.enable_lip_reset = 0;
6067 ha->flags.enable_lip_full_login =
6068 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6069 ha->flags.enable_target_reset =
6070 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006071 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07006072 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006073
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07006074 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6075 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006076
6077 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
6078 sizeof(ha->fw_seriallink_options24));
6079
6080 /* save HBA serial number */
6081 ha->serial0 = icb->port_name[5];
6082 ha->serial1 = icb->port_name[6];
6083 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006084 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6085 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006086
Bart Van Asschead950362015-07-09 07:24:08 -07006087 icb->execution_throttle = cpu_to_le16(0xFFFF);
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08006088
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006089 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6090
6091 /* Set minimum login_timeout to 4 seconds. */
6092 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6093 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6094 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07006095 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006096 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006097
Andrew Vasquez00a537b2008-02-28 14:06:11 -08006098 /* Set minimum RATOV to 100 tenths of a second. */
6099 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006100
6101 ha->loop_reset_delay = nv->reset_delay;
6102
6103 /* Link Down Timeout = 0:
6104 *
6105 * When Port Down timer expires we will start returning
6106 * I/O's to OS with "DID_NO_CONNECT".
6107 *
6108 * Link Down Timeout != 0:
6109 *
6110 * The driver waits for the link to come up after link down
6111 * before returning I/Os to OS with "DID_NO_CONNECT".
6112 */
6113 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6114 ha->loop_down_abort_time =
6115 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6116 } else {
6117 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6118 ha->loop_down_abort_time =
6119 (LOOP_DOWN_TIME - ha->link_down_timeout);
6120 }
6121
6122 /* Need enough time to try and get the port back. */
6123 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6124 if (qlport_down_retry)
6125 ha->port_down_retry_count = qlport_down_retry;
6126
6127 /* Set login_retry_count */
6128 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6129 if (ha->port_down_retry_count ==
6130 le16_to_cpu(nv->port_down_retry_count) &&
6131 ha->port_down_retry_count > 3)
6132 ha->login_retry_count = ha->port_down_retry_count;
6133 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6134 ha->login_retry_count = ha->port_down_retry_count;
6135 if (ql2xloginretrycount)
6136 ha->login_retry_count = ql2xloginretrycount;
6137
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006138 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006139 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006140 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6141 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6142 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6143 le16_to_cpu(icb->interrupt_delay_timer): 2;
6144 }
Bart Van Asschead950362015-07-09 07:24:08 -07006145 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006146 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006147 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006148 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08006149 ha->zio_mode = QLA_ZIO_MODE_6;
6150
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006151 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006152 "ZIO mode %d enabled; timer delay (%d us).\n",
6153 ha->zio_mode, ha->zio_timer * 100);
6154
6155 icb->firmware_options_2 |= cpu_to_le32(
6156 (uint32_t)ha->zio_mode);
6157 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006158 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006159 }
6160
David Miller4e08df32007-04-16 12:37:43 -07006161 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006162 ql_log(ql_log_warn, vha, 0x0070,
6163 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07006164 }
6165 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006166}
6167
Sawan Chandak4243c112016-01-27 12:03:31 -05006168uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
6169{
6170 struct qla27xx_image_status pri_image_status, sec_image_status;
6171 uint8_t valid_pri_image, valid_sec_image;
6172 uint32_t *wptr;
6173 uint32_t cnt, chksum, size;
6174 struct qla_hw_data *ha = vha->hw;
6175
6176 valid_pri_image = valid_sec_image = 1;
6177 ha->active_image = 0;
6178 size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
6179
6180 if (!ha->flt_region_img_status_pri) {
6181 valid_pri_image = 0;
6182 goto check_sec_image;
6183 }
6184
6185 qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
6186 ha->flt_region_img_status_pri, size);
6187
6188 if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6189 ql_dbg(ql_dbg_init, vha, 0x018b,
6190 "Primary image signature (0x%x) not valid\n",
6191 pri_image_status.signature);
6192 valid_pri_image = 0;
6193 goto check_sec_image;
6194 }
6195
6196 wptr = (uint32_t *)(&pri_image_status);
6197 cnt = size;
6198
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006199 for (chksum = 0; cnt--; wptr++)
6200 chksum += le32_to_cpu(*wptr);
Quinn Tran41dc5292017-01-19 22:28:03 -08006201
Sawan Chandak4243c112016-01-27 12:03:31 -05006202 if (chksum) {
6203 ql_dbg(ql_dbg_init, vha, 0x018c,
6204 "Checksum validation failed for primary image (0x%x)\n",
6205 chksum);
6206 valid_pri_image = 0;
6207 }
6208
6209check_sec_image:
6210 if (!ha->flt_region_img_status_sec) {
6211 valid_sec_image = 0;
6212 goto check_valid_image;
6213 }
6214
6215 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
6216 ha->flt_region_img_status_sec, size);
6217
6218 if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6219 ql_dbg(ql_dbg_init, vha, 0x018d,
6220 "Secondary image signature(0x%x) not valid\n",
6221 sec_image_status.signature);
6222 valid_sec_image = 0;
6223 goto check_valid_image;
6224 }
6225
6226 wptr = (uint32_t *)(&sec_image_status);
6227 cnt = size;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006228 for (chksum = 0; cnt--; wptr++)
6229 chksum += le32_to_cpu(*wptr);
Sawan Chandak4243c112016-01-27 12:03:31 -05006230 if (chksum) {
6231 ql_dbg(ql_dbg_init, vha, 0x018e,
6232 "Checksum validation failed for secondary image (0x%x)\n",
6233 chksum);
6234 valid_sec_image = 0;
6235 }
6236
6237check_valid_image:
6238 if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
6239 ha->active_image = QLA27XX_PRIMARY_IMAGE;
6240 if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
6241 if (!ha->active_image ||
6242 pri_image_status.generation_number <
6243 sec_image_status.generation_number)
6244 ha->active_image = QLA27XX_SECONDARY_IMAGE;
6245 }
6246
6247 ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n",
6248 ha->active_image == 0 ? "default bootld and fw" :
6249 ha->active_image == 1 ? "primary" :
6250 ha->active_image == 2 ? "secondary" :
6251 "Invalid");
6252
6253 return ha->active_image;
6254}
6255
Adrian Bunk413975a2006-06-30 02:33:06 -07006256static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006257qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
6258 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006259{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006260 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006261 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006262 uint32_t *dcode, dlen;
6263 uint32_t risc_addr;
6264 uint32_t risc_size;
6265 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006266 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006267 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006268
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006269 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006270 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006271
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006272 rval = QLA_SUCCESS;
6273
6274 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006275 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006276 *srisc_addr = 0;
6277
Sawan Chandak4243c112016-01-27 12:03:31 -05006278 if (IS_QLA27XX(ha) &&
6279 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
6280 faddr = ha->flt_region_fw_sec;
6281
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006282 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006283 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006284 for (i = 0; i < 4; i++)
6285 dcode[i] = be32_to_cpu(dcode[i]);
6286 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
6287 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
6288 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
6289 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006290 ql_log(ql_log_fatal, vha, 0x008c,
6291 "Unable to verify the integrity of flash firmware "
6292 "image.\n");
6293 ql_log(ql_log_fatal, vha, 0x008d,
6294 "Firmware data: %08x %08x %08x %08x.\n",
6295 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006296
6297 return QLA_FUNCTION_FAILED;
6298 }
6299
6300 while (segments && rval == QLA_SUCCESS) {
6301 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006302 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006303
6304 risc_addr = be32_to_cpu(dcode[2]);
6305 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
6306 risc_size = be32_to_cpu(dcode[3]);
6307
6308 fragment = 0;
6309 while (risc_size > 0 && rval == QLA_SUCCESS) {
6310 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
6311 if (dlen > risc_size)
6312 dlen = risc_size;
6313
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006314 ql_dbg(ql_dbg_init, vha, 0x008e,
6315 "Loading risc segment@ risc addr %x "
6316 "number of dwords 0x%x offset 0x%x.\n",
6317 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006318
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006319 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006320 for (i = 0; i < dlen; i++)
6321 dcode[i] = swab32(dcode[i]);
6322
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006323 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006324 dlen);
6325 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006326 ql_log(ql_log_fatal, vha, 0x008f,
6327 "Failed to load segment %d of firmware.\n",
6328 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04006329 return QLA_FUNCTION_FAILED;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006330 }
6331
6332 faddr += dlen;
6333 risc_addr += dlen;
6334 risc_size -= dlen;
6335 fragment++;
6336 }
6337
6338 /* Next segment. */
6339 segments--;
6340 }
6341
Chad Dupuisf73cb692014-02-26 04:15:06 -05006342 if (!IS_QLA27XX(ha))
6343 return rval;
6344
6345 if (ha->fw_dump_template)
6346 vfree(ha->fw_dump_template);
6347 ha->fw_dump_template = NULL;
6348 ha->fw_dump_template_len = 0;
6349
6350 ql_dbg(ql_dbg_init, vha, 0x0161,
6351 "Loading fwdump template from %x\n", faddr);
6352 qla24xx_read_flash_data(vha, dcode, faddr, 7);
6353 risc_size = be32_to_cpu(dcode[2]);
6354 ql_dbg(ql_dbg_init, vha, 0x0162,
6355 "-> array size %x dwords\n", risc_size);
6356 if (risc_size == 0 || risc_size == ~0)
6357 goto default_template;
6358
6359 dlen = (risc_size - 8) * sizeof(*dcode);
6360 ql_dbg(ql_dbg_init, vha, 0x0163,
6361 "-> template allocating %x bytes...\n", dlen);
6362 ha->fw_dump_template = vmalloc(dlen);
6363 if (!ha->fw_dump_template) {
6364 ql_log(ql_log_warn, vha, 0x0164,
6365 "Failed fwdump template allocate %x bytes.\n", risc_size);
6366 goto default_template;
6367 }
6368
6369 faddr += 7;
6370 risc_size -= 8;
6371 dcode = ha->fw_dump_template;
6372 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
6373 for (i = 0; i < risc_size; i++)
6374 dcode[i] = le32_to_cpu(dcode[i]);
6375
6376 if (!qla27xx_fwdt_template_valid(dcode)) {
6377 ql_log(ql_log_warn, vha, 0x0165,
6378 "Failed fwdump template validate\n");
6379 goto default_template;
6380 }
6381
6382 dlen = qla27xx_fwdt_template_size(dcode);
6383 ql_dbg(ql_dbg_init, vha, 0x0166,
6384 "-> template size %x bytes\n", dlen);
6385 if (dlen > risc_size * sizeof(*dcode)) {
6386 ql_log(ql_log_warn, vha, 0x0167,
Chad Dupuis97ea7022014-03-13 14:16:40 -04006387 "Failed fwdump template exceeds array by %x bytes\n",
6388 (uint32_t)(dlen - risc_size * sizeof(*dcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05006389 goto default_template;
6390 }
6391 ha->fw_dump_template_len = dlen;
6392 return rval;
6393
6394default_template:
6395 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
6396 if (ha->fw_dump_template)
6397 vfree(ha->fw_dump_template);
6398 ha->fw_dump_template = NULL;
6399 ha->fw_dump_template_len = 0;
6400
6401 dlen = qla27xx_fwdt_template_default_size();
6402 ql_dbg(ql_dbg_init, vha, 0x0169,
6403 "-> template allocating %x bytes...\n", dlen);
6404 ha->fw_dump_template = vmalloc(dlen);
6405 if (!ha->fw_dump_template) {
6406 ql_log(ql_log_warn, vha, 0x016a,
6407 "Failed fwdump template allocate %x bytes.\n", risc_size);
6408 goto failed_template;
6409 }
6410
6411 dcode = ha->fw_dump_template;
6412 risc_size = dlen / sizeof(*dcode);
6413 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
6414 for (i = 0; i < risc_size; i++)
6415 dcode[i] = be32_to_cpu(dcode[i]);
6416
6417 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
6418 ql_log(ql_log_warn, vha, 0x016b,
6419 "Failed fwdump template validate\n");
6420 goto failed_template;
6421 }
6422
6423 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
6424 ql_dbg(ql_dbg_init, vha, 0x016c,
6425 "-> template size %x bytes\n", dlen);
6426 ha->fw_dump_template_len = dlen;
6427 return rval;
6428
6429failed_template:
6430 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
6431 if (ha->fw_dump_template)
6432 vfree(ha->fw_dump_template);
6433 ha->fw_dump_template = NULL;
6434 ha->fw_dump_template_len = 0;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006435 return rval;
6436}
6437
Giridhar Malavalie9454a82013-02-08 01:57:47 -05006438#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006439
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006440int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006441qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08006442{
6443 int rval;
6444 int i, fragment;
6445 uint16_t *wcode, *fwcode;
6446 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
6447 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006448 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006449 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08006450
6451 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006452 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08006453 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006454 ql_log(ql_log_info, vha, 0x0083,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01006455 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006456 ql_log(ql_log_info, vha, 0x0084,
6457 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08006458 return QLA_FUNCTION_FAILED;
6459 }
6460
6461 rval = QLA_SUCCESS;
6462
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006463 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08006464 *srisc_addr = 0;
6465 fwcode = (uint16_t *)blob->fw->data;
6466 fwclen = 0;
6467
6468 /* Validate firmware image by checking version. */
6469 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006470 ql_log(ql_log_fatal, vha, 0x0085,
6471 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08006472 blob->fw->size);
6473 goto fail_fw_integrity;
6474 }
6475 for (i = 0; i < 4; i++)
6476 wcode[i] = be16_to_cpu(fwcode[i + 4]);
6477 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
6478 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
6479 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006480 ql_log(ql_log_fatal, vha, 0x0086,
6481 "Unable to verify integrity of firmware image.\n");
6482 ql_log(ql_log_fatal, vha, 0x0087,
6483 "Firmware data: %04x %04x %04x %04x.\n",
6484 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08006485 goto fail_fw_integrity;
6486 }
6487
6488 seg = blob->segs;
6489 while (*seg && rval == QLA_SUCCESS) {
6490 risc_addr = *seg;
6491 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
6492 risc_size = be16_to_cpu(fwcode[3]);
6493
6494 /* Validate firmware image size. */
6495 fwclen += risc_size * sizeof(uint16_t);
6496 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006497 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08006498 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006499 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08006500 goto fail_fw_integrity;
6501 }
6502
6503 fragment = 0;
6504 while (risc_size > 0 && rval == QLA_SUCCESS) {
6505 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
6506 if (wlen > risc_size)
6507 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006508 ql_dbg(ql_dbg_init, vha, 0x0089,
6509 "Loading risc segment@ risc addr %x number of "
6510 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08006511
6512 for (i = 0; i < wlen; i++)
6513 wcode[i] = swab16(fwcode[i]);
6514
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006515 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08006516 wlen);
6517 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006518 ql_log(ql_log_fatal, vha, 0x008a,
6519 "Failed to load segment %d of firmware.\n",
6520 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08006521 break;
6522 }
6523
6524 fwcode += wlen;
6525 risc_addr += wlen;
6526 risc_size -= wlen;
6527 fragment++;
6528 }
6529
6530 /* Next segment. */
6531 seg++;
6532 }
6533 return rval;
6534
6535fail_fw_integrity:
6536 return QLA_FUNCTION_FAILED;
6537}
6538
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006539static int
6540qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006541{
6542 int rval;
6543 int segments, fragment;
6544 uint32_t *dcode, dlen;
6545 uint32_t risc_addr;
6546 uint32_t risc_size;
6547 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08006548 struct fw_blob *blob;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006549 const uint32_t *fwcode;
6550 uint32_t fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006551 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006552 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006553
Andrew Vasquez54333832005-11-09 15:49:04 -08006554 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006555 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08006556 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006557 ql_log(ql_log_warn, vha, 0x0090,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01006558 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006559 ql_log(ql_log_warn, vha, 0x0091,
6560 "Firmware images can be retrieved from: "
6561 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006562
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006563 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006564 }
6565
Chad Dupuiscfb09192011-11-18 09:03:07 -08006566 ql_dbg(ql_dbg_init, vha, 0x0092,
6567 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006568
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006569 rval = QLA_SUCCESS;
6570
6571 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006572 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006573 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08006574 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006575 fwclen = 0;
6576
6577 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08006578 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006579 ql_log(ql_log_fatal, vha, 0x0093,
6580 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08006581 blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05006582 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006583 }
6584 for (i = 0; i < 4; i++)
6585 dcode[i] = be32_to_cpu(fwcode[i + 4]);
6586 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
6587 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
6588 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
6589 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006590 ql_log(ql_log_fatal, vha, 0x0094,
6591 "Unable to verify integrity of firmware image (%Zd).\n",
6592 blob->fw->size);
6593 ql_log(ql_log_fatal, vha, 0x0095,
6594 "Firmware data: %08x %08x %08x %08x.\n",
6595 dcode[0], dcode[1], dcode[2], dcode[3]);
Chad Dupuisf73cb692014-02-26 04:15:06 -05006596 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006597 }
6598
6599 while (segments && rval == QLA_SUCCESS) {
6600 risc_addr = be32_to_cpu(fwcode[2]);
6601 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
6602 risc_size = be32_to_cpu(fwcode[3]);
6603
6604 /* Validate firmware image size. */
6605 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08006606 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006607 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08006608 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006609 "(%Zd).\n", blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05006610 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006611 }
6612
6613 fragment = 0;
6614 while (risc_size > 0 && rval == QLA_SUCCESS) {
6615 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
6616 if (dlen > risc_size)
6617 dlen = risc_size;
6618
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006619 ql_dbg(ql_dbg_init, vha, 0x0097,
6620 "Loading risc segment@ risc addr %x "
6621 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006622
6623 for (i = 0; i < dlen; i++)
6624 dcode[i] = swab32(fwcode[i]);
6625
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006626 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08006627 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006628 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006629 ql_log(ql_log_fatal, vha, 0x0098,
6630 "Failed to load segment %d of firmware.\n",
6631 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04006632 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006633 }
6634
6635 fwcode += dlen;
6636 risc_addr += dlen;
6637 risc_size -= dlen;
6638 fragment++;
6639 }
6640
6641 /* Next segment. */
6642 segments--;
6643 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05006644
6645 if (!IS_QLA27XX(ha))
6646 return rval;
6647
6648 if (ha->fw_dump_template)
6649 vfree(ha->fw_dump_template);
6650 ha->fw_dump_template = NULL;
6651 ha->fw_dump_template_len = 0;
6652
6653 ql_dbg(ql_dbg_init, vha, 0x171,
Chad Dupuis97ea7022014-03-13 14:16:40 -04006654 "Loading fwdump template from %x\n",
6655 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
Chad Dupuisf73cb692014-02-26 04:15:06 -05006656 risc_size = be32_to_cpu(fwcode[2]);
6657 ql_dbg(ql_dbg_init, vha, 0x172,
6658 "-> array size %x dwords\n", risc_size);
6659 if (risc_size == 0 || risc_size == ~0)
6660 goto default_template;
6661
6662 dlen = (risc_size - 8) * sizeof(*fwcode);
6663 ql_dbg(ql_dbg_init, vha, 0x0173,
6664 "-> template allocating %x bytes...\n", dlen);
6665 ha->fw_dump_template = vmalloc(dlen);
6666 if (!ha->fw_dump_template) {
6667 ql_log(ql_log_warn, vha, 0x0174,
6668 "Failed fwdump template allocate %x bytes.\n", risc_size);
6669 goto default_template;
6670 }
6671
6672 fwcode += 7;
6673 risc_size -= 8;
6674 dcode = ha->fw_dump_template;
6675 for (i = 0; i < risc_size; i++)
6676 dcode[i] = le32_to_cpu(fwcode[i]);
6677
6678 if (!qla27xx_fwdt_template_valid(dcode)) {
6679 ql_log(ql_log_warn, vha, 0x0175,
6680 "Failed fwdump template validate\n");
6681 goto default_template;
6682 }
6683
6684 dlen = qla27xx_fwdt_template_size(dcode);
6685 ql_dbg(ql_dbg_init, vha, 0x0176,
6686 "-> template size %x bytes\n", dlen);
6687 if (dlen > risc_size * sizeof(*fwcode)) {
6688 ql_log(ql_log_warn, vha, 0x0177,
Chad Dupuis97ea7022014-03-13 14:16:40 -04006689 "Failed fwdump template exceeds array by %x bytes\n",
6690 (uint32_t)(dlen - risc_size * sizeof(*fwcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05006691 goto default_template;
6692 }
6693 ha->fw_dump_template_len = dlen;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006694 return rval;
6695
Chad Dupuisf73cb692014-02-26 04:15:06 -05006696default_template:
6697 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
6698 if (ha->fw_dump_template)
6699 vfree(ha->fw_dump_template);
6700 ha->fw_dump_template = NULL;
6701 ha->fw_dump_template_len = 0;
6702
6703 dlen = qla27xx_fwdt_template_default_size();
6704 ql_dbg(ql_dbg_init, vha, 0x0179,
6705 "-> template allocating %x bytes...\n", dlen);
6706 ha->fw_dump_template = vmalloc(dlen);
6707 if (!ha->fw_dump_template) {
6708 ql_log(ql_log_warn, vha, 0x017a,
6709 "Failed fwdump template allocate %x bytes.\n", risc_size);
6710 goto failed_template;
6711 }
6712
6713 dcode = ha->fw_dump_template;
6714 risc_size = dlen / sizeof(*fwcode);
6715 fwcode = qla27xx_fwdt_template_default();
6716 for (i = 0; i < risc_size; i++)
6717 dcode[i] = be32_to_cpu(fwcode[i]);
6718
6719 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
6720 ql_log(ql_log_warn, vha, 0x017b,
6721 "Failed fwdump template validate\n");
6722 goto failed_template;
6723 }
6724
6725 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
6726 ql_dbg(ql_dbg_init, vha, 0x017c,
6727 "-> template size %x bytes\n", dlen);
6728 ha->fw_dump_template_len = dlen;
6729 return rval;
6730
6731failed_template:
6732 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
6733 if (ha->fw_dump_template)
6734 vfree(ha->fw_dump_template);
6735 ha->fw_dump_template = NULL;
6736 ha->fw_dump_template_len = 0;
6737 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006738}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006739
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006740int
6741qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
6742{
6743 int rval;
6744
Andrew Vasqueze337d902009-04-06 22:33:49 -07006745 if (ql2xfwloadbin == 1)
6746 return qla81xx_load_risc(vha, srisc_addr);
6747
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006748 /*
6749 * FW Load priority:
6750 * 1) Firmware via request-firmware interface (.bin file).
6751 * 2) Firmware residing in flash.
6752 */
6753 rval = qla24xx_load_risc_blob(vha, srisc_addr);
6754 if (rval == QLA_SUCCESS)
6755 return rval;
6756
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006757 return qla24xx_load_risc_flash(vha, srisc_addr,
6758 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006759}
6760
6761int
6762qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
6763{
6764 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006765 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006766
Andrew Vasqueze337d902009-04-06 22:33:49 -07006767 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006768 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07006769
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006770 /*
6771 * FW Load priority:
6772 * 1) Firmware residing in flash.
6773 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006774 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006775 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006776 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006777 if (rval == QLA_SUCCESS)
6778 return rval;
6779
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006780try_blob_fw:
6781 rval = qla24xx_load_risc_blob(vha, srisc_addr);
6782 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
6783 return rval;
6784
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006785 ql_log(ql_log_info, vha, 0x0099,
6786 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006787 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
6788 if (rval != QLA_SUCCESS)
6789 return rval;
6790
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006791 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006792 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006793 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006794}
6795
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006796void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006797qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006798{
6799 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006800 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006801
Andrew Vasquez85880802009-12-15 21:29:46 -08006802 if (ha->flags.pci_channel_io_perm_failure)
6803 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07006804 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006805 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07006806 if (!ha->fw_major_version)
6807 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006808
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006809 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08006810 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07006811 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006812 ha->isp_ops->reset_chip(vha);
6813 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006814 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006815 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006816 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006817 ql_log(ql_log_info, vha, 0x8015,
6818 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006819 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006820 }
6821}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006822
6823int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006824qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006825{
6826 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08006827 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006828 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006829 struct qla_hw_data *ha = vha->hw;
6830 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07006831 struct req_que *req;
6832 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006833
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006834 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006835 return -EINVAL;
6836
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006837 rval = qla2x00_fw_ready(base_vha);
Michael Hernandezd7459522016-12-12 14:40:07 -08006838 if (vha->qpair)
6839 req = vha->qpair->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07006840 else
Michael Hernandezd7459522016-12-12 14:40:07 -08006841 req = ha->req_q_map[0];
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07006842 rsp = req->rsp;
6843
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006844 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006845 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006846 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006847 }
6848
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006849 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006850
6851 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08006852 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
6853 BIT_1);
6854 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
6855 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
6856 ql_dbg(ql_dbg_init, vha, 0x0120,
6857 "Failed SNS login: loop_id=%x, rval2=%d\n",
6858 NPH_SNS, rval2);
6859 else
6860 ql_dbg(ql_dbg_init, vha, 0x0103,
6861 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
6862 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
6863 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006864 return (QLA_FUNCTION_FAILED);
6865 }
6866
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006867 atomic_set(&vha->loop_down_timer, 0);
6868 atomic_set(&vha->loop_state, LOOP_UP);
6869 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6870 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
6871 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006872
6873 return rval;
6874}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006875
6876/* 84XX Support **************************************************************/
6877
6878static LIST_HEAD(qla_cs84xx_list);
6879static DEFINE_MUTEX(qla_cs84xx_mutex);
6880
6881static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006882qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006883{
6884 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006885 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006886
6887 mutex_lock(&qla_cs84xx_mutex);
6888
6889 /* Find any shared 84xx chip. */
6890 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
6891 if (cs84xx->bus == ha->pdev->bus) {
6892 kref_get(&cs84xx->kref);
6893 goto done;
6894 }
6895 }
6896
6897 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
6898 if (!cs84xx)
6899 goto done;
6900
6901 kref_init(&cs84xx->kref);
6902 spin_lock_init(&cs84xx->access_lock);
6903 mutex_init(&cs84xx->fw_update_mutex);
6904 cs84xx->bus = ha->pdev->bus;
6905
6906 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
6907done:
6908 mutex_unlock(&qla_cs84xx_mutex);
6909 return cs84xx;
6910}
6911
6912static void
6913__qla84xx_chip_release(struct kref *kref)
6914{
6915 struct qla_chip_state_84xx *cs84xx =
6916 container_of(kref, struct qla_chip_state_84xx, kref);
6917
6918 mutex_lock(&qla_cs84xx_mutex);
6919 list_del(&cs84xx->list);
6920 mutex_unlock(&qla_cs84xx_mutex);
6921 kfree(cs84xx);
6922}
6923
6924void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006925qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006926{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006927 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006928 if (ha->cs84xx)
6929 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
6930}
6931
6932static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006933qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006934{
6935 int rval;
6936 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006937 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006938
6939 mutex_lock(&ha->cs84xx->fw_update_mutex);
6940
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006941 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006942
6943 mutex_unlock(&ha->cs84xx->fw_update_mutex);
6944
6945 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
6946 QLA_SUCCESS;
6947}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006948
6949/* 81XX Support **************************************************************/
6950
6951int
6952qla81xx_nvram_config(scsi_qla_host_t *vha)
6953{
6954 int rval;
6955 struct init_cb_81xx *icb;
6956 struct nvram_81xx *nv;
6957 uint32_t *dptr;
6958 uint8_t *dptr1, *dptr2;
6959 uint32_t chksum;
6960 uint16_t cnt;
6961 struct qla_hw_data *ha = vha->hw;
6962
6963 rval = QLA_SUCCESS;
6964 icb = (struct init_cb_81xx *)ha->init_cb;
6965 nv = ha->nvram;
6966
6967 /* Determine NVRAM starting address. */
6968 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006969 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006970 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
6971 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006972
6973 /* Get VPD data into cache */
6974 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006975 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
6976 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006977
6978 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006979 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006980 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006981 dptr = (uint32_t *)nv;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006982 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
6983 chksum += le32_to_cpu(*dptr);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006984
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006985 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
6986 "Contents of NVRAM:\n");
6987 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
6988 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006989
6990 /* Bad NVRAM data, set defaults parameters. */
6991 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6992 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07006993 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006994 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006995 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04006996 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006997 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006998 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006999 ql_log(ql_log_info, vha, 0x0074,
7000 "Falling back to functioning (yet invalid -- WWPN) "
7001 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007002
7003 /*
7004 * Set default initialization control block.
7005 */
7006 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07007007 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7008 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04007009 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07007010 nv->execution_throttle = cpu_to_le16(0xFFFF);
7011 nv->exchange_count = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007012 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007013 nv->port_name[1] = 0x00 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007014 nv->port_name[2] = 0x00;
7015 nv->port_name[3] = 0xe0;
7016 nv->port_name[4] = 0x8b;
7017 nv->port_name[5] = 0x1c;
7018 nv->port_name[6] = 0x55;
7019 nv->port_name[7] = 0x86;
7020 nv->node_name[0] = 0x20;
7021 nv->node_name[1] = 0x00;
7022 nv->node_name[2] = 0x00;
7023 nv->node_name[3] = 0xe0;
7024 nv->node_name[4] = 0x8b;
7025 nv->node_name[5] = 0x1c;
7026 nv->node_name[6] = 0x55;
7027 nv->node_name[7] = 0x86;
Bart Van Asschead950362015-07-09 07:24:08 -07007028 nv->login_retry_count = cpu_to_le16(8);
7029 nv->interrupt_delay_timer = cpu_to_le16(0);
7030 nv->login_timeout = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007031 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07007032 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7033 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7034 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7035 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7036 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7037 nv->efi_parameters = cpu_to_le32(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007038 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07007039 nv->max_luns_per_target = cpu_to_le16(128);
7040 nv->port_down_retry_count = cpu_to_le16(30);
7041 nv->link_down_timeout = cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07007042 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007043 nv->enode_mac[1] = 0xC0;
7044 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007045 nv->enode_mac[3] = 0x04;
7046 nv->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007047 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007048
7049 rval = 1;
7050 }
7051
Arun Easi9e522cd2012-08-22 14:21:31 -04007052 if (IS_T10_PI_CAPABLE(ha))
7053 nv->frame_payload_size &= ~7;
7054
Arun Easiaa230bc2013-01-30 03:34:39 -05007055 qlt_81xx_config_nvram_stage1(vha, nv);
7056
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007057 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07007058 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007059
7060 /* Copy 1st segment. */
7061 dptr1 = (uint8_t *)icb;
7062 dptr2 = (uint8_t *)&nv->version;
7063 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7064 while (cnt--)
7065 *dptr1++ = *dptr2++;
7066
7067 icb->login_retry_count = nv->login_retry_count;
7068
7069 /* Copy 2nd segment. */
7070 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7071 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7072 cnt = (uint8_t *)&icb->reserved_5 -
7073 (uint8_t *)&icb->interrupt_delay_timer;
7074 while (cnt--)
7075 *dptr1++ = *dptr2++;
7076
7077 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
7078 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
7079 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08007080 icb->enode_mac[0] = 0x00;
7081 icb->enode_mac[1] = 0xC0;
7082 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007083 icb->enode_mac[3] = 0x04;
7084 icb->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007085 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007086 }
7087
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07007088 /* Use extended-initialization control block. */
7089 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
7090
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007091 /*
7092 * Setup driver NVRAM options.
7093 */
7094 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07007095 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007096
Arun Easiaa230bc2013-01-30 03:34:39 -05007097 qlt_81xx_config_nvram_stage2(vha, icb);
7098
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007099 /* Use alternate WWN? */
Bart Van Asschead950362015-07-09 07:24:08 -07007100 if (nv->host_p & cpu_to_le32(BIT_15)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007101 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7102 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7103 }
7104
7105 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07007106 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007107 /*
7108 * Firmware will apply the following mask if the nodename was
7109 * not provided.
7110 */
7111 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7112 icb->node_name[0] &= 0xF0;
7113 }
7114
7115 /* Set host adapter parameters. */
7116 ha->flags.disable_risc_code_load = 0;
7117 ha->flags.enable_lip_reset = 0;
7118 ha->flags.enable_lip_full_login =
7119 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
7120 ha->flags.enable_target_reset =
7121 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
7122 ha->flags.enable_led_scheme = 0;
7123 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
7124
7125 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7126 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7127
7128 /* save HBA serial number */
7129 ha->serial0 = icb->port_name[5];
7130 ha->serial1 = icb->port_name[6];
7131 ha->serial2 = icb->port_name[7];
7132 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7133 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7134
Bart Van Asschead950362015-07-09 07:24:08 -07007135 icb->execution_throttle = cpu_to_le16(0xFFFF);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007136
7137 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7138
7139 /* Set minimum login_timeout to 4 seconds. */
7140 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7141 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7142 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07007143 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007144 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007145
7146 /* Set minimum RATOV to 100 tenths of a second. */
7147 ha->r_a_tov = 100;
7148
7149 ha->loop_reset_delay = nv->reset_delay;
7150
7151 /* Link Down Timeout = 0:
7152 *
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007153 * When Port Down timer expires we will start returning
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007154 * I/O's to OS with "DID_NO_CONNECT".
7155 *
7156 * Link Down Timeout != 0:
7157 *
7158 * The driver waits for the link to come up after link down
7159 * before returning I/Os to OS with "DID_NO_CONNECT".
7160 */
7161 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7162 ha->loop_down_abort_time =
7163 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7164 } else {
7165 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7166 ha->loop_down_abort_time =
7167 (LOOP_DOWN_TIME - ha->link_down_timeout);
7168 }
7169
7170 /* Need enough time to try and get the port back. */
7171 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7172 if (qlport_down_retry)
7173 ha->port_down_retry_count = qlport_down_retry;
7174
7175 /* Set login_retry_count */
7176 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7177 if (ha->port_down_retry_count ==
7178 le16_to_cpu(nv->port_down_retry_count) &&
7179 ha->port_down_retry_count > 3)
7180 ha->login_retry_count = ha->port_down_retry_count;
7181 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7182 ha->login_retry_count = ha->port_down_retry_count;
7183 if (ql2xloginretrycount)
7184 ha->login_retry_count = ql2xloginretrycount;
7185
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007186 /* if not running MSI-X we need handshaking on interrupts */
Chad Dupuisf73cb692014-02-26 04:15:06 -05007187 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
Bart Van Asschead950362015-07-09 07:24:08 -07007188 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007189
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007190 /* Enable ZIO. */
7191 if (!vha->flags.init_done) {
7192 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7193 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7194 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7195 le16_to_cpu(icb->interrupt_delay_timer): 2;
7196 }
Bart Van Asschead950362015-07-09 07:24:08 -07007197 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007198 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7199 vha->flags.process_response_queue = 0;
7200 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7201 ha->zio_mode = QLA_ZIO_MODE_6;
7202
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007203 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007204 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007205 ha->zio_mode,
7206 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007207
7208 icb->firmware_options_2 |= cpu_to_le32(
7209 (uint32_t)ha->zio_mode);
7210 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7211 vha->flags.process_response_queue = 1;
7212 }
7213
Quinn Tran41dc5292017-01-19 22:28:03 -08007214 /* enable RIDA Format2 */
7215 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))
7216 icb->firmware_options_3 |= BIT_0;
7217
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007218 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007219 ql_log(ql_log_warn, vha, 0x0076,
7220 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007221 }
7222 return (rval);
7223}
7224
Giridhar Malavalia9083012010-04-12 17:59:55 -07007225int
7226qla82xx_restart_isp(scsi_qla_host_t *vha)
7227{
7228 int status, rval;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007229 struct qla_hw_data *ha = vha->hw;
7230 struct req_que *req = ha->req_q_map[0];
7231 struct rsp_que *rsp = ha->rsp_q_map[0];
7232 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07007233 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007234
7235 status = qla2x00_init_rings(vha);
7236 if (!status) {
7237 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7238 ha->flags.chip_reset_done = 1;
7239
7240 status = qla2x00_fw_ready(vha);
7241 if (!status) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07007242 /* Issue a marker after FW becomes ready. */
7243 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007244 vha->flags.online = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04007245 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007246 }
7247
7248 /* if no cable then assume it's good */
7249 if ((vha->device_flags & DFLG_NO_CABLE))
7250 status = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007251 }
7252
7253 if (!status) {
7254 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7255
7256 if (!atomic_read(&vha->loop_down_timer)) {
7257 /*
7258 * Issue marker command only when we are going
7259 * to start the I/O .
7260 */
7261 vha->marker_needed = 1;
7262 }
7263
Giridhar Malavalia9083012010-04-12 17:59:55 -07007264 ha->isp_ops->enable_intrs(ha);
7265
7266 ha->isp_abort_cnt = 0;
7267 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7268
Saurav Kashyap53296782011-05-10 11:30:06 -07007269 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07007270 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07007271
Giridhar Malavalia9083012010-04-12 17:59:55 -07007272 if (ha->fce) {
7273 ha->flags.fce_enabled = 1;
7274 memset(ha->fce, 0,
7275 fce_calc_size(ha->fce_bufs));
7276 rval = qla2x00_enable_fce_trace(vha,
7277 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
7278 &ha->fce_bufs);
7279 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007280 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007281 "Unable to reinitialize FCE (%d).\n",
7282 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007283 ha->flags.fce_enabled = 0;
7284 }
7285 }
7286
7287 if (ha->eft) {
7288 memset(ha->eft, 0, EFT_SIZE);
7289 rval = qla2x00_enable_eft_trace(vha,
7290 ha->eft_dma, EFT_NUM_BUFFERS);
7291 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007292 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007293 "Unable to reinitialize EFT (%d).\n",
7294 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007295 }
7296 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07007297 }
7298
7299 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007300 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007301 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07007302
7303 spin_lock_irqsave(&ha->vport_slock, flags);
7304 list_for_each_entry(vp, &ha->vp_list, list) {
7305 if (vp->vp_idx) {
7306 atomic_inc(&vp->vref_count);
7307 spin_unlock_irqrestore(&ha->vport_slock, flags);
7308
Giridhar Malavalia9083012010-04-12 17:59:55 -07007309 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07007310
7311 spin_lock_irqsave(&ha->vport_slock, flags);
7312 atomic_dec(&vp->vref_count);
7313 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07007314 }
Arun Easifeafb7b2010-09-03 14:57:00 -07007315 spin_unlock_irqrestore(&ha->vport_slock, flags);
7316
Giridhar Malavalia9083012010-04-12 17:59:55 -07007317 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007318 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007319 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07007320 }
7321
7322 return status;
7323}
7324
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007325void
Andrew Vasquezae97c912010-02-18 10:07:28 -08007326qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007327{
Andrew Vasquezae97c912010-02-18 10:07:28 -08007328 struct qla_hw_data *ha = vha->hw;
7329
Himanshu Madhanif198caf2016-01-27 12:03:30 -05007330 /* Hold status IOCBs until ABTS response received. */
7331 if (ql2xfwholdabts)
7332 ha->fw_options[3] |= BIT_12;
7333
Giridhar Malavali088d09d2016-07-06 11:14:20 -04007334 /* Set Retry FLOGI in case of P2P connection */
7335 if (ha->operating_mode == P2P) {
7336 ha->fw_options[2] |= BIT_3;
7337 ql_dbg(ql_dbg_disc, vha, 0x2103,
7338 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
7339 __func__, ha->fw_options[2]);
7340 }
7341
Quinn Tran41dc5292017-01-19 22:28:03 -08007342 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
7343 if (ql2xmvasynctoatio) {
7344 if (qla_tgt_mode_enabled(vha) ||
7345 qla_dual_mode_enabled(vha))
7346 ha->fw_options[2] |= BIT_11;
7347 else
7348 ha->fw_options[2] &= ~BIT_11;
7349 }
Andrew Vasquezae97c912010-02-18 10:07:28 -08007350
Quinn Tran41dc5292017-01-19 22:28:03 -08007351 if (ql2xetsenable) {
7352 /* Enable ETS Burst. */
7353 memset(ha->fw_options, 0, sizeof(ha->fw_options));
7354 ha->fw_options[2] |= BIT_9;
7355 }
7356
7357 ql_dbg(ql_dbg_init, vha, 0xffff,
7358 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
7359 __func__, ha->fw_options[1], ha->fw_options[2],
7360 ha->fw_options[3], vha->host->active_mode);
7361
Andrew Vasquezae97c912010-02-18 10:07:28 -08007362 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007363}
Sarang Radke09ff7012010-03-19 17:03:59 -07007364
7365/*
7366 * qla24xx_get_fcp_prio
7367 * Gets the fcp cmd priority value for the logged in port.
7368 * Looks for a match of the port descriptors within
7369 * each of the fcp prio config entries. If a match is found,
7370 * the tag (priority) value is returned.
7371 *
7372 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007373 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07007374 * fcport = port structure pointer.
7375 *
7376 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07007377 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007378 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07007379 *
7380 * Context:
7381 * Kernel context
7382 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007383static int
Sarang Radke09ff7012010-03-19 17:03:59 -07007384qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
7385{
7386 int i, entries;
7387 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007388 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07007389 uint32_t pid1, pid2;
7390 uint64_t wwn1, wwn2;
7391 struct qla_fcp_prio_entry *pri_entry;
7392 struct qla_hw_data *ha = vha->hw;
7393
7394 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007395 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07007396
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007397 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07007398 entries = ha->fcp_prio_cfg->num_entries;
7399 pri_entry = &ha->fcp_prio_cfg->entry[0];
7400
7401 for (i = 0; i < entries; i++) {
7402 pid_match = wwn_match = 0;
7403
7404 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
7405 pri_entry++;
7406 continue;
7407 }
7408
7409 /* check source pid for a match */
7410 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
7411 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
7412 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
7413 if (pid1 == INVALID_PORT_ID)
7414 pid_match++;
7415 else if (pid1 == pid2)
7416 pid_match++;
7417 }
7418
7419 /* check destination pid for a match */
7420 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
7421 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
7422 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
7423 if (pid1 == INVALID_PORT_ID)
7424 pid_match++;
7425 else if (pid1 == pid2)
7426 pid_match++;
7427 }
7428
7429 /* check source WWN for a match */
7430 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
7431 wwn1 = wwn_to_u64(vha->port_name);
7432 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
7433 if (wwn2 == (uint64_t)-1)
7434 wwn_match++;
7435 else if (wwn1 == wwn2)
7436 wwn_match++;
7437 }
7438
7439 /* check destination WWN for a match */
7440 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
7441 wwn1 = wwn_to_u64(fcport->port_name);
7442 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
7443 if (wwn2 == (uint64_t)-1)
7444 wwn_match++;
7445 else if (wwn1 == wwn2)
7446 wwn_match++;
7447 }
7448
7449 if (pid_match == 2 || wwn_match == 2) {
7450 /* Found a matching entry */
7451 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
7452 priority = pri_entry->tag;
7453 break;
7454 }
7455
7456 pri_entry++;
7457 }
7458
7459 return priority;
7460}
7461
7462/*
7463 * qla24xx_update_fcport_fcp_prio
7464 * Activates fcp priority for the logged in fc port
7465 *
7466 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007467 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07007468 * fcp = port structure pointer.
7469 *
7470 * Return:
7471 * QLA_SUCCESS or QLA_FUNCTION_FAILED
7472 *
7473 * Context:
7474 * Kernel context.
7475 */
7476int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007477qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07007478{
7479 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007480 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07007481 uint16_t mb[5];
7482
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007483 if (fcport->port_type != FCT_TARGET ||
7484 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07007485 return QLA_FUNCTION_FAILED;
7486
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007487 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007488 if (priority < 0)
7489 return QLA_FUNCTION_FAILED;
7490
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007491 if (IS_P3P_TYPE(vha->hw)) {
Saurav Kashyapa00f6292011-11-18 09:03:19 -08007492 fcport->fcp_prio = priority & 0xf;
7493 return QLA_SUCCESS;
7494 }
7495
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007496 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08007497 if (ret == QLA_SUCCESS) {
7498 if (fcport->fcp_prio != priority)
7499 ql_dbg(ql_dbg_user, vha, 0x709e,
7500 "Updated FCP_CMND priority - value=%d loop_id=%d "
7501 "port_id=%02x%02x%02x.\n", priority,
7502 fcport->loop_id, fcport->d_id.b.domain,
7503 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08007504 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08007505 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007506 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08007507 "Unable to update FCP_CMND priority - ret=0x%x for "
7508 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
7509 fcport->d_id.b.domain, fcport->d_id.b.area,
7510 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07007511 return ret;
7512}
7513
7514/*
7515 * qla24xx_update_all_fcp_prio
7516 * Activates fcp priority for all the logged in ports
7517 *
7518 * Input:
7519 * ha = adapter block pointer.
7520 *
7521 * Return:
7522 * QLA_SUCCESS or QLA_FUNCTION_FAILED
7523 *
7524 * Context:
7525 * Kernel context.
7526 */
7527int
7528qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
7529{
7530 int ret;
7531 fc_port_t *fcport;
7532
7533 ret = QLA_FUNCTION_FAILED;
7534 /* We need to set priority for all logged in ports */
7535 list_for_each_entry(fcport, &vha->vp_fcports, list)
7536 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
7537
7538 return ret;
7539}
Michael Hernandezd7459522016-12-12 14:40:07 -08007540
7541struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos, int vp_idx)
7542{
7543 int rsp_id = 0;
7544 int req_id = 0;
7545 int i;
7546 struct qla_hw_data *ha = vha->hw;
7547 uint16_t qpair_id = 0;
7548 struct qla_qpair *qpair = NULL;
7549 struct qla_msix_entry *msix;
7550
7551 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
7552 ql_log(ql_log_warn, vha, 0x00181,
7553 "FW/Driver is not multi-queue capable.\n");
7554 return NULL;
7555 }
7556
7557 if (ql2xmqsupport) {
7558 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
7559 if (qpair == NULL) {
7560 ql_log(ql_log_warn, vha, 0x0182,
7561 "Failed to allocate memory for queue pair.\n");
7562 return NULL;
7563 }
7564 memset(qpair, 0, sizeof(struct qla_qpair));
7565
7566 qpair->hw = vha->hw;
7567
7568 /* Assign available que pair id */
7569 mutex_lock(&ha->mq_lock);
7570 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
7571 if (qpair_id >= ha->max_qpairs) {
7572 mutex_unlock(&ha->mq_lock);
7573 ql_log(ql_log_warn, vha, 0x0183,
7574 "No resources to create additional q pair.\n");
7575 goto fail_qid_map;
7576 }
7577 set_bit(qpair_id, ha->qpair_qid_map);
7578 ha->queue_pair_map[qpair_id] = qpair;
7579 qpair->id = qpair_id;
7580 qpair->vp_idx = vp_idx;
7581
7582 for (i = 0; i < ha->msix_count; i++) {
Quinn Tran093df732016-12-12 14:40:09 -08007583 msix = &ha->msix_entries[i];
Michael Hernandezd7459522016-12-12 14:40:07 -08007584 if (msix->in_use)
7585 continue;
7586 qpair->msix = msix;
7587 ql_log(ql_dbg_multiq, vha, 0xc00f,
7588 "Vector %x selected for qpair\n", msix->vector);
7589 break;
7590 }
7591 if (!qpair->msix) {
7592 ql_log(ql_log_warn, vha, 0x0184,
7593 "Out of MSI-X vectors!.\n");
7594 goto fail_msix;
7595 }
7596
7597 qpair->msix->in_use = 1;
7598 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
7599
7600 mutex_unlock(&ha->mq_lock);
7601
7602 /* Create response queue first */
7603 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair);
7604 if (!rsp_id) {
7605 ql_log(ql_log_warn, vha, 0x0185,
7606 "Failed to create response queue.\n");
7607 goto fail_rsp;
7608 }
7609
7610 qpair->rsp = ha->rsp_q_map[rsp_id];
7611
7612 /* Create request queue */
7613 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos);
7614 if (!req_id) {
7615 ql_log(ql_log_warn, vha, 0x0186,
7616 "Failed to create request queue.\n");
7617 goto fail_req;
7618 }
7619
7620 qpair->req = ha->req_q_map[req_id];
7621 qpair->rsp->req = qpair->req;
7622
7623 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
7624 if (ha->fw_attributes & BIT_4)
7625 qpair->difdix_supported = 1;
7626 }
7627
7628 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
7629 if (!qpair->srb_mempool) {
7630 ql_log(ql_log_warn, vha, 0x0191,
7631 "Failed to create srb mempool for qpair %d\n",
7632 qpair->id);
7633 goto fail_mempool;
7634 }
7635
7636 /* Mark as online */
7637 qpair->online = 1;
7638
7639 if (!vha->flags.qpairs_available)
7640 vha->flags.qpairs_available = 1;
7641
7642 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
7643 "Request/Response queue pair created, id %d\n",
7644 qpair->id);
7645 ql_dbg(ql_dbg_init, vha, 0x0187,
7646 "Request/Response queue pair created, id %d\n",
7647 qpair->id);
7648 }
7649 return qpair;
7650
7651fail_mempool:
7652fail_req:
7653 qla25xx_delete_rsp_que(vha, qpair->rsp);
7654fail_rsp:
7655 mutex_lock(&ha->mq_lock);
7656 qpair->msix->in_use = 0;
7657 list_del(&qpair->qp_list_elem);
7658 if (list_empty(&vha->qp_list))
7659 vha->flags.qpairs_available = 0;
7660fail_msix:
7661 ha->queue_pair_map[qpair_id] = NULL;
7662 clear_bit(qpair_id, ha->qpair_qid_map);
7663 mutex_unlock(&ha->mq_lock);
7664fail_qid_map:
7665 kfree(qpair);
7666 return NULL;
7667}
7668
7669int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
7670{
7671 int ret;
7672 struct qla_hw_data *ha = qpair->hw;
7673
7674 qpair->delete_in_progress = 1;
7675 while (atomic_read(&qpair->ref_count))
7676 msleep(500);
7677
7678 ret = qla25xx_delete_req_que(vha, qpair->req);
7679 if (ret != QLA_SUCCESS)
7680 goto fail;
7681 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
7682 if (ret != QLA_SUCCESS)
7683 goto fail;
7684
7685 mutex_lock(&ha->mq_lock);
7686 ha->queue_pair_map[qpair->id] = NULL;
7687 clear_bit(qpair->id, ha->qpair_qid_map);
7688 list_del(&qpair->qp_list_elem);
7689 if (list_empty(&vha->qp_list))
7690 vha->flags.qpairs_available = 0;
7691 mempool_destroy(qpair->srb_mempool);
7692 kfree(qpair);
7693 mutex_unlock(&ha->mq_lock);
7694
7695 return QLA_SUCCESS;
7696fail:
7697 return ret;
7698}