blob: 8b7c0468a0e0c6ac62bfefc88f685c97cb358396 [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
1074void qla2x00_fcport_event_handler(scsi_qla_host_t *vha,
1075 struct event_arg *ea)
1076{
1077 fc_port_t *fcport;
1078 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;
1090
1091 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1092 if (!fcport) {
1093 /* cable moved */
1094 rc = qla24xx_post_gpnid_work(vha, &ea->id);
1095 if (rc) {
1096 ql_log(ql_log_warn, vha, 0xffff,
1097 "RSCN GPNID work failed %02x%02x%02x\n",
1098 ea->id.b.domain, ea->id.b.area,
1099 ea->id.b.al_pa);
1100 }
1101 } else {
1102 ea->fcport = fcport;
1103 qla24xx_handle_rscn_event(fcport, ea);
1104 }
1105 break;
1106 case FCME_GIDPN_DONE:
1107 qla24xx_handle_gidpn_event(vha, ea);
1108 break;
1109 case FCME_GNL_DONE:
1110 qla24xx_handle_gnl_done_event(vha, ea);
1111 break;
1112 case FCME_GPSC_DONE:
1113 qla24xx_post_upd_fcport_work(vha, ea->fcport);
1114 break;
1115 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1116 qla24xx_handle_plogi_done_event(vha, ea);
1117 break;
1118 case FCME_GPDB_DONE:
1119 qla24xx_handle_gpdb_event(vha, ea);
1120 break;
1121 case FCME_GPNID_DONE:
1122 qla24xx_handle_gpnid_event(vha, ea);
1123 break;
1124 case FCME_DELETE_DONE:
1125 qla24xx_handle_delete_done_event(vha, ea);
1126 break;
1127 default:
1128 BUG_ON(1);
1129 break;
1130 }
1131}
1132
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001133static void
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001134qla2x00_tmf_iocb_timeout(void *data)
1135{
1136 srb_t *sp = (srb_t *)data;
1137 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1138
1139 tmf->u.tmf.comp_status = CS_TIMEOUT;
1140 complete(&tmf->u.tmf.comp);
1141}
1142
1143static void
1144qla2x00_tmf_sp_done(void *data, void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001145{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001146 srb_t *sp = (srb_t *)ptr;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001147 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1148 complete(&tmf->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001149}
1150
1151int
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001152qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001153 uint32_t tag)
1154{
1155 struct scsi_qla_host *vha = fcport->vha;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001156 struct srb_iocb *tm_iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001157 srb_t *sp;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001158 int rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001159
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001160 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001161 if (!sp)
1162 goto done;
1163
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001164 tm_iocb = &sp->u.iocb_cmd;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001165 sp->type = SRB_TM_CMD;
1166 sp->name = "tmf";
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001167 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1168 tm_iocb->u.tmf.flags = flags;
1169 tm_iocb->u.tmf.lun = lun;
1170 tm_iocb->u.tmf.data = tag;
1171 sp->done = qla2x00_tmf_sp_done;
1172 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1173 init_completion(&tm_iocb->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001174
1175 rval = qla2x00_start_sp(sp);
1176 if (rval != QLA_SUCCESS)
1177 goto done_free_sp;
1178
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001179 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001180 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1181 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1182 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001183
1184 wait_for_completion(&tm_iocb->u.tmf.comp);
1185
1186 rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
1187 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1188
1189 if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
1190 ql_dbg(ql_dbg_taskm, vha, 0x8030,
1191 "TM IOCB failed (%x).\n", rval);
1192 }
1193
1194 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1195 flags = tm_iocb->u.tmf.flags;
1196 lun = (uint16_t)tm_iocb->u.tmf.lun;
1197
1198 /* Issue Marker IOCB */
1199 qla2x00_marker(vha, vha->hw->req_q_map[0],
1200 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
1201 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1202 }
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001203
1204done_free_sp:
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001205 sp->free(vha, sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001206done:
1207 return rval;
1208}
1209
Armen Baloyan4440e462014-02-26 04:15:18 -05001210static void
1211qla24xx_abort_iocb_timeout(void *data)
1212{
1213 srb_t *sp = (srb_t *)data;
1214 struct srb_iocb *abt = &sp->u.iocb_cmd;
1215
1216 abt->u.abt.comp_status = CS_TIMEOUT;
1217 complete(&abt->u.abt.comp);
1218}
1219
1220static void
1221qla24xx_abort_sp_done(void *data, void *ptr, int res)
1222{
1223 srb_t *sp = (srb_t *)ptr;
1224 struct srb_iocb *abt = &sp->u.iocb_cmd;
1225
1226 complete(&abt->u.abt.comp);
1227}
1228
1229static int
1230qla24xx_async_abort_cmd(srb_t *cmd_sp)
1231{
1232 scsi_qla_host_t *vha = cmd_sp->fcport->vha;
1233 fc_port_t *fcport = cmd_sp->fcport;
1234 struct srb_iocb *abt_iocb;
1235 srb_t *sp;
1236 int rval = QLA_FUNCTION_FAILED;
1237
1238 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1239 if (!sp)
1240 goto done;
1241
1242 abt_iocb = &sp->u.iocb_cmd;
1243 sp->type = SRB_ABT_CMD;
1244 sp->name = "abort";
1245 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1246 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
1247 sp->done = qla24xx_abort_sp_done;
1248 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
1249 init_completion(&abt_iocb->u.abt.comp);
1250
1251 rval = qla2x00_start_sp(sp);
1252 if (rval != QLA_SUCCESS)
1253 goto done_free_sp;
1254
1255 ql_dbg(ql_dbg_async, vha, 0x507c,
1256 "Abort command issued - hdl=%x, target_id=%x\n",
1257 cmd_sp->handle, fcport->tgt_id);
1258
1259 wait_for_completion(&abt_iocb->u.abt.comp);
1260
1261 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
1262 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1263
1264done_free_sp:
1265 sp->free(vha, sp);
1266done:
1267 return rval;
1268}
1269
1270int
1271qla24xx_async_abort_command(srb_t *sp)
1272{
1273 unsigned long flags = 0;
1274
1275 uint32_t handle;
1276 fc_port_t *fcport = sp->fcport;
1277 struct scsi_qla_host *vha = fcport->vha;
1278 struct qla_hw_data *ha = vha->hw;
1279 struct req_que *req = vha->req;
1280
1281 spin_lock_irqsave(&ha->hardware_lock, flags);
1282 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1283 if (req->outstanding_cmds[handle] == sp)
1284 break;
1285 }
1286 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1287 if (handle == req->num_outstanding_cmds) {
1288 /* Command not found. */
1289 return QLA_FUNCTION_FAILED;
1290 }
1291 if (sp->type == SRB_FXIOCB_DCMD)
1292 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1293 FXDISC_ABORT_IOCTL);
1294
1295 return qla24xx_async_abort_cmd(sp);
1296}
1297
Quinn Tran726b8542017-01-19 22:28:00 -08001298static void
1299qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001300{
Quinn Tran726b8542017-01-19 22:28:00 -08001301 port_id_t cid; /* conflict Nport id */
Andrew Vasquezac280b62009-08-20 11:06:05 -07001302
Quinn Tran726b8542017-01-19 22:28:00 -08001303 switch (ea->data[0]) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07001304 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -07001305 /*
1306 * Driver must validate login state - If PRLI not complete,
1307 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1308 * requests.
1309 */
Quinn Tran726b8542017-01-19 22:28:00 -08001310 ql_dbg(ql_dbg_disc, vha, 0xffff,
1311 "%s %d %8phC post gpdb\n",
1312 __func__, __LINE__, ea->fcport->port_name);
1313 ea->fcport->chip_reset = vha->hw->chip_reset;
1314 ea->fcport->logout_on_delete = 1;
1315 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001316 break;
1317 case MBS_COMMAND_ERROR:
Quinn Tran726b8542017-01-19 22:28:00 -08001318 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC cmd error %x\n",
1319 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
1320
1321 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1322 ea->fcport->disc_state = DSC_LOGIN_FAILED;
1323 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001324 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1325 else
Quinn Tran726b8542017-01-19 22:28:00 -08001326 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001327 break;
1328 case MBS_LOOP_ID_USED:
Quinn Tran726b8542017-01-19 22:28:00 -08001329 /* data[1] = IO PARAM 1 = nport ID */
1330 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
1331 cid.b.area = (ea->iop[1] >> 8) & 0xff;
1332 cid.b.al_pa = ea->iop[1] & 0xff;
1333 cid.b.rsvd_1 = 0;
1334
1335 ql_dbg(ql_dbg_disc, vha, 0xffff,
1336 "%s %d %8phC LoopID 0x%x in use post gnl\n",
1337 __func__, __LINE__, ea->fcport->port_name,
1338 ea->fcport->loop_id);
1339
1340 if (IS_SW_RESV_ADDR(cid)) {
1341 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1342 ea->fcport->loop_id = FC_NO_LOOP_ID;
1343 } else {
1344 qla2x00_clear_loop_id(ea->fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001345 }
Quinn Tran726b8542017-01-19 22:28:00 -08001346 qla24xx_post_gnl_work(vha, ea->fcport);
1347 break;
1348 case MBS_PORT_ID_USED:
1349 ql_dbg(ql_dbg_disc, vha, 0xffff,
1350 "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n",
1351 __func__, __LINE__, ea->fcport->port_name,
1352 ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area,
1353 ea->fcport->d_id.b.al_pa);
1354
1355 qla2x00_clear_loop_id(ea->fcport);
1356 qla24xx_post_gidpn_work(vha, ea->fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001357 break;
1358 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001359 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001360}
1361
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001362void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001363qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1364 uint16_t *data)
1365{
Quinn Tran726b8542017-01-19 22:28:00 -08001366 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Alexei Potashnika6ca8872015-07-14 16:00:44 -04001367 qlt_logo_completion_handler(fcport, data[0]);
Quinn Tran726b8542017-01-19 22:28:00 -08001368 fcport->login_gen++;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001369 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001370}
1371
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001372void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001373qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1374 uint16_t *data)
1375{
1376 if (data[0] == MBS_COMMAND_COMPLETE) {
1377 qla2x00_update_fcport(vha, fcport);
1378
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001379 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001380 }
1381
1382 /* Retry login. */
1383 fcport->flags &= ~FCF_ASYNC_SENT;
1384 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
1385 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1386 else
Andrew Vasquez80d79442011-03-30 11:46:17 -07001387 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001388
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001389 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001390}
1391
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392/****************************************************************************/
1393/* QLogic ISP2x00 Hardware Support Functions. */
1394/****************************************************************************/
1395
Saurav Kashyapfa492632012-11-21 02:40:29 -05001396static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001397qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
1398{
1399 int rval = QLA_SUCCESS;
1400 struct qla_hw_data *ha = vha->hw;
1401 uint32_t idc_major_ver, idc_minor_ver;
Saurav Kashyap711aa7f2012-08-22 14:21:15 -04001402 uint16_t config[4];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001403
1404 qla83xx_idc_lock(vha, 0);
1405
1406 /* SV: TODO: Assign initialization timeout from
1407 * flash-info / other param
1408 */
1409 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
1410 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
1411
1412 /* Set our fcoe function presence */
1413 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
1414 ql_dbg(ql_dbg_p3p, vha, 0xb077,
1415 "Error while setting DRV-Presence.\n");
1416 rval = QLA_FUNCTION_FAILED;
1417 goto exit;
1418 }
1419
1420 /* Decide the reset ownership */
1421 qla83xx_reset_ownership(vha);
1422
1423 /*
1424 * On first protocol driver load:
1425 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
1426 * register.
1427 * Others: Check compatibility with current IDC Major version.
1428 */
1429 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
1430 if (ha->flags.nic_core_reset_owner) {
1431 /* Set IDC Major version */
1432 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
1433 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
1434
1435 /* Clearing IDC-Lock-Recovery register */
1436 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
1437 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
1438 /*
1439 * Clear further IDC participation if we are not compatible with
1440 * the current IDC Major Version.
1441 */
1442 ql_log(ql_log_warn, vha, 0xb07d,
1443 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
1444 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
1445 __qla83xx_clear_drv_presence(vha);
1446 rval = QLA_FUNCTION_FAILED;
1447 goto exit;
1448 }
1449 /* Each function sets its supported Minor version. */
1450 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
1451 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
1452 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
1453
Saurav Kashyap711aa7f2012-08-22 14:21:15 -04001454 if (ha->flags.nic_core_reset_owner) {
1455 memset(config, 0, sizeof(config));
1456 if (!qla81xx_get_port_config(vha, config))
1457 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
1458 QLA8XXX_DEV_READY);
1459 }
1460
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001461 rval = qla83xx_idc_state_handler(vha);
1462
1463exit:
1464 qla83xx_idc_unlock(vha, 0);
1465
1466 return rval;
1467}
1468
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469/*
1470* qla2x00_initialize_adapter
1471* Initialize board.
1472*
1473* Input:
1474* ha = adapter block pointer.
1475*
1476* Returns:
1477* 0 = success
1478*/
1479int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001480qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481{
1482 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001483 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001484 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001485
Joe Carnucciofc90ada2016-07-06 11:14:23 -04001486 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
1487 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
1488
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001490 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001491 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001492 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -08001493 ha->flags.pci_channel_io_perm_failure = 0;
1494 ha->flags.eeh_busy = 0;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -04001495 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001496 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1497 atomic_set(&vha->loop_state, LOOP_DOWN);
1498 vha->device_flags = DFLG_NO_CABLE;
1499 vha->dpc_flags = 0;
1500 vha->flags.management_server_logged_in = 0;
1501 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 ha->isp_abort_cnt = 0;
1503 ha->beacon_blink_led = 0;
1504
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001505 set_bit(0, ha->req_qid_map);
1506 set_bit(0, ha->rsp_qid_map);
1507
Chad Dupuiscfb09192011-11-18 09:03:07 -08001508 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001509 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001510 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001512 ql_log(ql_log_warn, vha, 0x0044,
1513 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 return (rval);
1515 }
1516
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001517 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001519 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001520 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001521 ql_log(ql_log_fatal, vha, 0x004f,
1522 "Unable to validate FLASH data.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001523 return rval;
1524 }
1525
1526 if (IS_QLA8044(ha)) {
1527 qla8044_read_reset_template(vha);
1528
1529 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
1530 * If DONRESET_BIT0 is set, drivers should not set dev_state
1531 * to NEED_RESET. But if NEED_RESET is set, drivers should
1532 * should honor the reset. */
1533 if (ql2xdontresethba == 1)
1534 qla8044_set_idc_dontreset(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001535 }
1536
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001537 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001538 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001539 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001540
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001541 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001543 if (ha->flags.disable_serdes) {
1544 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001545 ql_log(ql_log_info, vha, 0x0077,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04001546 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001547 return QLA_FUNCTION_FAILED;
1548 }
1549
Chad Dupuiscfb09192011-11-18 09:03:07 -08001550 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001551 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001553 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
1554 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001555 if (rval)
1556 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001557 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001558 if (rval)
1559 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07001561
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001562 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001563 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001564 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001565 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001566 "Unable to configure ISP84XX.\n");
1567 return QLA_FUNCTION_FAILED;
1568 }
1569 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001570
Quinn Tran726b8542017-01-19 22:28:00 -08001571 if (qla_ini_mode_enabled(vha) ||
1572 qla_dual_mode_enabled(vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001573 rval = qla2x00_init_rings(vha);
1574
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001575 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001577 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001578 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001579 rval = qla84xx_init_chip(vha);
1580 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001581 ql_log(ql_log_warn, vha, 0x00d4,
1582 "Unable to initialize ISP84XX.\n");
Bart Van Assche8d2b21d2015-06-04 15:58:09 -07001583 qla84xx_put_chip(vha);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001584 }
1585 }
1586
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001587 /* Load the NIC Core f/w if we are the first protocol driver. */
1588 if (IS_QLA8031(ha)) {
1589 rval = qla83xx_nic_core_fw_load(vha);
1590 if (rval)
1591 ql_log(ql_log_warn, vha, 0x0124,
1592 "Error in initializing NIC Core f/w.\n");
1593 }
1594
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +05001595 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
1596 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -07001597
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04001598 if (IS_P3P_TYPE(ha))
1599 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
1600 else
1601 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
1602
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 return (rval);
1604}
1605
1606/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001607 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 * @ha: HA context
1609 *
1610 * Returns 0 on success.
1611 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001612int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001613qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001615 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001616 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001617 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001618 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001621 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001624 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1626
Andrew Vasquez737faec2008-10-24 15:13:45 -07001627 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001629 /* Get PCI bus information. */
1630 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07001631 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001632 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1633
1634 return QLA_SUCCESS;
1635}
1636
1637/**
1638 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
1639 * @ha: HA context
1640 *
1641 * Returns 0 on success.
1642 */
1643int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001644qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001645{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001646 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001647 unsigned long flags = 0;
1648 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001649 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001650 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001651
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001652 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001653 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001654
1655 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001656 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001657
1658 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1659 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -07001660 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001661
1662 /*
1663 * If this is a 2300 card and not 2312, reset the
1664 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
1665 * the 2310 also reports itself as a 2300 so we need to get the
1666 * fb revision level -- a 6 indicates it really is a 2300 and
1667 * not a 2310.
1668 */
1669 if (IS_QLA2300(ha)) {
1670 spin_lock_irqsave(&ha->hardware_lock, flags);
1671
1672 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001673 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001674 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07001675 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001676 break;
1677
1678 udelay(10);
1679 }
1680
1681 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001682 WRT_REG_WORD(&reg->ctrl_status, 0x20);
1683 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001684
1685 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001686 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001687
1688 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -07001689 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001690
1691 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001692 WRT_REG_WORD(&reg->ctrl_status, 0x0);
1693 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001694
1695 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001696 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001697 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07001698 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001699 break;
1700
1701 udelay(10);
1702 }
1703
1704 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1705 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001706
1707 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
1708
Andrew Vasquez737faec2008-10-24 15:13:45 -07001709 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001710
1711 /* Get PCI bus information. */
1712 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07001713 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001714 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1715
1716 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717}
1718
1719/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001720 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
1721 * @ha: HA context
1722 *
1723 * Returns 0 on success.
1724 */
1725int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001726qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001727{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001728 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001729 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001730 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001731 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001732
1733 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001734 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001735
1736 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001737 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001738 w &= ~PCI_COMMAND_INTX_DISABLE;
1739 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1740
1741 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
1742
1743 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -07001744 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
1745 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001746
1747 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07001748 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04001749 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001750
Andrew Vasquez737faec2008-10-24 15:13:45 -07001751 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001752
Auke Kok44c10132007-06-08 15:46:36 -07001753 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001754
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001755 /* Get PCI bus information. */
1756 spin_lock_irqsave(&ha->hardware_lock, flags);
1757 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
1758 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1759
1760 return QLA_SUCCESS;
1761}
1762
1763/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001764 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
1765 * @ha: HA context
1766 *
1767 * Returns 0 on success.
1768 */
1769int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001770qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001771{
1772 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001773 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001774
1775 pci_set_master(ha->pdev);
1776 pci_try_set_mwi(ha->pdev);
1777
1778 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
1779 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
1780 w &= ~PCI_COMMAND_INTX_DISABLE;
1781 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1782
1783 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07001784 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04001785 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001786
Andrew Vasquez737faec2008-10-24 15:13:45 -07001787 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001788
1789 ha->chip_revision = ha->pdev->revision;
1790
1791 return QLA_SUCCESS;
1792}
1793
1794/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 * qla2x00_isp_firmware() - Choose firmware image.
1796 * @ha: HA context
1797 *
1798 * Returns 0 on success.
1799 */
1800static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001801qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802{
1803 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001804 uint16_t loop_id, topo, sw_cap;
1805 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001806 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
1808 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001809 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
1811 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001812 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813
1814 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001815 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001816 if (rval == QLA_SUCCESS) {
1817 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001818 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001819 &area, &domain, &topo, &sw_cap);
1820 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 }
1822
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001823 if (rval)
1824 ql_dbg(ql_dbg_init, vha, 0x007a,
1825 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826
1827 return (rval);
1828}
1829
1830/**
1831 * qla2x00_reset_chip() - Reset ISP chip.
1832 * @ha: HA context
1833 *
1834 * Returns 0 on success.
1835 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001836void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001837qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838{
1839 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001840 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001841 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 uint16_t cmd;
1844
Andrew Vasquez85880802009-12-15 21:29:46 -08001845 if (unlikely(pci_channel_offline(ha->pdev)))
1846 return;
1847
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001848 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
1850 spin_lock_irqsave(&ha->hardware_lock, flags);
1851
1852 /* Turn off master enable */
1853 cmd = 0;
1854 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
1855 cmd &= ~PCI_COMMAND_MASTER;
1856 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
1857
1858 if (!IS_QLA2100(ha)) {
1859 /* Pause RISC. */
1860 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
1861 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
1862 for (cnt = 0; cnt < 30000; cnt++) {
1863 if ((RD_REG_WORD(&reg->hccr) &
1864 HCCR_RISC_PAUSE) != 0)
1865 break;
1866 udelay(100);
1867 }
1868 } else {
1869 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1870 udelay(10);
1871 }
1872
1873 /* Select FPM registers. */
1874 WRT_REG_WORD(&reg->ctrl_status, 0x20);
1875 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1876
1877 /* FPM Soft Reset. */
1878 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
1879 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
1880
1881 /* Toggle Fpm Reset. */
1882 if (!IS_QLA2200(ha)) {
1883 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
1884 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
1885 }
1886
1887 /* Select frame buffer registers. */
1888 WRT_REG_WORD(&reg->ctrl_status, 0x10);
1889 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1890
1891 /* Reset frame buffer FIFOs. */
1892 if (IS_QLA2200(ha)) {
1893 WRT_FB_CMD_REG(ha, reg, 0xa000);
1894 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
1895 } else {
1896 WRT_FB_CMD_REG(ha, reg, 0x00fc);
1897
1898 /* Read back fb_cmd until zero or 3 seconds max */
1899 for (cnt = 0; cnt < 3000; cnt++) {
1900 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
1901 break;
1902 udelay(100);
1903 }
1904 }
1905
1906 /* Select RISC module registers. */
1907 WRT_REG_WORD(&reg->ctrl_status, 0);
1908 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1909
1910 /* Reset RISC processor. */
1911 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1912 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1913
1914 /* Release RISC processor. */
1915 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1916 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1917 }
1918
1919 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
1920 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
1921
1922 /* Reset ISP chip. */
1923 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1924
1925 /* Wait for RISC to recover from reset. */
1926 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1927 /*
1928 * It is necessary to for a delay here since the card doesn't
1929 * respond to PCI reads during a reset. On some architectures
1930 * this will result in an MCA.
1931 */
1932 udelay(20);
1933 for (cnt = 30000; cnt; cnt--) {
1934 if ((RD_REG_WORD(&reg->ctrl_status) &
1935 CSR_ISP_SOFT_RESET) == 0)
1936 break;
1937 udelay(100);
1938 }
1939 } else
1940 udelay(10);
1941
1942 /* Reset RISC processor. */
1943 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1944
1945 WRT_REG_WORD(&reg->semaphore, 0);
1946
1947 /* Release RISC processor. */
1948 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1949 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1950
1951 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1952 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -07001953 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
1956 udelay(100);
1957 }
1958 } else
1959 udelay(100);
1960
1961 /* Turn on master enable */
1962 cmd |= PCI_COMMAND_MASTER;
1963 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
1964
1965 /* Disable RISC pause on FPM parity error. */
1966 if (!IS_QLA2100(ha)) {
1967 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
1968 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1969 }
1970
1971 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1972}
1973
1974/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001975 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
1976 *
1977 * Returns 0 on success.
1978 */
Saurav Kashyapfa492632012-11-21 02:40:29 -05001979static int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001980qla81xx_reset_mpi(scsi_qla_host_t *vha)
1981{
1982 uint16_t mb[4] = {0x1010, 0, 1, 0};
1983
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001984 if (!IS_QLA81XX(vha->hw))
1985 return QLA_SUCCESS;
1986
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001987 return qla81xx_write_mpi_register(vha, mb);
1988}
1989
1990/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001991 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001992 * @ha: HA context
1993 *
1994 * Returns 0 on success.
1995 */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001996static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001997qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001998{
1999 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002000 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002001 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Bart Van Assche52c82822015-07-09 07:23:26 -07002002 uint32_t cnt;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002003 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002004 static int abts_cnt; /* ISP abort retry counts */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002005 int rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002006
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002007 spin_lock_irqsave(&ha->hardware_lock, flags);
2008
2009 /* Reset RISC. */
2010 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2011 for (cnt = 0; cnt < 30000; cnt++) {
2012 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2013 break;
2014
2015 udelay(10);
2016 }
2017
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002018 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE))
2019 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2020
2021 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2022 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2023 RD_REG_DWORD(&reg->hccr),
2024 RD_REG_DWORD(&reg->ctrl_status),
2025 (RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE));
2026
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002027 WRT_REG_DWORD(&reg->ctrl_status,
2028 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002029 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002030
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002031 udelay(100);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002032
Andrew Vasquez88c26662005-07-08 17:59:26 -07002033 /* Wait for firmware to complete NVRAM accesses. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002034 RD_REG_WORD(&reg->mailbox0);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002035 for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
2036 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez88c26662005-07-08 17:59:26 -07002037 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002038 if (cnt)
2039 udelay(5);
2040 else
2041 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez88c26662005-07-08 17:59:26 -07002042 }
2043
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002044 if (rval == QLA_SUCCESS)
2045 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2046
2047 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2048 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2049 RD_REG_DWORD(&reg->hccr),
2050 RD_REG_DWORD(&reg->mailbox0));
2051
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002052 /* Wait for soft-reset to complete. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002053 RD_REG_DWORD(&reg->ctrl_status);
Quinn Tran200ffb12016-12-23 18:06:12 -08002054 for (cnt = 0; cnt < 60; cnt++) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002055 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002056 if ((RD_REG_DWORD(&reg->ctrl_status) &
2057 CSRX_ISP_SOFT_RESET) == 0)
2058 break;
2059
2060 udelay(5);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002061 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002062 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_ISP_SOFT_RESET))
2063 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2064
2065 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2066 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2067 RD_REG_DWORD(&reg->hccr),
2068 RD_REG_DWORD(&reg->ctrl_status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002069
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002070 /* If required, do an MPI FW reset now */
2071 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2072 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2073 if (++abts_cnt < 5) {
2074 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2075 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2076 } else {
2077 /*
2078 * We exhausted the ISP abort retries. We have to
2079 * set the board offline.
2080 */
2081 abts_cnt = 0;
2082 vha->flags.online = 0;
2083 }
2084 }
2085 }
2086
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002087 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
2088 RD_REG_DWORD(&reg->hccr);
2089
2090 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
2091 RD_REG_DWORD(&reg->hccr);
2092
2093 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
2094 RD_REG_DWORD(&reg->hccr);
2095
Bart Van Assche52c82822015-07-09 07:23:26 -07002096 RD_REG_WORD(&reg->mailbox0);
Quinn Tran200ffb12016-12-23 18:06:12 -08002097 for (cnt = 60; RD_REG_WORD(&reg->mailbox0) != 0 &&
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002098 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002099 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002100 if (cnt)
2101 udelay(5);
2102 else
2103 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002104 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002105 if (rval == QLA_SUCCESS)
2106 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2107
2108 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2109 "Host Risc 0x%x, mailbox0 0x%x\n",
2110 RD_REG_DWORD(&reg->hccr),
2111 RD_REG_WORD(&reg->mailbox0));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002112
2113 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002114
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002115 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2116 "Driver in %s mode\n",
2117 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2118
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002119 if (IS_NOPOLLING_TYPE(ha))
2120 ha->isp_ops->enable_intrs(ha);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002121
2122 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002123}
2124
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002125static void
2126qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2127{
2128 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2129
2130 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2131 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2132
2133}
2134
2135static void
2136qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2137{
2138 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2139
2140 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2141 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2142}
2143
2144static void
2145qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2146{
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002147 uint32_t wd32 = 0;
2148 uint delta_msec = 100;
2149 uint elapsed_msec = 0;
2150 uint timeout_msec;
2151 ulong n;
2152
Joe Carnucciocc790762015-08-04 13:37:53 -04002153 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2154 vha->hw->pdev->subsystem_device != 0x0240)
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002155 return;
2156
Joe Carnuccio8dd7e3a2015-08-04 13:37:54 -04002157 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2158 udelay(100);
2159
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002160attempt:
2161 timeout_msec = TIMEOUT_SEMAPHORE;
2162 n = timeout_msec / delta_msec;
2163 while (n--) {
2164 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2165 qla25xx_read_risc_sema_reg(vha, &wd32);
2166 if (wd32 & RISC_SEMAPHORE)
2167 break;
2168 msleep(delta_msec);
2169 elapsed_msec += delta_msec;
2170 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2171 goto force;
2172 }
2173
2174 if (!(wd32 & RISC_SEMAPHORE))
2175 goto force;
2176
2177 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2178 goto acquired;
2179
2180 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2181 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2182 n = timeout_msec / delta_msec;
2183 while (n--) {
2184 qla25xx_read_risc_sema_reg(vha, &wd32);
2185 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2186 break;
2187 msleep(delta_msec);
2188 elapsed_msec += delta_msec;
2189 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2190 goto force;
2191 }
2192
2193 if (wd32 & RISC_SEMAPHORE_FORCE)
2194 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2195
2196 goto attempt;
2197
2198force:
2199 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2200
2201acquired:
2202 return;
2203}
2204
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002205/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002206 * qla24xx_reset_chip() - Reset ISP24xx chip.
2207 * @ha: HA context
2208 *
2209 * Returns 0 on success.
2210 */
2211void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002212qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07002213{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002214 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08002215
2216 if (pci_channel_offline(ha->pdev) &&
2217 ha->flags.pci_channel_io_perm_failure) {
2218 return;
2219 }
2220
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002221 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002222
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002223 qla25xx_manipulate_risc_semaphore(vha);
2224
Andrew Vasquez88c26662005-07-08 17:59:26 -07002225 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002226 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002227}
2228
2229/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 * qla2x00_chip_diag() - Test chip for proper operation.
2231 * @ha: HA context
2232 *
2233 * Returns 0 on success.
2234 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002235int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002236qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237{
2238 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002239 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002240 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 unsigned long flags = 0;
2242 uint16_t data;
2243 uint32_t cnt;
2244 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002245 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246
2247 /* Assume a failed state */
2248 rval = QLA_FUNCTION_FAILED;
2249
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002250 ql_dbg(ql_dbg_init, vha, 0x007b,
2251 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252
2253 spin_lock_irqsave(&ha->hardware_lock, flags);
2254
2255 /* Reset ISP chip. */
2256 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
2257
2258 /*
2259 * We need to have a delay here since the card will not respond while
2260 * in reset causing an MCA on some architectures.
2261 */
2262 udelay(20);
2263 data = qla2x00_debounce_register(&reg->ctrl_status);
2264 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2265 udelay(5);
2266 data = RD_REG_WORD(&reg->ctrl_status);
2267 barrier();
2268 }
2269
2270 if (!cnt)
2271 goto chip_diag_failed;
2272
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002273 ql_dbg(ql_dbg_init, vha, 0x007c,
2274 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
2276 /* Reset RISC processor. */
2277 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2278 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2279
2280 /* Workaround for QLA2312 PCI parity error */
2281 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2282 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2283 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2284 udelay(5);
2285 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002286 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 }
2288 } else
2289 udelay(10);
2290
2291 if (!cnt)
2292 goto chip_diag_failed;
2293
2294 /* Check product ID of chip */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002295 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296
2297 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
2298 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
2299 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
2300 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
2301 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
2302 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002303 ql_log(ql_log_warn, vha, 0x0062,
2304 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2305 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306
2307 goto chip_diag_failed;
2308 }
2309 ha->product_id[0] = mb[1];
2310 ha->product_id[1] = mb[2];
2311 ha->product_id[2] = mb[3];
2312 ha->product_id[3] = mb[4];
2313
2314 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002315 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
2317 else
2318 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002319 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
2321 if (IS_QLA2200(ha) &&
2322 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
2323 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002324 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002326 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 ha->fw_transfer_size = 128;
2328 }
2329
2330 /* Wrap Incoming Mailboxes Test. */
2331 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2332
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002333 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002334 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002335 if (rval)
2336 ql_log(ql_log_warn, vha, 0x0080,
2337 "Failed mailbox send register test.\n");
2338 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 /* Flag a successful rval */
2340 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 spin_lock_irqsave(&ha->hardware_lock, flags);
2342
2343chip_diag_failed:
2344 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002345 ql_log(ql_log_info, vha, 0x0081,
2346 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347
2348 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2349
2350 return (rval);
2351}
2352
2353/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002354 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2355 * @ha: HA context
2356 *
2357 * Returns 0 on success.
2358 */
2359int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002360qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002361{
2362 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002363 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002364 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002365
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002366 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07002367 return QLA_SUCCESS;
2368
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002369 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002370
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002371 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002372 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002373 ql_log(ql_log_warn, vha, 0x0082,
2374 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002375 } else {
2376 /* Flag a successful rval */
2377 rval = QLA_SUCCESS;
2378 }
2379
2380 return rval;
2381}
2382
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002383void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002384qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002385{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002386 int rval;
2387 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002388 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002389 dma_addr_t tc_dma;
2390 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002391 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002392 struct req_que *req = ha->req_q_map[0];
2393 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002394
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002395 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002396 ql_dbg(ql_dbg_init, vha, 0x00bd,
2397 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002398 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002399 }
2400
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002401 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04002402 ha->fw_dump_cap_flags = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002403 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
2404 req_q_size = rsp_q_size = 0;
2405
2406 if (IS_QLA27XX(ha))
2407 goto try_fce;
2408
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002409 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2410 fixed_size = sizeof(struct qla2100_fw_dump);
2411 } else if (IS_QLA23XX(ha)) {
2412 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
2413 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
2414 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07002415 } else if (IS_FWI2_CAPABLE(ha)) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002416 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002417 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
2418 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002419 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
2420 else if (IS_QLA25XX(ha))
2421 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
2422 else
2423 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002424
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002425 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
2426 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002427 if (ha->mqenable) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002428 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002429 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002430 /*
2431 * Allocate maximum buffer size for all queues.
2432 * Resizing must be done at end-of-dump processing.
2433 */
2434 mq_size += ha->max_req_queues *
2435 (req->length * sizeof(request_t));
2436 mq_size += ha->max_rsp_queues *
2437 (rsp->length * sizeof(response_t));
2438 }
Arun Easi00876ae2013-03-25 02:21:37 -04002439 if (ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002440 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002441 /* Allocate memory for Fibre Channel Event Buffer. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05002442 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2443 !IS_QLA27XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002444 goto try_eft;
2445
Chad Dupuisf73cb692014-02-26 04:15:06 -05002446try_fce:
2447 if (ha->fce)
2448 dma_free_coherent(&ha->pdev->dev,
2449 FCE_SIZE, ha->fce, ha->fce_dma);
2450
2451 /* Allocate memory for Fibre Channel Event Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07002452 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
2453 GFP_KERNEL);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002454 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002455 ql_log(ql_log_warn, vha, 0x00be,
2456 "Unable to allocate (%d KB) for FCE.\n",
2457 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002458 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002459 }
2460
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002461 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002462 ha->fce_mb, &ha->fce_bufs);
2463 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002464 ql_log(ql_log_warn, vha, 0x00bf,
2465 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002466 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
2467 tc_dma);
2468 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002469 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002470 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002471 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002472 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002473
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07002474 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002475 ha->flags.fce_enabled = 1;
2476 ha->fce_dma = tc_dma;
2477 ha->fce = tc;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002478
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002479try_eft:
Chad Dupuisf73cb692014-02-26 04:15:06 -05002480 if (ha->eft)
2481 dma_free_coherent(&ha->pdev->dev,
2482 EFT_SIZE, ha->eft, ha->eft_dma);
2483
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002484 /* Allocate memory for Extended Trace Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07002485 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
2486 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002487 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002488 ql_log(ql_log_warn, vha, 0x00c1,
2489 "Unable to allocate (%d KB) for EFT.\n",
2490 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002491 goto cont_alloc;
2492 }
2493
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002494 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002495 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002496 ql_log(ql_log_warn, vha, 0x00c2,
2497 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002498 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
2499 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002500 goto cont_alloc;
2501 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002502 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002503 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002504
2505 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002506 ha->eft_dma = tc_dma;
2507 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002508 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05002509
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002510cont_alloc:
Chad Dupuisf73cb692014-02-26 04:15:06 -05002511 if (IS_QLA27XX(ha)) {
2512 if (!ha->fw_dump_template) {
2513 ql_log(ql_log_warn, vha, 0x00ba,
2514 "Failed missing fwdump template\n");
2515 return;
2516 }
2517 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
2518 ql_dbg(ql_dbg_init, vha, 0x00fa,
2519 "-> allocating fwdump (%x bytes)...\n", dump_size);
2520 goto allocate;
2521 }
2522
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002523 req_q_size = req->length * sizeof(request_t);
2524 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002525 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002526 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08002527 ha->chain_offset = dump_size;
2528 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002529
Chad Dupuisf73cb692014-02-26 04:15:06 -05002530allocate:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002531 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002532 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002533 ql_log(ql_log_warn, vha, 0x00c4,
2534 "Unable to allocate (%d KB) for firmware dump.\n",
2535 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002536
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002537 if (ha->fce) {
2538 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2539 ha->fce_dma);
2540 ha->fce = NULL;
2541 ha->fce_dma = 0;
2542 }
2543
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002544 if (ha->eft) {
2545 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
2546 ha->eft_dma);
2547 ha->eft = NULL;
2548 ha->eft_dma = 0;
2549 }
2550 return;
2551 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05002552 ha->fw_dump_len = dump_size;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002553 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002554 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002555
Chad Dupuisf73cb692014-02-26 04:15:06 -05002556 if (IS_QLA27XX(ha))
2557 return;
2558
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002559 ha->fw_dump->signature[0] = 'Q';
2560 ha->fw_dump->signature[1] = 'L';
2561 ha->fw_dump->signature[2] = 'G';
2562 ha->fw_dump->signature[3] = 'C';
Bart Van Asschead950362015-07-09 07:24:08 -07002563 ha->fw_dump->version = htonl(1);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002564
2565 ha->fw_dump->fixed_size = htonl(fixed_size);
2566 ha->fw_dump->mem_size = htonl(mem_size);
2567 ha->fw_dump->req_q_size = htonl(req_q_size);
2568 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
2569
2570 ha->fw_dump->eft_size = htonl(eft_size);
2571 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
2572 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
2573
2574 ha->fw_dump->header_size =
2575 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002576}
2577
Andrew Vasquez18e75552009-06-03 09:55:30 -07002578static int
2579qla81xx_mpi_sync(scsi_qla_host_t *vha)
2580{
2581#define MPS_MASK 0xe0
2582 int rval;
2583 uint16_t dc;
2584 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07002585
2586 if (!IS_QLA81XX(vha->hw))
2587 return QLA_SUCCESS;
2588
2589 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
2590 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002591 ql_log(ql_log_warn, vha, 0x0105,
2592 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002593 goto done;
2594 }
2595
2596 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
2597 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
2598 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002599 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002600 goto done_release;
2601 }
2602
2603 dc &= MPS_MASK;
2604 if (dc == (dw & MPS_MASK))
2605 goto done_release;
2606
2607 dw &= ~MPS_MASK;
2608 dw |= dc;
2609 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
2610 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002611 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002612 }
2613
2614done_release:
2615 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
2616 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002617 ql_log(ql_log_warn, vha, 0x006d,
2618 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002619 }
2620
2621done:
2622 return rval;
2623}
2624
Chad Dupuis8d93f552013-01-30 03:34:37 -05002625int
2626qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
2627{
2628 /* Don't try to reallocate the array */
2629 if (req->outstanding_cmds)
2630 return QLA_SUCCESS;
2631
Michael Hernandezd7459522016-12-12 14:40:07 -08002632 if (!IS_FWI2_CAPABLE(ha))
Chad Dupuis8d93f552013-01-30 03:34:37 -05002633 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
2634 else {
Quinn Tran03e8c682015-12-17 14:56:59 -05002635 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
2636 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002637 else
Quinn Tran03e8c682015-12-17 14:56:59 -05002638 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002639 }
2640
2641 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
2642 req->num_outstanding_cmds, GFP_KERNEL);
2643
2644 if (!req->outstanding_cmds) {
2645 /*
2646 * Try to allocate a minimal size just so we can get through
2647 * initialization.
2648 */
2649 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
2650 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
2651 req->num_outstanding_cmds, GFP_KERNEL);
2652
2653 if (!req->outstanding_cmds) {
2654 ql_log(ql_log_fatal, NULL, 0x0126,
2655 "Failed to allocate memory for "
2656 "outstanding_cmds for req_que %p.\n", req);
2657 req->num_outstanding_cmds = 0;
2658 return QLA_FUNCTION_FAILED;
2659 }
2660 }
2661
2662 return QLA_SUCCESS;
2663}
2664
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002665/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 * qla2x00_setup_chip() - Load and start RISC firmware.
2667 * @ha: HA context
2668 *
2669 * Returns 0 on success.
2670 */
2671static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002672qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002674 int rval;
2675 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002676 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08002677 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2678 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07002679 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08002680
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002681 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002682 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05002683 if (rval == QLA_SUCCESS) {
2684 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002685 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05002686 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07002687 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002688 }
2689
Andrew Vasquez3db06522008-01-31 12:33:49 -08002690 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
2691 /* Disable SRAM, Instruction RAM and GP RAM parity. */
2692 spin_lock_irqsave(&ha->hardware_lock, flags);
2693 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
2694 RD_REG_WORD(&reg->hccr);
2695 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2696 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697
Andrew Vasquez18e75552009-06-03 09:55:30 -07002698 qla81xx_mpi_sync(vha);
2699
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002701 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002702 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002703 ql_dbg(ql_dbg_init, vha, 0x00c9,
2704 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002706 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 if (rval == QLA_SUCCESS) {
2708 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002709 ql_dbg(ql_dbg_init, vha, 0x00ca,
2710 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05002712 if (ql2xexlogins)
2713 ha->flags.exlogins_enabled = 1;
2714
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05002715 if (ql2xexchoffld)
2716 ha->flags.exchoffld_enabled = 1;
2717
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002718 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07002720 if (rval == QLA_SUCCESS) {
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05002721 rval = qla2x00_set_exlogins_buffer(vha);
2722 if (rval != QLA_SUCCESS)
2723 goto failed;
2724
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05002725 rval = qla2x00_set_exchoffld_buffer(vha);
2726 if (rval != QLA_SUCCESS)
2727 goto failed;
2728
Giridhar Malavalia9083012010-04-12 17:59:55 -07002729enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07002730 fw_major_version = ha->fw_major_version;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002731 if (IS_P3P_TYPE(ha))
Giridhar Malavali31731672011-08-16 11:31:54 -07002732 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002733 else
2734 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07002735 if (rval != QLA_SUCCESS)
2736 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002737 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002738 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07002739 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002740 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002741 if ((!ha->max_npiv_vports) ||
2742 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002743 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002744 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002745 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002746 }
Quinn Tran03e8c682015-12-17 14:56:59 -05002747 qla2x00_get_resource_cnts(vha);
Andrew Vasquezd743de62009-03-24 09:08:15 -07002748
Chad Dupuis8d93f552013-01-30 03:34:37 -05002749 /*
2750 * Allocate the array of outstanding commands
2751 * now that we know the firmware resources.
2752 */
2753 rval = qla2x00_alloc_outstanding_cmds(ha,
2754 vha->req);
2755 if (rval != QLA_SUCCESS)
2756 goto failed;
2757
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08002758 if (!fw_major_version && ql2xallocfwdump
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002759 && !(IS_P3P_TYPE(ha)))
Giridhar Malavali08de2842011-08-16 11:31:44 -07002760 qla2x00_alloc_fw_dump(vha);
Chad Dupuis3b6e5b92013-10-30 03:38:09 -04002761 } else {
2762 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 }
2764 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002765 ql_log(ql_log_fatal, vha, 0x00cd,
2766 "ISP Firmware failed checksum.\n");
2767 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04002769 } else
2770 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771
Andrew Vasquez3db06522008-01-31 12:33:49 -08002772 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
2773 /* Enable proper parity. */
2774 spin_lock_irqsave(&ha->hardware_lock, flags);
2775 if (IS_QLA2300(ha))
2776 /* SRAM parity */
2777 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
2778 else
2779 /* SRAM, Instruction RAM and GP RAM parity */
2780 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
2781 RD_REG_WORD(&reg->hccr);
2782 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2783 }
2784
Chad Dupuisf3982d82014-09-25 05:16:57 -04002785 if (IS_QLA27XX(ha))
2786 ha->flags.fac_supported = 1;
2787 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07002788 uint32_t size;
2789
2790 rval = qla81xx_fac_get_sector_size(vha, &size);
2791 if (rval == QLA_SUCCESS) {
2792 ha->flags.fac_supported = 1;
2793 ha->fdt_block_size = size << 2;
2794 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002795 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07002796 "Unsupported FAC firmware (%d.%02d.%02d).\n",
2797 ha->fw_major_version, ha->fw_minor_version,
2798 ha->fw_subminor_version);
Joe Carnuccio1ca60e32014-02-26 04:15:02 -05002799
Chad Dupuisf73cb692014-02-26 04:15:06 -05002800 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002801 ha->flags.fac_supported = 0;
2802 rval = QLA_SUCCESS;
2803 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07002804 }
2805 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07002806failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002808 ql_log(ql_log_fatal, vha, 0x00cf,
2809 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 }
2811
2812 return (rval);
2813}
2814
2815/**
2816 * qla2x00_init_response_q_entries() - Initializes response queue entries.
2817 * @ha: HA context
2818 *
2819 * Beginning of request ring has initialization control block already built
2820 * by nvram config routine.
2821 *
2822 * Returns 0 on success.
2823 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002824void
2825qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826{
2827 uint16_t cnt;
2828 response_t *pkt;
2829
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002830 rsp->ring_ptr = rsp->ring;
2831 rsp->ring_index = 0;
2832 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002833 pkt = rsp->ring_ptr;
2834 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 pkt->signature = RESPONSE_PROCESSED;
2836 pkt++;
2837 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838}
2839
2840/**
2841 * qla2x00_update_fw_options() - Read and process firmware options.
2842 * @ha: HA context
2843 *
2844 * Returns 0 on success.
2845 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002846void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002847qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848{
2849 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002850 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851
2852 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002853 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854
2855 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2856 return;
2857
2858 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002859 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
2860 "Serial link options.\n");
2861 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
2862 (uint8_t *)&ha->fw_seriallink_options,
2863 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864
2865 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
2866 if (ha->fw_seriallink_options[3] & BIT_2) {
2867 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
2868
2869 /* 1G settings */
2870 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
2871 emphasis = (ha->fw_seriallink_options[2] &
2872 (BIT_4 | BIT_3)) >> 3;
2873 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002874 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 rx_sens = (ha->fw_seriallink_options[0] &
2876 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
2877 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
2878 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2879 if (rx_sens == 0x0)
2880 rx_sens = 0x3;
2881 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
2882 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2883 ha->fw_options[10] |= BIT_5 |
2884 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2885 (tx_sens & (BIT_1 | BIT_0));
2886
2887 /* 2G settings */
2888 swing = (ha->fw_seriallink_options[2] &
2889 (BIT_7 | BIT_6 | BIT_5)) >> 5;
2890 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
2891 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002892 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 rx_sens = (ha->fw_seriallink_options[1] &
2894 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
2895 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
2896 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2897 if (rx_sens == 0x0)
2898 rx_sens = 0x3;
2899 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
2900 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2901 ha->fw_options[11] |= BIT_5 |
2902 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2903 (tx_sens & (BIT_1 | BIT_0));
2904 }
2905
2906 /* FCP2 options. */
2907 /* Return command IOCBs without waiting for an ABTS to complete. */
2908 ha->fw_options[3] |= BIT_13;
2909
2910 /* LED scheme. */
2911 if (ha->flags.enable_led_scheme)
2912 ha->fw_options[2] |= BIT_12;
2913
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002914 /* Detect ISP6312. */
2915 if (IS_QLA6312(ha))
2916 ha->fw_options[2] |= BIT_13;
2917
Giridhar Malavali088d09d2016-07-06 11:14:20 -04002918 /* Set Retry FLOGI in case of P2P connection */
2919 if (ha->operating_mode == P2P) {
2920 ha->fw_options[2] |= BIT_3;
2921 ql_dbg(ql_dbg_disc, vha, 0x2100,
2922 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
2923 __func__, ha->fw_options[2]);
2924 }
2925
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002927 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928}
2929
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002930void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002931qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002932{
2933 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002934 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002935
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002936 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07002937 return;
2938
Himanshu Madhanif198caf2016-01-27 12:03:30 -05002939 /* Hold status IOCBs until ABTS response received. */
2940 if (ql2xfwholdabts)
2941 ha->fw_options[3] |= BIT_12;
2942
Giridhar Malavali088d09d2016-07-06 11:14:20 -04002943 /* Set Retry FLOGI in case of P2P connection */
2944 if (ha->operating_mode == P2P) {
2945 ha->fw_options[2] |= BIT_3;
2946 ql_dbg(ql_dbg_disc, vha, 0x2101,
2947 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
2948 __func__, ha->fw_options[2]);
2949 }
2950
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002951 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08002952 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002953 return;
2954
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002955 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08002956 le16_to_cpu(ha->fw_seriallink_options24[1]),
2957 le16_to_cpu(ha->fw_seriallink_options24[2]),
2958 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002959 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002960 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002961 "Unable to update Serial Link options (%x).\n", rval);
2962 }
2963}
2964
2965void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002966qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002967{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002968 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002969 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002970 struct req_que *req = ha->req_q_map[0];
2971 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002972
2973 /* Setup ring parameters in initialization control block. */
Bart Van Asschead950362015-07-09 07:24:08 -07002974 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
2975 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002976 ha->init_cb->request_q_length = cpu_to_le16(req->length);
2977 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
2978 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2979 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2980 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2981 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002982
2983 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
2984 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
2985 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
2986 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
2987 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
2988}
2989
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002990void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002991qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002992{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002993 struct qla_hw_data *ha = vha->hw;
Bart Van Assche118e2ef2015-07-09 07:24:27 -07002994 device_reg_t *reg = ISP_QUE_REG(ha, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002995 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
2996 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002997 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002998 uint16_t rid = 0;
2999 struct req_que *req = ha->req_q_map[0];
3000 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003001
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003002 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003003 icb = (struct init_cb_24xx *)ha->init_cb;
Bart Van Asschead950362015-07-09 07:24:08 -07003004 icb->request_q_outpointer = cpu_to_le16(0);
3005 icb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003006 icb->request_q_length = cpu_to_le16(req->length);
3007 icb->response_q_length = cpu_to_le16(rsp->length);
3008 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3009 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3010 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3011 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003012
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003013 /* Setup ATIO queue dma pointers for target mode */
Bart Van Asschead950362015-07-09 07:24:08 -07003014 icb->atio_q_inpointer = cpu_to_le16(0);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003015 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3016 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
3017 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
3018
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003019 if (IS_SHADOW_REG_CAPABLE(ha))
Bart Van Asschead950362015-07-09 07:24:08 -07003020 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003021
Chad Dupuisf73cb692014-02-26 04:15:06 -05003022 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003023 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3024 icb->rid = cpu_to_le16(rid);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003025 if (ha->flags.msix_enabled) {
3026 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003027 ql_dbg(ql_dbg_init, vha, 0x00fd,
3028 "Registering vector 0x%x for base que.\n",
3029 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003030 icb->msix = cpu_to_le16(msix->entry);
3031 }
3032 /* Use alternate PCI bus number */
3033 if (MSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003034 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003035 /* Use alternate PCI devfn */
3036 if (LSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003037 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003038
Anirban Chakraborty31557542009-12-02 10:36:55 -08003039 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003040 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
3041 (ha->flags.msix_enabled)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003042 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003043 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003044 ql_dbg(ql_dbg_init, vha, 0x00fe,
3045 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08003046 } else {
Bart Van Asschead950362015-07-09 07:24:08 -07003047 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003048 }
Bart Van Asschead950362015-07-09 07:24:08 -07003049 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003050
3051 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
3052 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
3053 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
3054 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
3055 } else {
3056 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
3057 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
3058 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
3059 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
3060 }
Arun Easiaa230bc2013-01-30 03:34:39 -05003061 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003062
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003063 /* PCI posting */
3064 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003065}
3066
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067/**
3068 * qla2x00_init_rings() - Initializes firmware.
3069 * @ha: HA context
3070 *
3071 * Beginning of request ring has initialization control block already built
3072 * by nvram config routine.
3073 *
3074 * Returns 0 on success.
3075 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003076int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003077qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078{
3079 int rval;
3080 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003081 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003082 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003083 struct req_que *req;
3084 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003085 struct mid_init_cb_24xx *mid_init_cb =
3086 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087
3088 spin_lock_irqsave(&ha->hardware_lock, flags);
3089
3090 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003091 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003092 req = ha->req_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003093 if (!req || !test_bit(que, ha->req_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003094 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003095 req->out_ptr = (void *)(req->ring + req->length);
3096 *req->out_ptr = 0;
Chad Dupuis8d93f552013-01-30 03:34:37 -05003097 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003098 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003100 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003101
3102 /* Initialize firmware. */
3103 req->ring_ptr = req->ring;
3104 req->ring_index = 0;
3105 req->cnt = req->length;
3106 }
3107
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003108 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003109 rsp = ha->rsp_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003110 if (!rsp || !test_bit(que, ha->rsp_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003111 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003112 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
3113 *rsp->in_ptr = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003114 /* Initialize response queue entries */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003115 if (IS_QLAFX00(ha))
3116 qlafx00_init_response_q_entries(rsp);
3117 else
3118 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003119 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003121 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
3122 ha->tgt.atio_ring_index = 0;
3123 /* Initialize ATIO queue entries */
3124 qlt_init_atio_q_entries(vha);
3125
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003126 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127
3128 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3129
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003130 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
3131
3132 if (IS_QLAFX00(ha)) {
3133 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
3134 goto next_check;
3135 }
3136
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003138 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003140 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04003141 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003142 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08003143 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003144 }
3145
Andrew Vasquez24a08132009-03-24 09:08:16 -07003146 if (IS_FWI2_CAPABLE(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003147 mid_init_cb->options = cpu_to_le16(BIT_1);
Andrew Vasquez24a08132009-03-24 09:08:16 -07003148 mid_init_cb->init_cb.execution_throttle =
Quinn Tran03e8c682015-12-17 14:56:59 -05003149 cpu_to_le16(ha->cur_fw_xcb_count);
Joe Carnuccio40f38622016-07-06 11:14:28 -04003150 ha->flags.dport_enabled =
3151 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
3152 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
3153 (ha->flags.dport_enabled) ? "enabled" : "disabled");
3154 /* FA-WWPN Status */
Himanshu Madhani2486c622014-09-25 05:17:00 -04003155 ha->flags.fawwpn_enabled =
Joe Carnuccio40f38622016-07-06 11:14:28 -04003156 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
Himanshu Madhani2486c622014-09-25 05:17:00 -04003157 ql_dbg(ql_dbg_init, vha, 0x0141, "FA-WWPN Support: %s.\n",
3158 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
Andrew Vasquez24a08132009-03-24 09:08:16 -07003159 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003160
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003161 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003162next_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003164 ql_log(ql_log_fatal, vha, 0x00d2,
3165 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003167 ql_dbg(ql_dbg_init, vha, 0x00d3,
3168 "Init Firmware -- success.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 }
3170
3171 return (rval);
3172}
3173
3174/**
3175 * qla2x00_fw_ready() - Waits for firmware ready.
3176 * @ha: HA context
3177 *
3178 * Returns 0 on success.
3179 */
3180static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003181qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182{
3183 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003184 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 uint16_t min_wait; /* Minimum wait time if loop is down */
3186 uint16_t wait_time; /* Wait time if loop is coming ready */
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003187 uint16_t state[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003188 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003190 if (IS_QLAFX00(vha->hw))
3191 return qlafx00_fw_ready(vha);
3192
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 rval = QLA_SUCCESS;
3194
Chad Dupuis334614912015-04-09 14:59:57 -04003195 /* Time to wait for loop down */
3196 if (IS_P3P_TYPE(ha))
3197 min_wait = 30;
3198 else
3199 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200
3201 /*
3202 * Firmware should take at most one RATOV to login, plus 5 seconds for
3203 * our own processing.
3204 */
3205 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
3206 wait_time = min_wait;
3207 }
3208
3209 /* Min wait time if loop down */
3210 mtime = jiffies + (min_wait * HZ);
3211
3212 /* wait time before firmware ready */
3213 wtime = jiffies + (wait_time * HZ);
3214
3215 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003216 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003217 ql_log(ql_log_info, vha, 0x801e,
3218 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219
3220 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05003221 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003222 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003224 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003225 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003227 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003228 ql_dbg(ql_dbg_taskm, vha, 0x801f,
3229 "fw_state=%x 84xx=%x.\n", state[0],
3230 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003231 if ((state[2] & FSTATE_LOGGED_IN) &&
3232 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003233 ql_dbg(ql_dbg_taskm, vha, 0x8028,
3234 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003235
3236 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003237 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003238 if (rval != QLA_SUCCESS) {
3239 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08003240 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003241 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003242 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003243 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003244
3245 /* Add time taken to initialize. */
3246 cs84xx_time = jiffies - cs84xx_time;
3247 wtime += cs84xx_time;
3248 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08003249 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003250 "Increasing wait time by %ld. "
3251 "New time %ld.\n", cs84xx_time,
3252 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003253 }
3254 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003255 ql_dbg(ql_dbg_taskm, vha, 0x8037,
3256 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003258 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 &ha->login_timeout, &ha->r_a_tov);
3260
3261 rval = QLA_SUCCESS;
3262 break;
3263 }
3264
3265 rval = QLA_FUNCTION_FAILED;
3266
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003267 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003268 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003270 * other than Wait for Login.
3271 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003273 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 "Cable is unplugged...\n");
3275
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003276 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 break;
3278 }
3279 }
3280 } else {
3281 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07003282 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08003283 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 break;
3285 }
3286
3287 if (time_after_eq(jiffies, wtime))
3288 break;
3289
3290 /* Delay for a while */
3291 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 } while (1);
3293
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003294 ql_dbg(ql_dbg_taskm, vha, 0x803a,
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003295 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
3296 state[1], state[2], state[3], state[4], state[5], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297
Chad Dupuiscfb09192011-11-18 09:03:07 -08003298 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003299 ql_log(ql_log_warn, vha, 0x803b,
3300 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 }
3302
3303 return (rval);
3304}
3305
3306/*
3307* qla2x00_configure_hba
3308* Setup adapter context.
3309*
3310* Input:
3311* ha = adapter state pointer.
3312*
3313* Returns:
3314* 0 = success
3315*
3316* Context:
3317* Kernel context.
3318*/
3319static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003320qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321{
3322 int rval;
3323 uint16_t loop_id;
3324 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003325 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 uint8_t al_pa;
3327 uint8_t area;
3328 uint8_t domain;
3329 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003330 struct qla_hw_data *ha = vha->hw;
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02003331 unsigned long flags;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003332 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333
3334 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003335 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003336 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003338 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003339 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08003340 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003341 ql_dbg(ql_dbg_disc, vha, 0x2008,
3342 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08003343 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003344 ql_log(ql_log_warn, vha, 0x2009,
3345 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003346 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
3347 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
3348 ql_log(ql_log_warn, vha, 0x1151,
3349 "Doing link init.\n");
3350 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
3351 return rval;
3352 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003353 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08003354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 return (rval);
3356 }
3357
3358 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003359 ql_log(ql_log_info, vha, 0x200a,
3360 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 return (QLA_FUNCTION_FAILED);
3362 }
3363
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003364 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365
3366 /* initialize */
3367 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
3368 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003369 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370
3371 switch (topo) {
3372 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003373 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 ha->current_topology = ISP_CFG_NL;
3375 strcpy(connect_type, "(Loop)");
3376 break;
3377
3378 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003379 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003380 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 ha->current_topology = ISP_CFG_FL;
3382 strcpy(connect_type, "(FL_Port)");
3383 break;
3384
3385 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003386 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 ha->operating_mode = P2P;
3388 ha->current_topology = ISP_CFG_N;
3389 strcpy(connect_type, "(N_Port-to-N_Port)");
3390 break;
3391
3392 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003393 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003394 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 ha->operating_mode = P2P;
3396 ha->current_topology = ISP_CFG_F;
3397 strcpy(connect_type, "(F_Port)");
3398 break;
3399
3400 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003401 ql_dbg(ql_dbg_disc, vha, 0x200f,
3402 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403 ha->current_topology = ISP_CFG_NL;
3404 strcpy(connect_type, "(Loop)");
3405 break;
3406 }
3407
3408 /* Save Host port and loop ID. */
3409 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003410 vha->d_id.b.domain = domain;
3411 vha->d_id.b.area = area;
3412 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02003414 spin_lock_irqsave(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003415 qlt_update_vp_map(vha, SET_AL_PA);
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02003416 spin_unlock_irqrestore(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003417
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003419 ql_log(ql_log_info, vha, 0x2010,
3420 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003421 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 return(rval);
3424}
3425
Giridhar Malavalia9083012010-04-12 17:59:55 -07003426inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003427qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
3428 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003429{
3430 char *st, *en;
3431 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003432 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07003433 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003434 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003435
3436 if (memcmp(model, BINZERO, len) != 0) {
3437 strncpy(ha->model_number, model, len);
3438 st = en = ha->model_number;
3439 en += len - 1;
3440 while (en > st) {
3441 if (*en != 0x20 && *en != 0x00)
3442 break;
3443 *en-- = '\0';
3444 }
3445
3446 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07003447 if (use_tbl &&
3448 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003449 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003450 strncpy(ha->model_desc,
3451 qla2x00_model_name[index * 2 + 1],
3452 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003453 } else {
3454 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07003455 if (use_tbl &&
3456 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003457 index < QLA_MODEL_NAMES) {
3458 strcpy(ha->model_number,
3459 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003460 strncpy(ha->model_desc,
3461 qla2x00_model_name[index * 2 + 1],
3462 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003463 } else {
3464 strcpy(ha->model_number, def);
3465 }
3466 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003467 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003468 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003469 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003470}
3471
David Miller4e08df32007-04-16 12:37:43 -07003472/* On sparc systems, obtain port and node WWN from firmware
3473 * properties.
3474 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003475static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07003476{
3477#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003478 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003479 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003480 struct device_node *dp = pci_device_to_OF_node(pdev);
3481 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003482 int len;
3483
3484 val = of_get_property(dp, "port-wwn", &len);
3485 if (val && len >= WWN_SIZE)
3486 memcpy(nv->port_name, val, WWN_SIZE);
3487
3488 val = of_get_property(dp, "node-wwn", &len);
3489 if (val && len >= WWN_SIZE)
3490 memcpy(nv->node_name, val, WWN_SIZE);
3491#endif
3492}
3493
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494/*
3495* NVRAM configuration for ISP 2xxx
3496*
3497* Input:
3498* ha = adapter block pointer.
3499*
3500* Output:
3501* initialization control block in response_ring
3502* host adapters parameters in host adapter block
3503*
3504* Returns:
3505* 0 = success.
3506*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003507int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003508qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509{
David Miller4e08df32007-04-16 12:37:43 -07003510 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003511 uint8_t chksum = 0;
3512 uint16_t cnt;
3513 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003514 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003515 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003516 nvram_t *nv = ha->nvram;
3517 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003518 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519
David Miller4e08df32007-04-16 12:37:43 -07003520 rval = QLA_SUCCESS;
3521
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003523 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524 ha->nvram_base = 0;
3525 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
3526 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
3527 ha->nvram_base = 0x80;
3528
3529 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003530 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003531 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
3532 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003534 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
3535 "Contents of NVRAM.\n");
3536 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
3537 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538
3539 /* Bad NVRAM data, set defaults parameters. */
3540 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
3541 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
3542 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003543 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04003544 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003545 "detected: checksum=0x%x id=%c version=0x%x.\n",
3546 chksum, nv->id[0], nv->nvram_version);
3547 ql_log(ql_log_warn, vha, 0x0065,
3548 "Falling back to "
3549 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07003550
3551 /*
3552 * Set default initialization control block.
3553 */
3554 memset(nv, 0, ha->nvram_size);
3555 nv->parameter_block_version = ICB_VERSION;
3556
3557 if (IS_QLA23XX(ha)) {
3558 nv->firmware_options[0] = BIT_2 | BIT_1;
3559 nv->firmware_options[1] = BIT_7 | BIT_5;
3560 nv->add_firmware_options[0] = BIT_5;
3561 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04003562 nv->frame_payload_size = 2048;
David Miller4e08df32007-04-16 12:37:43 -07003563 nv->special_options[1] = BIT_7;
3564 } else if (IS_QLA2200(ha)) {
3565 nv->firmware_options[0] = BIT_2 | BIT_1;
3566 nv->firmware_options[1] = BIT_7 | BIT_5;
3567 nv->add_firmware_options[0] = BIT_5;
3568 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04003569 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07003570 } else if (IS_QLA2100(ha)) {
3571 nv->firmware_options[0] = BIT_3 | BIT_1;
3572 nv->firmware_options[1] = BIT_5;
Joe Carnuccio98aee702014-09-25 05:16:38 -04003573 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07003574 }
3575
Bart Van Asschead950362015-07-09 07:24:08 -07003576 nv->max_iocb_allocation = cpu_to_le16(256);
3577 nv->execution_throttle = cpu_to_le16(16);
David Miller4e08df32007-04-16 12:37:43 -07003578 nv->retry_count = 8;
3579 nv->retry_delay = 1;
3580
3581 nv->port_name[0] = 33;
3582 nv->port_name[3] = 224;
3583 nv->port_name[4] = 139;
3584
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003585 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003586
3587 nv->login_timeout = 4;
3588
3589 /*
3590 * Set default host adapter parameters
3591 */
3592 nv->host_p[1] = BIT_2;
3593 nv->reset_delay = 5;
3594 nv->port_down_retry_count = 8;
Bart Van Asschead950362015-07-09 07:24:08 -07003595 nv->max_luns_per_target = cpu_to_le16(8);
David Miller4e08df32007-04-16 12:37:43 -07003596 nv->link_down_timeout = 60;
3597
3598 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599 }
3600
3601#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3602 /*
3603 * The SN2 does not provide BIOS emulation which means you can't change
3604 * potentially bogus BIOS settings. Force the use of default settings
3605 * for link rate and frame size. Hope that the rest of the settings
3606 * are valid.
3607 */
3608 if (ia64_platform_is("sn2")) {
Joe Carnuccio98aee702014-09-25 05:16:38 -04003609 nv->frame_payload_size = 2048;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 if (IS_QLA23XX(ha))
3611 nv->special_options[1] = BIT_7;
3612 }
3613#endif
3614
3615 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003616 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617
3618 /*
3619 * Setup driver NVRAM options.
3620 */
3621 nv->firmware_options[0] |= (BIT_6 | BIT_1);
3622 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
3623 nv->firmware_options[1] |= (BIT_5 | BIT_0);
3624 nv->firmware_options[1] &= ~BIT_4;
3625
3626 if (IS_QLA23XX(ha)) {
3627 nv->firmware_options[0] |= BIT_2;
3628 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003629 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003630 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631
3632 if (IS_QLA2300(ha)) {
3633 if (ha->fb_rev == FPM_2310) {
3634 strcpy(ha->model_number, "QLA2310");
3635 } else {
3636 strcpy(ha->model_number, "QLA2300");
3637 }
3638 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003639 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003640 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641 }
3642 } else if (IS_QLA2200(ha)) {
3643 nv->firmware_options[0] |= BIT_2;
3644 /*
3645 * 'Point-to-point preferred, else loop' is not a safe
3646 * connection mode setting.
3647 */
3648 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
3649 (BIT_5 | BIT_4)) {
3650 /* Force 'loop preferred, else point-to-point'. */
3651 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
3652 nv->add_firmware_options[0] |= BIT_5;
3653 }
3654 strcpy(ha->model_number, "QLA22xx");
3655 } else /*if (IS_QLA2100(ha))*/ {
3656 strcpy(ha->model_number, "QLA2100");
3657 }
3658
3659 /*
3660 * Copy over NVRAM RISC parameter block to initialization control block.
3661 */
3662 dptr1 = (uint8_t *)icb;
3663 dptr2 = (uint8_t *)&nv->parameter_block_version;
3664 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
3665 while (cnt--)
3666 *dptr1++ = *dptr2++;
3667
3668 /* Copy 2nd half. */
3669 dptr1 = (uint8_t *)icb->add_firmware_options;
3670 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
3671 while (cnt--)
3672 *dptr1++ = *dptr2++;
3673
Andrew Vasquez5341e862006-05-17 15:09:16 -07003674 /* Use alternate WWN? */
3675 if (nv->host_p[1] & BIT_7) {
3676 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3677 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3678 }
3679
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680 /* Prepare nodename */
3681 if ((icb->firmware_options[1] & BIT_6) == 0) {
3682 /*
3683 * Firmware will apply the following mask if the nodename was
3684 * not provided.
3685 */
3686 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3687 icb->node_name[0] &= 0xF0;
3688 }
3689
3690 /*
3691 * Set host adapter parameters.
3692 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07003693
3694 /*
3695 * BIT_7 in the host-parameters section allows for modification to
3696 * internal driver logging.
3697 */
Andrew Vasquez01819442006-06-23 16:11:10 -07003698 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08003699 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
3701 /* Always load RISC code on non ISP2[12]00 chips. */
3702 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
3703 ha->flags.disable_risc_code_load = 0;
3704 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
3705 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
3706 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07003707 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003708 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709
3710 ha->operating_mode =
3711 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
3712
3713 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
3714 sizeof(ha->fw_seriallink_options));
3715
3716 /* save HBA serial number */
3717 ha->serial0 = icb->port_name[5];
3718 ha->serial1 = icb->port_name[6];
3719 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003720 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3721 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722
Bart Van Asschead950362015-07-09 07:24:08 -07003723 icb->execution_throttle = cpu_to_le16(0xFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724
3725 ha->retry_count = nv->retry_count;
3726
3727 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07003728 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729 nv->login_timeout = ql2xlogintimeout;
3730 if (nv->login_timeout < 4)
3731 nv->login_timeout = 4;
3732 ha->login_timeout = nv->login_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003734 /* Set minimum RATOV to 100 tenths of a second. */
3735 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 ha->loop_reset_delay = nv->reset_delay;
3738
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 /* Link Down Timeout = 0:
3740 *
3741 * When Port Down timer expires we will start returning
3742 * I/O's to OS with "DID_NO_CONNECT".
3743 *
3744 * Link Down Timeout != 0:
3745 *
3746 * The driver waits for the link to come up after link down
3747 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003748 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 if (nv->link_down_timeout == 0) {
3750 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003751 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 } else {
3753 ha->link_down_timeout = nv->link_down_timeout;
3754 ha->loop_down_abort_time =
3755 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003756 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758 /*
3759 * Need enough time to try and get the port back.
3760 */
3761 ha->port_down_retry_count = nv->port_down_retry_count;
3762 if (qlport_down_retry)
3763 ha->port_down_retry_count = qlport_down_retry;
3764 /* Set login_retry_count */
3765 ha->login_retry_count = nv->retry_count;
3766 if (ha->port_down_retry_count == nv->port_down_retry_count &&
3767 ha->port_down_retry_count > 3)
3768 ha->login_retry_count = ha->port_down_retry_count;
3769 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3770 ha->login_retry_count = ha->port_down_retry_count;
3771 if (ql2xloginretrycount)
3772 ha->login_retry_count = ql2xloginretrycount;
3773
Bart Van Asschead950362015-07-09 07:24:08 -07003774 icb->lun_enables = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 icb->command_resource_count = 0;
3776 icb->immediate_notify_resource_count = 0;
Bart Van Asschead950362015-07-09 07:24:08 -07003777 icb->timeout = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778
3779 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3780 /* Enable RIO */
3781 icb->firmware_options[0] &= ~BIT_3;
3782 icb->add_firmware_options[0] &=
3783 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
3784 icb->add_firmware_options[0] |= BIT_2;
3785 icb->response_accumulation_timer = 3;
3786 icb->interrupt_delay_timer = 5;
3787
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003788 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003790 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003791 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003792 ha->zio_mode = icb->add_firmware_options[0] &
3793 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3794 ha->zio_timer = icb->interrupt_delay_timer ?
3795 icb->interrupt_delay_timer: 2;
3796 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797 icb->add_firmware_options[0] &=
3798 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003799 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003800 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003801 ha->zio_mode = QLA_ZIO_MODE_6;
3802
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003803 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003804 "ZIO mode %d enabled; timer delay (%d us).\n",
3805 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003807 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
3808 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003809 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 }
3811 }
3812
David Miller4e08df32007-04-16 12:37:43 -07003813 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003814 ql_log(ql_log_warn, vha, 0x0069,
3815 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07003816 }
3817 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818}
3819
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003820static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003821qla2x00_rport_del(void *data)
3822{
3823 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003824 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003825 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003826
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003827 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07003828 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003829 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003830 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08003831 if (rport) {
3832 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
3833 "%s %8phN. rport %p roles %x \n",
3834 __func__, fcport->port_name, rport,
3835 rport->roles);
3836
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003837 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08003838 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003839}
3840
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841/**
3842 * qla2x00_alloc_fcport() - Allocate a generic fcport.
3843 * @ha: HA context
3844 * @flags: allocation flags
3845 *
3846 * Returns a pointer to the allocated fcport, or NULL, if none available.
3847 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003848fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003849qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850{
3851 fc_port_t *fcport;
3852
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003853 fcport = kzalloc(sizeof(fc_port_t), flags);
3854 if (!fcport)
3855 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856
3857 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003858 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 fcport->port_type = FCT_UNKNOWN;
3860 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07003861 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003862 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863
Quinn Tran726b8542017-01-19 22:28:00 -08003864 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
3865 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
3866 GFP_ATOMIC);
3867 fcport->disc_state = DSC_DELETED;
3868 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
3869 fcport->deleted = QLA_SESS_DELETED;
3870 fcport->login_retry = vha->hw->login_retry_count;
3871 fcport->login_retry = 5;
3872 fcport->logout_on_delete = 1;
3873
3874 if (!fcport->ct_desc.ct_sns) {
3875 ql_log(ql_log_warn, vha, 0xffff,
3876 "Failed to allocate ct_sns request.\n");
3877 kfree(fcport);
3878 fcport = NULL;
3879 }
3880 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
3881 INIT_LIST_HEAD(&fcport->gnl_entry);
3882 INIT_LIST_HEAD(&fcport->list);
3883
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003884 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885}
3886
Quinn Tran726b8542017-01-19 22:28:00 -08003887void
3888qla2x00_free_fcport(fc_port_t *fcport)
3889{
3890 if (fcport->ct_desc.ct_sns) {
3891 dma_free_coherent(&fcport->vha->hw->pdev->dev,
3892 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
3893 fcport->ct_desc.ct_sns_dma);
3894
3895 fcport->ct_desc.ct_sns = NULL;
3896 }
3897 kfree(fcport);
3898}
3899
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900/*
3901 * qla2x00_configure_loop
3902 * Updates Fibre Channel Device Database with what is actually on loop.
3903 *
3904 * Input:
3905 * ha = adapter block pointer.
3906 *
3907 * Returns:
3908 * 0 = success.
3909 * 1 = error.
3910 * 2 = database was full and device was not configured.
3911 */
3912static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003913qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914{
3915 int rval;
3916 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003917 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 rval = QLA_SUCCESS;
3919
3920 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003921 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
3922 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003924 ql_dbg(ql_dbg_disc, vha, 0x2013,
3925 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 return (rval);
3927 }
3928 }
3929
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003930 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003931 ql_dbg(ql_dbg_disc, vha, 0x2014,
3932 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933
3934 /*
3935 * If we have both an RSCN and PORT UPDATE pending then handle them
3936 * both at the same time.
3937 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003938 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3939 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940
Michael Hernandez3064ff32009-12-15 21:29:44 -08003941 qla2x00_get_data_rate(vha);
3942
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 /* Determine what we need to do */
3944 if (ha->current_topology == ISP_CFG_FL &&
3945 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
3946
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947 set_bit(RSCN_UPDATE, &flags);
3948
3949 } else if (ha->current_topology == ISP_CFG_F &&
3950 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
3951
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 set_bit(RSCN_UPDATE, &flags);
3953 clear_bit(LOCAL_LOOP_UPDATE, &flags);
3954
Andrew Vasquez21333b42006-05-17 15:09:56 -07003955 } else if (ha->current_topology == ISP_CFG_N) {
3956 clear_bit(RSCN_UPDATE, &flags);
3957
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003958 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
3960
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961 set_bit(RSCN_UPDATE, &flags);
3962 set_bit(LOCAL_LOOP_UPDATE, &flags);
3963 }
3964
3965 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003966 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
3967 ql_dbg(ql_dbg_disc, vha, 0x2015,
3968 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08003970 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003971 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 }
3973
3974 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003975 if (LOOP_TRANSITION(vha)) {
3976 ql_dbg(ql_dbg_disc, vha, 0x201e,
3977 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003979 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003980 else
3981 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 }
3983
3984 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003985 if (atomic_read(&vha->loop_down_timer) ||
3986 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 rval = QLA_FUNCTION_FAILED;
3988 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003989 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003990 ql_dbg(ql_dbg_disc, vha, 0x2069,
3991 "LOOP READY.\n");
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05003992
3993 /*
3994 * Process any ATIO queue entries that came in
3995 * while we weren't online.
3996 */
3997 if (qla_tgt_mode_enabled(vha)) {
3998 if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) {
3999 spin_lock_irqsave(&ha->tgt.atio_lock,
4000 flags);
4001 qlt_24xx_process_atio_queue(vha, 0);
4002 spin_unlock_irqrestore(
4003 &ha->tgt.atio_lock, flags);
4004 } else {
4005 spin_lock_irqsave(&ha->hardware_lock,
4006 flags);
4007 qlt_24xx_process_atio_queue(vha, 1);
4008 spin_unlock_irqrestore(
4009 &ha->hardware_lock, flags);
4010 }
4011 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 }
4013 }
4014
4015 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004016 ql_dbg(ql_dbg_disc, vha, 0x206a,
4017 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004019 ql_dbg(ql_dbg_disc, vha, 0x206b,
4020 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021 }
4022
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07004023 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004024 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004026 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004027 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004028 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004029 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 }
4031
4032 return (rval);
4033}
4034
4035
4036
4037/*
4038 * qla2x00_configure_local_loop
4039 * Updates Fibre Channel Device Database with local loop devices.
4040 *
4041 * Input:
4042 * ha = adapter block pointer.
4043 *
4044 * Returns:
4045 * 0 = success.
4046 */
4047static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004048qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049{
4050 int rval, rval2;
4051 int found_devs;
4052 int found;
4053 fc_port_t *fcport, *new_fcport;
4054
4055 uint16_t index;
4056 uint16_t entries;
4057 char *id_iter;
4058 uint16_t loop_id;
4059 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004060 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061
4062 found_devs = 0;
4063 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08004064 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08004067 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004068 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069 &entries);
4070 if (rval != QLA_SUCCESS)
4071 goto cleanup_allocation;
4072
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004073 ql_dbg(ql_dbg_disc, vha, 0x2017,
4074 "Entries in ID list (%d).\n", entries);
4075 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
4076 (uint8_t *)ha->gid_list,
4077 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078
4079 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004080 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004082 ql_log(ql_log_warn, vha, 0x2018,
4083 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 rval = QLA_MEMORY_ALLOC_FAILED;
4085 goto cleanup_allocation;
4086 }
4087 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4088
4089 /*
4090 * Mark local devices that were present with FCF_DEVICE_LOST for now.
4091 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004092 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093 if (atomic_read(&fcport->state) == FCS_ONLINE &&
4094 fcport->port_type != FCT_BROADCAST &&
4095 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
4096
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004097 ql_dbg(ql_dbg_disc, vha, 0x2019,
4098 "Marking port lost loop_id=0x%04x.\n",
4099 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100
Chad Dupuisec426e12011-03-30 11:46:32 -07004101 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102 }
4103 }
4104
4105 /* Add devices to port list. */
4106 id_iter = (char *)ha->gid_list;
4107 for (index = 0; index < entries; index++) {
4108 domain = ((struct gid_list_info *)id_iter)->domain;
4109 area = ((struct gid_list_info *)id_iter)->area;
4110 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004111 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 loop_id = (uint16_t)
4113 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004114 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115 loop_id = le16_to_cpu(
4116 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004117 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118
4119 /* Bypass reserved domain fields. */
4120 if ((domain & 0xf0) == 0xf0)
4121 continue;
4122
4123 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004124 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004125 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126 continue;
4127
4128 /* Bypass invalid local loop ID. */
4129 if (loop_id > LAST_LOCAL_LOOP_ID)
4130 continue;
4131
Arun Easi370d5502012-08-22 14:21:10 -04004132 memset(new_fcport, 0, sizeof(fc_port_t));
4133
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 /* Fill in member data. */
4135 new_fcport->d_id.b.domain = domain;
4136 new_fcport->d_id.b.area = area;
4137 new_fcport->d_id.b.al_pa = al_pa;
4138 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004139 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004141 ql_dbg(ql_dbg_disc, vha, 0x201a,
4142 "Failed to retrieve fcport information "
4143 "-- get_port_database=%x, loop_id=0x%04x.\n",
4144 rval2, new_fcport->loop_id);
4145 ql_dbg(ql_dbg_disc, vha, 0x201b,
4146 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004147 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148 continue;
4149 }
4150
4151 /* Check for matching device in port list. */
4152 found = 0;
4153 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004154 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155 if (memcmp(new_fcport->port_name, fcport->port_name,
4156 WWN_SIZE))
4157 continue;
4158
Shyam Sundarddb9b122009-03-24 09:08:10 -07004159 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 fcport->loop_id = new_fcport->loop_id;
4161 fcport->port_type = new_fcport->port_type;
4162 fcport->d_id.b24 = new_fcport->d_id.b24;
4163 memcpy(fcport->node_name, new_fcport->node_name,
4164 WWN_SIZE);
4165
4166 found++;
4167 break;
4168 }
4169
4170 if (!found) {
4171 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004172 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173
4174 /* Allocate a new replacement fcport. */
4175 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004176 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004178 ql_log(ql_log_warn, vha, 0x201c,
4179 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180 rval = QLA_MEMORY_ALLOC_FAILED;
4181 goto cleanup_allocation;
4182 }
4183 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4184 }
4185
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004186 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004187 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004188
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004189 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190
4191 found_devs++;
4192 }
4193
4194cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08004195 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196
4197 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004198 ql_dbg(ql_dbg_disc, vha, 0x201d,
4199 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200 }
4201
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202 return (rval);
4203}
4204
4205static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004206qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004207{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004208 int rval;
Quinn Tran93f2bd62014-09-25 05:16:53 -04004209 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004210 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004211
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07004212 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004213 return;
4214
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07004215 if (atomic_read(&fcport->state) != FCS_ONLINE)
4216 return;
4217
Andrew Vasquez39bd9622007-09-20 14:07:34 -07004218 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
4219 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004220 return;
4221
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004222 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004223 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004224 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004225 ql_dbg(ql_dbg_disc, vha, 0x2004,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004226 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
4227 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004228 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004229 ql_dbg(ql_dbg_disc, vha, 0x2005,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004230 "iIDMA adjusted to %s GB/s on %8phN.\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -05004231 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04004232 fcport->port_name);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004233 }
4234}
4235
Quinn Tran726b8542017-01-19 22:28:00 -08004236/* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
Adrian Bunk23be3312006-11-24 02:46:01 +01004237static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004238qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05004239{
4240 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05004241 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004242 unsigned long flags;
8482e1182005-04-17 15:04:54 -05004243
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07004244 rport_ids.node_name = wwn_to_u64(fcport->node_name);
4245 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05004246 rport_ids.port_id = fcport->d_id.b.domain << 16 |
4247 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
4248 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004249 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07004250 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004251 ql_log(ql_log_warn, vha, 0x2006,
4252 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07004253 return;
4254 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004255
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004256 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004257 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004258 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004259
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004260 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07004261
4262 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05004263 if (fcport->port_type == FCT_INITIATOR)
4264 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
4265 if (fcport->port_type == FCT_TARGET)
4266 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Quinn Tran726b8542017-01-19 22:28:00 -08004267
4268 ql_dbg(ql_dbg_disc, vha, 0xffff,
4269 "%s %8phN. rport %p is %s mode \n",
4270 __func__, fcport->port_name, rport,
4271 (fcport->port_type == FCT_TARGET) ? "tgt" : "ini");
4272
Andrew Vasquez77d74142005-07-08 18:00:36 -07004273 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05004274}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275
4276/*
Adrian Bunk23be3312006-11-24 02:46:01 +01004277 * qla2x00_update_fcport
4278 * Updates device on list.
4279 *
4280 * Input:
4281 * ha = adapter block pointer.
4282 * fcport = port structure pointer.
4283 *
4284 * Return:
4285 * 0 - Success
4286 * BIT_0 - error
4287 *
4288 * Context:
4289 * Kernel context.
4290 */
4291void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004292qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01004293{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004294 fcport->vha = vha;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004295
Quinn Tran726b8542017-01-19 22:28:00 -08004296 if (IS_SW_RESV_ADDR(fcport->d_id))
4297 return;
4298
4299 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %8phC \n",
4300 __func__, fcport->port_name);
4301
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004302 if (IS_QLAFX00(vha->hw)) {
4303 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004304 goto reg_port;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004305 }
Adrian Bunk23be3312006-11-24 02:46:01 +01004306 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004307 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Quinn Tran726b8542017-01-19 22:28:00 -08004308 fcport->disc_state = DSC_LOGIN_COMPLETE;
4309 fcport->deleted = 0;
4310 fcport->logout_on_delete = 1;
Adrian Bunk23be3312006-11-24 02:46:01 +01004311
Joe Carnuccio1f93da522012-11-21 02:40:38 -05004312 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004313 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08004314 qla24xx_update_fcport_fcp_prio(vha, fcport);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004315
4316reg_port:
Quinn Tran726b8542017-01-19 22:28:00 -08004317 switch (vha->host->active_mode) {
4318 case MODE_INITIATOR:
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004319 qla2x00_reg_remote_port(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08004320 break;
4321 case MODE_TARGET:
4322 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
4323 !vha->vha_tgt.qla_tgt->tgt_stopped)
4324 qlt_fc_port_added(vha, fcport);
4325 break;
4326 case MODE_DUAL:
4327 qla2x00_reg_remote_port(vha, fcport);
4328 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
4329 !vha->vha_tgt.qla_tgt->tgt_stopped)
4330 qlt_fc_port_added(vha, fcport);
4331 break;
4332 default:
4333 break;
4334 }
Adrian Bunk23be3312006-11-24 02:46:01 +01004335}
4336
4337/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338 * qla2x00_configure_fabric
4339 * Setup SNS devices with loop ID's.
4340 *
4341 * Input:
4342 * ha = adapter block pointer.
4343 *
4344 * Returns:
4345 * 0 = success.
4346 * BIT_0 = error
4347 */
4348static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004349qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350{
Arun Easib3b02e62012-02-09 11:15:39 -08004351 int rval;
Quinn Tran726b8542017-01-19 22:28:00 -08004352 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004354 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004356 struct qla_hw_data *ha = vha->hw;
Alexei Potashnikdf673272015-07-14 16:00:46 -04004357 int discovery_gen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004358
4359 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07004360 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004361 loop_id = NPH_F_PORT;
4362 else
4363 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004364 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004366 ql_dbg(ql_dbg_disc, vha, 0x201f,
4367 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004369 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004370 return (QLA_SUCCESS);
4371 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004372 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373
Linus Torvalds1da177e2005-04-16 15:20:36 -07004374 do {
Quinn Tran726b8542017-01-19 22:28:00 -08004375 qla2x00_mgmt_svr_login(vha);
4376
Andrew Vasquezcca53352005-08-26 19:08:30 -07004377 /* FDMI support. */
4378 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004379 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
4380 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07004381
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07004383 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004384 loop_id = NPH_SNS;
4385 else
4386 loop_id = SIMPLE_NAME_SERVER;
Chad Dupuis0b91d112012-02-09 11:15:42 -08004387 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
4388 0xfc, mb, BIT_1|BIT_0);
4389 if (rval != QLA_SUCCESS) {
4390 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05004391 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08004392 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004394 ql_dbg(ql_dbg_disc, vha, 0x2042,
4395 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
4396 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
4397 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398 return (QLA_SUCCESS);
4399 }
4400
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004401 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
4402 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004403 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004404 ql_dbg(ql_dbg_disc, vha, 0x2045,
4405 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004407 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004409 ql_dbg(ql_dbg_disc, vha, 0x2049,
4410 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004412 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004414 ql_dbg(ql_dbg_disc, vha, 0x204f,
4415 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004416 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004418 ql_dbg(ql_dbg_disc, vha, 0x2053,
4419 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420 }
4421 }
4422
Joe Carnuccio827210b2013-02-08 01:57:57 -05004423 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4424 fcport->scan_state = QLA_FCPORT_SCAN;
4425 }
4426
Alexei Potashnikdf673272015-07-14 16:00:46 -04004427 /* Mark the time right before querying FW for connected ports.
4428 * This process is long, asynchronous and by the time it's done,
4429 * collected information might not be accurate anymore. E.g.
4430 * disconnected port might have re-connected and a brand new
4431 * session has been created. In this case session's generation
4432 * will be newer than discovery_gen. */
4433 qlt_do_generation_tick(vha, &discovery_gen);
4434
Quinn Tran726b8542017-01-19 22:28:00 -08004435 rval = qla2x00_find_all_fabric_devs(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004436 if (rval != QLA_SUCCESS)
4437 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 } while (0);
4439
Quinn Tran726b8542017-01-19 22:28:00 -08004440 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004441 ql_dbg(ql_dbg_disc, vha, 0x2068,
4442 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443
4444 return (rval);
4445}
4446
Linus Torvalds1da177e2005-04-16 15:20:36 -07004447/*
4448 * qla2x00_find_all_fabric_devs
4449 *
4450 * Input:
4451 * ha = adapter block pointer.
4452 * dev = database device entry pointer.
4453 *
4454 * Returns:
4455 * 0 = success.
4456 *
4457 * Context:
4458 * Kernel context.
4459 */
4460static int
Quinn Tran726b8542017-01-19 22:28:00 -08004461qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462{
4463 int rval;
4464 uint16_t loop_id;
Quinn Tran726b8542017-01-19 22:28:00 -08004465 fc_port_t *fcport, *new_fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004466 int found;
4467
4468 sw_info_t *swl;
4469 int swl_idx;
4470 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07004471 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004472 struct qla_hw_data *ha = vha->hw;
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05004473 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran726b8542017-01-19 22:28:00 -08004474 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004475
4476 rval = QLA_SUCCESS;
4477
4478 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08004479 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08004480 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08004481 GFP_KERNEL);
4482 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004483 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004484 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004485 ql_dbg(ql_dbg_disc, vha, 0x2054,
4486 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004487 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08004488 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004489 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004491 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004492 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004493 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004494 swl = NULL;
Quinn Tran726b8542017-01-19 22:28:00 -08004495 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
4496 swl = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004498
4499 /* If other queries succeeded probe for FC-4 type */
4500 if (swl)
4501 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502 }
4503 swl_idx = 0;
4504
4505 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004506 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004508 ql_log(ql_log_warn, vha, 0x205e,
4509 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510 return (QLA_MEMORY_ALLOC_FAILED);
4511 }
4512 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004513 /* Set start port ID scan at adapter ID. */
4514 first_dev = 1;
4515 last_dev = 0;
4516
4517 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004518 loop_id = ha->min_external_loopid;
4519 for (; loop_id <= ha->max_loop_id; loop_id++) {
4520 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521 continue;
4522
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07004523 if (ha->current_topology == ISP_CFG_FL &&
4524 (atomic_read(&vha->loop_down_timer) ||
4525 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08004526 atomic_set(&vha->loop_down_timer, 0);
4527 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4528 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08004530 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004531
4532 if (swl != NULL) {
4533 if (last_dev) {
4534 wrap.b24 = new_fcport->d_id.b24;
4535 } else {
4536 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
4537 memcpy(new_fcport->node_name,
4538 swl[swl_idx].node_name, WWN_SIZE);
4539 memcpy(new_fcport->port_name,
4540 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004541 memcpy(new_fcport->fabric_port_name,
4542 swl[swl_idx].fabric_port_name, WWN_SIZE);
4543 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004544 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545
4546 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
4547 last_dev = 1;
4548 }
4549 swl_idx++;
4550 }
4551 } else {
4552 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004553 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004554 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004555 ql_log(ql_log_warn, vha, 0x2064,
4556 "SNS scan failed -- assuming "
4557 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004558 rval = QLA_SUCCESS;
4559 break;
4560 }
4561 }
4562
4563 /* If wrap on switch device list, exit. */
4564 if (first_dev) {
4565 wrap.b24 = new_fcport->d_id.b24;
4566 first_dev = 0;
4567 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004568 ql_dbg(ql_dbg_disc, vha, 0x2065,
4569 "Device wrap (%02x%02x%02x).\n",
4570 new_fcport->d_id.b.domain,
4571 new_fcport->d_id.b.area,
4572 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004573 break;
4574 }
4575
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004576 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004577 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004578 continue;
4579
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004580 /* Bypass virtual ports of the same host. */
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05004581 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
4582 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004583
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004584 /* Bypass if same domain and area of adapter. */
4585 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004586 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004587 ISP_CFG_FL)
4588 continue;
4589
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590 /* Bypass reserved domain fields. */
4591 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
4592 continue;
4593
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004594 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07004595 if (ql2xgffidenable &&
4596 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
4597 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004598 continue;
4599
Quinn Tran726b8542017-01-19 22:28:00 -08004600 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4601
Linus Torvalds1da177e2005-04-16 15:20:36 -07004602 /* Locate matching device in database. */
4603 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004604 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004605 if (memcmp(new_fcport->port_name, fcport->port_name,
4606 WWN_SIZE))
4607 continue;
4608
Joe Carnuccio827210b2013-02-08 01:57:57 -05004609 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08004610
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611 found++;
4612
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004613 /* Update port state. */
4614 memcpy(fcport->fabric_port_name,
4615 new_fcport->fabric_port_name, WWN_SIZE);
4616 fcport->fp_speed = new_fcport->fp_speed;
4617
Linus Torvalds1da177e2005-04-16 15:20:36 -07004618 /*
Roland Dreierb2032fd2015-07-14 16:00:42 -04004619 * If address the same and state FCS_ONLINE
4620 * (or in target mode), nothing changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004621 */
4622 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
Roland Dreierb2032fd2015-07-14 16:00:42 -04004623 (atomic_read(&fcport->state) == FCS_ONLINE ||
Quinn Tran726b8542017-01-19 22:28:00 -08004624 (vha->host->active_mode == MODE_TARGET))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625 break;
4626 }
4627
4628 /*
4629 * If device was not a fabric device before.
4630 */
4631 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
4632 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04004633 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634 fcport->flags |= (FCF_FABRIC_DEVICE |
4635 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004636 break;
4637 }
4638
4639 /*
4640 * Port ID changed or device was marked to be updated;
4641 * Log it out if still logged in and mark it for
4642 * relogin later.
4643 */
Quinn Tran726b8542017-01-19 22:28:00 -08004644 if (qla_tgt_mode_enabled(base_vha)) {
Roland Dreierb2032fd2015-07-14 16:00:42 -04004645 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
4646 "port changed FC ID, %8phC"
4647 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
4648 fcport->port_name,
4649 fcport->d_id.b.domain,
4650 fcport->d_id.b.area,
4651 fcport->d_id.b.al_pa,
4652 fcport->loop_id,
4653 new_fcport->d_id.b.domain,
4654 new_fcport->d_id.b.area,
4655 new_fcport->d_id.b.al_pa);
4656 fcport->d_id.b24 = new_fcport->d_id.b24;
4657 break;
4658 }
4659
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 fcport->d_id.b24 = new_fcport->d_id.b24;
4661 fcport->flags |= FCF_LOGIN_NEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 break;
4663 }
4664
Quinn Tran726b8542017-01-19 22:28:00 -08004665 if (found) {
4666 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004667 continue;
Quinn Tran726b8542017-01-19 22:28:00 -08004668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004669 /* If device was not in our fcports list, then add it. */
Roland Dreierb2032fd2015-07-14 16:00:42 -04004670 new_fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tran726b8542017-01-19 22:28:00 -08004671 list_add_tail(&new_fcport->list, &vha->vp_fcports);
4672
4673 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4674
Linus Torvalds1da177e2005-04-16 15:20:36 -07004675
4676 /* Allocate a new replacement fcport. */
4677 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004678 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004679 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004680 ql_log(ql_log_warn, vha, 0x2066,
4681 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682 return (QLA_MEMORY_ALLOC_FAILED);
4683 }
4684 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
4685 new_fcport->d_id.b24 = nxt_d_id.b24;
4686 }
4687
Quinn Tran726b8542017-01-19 22:28:00 -08004688 qla2x00_free_fcport(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004689
Quinn Tran726b8542017-01-19 22:28:00 -08004690 /*
4691 * Logout all previous fabric dev marked lost, except FCP2 devices.
4692 */
4693 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4694 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4695 break;
4696
4697 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
4698 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
4699 continue;
4700
4701 if (fcport->scan_state == QLA_FCPORT_SCAN) {
4702 if ((qla_dual_mode_enabled(vha) ||
4703 qla_ini_mode_enabled(vha)) &&
4704 atomic_read(&fcport->state) == FCS_ONLINE) {
4705 qla2x00_mark_device_lost(vha, fcport,
4706 ql2xplogiabsentdevice, 0);
4707 if (fcport->loop_id != FC_NO_LOOP_ID &&
4708 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
4709 fcport->port_type != FCT_INITIATOR &&
4710 fcport->port_type != FCT_BROADCAST) {
4711 ql_dbg(ql_dbg_disc, vha, 0xffff,
4712 "%s %d %8phC post del sess\n",
4713 __func__, __LINE__,
4714 fcport->port_name);
4715
4716 qlt_schedule_sess_for_deletion_lock
4717 (fcport);
4718 continue;
4719 }
4720 }
4721 }
4722
4723 if (fcport->scan_state == QLA_FCPORT_FOUND)
4724 qla24xx_fcport_handle_login(vha, fcport);
4725 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726 return (rval);
4727}
4728
4729/*
4730 * qla2x00_find_new_loop_id
4731 * Scan through our port list and find a new usable loop ID.
4732 *
4733 * Input:
4734 * ha: adapter state pointer.
4735 * dev: port structure pointer.
4736 *
4737 * Returns:
4738 * qla2x00 local function return status code.
4739 *
4740 * Context:
4741 * Kernel context.
4742 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07004743int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004744qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745{
4746 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004747 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07004748 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749
4750 rval = QLA_SUCCESS;
4751
Chad Dupuis5f16b332012-08-22 14:21:00 -04004752 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004753
Chad Dupuis5f16b332012-08-22 14:21:00 -04004754 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
4755 LOOPID_MAP_SIZE);
4756 if (dev->loop_id >= LOOPID_MAP_SIZE ||
4757 qla2x00_is_reserved_id(vha, dev->loop_id)) {
4758 dev->loop_id = FC_NO_LOOP_ID;
4759 rval = QLA_FUNCTION_FAILED;
4760 } else
4761 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762
Chad Dupuis5f16b332012-08-22 14:21:00 -04004763 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004764
Chad Dupuis5f16b332012-08-22 14:21:00 -04004765 if (rval == QLA_SUCCESS)
4766 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
4767 "Assigning new loopid=%x, portid=%x.\n",
4768 dev->loop_id, dev->d_id.b24);
4769 else
4770 ql_log(ql_log_warn, dev->vha, 0x2087,
4771 "No loop_id's available, portid=%x.\n",
4772 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004773
4774 return (rval);
4775}
4776
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777
4778/*
4779 * qla2x00_fabric_login
4780 * Issue fabric login command.
4781 *
4782 * Input:
4783 * ha = adapter block pointer.
4784 * device = pointer to FC device type structure.
4785 *
4786 * Returns:
4787 * 0 - Login successfully
4788 * 1 - Login failed
4789 * 2 - Initiator device
4790 * 3 - Fatal error
4791 */
4792int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004793qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794 uint16_t *next_loopid)
4795{
4796 int rval;
4797 int retry;
4798 uint16_t tmp_loopid;
4799 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004800 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801
4802 retry = 0;
4803 tmp_loopid = 0;
4804
4805 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004806 ql_dbg(ql_dbg_disc, vha, 0x2000,
4807 "Trying Fabric Login w/loop id 0x%04x for port "
4808 "%02x%02x%02x.\n",
4809 fcport->loop_id, fcport->d_id.b.domain,
4810 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004811
4812 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08004813 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814 fcport->d_id.b.domain, fcport->d_id.b.area,
4815 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08004816 if (rval != QLA_SUCCESS) {
4817 return rval;
4818 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004819 if (mb[0] == MBS_PORT_ID_USED) {
4820 /*
4821 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004822 * recommends the driver perform an implicit login with
4823 * the specified ID again. The ID we just used is save
4824 * here so we return with an ID that can be tried by
4825 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826 */
4827 retry++;
4828 tmp_loopid = fcport->loop_id;
4829 fcport->loop_id = mb[1];
4830
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004831 ql_dbg(ql_dbg_disc, vha, 0x2001,
4832 "Fabric Login: port in use - next loop "
4833 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004834 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004835 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836
4837 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
4838 /*
4839 * Login succeeded.
4840 */
4841 if (retry) {
4842 /* A retry occurred before. */
4843 *next_loopid = tmp_loopid;
4844 } else {
4845 /*
4846 * No retry occurred before. Just increment the
4847 * ID value for next login.
4848 */
4849 *next_loopid = (fcport->loop_id + 1);
4850 }
4851
4852 if (mb[1] & BIT_0) {
4853 fcport->port_type = FCT_INITIATOR;
4854 } else {
4855 fcport->port_type = FCT_TARGET;
4856 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07004857 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858 }
4859 }
4860
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004861 if (mb[10] & BIT_0)
4862 fcport->supported_classes |= FC_COS_CLASS2;
4863 if (mb[10] & BIT_1)
4864 fcport->supported_classes |= FC_COS_CLASS3;
4865
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004866 if (IS_FWI2_CAPABLE(ha)) {
4867 if (mb[10] & BIT_7)
4868 fcport->flags |=
4869 FCF_CONF_COMP_SUPPORTED;
4870 }
4871
Linus Torvalds1da177e2005-04-16 15:20:36 -07004872 rval = QLA_SUCCESS;
4873 break;
4874 } else if (mb[0] == MBS_LOOP_ID_USED) {
4875 /*
4876 * Loop ID already used, try next loop ID.
4877 */
4878 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004879 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880 if (rval != QLA_SUCCESS) {
4881 /* Ran out of loop IDs to use */
4882 break;
4883 }
4884 } else if (mb[0] == MBS_COMMAND_ERROR) {
4885 /*
4886 * Firmware possibly timed out during login. If NO
4887 * retries are left to do then the device is declared
4888 * dead.
4889 */
4890 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004891 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07004892 fcport->d_id.b.domain, fcport->d_id.b.area,
4893 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004894 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895
4896 rval = 1;
4897 break;
4898 } else {
4899 /*
4900 * unrecoverable / not handled error
4901 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004902 ql_dbg(ql_dbg_disc, vha, 0x2002,
4903 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
4904 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
4905 fcport->d_id.b.area, fcport->d_id.b.al_pa,
4906 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004907
4908 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004909 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07004910 fcport->d_id.b.domain, fcport->d_id.b.area,
4911 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004912 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07004913 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004914
4915 rval = 3;
4916 break;
4917 }
4918 }
4919
4920 return (rval);
4921}
4922
4923/*
4924 * qla2x00_local_device_login
4925 * Issue local device login command.
4926 *
4927 * Input:
4928 * ha = adapter block pointer.
4929 * loop_id = loop id of device to login to.
4930 *
4931 * Returns (Where's the #define!!!!):
4932 * 0 - Login successfully
4933 * 1 - Login failed
4934 * 3 - Fatal error
4935 */
4936int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004937qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004938{
4939 int rval;
4940 uint16_t mb[MAILBOX_REGISTER_COUNT];
4941
4942 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004943 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004944 if (rval == QLA_SUCCESS) {
4945 /* Interrogate mailbox registers for any errors */
4946 if (mb[0] == MBS_COMMAND_ERROR)
4947 rval = 1;
4948 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
4949 /* device not in PCB table */
4950 rval = 3;
4951 }
4952
4953 return (rval);
4954}
4955
4956/*
4957 * qla2x00_loop_resync
4958 * Resync with fibre channel devices.
4959 *
4960 * Input:
4961 * ha = adapter block pointer.
4962 *
4963 * Returns:
4964 * 0 = success
4965 */
4966int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004967qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004968{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004969 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004970 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004971 struct req_que *req;
4972 struct rsp_que *rsp;
4973
Michael Hernandezd7459522016-12-12 14:40:07 -08004974 req = vha->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004975 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004976
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004977 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4978 if (vha->flags.online) {
4979 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4981 wait_time = 256;
4982 do {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004983 if (!IS_QLAFX00(vha->hw)) {
4984 /*
4985 * Issue a marker after FW becomes
4986 * ready.
4987 */
4988 qla2x00_marker(vha, req, rsp, 0, 0,
4989 MK_SYNC_ALL);
4990 vha->marker_needed = 0;
4991 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992
4993 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004994 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004995
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004996 if (IS_QLAFX00(vha->hw))
4997 qlafx00_configure_devices(vha);
4998 else
4999 qla2x00_configure_loop(vha);
5000
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005002 } while (!atomic_read(&vha->loop_down_timer) &&
5003 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5004 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
5005 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005007 }
5008
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005009 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005011
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005012 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005013 ql_dbg(ql_dbg_disc, vha, 0x206c,
5014 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005015
5016 return (rval);
5017}
5018
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005019/*
5020* qla2x00_perform_loop_resync
5021* Description: This function will set the appropriate flags and call
5022* qla2x00_loop_resync. If successful loop will be resynced
5023* Arguments : scsi_qla_host_t pointer
5024* returm : Success or Failure
5025*/
5026
5027int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
5028{
5029 int32_t rval = 0;
5030
5031 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
5032 /*Configure the flags so that resync happens properly*/
5033 atomic_set(&ha->loop_down_timer, 0);
5034 if (!(ha->device_flags & DFLG_NO_CABLE)) {
5035 atomic_set(&ha->loop_state, LOOP_UP);
5036 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
5037 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
5038 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
5039
5040 rval = qla2x00_loop_resync(ha);
5041 } else
5042 atomic_set(&ha->loop_state, LOOP_DEAD);
5043
5044 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
5045 }
5046
5047 return rval;
5048}
5049
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050void
Andrew Vasquez67becc02009-08-25 11:36:20 -07005051qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005052{
5053 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07005054 struct scsi_qla_host *vha;
5055 struct qla_hw_data *ha = base_vha->hw;
5056 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005057
Arun Easifeafb7b2010-09-03 14:57:00 -07005058 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005059 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07005060 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
5061 atomic_inc(&vha->vref_count);
5062 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08005063 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07005064 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
5065 spin_unlock_irqrestore(&ha->vport_slock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07005066 qla2x00_rport_del(fcport);
Alexei Potashnikdf673272015-07-14 16:00:46 -04005067
Arun Easifeafb7b2010-09-03 14:57:00 -07005068 spin_lock_irqsave(&ha->vport_slock, flags);
5069 }
5070 }
5071 atomic_dec(&vha->vref_count);
5072 }
5073 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005074}
5075
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005076/* Assumes idc_lock always held on entry */
5077void
5078qla83xx_reset_ownership(scsi_qla_host_t *vha)
5079{
5080 struct qla_hw_data *ha = vha->hw;
5081 uint32_t drv_presence, drv_presence_mask;
5082 uint32_t dev_part_info1, dev_part_info2, class_type;
5083 uint32_t class_type_mask = 0x3;
5084 uint16_t fcoe_other_function = 0xffff, i;
5085
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005086 if (IS_QLA8044(ha)) {
5087 drv_presence = qla8044_rd_direct(vha,
5088 QLA8044_CRB_DRV_ACTIVE_INDEX);
5089 dev_part_info1 = qla8044_rd_direct(vha,
5090 QLA8044_CRB_DEV_PART_INFO_INDEX);
5091 dev_part_info2 = qla8044_rd_direct(vha,
5092 QLA8044_CRB_DEV_PART_INFO2);
5093 } else {
5094 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5095 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
5096 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
5097 }
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005098 for (i = 0; i < 8; i++) {
5099 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
5100 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5101 (i != ha->portnum)) {
5102 fcoe_other_function = i;
5103 break;
5104 }
5105 }
5106 if (fcoe_other_function == 0xffff) {
5107 for (i = 0; i < 8; i++) {
5108 class_type = ((dev_part_info2 >> (i * 4)) &
5109 class_type_mask);
5110 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5111 ((i + 8) != ha->portnum)) {
5112 fcoe_other_function = i + 8;
5113 break;
5114 }
5115 }
5116 }
5117 /*
5118 * Prepare drv-presence mask based on fcoe functions present.
5119 * However consider only valid physical fcoe function numbers (0-15).
5120 */
5121 drv_presence_mask = ~((1 << (ha->portnum)) |
5122 ((fcoe_other_function == 0xffff) ?
5123 0 : (1 << (fcoe_other_function))));
5124
5125 /* We are the reset owner iff:
5126 * - No other protocol drivers present.
5127 * - This is the lowest among fcoe functions. */
5128 if (!(drv_presence & drv_presence_mask) &&
5129 (ha->portnum < fcoe_other_function)) {
5130 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
5131 "This host is Reset owner.\n");
5132 ha->flags.nic_core_reset_owner = 1;
5133 }
5134}
5135
Saurav Kashyapfa492632012-11-21 02:40:29 -05005136static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005137__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
5138{
5139 int rval = QLA_SUCCESS;
5140 struct qla_hw_data *ha = vha->hw;
5141 uint32_t drv_ack;
5142
5143 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5144 if (rval == QLA_SUCCESS) {
5145 drv_ack |= (1 << ha->portnum);
5146 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5147 }
5148
5149 return rval;
5150}
5151
Saurav Kashyapfa492632012-11-21 02:40:29 -05005152static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005153__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
5154{
5155 int rval = QLA_SUCCESS;
5156 struct qla_hw_data *ha = vha->hw;
5157 uint32_t drv_ack;
5158
5159 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5160 if (rval == QLA_SUCCESS) {
5161 drv_ack &= ~(1 << ha->portnum);
5162 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5163 }
5164
5165 return rval;
5166}
5167
Saurav Kashyapfa492632012-11-21 02:40:29 -05005168static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005169qla83xx_dev_state_to_string(uint32_t dev_state)
5170{
5171 switch (dev_state) {
5172 case QLA8XXX_DEV_COLD:
5173 return "COLD/RE-INIT";
5174 case QLA8XXX_DEV_INITIALIZING:
5175 return "INITIALIZING";
5176 case QLA8XXX_DEV_READY:
5177 return "READY";
5178 case QLA8XXX_DEV_NEED_RESET:
5179 return "NEED RESET";
5180 case QLA8XXX_DEV_NEED_QUIESCENT:
5181 return "NEED QUIESCENT";
5182 case QLA8XXX_DEV_FAILED:
5183 return "FAILED";
5184 case QLA8XXX_DEV_QUIESCENT:
5185 return "QUIESCENT";
5186 default:
5187 return "Unknown";
5188 }
5189}
5190
5191/* Assumes idc-lock always held on entry */
5192void
5193qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
5194{
5195 struct qla_hw_data *ha = vha->hw;
5196 uint32_t idc_audit_reg = 0, duration_secs = 0;
5197
5198 switch (audit_type) {
5199 case IDC_AUDIT_TIMESTAMP:
5200 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
5201 idc_audit_reg = (ha->portnum) |
5202 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
5203 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5204 break;
5205
5206 case IDC_AUDIT_COMPLETION:
5207 duration_secs = ((jiffies_to_msecs(jiffies) -
5208 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
5209 idc_audit_reg = (ha->portnum) |
5210 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
5211 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5212 break;
5213
5214 default:
5215 ql_log(ql_log_warn, vha, 0xb078,
5216 "Invalid audit type specified.\n");
5217 break;
5218 }
5219}
5220
5221/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05005222static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005223qla83xx_initiating_reset(scsi_qla_host_t *vha)
5224{
5225 struct qla_hw_data *ha = vha->hw;
5226 uint32_t idc_control, dev_state;
5227
5228 __qla83xx_get_idc_control(vha, &idc_control);
5229 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
5230 ql_log(ql_log_info, vha, 0xb080,
5231 "NIC Core reset has been disabled. idc-control=0x%x\n",
5232 idc_control);
5233 return QLA_FUNCTION_FAILED;
5234 }
5235
5236 /* Set NEED-RESET iff in READY state and we are the reset-owner */
5237 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5238 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
5239 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
5240 QLA8XXX_DEV_NEED_RESET);
5241 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
5242 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
5243 } else {
5244 const char *state = qla83xx_dev_state_to_string(dev_state);
5245 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
5246
5247 /* SV: XXX: Is timeout required here? */
5248 /* Wait for IDC state change READY -> NEED_RESET */
5249 while (dev_state == QLA8XXX_DEV_READY) {
5250 qla83xx_idc_unlock(vha, 0);
5251 msleep(200);
5252 qla83xx_idc_lock(vha, 0);
5253 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5254 }
5255 }
5256
5257 /* Send IDC ack by writing to drv-ack register */
5258 __qla83xx_set_drv_ack(vha);
5259
5260 return QLA_SUCCESS;
5261}
5262
5263int
5264__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
5265{
5266 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5267}
5268
5269int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005270__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
5271{
5272 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5273}
5274
Saurav Kashyapfa492632012-11-21 02:40:29 -05005275static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005276qla83xx_check_driver_presence(scsi_qla_host_t *vha)
5277{
5278 uint32_t drv_presence = 0;
5279 struct qla_hw_data *ha = vha->hw;
5280
5281 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5282 if (drv_presence & (1 << ha->portnum))
5283 return QLA_SUCCESS;
5284 else
5285 return QLA_TEST_FAILED;
5286}
5287
5288int
5289qla83xx_nic_core_reset(scsi_qla_host_t *vha)
5290{
5291 int rval = QLA_SUCCESS;
5292 struct qla_hw_data *ha = vha->hw;
5293
5294 ql_dbg(ql_dbg_p3p, vha, 0xb058,
5295 "Entered %s().\n", __func__);
5296
5297 if (vha->device_flags & DFLG_DEV_FAILED) {
5298 ql_log(ql_log_warn, vha, 0xb059,
5299 "Device in unrecoverable FAILED state.\n");
5300 return QLA_FUNCTION_FAILED;
5301 }
5302
5303 qla83xx_idc_lock(vha, 0);
5304
5305 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
5306 ql_log(ql_log_warn, vha, 0xb05a,
5307 "Function=0x%x has been removed from IDC participation.\n",
5308 ha->portnum);
5309 rval = QLA_FUNCTION_FAILED;
5310 goto exit;
5311 }
5312
5313 qla83xx_reset_ownership(vha);
5314
5315 rval = qla83xx_initiating_reset(vha);
5316
5317 /*
5318 * Perform reset if we are the reset-owner,
5319 * else wait till IDC state changes to READY/FAILED.
5320 */
5321 if (rval == QLA_SUCCESS) {
5322 rval = qla83xx_idc_state_handler(vha);
5323
5324 if (rval == QLA_SUCCESS)
5325 ha->flags.nic_core_hung = 0;
5326 __qla83xx_clear_drv_ack(vha);
5327 }
5328
5329exit:
5330 qla83xx_idc_unlock(vha, 0);
5331
5332 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
5333
5334 return rval;
5335}
5336
Saurav Kashyap81178772012-08-22 14:21:04 -04005337int
5338qla2xxx_mctp_dump(scsi_qla_host_t *vha)
5339{
5340 struct qla_hw_data *ha = vha->hw;
5341 int rval = QLA_FUNCTION_FAILED;
5342
5343 if (!IS_MCTP_CAPABLE(ha)) {
5344 /* This message can be removed from the final version */
5345 ql_log(ql_log_info, vha, 0x506d,
5346 "This board is not MCTP capable\n");
5347 return rval;
5348 }
5349
5350 if (!ha->mctp_dump) {
5351 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
5352 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
5353
5354 if (!ha->mctp_dump) {
5355 ql_log(ql_log_warn, vha, 0x506e,
5356 "Failed to allocate memory for mctp dump\n");
5357 return rval;
5358 }
5359 }
5360
5361#define MCTP_DUMP_STR_ADDR 0x00000000
5362 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
5363 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
5364 if (rval != QLA_SUCCESS) {
5365 ql_log(ql_log_warn, vha, 0x506f,
5366 "Failed to capture mctp dump\n");
5367 } else {
5368 ql_log(ql_log_info, vha, 0x5070,
5369 "Mctp dump capture for host (%ld/%p).\n",
5370 vha->host_no, ha->mctp_dump);
5371 ha->mctp_dumped = 1;
5372 }
5373
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04005374 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04005375 ha->flags.nic_core_reset_hdlr_active = 1;
5376 rval = qla83xx_restart_nic_firmware(vha);
5377 if (rval)
5378 /* NIC Core reset failed. */
5379 ql_log(ql_log_warn, vha, 0x5071,
5380 "Failed to restart nic firmware\n");
5381 else
5382 ql_dbg(ql_dbg_p3p, vha, 0xb084,
5383 "Restarted NIC firmware successfully.\n");
5384 ha->flags.nic_core_reset_hdlr_active = 0;
5385 }
5386
5387 return rval;
5388
5389}
5390
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005391/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005392* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005393* Description: This function will block the new I/Os
5394* Its not aborting any I/Os as context
5395* is not destroyed during quiescence
5396* Arguments: scsi_qla_host_t
5397* return : void
5398*/
5399void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005400qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005401{
5402 struct qla_hw_data *ha = vha->hw;
5403 struct scsi_qla_host *vp;
5404
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005405 ql_dbg(ql_dbg_dpc, vha, 0x401d,
5406 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005407
5408 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
5409 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
5410 atomic_set(&vha->loop_state, LOOP_DOWN);
5411 qla2x00_mark_all_devices_lost(vha, 0);
5412 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005413 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005414 } else {
5415 if (!atomic_read(&vha->loop_down_timer))
5416 atomic_set(&vha->loop_down_timer,
5417 LOOP_DOWN_TIME);
5418 }
5419 /* Wait for pending cmds to complete */
5420 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
5421}
5422
Giridhar Malavalia9083012010-04-12 17:59:55 -07005423void
5424qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
5425{
5426 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005427 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005428 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08005429 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005430
Saurav Kashyape46ef002011-02-23 15:27:16 -08005431 /* For ISP82XX, driver waits for completion of the commands.
5432 * online flag should be set.
5433 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005434 if (!(IS_P3P_TYPE(ha)))
Saurav Kashyape46ef002011-02-23 15:27:16 -08005435 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005436 ha->flags.chip_reset_done = 0;
5437 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04005438 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005439
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005440 ql_log(ql_log_info, vha, 0x00af,
5441 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005442
Saurav Kashyape46ef002011-02-23 15:27:16 -08005443 /* For ISP82XX, reset_chip is just disabling interrupts.
5444 * Driver waits for the completion of the commands.
5445 * the interrupts need to be enabled.
5446 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005447 if (!(IS_P3P_TYPE(ha)))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005448 ha->isp_ops->reset_chip(vha);
5449
Quinn Tran726b8542017-01-19 22:28:00 -08005450 ha->chip_reset++;
5451
Giridhar Malavalia9083012010-04-12 17:59:55 -07005452 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
5453 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
5454 atomic_set(&vha->loop_state, LOOP_DOWN);
5455 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07005456
5457 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005458 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07005459 atomic_inc(&vp->vref_count);
5460 spin_unlock_irqrestore(&ha->vport_slock, flags);
5461
Giridhar Malavalia9083012010-04-12 17:59:55 -07005462 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07005463
5464 spin_lock_irqsave(&ha->vport_slock, flags);
5465 atomic_dec(&vp->vref_count);
5466 }
5467 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005468 } else {
5469 if (!atomic_read(&vha->loop_down_timer))
5470 atomic_set(&vha->loop_down_timer,
5471 LOOP_DOWN_TIME);
5472 }
5473
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08005474 /* Clear all async request states across all VPs. */
5475 list_for_each_entry(fcport, &vha->vp_fcports, list)
5476 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5477 spin_lock_irqsave(&ha->vport_slock, flags);
5478 list_for_each_entry(vp, &ha->vp_list, list) {
5479 atomic_inc(&vp->vref_count);
5480 spin_unlock_irqrestore(&ha->vport_slock, flags);
5481
5482 list_for_each_entry(fcport, &vp->vp_fcports, list)
5483 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5484
5485 spin_lock_irqsave(&ha->vport_slock, flags);
5486 atomic_dec(&vp->vref_count);
5487 }
5488 spin_unlock_irqrestore(&ha->vport_slock, flags);
5489
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005490 if (!ha->flags.eeh_busy) {
5491 /* Make sure for ISP 82XX IO DMA is complete */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005492 if (IS_P3P_TYPE(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005493 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005494 ql_log(ql_log_info, vha, 0x00b4,
5495 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005496
Saurav Kashyape46ef002011-02-23 15:27:16 -08005497 /* Done waiting for pending commands.
5498 * Reset the online flag.
5499 */
5500 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005502
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005503 /* Requeue all commands in outstanding command list. */
5504 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
5505 }
Arun Easib6a029e2014-09-25 06:14:52 -04005506 /* memory barrier */
5507 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005508}
5509
5510/*
5511* qla2x00_abort_isp
5512* Resets ISP and aborts all outstanding commands.
5513*
5514* Input:
5515* ha = adapter block pointer.
5516*
5517* Returns:
5518* 0 = success
5519*/
5520int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005521qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005522{
Andrew Vasquez476e8972006-08-23 14:54:55 -07005523 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005524 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005525 struct qla_hw_data *ha = vha->hw;
5526 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005527 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07005528 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005529
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005530 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07005531 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532
Santosh Vernekara61712972012-08-22 14:21:13 -04005533 if (IS_QLA8031(ha)) {
5534 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
5535 "Clearing fcoe driver presence.\n");
5536 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
5537 ql_dbg(ql_dbg_p3p, vha, 0xb073,
5538 "Error while clearing DRV-Presence.\n");
5539 }
5540
Andrew Vasquez85880802009-12-15 21:29:46 -08005541 if (unlikely(pci_channel_offline(ha->pdev) &&
5542 ha->flags.pci_channel_io_perm_failure)) {
5543 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5544 status = 0;
5545 return status;
5546 }
5547
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005548 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08005549
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005550 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005551
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005552 if (!qla2x00_restart_isp(vha)) {
5553 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005554
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005555 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005556 /*
5557 * Issue marker command only when we are going
5558 * to start the I/O .
5559 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005560 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005561 }
5562
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005563 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005564
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005565 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005566
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07005567 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005568 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07005569
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005570 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
5571 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08005572 if (ha->fce) {
5573 ha->flags.fce_enabled = 1;
5574 memset(ha->fce, 0,
5575 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005576 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08005577 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5578 &ha->fce_bufs);
5579 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005580 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08005581 "Unable to reinitialize FCE "
5582 "(%d).\n", rval);
5583 ha->flags.fce_enabled = 0;
5584 }
5585 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07005586
5587 if (ha->eft) {
5588 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005589 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07005590 ha->eft_dma, EFT_NUM_BUFFERS);
5591 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005592 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07005593 "Unable to reinitialize EFT "
5594 "(%d).\n", rval);
5595 }
5596 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005597 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005598 vha->flags.online = 1;
5599 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005600 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005601 ql_log(ql_log_fatal, vha, 0x8035,
5602 "ISP error recover failed - "
5603 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07005604 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005605 * The next call disables the board
5606 * completely.
5607 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005608 ha->isp_ops->reset_adapter(vha);
5609 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005610 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005611 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005612 status = 0;
5613 } else { /* schedule another ISP abort */
5614 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005615 ql_dbg(ql_dbg_taskm, vha, 0x8020,
5616 "ISP abort - retry remaining %d.\n",
5617 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005618 status = 1;
5619 }
5620 } else {
5621 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005622 ql_dbg(ql_dbg_taskm, vha, 0x8021,
5623 "ISP error recovery - retrying (%d) "
5624 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005625 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005626 status = 1;
5627 }
5628 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07005629
Linus Torvalds1da177e2005-04-16 15:20:36 -07005630 }
5631
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005632 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005633 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07005634
5635 spin_lock_irqsave(&ha->vport_slock, flags);
5636 list_for_each_entry(vp, &ha->vp_list, list) {
5637 if (vp->vp_idx) {
5638 atomic_inc(&vp->vref_count);
5639 spin_unlock_irqrestore(&ha->vport_slock, flags);
5640
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005641 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07005642
5643 spin_lock_irqsave(&ha->vport_slock, flags);
5644 atomic_dec(&vp->vref_count);
5645 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005646 }
Arun Easifeafb7b2010-09-03 14:57:00 -07005647 spin_unlock_irqrestore(&ha->vport_slock, flags);
5648
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005649 if (IS_QLA8031(ha)) {
5650 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
5651 "Setting back fcoe driver presence.\n");
5652 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
5653 ql_dbg(ql_dbg_p3p, vha, 0xb074,
5654 "Error while setting DRV-Presence.\n");
5655 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005656 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08005657 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
5658 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005659 }
5660
5661 return(status);
5662}
5663
5664/*
5665* qla2x00_restart_isp
5666* restarts the ISP after a reset
5667*
5668* Input:
5669* ha = adapter block pointer.
5670*
5671* Returns:
5672* 0 = success
5673*/
5674static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005675qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005676{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08005677 int status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005678 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005679 struct req_que *req = ha->req_q_map[0];
5680 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005681
5682 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005683 if (qla2x00_isp_firmware(vha)) {
5684 vha->flags.online = 0;
5685 status = ha->isp_ops->chip_diag(vha);
5686 if (!status)
5687 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005688 }
5689
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005690 if (!status && !(status = qla2x00_init_rings(vha))) {
5691 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07005692 ha->flags.chip_reset_done = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04005693
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005694 /* Initialize the queues in use */
5695 qla25xx_init_queues(ha);
5696
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005697 status = qla2x00_fw_ready(vha);
5698 if (!status) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005699 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005700 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Chad Dupuis7108b762014-04-11 16:54:45 -04005701 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005702 }
5703
5704 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005705 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005706 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005707 }
5708 return (status);
5709}
5710
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005711static int
5712qla25xx_init_queues(struct qla_hw_data *ha)
5713{
5714 struct rsp_que *rsp = NULL;
5715 struct req_que *req = NULL;
5716 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5717 int ret = -1;
5718 int i;
5719
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07005720 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005721 rsp = ha->rsp_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05005722 if (rsp && test_bit(i, ha->rsp_qid_map)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005723 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08005724 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005725 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005726 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
5727 "%s Rsp que: %d init failed.\n",
5728 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005729 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005730 ql_dbg(ql_dbg_init, base_vha, 0x0100,
5731 "%s Rsp que: %d inited.\n",
5732 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005733 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07005734 }
5735 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005736 req = ha->req_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05005737 if (req && test_bit(i, ha->req_qid_map)) {
5738 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005739 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08005740 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005741 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005742 ql_dbg(ql_dbg_init, base_vha, 0x0101,
5743 "%s Req que: %d init failed.\n",
5744 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005745 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005746 ql_dbg(ql_dbg_init, base_vha, 0x0102,
5747 "%s Req que: %d inited.\n",
5748 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005749 }
5750 }
5751 return ret;
5752}
5753
Linus Torvalds1da177e2005-04-16 15:20:36 -07005754/*
5755* qla2x00_reset_adapter
5756* Reset adapter.
5757*
5758* Input:
5759* ha = adapter block pointer.
5760*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07005761void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005762qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005763{
5764 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005765 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07005766 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005767
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005768 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005769 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005770
Linus Torvalds1da177e2005-04-16 15:20:36 -07005771 spin_lock_irqsave(&ha->hardware_lock, flags);
5772 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
5773 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
5774 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
5775 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
5776 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5777}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005778
5779void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005780qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005781{
5782 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005783 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005784 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
5785
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005786 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005787 return;
5788
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005789 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005790 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005791
5792 spin_lock_irqsave(&ha->hardware_lock, flags);
5793 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
5794 RD_REG_DWORD(&reg->hccr);
5795 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
5796 RD_REG_DWORD(&reg->hccr);
5797 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08005798
5799 if (IS_NOPOLLING_TYPE(ha))
5800 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005801}
5802
David Miller4e08df32007-04-16 12:37:43 -07005803/* On sparc systems, obtain port and node WWN from firmware
5804 * properties.
5805 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005806static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
5807 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07005808{
5809#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005810 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07005811 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07005812 struct device_node *dp = pci_device_to_OF_node(pdev);
5813 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07005814 int len;
5815
5816 val = of_get_property(dp, "port-wwn", &len);
5817 if (val && len >= WWN_SIZE)
5818 memcpy(nv->port_name, val, WWN_SIZE);
5819
5820 val = of_get_property(dp, "node-wwn", &len);
5821 if (val && len >= WWN_SIZE)
5822 memcpy(nv->node_name, val, WWN_SIZE);
5823#endif
5824}
5825
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005826int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005827qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005828{
David Miller4e08df32007-04-16 12:37:43 -07005829 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005830 struct init_cb_24xx *icb;
5831 struct nvram_24xx *nv;
5832 uint32_t *dptr;
5833 uint8_t *dptr1, *dptr2;
5834 uint32_t chksum;
5835 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005836 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005837
David Miller4e08df32007-04-16 12:37:43 -07005838 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005839 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07005840 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005841
5842 /* Determine NVRAM starting address. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05005843 if (ha->port_no == 0) {
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005844 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
5845 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
5846 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005847 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08005848 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
5849 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05005850
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005851 ha->nvram_size = sizeof(struct nvram_24xx);
5852 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005853
Seokmann Ju281afe12007-07-26 13:43:34 -07005854 /* Get VPD data into cache */
5855 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005856 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07005857 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
5858
5859 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005860 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005861 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005862 ha->nvram_size);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05005863 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
5864 chksum += le32_to_cpu(*dptr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005865
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005866 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
5867 "Contents of NVRAM\n");
5868 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
5869 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005870
5871 /* Bad NVRAM data, set defaults parameters. */
5872 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5873 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07005874 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005875 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005876 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04005877 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005878 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
5879 ql_log(ql_log_warn, vha, 0x006c,
5880 "Falling back to functioning (yet invalid -- WWPN) "
5881 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07005882
5883 /*
5884 * Set default initialization control block.
5885 */
5886 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07005887 nv->nvram_version = cpu_to_le16(ICB_VERSION);
5888 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04005889 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07005890 nv->execution_throttle = cpu_to_le16(0xFFFF);
5891 nv->exchange_count = cpu_to_le16(0);
5892 nv->hard_address = cpu_to_le16(124);
David Miller4e08df32007-04-16 12:37:43 -07005893 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005894 nv->port_name[1] = 0x00 + ha->port_no + 1;
David Miller4e08df32007-04-16 12:37:43 -07005895 nv->port_name[2] = 0x00;
5896 nv->port_name[3] = 0xe0;
5897 nv->port_name[4] = 0x8b;
5898 nv->port_name[5] = 0x1c;
5899 nv->port_name[6] = 0x55;
5900 nv->port_name[7] = 0x86;
5901 nv->node_name[0] = 0x20;
5902 nv->node_name[1] = 0x00;
5903 nv->node_name[2] = 0x00;
5904 nv->node_name[3] = 0xe0;
5905 nv->node_name[4] = 0x8b;
5906 nv->node_name[5] = 0x1c;
5907 nv->node_name[6] = 0x55;
5908 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005909 qla24xx_nvram_wwn_from_ofw(vha, nv);
Bart Van Asschead950362015-07-09 07:24:08 -07005910 nv->login_retry_count = cpu_to_le16(8);
5911 nv->interrupt_delay_timer = cpu_to_le16(0);
5912 nv->login_timeout = cpu_to_le16(0);
David Miller4e08df32007-04-16 12:37:43 -07005913 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07005914 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5915 nv->firmware_options_2 = cpu_to_le32(2 << 4);
5916 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
5917 nv->firmware_options_3 = cpu_to_le32(2 << 13);
5918 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
5919 nv->efi_parameters = cpu_to_le32(0);
David Miller4e08df32007-04-16 12:37:43 -07005920 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07005921 nv->max_luns_per_target = cpu_to_le16(128);
5922 nv->port_down_retry_count = cpu_to_le16(30);
5923 nv->link_down_timeout = cpu_to_le16(30);
David Miller4e08df32007-04-16 12:37:43 -07005924
5925 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005926 }
5927
Quinn Tran726b8542017-01-19 22:28:00 -08005928 if (qla_tgt_mode_enabled(vha)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005929 /* Don't enable full login after initial LIP */
Bart Van Asschead950362015-07-09 07:24:08 -07005930 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005931 /* Don't enable LIP full login for initiator */
Bart Van Asschead950362015-07-09 07:24:08 -07005932 nv->host_p &= cpu_to_le32(~BIT_10);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005933 }
5934
5935 qlt_24xx_config_nvram_stage1(vha, nv);
5936
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005937 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005938 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005939
5940 /* Copy 1st segment. */
5941 dptr1 = (uint8_t *)icb;
5942 dptr2 = (uint8_t *)&nv->version;
5943 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5944 while (cnt--)
5945 *dptr1++ = *dptr2++;
5946
5947 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07005948 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005949
5950 /* Copy 2nd segment. */
5951 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5952 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5953 cnt = (uint8_t *)&icb->reserved_3 -
5954 (uint8_t *)&icb->interrupt_delay_timer;
5955 while (cnt--)
5956 *dptr1++ = *dptr2++;
5957
5958 /*
5959 * Setup driver NVRAM options.
5960 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005961 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08005962 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005963
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005964 qlt_24xx_config_nvram_stage2(vha, icb);
5965
Bart Van Asschead950362015-07-09 07:24:08 -07005966 if (nv->host_p & cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005967 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07005968 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5969 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5970 }
5971
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005972 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07005973 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005974 /*
5975 * Firmware will apply the following mask if the nodename was
5976 * not provided.
5977 */
5978 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5979 icb->node_name[0] &= 0xF0;
5980 }
5981
5982 /* Set host adapter parameters. */
5983 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08005984 ha->flags.enable_lip_reset = 0;
5985 ha->flags.enable_lip_full_login =
5986 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5987 ha->flags.enable_target_reset =
5988 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005989 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07005990 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005991
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07005992 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5993 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005994
5995 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
5996 sizeof(ha->fw_seriallink_options24));
5997
5998 /* save HBA serial number */
5999 ha->serial0 = icb->port_name[5];
6000 ha->serial1 = icb->port_name[6];
6001 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006002 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6003 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006004
Bart Van Asschead950362015-07-09 07:24:08 -07006005 icb->execution_throttle = cpu_to_le16(0xFFFF);
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08006006
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006007 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6008
6009 /* Set minimum login_timeout to 4 seconds. */
6010 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6011 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6012 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07006013 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006014 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006015
Andrew Vasquez00a537b2008-02-28 14:06:11 -08006016 /* Set minimum RATOV to 100 tenths of a second. */
6017 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006018
6019 ha->loop_reset_delay = nv->reset_delay;
6020
6021 /* Link Down Timeout = 0:
6022 *
6023 * When Port Down timer expires we will start returning
6024 * I/O's to OS with "DID_NO_CONNECT".
6025 *
6026 * Link Down Timeout != 0:
6027 *
6028 * The driver waits for the link to come up after link down
6029 * before returning I/Os to OS with "DID_NO_CONNECT".
6030 */
6031 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6032 ha->loop_down_abort_time =
6033 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6034 } else {
6035 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6036 ha->loop_down_abort_time =
6037 (LOOP_DOWN_TIME - ha->link_down_timeout);
6038 }
6039
6040 /* Need enough time to try and get the port back. */
6041 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6042 if (qlport_down_retry)
6043 ha->port_down_retry_count = qlport_down_retry;
6044
6045 /* Set login_retry_count */
6046 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6047 if (ha->port_down_retry_count ==
6048 le16_to_cpu(nv->port_down_retry_count) &&
6049 ha->port_down_retry_count > 3)
6050 ha->login_retry_count = ha->port_down_retry_count;
6051 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6052 ha->login_retry_count = ha->port_down_retry_count;
6053 if (ql2xloginretrycount)
6054 ha->login_retry_count = ql2xloginretrycount;
6055
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006056 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006057 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006058 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6059 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6060 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6061 le16_to_cpu(icb->interrupt_delay_timer): 2;
6062 }
Bart Van Asschead950362015-07-09 07:24:08 -07006063 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006064 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006065 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006066 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08006067 ha->zio_mode = QLA_ZIO_MODE_6;
6068
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006069 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006070 "ZIO mode %d enabled; timer delay (%d us).\n",
6071 ha->zio_mode, ha->zio_timer * 100);
6072
6073 icb->firmware_options_2 |= cpu_to_le32(
6074 (uint32_t)ha->zio_mode);
6075 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006076 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006077 }
6078
David Miller4e08df32007-04-16 12:37:43 -07006079 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006080 ql_log(ql_log_warn, vha, 0x0070,
6081 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07006082 }
6083 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006084}
6085
Sawan Chandak4243c112016-01-27 12:03:31 -05006086uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
6087{
6088 struct qla27xx_image_status pri_image_status, sec_image_status;
6089 uint8_t valid_pri_image, valid_sec_image;
6090 uint32_t *wptr;
6091 uint32_t cnt, chksum, size;
6092 struct qla_hw_data *ha = vha->hw;
6093
6094 valid_pri_image = valid_sec_image = 1;
6095 ha->active_image = 0;
6096 size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
6097
6098 if (!ha->flt_region_img_status_pri) {
6099 valid_pri_image = 0;
6100 goto check_sec_image;
6101 }
6102
6103 qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
6104 ha->flt_region_img_status_pri, size);
6105
6106 if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6107 ql_dbg(ql_dbg_init, vha, 0x018b,
6108 "Primary image signature (0x%x) not valid\n",
6109 pri_image_status.signature);
6110 valid_pri_image = 0;
6111 goto check_sec_image;
6112 }
6113
6114 wptr = (uint32_t *)(&pri_image_status);
6115 cnt = size;
6116
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006117 for (chksum = 0; cnt--; wptr++)
6118 chksum += le32_to_cpu(*wptr);
Sawan Chandak4243c112016-01-27 12:03:31 -05006119 if (chksum) {
6120 ql_dbg(ql_dbg_init, vha, 0x018c,
6121 "Checksum validation failed for primary image (0x%x)\n",
6122 chksum);
6123 valid_pri_image = 0;
6124 }
6125
6126check_sec_image:
6127 if (!ha->flt_region_img_status_sec) {
6128 valid_sec_image = 0;
6129 goto check_valid_image;
6130 }
6131
6132 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
6133 ha->flt_region_img_status_sec, size);
6134
6135 if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6136 ql_dbg(ql_dbg_init, vha, 0x018d,
6137 "Secondary image signature(0x%x) not valid\n",
6138 sec_image_status.signature);
6139 valid_sec_image = 0;
6140 goto check_valid_image;
6141 }
6142
6143 wptr = (uint32_t *)(&sec_image_status);
6144 cnt = size;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006145 for (chksum = 0; cnt--; wptr++)
6146 chksum += le32_to_cpu(*wptr);
Sawan Chandak4243c112016-01-27 12:03:31 -05006147 if (chksum) {
6148 ql_dbg(ql_dbg_init, vha, 0x018e,
6149 "Checksum validation failed for secondary image (0x%x)\n",
6150 chksum);
6151 valid_sec_image = 0;
6152 }
6153
6154check_valid_image:
6155 if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
6156 ha->active_image = QLA27XX_PRIMARY_IMAGE;
6157 if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
6158 if (!ha->active_image ||
6159 pri_image_status.generation_number <
6160 sec_image_status.generation_number)
6161 ha->active_image = QLA27XX_SECONDARY_IMAGE;
6162 }
6163
6164 ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n",
6165 ha->active_image == 0 ? "default bootld and fw" :
6166 ha->active_image == 1 ? "primary" :
6167 ha->active_image == 2 ? "secondary" :
6168 "Invalid");
6169
6170 return ha->active_image;
6171}
6172
Adrian Bunk413975a2006-06-30 02:33:06 -07006173static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006174qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
6175 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006176{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006177 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006178 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006179 uint32_t *dcode, dlen;
6180 uint32_t risc_addr;
6181 uint32_t risc_size;
6182 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006183 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006184 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006185
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006186 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006187 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006188
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006189 rval = QLA_SUCCESS;
6190
6191 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006192 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006193 *srisc_addr = 0;
6194
Sawan Chandak4243c112016-01-27 12:03:31 -05006195 if (IS_QLA27XX(ha) &&
6196 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
6197 faddr = ha->flt_region_fw_sec;
6198
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006199 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006200 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006201 for (i = 0; i < 4; i++)
6202 dcode[i] = be32_to_cpu(dcode[i]);
6203 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
6204 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
6205 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
6206 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006207 ql_log(ql_log_fatal, vha, 0x008c,
6208 "Unable to verify the integrity of flash firmware "
6209 "image.\n");
6210 ql_log(ql_log_fatal, vha, 0x008d,
6211 "Firmware data: %08x %08x %08x %08x.\n",
6212 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006213
6214 return QLA_FUNCTION_FAILED;
6215 }
6216
6217 while (segments && rval == QLA_SUCCESS) {
6218 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006219 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006220
6221 risc_addr = be32_to_cpu(dcode[2]);
6222 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
6223 risc_size = be32_to_cpu(dcode[3]);
6224
6225 fragment = 0;
6226 while (risc_size > 0 && rval == QLA_SUCCESS) {
6227 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
6228 if (dlen > risc_size)
6229 dlen = risc_size;
6230
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006231 ql_dbg(ql_dbg_init, vha, 0x008e,
6232 "Loading risc segment@ risc addr %x "
6233 "number of dwords 0x%x offset 0x%x.\n",
6234 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006235
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006236 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006237 for (i = 0; i < dlen; i++)
6238 dcode[i] = swab32(dcode[i]);
6239
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006240 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006241 dlen);
6242 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006243 ql_log(ql_log_fatal, vha, 0x008f,
6244 "Failed to load segment %d of firmware.\n",
6245 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04006246 return QLA_FUNCTION_FAILED;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006247 }
6248
6249 faddr += dlen;
6250 risc_addr += dlen;
6251 risc_size -= dlen;
6252 fragment++;
6253 }
6254
6255 /* Next segment. */
6256 segments--;
6257 }
6258
Chad Dupuisf73cb692014-02-26 04:15:06 -05006259 if (!IS_QLA27XX(ha))
6260 return rval;
6261
6262 if (ha->fw_dump_template)
6263 vfree(ha->fw_dump_template);
6264 ha->fw_dump_template = NULL;
6265 ha->fw_dump_template_len = 0;
6266
6267 ql_dbg(ql_dbg_init, vha, 0x0161,
6268 "Loading fwdump template from %x\n", faddr);
6269 qla24xx_read_flash_data(vha, dcode, faddr, 7);
6270 risc_size = be32_to_cpu(dcode[2]);
6271 ql_dbg(ql_dbg_init, vha, 0x0162,
6272 "-> array size %x dwords\n", risc_size);
6273 if (risc_size == 0 || risc_size == ~0)
6274 goto default_template;
6275
6276 dlen = (risc_size - 8) * sizeof(*dcode);
6277 ql_dbg(ql_dbg_init, vha, 0x0163,
6278 "-> template allocating %x bytes...\n", dlen);
6279 ha->fw_dump_template = vmalloc(dlen);
6280 if (!ha->fw_dump_template) {
6281 ql_log(ql_log_warn, vha, 0x0164,
6282 "Failed fwdump template allocate %x bytes.\n", risc_size);
6283 goto default_template;
6284 }
6285
6286 faddr += 7;
6287 risc_size -= 8;
6288 dcode = ha->fw_dump_template;
6289 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
6290 for (i = 0; i < risc_size; i++)
6291 dcode[i] = le32_to_cpu(dcode[i]);
6292
6293 if (!qla27xx_fwdt_template_valid(dcode)) {
6294 ql_log(ql_log_warn, vha, 0x0165,
6295 "Failed fwdump template validate\n");
6296 goto default_template;
6297 }
6298
6299 dlen = qla27xx_fwdt_template_size(dcode);
6300 ql_dbg(ql_dbg_init, vha, 0x0166,
6301 "-> template size %x bytes\n", dlen);
6302 if (dlen > risc_size * sizeof(*dcode)) {
6303 ql_log(ql_log_warn, vha, 0x0167,
Chad Dupuis97ea7022014-03-13 14:16:40 -04006304 "Failed fwdump template exceeds array by %x bytes\n",
6305 (uint32_t)(dlen - risc_size * sizeof(*dcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05006306 goto default_template;
6307 }
6308 ha->fw_dump_template_len = dlen;
6309 return rval;
6310
6311default_template:
6312 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
6313 if (ha->fw_dump_template)
6314 vfree(ha->fw_dump_template);
6315 ha->fw_dump_template = NULL;
6316 ha->fw_dump_template_len = 0;
6317
6318 dlen = qla27xx_fwdt_template_default_size();
6319 ql_dbg(ql_dbg_init, vha, 0x0169,
6320 "-> template allocating %x bytes...\n", dlen);
6321 ha->fw_dump_template = vmalloc(dlen);
6322 if (!ha->fw_dump_template) {
6323 ql_log(ql_log_warn, vha, 0x016a,
6324 "Failed fwdump template allocate %x bytes.\n", risc_size);
6325 goto failed_template;
6326 }
6327
6328 dcode = ha->fw_dump_template;
6329 risc_size = dlen / sizeof(*dcode);
6330 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
6331 for (i = 0; i < risc_size; i++)
6332 dcode[i] = be32_to_cpu(dcode[i]);
6333
6334 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
6335 ql_log(ql_log_warn, vha, 0x016b,
6336 "Failed fwdump template validate\n");
6337 goto failed_template;
6338 }
6339
6340 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
6341 ql_dbg(ql_dbg_init, vha, 0x016c,
6342 "-> template size %x bytes\n", dlen);
6343 ha->fw_dump_template_len = dlen;
6344 return rval;
6345
6346failed_template:
6347 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
6348 if (ha->fw_dump_template)
6349 vfree(ha->fw_dump_template);
6350 ha->fw_dump_template = NULL;
6351 ha->fw_dump_template_len = 0;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006352 return rval;
6353}
6354
Giridhar Malavalie9454a82013-02-08 01:57:47 -05006355#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006356
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006357int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006358qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08006359{
6360 int rval;
6361 int i, fragment;
6362 uint16_t *wcode, *fwcode;
6363 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
6364 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006365 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006366 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08006367
6368 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006369 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08006370 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006371 ql_log(ql_log_info, vha, 0x0083,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01006372 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006373 ql_log(ql_log_info, vha, 0x0084,
6374 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08006375 return QLA_FUNCTION_FAILED;
6376 }
6377
6378 rval = QLA_SUCCESS;
6379
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006380 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08006381 *srisc_addr = 0;
6382 fwcode = (uint16_t *)blob->fw->data;
6383 fwclen = 0;
6384
6385 /* Validate firmware image by checking version. */
6386 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006387 ql_log(ql_log_fatal, vha, 0x0085,
6388 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08006389 blob->fw->size);
6390 goto fail_fw_integrity;
6391 }
6392 for (i = 0; i < 4; i++)
6393 wcode[i] = be16_to_cpu(fwcode[i + 4]);
6394 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
6395 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
6396 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006397 ql_log(ql_log_fatal, vha, 0x0086,
6398 "Unable to verify integrity of firmware image.\n");
6399 ql_log(ql_log_fatal, vha, 0x0087,
6400 "Firmware data: %04x %04x %04x %04x.\n",
6401 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08006402 goto fail_fw_integrity;
6403 }
6404
6405 seg = blob->segs;
6406 while (*seg && rval == QLA_SUCCESS) {
6407 risc_addr = *seg;
6408 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
6409 risc_size = be16_to_cpu(fwcode[3]);
6410
6411 /* Validate firmware image size. */
6412 fwclen += risc_size * sizeof(uint16_t);
6413 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006414 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08006415 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006416 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08006417 goto fail_fw_integrity;
6418 }
6419
6420 fragment = 0;
6421 while (risc_size > 0 && rval == QLA_SUCCESS) {
6422 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
6423 if (wlen > risc_size)
6424 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006425 ql_dbg(ql_dbg_init, vha, 0x0089,
6426 "Loading risc segment@ risc addr %x number of "
6427 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08006428
6429 for (i = 0; i < wlen; i++)
6430 wcode[i] = swab16(fwcode[i]);
6431
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006432 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08006433 wlen);
6434 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006435 ql_log(ql_log_fatal, vha, 0x008a,
6436 "Failed to load segment %d of firmware.\n",
6437 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08006438 break;
6439 }
6440
6441 fwcode += wlen;
6442 risc_addr += wlen;
6443 risc_size -= wlen;
6444 fragment++;
6445 }
6446
6447 /* Next segment. */
6448 seg++;
6449 }
6450 return rval;
6451
6452fail_fw_integrity:
6453 return QLA_FUNCTION_FAILED;
6454}
6455
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006456static int
6457qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006458{
6459 int rval;
6460 int segments, fragment;
6461 uint32_t *dcode, dlen;
6462 uint32_t risc_addr;
6463 uint32_t risc_size;
6464 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08006465 struct fw_blob *blob;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006466 const uint32_t *fwcode;
6467 uint32_t fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006468 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006469 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006470
Andrew Vasquez54333832005-11-09 15:49:04 -08006471 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006472 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08006473 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006474 ql_log(ql_log_warn, vha, 0x0090,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01006475 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006476 ql_log(ql_log_warn, vha, 0x0091,
6477 "Firmware images can be retrieved from: "
6478 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006479
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006480 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006481 }
6482
Chad Dupuiscfb09192011-11-18 09:03:07 -08006483 ql_dbg(ql_dbg_init, vha, 0x0092,
6484 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006485
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006486 rval = QLA_SUCCESS;
6487
6488 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006489 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006490 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08006491 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006492 fwclen = 0;
6493
6494 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08006495 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006496 ql_log(ql_log_fatal, vha, 0x0093,
6497 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08006498 blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05006499 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006500 }
6501 for (i = 0; i < 4; i++)
6502 dcode[i] = be32_to_cpu(fwcode[i + 4]);
6503 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
6504 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
6505 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
6506 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006507 ql_log(ql_log_fatal, vha, 0x0094,
6508 "Unable to verify integrity of firmware image (%Zd).\n",
6509 blob->fw->size);
6510 ql_log(ql_log_fatal, vha, 0x0095,
6511 "Firmware data: %08x %08x %08x %08x.\n",
6512 dcode[0], dcode[1], dcode[2], dcode[3]);
Chad Dupuisf73cb692014-02-26 04:15:06 -05006513 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006514 }
6515
6516 while (segments && rval == QLA_SUCCESS) {
6517 risc_addr = be32_to_cpu(fwcode[2]);
6518 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
6519 risc_size = be32_to_cpu(fwcode[3]);
6520
6521 /* Validate firmware image size. */
6522 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08006523 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006524 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08006525 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006526 "(%Zd).\n", blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05006527 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006528 }
6529
6530 fragment = 0;
6531 while (risc_size > 0 && rval == QLA_SUCCESS) {
6532 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
6533 if (dlen > risc_size)
6534 dlen = risc_size;
6535
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006536 ql_dbg(ql_dbg_init, vha, 0x0097,
6537 "Loading risc segment@ risc addr %x "
6538 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006539
6540 for (i = 0; i < dlen; i++)
6541 dcode[i] = swab32(fwcode[i]);
6542
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006543 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08006544 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006545 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006546 ql_log(ql_log_fatal, vha, 0x0098,
6547 "Failed to load segment %d of firmware.\n",
6548 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04006549 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006550 }
6551
6552 fwcode += dlen;
6553 risc_addr += dlen;
6554 risc_size -= dlen;
6555 fragment++;
6556 }
6557
6558 /* Next segment. */
6559 segments--;
6560 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05006561
6562 if (!IS_QLA27XX(ha))
6563 return rval;
6564
6565 if (ha->fw_dump_template)
6566 vfree(ha->fw_dump_template);
6567 ha->fw_dump_template = NULL;
6568 ha->fw_dump_template_len = 0;
6569
6570 ql_dbg(ql_dbg_init, vha, 0x171,
Chad Dupuis97ea7022014-03-13 14:16:40 -04006571 "Loading fwdump template from %x\n",
6572 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
Chad Dupuisf73cb692014-02-26 04:15:06 -05006573 risc_size = be32_to_cpu(fwcode[2]);
6574 ql_dbg(ql_dbg_init, vha, 0x172,
6575 "-> array size %x dwords\n", risc_size);
6576 if (risc_size == 0 || risc_size == ~0)
6577 goto default_template;
6578
6579 dlen = (risc_size - 8) * sizeof(*fwcode);
6580 ql_dbg(ql_dbg_init, vha, 0x0173,
6581 "-> template allocating %x bytes...\n", dlen);
6582 ha->fw_dump_template = vmalloc(dlen);
6583 if (!ha->fw_dump_template) {
6584 ql_log(ql_log_warn, vha, 0x0174,
6585 "Failed fwdump template allocate %x bytes.\n", risc_size);
6586 goto default_template;
6587 }
6588
6589 fwcode += 7;
6590 risc_size -= 8;
6591 dcode = ha->fw_dump_template;
6592 for (i = 0; i < risc_size; i++)
6593 dcode[i] = le32_to_cpu(fwcode[i]);
6594
6595 if (!qla27xx_fwdt_template_valid(dcode)) {
6596 ql_log(ql_log_warn, vha, 0x0175,
6597 "Failed fwdump template validate\n");
6598 goto default_template;
6599 }
6600
6601 dlen = qla27xx_fwdt_template_size(dcode);
6602 ql_dbg(ql_dbg_init, vha, 0x0176,
6603 "-> template size %x bytes\n", dlen);
6604 if (dlen > risc_size * sizeof(*fwcode)) {
6605 ql_log(ql_log_warn, vha, 0x0177,
Chad Dupuis97ea7022014-03-13 14:16:40 -04006606 "Failed fwdump template exceeds array by %x bytes\n",
6607 (uint32_t)(dlen - risc_size * sizeof(*fwcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05006608 goto default_template;
6609 }
6610 ha->fw_dump_template_len = dlen;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006611 return rval;
6612
Chad Dupuisf73cb692014-02-26 04:15:06 -05006613default_template:
6614 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
6615 if (ha->fw_dump_template)
6616 vfree(ha->fw_dump_template);
6617 ha->fw_dump_template = NULL;
6618 ha->fw_dump_template_len = 0;
6619
6620 dlen = qla27xx_fwdt_template_default_size();
6621 ql_dbg(ql_dbg_init, vha, 0x0179,
6622 "-> template allocating %x bytes...\n", dlen);
6623 ha->fw_dump_template = vmalloc(dlen);
6624 if (!ha->fw_dump_template) {
6625 ql_log(ql_log_warn, vha, 0x017a,
6626 "Failed fwdump template allocate %x bytes.\n", risc_size);
6627 goto failed_template;
6628 }
6629
6630 dcode = ha->fw_dump_template;
6631 risc_size = dlen / sizeof(*fwcode);
6632 fwcode = qla27xx_fwdt_template_default();
6633 for (i = 0; i < risc_size; i++)
6634 dcode[i] = be32_to_cpu(fwcode[i]);
6635
6636 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
6637 ql_log(ql_log_warn, vha, 0x017b,
6638 "Failed fwdump template validate\n");
6639 goto failed_template;
6640 }
6641
6642 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
6643 ql_dbg(ql_dbg_init, vha, 0x017c,
6644 "-> template size %x bytes\n", dlen);
6645 ha->fw_dump_template_len = dlen;
6646 return rval;
6647
6648failed_template:
6649 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
6650 if (ha->fw_dump_template)
6651 vfree(ha->fw_dump_template);
6652 ha->fw_dump_template = NULL;
6653 ha->fw_dump_template_len = 0;
6654 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006655}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006656
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006657int
6658qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
6659{
6660 int rval;
6661
Andrew Vasqueze337d902009-04-06 22:33:49 -07006662 if (ql2xfwloadbin == 1)
6663 return qla81xx_load_risc(vha, srisc_addr);
6664
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006665 /*
6666 * FW Load priority:
6667 * 1) Firmware via request-firmware interface (.bin file).
6668 * 2) Firmware residing in flash.
6669 */
6670 rval = qla24xx_load_risc_blob(vha, srisc_addr);
6671 if (rval == QLA_SUCCESS)
6672 return rval;
6673
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006674 return qla24xx_load_risc_flash(vha, srisc_addr,
6675 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006676}
6677
6678int
6679qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
6680{
6681 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006682 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006683
Andrew Vasqueze337d902009-04-06 22:33:49 -07006684 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006685 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07006686
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006687 /*
6688 * FW Load priority:
6689 * 1) Firmware residing in flash.
6690 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006691 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006692 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006693 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006694 if (rval == QLA_SUCCESS)
6695 return rval;
6696
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006697try_blob_fw:
6698 rval = qla24xx_load_risc_blob(vha, srisc_addr);
6699 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
6700 return rval;
6701
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006702 ql_log(ql_log_info, vha, 0x0099,
6703 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006704 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
6705 if (rval != QLA_SUCCESS)
6706 return rval;
6707
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006708 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006709 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006710 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006711}
6712
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006713void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006714qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006715{
6716 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006717 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006718
Andrew Vasquez85880802009-12-15 21:29:46 -08006719 if (ha->flags.pci_channel_io_perm_failure)
6720 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07006721 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006722 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07006723 if (!ha->fw_major_version)
6724 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006725
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006726 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08006727 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07006728 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006729 ha->isp_ops->reset_chip(vha);
6730 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006731 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006732 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006733 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006734 ql_log(ql_log_info, vha, 0x8015,
6735 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006736 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006737 }
6738}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006739
6740int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006741qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006742{
6743 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08006744 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006745 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006746 struct qla_hw_data *ha = vha->hw;
6747 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07006748 struct req_que *req;
6749 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006750
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006751 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006752 return -EINVAL;
6753
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006754 rval = qla2x00_fw_ready(base_vha);
Michael Hernandezd7459522016-12-12 14:40:07 -08006755 if (vha->qpair)
6756 req = vha->qpair->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07006757 else
Michael Hernandezd7459522016-12-12 14:40:07 -08006758 req = ha->req_q_map[0];
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07006759 rsp = req->rsp;
6760
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006761 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006762 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006763 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006764 }
6765
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006766 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006767
6768 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08006769 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
6770 BIT_1);
6771 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
6772 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
6773 ql_dbg(ql_dbg_init, vha, 0x0120,
6774 "Failed SNS login: loop_id=%x, rval2=%d\n",
6775 NPH_SNS, rval2);
6776 else
6777 ql_dbg(ql_dbg_init, vha, 0x0103,
6778 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
6779 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
6780 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006781 return (QLA_FUNCTION_FAILED);
6782 }
6783
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006784 atomic_set(&vha->loop_down_timer, 0);
6785 atomic_set(&vha->loop_state, LOOP_UP);
6786 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6787 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
6788 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006789
6790 return rval;
6791}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006792
6793/* 84XX Support **************************************************************/
6794
6795static LIST_HEAD(qla_cs84xx_list);
6796static DEFINE_MUTEX(qla_cs84xx_mutex);
6797
6798static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006799qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006800{
6801 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006802 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006803
6804 mutex_lock(&qla_cs84xx_mutex);
6805
6806 /* Find any shared 84xx chip. */
6807 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
6808 if (cs84xx->bus == ha->pdev->bus) {
6809 kref_get(&cs84xx->kref);
6810 goto done;
6811 }
6812 }
6813
6814 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
6815 if (!cs84xx)
6816 goto done;
6817
6818 kref_init(&cs84xx->kref);
6819 spin_lock_init(&cs84xx->access_lock);
6820 mutex_init(&cs84xx->fw_update_mutex);
6821 cs84xx->bus = ha->pdev->bus;
6822
6823 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
6824done:
6825 mutex_unlock(&qla_cs84xx_mutex);
6826 return cs84xx;
6827}
6828
6829static void
6830__qla84xx_chip_release(struct kref *kref)
6831{
6832 struct qla_chip_state_84xx *cs84xx =
6833 container_of(kref, struct qla_chip_state_84xx, kref);
6834
6835 mutex_lock(&qla_cs84xx_mutex);
6836 list_del(&cs84xx->list);
6837 mutex_unlock(&qla_cs84xx_mutex);
6838 kfree(cs84xx);
6839}
6840
6841void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006842qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006843{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006844 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006845 if (ha->cs84xx)
6846 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
6847}
6848
6849static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006850qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006851{
6852 int rval;
6853 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006854 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006855
6856 mutex_lock(&ha->cs84xx->fw_update_mutex);
6857
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006858 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006859
6860 mutex_unlock(&ha->cs84xx->fw_update_mutex);
6861
6862 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
6863 QLA_SUCCESS;
6864}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006865
6866/* 81XX Support **************************************************************/
6867
6868int
6869qla81xx_nvram_config(scsi_qla_host_t *vha)
6870{
6871 int rval;
6872 struct init_cb_81xx *icb;
6873 struct nvram_81xx *nv;
6874 uint32_t *dptr;
6875 uint8_t *dptr1, *dptr2;
6876 uint32_t chksum;
6877 uint16_t cnt;
6878 struct qla_hw_data *ha = vha->hw;
6879
6880 rval = QLA_SUCCESS;
6881 icb = (struct init_cb_81xx *)ha->init_cb;
6882 nv = ha->nvram;
6883
6884 /* Determine NVRAM starting address. */
6885 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006886 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006887 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
6888 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006889
6890 /* Get VPD data into cache */
6891 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006892 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
6893 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006894
6895 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006896 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006897 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006898 dptr = (uint32_t *)nv;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006899 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
6900 chksum += le32_to_cpu(*dptr);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006901
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006902 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
6903 "Contents of NVRAM:\n");
6904 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
6905 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006906
6907 /* Bad NVRAM data, set defaults parameters. */
6908 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6909 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07006910 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006911 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006912 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04006913 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006914 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006915 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006916 ql_log(ql_log_info, vha, 0x0074,
6917 "Falling back to functioning (yet invalid -- WWPN) "
6918 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006919
6920 /*
6921 * Set default initialization control block.
6922 */
6923 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07006924 nv->nvram_version = cpu_to_le16(ICB_VERSION);
6925 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04006926 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07006927 nv->execution_throttle = cpu_to_le16(0xFFFF);
6928 nv->exchange_count = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006929 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006930 nv->port_name[1] = 0x00 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006931 nv->port_name[2] = 0x00;
6932 nv->port_name[3] = 0xe0;
6933 nv->port_name[4] = 0x8b;
6934 nv->port_name[5] = 0x1c;
6935 nv->port_name[6] = 0x55;
6936 nv->port_name[7] = 0x86;
6937 nv->node_name[0] = 0x20;
6938 nv->node_name[1] = 0x00;
6939 nv->node_name[2] = 0x00;
6940 nv->node_name[3] = 0xe0;
6941 nv->node_name[4] = 0x8b;
6942 nv->node_name[5] = 0x1c;
6943 nv->node_name[6] = 0x55;
6944 nv->node_name[7] = 0x86;
Bart Van Asschead950362015-07-09 07:24:08 -07006945 nv->login_retry_count = cpu_to_le16(8);
6946 nv->interrupt_delay_timer = cpu_to_le16(0);
6947 nv->login_timeout = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006948 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07006949 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6950 nv->firmware_options_2 = cpu_to_le32(2 << 4);
6951 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6952 nv->firmware_options_3 = cpu_to_le32(2 << 13);
6953 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6954 nv->efi_parameters = cpu_to_le32(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006955 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07006956 nv->max_luns_per_target = cpu_to_le16(128);
6957 nv->port_down_retry_count = cpu_to_le16(30);
6958 nv->link_down_timeout = cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07006959 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006960 nv->enode_mac[1] = 0xC0;
6961 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006962 nv->enode_mac[3] = 0x04;
6963 nv->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006964 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006965
6966 rval = 1;
6967 }
6968
Arun Easi9e522cd2012-08-22 14:21:31 -04006969 if (IS_T10_PI_CAPABLE(ha))
6970 nv->frame_payload_size &= ~7;
6971
Arun Easiaa230bc2013-01-30 03:34:39 -05006972 qlt_81xx_config_nvram_stage1(vha, nv);
6973
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006974 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07006975 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006976
6977 /* Copy 1st segment. */
6978 dptr1 = (uint8_t *)icb;
6979 dptr2 = (uint8_t *)&nv->version;
6980 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6981 while (cnt--)
6982 *dptr1++ = *dptr2++;
6983
6984 icb->login_retry_count = nv->login_retry_count;
6985
6986 /* Copy 2nd segment. */
6987 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6988 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6989 cnt = (uint8_t *)&icb->reserved_5 -
6990 (uint8_t *)&icb->interrupt_delay_timer;
6991 while (cnt--)
6992 *dptr1++ = *dptr2++;
6993
6994 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
6995 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
6996 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08006997 icb->enode_mac[0] = 0x00;
6998 icb->enode_mac[1] = 0xC0;
6999 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007000 icb->enode_mac[3] = 0x04;
7001 icb->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007002 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007003 }
7004
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07007005 /* Use extended-initialization control block. */
7006 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
7007
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007008 /*
7009 * Setup driver NVRAM options.
7010 */
7011 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07007012 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007013
Arun Easiaa230bc2013-01-30 03:34:39 -05007014 qlt_81xx_config_nvram_stage2(vha, icb);
7015
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007016 /* Use alternate WWN? */
Bart Van Asschead950362015-07-09 07:24:08 -07007017 if (nv->host_p & cpu_to_le32(BIT_15)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007018 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7019 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7020 }
7021
7022 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07007023 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007024 /*
7025 * Firmware will apply the following mask if the nodename was
7026 * not provided.
7027 */
7028 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7029 icb->node_name[0] &= 0xF0;
7030 }
7031
7032 /* Set host adapter parameters. */
7033 ha->flags.disable_risc_code_load = 0;
7034 ha->flags.enable_lip_reset = 0;
7035 ha->flags.enable_lip_full_login =
7036 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
7037 ha->flags.enable_target_reset =
7038 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
7039 ha->flags.enable_led_scheme = 0;
7040 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
7041
7042 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7043 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7044
7045 /* save HBA serial number */
7046 ha->serial0 = icb->port_name[5];
7047 ha->serial1 = icb->port_name[6];
7048 ha->serial2 = icb->port_name[7];
7049 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7050 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7051
Bart Van Asschead950362015-07-09 07:24:08 -07007052 icb->execution_throttle = cpu_to_le16(0xFFFF);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007053
7054 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7055
7056 /* Set minimum login_timeout to 4 seconds. */
7057 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7058 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7059 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07007060 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007061 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007062
7063 /* Set minimum RATOV to 100 tenths of a second. */
7064 ha->r_a_tov = 100;
7065
7066 ha->loop_reset_delay = nv->reset_delay;
7067
7068 /* Link Down Timeout = 0:
7069 *
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007070 * When Port Down timer expires we will start returning
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007071 * I/O's to OS with "DID_NO_CONNECT".
7072 *
7073 * Link Down Timeout != 0:
7074 *
7075 * The driver waits for the link to come up after link down
7076 * before returning I/Os to OS with "DID_NO_CONNECT".
7077 */
7078 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7079 ha->loop_down_abort_time =
7080 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7081 } else {
7082 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7083 ha->loop_down_abort_time =
7084 (LOOP_DOWN_TIME - ha->link_down_timeout);
7085 }
7086
7087 /* Need enough time to try and get the port back. */
7088 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7089 if (qlport_down_retry)
7090 ha->port_down_retry_count = qlport_down_retry;
7091
7092 /* Set login_retry_count */
7093 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7094 if (ha->port_down_retry_count ==
7095 le16_to_cpu(nv->port_down_retry_count) &&
7096 ha->port_down_retry_count > 3)
7097 ha->login_retry_count = ha->port_down_retry_count;
7098 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7099 ha->login_retry_count = ha->port_down_retry_count;
7100 if (ql2xloginretrycount)
7101 ha->login_retry_count = ql2xloginretrycount;
7102
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007103 /* if not running MSI-X we need handshaking on interrupts */
Chad Dupuisf73cb692014-02-26 04:15:06 -05007104 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
Bart Van Asschead950362015-07-09 07:24:08 -07007105 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007106
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007107 /* Enable ZIO. */
7108 if (!vha->flags.init_done) {
7109 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7110 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7111 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7112 le16_to_cpu(icb->interrupt_delay_timer): 2;
7113 }
Bart Van Asschead950362015-07-09 07:24:08 -07007114 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007115 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7116 vha->flags.process_response_queue = 0;
7117 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7118 ha->zio_mode = QLA_ZIO_MODE_6;
7119
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007120 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007121 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007122 ha->zio_mode,
7123 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007124
7125 icb->firmware_options_2 |= cpu_to_le32(
7126 (uint32_t)ha->zio_mode);
7127 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7128 vha->flags.process_response_queue = 1;
7129 }
7130
7131 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007132 ql_log(ql_log_warn, vha, 0x0076,
7133 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007134 }
7135 return (rval);
7136}
7137
Giridhar Malavalia9083012010-04-12 17:59:55 -07007138int
7139qla82xx_restart_isp(scsi_qla_host_t *vha)
7140{
7141 int status, rval;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007142 struct qla_hw_data *ha = vha->hw;
7143 struct req_que *req = ha->req_q_map[0];
7144 struct rsp_que *rsp = ha->rsp_q_map[0];
7145 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07007146 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007147
7148 status = qla2x00_init_rings(vha);
7149 if (!status) {
7150 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7151 ha->flags.chip_reset_done = 1;
7152
7153 status = qla2x00_fw_ready(vha);
7154 if (!status) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07007155 /* Issue a marker after FW becomes ready. */
7156 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007157 vha->flags.online = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04007158 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007159 }
7160
7161 /* if no cable then assume it's good */
7162 if ((vha->device_flags & DFLG_NO_CABLE))
7163 status = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007164 }
7165
7166 if (!status) {
7167 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7168
7169 if (!atomic_read(&vha->loop_down_timer)) {
7170 /*
7171 * Issue marker command only when we are going
7172 * to start the I/O .
7173 */
7174 vha->marker_needed = 1;
7175 }
7176
Giridhar Malavalia9083012010-04-12 17:59:55 -07007177 ha->isp_ops->enable_intrs(ha);
7178
7179 ha->isp_abort_cnt = 0;
7180 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7181
Saurav Kashyap53296782011-05-10 11:30:06 -07007182 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07007183 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07007184
Giridhar Malavalia9083012010-04-12 17:59:55 -07007185 if (ha->fce) {
7186 ha->flags.fce_enabled = 1;
7187 memset(ha->fce, 0,
7188 fce_calc_size(ha->fce_bufs));
7189 rval = qla2x00_enable_fce_trace(vha,
7190 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
7191 &ha->fce_bufs);
7192 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007193 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007194 "Unable to reinitialize FCE (%d).\n",
7195 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007196 ha->flags.fce_enabled = 0;
7197 }
7198 }
7199
7200 if (ha->eft) {
7201 memset(ha->eft, 0, EFT_SIZE);
7202 rval = qla2x00_enable_eft_trace(vha,
7203 ha->eft_dma, EFT_NUM_BUFFERS);
7204 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007205 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007206 "Unable to reinitialize EFT (%d).\n",
7207 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007208 }
7209 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07007210 }
7211
7212 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007213 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007214 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07007215
7216 spin_lock_irqsave(&ha->vport_slock, flags);
7217 list_for_each_entry(vp, &ha->vp_list, list) {
7218 if (vp->vp_idx) {
7219 atomic_inc(&vp->vref_count);
7220 spin_unlock_irqrestore(&ha->vport_slock, flags);
7221
Giridhar Malavalia9083012010-04-12 17:59:55 -07007222 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07007223
7224 spin_lock_irqsave(&ha->vport_slock, flags);
7225 atomic_dec(&vp->vref_count);
7226 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07007227 }
Arun Easifeafb7b2010-09-03 14:57:00 -07007228 spin_unlock_irqrestore(&ha->vport_slock, flags);
7229
Giridhar Malavalia9083012010-04-12 17:59:55 -07007230 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007231 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007232 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07007233 }
7234
7235 return status;
7236}
7237
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007238void
Andrew Vasquezae97c912010-02-18 10:07:28 -08007239qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007240{
Andrew Vasquezae97c912010-02-18 10:07:28 -08007241 struct qla_hw_data *ha = vha->hw;
7242
Himanshu Madhanif198caf2016-01-27 12:03:30 -05007243 /* Hold status IOCBs until ABTS response received. */
7244 if (ql2xfwholdabts)
7245 ha->fw_options[3] |= BIT_12;
7246
Giridhar Malavali088d09d2016-07-06 11:14:20 -04007247 /* Set Retry FLOGI in case of P2P connection */
7248 if (ha->operating_mode == P2P) {
7249 ha->fw_options[2] |= BIT_3;
7250 ql_dbg(ql_dbg_disc, vha, 0x2103,
7251 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
7252 __func__, ha->fw_options[2]);
7253 }
7254
Andrew Vasquezae97c912010-02-18 10:07:28 -08007255 if (!ql2xetsenable)
Himanshu Madhanif198caf2016-01-27 12:03:30 -05007256 goto out;
Andrew Vasquezae97c912010-02-18 10:07:28 -08007257
7258 /* Enable ETS Burst. */
7259 memset(ha->fw_options, 0, sizeof(ha->fw_options));
7260 ha->fw_options[2] |= BIT_9;
Himanshu Madhanif198caf2016-01-27 12:03:30 -05007261out:
Andrew Vasquezae97c912010-02-18 10:07:28 -08007262 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007263}
Sarang Radke09ff7012010-03-19 17:03:59 -07007264
7265/*
7266 * qla24xx_get_fcp_prio
7267 * Gets the fcp cmd priority value for the logged in port.
7268 * Looks for a match of the port descriptors within
7269 * each of the fcp prio config entries. If a match is found,
7270 * the tag (priority) value is returned.
7271 *
7272 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007273 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07007274 * fcport = port structure pointer.
7275 *
7276 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07007277 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007278 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07007279 *
7280 * Context:
7281 * Kernel context
7282 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007283static int
Sarang Radke09ff7012010-03-19 17:03:59 -07007284qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
7285{
7286 int i, entries;
7287 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007288 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07007289 uint32_t pid1, pid2;
7290 uint64_t wwn1, wwn2;
7291 struct qla_fcp_prio_entry *pri_entry;
7292 struct qla_hw_data *ha = vha->hw;
7293
7294 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007295 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07007296
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007297 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07007298 entries = ha->fcp_prio_cfg->num_entries;
7299 pri_entry = &ha->fcp_prio_cfg->entry[0];
7300
7301 for (i = 0; i < entries; i++) {
7302 pid_match = wwn_match = 0;
7303
7304 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
7305 pri_entry++;
7306 continue;
7307 }
7308
7309 /* check source pid for a match */
7310 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
7311 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
7312 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
7313 if (pid1 == INVALID_PORT_ID)
7314 pid_match++;
7315 else if (pid1 == pid2)
7316 pid_match++;
7317 }
7318
7319 /* check destination pid for a match */
7320 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
7321 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
7322 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
7323 if (pid1 == INVALID_PORT_ID)
7324 pid_match++;
7325 else if (pid1 == pid2)
7326 pid_match++;
7327 }
7328
7329 /* check source WWN for a match */
7330 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
7331 wwn1 = wwn_to_u64(vha->port_name);
7332 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
7333 if (wwn2 == (uint64_t)-1)
7334 wwn_match++;
7335 else if (wwn1 == wwn2)
7336 wwn_match++;
7337 }
7338
7339 /* check destination WWN for a match */
7340 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
7341 wwn1 = wwn_to_u64(fcport->port_name);
7342 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
7343 if (wwn2 == (uint64_t)-1)
7344 wwn_match++;
7345 else if (wwn1 == wwn2)
7346 wwn_match++;
7347 }
7348
7349 if (pid_match == 2 || wwn_match == 2) {
7350 /* Found a matching entry */
7351 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
7352 priority = pri_entry->tag;
7353 break;
7354 }
7355
7356 pri_entry++;
7357 }
7358
7359 return priority;
7360}
7361
7362/*
7363 * qla24xx_update_fcport_fcp_prio
7364 * Activates fcp priority for the logged in fc port
7365 *
7366 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007367 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07007368 * fcp = port structure pointer.
7369 *
7370 * Return:
7371 * QLA_SUCCESS or QLA_FUNCTION_FAILED
7372 *
7373 * Context:
7374 * Kernel context.
7375 */
7376int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007377qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07007378{
7379 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007380 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07007381 uint16_t mb[5];
7382
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007383 if (fcport->port_type != FCT_TARGET ||
7384 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07007385 return QLA_FUNCTION_FAILED;
7386
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007387 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007388 if (priority < 0)
7389 return QLA_FUNCTION_FAILED;
7390
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007391 if (IS_P3P_TYPE(vha->hw)) {
Saurav Kashyapa00f6292011-11-18 09:03:19 -08007392 fcport->fcp_prio = priority & 0xf;
7393 return QLA_SUCCESS;
7394 }
7395
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007396 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08007397 if (ret == QLA_SUCCESS) {
7398 if (fcport->fcp_prio != priority)
7399 ql_dbg(ql_dbg_user, vha, 0x709e,
7400 "Updated FCP_CMND priority - value=%d loop_id=%d "
7401 "port_id=%02x%02x%02x.\n", priority,
7402 fcport->loop_id, fcport->d_id.b.domain,
7403 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08007404 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08007405 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007406 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08007407 "Unable to update FCP_CMND priority - ret=0x%x for "
7408 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
7409 fcport->d_id.b.domain, fcport->d_id.b.area,
7410 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07007411 return ret;
7412}
7413
7414/*
7415 * qla24xx_update_all_fcp_prio
7416 * Activates fcp priority for all the logged in ports
7417 *
7418 * Input:
7419 * ha = adapter block pointer.
7420 *
7421 * Return:
7422 * QLA_SUCCESS or QLA_FUNCTION_FAILED
7423 *
7424 * Context:
7425 * Kernel context.
7426 */
7427int
7428qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
7429{
7430 int ret;
7431 fc_port_t *fcport;
7432
7433 ret = QLA_FUNCTION_FAILED;
7434 /* We need to set priority for all logged in ports */
7435 list_for_each_entry(fcport, &vha->vp_fcports, list)
7436 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
7437
7438 return ret;
7439}
Michael Hernandezd7459522016-12-12 14:40:07 -08007440
7441struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos, int vp_idx)
7442{
7443 int rsp_id = 0;
7444 int req_id = 0;
7445 int i;
7446 struct qla_hw_data *ha = vha->hw;
7447 uint16_t qpair_id = 0;
7448 struct qla_qpair *qpair = NULL;
7449 struct qla_msix_entry *msix;
7450
7451 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
7452 ql_log(ql_log_warn, vha, 0x00181,
7453 "FW/Driver is not multi-queue capable.\n");
7454 return NULL;
7455 }
7456
7457 if (ql2xmqsupport) {
7458 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
7459 if (qpair == NULL) {
7460 ql_log(ql_log_warn, vha, 0x0182,
7461 "Failed to allocate memory for queue pair.\n");
7462 return NULL;
7463 }
7464 memset(qpair, 0, sizeof(struct qla_qpair));
7465
7466 qpair->hw = vha->hw;
7467
7468 /* Assign available que pair id */
7469 mutex_lock(&ha->mq_lock);
7470 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
7471 if (qpair_id >= ha->max_qpairs) {
7472 mutex_unlock(&ha->mq_lock);
7473 ql_log(ql_log_warn, vha, 0x0183,
7474 "No resources to create additional q pair.\n");
7475 goto fail_qid_map;
7476 }
7477 set_bit(qpair_id, ha->qpair_qid_map);
7478 ha->queue_pair_map[qpair_id] = qpair;
7479 qpair->id = qpair_id;
7480 qpair->vp_idx = vp_idx;
7481
7482 for (i = 0; i < ha->msix_count; i++) {
Quinn Tran093df732016-12-12 14:40:09 -08007483 msix = &ha->msix_entries[i];
Michael Hernandezd7459522016-12-12 14:40:07 -08007484 if (msix->in_use)
7485 continue;
7486 qpair->msix = msix;
7487 ql_log(ql_dbg_multiq, vha, 0xc00f,
7488 "Vector %x selected for qpair\n", msix->vector);
7489 break;
7490 }
7491 if (!qpair->msix) {
7492 ql_log(ql_log_warn, vha, 0x0184,
7493 "Out of MSI-X vectors!.\n");
7494 goto fail_msix;
7495 }
7496
7497 qpair->msix->in_use = 1;
7498 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
7499
7500 mutex_unlock(&ha->mq_lock);
7501
7502 /* Create response queue first */
7503 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair);
7504 if (!rsp_id) {
7505 ql_log(ql_log_warn, vha, 0x0185,
7506 "Failed to create response queue.\n");
7507 goto fail_rsp;
7508 }
7509
7510 qpair->rsp = ha->rsp_q_map[rsp_id];
7511
7512 /* Create request queue */
7513 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos);
7514 if (!req_id) {
7515 ql_log(ql_log_warn, vha, 0x0186,
7516 "Failed to create request queue.\n");
7517 goto fail_req;
7518 }
7519
7520 qpair->req = ha->req_q_map[req_id];
7521 qpair->rsp->req = qpair->req;
7522
7523 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
7524 if (ha->fw_attributes & BIT_4)
7525 qpair->difdix_supported = 1;
7526 }
7527
7528 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
7529 if (!qpair->srb_mempool) {
7530 ql_log(ql_log_warn, vha, 0x0191,
7531 "Failed to create srb mempool for qpair %d\n",
7532 qpair->id);
7533 goto fail_mempool;
7534 }
7535
7536 /* Mark as online */
7537 qpair->online = 1;
7538
7539 if (!vha->flags.qpairs_available)
7540 vha->flags.qpairs_available = 1;
7541
7542 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
7543 "Request/Response queue pair created, id %d\n",
7544 qpair->id);
7545 ql_dbg(ql_dbg_init, vha, 0x0187,
7546 "Request/Response queue pair created, id %d\n",
7547 qpair->id);
7548 }
7549 return qpair;
7550
7551fail_mempool:
7552fail_req:
7553 qla25xx_delete_rsp_que(vha, qpair->rsp);
7554fail_rsp:
7555 mutex_lock(&ha->mq_lock);
7556 qpair->msix->in_use = 0;
7557 list_del(&qpair->qp_list_elem);
7558 if (list_empty(&vha->qp_list))
7559 vha->flags.qpairs_available = 0;
7560fail_msix:
7561 ha->queue_pair_map[qpair_id] = NULL;
7562 clear_bit(qpair_id, ha->qpair_qid_map);
7563 mutex_unlock(&ha->mq_lock);
7564fail_qid_map:
7565 kfree(qpair);
7566 return NULL;
7567}
7568
7569int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
7570{
7571 int ret;
7572 struct qla_hw_data *ha = qpair->hw;
7573
7574 qpair->delete_in_progress = 1;
7575 while (atomic_read(&qpair->ref_count))
7576 msleep(500);
7577
7578 ret = qla25xx_delete_req_que(vha, qpair->req);
7579 if (ret != QLA_SUCCESS)
7580 goto fail;
7581 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
7582 if (ret != QLA_SUCCESS)
7583 goto fail;
7584
7585 mutex_lock(&ha->mq_lock);
7586 ha->queue_pair_map[qpair->id] = NULL;
7587 clear_bit(qpair->id, ha->qpair_qid_map);
7588 list_del(&qpair->qp_list_elem);
7589 if (list_empty(&vha->qp_list))
7590 vha->flags.qpairs_available = 0;
7591 mempool_destroy(qpair->srb_mempool);
7592 kfree(qpair);
7593 mutex_unlock(&ha->mq_lock);
7594
7595 return QLA_SUCCESS;
7596fail:
7597 return ret;
7598}