blob: ef61a241a350350df845f0564b8b3117f41ce3c2 [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 *);
33static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
35 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Harihara Kadayam4d4df192008-04-03 13:13:26 -070039static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
40static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080041static int qla25xx_init_queues(struct qla_hw_data *);
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;
Andrew Vasquezac280b62009-08-20 11:06:05 -070050 fc_port_t *fcport = sp->fcport;
51 struct qla_hw_data *ha = fcport->vha->hw;
52 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);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080060 sp->free(fcport->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
97static void
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;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700102
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700103 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800104 "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800105 sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700106 fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700107
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700108 fcport->flags &= ~FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800109 if (sp->type == SRB_LOGIN_CMD) {
110 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700111 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700112 /* Retry as needed. */
113 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
114 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
115 QLA_LOGIO_LOGIN_RETRIED : 0;
116 qla2x00_post_async_login_done_work(fcport->vha, fcport,
117 lio->u.logio.data);
Alexei Potashnika6ca8872015-07-14 16:00:44 -0400118 } else if (sp->type == SRB_LOGOUT_CMD) {
119 qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT);
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700120 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700121}
122
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700123static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800124qla2x00_async_login_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700125{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800126 srb_t *sp = (srb_t *)ptr;
127 struct srb_iocb *lio = &sp->u.iocb_cmd;
128 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700129
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800130 if (!test_bit(UNLOADING, &vha->dpc_flags))
131 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
132 lio->u.logio.data);
133 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700134}
135
Andrew Vasquezac280b62009-08-20 11:06:05 -0700136int
137qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
138 uint16_t *data)
139{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700140 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700141 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700142 int rval;
143
144 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800145 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700146 if (!sp)
147 goto done;
148
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800149 sp->type = SRB_LOGIN_CMD;
150 sp->name = "login";
151 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
152
153 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700154 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800155 sp->done = qla2x00_async_login_sp_done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700156 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700157 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700158 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700159 rval = qla2x00_start_sp(sp);
160 if (rval != QLA_SUCCESS)
161 goto done_free_sp;
162
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700163 ql_dbg(ql_dbg_disc, vha, 0x2072,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800164 "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
165 "retries=%d.\n", sp->handle, fcport->loop_id,
166 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
167 fcport->login_retry);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700168 return rval;
169
170done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800171 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700172done:
173 return rval;
174}
175
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700176static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800177qla2x00_async_logout_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700178{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800179 srb_t *sp = (srb_t *)ptr;
180 struct srb_iocb *lio = &sp->u.iocb_cmd;
181 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700182
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800183 if (!test_bit(UNLOADING, &vha->dpc_flags))
184 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
185 lio->u.logio.data);
186 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700187}
188
Andrew Vasquezac280b62009-08-20 11:06:05 -0700189int
190qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
191{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700192 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700193 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700194 int rval;
195
196 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800197 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700198 if (!sp)
199 goto done;
200
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800201 sp->type = SRB_LOGOUT_CMD;
202 sp->name = "logout";
203 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
204
205 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700206 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800207 sp->done = qla2x00_async_logout_sp_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700208 rval = qla2x00_start_sp(sp);
209 if (rval != QLA_SUCCESS)
210 goto done_free_sp;
211
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700212 ql_dbg(ql_dbg_disc, vha, 0x2070,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800213 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
214 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
215 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700216 return rval;
217
218done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800219 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700220done:
221 return rval;
222}
223
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700224static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800225qla2x00_async_adisc_sp_done(void *data, void *ptr, int res)
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700226{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800227 srb_t *sp = (srb_t *)ptr;
228 struct srb_iocb *lio = &sp->u.iocb_cmd;
229 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700230
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800231 if (!test_bit(UNLOADING, &vha->dpc_flags))
232 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
233 lio->u.logio.data);
234 sp->free(sp->fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700235}
236
237int
238qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
239 uint16_t *data)
240{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700241 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700242 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700243 int rval;
244
245 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800246 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700247 if (!sp)
248 goto done;
249
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800250 sp->type = SRB_ADISC_CMD;
251 sp->name = "adisc";
252 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
253
254 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700255 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800256 sp->done = qla2x00_async_adisc_sp_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700257 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700258 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700259 rval = qla2x00_start_sp(sp);
260 if (rval != QLA_SUCCESS)
261 goto done_free_sp;
262
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700263 ql_dbg(ql_dbg_disc, vha, 0x206f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800264 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
265 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
266 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700267 return rval;
268
269done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800270 sp->free(fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700271done:
272 return rval;
273}
274
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700275static void
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500276qla2x00_tmf_iocb_timeout(void *data)
277{
278 srb_t *sp = (srb_t *)data;
279 struct srb_iocb *tmf = &sp->u.iocb_cmd;
280
281 tmf->u.tmf.comp_status = CS_TIMEOUT;
282 complete(&tmf->u.tmf.comp);
283}
284
285static void
286qla2x00_tmf_sp_done(void *data, void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700287{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800288 srb_t *sp = (srb_t *)ptr;
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500289 struct srb_iocb *tmf = &sp->u.iocb_cmd;
290 complete(&tmf->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700291}
292
293int
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500294qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700295 uint32_t tag)
296{
297 struct scsi_qla_host *vha = fcport->vha;
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500298 struct srb_iocb *tm_iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700299 srb_t *sp;
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500300 int rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700301
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800302 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700303 if (!sp)
304 goto done;
305
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500306 tm_iocb = &sp->u.iocb_cmd;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800307 sp->type = SRB_TM_CMD;
308 sp->name = "tmf";
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500309 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
310 tm_iocb->u.tmf.flags = flags;
311 tm_iocb->u.tmf.lun = lun;
312 tm_iocb->u.tmf.data = tag;
313 sp->done = qla2x00_tmf_sp_done;
314 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
315 init_completion(&tm_iocb->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700316
317 rval = qla2x00_start_sp(sp);
318 if (rval != QLA_SUCCESS)
319 goto done_free_sp;
320
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700321 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800322 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
323 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
324 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500325
326 wait_for_completion(&tm_iocb->u.tmf.comp);
327
328 rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
329 QLA_SUCCESS : QLA_FUNCTION_FAILED;
330
331 if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
332 ql_dbg(ql_dbg_taskm, vha, 0x8030,
333 "TM IOCB failed (%x).\n", rval);
334 }
335
336 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
337 flags = tm_iocb->u.tmf.flags;
338 lun = (uint16_t)tm_iocb->u.tmf.lun;
339
340 /* Issue Marker IOCB */
341 qla2x00_marker(vha, vha->hw->req_q_map[0],
342 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
343 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
344 }
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700345
346done_free_sp:
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500347 sp->free(vha, sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700348done:
349 return rval;
350}
351
Armen Baloyan4440e462014-02-26 04:15:18 -0500352static void
353qla24xx_abort_iocb_timeout(void *data)
354{
355 srb_t *sp = (srb_t *)data;
356 struct srb_iocb *abt = &sp->u.iocb_cmd;
357
358 abt->u.abt.comp_status = CS_TIMEOUT;
359 complete(&abt->u.abt.comp);
360}
361
362static void
363qla24xx_abort_sp_done(void *data, void *ptr, int res)
364{
365 srb_t *sp = (srb_t *)ptr;
366 struct srb_iocb *abt = &sp->u.iocb_cmd;
367
368 complete(&abt->u.abt.comp);
369}
370
371static int
372qla24xx_async_abort_cmd(srb_t *cmd_sp)
373{
374 scsi_qla_host_t *vha = cmd_sp->fcport->vha;
375 fc_port_t *fcport = cmd_sp->fcport;
376 struct srb_iocb *abt_iocb;
377 srb_t *sp;
378 int rval = QLA_FUNCTION_FAILED;
379
380 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
381 if (!sp)
382 goto done;
383
384 abt_iocb = &sp->u.iocb_cmd;
385 sp->type = SRB_ABT_CMD;
386 sp->name = "abort";
387 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
388 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
389 sp->done = qla24xx_abort_sp_done;
390 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
391 init_completion(&abt_iocb->u.abt.comp);
392
393 rval = qla2x00_start_sp(sp);
394 if (rval != QLA_SUCCESS)
395 goto done_free_sp;
396
397 ql_dbg(ql_dbg_async, vha, 0x507c,
398 "Abort command issued - hdl=%x, target_id=%x\n",
399 cmd_sp->handle, fcport->tgt_id);
400
401 wait_for_completion(&abt_iocb->u.abt.comp);
402
403 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
404 QLA_SUCCESS : QLA_FUNCTION_FAILED;
405
406done_free_sp:
407 sp->free(vha, sp);
408done:
409 return rval;
410}
411
412int
413qla24xx_async_abort_command(srb_t *sp)
414{
415 unsigned long flags = 0;
416
417 uint32_t handle;
418 fc_port_t *fcport = sp->fcport;
419 struct scsi_qla_host *vha = fcport->vha;
420 struct qla_hw_data *ha = vha->hw;
421 struct req_que *req = vha->req;
422
423 spin_lock_irqsave(&ha->hardware_lock, flags);
424 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
425 if (req->outstanding_cmds[handle] == sp)
426 break;
427 }
428 spin_unlock_irqrestore(&ha->hardware_lock, flags);
429 if (handle == req->num_outstanding_cmds) {
430 /* Command not found. */
431 return QLA_FUNCTION_FAILED;
432 }
433 if (sp->type == SRB_FXIOCB_DCMD)
434 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
435 FXDISC_ABORT_IOCTL);
436
437 return qla24xx_async_abort_cmd(sp);
438}
439
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700440void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700441qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
442 uint16_t *data)
443{
444 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700445
446 switch (data[0]) {
447 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700448 /*
449 * Driver must validate login state - If PRLI not complete,
450 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
451 * requests.
452 */
453 rval = qla2x00_get_port_database(vha, fcport, 0);
Arun Easi0eba25d2012-02-09 11:15:58 -0800454 if (rval == QLA_NOT_LOGGED_IN) {
455 fcport->flags &= ~FCF_ASYNC_SENT;
456 fcport->flags |= FCF_LOGIN_NEEDED;
457 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
458 break;
459 }
460
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700461 if (rval != QLA_SUCCESS) {
462 qla2x00_post_async_logout_work(vha, fcport, NULL);
463 qla2x00_post_async_login_work(vha, fcport, NULL);
464 break;
465 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700466 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700467 qla2x00_post_async_adisc_work(vha, fcport, data);
468 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700469 }
470 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700471 break;
472 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700473 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700474 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
475 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
476 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700477 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700478 break;
479 case MBS_PORT_ID_USED:
480 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700481 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700482 qla2x00_post_async_login_work(vha, fcport, NULL);
483 break;
484 case MBS_LOOP_ID_USED:
485 fcport->loop_id++;
486 rval = qla2x00_find_new_loop_id(vha, fcport);
487 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700488 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez80d79442011-03-30 11:46:17 -0700489 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700490 break;
491 }
492 qla2x00_post_async_login_work(vha, fcport, NULL);
493 break;
494 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700495 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700496}
497
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700498void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700499qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
500 uint16_t *data)
501{
Alexei Potashnika6ca8872015-07-14 16:00:44 -0400502 /* Don't re-login in target mode */
503 if (!fcport->tgt_session)
504 qla2x00_mark_device_lost(vha, fcport, 1, 0);
505 qlt_logo_completion_handler(fcport, data[0]);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700506 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700507}
508
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700509void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700510qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
511 uint16_t *data)
512{
513 if (data[0] == MBS_COMMAND_COMPLETE) {
514 qla2x00_update_fcport(vha, fcport);
515
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700516 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700517 }
518
519 /* Retry login. */
520 fcport->flags &= ~FCF_ASYNC_SENT;
521 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
522 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
523 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700524 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700525
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700526 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700527}
528
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529/****************************************************************************/
530/* QLogic ISP2x00 Hardware Support Functions. */
531/****************************************************************************/
532
Saurav Kashyapfa492632012-11-21 02:40:29 -0500533static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400534qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
535{
536 int rval = QLA_SUCCESS;
537 struct qla_hw_data *ha = vha->hw;
538 uint32_t idc_major_ver, idc_minor_ver;
Saurav Kashyap711aa7f2012-08-22 14:21:15 -0400539 uint16_t config[4];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400540
541 qla83xx_idc_lock(vha, 0);
542
543 /* SV: TODO: Assign initialization timeout from
544 * flash-info / other param
545 */
546 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
547 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
548
549 /* Set our fcoe function presence */
550 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
551 ql_dbg(ql_dbg_p3p, vha, 0xb077,
552 "Error while setting DRV-Presence.\n");
553 rval = QLA_FUNCTION_FAILED;
554 goto exit;
555 }
556
557 /* Decide the reset ownership */
558 qla83xx_reset_ownership(vha);
559
560 /*
561 * On first protocol driver load:
562 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
563 * register.
564 * Others: Check compatibility with current IDC Major version.
565 */
566 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
567 if (ha->flags.nic_core_reset_owner) {
568 /* Set IDC Major version */
569 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
570 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
571
572 /* Clearing IDC-Lock-Recovery register */
573 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
574 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
575 /*
576 * Clear further IDC participation if we are not compatible with
577 * the current IDC Major Version.
578 */
579 ql_log(ql_log_warn, vha, 0xb07d,
580 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
581 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
582 __qla83xx_clear_drv_presence(vha);
583 rval = QLA_FUNCTION_FAILED;
584 goto exit;
585 }
586 /* Each function sets its supported Minor version. */
587 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
588 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
589 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
590
Saurav Kashyap711aa7f2012-08-22 14:21:15 -0400591 if (ha->flags.nic_core_reset_owner) {
592 memset(config, 0, sizeof(config));
593 if (!qla81xx_get_port_config(vha, config))
594 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
595 QLA8XXX_DEV_READY);
596 }
597
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400598 rval = qla83xx_idc_state_handler(vha);
599
600exit:
601 qla83xx_idc_unlock(vha, 0);
602
603 return rval;
604}
605
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606/*
607* qla2x00_initialize_adapter
608* Initialize board.
609*
610* Input:
611* ha = adapter block pointer.
612*
613* Returns:
614* 0 = success
615*/
616int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800617qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618{
619 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800620 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800621 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800624 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700625 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800626 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800627 ha->flags.pci_channel_io_perm_failure = 0;
628 ha->flags.eeh_busy = 0;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -0400629 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800630 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
631 atomic_set(&vha->loop_state, LOOP_DOWN);
632 vha->device_flags = DFLG_NO_CABLE;
633 vha->dpc_flags = 0;
634 vha->flags.management_server_logged_in = 0;
635 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 ha->isp_abort_cnt = 0;
637 ha->beacon_blink_led = 0;
638
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800639 set_bit(0, ha->req_qid_map);
640 set_bit(0, ha->rsp_qid_map);
641
Chad Dupuiscfb09192011-11-18 09:03:07 -0800642 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700643 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800644 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700646 ql_log(ql_log_warn, vha, 0x0044,
647 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 return (rval);
649 }
650
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800651 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800653 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700654 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700655 ql_log(ql_log_fatal, vha, 0x004f,
656 "Unable to validate FLASH data.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400657 return rval;
658 }
659
660 if (IS_QLA8044(ha)) {
661 qla8044_read_reset_template(vha);
662
663 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
664 * If DONRESET_BIT0 is set, drivers should not set dev_state
665 * to NEED_RESET. But if NEED_RESET is set, drivers should
666 * should honor the reset. */
667 if (ql2xdontresethba == 1)
668 qla8044_set_idc_dontreset(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700669 }
670
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800671 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -0800672 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700673 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700674
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800675 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700677 if (ha->flags.disable_serdes) {
678 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700679 ql_log(ql_log_info, vha, 0x0077,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -0400680 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700681 return QLA_FUNCTION_FAILED;
682 }
683
Chad Dupuiscfb09192011-11-18 09:03:07 -0800684 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700685 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800687 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
688 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800689 if (rval)
690 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800691 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800692 if (rval)
693 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700695
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700696 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800697 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700698 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700699 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700700 "Unable to configure ISP84XX.\n");
701 return QLA_FUNCTION_FAILED;
702 }
703 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400704
705 if (qla_ini_mode_enabled(vha))
706 rval = qla2x00_init_rings(vha);
707
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700708 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800710 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700711 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800712 rval = qla84xx_init_chip(vha);
713 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700714 ql_log(ql_log_warn, vha, 0x00d4,
715 "Unable to initialize ISP84XX.\n");
Bart Van Assche8d2b21d2015-06-04 15:58:09 -0700716 qla84xx_put_chip(vha);
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800717 }
718 }
719
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400720 /* Load the NIC Core f/w if we are the first protocol driver. */
721 if (IS_QLA8031(ha)) {
722 rval = qla83xx_nic_core_fw_load(vha);
723 if (rval)
724 ql_log(ql_log_warn, vha, 0x0124,
725 "Error in initializing NIC Core f/w.\n");
726 }
727
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500728 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
729 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700730
Joe Carnuccioc46e65c2013-08-27 01:37:35 -0400731 if (IS_P3P_TYPE(ha))
732 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
733 else
734 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 return (rval);
737}
738
739/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700740 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 * @ha: HA context
742 *
743 * Returns 0 on success.
744 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700745int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800746qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700748 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700749 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800750 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700751 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700754 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700757 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
759
Andrew Vasquez737faec2008-10-24 15:13:45 -0700760 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700762 /* Get PCI bus information. */
763 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700764 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700765 spin_unlock_irqrestore(&ha->hardware_lock, flags);
766
767 return QLA_SUCCESS;
768}
769
770/**
771 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
772 * @ha: HA context
773 *
774 * Returns 0 on success.
775 */
776int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800777qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700778{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700779 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700780 unsigned long flags = 0;
781 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800782 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700783 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700784
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700785 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700786 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700787
788 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700789 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700790
791 if (IS_QLA2322(ha) || IS_QLA6322(ha))
792 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700793 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700794
795 /*
796 * If this is a 2300 card and not 2312, reset the
797 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
798 * the 2310 also reports itself as a 2300 so we need to get the
799 * fb revision level -- a 6 indicates it really is a 2300 and
800 * not a 2310.
801 */
802 if (IS_QLA2300(ha)) {
803 spin_lock_irqsave(&ha->hardware_lock, flags);
804
805 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700806 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700807 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700808 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700809 break;
810
811 udelay(10);
812 }
813
814 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700815 WRT_REG_WORD(&reg->ctrl_status, 0x20);
816 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700817
818 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700819 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700820
821 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700822 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700823
824 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700825 WRT_REG_WORD(&reg->ctrl_status, 0x0);
826 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700827
828 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700829 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700830 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700831 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700832 break;
833
834 udelay(10);
835 }
836
837 spin_unlock_irqrestore(&ha->hardware_lock, flags);
838 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700839
840 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
841
Andrew Vasquez737faec2008-10-24 15:13:45 -0700842 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700843
844 /* Get PCI bus information. */
845 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700846 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700847 spin_unlock_irqrestore(&ha->hardware_lock, flags);
848
849 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850}
851
852/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700853 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
854 * @ha: HA context
855 *
856 * Returns 0 on success.
857 */
858int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800859qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700860{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700861 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700862 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800863 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700864 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700865
866 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700867 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700868
869 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700870 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700871 w &= ~PCI_COMMAND_INTX_DISABLE;
872 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
873
874 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
875
876 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700877 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
878 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700879
880 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700881 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -0400882 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700883
Andrew Vasquez737faec2008-10-24 15:13:45 -0700884 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700885
Auke Kok44c10132007-06-08 15:46:36 -0700886 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800887
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700888 /* Get PCI bus information. */
889 spin_lock_irqsave(&ha->hardware_lock, flags);
890 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
891 spin_unlock_irqrestore(&ha->hardware_lock, flags);
892
893 return QLA_SUCCESS;
894}
895
896/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700897 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
898 * @ha: HA context
899 *
900 * Returns 0 on success.
901 */
902int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800903qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700904{
905 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800906 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700907
908 pci_set_master(ha->pdev);
909 pci_try_set_mwi(ha->pdev);
910
911 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
912 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
913 w &= ~PCI_COMMAND_INTX_DISABLE;
914 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
915
916 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700917 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -0400918 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700919
Andrew Vasquez737faec2008-10-24 15:13:45 -0700920 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700921
922 ha->chip_revision = ha->pdev->revision;
923
924 return QLA_SUCCESS;
925}
926
927/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 * qla2x00_isp_firmware() - Choose firmware image.
929 * @ha: HA context
930 *
931 * Returns 0 on success.
932 */
933static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800934qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935{
936 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700937 uint16_t loop_id, topo, sw_cap;
938 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800939 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700942 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
944 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700945 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
947 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800948 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700949 if (rval == QLA_SUCCESS) {
950 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800951 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700952 &area, &domain, &topo, &sw_cap);
953 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 }
955
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700956 if (rval)
957 ql_dbg(ql_dbg_init, vha, 0x007a,
958 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
960 return (rval);
961}
962
963/**
964 * qla2x00_reset_chip() - Reset ISP chip.
965 * @ha: HA context
966 *
967 * Returns 0 on success.
968 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700969void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800970qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971{
972 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800973 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700974 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 uint16_t cmd;
977
Andrew Vasquez85880802009-12-15 21:29:46 -0800978 if (unlikely(pci_channel_offline(ha->pdev)))
979 return;
980
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700981 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983 spin_lock_irqsave(&ha->hardware_lock, flags);
984
985 /* Turn off master enable */
986 cmd = 0;
987 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
988 cmd &= ~PCI_COMMAND_MASTER;
989 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
990
991 if (!IS_QLA2100(ha)) {
992 /* Pause RISC. */
993 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
994 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
995 for (cnt = 0; cnt < 30000; cnt++) {
996 if ((RD_REG_WORD(&reg->hccr) &
997 HCCR_RISC_PAUSE) != 0)
998 break;
999 udelay(100);
1000 }
1001 } else {
1002 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1003 udelay(10);
1004 }
1005
1006 /* Select FPM registers. */
1007 WRT_REG_WORD(&reg->ctrl_status, 0x20);
1008 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1009
1010 /* FPM Soft Reset. */
1011 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
1012 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
1013
1014 /* Toggle Fpm Reset. */
1015 if (!IS_QLA2200(ha)) {
1016 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
1017 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
1018 }
1019
1020 /* Select frame buffer registers. */
1021 WRT_REG_WORD(&reg->ctrl_status, 0x10);
1022 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1023
1024 /* Reset frame buffer FIFOs. */
1025 if (IS_QLA2200(ha)) {
1026 WRT_FB_CMD_REG(ha, reg, 0xa000);
1027 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
1028 } else {
1029 WRT_FB_CMD_REG(ha, reg, 0x00fc);
1030
1031 /* Read back fb_cmd until zero or 3 seconds max */
1032 for (cnt = 0; cnt < 3000; cnt++) {
1033 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
1034 break;
1035 udelay(100);
1036 }
1037 }
1038
1039 /* Select RISC module registers. */
1040 WRT_REG_WORD(&reg->ctrl_status, 0);
1041 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1042
1043 /* Reset RISC processor. */
1044 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1045 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1046
1047 /* Release RISC processor. */
1048 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1049 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1050 }
1051
1052 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
1053 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
1054
1055 /* Reset ISP chip. */
1056 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1057
1058 /* Wait for RISC to recover from reset. */
1059 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1060 /*
1061 * It is necessary to for a delay here since the card doesn't
1062 * respond to PCI reads during a reset. On some architectures
1063 * this will result in an MCA.
1064 */
1065 udelay(20);
1066 for (cnt = 30000; cnt; cnt--) {
1067 if ((RD_REG_WORD(&reg->ctrl_status) &
1068 CSR_ISP_SOFT_RESET) == 0)
1069 break;
1070 udelay(100);
1071 }
1072 } else
1073 udelay(10);
1074
1075 /* Reset RISC processor. */
1076 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1077
1078 WRT_REG_WORD(&reg->semaphore, 0);
1079
1080 /* Release RISC processor. */
1081 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1082 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1083
1084 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1085 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -07001086 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
1089 udelay(100);
1090 }
1091 } else
1092 udelay(100);
1093
1094 /* Turn on master enable */
1095 cmd |= PCI_COMMAND_MASTER;
1096 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
1097
1098 /* Disable RISC pause on FPM parity error. */
1099 if (!IS_QLA2100(ha)) {
1100 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
1101 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1102 }
1103
1104 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1105}
1106
1107/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001108 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
1109 *
1110 * Returns 0 on success.
1111 */
Saurav Kashyapfa492632012-11-21 02:40:29 -05001112static int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001113qla81xx_reset_mpi(scsi_qla_host_t *vha)
1114{
1115 uint16_t mb[4] = {0x1010, 0, 1, 0};
1116
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001117 if (!IS_QLA81XX(vha->hw))
1118 return QLA_SUCCESS;
1119
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001120 return qla81xx_write_mpi_register(vha, mb);
1121}
1122
1123/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001124 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001125 * @ha: HA context
1126 *
1127 * Returns 0 on success.
1128 */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001129static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001130qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001131{
1132 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001133 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001134 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Bart Van Assche52c82822015-07-09 07:23:26 -07001135 uint32_t cnt;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001136 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001137 static int abts_cnt; /* ISP abort retry counts */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001138 int rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001139
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001140 spin_lock_irqsave(&ha->hardware_lock, flags);
1141
1142 /* Reset RISC. */
1143 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1144 for (cnt = 0; cnt < 30000; cnt++) {
1145 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
1146 break;
1147
1148 udelay(10);
1149 }
1150
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001151 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE))
1152 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
1153
1154 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
1155 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
1156 RD_REG_DWORD(&reg->hccr),
1157 RD_REG_DWORD(&reg->ctrl_status),
1158 (RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE));
1159
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001160 WRT_REG_DWORD(&reg->ctrl_status,
1161 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001162 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001163
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001164 udelay(100);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001165
Andrew Vasquez88c26662005-07-08 17:59:26 -07001166 /* Wait for firmware to complete NVRAM accesses. */
Bart Van Assche52c82822015-07-09 07:23:26 -07001167 RD_REG_WORD(&reg->mailbox0);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001168 for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
1169 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez88c26662005-07-08 17:59:26 -07001170 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001171 if (cnt)
1172 udelay(5);
1173 else
1174 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez88c26662005-07-08 17:59:26 -07001175 }
1176
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001177 if (rval == QLA_SUCCESS)
1178 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
1179
1180 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
1181 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
1182 RD_REG_DWORD(&reg->hccr),
1183 RD_REG_DWORD(&reg->mailbox0));
1184
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001185 /* Wait for soft-reset to complete. */
Bart Van Assche52c82822015-07-09 07:23:26 -07001186 RD_REG_DWORD(&reg->ctrl_status);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001187 for (cnt = 0; cnt < 6000000; cnt++) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001188 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001189 if ((RD_REG_DWORD(&reg->ctrl_status) &
1190 CSRX_ISP_SOFT_RESET) == 0)
1191 break;
1192
1193 udelay(5);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001194 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001195 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_ISP_SOFT_RESET))
1196 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
1197
1198 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
1199 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
1200 RD_REG_DWORD(&reg->hccr),
1201 RD_REG_DWORD(&reg->ctrl_status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001202
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001203 /* If required, do an MPI FW reset now */
1204 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1205 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1206 if (++abts_cnt < 5) {
1207 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1208 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1209 } else {
1210 /*
1211 * We exhausted the ISP abort retries. We have to
1212 * set the board offline.
1213 */
1214 abts_cnt = 0;
1215 vha->flags.online = 0;
1216 }
1217 }
1218 }
1219
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001220 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1221 RD_REG_DWORD(&reg->hccr);
1222
1223 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1224 RD_REG_DWORD(&reg->hccr);
1225
1226 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1227 RD_REG_DWORD(&reg->hccr);
1228
Bart Van Assche52c82822015-07-09 07:23:26 -07001229 RD_REG_WORD(&reg->mailbox0);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001230 for (cnt = 6000000; RD_REG_WORD(&reg->mailbox0) != 0 &&
1231 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001232 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001233 if (cnt)
1234 udelay(5);
1235 else
1236 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001237 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001238 if (rval == QLA_SUCCESS)
1239 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
1240
1241 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
1242 "Host Risc 0x%x, mailbox0 0x%x\n",
1243 RD_REG_DWORD(&reg->hccr),
1244 RD_REG_WORD(&reg->mailbox0));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001245
1246 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001247
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001248 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
1249 "Driver in %s mode\n",
1250 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
1251
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001252 if (IS_NOPOLLING_TYPE(ha))
1253 ha->isp_ops->enable_intrs(ha);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001254
1255 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001256}
1257
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001258static void
1259qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
1260{
1261 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1262
1263 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1264 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
1265
1266}
1267
1268static void
1269qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
1270{
1271 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1272
1273 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1274 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
1275}
1276
1277static void
1278qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
1279{
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001280 uint32_t wd32 = 0;
1281 uint delta_msec = 100;
1282 uint elapsed_msec = 0;
1283 uint timeout_msec;
1284 ulong n;
1285
Joe Carnucciocc790762015-08-04 13:37:53 -04001286 if (vha->hw->pdev->subsystem_device != 0x0175 &&
1287 vha->hw->pdev->subsystem_device != 0x0240)
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001288 return;
1289
Joe Carnuccio8dd7e3a2015-08-04 13:37:54 -04001290 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
1291 udelay(100);
1292
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001293attempt:
1294 timeout_msec = TIMEOUT_SEMAPHORE;
1295 n = timeout_msec / delta_msec;
1296 while (n--) {
1297 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
1298 qla25xx_read_risc_sema_reg(vha, &wd32);
1299 if (wd32 & RISC_SEMAPHORE)
1300 break;
1301 msleep(delta_msec);
1302 elapsed_msec += delta_msec;
1303 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1304 goto force;
1305 }
1306
1307 if (!(wd32 & RISC_SEMAPHORE))
1308 goto force;
1309
1310 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1311 goto acquired;
1312
1313 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
1314 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
1315 n = timeout_msec / delta_msec;
1316 while (n--) {
1317 qla25xx_read_risc_sema_reg(vha, &wd32);
1318 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1319 break;
1320 msleep(delta_msec);
1321 elapsed_msec += delta_msec;
1322 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1323 goto force;
1324 }
1325
1326 if (wd32 & RISC_SEMAPHORE_FORCE)
1327 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
1328
1329 goto attempt;
1330
1331force:
1332 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
1333
1334acquired:
1335 return;
1336}
1337
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001338/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001339 * qla24xx_reset_chip() - Reset ISP24xx chip.
1340 * @ha: HA context
1341 *
1342 * Returns 0 on success.
1343 */
1344void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001345qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001346{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001347 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001348
1349 if (pci_channel_offline(ha->pdev) &&
1350 ha->flags.pci_channel_io_perm_failure) {
1351 return;
1352 }
1353
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001354 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001355
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001356 qla25xx_manipulate_risc_semaphore(vha);
1357
Andrew Vasquez88c26662005-07-08 17:59:26 -07001358 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001359 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001360}
1361
1362/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 * qla2x00_chip_diag() - Test chip for proper operation.
1364 * @ha: HA context
1365 *
1366 * Returns 0 on success.
1367 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001368int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001369qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370{
1371 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001372 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001373 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 unsigned long flags = 0;
1375 uint16_t data;
1376 uint32_t cnt;
1377 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001378 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
1380 /* Assume a failed state */
1381 rval = QLA_FUNCTION_FAILED;
1382
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001383 ql_dbg(ql_dbg_init, vha, 0x007b,
1384 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
1386 spin_lock_irqsave(&ha->hardware_lock, flags);
1387
1388 /* Reset ISP chip. */
1389 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1390
1391 /*
1392 * We need to have a delay here since the card will not respond while
1393 * in reset causing an MCA on some architectures.
1394 */
1395 udelay(20);
1396 data = qla2x00_debounce_register(&reg->ctrl_status);
1397 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1398 udelay(5);
1399 data = RD_REG_WORD(&reg->ctrl_status);
1400 barrier();
1401 }
1402
1403 if (!cnt)
1404 goto chip_diag_failed;
1405
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001406 ql_dbg(ql_dbg_init, vha, 0x007c,
1407 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
1409 /* Reset RISC processor. */
1410 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1411 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1412
1413 /* Workaround for QLA2312 PCI parity error */
1414 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1415 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1416 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1417 udelay(5);
1418 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001419 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 }
1421 } else
1422 udelay(10);
1423
1424 if (!cnt)
1425 goto chip_diag_failed;
1426
1427 /* Check product ID of chip */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001428 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
1430 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1431 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1432 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1433 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1434 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1435 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001436 ql_log(ql_log_warn, vha, 0x0062,
1437 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1438 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
1440 goto chip_diag_failed;
1441 }
1442 ha->product_id[0] = mb[1];
1443 ha->product_id[1] = mb[2];
1444 ha->product_id[2] = mb[3];
1445 ha->product_id[3] = mb[4];
1446
1447 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001448 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1450 else
1451 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001452 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
1454 if (IS_QLA2200(ha) &&
1455 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1456 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001457 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001459 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 ha->fw_transfer_size = 128;
1461 }
1462
1463 /* Wrap Incoming Mailboxes Test. */
1464 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1465
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001466 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001467 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001468 if (rval)
1469 ql_log(ql_log_warn, vha, 0x0080,
1470 "Failed mailbox send register test.\n");
1471 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 /* Flag a successful rval */
1473 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 spin_lock_irqsave(&ha->hardware_lock, flags);
1475
1476chip_diag_failed:
1477 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001478 ql_log(ql_log_info, vha, 0x0081,
1479 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
1481 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1482
1483 return (rval);
1484}
1485
1486/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001487 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1488 * @ha: HA context
1489 *
1490 * Returns 0 on success.
1491 */
1492int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001493qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001494{
1495 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001496 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001497 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001498
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001499 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07001500 return QLA_SUCCESS;
1501
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001502 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001503
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001504 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001505 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001506 ql_log(ql_log_warn, vha, 0x0082,
1507 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001508 } else {
1509 /* Flag a successful rval */
1510 rval = QLA_SUCCESS;
1511 }
1512
1513 return rval;
1514}
1515
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001516void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001517qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001518{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001519 int rval;
1520 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001521 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001522 dma_addr_t tc_dma;
1523 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001524 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001525 struct req_que *req = ha->req_q_map[0];
1526 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001527
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001528 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001529 ql_dbg(ql_dbg_init, vha, 0x00bd,
1530 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001531 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001532 }
1533
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001534 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04001535 ha->fw_dump_cap_flags = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001536 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
1537 req_q_size = rsp_q_size = 0;
1538
1539 if (IS_QLA27XX(ha))
1540 goto try_fce;
1541
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001542 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1543 fixed_size = sizeof(struct qla2100_fw_dump);
1544 } else if (IS_QLA23XX(ha)) {
1545 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1546 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1547 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001548 } else if (IS_FWI2_CAPABLE(ha)) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04001549 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001550 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
1551 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001552 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1553 else if (IS_QLA25XX(ha))
1554 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1555 else
1556 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Chad Dupuisf73cb692014-02-26 04:15:06 -05001557
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001558 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1559 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001560 if (ha->mqenable) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04001561 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001562 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001563 /*
1564 * Allocate maximum buffer size for all queues.
1565 * Resizing must be done at end-of-dump processing.
1566 */
1567 mq_size += ha->max_req_queues *
1568 (req->length * sizeof(request_t));
1569 mq_size += ha->max_rsp_queues *
1570 (rsp->length * sizeof(response_t));
1571 }
Arun Easi00876ae2013-03-25 02:21:37 -04001572 if (ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001573 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001574 /* Allocate memory for Fibre Channel Event Buffer. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05001575 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
1576 !IS_QLA27XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001577 goto try_eft;
1578
Chad Dupuisf73cb692014-02-26 04:15:06 -05001579try_fce:
1580 if (ha->fce)
1581 dma_free_coherent(&ha->pdev->dev,
1582 FCE_SIZE, ha->fce, ha->fce_dma);
1583
1584 /* Allocate memory for Fibre Channel Event Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07001585 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1586 GFP_KERNEL);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001587 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001588 ql_log(ql_log_warn, vha, 0x00be,
1589 "Unable to allocate (%d KB) for FCE.\n",
1590 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001591 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001592 }
1593
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001594 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001595 ha->fce_mb, &ha->fce_bufs);
1596 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001597 ql_log(ql_log_warn, vha, 0x00bf,
1598 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001599 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1600 tc_dma);
1601 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001602 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001603 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001604 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001605 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001606
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001607 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001608 ha->flags.fce_enabled = 1;
1609 ha->fce_dma = tc_dma;
1610 ha->fce = tc;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001611
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001612try_eft:
Chad Dupuisf73cb692014-02-26 04:15:06 -05001613 if (ha->eft)
1614 dma_free_coherent(&ha->pdev->dev,
1615 EFT_SIZE, ha->eft, ha->eft_dma);
1616
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001617 /* Allocate memory for Extended Trace Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07001618 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
1619 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001620 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001621 ql_log(ql_log_warn, vha, 0x00c1,
1622 "Unable to allocate (%d KB) for EFT.\n",
1623 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001624 goto cont_alloc;
1625 }
1626
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001627 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001628 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001629 ql_log(ql_log_warn, vha, 0x00c2,
1630 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001631 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1632 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001633 goto cont_alloc;
1634 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001635 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001636 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001637
1638 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001639 ha->eft_dma = tc_dma;
1640 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001641 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05001642
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001643cont_alloc:
Chad Dupuisf73cb692014-02-26 04:15:06 -05001644 if (IS_QLA27XX(ha)) {
1645 if (!ha->fw_dump_template) {
1646 ql_log(ql_log_warn, vha, 0x00ba,
1647 "Failed missing fwdump template\n");
1648 return;
1649 }
1650 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
1651 ql_dbg(ql_dbg_init, vha, 0x00fa,
1652 "-> allocating fwdump (%x bytes)...\n", dump_size);
1653 goto allocate;
1654 }
1655
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001656 req_q_size = req->length * sizeof(request_t);
1657 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001658 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001659 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001660 ha->chain_offset = dump_size;
1661 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001662
Chad Dupuisf73cb692014-02-26 04:15:06 -05001663allocate:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001664 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001665 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001666 ql_log(ql_log_warn, vha, 0x00c4,
1667 "Unable to allocate (%d KB) for firmware dump.\n",
1668 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001669
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001670 if (ha->fce) {
1671 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1672 ha->fce_dma);
1673 ha->fce = NULL;
1674 ha->fce_dma = 0;
1675 }
1676
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001677 if (ha->eft) {
1678 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1679 ha->eft_dma);
1680 ha->eft = NULL;
1681 ha->eft_dma = 0;
1682 }
1683 return;
1684 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05001685 ha->fw_dump_len = dump_size;
Chad Dupuiscfb09192011-11-18 09:03:07 -08001686 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001687 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001688
Chad Dupuisf73cb692014-02-26 04:15:06 -05001689 if (IS_QLA27XX(ha))
1690 return;
1691
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001692 ha->fw_dump->signature[0] = 'Q';
1693 ha->fw_dump->signature[1] = 'L';
1694 ha->fw_dump->signature[2] = 'G';
1695 ha->fw_dump->signature[3] = 'C';
Bart Van Asschead950362015-07-09 07:24:08 -07001696 ha->fw_dump->version = htonl(1);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001697
1698 ha->fw_dump->fixed_size = htonl(fixed_size);
1699 ha->fw_dump->mem_size = htonl(mem_size);
1700 ha->fw_dump->req_q_size = htonl(req_q_size);
1701 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1702
1703 ha->fw_dump->eft_size = htonl(eft_size);
1704 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1705 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1706
1707 ha->fw_dump->header_size =
1708 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001709}
1710
Andrew Vasquez18e75552009-06-03 09:55:30 -07001711static int
1712qla81xx_mpi_sync(scsi_qla_host_t *vha)
1713{
1714#define MPS_MASK 0xe0
1715 int rval;
1716 uint16_t dc;
1717 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07001718
1719 if (!IS_QLA81XX(vha->hw))
1720 return QLA_SUCCESS;
1721
1722 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1723 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001724 ql_log(ql_log_warn, vha, 0x0105,
1725 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001726 goto done;
1727 }
1728
1729 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1730 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1731 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001732 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001733 goto done_release;
1734 }
1735
1736 dc &= MPS_MASK;
1737 if (dc == (dw & MPS_MASK))
1738 goto done_release;
1739
1740 dw &= ~MPS_MASK;
1741 dw |= dc;
1742 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1743 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001744 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001745 }
1746
1747done_release:
1748 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1749 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001750 ql_log(ql_log_warn, vha, 0x006d,
1751 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001752 }
1753
1754done:
1755 return rval;
1756}
1757
Chad Dupuis8d93f552013-01-30 03:34:37 -05001758int
1759qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
1760{
1761 /* Don't try to reallocate the array */
1762 if (req->outstanding_cmds)
1763 return QLA_SUCCESS;
1764
1765 if (!IS_FWI2_CAPABLE(ha) || (ha->mqiobase &&
1766 (ql2xmultique_tag || ql2xmaxqueues > 1)))
1767 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
1768 else {
1769 if (ha->fw_xcb_count <= ha->fw_iocb_count)
1770 req->num_outstanding_cmds = ha->fw_xcb_count;
1771 else
1772 req->num_outstanding_cmds = ha->fw_iocb_count;
1773 }
1774
1775 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1776 req->num_outstanding_cmds, GFP_KERNEL);
1777
1778 if (!req->outstanding_cmds) {
1779 /*
1780 * Try to allocate a minimal size just so we can get through
1781 * initialization.
1782 */
1783 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
1784 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1785 req->num_outstanding_cmds, GFP_KERNEL);
1786
1787 if (!req->outstanding_cmds) {
1788 ql_log(ql_log_fatal, NULL, 0x0126,
1789 "Failed to allocate memory for "
1790 "outstanding_cmds for req_que %p.\n", req);
1791 req->num_outstanding_cmds = 0;
1792 return QLA_FUNCTION_FAILED;
1793 }
1794 }
1795
1796 return QLA_SUCCESS;
1797}
1798
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001799/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 * qla2x00_setup_chip() - Load and start RISC firmware.
1801 * @ha: HA context
1802 *
1803 * Returns 0 on success.
1804 */
1805static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001806qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001808 int rval;
1809 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001810 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001811 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1812 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001813 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001814
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001815 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001816 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001817 if (rval == QLA_SUCCESS) {
1818 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001819 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001820 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001821 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001822 }
1823
Andrew Vasquez3db06522008-01-31 12:33:49 -08001824 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1825 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1826 spin_lock_irqsave(&ha->hardware_lock, flags);
1827 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1828 RD_REG_WORD(&reg->hccr);
1829 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1830 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
Andrew Vasquez18e75552009-06-03 09:55:30 -07001832 qla81xx_mpi_sync(vha);
1833
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001835 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001836 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001837 ql_dbg(ql_dbg_init, vha, 0x00c9,
1838 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001840 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 if (rval == QLA_SUCCESS) {
1842 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001843 ql_dbg(ql_dbg_init, vha, 0x00ca,
1844 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05001846 if (ql2xexlogins)
1847 ha->flags.exlogins_enabled = 1;
1848
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001849 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001851 if (rval == QLA_SUCCESS) {
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05001852 rval = qla2x00_set_exlogins_buffer(vha);
1853 if (rval != QLA_SUCCESS)
1854 goto failed;
1855
Giridhar Malavalia9083012010-04-12 17:59:55 -07001856enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001857 fw_major_version = ha->fw_major_version;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001858 if (IS_P3P_TYPE(ha))
Giridhar Malavali31731672011-08-16 11:31:54 -07001859 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001860 else
1861 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001862 if (rval != QLA_SUCCESS)
1863 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001864 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001865 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001866 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001867 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001868 if ((!ha->max_npiv_vports) ||
1869 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001870 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001871 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001872 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001873 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001874 qla2x00_get_resource_cnts(vha, NULL,
Chad Dupuis8d93f552013-01-30 03:34:37 -05001875 &ha->fw_xcb_count, NULL, &ha->fw_iocb_count,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001876 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001877
Chad Dupuis8d93f552013-01-30 03:34:37 -05001878 /*
1879 * Allocate the array of outstanding commands
1880 * now that we know the firmware resources.
1881 */
1882 rval = qla2x00_alloc_outstanding_cmds(ha,
1883 vha->req);
1884 if (rval != QLA_SUCCESS)
1885 goto failed;
1886
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08001887 if (!fw_major_version && ql2xallocfwdump
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001888 && !(IS_P3P_TYPE(ha)))
Giridhar Malavali08de2842011-08-16 11:31:44 -07001889 qla2x00_alloc_fw_dump(vha);
Chad Dupuis3b6e5b92013-10-30 03:38:09 -04001890 } else {
1891 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 }
1893 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001894 ql_log(ql_log_fatal, vha, 0x00cd,
1895 "ISP Firmware failed checksum.\n");
1896 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04001898 } else
1899 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Andrew Vasquez3db06522008-01-31 12:33:49 -08001901 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1902 /* Enable proper parity. */
1903 spin_lock_irqsave(&ha->hardware_lock, flags);
1904 if (IS_QLA2300(ha))
1905 /* SRAM parity */
1906 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1907 else
1908 /* SRAM, Instruction RAM and GP RAM parity */
1909 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1910 RD_REG_WORD(&reg->hccr);
1911 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1912 }
1913
Chad Dupuisf3982d82014-09-25 05:16:57 -04001914 if (IS_QLA27XX(ha))
1915 ha->flags.fac_supported = 1;
1916 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001917 uint32_t size;
1918
1919 rval = qla81xx_fac_get_sector_size(vha, &size);
1920 if (rval == QLA_SUCCESS) {
1921 ha->flags.fac_supported = 1;
1922 ha->fdt_block_size = size << 2;
1923 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001924 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001925 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1926 ha->fw_major_version, ha->fw_minor_version,
1927 ha->fw_subminor_version);
Joe Carnuccio1ca60e32014-02-26 04:15:02 -05001928
Chad Dupuisf73cb692014-02-26 04:15:06 -05001929 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001930 ha->flags.fac_supported = 0;
1931 rval = QLA_SUCCESS;
1932 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001933 }
1934 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001935failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001937 ql_log(ql_log_fatal, vha, 0x00cf,
1938 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 }
1940
1941 return (rval);
1942}
1943
1944/**
1945 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1946 * @ha: HA context
1947 *
1948 * Beginning of request ring has initialization control block already built
1949 * by nvram config routine.
1950 *
1951 * Returns 0 on success.
1952 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001953void
1954qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955{
1956 uint16_t cnt;
1957 response_t *pkt;
1958
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001959 rsp->ring_ptr = rsp->ring;
1960 rsp->ring_index = 0;
1961 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001962 pkt = rsp->ring_ptr;
1963 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 pkt->signature = RESPONSE_PROCESSED;
1965 pkt++;
1966 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967}
1968
1969/**
1970 * qla2x00_update_fw_options() - Read and process firmware options.
1971 * @ha: HA context
1972 *
1973 * Returns 0 on success.
1974 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001975void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001976qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977{
1978 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001979 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980
1981 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001982 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983
1984 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1985 return;
1986
1987 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001988 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1989 "Serial link options.\n");
1990 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1991 (uint8_t *)&ha->fw_seriallink_options,
1992 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
1994 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1995 if (ha->fw_seriallink_options[3] & BIT_2) {
1996 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1997
1998 /* 1G settings */
1999 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
2000 emphasis = (ha->fw_seriallink_options[2] &
2001 (BIT_4 | BIT_3)) >> 3;
2002 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002003 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 rx_sens = (ha->fw_seriallink_options[0] &
2005 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
2006 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
2007 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2008 if (rx_sens == 0x0)
2009 rx_sens = 0x3;
2010 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
2011 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2012 ha->fw_options[10] |= BIT_5 |
2013 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2014 (tx_sens & (BIT_1 | BIT_0));
2015
2016 /* 2G settings */
2017 swing = (ha->fw_seriallink_options[2] &
2018 (BIT_7 | BIT_6 | BIT_5)) >> 5;
2019 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
2020 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002021 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 rx_sens = (ha->fw_seriallink_options[1] &
2023 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
2024 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
2025 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2026 if (rx_sens == 0x0)
2027 rx_sens = 0x3;
2028 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
2029 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2030 ha->fw_options[11] |= BIT_5 |
2031 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2032 (tx_sens & (BIT_1 | BIT_0));
2033 }
2034
2035 /* FCP2 options. */
2036 /* Return command IOCBs without waiting for an ABTS to complete. */
2037 ha->fw_options[3] |= BIT_13;
2038
2039 /* LED scheme. */
2040 if (ha->flags.enable_led_scheme)
2041 ha->fw_options[2] |= BIT_12;
2042
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002043 /* Detect ISP6312. */
2044 if (IS_QLA6312(ha))
2045 ha->fw_options[2] |= BIT_13;
2046
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002048 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049}
2050
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002051void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002053{
2054 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002055 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002056
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002057 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07002058 return;
2059
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002060 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08002061 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002062 return;
2063
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002064 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08002065 le16_to_cpu(ha->fw_seriallink_options24[1]),
2066 le16_to_cpu(ha->fw_seriallink_options24[2]),
2067 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002068 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002069 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002070 "Unable to update Serial Link options (%x).\n", rval);
2071 }
2072}
2073
2074void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002075qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002076{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002077 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002078 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002079 struct req_que *req = ha->req_q_map[0];
2080 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002081
2082 /* Setup ring parameters in initialization control block. */
Bart Van Asschead950362015-07-09 07:24:08 -07002083 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
2084 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002085 ha->init_cb->request_q_length = cpu_to_le16(req->length);
2086 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
2087 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2088 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2089 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2090 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002091
2092 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
2093 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
2094 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
2095 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
2096 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
2097}
2098
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002099void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002100qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002101{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002102 struct qla_hw_data *ha = vha->hw;
Bart Van Assche118e2ef2015-07-09 07:24:27 -07002103 device_reg_t *reg = ISP_QUE_REG(ha, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002104 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
2105 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002106 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002107 uint16_t rid = 0;
2108 struct req_que *req = ha->req_q_map[0];
2109 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002110
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002111 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002112 icb = (struct init_cb_24xx *)ha->init_cb;
Bart Van Asschead950362015-07-09 07:24:08 -07002113 icb->request_q_outpointer = cpu_to_le16(0);
2114 icb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002115 icb->request_q_length = cpu_to_le16(req->length);
2116 icb->response_q_length = cpu_to_le16(rsp->length);
2117 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2118 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2119 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2120 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002121
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002122 /* Setup ATIO queue dma pointers for target mode */
Bart Van Asschead950362015-07-09 07:24:08 -07002123 icb->atio_q_inpointer = cpu_to_le16(0);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002124 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
2125 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
2126 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
2127
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002128 if (IS_SHADOW_REG_CAPABLE(ha))
Bart Van Asschead950362015-07-09 07:24:08 -07002129 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002130
Chad Dupuisf73cb692014-02-26 04:15:06 -05002131 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07002132 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
2133 icb->rid = cpu_to_le16(rid);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002134 if (ha->flags.msix_enabled) {
2135 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002136 ql_dbg(ql_dbg_init, vha, 0x00fd,
2137 "Registering vector 0x%x for base que.\n",
2138 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002139 icb->msix = cpu_to_le16(msix->entry);
2140 }
2141 /* Use alternate PCI bus number */
2142 if (MSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07002143 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002144 /* Use alternate PCI devfn */
2145 if (LSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07002146 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002147
Anirban Chakraborty31557542009-12-02 10:36:55 -08002148 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002149 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
2150 (ha->flags.msix_enabled)) {
Bart Van Asschead950362015-07-09 07:24:08 -07002151 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002152 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002153 ql_dbg(ql_dbg_init, vha, 0x00fe,
2154 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08002155 } else {
Bart Van Asschead950362015-07-09 07:24:08 -07002156 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002157 }
Bart Van Asschead950362015-07-09 07:24:08 -07002158 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002159
2160 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
2161 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
2162 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
2163 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
2164 } else {
2165 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
2166 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
2167 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
2168 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
2169 }
Arun Easiaa230bc2013-01-30 03:34:39 -05002170 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002171
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002172 /* PCI posting */
2173 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002174}
2175
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176/**
2177 * qla2x00_init_rings() - Initializes firmware.
2178 * @ha: HA context
2179 *
2180 * Beginning of request ring has initialization control block already built
2181 * by nvram config routine.
2182 *
2183 * Returns 0 on success.
2184 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002185int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002186qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187{
2188 int rval;
2189 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002190 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002191 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002192 struct req_que *req;
2193 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002194 struct mid_init_cb_24xx *mid_init_cb =
2195 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196
2197 spin_lock_irqsave(&ha->hardware_lock, flags);
2198
2199 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002200 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002201 req = ha->req_q_map[que];
2202 if (!req)
2203 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002204 req->out_ptr = (void *)(req->ring + req->length);
2205 *req->out_ptr = 0;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002206 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002207 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002209 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002210
2211 /* Initialize firmware. */
2212 req->ring_ptr = req->ring;
2213 req->ring_index = 0;
2214 req->cnt = req->length;
2215 }
2216
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002217 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002218 rsp = ha->rsp_q_map[que];
2219 if (!rsp)
2220 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002221 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
2222 *rsp->in_ptr = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002223 /* Initialize response queue entries */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002224 if (IS_QLAFX00(ha))
2225 qlafx00_init_response_q_entries(rsp);
2226 else
2227 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002230 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
2231 ha->tgt.atio_ring_index = 0;
2232 /* Initialize ATIO queue entries */
2233 qlt_init_atio_q_entries(vha);
2234
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002235 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
2237 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2238
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002239 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
2240
2241 if (IS_QLAFX00(ha)) {
2242 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
2243 goto next_check;
2244 }
2245
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002247 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002249 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04002250 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002251 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08002252 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002253 }
2254
Andrew Vasquez24a08132009-03-24 09:08:16 -07002255 if (IS_FWI2_CAPABLE(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07002256 mid_init_cb->options = cpu_to_le16(BIT_1);
Andrew Vasquez24a08132009-03-24 09:08:16 -07002257 mid_init_cb->init_cb.execution_throttle =
2258 cpu_to_le16(ha->fw_xcb_count);
Himanshu Madhani25232cc2014-09-25 05:16:54 -04002259 /* D-Port Status */
2260 if (IS_DPORT_CAPABLE(ha))
2261 mid_init_cb->init_cb.firmware_options_1 |=
2262 cpu_to_le16(BIT_7);
Himanshu Madhani2486c622014-09-25 05:17:00 -04002263 /* Enable FA-WWPN */
2264 ha->flags.fawwpn_enabled =
2265 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) ? 1 : 0;
2266 ql_dbg(ql_dbg_init, vha, 0x0141, "FA-WWPN Support: %s.\n",
2267 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
Andrew Vasquez24a08132009-03-24 09:08:16 -07002268 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002269
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002270 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002271next_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002273 ql_log(ql_log_fatal, vha, 0x00d2,
2274 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002276 ql_dbg(ql_dbg_init, vha, 0x00d3,
2277 "Init Firmware -- success.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 }
2279
2280 return (rval);
2281}
2282
2283/**
2284 * qla2x00_fw_ready() - Waits for firmware ready.
2285 * @ha: HA context
2286 *
2287 * Returns 0 on success.
2288 */
2289static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002290qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291{
2292 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002293 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 uint16_t min_wait; /* Minimum wait time if loop is down */
2295 uint16_t wait_time; /* Wait time if loop is coming ready */
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002296 uint16_t state[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002297 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002299 if (IS_QLAFX00(vha->hw))
2300 return qlafx00_fw_ready(vha);
2301
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 rval = QLA_SUCCESS;
2303
Chad Dupuis334614912015-04-09 14:59:57 -04002304 /* Time to wait for loop down */
2305 if (IS_P3P_TYPE(ha))
2306 min_wait = 30;
2307 else
2308 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309
2310 /*
2311 * Firmware should take at most one RATOV to login, plus 5 seconds for
2312 * our own processing.
2313 */
2314 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
2315 wait_time = min_wait;
2316 }
2317
2318 /* Min wait time if loop down */
2319 mtime = jiffies + (min_wait * HZ);
2320
2321 /* wait time before firmware ready */
2322 wtime = jiffies + (wait_time * HZ);
2323
2324 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002325 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002326 ql_log(ql_log_info, vha, 0x801e,
2327 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
2329 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05002330 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002331 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002333 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002334 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002336 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002337 ql_dbg(ql_dbg_taskm, vha, 0x801f,
2338 "fw_state=%x 84xx=%x.\n", state[0],
2339 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002340 if ((state[2] & FSTATE_LOGGED_IN) &&
2341 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002342 ql_dbg(ql_dbg_taskm, vha, 0x8028,
2343 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002344
2345 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002346 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002347 if (rval != QLA_SUCCESS) {
2348 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002349 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002350 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002351 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002352 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002353
2354 /* Add time taken to initialize. */
2355 cs84xx_time = jiffies - cs84xx_time;
2356 wtime += cs84xx_time;
2357 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002358 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002359 "Increasing wait time by %ld. "
2360 "New time %ld.\n", cs84xx_time,
2361 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002362 }
2363 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002364 ql_dbg(ql_dbg_taskm, vha, 0x8037,
2365 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002367 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 &ha->login_timeout, &ha->r_a_tov);
2369
2370 rval = QLA_SUCCESS;
2371 break;
2372 }
2373
2374 rval = QLA_FUNCTION_FAILED;
2375
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002376 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002377 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002379 * other than Wait for Login.
2380 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002382 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 "Cable is unplugged...\n");
2384
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002385 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 break;
2387 }
2388 }
2389 } else {
2390 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07002391 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08002392 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 break;
2394 }
2395
2396 if (time_after_eq(jiffies, wtime))
2397 break;
2398
2399 /* Delay for a while */
2400 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 } while (1);
2402
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002403 ql_dbg(ql_dbg_taskm, vha, 0x803a,
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002404 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
2405 state[1], state[2], state[3], state[4], state[5], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
Chad Dupuiscfb09192011-11-18 09:03:07 -08002407 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002408 ql_log(ql_log_warn, vha, 0x803b,
2409 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 }
2411
2412 return (rval);
2413}
2414
2415/*
2416* qla2x00_configure_hba
2417* Setup adapter context.
2418*
2419* Input:
2420* ha = adapter state pointer.
2421*
2422* Returns:
2423* 0 = success
2424*
2425* Context:
2426* Kernel context.
2427*/
2428static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002429qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430{
2431 int rval;
2432 uint16_t loop_id;
2433 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002434 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 uint8_t al_pa;
2436 uint8_t area;
2437 uint8_t domain;
2438 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002439 struct qla_hw_data *ha = vha->hw;
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002440 unsigned long flags;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002441 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442
2443 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002444 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002445 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002447 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002448 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002449 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002450 ql_dbg(ql_dbg_disc, vha, 0x2008,
2451 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08002452 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002453 ql_log(ql_log_warn, vha, 0x2009,
2454 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002455 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
2456 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
2457 ql_log(ql_log_warn, vha, 0x1151,
2458 "Doing link init.\n");
2459 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
2460 return rval;
2461 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002462 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002463 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 return (rval);
2465 }
2466
2467 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002468 ql_log(ql_log_info, vha, 0x200a,
2469 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 return (QLA_FUNCTION_FAILED);
2471 }
2472
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002473 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
2475 /* initialize */
2476 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2477 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002478 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479
2480 switch (topo) {
2481 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002482 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 ha->current_topology = ISP_CFG_NL;
2484 strcpy(connect_type, "(Loop)");
2485 break;
2486
2487 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002488 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002489 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 ha->current_topology = ISP_CFG_FL;
2491 strcpy(connect_type, "(FL_Port)");
2492 break;
2493
2494 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002495 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 ha->operating_mode = P2P;
2497 ha->current_topology = ISP_CFG_N;
2498 strcpy(connect_type, "(N_Port-to-N_Port)");
2499 break;
2500
2501 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002502 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002503 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 ha->operating_mode = P2P;
2505 ha->current_topology = ISP_CFG_F;
2506 strcpy(connect_type, "(F_Port)");
2507 break;
2508
2509 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002510 ql_dbg(ql_dbg_disc, vha, 0x200f,
2511 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 ha->current_topology = ISP_CFG_NL;
2513 strcpy(connect_type, "(Loop)");
2514 break;
2515 }
2516
2517 /* Save Host port and loop ID. */
2518 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002519 vha->d_id.b.domain = domain;
2520 vha->d_id.b.area = area;
2521 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002523 spin_lock_irqsave(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002524 qlt_update_vp_map(vha, SET_AL_PA);
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002525 spin_unlock_irqrestore(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002526
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002527 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002528 ql_log(ql_log_info, vha, 0x2010,
2529 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002530 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 return(rval);
2533}
2534
Giridhar Malavalia9083012010-04-12 17:59:55 -07002535inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002536qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2537 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002538{
2539 char *st, *en;
2540 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002541 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002542 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002543 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002544
2545 if (memcmp(model, BINZERO, len) != 0) {
2546 strncpy(ha->model_number, model, len);
2547 st = en = ha->model_number;
2548 en += len - 1;
2549 while (en > st) {
2550 if (*en != 0x20 && *en != 0x00)
2551 break;
2552 *en-- = '\0';
2553 }
2554
2555 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002556 if (use_tbl &&
2557 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002558 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002559 strncpy(ha->model_desc,
2560 qla2x00_model_name[index * 2 + 1],
2561 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002562 } else {
2563 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002564 if (use_tbl &&
2565 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002566 index < QLA_MODEL_NAMES) {
2567 strcpy(ha->model_number,
2568 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002569 strncpy(ha->model_desc,
2570 qla2x00_model_name[index * 2 + 1],
2571 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002572 } else {
2573 strcpy(ha->model_number, def);
2574 }
2575 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002576 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002577 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002578 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002579}
2580
David Miller4e08df32007-04-16 12:37:43 -07002581/* On sparc systems, obtain port and node WWN from firmware
2582 * properties.
2583 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002584static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002585{
2586#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002587 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002588 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002589 struct device_node *dp = pci_device_to_OF_node(pdev);
2590 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002591 int len;
2592
2593 val = of_get_property(dp, "port-wwn", &len);
2594 if (val && len >= WWN_SIZE)
2595 memcpy(nv->port_name, val, WWN_SIZE);
2596
2597 val = of_get_property(dp, "node-wwn", &len);
2598 if (val && len >= WWN_SIZE)
2599 memcpy(nv->node_name, val, WWN_SIZE);
2600#endif
2601}
2602
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603/*
2604* NVRAM configuration for ISP 2xxx
2605*
2606* Input:
2607* ha = adapter block pointer.
2608*
2609* Output:
2610* initialization control block in response_ring
2611* host adapters parameters in host adapter block
2612*
2613* Returns:
2614* 0 = success.
2615*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002616int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002617qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618{
David Miller4e08df32007-04-16 12:37:43 -07002619 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002620 uint8_t chksum = 0;
2621 uint16_t cnt;
2622 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002623 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002624 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002625 nvram_t *nv = ha->nvram;
2626 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002627 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628
David Miller4e08df32007-04-16 12:37:43 -07002629 rval = QLA_SUCCESS;
2630
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002632 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 ha->nvram_base = 0;
2634 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2635 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2636 ha->nvram_base = 0x80;
2637
2638 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002639 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002640 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2641 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002643 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2644 "Contents of NVRAM.\n");
2645 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2646 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
2648 /* Bad NVRAM data, set defaults parameters. */
2649 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2650 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2651 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002652 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04002653 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002654 "detected: checksum=0x%x id=%c version=0x%x.\n",
2655 chksum, nv->id[0], nv->nvram_version);
2656 ql_log(ql_log_warn, vha, 0x0065,
2657 "Falling back to "
2658 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07002659
2660 /*
2661 * Set default initialization control block.
2662 */
2663 memset(nv, 0, ha->nvram_size);
2664 nv->parameter_block_version = ICB_VERSION;
2665
2666 if (IS_QLA23XX(ha)) {
2667 nv->firmware_options[0] = BIT_2 | BIT_1;
2668 nv->firmware_options[1] = BIT_7 | BIT_5;
2669 nv->add_firmware_options[0] = BIT_5;
2670 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04002671 nv->frame_payload_size = 2048;
David Miller4e08df32007-04-16 12:37:43 -07002672 nv->special_options[1] = BIT_7;
2673 } else if (IS_QLA2200(ha)) {
2674 nv->firmware_options[0] = BIT_2 | BIT_1;
2675 nv->firmware_options[1] = BIT_7 | BIT_5;
2676 nv->add_firmware_options[0] = BIT_5;
2677 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04002678 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07002679 } else if (IS_QLA2100(ha)) {
2680 nv->firmware_options[0] = BIT_3 | BIT_1;
2681 nv->firmware_options[1] = BIT_5;
Joe Carnuccio98aee702014-09-25 05:16:38 -04002682 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07002683 }
2684
Bart Van Asschead950362015-07-09 07:24:08 -07002685 nv->max_iocb_allocation = cpu_to_le16(256);
2686 nv->execution_throttle = cpu_to_le16(16);
David Miller4e08df32007-04-16 12:37:43 -07002687 nv->retry_count = 8;
2688 nv->retry_delay = 1;
2689
2690 nv->port_name[0] = 33;
2691 nv->port_name[3] = 224;
2692 nv->port_name[4] = 139;
2693
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002694 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002695
2696 nv->login_timeout = 4;
2697
2698 /*
2699 * Set default host adapter parameters
2700 */
2701 nv->host_p[1] = BIT_2;
2702 nv->reset_delay = 5;
2703 nv->port_down_retry_count = 8;
Bart Van Asschead950362015-07-09 07:24:08 -07002704 nv->max_luns_per_target = cpu_to_le16(8);
David Miller4e08df32007-04-16 12:37:43 -07002705 nv->link_down_timeout = 60;
2706
2707 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 }
2709
2710#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2711 /*
2712 * The SN2 does not provide BIOS emulation which means you can't change
2713 * potentially bogus BIOS settings. Force the use of default settings
2714 * for link rate and frame size. Hope that the rest of the settings
2715 * are valid.
2716 */
2717 if (ia64_platform_is("sn2")) {
Joe Carnuccio98aee702014-09-25 05:16:38 -04002718 nv->frame_payload_size = 2048;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 if (IS_QLA23XX(ha))
2720 nv->special_options[1] = BIT_7;
2721 }
2722#endif
2723
2724 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002725 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726
2727 /*
2728 * Setup driver NVRAM options.
2729 */
2730 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2731 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2732 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2733 nv->firmware_options[1] &= ~BIT_4;
2734
2735 if (IS_QLA23XX(ha)) {
2736 nv->firmware_options[0] |= BIT_2;
2737 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002738 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002739 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740
2741 if (IS_QLA2300(ha)) {
2742 if (ha->fb_rev == FPM_2310) {
2743 strcpy(ha->model_number, "QLA2310");
2744 } else {
2745 strcpy(ha->model_number, "QLA2300");
2746 }
2747 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002748 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002749 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 }
2751 } else if (IS_QLA2200(ha)) {
2752 nv->firmware_options[0] |= BIT_2;
2753 /*
2754 * 'Point-to-point preferred, else loop' is not a safe
2755 * connection mode setting.
2756 */
2757 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2758 (BIT_5 | BIT_4)) {
2759 /* Force 'loop preferred, else point-to-point'. */
2760 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2761 nv->add_firmware_options[0] |= BIT_5;
2762 }
2763 strcpy(ha->model_number, "QLA22xx");
2764 } else /*if (IS_QLA2100(ha))*/ {
2765 strcpy(ha->model_number, "QLA2100");
2766 }
2767
2768 /*
2769 * Copy over NVRAM RISC parameter block to initialization control block.
2770 */
2771 dptr1 = (uint8_t *)icb;
2772 dptr2 = (uint8_t *)&nv->parameter_block_version;
2773 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2774 while (cnt--)
2775 *dptr1++ = *dptr2++;
2776
2777 /* Copy 2nd half. */
2778 dptr1 = (uint8_t *)icb->add_firmware_options;
2779 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2780 while (cnt--)
2781 *dptr1++ = *dptr2++;
2782
Andrew Vasquez5341e862006-05-17 15:09:16 -07002783 /* Use alternate WWN? */
2784 if (nv->host_p[1] & BIT_7) {
2785 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2786 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2787 }
2788
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 /* Prepare nodename */
2790 if ((icb->firmware_options[1] & BIT_6) == 0) {
2791 /*
2792 * Firmware will apply the following mask if the nodename was
2793 * not provided.
2794 */
2795 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2796 icb->node_name[0] &= 0xF0;
2797 }
2798
2799 /*
2800 * Set host adapter parameters.
2801 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002802
2803 /*
2804 * BIT_7 in the host-parameters section allows for modification to
2805 * internal driver logging.
2806 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002807 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08002808 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2810 /* Always load RISC code on non ISP2[12]00 chips. */
2811 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2812 ha->flags.disable_risc_code_load = 0;
2813 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2814 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2815 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002816 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002817 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818
2819 ha->operating_mode =
2820 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2821
2822 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2823 sizeof(ha->fw_seriallink_options));
2824
2825 /* save HBA serial number */
2826 ha->serial0 = icb->port_name[5];
2827 ha->serial1 = icb->port_name[6];
2828 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002829 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2830 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831
Bart Van Asschead950362015-07-09 07:24:08 -07002832 icb->execution_throttle = cpu_to_le16(0xFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833
2834 ha->retry_count = nv->retry_count;
2835
2836 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002837 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 nv->login_timeout = ql2xlogintimeout;
2839 if (nv->login_timeout < 4)
2840 nv->login_timeout = 4;
2841 ha->login_timeout = nv->login_timeout;
2842 icb->login_timeout = nv->login_timeout;
2843
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002844 /* Set minimum RATOV to 100 tenths of a second. */
2845 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 ha->loop_reset_delay = nv->reset_delay;
2848
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 /* Link Down Timeout = 0:
2850 *
2851 * When Port Down timer expires we will start returning
2852 * I/O's to OS with "DID_NO_CONNECT".
2853 *
2854 * Link Down Timeout != 0:
2855 *
2856 * The driver waits for the link to come up after link down
2857 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002858 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 if (nv->link_down_timeout == 0) {
2860 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002861 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 } else {
2863 ha->link_down_timeout = nv->link_down_timeout;
2864 ha->loop_down_abort_time =
2865 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002866 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 /*
2869 * Need enough time to try and get the port back.
2870 */
2871 ha->port_down_retry_count = nv->port_down_retry_count;
2872 if (qlport_down_retry)
2873 ha->port_down_retry_count = qlport_down_retry;
2874 /* Set login_retry_count */
2875 ha->login_retry_count = nv->retry_count;
2876 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2877 ha->port_down_retry_count > 3)
2878 ha->login_retry_count = ha->port_down_retry_count;
2879 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2880 ha->login_retry_count = ha->port_down_retry_count;
2881 if (ql2xloginretrycount)
2882 ha->login_retry_count = ql2xloginretrycount;
2883
Bart Van Asschead950362015-07-09 07:24:08 -07002884 icb->lun_enables = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 icb->command_resource_count = 0;
2886 icb->immediate_notify_resource_count = 0;
Bart Van Asschead950362015-07-09 07:24:08 -07002887 icb->timeout = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888
2889 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2890 /* Enable RIO */
2891 icb->firmware_options[0] &= ~BIT_3;
2892 icb->add_firmware_options[0] &=
2893 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2894 icb->add_firmware_options[0] |= BIT_2;
2895 icb->response_accumulation_timer = 3;
2896 icb->interrupt_delay_timer = 5;
2897
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002898 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002900 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002901 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002902 ha->zio_mode = icb->add_firmware_options[0] &
2903 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2904 ha->zio_timer = icb->interrupt_delay_timer ?
2905 icb->interrupt_delay_timer: 2;
2906 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 icb->add_firmware_options[0] &=
2908 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002909 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002910 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002911 ha->zio_mode = QLA_ZIO_MODE_6;
2912
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002913 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002914 "ZIO mode %d enabled; timer delay (%d us).\n",
2915 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002917 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2918 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002919 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 }
2921 }
2922
David Miller4e08df32007-04-16 12:37:43 -07002923 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002924 ql_log(ql_log_warn, vha, 0x0069,
2925 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07002926 }
2927 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928}
2929
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002930static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002931qla2x00_rport_del(void *data)
2932{
2933 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002934 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002935 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002936
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002937 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002938 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002939 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002940 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04002941 if (rport)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002942 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002943}
2944
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945/**
2946 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2947 * @ha: HA context
2948 * @flags: allocation flags
2949 *
2950 * Returns a pointer to the allocated fcport, or NULL, if none available.
2951 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002952fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002953qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954{
2955 fc_port_t *fcport;
2956
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002957 fcport = kzalloc(sizeof(fc_port_t), flags);
2958 if (!fcport)
2959 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960
2961 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002962 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 fcport->port_type = FCT_UNKNOWN;
2964 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07002965 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002966 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002968 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969}
2970
2971/*
2972 * qla2x00_configure_loop
2973 * Updates Fibre Channel Device Database with what is actually on loop.
2974 *
2975 * Input:
2976 * ha = adapter block pointer.
2977 *
2978 * Returns:
2979 * 0 = success.
2980 * 1 = error.
2981 * 2 = database was full and device was not configured.
2982 */
2983static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002984qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985{
2986 int rval;
2987 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002988 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 rval = QLA_SUCCESS;
2990
2991 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002992 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2993 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002995 ql_dbg(ql_dbg_disc, vha, 0x2013,
2996 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 return (rval);
2998 }
2999 }
3000
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003001 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003002 ql_dbg(ql_dbg_disc, vha, 0x2014,
3003 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004
3005 /*
3006 * If we have both an RSCN and PORT UPDATE pending then handle them
3007 * both at the same time.
3008 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003009 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3010 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011
Michael Hernandez3064ff32009-12-15 21:29:44 -08003012 qla2x00_get_data_rate(vha);
3013
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 /* Determine what we need to do */
3015 if (ha->current_topology == ISP_CFG_FL &&
3016 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
3017
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 set_bit(RSCN_UPDATE, &flags);
3019
3020 } else if (ha->current_topology == ISP_CFG_F &&
3021 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
3022
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 set_bit(RSCN_UPDATE, &flags);
3024 clear_bit(LOCAL_LOOP_UPDATE, &flags);
3025
Andrew Vasquez21333b42006-05-17 15:09:56 -07003026 } else if (ha->current_topology == ISP_CFG_N) {
3027 clear_bit(RSCN_UPDATE, &flags);
3028
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003029 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
3031
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 set_bit(RSCN_UPDATE, &flags);
3033 set_bit(LOCAL_LOOP_UPDATE, &flags);
3034 }
3035
3036 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003037 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
3038 ql_dbg(ql_dbg_disc, vha, 0x2015,
3039 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08003041 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003042 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 }
3044
3045 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003046 if (LOOP_TRANSITION(vha)) {
3047 ql_dbg(ql_dbg_disc, vha, 0x201e,
3048 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003050 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003051 else
3052 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 }
3054
3055 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003056 if (atomic_read(&vha->loop_down_timer) ||
3057 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 rval = QLA_FUNCTION_FAILED;
3059 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003060 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003061 ql_dbg(ql_dbg_disc, vha, 0x2069,
3062 "LOOP READY.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 }
3064 }
3065
3066 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003067 ql_dbg(ql_dbg_disc, vha, 0x206a,
3068 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003070 ql_dbg(ql_dbg_disc, vha, 0x206b,
3071 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 }
3073
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07003074 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003075 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003077 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07003078 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003079 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07003080 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 }
3082
3083 return (rval);
3084}
3085
3086
3087
3088/*
3089 * qla2x00_configure_local_loop
3090 * Updates Fibre Channel Device Database with local loop devices.
3091 *
3092 * Input:
3093 * ha = adapter block pointer.
3094 *
3095 * Returns:
3096 * 0 = success.
3097 */
3098static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003099qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100{
3101 int rval, rval2;
3102 int found_devs;
3103 int found;
3104 fc_port_t *fcport, *new_fcport;
3105
3106 uint16_t index;
3107 uint16_t entries;
3108 char *id_iter;
3109 uint16_t loop_id;
3110 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003111 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112
3113 found_devs = 0;
3114 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08003115 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08003118 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003119 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 &entries);
3121 if (rval != QLA_SUCCESS)
3122 goto cleanup_allocation;
3123
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003124 ql_dbg(ql_dbg_disc, vha, 0x2017,
3125 "Entries in ID list (%d).\n", entries);
3126 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
3127 (uint8_t *)ha->gid_list,
3128 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129
3130 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003131 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003133 ql_log(ql_log_warn, vha, 0x2018,
3134 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 rval = QLA_MEMORY_ALLOC_FAILED;
3136 goto cleanup_allocation;
3137 }
3138 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3139
3140 /*
3141 * Mark local devices that were present with FCF_DEVICE_LOST for now.
3142 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003143 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 if (atomic_read(&fcport->state) == FCS_ONLINE &&
3145 fcport->port_type != FCT_BROADCAST &&
3146 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3147
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003148 ql_dbg(ql_dbg_disc, vha, 0x2019,
3149 "Marking port lost loop_id=0x%04x.\n",
3150 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151
Chad Dupuisec426e12011-03-30 11:46:32 -07003152 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 }
3154 }
3155
3156 /* Add devices to port list. */
3157 id_iter = (char *)ha->gid_list;
3158 for (index = 0; index < entries; index++) {
3159 domain = ((struct gid_list_info *)id_iter)->domain;
3160 area = ((struct gid_list_info *)id_iter)->area;
3161 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003162 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 loop_id = (uint16_t)
3164 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003165 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 loop_id = le16_to_cpu(
3167 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003168 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169
3170 /* Bypass reserved domain fields. */
3171 if ((domain & 0xf0) == 0xf0)
3172 continue;
3173
3174 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003175 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003176 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 continue;
3178
3179 /* Bypass invalid local loop ID. */
3180 if (loop_id > LAST_LOCAL_LOOP_ID)
3181 continue;
3182
Arun Easi370d5502012-08-22 14:21:10 -04003183 memset(new_fcport, 0, sizeof(fc_port_t));
3184
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 /* Fill in member data. */
3186 new_fcport->d_id.b.domain = domain;
3187 new_fcport->d_id.b.area = area;
3188 new_fcport->d_id.b.al_pa = al_pa;
3189 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003190 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003192 ql_dbg(ql_dbg_disc, vha, 0x201a,
3193 "Failed to retrieve fcport information "
3194 "-- get_port_database=%x, loop_id=0x%04x.\n",
3195 rval2, new_fcport->loop_id);
3196 ql_dbg(ql_dbg_disc, vha, 0x201b,
3197 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003198 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 continue;
3200 }
3201
3202 /* Check for matching device in port list. */
3203 found = 0;
3204 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003205 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 if (memcmp(new_fcport->port_name, fcport->port_name,
3207 WWN_SIZE))
3208 continue;
3209
Shyam Sundarddb9b122009-03-24 09:08:10 -07003210 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 fcport->loop_id = new_fcport->loop_id;
3212 fcport->port_type = new_fcport->port_type;
3213 fcport->d_id.b24 = new_fcport->d_id.b24;
3214 memcpy(fcport->node_name, new_fcport->node_name,
3215 WWN_SIZE);
3216
3217 found++;
3218 break;
3219 }
3220
3221 if (!found) {
3222 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003223 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224
3225 /* Allocate a new replacement fcport. */
3226 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003227 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003229 ql_log(ql_log_warn, vha, 0x201c,
3230 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 rval = QLA_MEMORY_ALLOC_FAILED;
3232 goto cleanup_allocation;
3233 }
3234 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3235 }
3236
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003237 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003238 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003239
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003240 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241
3242 found_devs++;
3243 }
3244
3245cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003246 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247
3248 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003249 ql_dbg(ql_dbg_disc, vha, 0x201d,
3250 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 }
3252
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 return (rval);
3254}
3255
3256static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003257qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003258{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003259 int rval;
Quinn Tran93f2bd62014-09-25 05:16:53 -04003260 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003261 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003262
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07003263 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003264 return;
3265
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07003266 if (atomic_read(&fcport->state) != FCS_ONLINE)
3267 return;
3268
Andrew Vasquez39bd9622007-09-20 14:07:34 -07003269 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
3270 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003271 return;
3272
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003273 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003274 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003275 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003276 ql_dbg(ql_dbg_disc, vha, 0x2004,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003277 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
3278 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003279 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003280 ql_dbg(ql_dbg_disc, vha, 0x2005,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003281 "iIDMA adjusted to %s GB/s on %8phN.\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -05003282 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003283 fcport->port_name);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003284 }
3285}
3286
Adrian Bunk23be3312006-11-24 02:46:01 +01003287static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003288qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05003289{
3290 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05003291 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003292 unsigned long flags;
8482e1182005-04-17 15:04:54 -05003293
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07003294 rport_ids.node_name = wwn_to_u64(fcport->node_name);
3295 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05003296 rport_ids.port_id = fcport->d_id.b.domain << 16 |
3297 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
3298 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003299 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07003300 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003301 ql_log(ql_log_warn, vha, 0x2006,
3302 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07003303 return;
3304 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003305 /*
3306 * Create target mode FC NEXUS in qla_target.c if target mode is
3307 * enabled..
3308 */
Saurav Kashyapba9f6f62015-06-10 11:05:17 -04003309
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003310 qlt_fc_port_added(vha, fcport);
3311
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003312 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003313 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003314 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003315
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003316 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003317
3318 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05003319 if (fcport->port_type == FCT_INITIATOR)
3320 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3321 if (fcport->port_type == FCT_TARGET)
3322 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003323 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05003324}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325
3326/*
Adrian Bunk23be3312006-11-24 02:46:01 +01003327 * qla2x00_update_fcport
3328 * Updates device on list.
3329 *
3330 * Input:
3331 * ha = adapter block pointer.
3332 * fcport = port structure pointer.
3333 *
3334 * Return:
3335 * 0 - Success
3336 * BIT_0 - error
3337 *
3338 * Context:
3339 * Kernel context.
3340 */
3341void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003342qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01003343{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003344 fcport->vha = vha;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003345
3346 if (IS_QLAFX00(vha->hw)) {
3347 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003348 goto reg_port;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003349 }
Adrian Bunk23be3312006-11-24 02:46:01 +01003350 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003351 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01003352
Joe Carnuccio1f93da522012-11-21 02:40:38 -05003353 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003354 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08003355 qla24xx_update_fcport_fcp_prio(vha, fcport);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003356
3357reg_port:
3358 if (qla_ini_mode_enabled(vha))
3359 qla2x00_reg_remote_port(vha, fcport);
3360 else {
3361 /*
3362 * Create target mode FC NEXUS in qla_target.c
3363 */
3364 qlt_fc_port_added(vha, fcport);
3365 }
Adrian Bunk23be3312006-11-24 02:46:01 +01003366}
3367
3368/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369 * qla2x00_configure_fabric
3370 * Setup SNS devices with loop ID's.
3371 *
3372 * Input:
3373 * ha = adapter block pointer.
3374 *
3375 * Returns:
3376 * 0 = success.
3377 * BIT_0 = error
3378 */
3379static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003380qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381{
Arun Easib3b02e62012-02-09 11:15:39 -08003382 int rval;
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003383 fc_port_t *fcport, *fcptemp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 uint16_t next_loopid;
3385 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003386 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003388 struct qla_hw_data *ha = vha->hw;
3389 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003390 int discovery_gen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391
3392 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003393 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003394 loop_id = NPH_F_PORT;
3395 else
3396 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003397 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003399 ql_dbg(ql_dbg_disc, vha, 0x201f,
3400 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003402 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403 return (QLA_SUCCESS);
3404 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003405 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07003408 /* FDMI support. */
3409 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003410 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
3411 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07003412
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003414 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003415 loop_id = NPH_SNS;
3416 else
3417 loop_id = SIMPLE_NAME_SERVER;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003418 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
3419 0xfc, mb, BIT_1|BIT_0);
3420 if (rval != QLA_SUCCESS) {
3421 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003422 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003423 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003425 ql_dbg(ql_dbg_disc, vha, 0x2042,
3426 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3427 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
3428 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 return (QLA_SUCCESS);
3430 }
3431
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003432 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3433 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003435 ql_dbg(ql_dbg_disc, vha, 0x2045,
3436 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003438 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003440 ql_dbg(ql_dbg_disc, vha, 0x2049,
3441 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003443 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003445 ql_dbg(ql_dbg_disc, vha, 0x204f,
3446 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003447 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003449 ql_dbg(ql_dbg_disc, vha, 0x2053,
3450 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 }
3452 }
3453
Joe Carnuccio827210b2013-02-08 01:57:57 -05003454#define QLA_FCPORT_SCAN 1
3455#define QLA_FCPORT_FOUND 2
3456
3457 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3458 fcport->scan_state = QLA_FCPORT_SCAN;
3459 }
3460
Alexei Potashnikdf673272015-07-14 16:00:46 -04003461 /* Mark the time right before querying FW for connected ports.
3462 * This process is long, asynchronous and by the time it's done,
3463 * collected information might not be accurate anymore. E.g.
3464 * disconnected port might have re-connected and a brand new
3465 * session has been created. In this case session's generation
3466 * will be newer than discovery_gen. */
3467 qlt_do_generation_tick(vha, &discovery_gen);
3468
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003469 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 if (rval != QLA_SUCCESS)
3471 break;
3472
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003473 /*
3474 * Logout all previous fabric devices marked lost, except
3475 * FCP2 devices.
3476 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003477 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3478 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 break;
3480
3481 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3482 continue;
3483
Roland Dreierb2032fd2015-07-14 16:00:42 -04003484 if (fcport->scan_state == QLA_FCPORT_SCAN) {
3485 if (qla_ini_mode_enabled(base_vha) &&
3486 atomic_read(&fcport->state) == FCS_ONLINE) {
3487 qla2x00_mark_device_lost(vha, fcport,
3488 ql2xplogiabsentdevice, 0);
3489 if (fcport->loop_id != FC_NO_LOOP_ID &&
3490 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
3491 fcport->port_type != FCT_INITIATOR &&
3492 fcport->port_type != FCT_BROADCAST) {
3493 ha->isp_ops->fabric_logout(vha,
3494 fcport->loop_id,
3495 fcport->d_id.b.domain,
3496 fcport->d_id.b.area,
3497 fcport->d_id.b.al_pa);
3498 qla2x00_clear_loop_id(fcport);
3499 }
3500 } else if (!qla_ini_mode_enabled(base_vha)) {
3501 /*
3502 * In target mode, explicitly kill
3503 * sessions and log out of devices
3504 * that are gone, so that we don't
3505 * end up with an initiator using the
3506 * wrong ACL (if the fabric recycles
3507 * an FC address and we have a stale
3508 * session around) and so that we don't
3509 * report initiators that are no longer
3510 * on the fabric.
3511 */
3512 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf077,
3513 "port gone, logging out/killing session: "
3514 "%8phC state 0x%x flags 0x%x fc4_type 0x%x "
3515 "scan_state %d\n",
3516 fcport->port_name,
3517 atomic_read(&fcport->state),
3518 fcport->flags, fcport->fc4_type,
3519 fcport->scan_state);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003520 qlt_fc_port_deleted(vha, fcport,
3521 discovery_gen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 }
3523 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003526 /* Starting free loop ID. */
3527 next_loopid = ha->min_external_loopid;
3528
3529 /*
3530 * Scan through our port list and login entries that need to be
3531 * logged in.
3532 */
3533 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3534 if (atomic_read(&vha->loop_down_timer) ||
3535 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3536 break;
3537
3538 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3539 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3540 continue;
3541
Roland Dreierb2032fd2015-07-14 16:00:42 -04003542 /*
3543 * If we're not an initiator, skip looking for devices
3544 * and logging in. There's no reason for us to do it,
3545 * and it seems to actively cause problems in target
3546 * mode if we race with the initiator logging into us
3547 * (we might get the "port ID used" status back from
3548 * our login command and log out the initiator, which
3549 * seems to cause havoc).
3550 */
3551 if (!qla_ini_mode_enabled(base_vha)) {
3552 if (fcport->scan_state == QLA_FCPORT_FOUND) {
3553 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf078,
3554 "port %8phC state 0x%x flags 0x%x fc4_type 0x%x "
3555 "scan_state %d (initiator mode disabled; skipping "
3556 "login)\n", fcport->port_name,
3557 atomic_read(&fcport->state),
3558 fcport->flags, fcport->fc4_type,
3559 fcport->scan_state);
3560 }
3561 continue;
3562 }
3563
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003564 if (fcport->loop_id == FC_NO_LOOP_ID) {
3565 fcport->loop_id = next_loopid;
3566 rval = qla2x00_find_new_loop_id(
3567 base_vha, fcport);
3568 if (rval != QLA_SUCCESS) {
3569 /* Ran out of IDs to use */
3570 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571 }
3572 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003573 /* Login and update database */
3574 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
3575 }
3576
3577 /* Exit if out of loop IDs. */
3578 if (rval != QLA_SUCCESS) {
3579 break;
3580 }
3581
3582 /*
3583 * Login and add the new devices to our port list.
3584 */
3585 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3586 if (atomic_read(&vha->loop_down_timer) ||
3587 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3588 break;
3589
Roland Dreierb2032fd2015-07-14 16:00:42 -04003590 /*
3591 * If we're not an initiator, skip looking for devices
3592 * and logging in. There's no reason for us to do it,
3593 * and it seems to actively cause problems in target
3594 * mode if we race with the initiator logging into us
3595 * (we might get the "port ID used" status back from
3596 * our login command and log out the initiator, which
3597 * seems to cause havoc).
3598 */
3599 if (qla_ini_mode_enabled(base_vha)) {
3600 /* Find a new loop ID to use. */
3601 fcport->loop_id = next_loopid;
3602 rval = qla2x00_find_new_loop_id(base_vha,
3603 fcport);
3604 if (rval != QLA_SUCCESS) {
3605 /* Ran out of IDs to use */
3606 break;
3607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608
Roland Dreierb2032fd2015-07-14 16:00:42 -04003609 /* Login and update database */
3610 qla2x00_fabric_dev_login(vha, fcport,
3611 &next_loopid);
3612 } else {
3613 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf079,
3614 "new port %8phC state 0x%x flags 0x%x fc4_type "
3615 "0x%x scan_state %d (initiator mode disabled; "
3616 "skipping login)\n",
3617 fcport->port_name,
3618 atomic_read(&fcport->state),
3619 fcport->flags, fcport->fc4_type,
3620 fcport->scan_state);
3621 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003622
3623 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 }
3625 } while (0);
3626
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003627 /* Free all new device structures not processed. */
3628 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3629 list_del(&fcport->list);
3630 kfree(fcport);
3631 }
3632
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003634 ql_dbg(ql_dbg_disc, vha, 0x2068,
3635 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636 }
3637
3638 return (rval);
3639}
3640
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641/*
3642 * qla2x00_find_all_fabric_devs
3643 *
3644 * Input:
3645 * ha = adapter block pointer.
3646 * dev = database device entry pointer.
3647 *
3648 * Returns:
3649 * 0 = success.
3650 *
3651 * Context:
3652 * Kernel context.
3653 */
3654static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003655qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3656 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657{
3658 int rval;
3659 uint16_t loop_id;
3660 fc_port_t *fcport, *new_fcport, *fcptemp;
3661 int found;
3662
3663 sw_info_t *swl;
3664 int swl_idx;
3665 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003666 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003667 struct qla_hw_data *ha = vha->hw;
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05003668 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669
3670 rval = QLA_SUCCESS;
3671
3672 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08003673 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08003674 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08003675 GFP_KERNEL);
3676 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003677 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003679 ql_dbg(ql_dbg_disc, vha, 0x2054,
3680 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08003682 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003683 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003685 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003687 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003689 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003690 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3691 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003693
3694 /* If other queries succeeded probe for FC-4 type */
3695 if (swl)
3696 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697 }
3698 swl_idx = 0;
3699
3700 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003701 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003702 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003703 ql_log(ql_log_warn, vha, 0x205e,
3704 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 return (QLA_MEMORY_ALLOC_FAILED);
3706 }
3707 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 /* Set start port ID scan at adapter ID. */
3709 first_dev = 1;
3710 last_dev = 0;
3711
3712 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003713 loop_id = ha->min_external_loopid;
3714 for (; loop_id <= ha->max_loop_id; loop_id++) {
3715 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 continue;
3717
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003718 if (ha->current_topology == ISP_CFG_FL &&
3719 (atomic_read(&vha->loop_down_timer) ||
3720 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003721 atomic_set(&vha->loop_down_timer, 0);
3722 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3723 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003725 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726
3727 if (swl != NULL) {
3728 if (last_dev) {
3729 wrap.b24 = new_fcport->d_id.b24;
3730 } else {
3731 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3732 memcpy(new_fcport->node_name,
3733 swl[swl_idx].node_name, WWN_SIZE);
3734 memcpy(new_fcport->port_name,
3735 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003736 memcpy(new_fcport->fabric_port_name,
3737 swl[swl_idx].fabric_port_name, WWN_SIZE);
3738 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003739 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740
3741 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3742 last_dev = 1;
3743 }
3744 swl_idx++;
3745 }
3746 } else {
3747 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003748 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003750 ql_log(ql_log_warn, vha, 0x2064,
3751 "SNS scan failed -- assuming "
3752 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 list_for_each_entry_safe(fcport, fcptemp,
3754 new_fcports, list) {
3755 list_del(&fcport->list);
3756 kfree(fcport);
3757 }
3758 rval = QLA_SUCCESS;
3759 break;
3760 }
3761 }
3762
3763 /* If wrap on switch device list, exit. */
3764 if (first_dev) {
3765 wrap.b24 = new_fcport->d_id.b24;
3766 first_dev = 0;
3767 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003768 ql_dbg(ql_dbg_disc, vha, 0x2065,
3769 "Device wrap (%02x%02x%02x).\n",
3770 new_fcport->d_id.b.domain,
3771 new_fcport->d_id.b.area,
3772 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773 break;
3774 }
3775
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003776 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003777 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778 continue;
3779
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003780 /* Bypass virtual ports of the same host. */
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05003781 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
3782 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003783
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003784 /* Bypass if same domain and area of adapter. */
3785 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003786 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003787 ISP_CFG_FL)
3788 continue;
3789
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790 /* Bypass reserved domain fields. */
3791 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3792 continue;
3793
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003794 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003795 if (ql2xgffidenable &&
3796 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3797 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003798 continue;
3799
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 /* Locate matching device in database. */
3801 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003802 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 if (memcmp(new_fcport->port_name, fcport->port_name,
3804 WWN_SIZE))
3805 continue;
3806
Joe Carnuccio827210b2013-02-08 01:57:57 -05003807 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08003808
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 found++;
3810
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003811 /* Update port state. */
3812 memcpy(fcport->fabric_port_name,
3813 new_fcport->fabric_port_name, WWN_SIZE);
3814 fcport->fp_speed = new_fcport->fp_speed;
3815
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 /*
Roland Dreierb2032fd2015-07-14 16:00:42 -04003817 * If address the same and state FCS_ONLINE
3818 * (or in target mode), nothing changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 */
3820 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
Roland Dreierb2032fd2015-07-14 16:00:42 -04003821 (atomic_read(&fcport->state) == FCS_ONLINE ||
3822 !qla_ini_mode_enabled(base_vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 break;
3824 }
3825
3826 /*
3827 * If device was not a fabric device before.
3828 */
3829 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3830 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04003831 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 fcport->flags |= (FCF_FABRIC_DEVICE |
3833 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834 break;
3835 }
3836
3837 /*
3838 * Port ID changed or device was marked to be updated;
3839 * Log it out if still logged in and mark it for
3840 * relogin later.
3841 */
Roland Dreierb2032fd2015-07-14 16:00:42 -04003842 if (!qla_ini_mode_enabled(base_vha)) {
3843 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
3844 "port changed FC ID, %8phC"
3845 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
3846 fcport->port_name,
3847 fcport->d_id.b.domain,
3848 fcport->d_id.b.area,
3849 fcport->d_id.b.al_pa,
3850 fcport->loop_id,
3851 new_fcport->d_id.b.domain,
3852 new_fcport->d_id.b.area,
3853 new_fcport->d_id.b.al_pa);
3854 fcport->d_id.b24 = new_fcport->d_id.b24;
3855 break;
3856 }
3857
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 fcport->d_id.b24 = new_fcport->d_id.b24;
3859 fcport->flags |= FCF_LOGIN_NEEDED;
3860 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003861 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Arun Easi0eba25d2012-02-09 11:15:58 -08003862 (fcport->flags & FCF_ASYNC_SENT) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 fcport->port_type != FCT_INITIATOR &&
3864 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003865 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003866 fcport->d_id.b.domain, fcport->d_id.b.area,
3867 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003868 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 }
3870
3871 break;
3872 }
3873
3874 if (found)
3875 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 /* If device was not in our fcports list, then add it. */
Roland Dreierb2032fd2015-07-14 16:00:42 -04003877 new_fcport->scan_state = QLA_FCPORT_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878 list_add_tail(&new_fcport->list, new_fcports);
3879
3880 /* Allocate a new replacement fcport. */
3881 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003882 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003884 ql_log(ql_log_warn, vha, 0x2066,
3885 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886 return (QLA_MEMORY_ALLOC_FAILED);
3887 }
3888 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3889 new_fcport->d_id.b24 = nxt_d_id.b24;
3890 }
3891
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003892 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 return (rval);
3895}
3896
3897/*
3898 * qla2x00_find_new_loop_id
3899 * Scan through our port list and find a new usable loop ID.
3900 *
3901 * Input:
3902 * ha: adapter state pointer.
3903 * dev: port structure pointer.
3904 *
3905 * Returns:
3906 * qla2x00 local function return status code.
3907 *
3908 * Context:
3909 * Kernel context.
3910 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003911int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003912qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913{
3914 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003915 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07003916 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917
3918 rval = QLA_SUCCESS;
3919
Chad Dupuis5f16b332012-08-22 14:21:00 -04003920 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921
Chad Dupuis5f16b332012-08-22 14:21:00 -04003922 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
3923 LOOPID_MAP_SIZE);
3924 if (dev->loop_id >= LOOPID_MAP_SIZE ||
3925 qla2x00_is_reserved_id(vha, dev->loop_id)) {
3926 dev->loop_id = FC_NO_LOOP_ID;
3927 rval = QLA_FUNCTION_FAILED;
3928 } else
3929 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930
Chad Dupuis5f16b332012-08-22 14:21:00 -04003931 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932
Chad Dupuis5f16b332012-08-22 14:21:00 -04003933 if (rval == QLA_SUCCESS)
3934 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
3935 "Assigning new loopid=%x, portid=%x.\n",
3936 dev->loop_id, dev->d_id.b24);
3937 else
3938 ql_log(ql_log_warn, dev->vha, 0x2087,
3939 "No loop_id's available, portid=%x.\n",
3940 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941
3942 return (rval);
3943}
3944
3945/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946 * qla2x00_fabric_dev_login
3947 * Login fabric target device and update FC port database.
3948 *
3949 * Input:
3950 * ha: adapter state pointer.
3951 * fcport: port structure list pointer.
3952 * next_loopid: contains value of a new loop ID that can be used
3953 * by the next login attempt.
3954 *
3955 * Returns:
3956 * qla2x00 local function return status code.
3957 *
3958 * Context:
3959 * Kernel context.
3960 */
3961static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003962qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963 uint16_t *next_loopid)
3964{
3965 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003966 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003967 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968
3969 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970
Andrew Vasquezac280b62009-08-20 11:06:05 -07003971 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003972 if (fcport->flags & FCF_ASYNC_SENT)
3973 return rval;
3974 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003975 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3976 if (!rval)
3977 return rval;
3978 }
3979
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003980 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003981 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003983 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003984 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003985 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003986 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003987 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003989 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003990 fcport->d_id.b.domain, fcport->d_id.b.area,
3991 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003992 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003994 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 }
Chad Dupuis0b91d112012-02-09 11:15:42 -08003996 } else {
3997 /* Retry Login. */
3998 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 }
4000
4001 return (rval);
4002}
4003
4004/*
4005 * qla2x00_fabric_login
4006 * Issue fabric login command.
4007 *
4008 * Input:
4009 * ha = adapter block pointer.
4010 * device = pointer to FC device type structure.
4011 *
4012 * Returns:
4013 * 0 - Login successfully
4014 * 1 - Login failed
4015 * 2 - Initiator device
4016 * 3 - Fatal error
4017 */
4018int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004019qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 uint16_t *next_loopid)
4021{
4022 int rval;
4023 int retry;
4024 uint16_t tmp_loopid;
4025 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004026 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027
4028 retry = 0;
4029 tmp_loopid = 0;
4030
4031 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004032 ql_dbg(ql_dbg_disc, vha, 0x2000,
4033 "Trying Fabric Login w/loop id 0x%04x for port "
4034 "%02x%02x%02x.\n",
4035 fcport->loop_id, fcport->d_id.b.domain,
4036 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037
4038 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08004039 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040 fcport->d_id.b.domain, fcport->d_id.b.area,
4041 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08004042 if (rval != QLA_SUCCESS) {
4043 return rval;
4044 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045 if (mb[0] == MBS_PORT_ID_USED) {
4046 /*
4047 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004048 * recommends the driver perform an implicit login with
4049 * the specified ID again. The ID we just used is save
4050 * here so we return with an ID that can be tried by
4051 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 */
4053 retry++;
4054 tmp_loopid = fcport->loop_id;
4055 fcport->loop_id = mb[1];
4056
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004057 ql_dbg(ql_dbg_disc, vha, 0x2001,
4058 "Fabric Login: port in use - next loop "
4059 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004061 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062
4063 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
4064 /*
4065 * Login succeeded.
4066 */
4067 if (retry) {
4068 /* A retry occurred before. */
4069 *next_loopid = tmp_loopid;
4070 } else {
4071 /*
4072 * No retry occurred before. Just increment the
4073 * ID value for next login.
4074 */
4075 *next_loopid = (fcport->loop_id + 1);
4076 }
4077
4078 if (mb[1] & BIT_0) {
4079 fcport->port_type = FCT_INITIATOR;
4080 } else {
4081 fcport->port_type = FCT_TARGET;
4082 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07004083 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 }
4085 }
4086
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004087 if (mb[10] & BIT_0)
4088 fcport->supported_classes |= FC_COS_CLASS2;
4089 if (mb[10] & BIT_1)
4090 fcport->supported_classes |= FC_COS_CLASS3;
4091
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004092 if (IS_FWI2_CAPABLE(ha)) {
4093 if (mb[10] & BIT_7)
4094 fcport->flags |=
4095 FCF_CONF_COMP_SUPPORTED;
4096 }
4097
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 rval = QLA_SUCCESS;
4099 break;
4100 } else if (mb[0] == MBS_LOOP_ID_USED) {
4101 /*
4102 * Loop ID already used, try next loop ID.
4103 */
4104 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004105 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 if (rval != QLA_SUCCESS) {
4107 /* Ran out of loop IDs to use */
4108 break;
4109 }
4110 } else if (mb[0] == MBS_COMMAND_ERROR) {
4111 /*
4112 * Firmware possibly timed out during login. If NO
4113 * retries are left to do then the device is declared
4114 * dead.
4115 */
4116 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004117 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07004118 fcport->d_id.b.domain, fcport->d_id.b.area,
4119 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004120 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121
4122 rval = 1;
4123 break;
4124 } else {
4125 /*
4126 * unrecoverable / not handled error
4127 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004128 ql_dbg(ql_dbg_disc, vha, 0x2002,
4129 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
4130 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
4131 fcport->d_id.b.area, fcport->d_id.b.al_pa,
4132 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133
4134 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004135 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07004136 fcport->d_id.b.domain, fcport->d_id.b.area,
4137 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004138 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07004139 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140
4141 rval = 3;
4142 break;
4143 }
4144 }
4145
4146 return (rval);
4147}
4148
4149/*
4150 * qla2x00_local_device_login
4151 * Issue local device login command.
4152 *
4153 * Input:
4154 * ha = adapter block pointer.
4155 * loop_id = loop id of device to login to.
4156 *
4157 * Returns (Where's the #define!!!!):
4158 * 0 - Login successfully
4159 * 1 - Login failed
4160 * 3 - Fatal error
4161 */
4162int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004163qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004164{
4165 int rval;
4166 uint16_t mb[MAILBOX_REGISTER_COUNT];
4167
4168 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004169 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170 if (rval == QLA_SUCCESS) {
4171 /* Interrogate mailbox registers for any errors */
4172 if (mb[0] == MBS_COMMAND_ERROR)
4173 rval = 1;
4174 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
4175 /* device not in PCB table */
4176 rval = 3;
4177 }
4178
4179 return (rval);
4180}
4181
4182/*
4183 * qla2x00_loop_resync
4184 * Resync with fibre channel devices.
4185 *
4186 * Input:
4187 * ha = adapter block pointer.
4188 *
4189 * Returns:
4190 * 0 = success
4191 */
4192int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004193qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004195 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004197 struct req_que *req;
4198 struct rsp_que *rsp;
4199
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004200 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004201 req = vha->hw->req_q_map[0];
4202 else
4203 req = vha->req;
4204 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004206 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4207 if (vha->flags.online) {
4208 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4210 wait_time = 256;
4211 do {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004212 if (!IS_QLAFX00(vha->hw)) {
4213 /*
4214 * Issue a marker after FW becomes
4215 * ready.
4216 */
4217 qla2x00_marker(vha, req, rsp, 0, 0,
4218 MK_SYNC_ALL);
4219 vha->marker_needed = 0;
4220 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221
4222 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004223 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004225 if (IS_QLAFX00(vha->hw))
4226 qlafx00_configure_devices(vha);
4227 else
4228 qla2x00_configure_loop(vha);
4229
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004231 } while (!atomic_read(&vha->loop_down_timer) &&
4232 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4233 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4234 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004236 }
4237
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004238 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004239 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004241 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004242 ql_dbg(ql_dbg_disc, vha, 0x206c,
4243 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004244
4245 return (rval);
4246}
4247
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004248/*
4249* qla2x00_perform_loop_resync
4250* Description: This function will set the appropriate flags and call
4251* qla2x00_loop_resync. If successful loop will be resynced
4252* Arguments : scsi_qla_host_t pointer
4253* returm : Success or Failure
4254*/
4255
4256int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
4257{
4258 int32_t rval = 0;
4259
4260 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
4261 /*Configure the flags so that resync happens properly*/
4262 atomic_set(&ha->loop_down_timer, 0);
4263 if (!(ha->device_flags & DFLG_NO_CABLE)) {
4264 atomic_set(&ha->loop_state, LOOP_UP);
4265 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4266 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
4267 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4268
4269 rval = qla2x00_loop_resync(ha);
4270 } else
4271 atomic_set(&ha->loop_state, LOOP_DEAD);
4272
4273 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
4274 }
4275
4276 return rval;
4277}
4278
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279void
Andrew Vasquez67becc02009-08-25 11:36:20 -07004280qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004281{
4282 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07004283 struct scsi_qla_host *vha;
4284 struct qla_hw_data *ha = base_vha->hw;
4285 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004286
Arun Easifeafb7b2010-09-03 14:57:00 -07004287 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004288 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07004289 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
4290 atomic_inc(&vha->vref_count);
4291 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08004292 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07004293 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
4294 spin_unlock_irqrestore(&ha->vport_slock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07004295 qla2x00_rport_del(fcport);
Alexei Potashnikdf673272015-07-14 16:00:46 -04004296
4297 /*
4298 * Release the target mode FC NEXUS in
4299 * qla_target.c, if target mod is enabled.
4300 */
4301 qlt_fc_port_deleted(vha, fcport,
4302 base_vha->total_fcport_update_gen);
4303
Arun Easifeafb7b2010-09-03 14:57:00 -07004304 spin_lock_irqsave(&ha->vport_slock, flags);
4305 }
4306 }
4307 atomic_dec(&vha->vref_count);
4308 }
4309 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004310}
4311
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004312/* Assumes idc_lock always held on entry */
4313void
4314qla83xx_reset_ownership(scsi_qla_host_t *vha)
4315{
4316 struct qla_hw_data *ha = vha->hw;
4317 uint32_t drv_presence, drv_presence_mask;
4318 uint32_t dev_part_info1, dev_part_info2, class_type;
4319 uint32_t class_type_mask = 0x3;
4320 uint16_t fcoe_other_function = 0xffff, i;
4321
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004322 if (IS_QLA8044(ha)) {
4323 drv_presence = qla8044_rd_direct(vha,
4324 QLA8044_CRB_DRV_ACTIVE_INDEX);
4325 dev_part_info1 = qla8044_rd_direct(vha,
4326 QLA8044_CRB_DEV_PART_INFO_INDEX);
4327 dev_part_info2 = qla8044_rd_direct(vha,
4328 QLA8044_CRB_DEV_PART_INFO2);
4329 } else {
4330 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4331 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
4332 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
4333 }
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004334 for (i = 0; i < 8; i++) {
4335 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
4336 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4337 (i != ha->portnum)) {
4338 fcoe_other_function = i;
4339 break;
4340 }
4341 }
4342 if (fcoe_other_function == 0xffff) {
4343 for (i = 0; i < 8; i++) {
4344 class_type = ((dev_part_info2 >> (i * 4)) &
4345 class_type_mask);
4346 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4347 ((i + 8) != ha->portnum)) {
4348 fcoe_other_function = i + 8;
4349 break;
4350 }
4351 }
4352 }
4353 /*
4354 * Prepare drv-presence mask based on fcoe functions present.
4355 * However consider only valid physical fcoe function numbers (0-15).
4356 */
4357 drv_presence_mask = ~((1 << (ha->portnum)) |
4358 ((fcoe_other_function == 0xffff) ?
4359 0 : (1 << (fcoe_other_function))));
4360
4361 /* We are the reset owner iff:
4362 * - No other protocol drivers present.
4363 * - This is the lowest among fcoe functions. */
4364 if (!(drv_presence & drv_presence_mask) &&
4365 (ha->portnum < fcoe_other_function)) {
4366 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
4367 "This host is Reset owner.\n");
4368 ha->flags.nic_core_reset_owner = 1;
4369 }
4370}
4371
Saurav Kashyapfa492632012-11-21 02:40:29 -05004372static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004373__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
4374{
4375 int rval = QLA_SUCCESS;
4376 struct qla_hw_data *ha = vha->hw;
4377 uint32_t drv_ack;
4378
4379 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4380 if (rval == QLA_SUCCESS) {
4381 drv_ack |= (1 << ha->portnum);
4382 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4383 }
4384
4385 return rval;
4386}
4387
Saurav Kashyapfa492632012-11-21 02:40:29 -05004388static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004389__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
4390{
4391 int rval = QLA_SUCCESS;
4392 struct qla_hw_data *ha = vha->hw;
4393 uint32_t drv_ack;
4394
4395 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4396 if (rval == QLA_SUCCESS) {
4397 drv_ack &= ~(1 << ha->portnum);
4398 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4399 }
4400
4401 return rval;
4402}
4403
Saurav Kashyapfa492632012-11-21 02:40:29 -05004404static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004405qla83xx_dev_state_to_string(uint32_t dev_state)
4406{
4407 switch (dev_state) {
4408 case QLA8XXX_DEV_COLD:
4409 return "COLD/RE-INIT";
4410 case QLA8XXX_DEV_INITIALIZING:
4411 return "INITIALIZING";
4412 case QLA8XXX_DEV_READY:
4413 return "READY";
4414 case QLA8XXX_DEV_NEED_RESET:
4415 return "NEED RESET";
4416 case QLA8XXX_DEV_NEED_QUIESCENT:
4417 return "NEED QUIESCENT";
4418 case QLA8XXX_DEV_FAILED:
4419 return "FAILED";
4420 case QLA8XXX_DEV_QUIESCENT:
4421 return "QUIESCENT";
4422 default:
4423 return "Unknown";
4424 }
4425}
4426
4427/* Assumes idc-lock always held on entry */
4428void
4429qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
4430{
4431 struct qla_hw_data *ha = vha->hw;
4432 uint32_t idc_audit_reg = 0, duration_secs = 0;
4433
4434 switch (audit_type) {
4435 case IDC_AUDIT_TIMESTAMP:
4436 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
4437 idc_audit_reg = (ha->portnum) |
4438 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
4439 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4440 break;
4441
4442 case IDC_AUDIT_COMPLETION:
4443 duration_secs = ((jiffies_to_msecs(jiffies) -
4444 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
4445 idc_audit_reg = (ha->portnum) |
4446 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
4447 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4448 break;
4449
4450 default:
4451 ql_log(ql_log_warn, vha, 0xb078,
4452 "Invalid audit type specified.\n");
4453 break;
4454 }
4455}
4456
4457/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05004458static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004459qla83xx_initiating_reset(scsi_qla_host_t *vha)
4460{
4461 struct qla_hw_data *ha = vha->hw;
4462 uint32_t idc_control, dev_state;
4463
4464 __qla83xx_get_idc_control(vha, &idc_control);
4465 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
4466 ql_log(ql_log_info, vha, 0xb080,
4467 "NIC Core reset has been disabled. idc-control=0x%x\n",
4468 idc_control);
4469 return QLA_FUNCTION_FAILED;
4470 }
4471
4472 /* Set NEED-RESET iff in READY state and we are the reset-owner */
4473 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4474 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
4475 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
4476 QLA8XXX_DEV_NEED_RESET);
4477 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
4478 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
4479 } else {
4480 const char *state = qla83xx_dev_state_to_string(dev_state);
4481 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
4482
4483 /* SV: XXX: Is timeout required here? */
4484 /* Wait for IDC state change READY -> NEED_RESET */
4485 while (dev_state == QLA8XXX_DEV_READY) {
4486 qla83xx_idc_unlock(vha, 0);
4487 msleep(200);
4488 qla83xx_idc_lock(vha, 0);
4489 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4490 }
4491 }
4492
4493 /* Send IDC ack by writing to drv-ack register */
4494 __qla83xx_set_drv_ack(vha);
4495
4496 return QLA_SUCCESS;
4497}
4498
4499int
4500__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
4501{
4502 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4503}
4504
4505int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004506__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
4507{
4508 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4509}
4510
Saurav Kashyapfa492632012-11-21 02:40:29 -05004511static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004512qla83xx_check_driver_presence(scsi_qla_host_t *vha)
4513{
4514 uint32_t drv_presence = 0;
4515 struct qla_hw_data *ha = vha->hw;
4516
4517 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4518 if (drv_presence & (1 << ha->portnum))
4519 return QLA_SUCCESS;
4520 else
4521 return QLA_TEST_FAILED;
4522}
4523
4524int
4525qla83xx_nic_core_reset(scsi_qla_host_t *vha)
4526{
4527 int rval = QLA_SUCCESS;
4528 struct qla_hw_data *ha = vha->hw;
4529
4530 ql_dbg(ql_dbg_p3p, vha, 0xb058,
4531 "Entered %s().\n", __func__);
4532
4533 if (vha->device_flags & DFLG_DEV_FAILED) {
4534 ql_log(ql_log_warn, vha, 0xb059,
4535 "Device in unrecoverable FAILED state.\n");
4536 return QLA_FUNCTION_FAILED;
4537 }
4538
4539 qla83xx_idc_lock(vha, 0);
4540
4541 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
4542 ql_log(ql_log_warn, vha, 0xb05a,
4543 "Function=0x%x has been removed from IDC participation.\n",
4544 ha->portnum);
4545 rval = QLA_FUNCTION_FAILED;
4546 goto exit;
4547 }
4548
4549 qla83xx_reset_ownership(vha);
4550
4551 rval = qla83xx_initiating_reset(vha);
4552
4553 /*
4554 * Perform reset if we are the reset-owner,
4555 * else wait till IDC state changes to READY/FAILED.
4556 */
4557 if (rval == QLA_SUCCESS) {
4558 rval = qla83xx_idc_state_handler(vha);
4559
4560 if (rval == QLA_SUCCESS)
4561 ha->flags.nic_core_hung = 0;
4562 __qla83xx_clear_drv_ack(vha);
4563 }
4564
4565exit:
4566 qla83xx_idc_unlock(vha, 0);
4567
4568 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
4569
4570 return rval;
4571}
4572
Saurav Kashyap81178772012-08-22 14:21:04 -04004573int
4574qla2xxx_mctp_dump(scsi_qla_host_t *vha)
4575{
4576 struct qla_hw_data *ha = vha->hw;
4577 int rval = QLA_FUNCTION_FAILED;
4578
4579 if (!IS_MCTP_CAPABLE(ha)) {
4580 /* This message can be removed from the final version */
4581 ql_log(ql_log_info, vha, 0x506d,
4582 "This board is not MCTP capable\n");
4583 return rval;
4584 }
4585
4586 if (!ha->mctp_dump) {
4587 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
4588 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
4589
4590 if (!ha->mctp_dump) {
4591 ql_log(ql_log_warn, vha, 0x506e,
4592 "Failed to allocate memory for mctp dump\n");
4593 return rval;
4594 }
4595 }
4596
4597#define MCTP_DUMP_STR_ADDR 0x00000000
4598 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
4599 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
4600 if (rval != QLA_SUCCESS) {
4601 ql_log(ql_log_warn, vha, 0x506f,
4602 "Failed to capture mctp dump\n");
4603 } else {
4604 ql_log(ql_log_info, vha, 0x5070,
4605 "Mctp dump capture for host (%ld/%p).\n",
4606 vha->host_no, ha->mctp_dump);
4607 ha->mctp_dumped = 1;
4608 }
4609
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04004610 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04004611 ha->flags.nic_core_reset_hdlr_active = 1;
4612 rval = qla83xx_restart_nic_firmware(vha);
4613 if (rval)
4614 /* NIC Core reset failed. */
4615 ql_log(ql_log_warn, vha, 0x5071,
4616 "Failed to restart nic firmware\n");
4617 else
4618 ql_dbg(ql_dbg_p3p, vha, 0xb084,
4619 "Restarted NIC firmware successfully.\n");
4620 ha->flags.nic_core_reset_hdlr_active = 0;
4621 }
4622
4623 return rval;
4624
4625}
4626
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004627/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004628* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004629* Description: This function will block the new I/Os
4630* Its not aborting any I/Os as context
4631* is not destroyed during quiescence
4632* Arguments: scsi_qla_host_t
4633* return : void
4634*/
4635void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004636qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004637{
4638 struct qla_hw_data *ha = vha->hw;
4639 struct scsi_qla_host *vp;
4640
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004641 ql_dbg(ql_dbg_dpc, vha, 0x401d,
4642 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004643
4644 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4645 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4646 atomic_set(&vha->loop_state, LOOP_DOWN);
4647 qla2x00_mark_all_devices_lost(vha, 0);
4648 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004649 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004650 } else {
4651 if (!atomic_read(&vha->loop_down_timer))
4652 atomic_set(&vha->loop_down_timer,
4653 LOOP_DOWN_TIME);
4654 }
4655 /* Wait for pending cmds to complete */
4656 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
4657}
4658
Giridhar Malavalia9083012010-04-12 17:59:55 -07004659void
4660qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
4661{
4662 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004663 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07004664 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004665 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004666
Saurav Kashyape46ef002011-02-23 15:27:16 -08004667 /* For ISP82XX, driver waits for completion of the commands.
4668 * online flag should be set.
4669 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004670 if (!(IS_P3P_TYPE(ha)))
Saurav Kashyape46ef002011-02-23 15:27:16 -08004671 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004672 ha->flags.chip_reset_done = 0;
4673 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04004674 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004675
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004676 ql_log(ql_log_info, vha, 0x00af,
4677 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004678
Saurav Kashyape46ef002011-02-23 15:27:16 -08004679 /* For ISP82XX, reset_chip is just disabling interrupts.
4680 * Driver waits for the completion of the commands.
4681 * the interrupts need to be enabled.
4682 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004683 if (!(IS_P3P_TYPE(ha)))
Giridhar Malavalia9083012010-04-12 17:59:55 -07004684 ha->isp_ops->reset_chip(vha);
4685
4686 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
4687 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4688 atomic_set(&vha->loop_state, LOOP_DOWN);
4689 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004690
4691 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004692 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07004693 atomic_inc(&vp->vref_count);
4694 spin_unlock_irqrestore(&ha->vport_slock, flags);
4695
Giridhar Malavalia9083012010-04-12 17:59:55 -07004696 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004697
4698 spin_lock_irqsave(&ha->vport_slock, flags);
4699 atomic_dec(&vp->vref_count);
4700 }
4701 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004702 } else {
4703 if (!atomic_read(&vha->loop_down_timer))
4704 atomic_set(&vha->loop_down_timer,
4705 LOOP_DOWN_TIME);
4706 }
4707
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004708 /* Clear all async request states across all VPs. */
4709 list_for_each_entry(fcport, &vha->vp_fcports, list)
4710 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4711 spin_lock_irqsave(&ha->vport_slock, flags);
4712 list_for_each_entry(vp, &ha->vp_list, list) {
4713 atomic_inc(&vp->vref_count);
4714 spin_unlock_irqrestore(&ha->vport_slock, flags);
4715
4716 list_for_each_entry(fcport, &vp->vp_fcports, list)
4717 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4718
4719 spin_lock_irqsave(&ha->vport_slock, flags);
4720 atomic_dec(&vp->vref_count);
4721 }
4722 spin_unlock_irqrestore(&ha->vport_slock, flags);
4723
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004724 if (!ha->flags.eeh_busy) {
4725 /* Make sure for ISP 82XX IO DMA is complete */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004726 if (IS_P3P_TYPE(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004727 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004728 ql_log(ql_log_info, vha, 0x00b4,
4729 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004730
Saurav Kashyape46ef002011-02-23 15:27:16 -08004731 /* Done waiting for pending commands.
4732 * Reset the online flag.
4733 */
4734 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004735 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004737 /* Requeue all commands in outstanding command list. */
4738 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4739 }
Arun Easib6a029e2014-09-25 06:14:52 -04004740
4741 ha->chip_reset++;
4742 /* memory barrier */
4743 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744}
4745
4746/*
4747* qla2x00_abort_isp
4748* Resets ISP and aborts all outstanding commands.
4749*
4750* Input:
4751* ha = adapter block pointer.
4752*
4753* Returns:
4754* 0 = success
4755*/
4756int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004757qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004758{
Andrew Vasquez476e8972006-08-23 14:54:55 -07004759 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004760 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004761 struct qla_hw_data *ha = vha->hw;
4762 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004763 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07004764 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004766 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004767 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004768
Santosh Vernekara61712972012-08-22 14:21:13 -04004769 if (IS_QLA8031(ha)) {
4770 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
4771 "Clearing fcoe driver presence.\n");
4772 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
4773 ql_dbg(ql_dbg_p3p, vha, 0xb073,
4774 "Error while clearing DRV-Presence.\n");
4775 }
4776
Andrew Vasquez85880802009-12-15 21:29:46 -08004777 if (unlikely(pci_channel_offline(ha->pdev) &&
4778 ha->flags.pci_channel_io_perm_failure)) {
4779 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4780 status = 0;
4781 return status;
4782 }
4783
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004784 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08004785
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004786 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004788 if (!qla2x00_restart_isp(vha)) {
4789 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004791 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004792 /*
4793 * Issue marker command only when we are going
4794 * to start the I/O .
4795 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004796 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797 }
4798
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004799 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004800
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004801 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004802
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004803 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004804 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07004805
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004806 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
4807 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004808 if (ha->fce) {
4809 ha->flags.fce_enabled = 1;
4810 memset(ha->fce, 0,
4811 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004812 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004813 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4814 &ha->fce_bufs);
4815 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004816 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004817 "Unable to reinitialize FCE "
4818 "(%d).\n", rval);
4819 ha->flags.fce_enabled = 0;
4820 }
4821 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004822
4823 if (ha->eft) {
4824 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004825 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004826 ha->eft_dma, EFT_NUM_BUFFERS);
4827 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004828 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004829 "Unable to reinitialize EFT "
4830 "(%d).\n", rval);
4831 }
4832 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004833 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004834 vha->flags.online = 1;
4835 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004837 ql_log(ql_log_fatal, vha, 0x8035,
4838 "ISP error recover failed - "
4839 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004840 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841 * The next call disables the board
4842 * completely.
4843 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004844 ha->isp_ops->reset_adapter(vha);
4845 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004847 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848 status = 0;
4849 } else { /* schedule another ISP abort */
4850 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004851 ql_dbg(ql_dbg_taskm, vha, 0x8020,
4852 "ISP abort - retry remaining %d.\n",
4853 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854 status = 1;
4855 }
4856 } else {
4857 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004858 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4859 "ISP error recovery - retrying (%d) "
4860 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004861 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004862 status = 1;
4863 }
4864 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004865
Linus Torvalds1da177e2005-04-16 15:20:36 -07004866 }
4867
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004868 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004869 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07004870
4871 spin_lock_irqsave(&ha->vport_slock, flags);
4872 list_for_each_entry(vp, &ha->vp_list, list) {
4873 if (vp->vp_idx) {
4874 atomic_inc(&vp->vref_count);
4875 spin_unlock_irqrestore(&ha->vport_slock, flags);
4876
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004877 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004878
4879 spin_lock_irqsave(&ha->vport_slock, flags);
4880 atomic_dec(&vp->vref_count);
4881 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004882 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004883 spin_unlock_irqrestore(&ha->vport_slock, flags);
4884
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004885 if (IS_QLA8031(ha)) {
4886 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
4887 "Setting back fcoe driver presence.\n");
4888 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
4889 ql_dbg(ql_dbg_p3p, vha, 0xb074,
4890 "Error while setting DRV-Presence.\n");
4891 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004892 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08004893 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
4894 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895 }
4896
4897 return(status);
4898}
4899
4900/*
4901* qla2x00_restart_isp
4902* restarts the ISP after a reset
4903*
4904* Input:
4905* ha = adapter block pointer.
4906*
4907* Returns:
4908* 0 = success
4909*/
4910static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004911qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004912{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004913 int status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004914 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004915 struct req_que *req = ha->req_q_map[0];
4916 struct rsp_que *rsp = ha->rsp_q_map[0];
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004917 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918
4919 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004920 if (qla2x00_isp_firmware(vha)) {
4921 vha->flags.online = 0;
4922 status = ha->isp_ops->chip_diag(vha);
4923 if (!status)
4924 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925 }
4926
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004927 if (!status && !(status = qla2x00_init_rings(vha))) {
4928 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004929 ha->flags.chip_reset_done = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04004930
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004931 /* Initialize the queues in use */
4932 qla25xx_init_queues(ha);
4933
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004934 status = qla2x00_fw_ready(vha);
4935 if (!status) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004936 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004937 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004938
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004939 vha->flags.online = 1;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004940
4941 /*
4942 * Process any ATIO queue entries that came in
4943 * while we weren't online.
4944 */
4945 spin_lock_irqsave(&ha->hardware_lock, flags);
4946 if (qla_tgt_mode_enabled(vha))
4947 qlt_24xx_process_atio_queue(vha);
4948 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4949
Chad Dupuis7108b762014-04-11 16:54:45 -04004950 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951 }
4952
4953 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004954 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004955 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004956 }
4957 return (status);
4958}
4959
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004960static int
4961qla25xx_init_queues(struct qla_hw_data *ha)
4962{
4963 struct rsp_que *rsp = NULL;
4964 struct req_que *req = NULL;
4965 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4966 int ret = -1;
4967 int i;
4968
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004969 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004970 rsp = ha->rsp_q_map[i];
4971 if (rsp) {
4972 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004973 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004974 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004975 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4976 "%s Rsp que: %d init failed.\n",
4977 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004978 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004979 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4980 "%s Rsp que: %d inited.\n",
4981 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004982 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004983 }
4984 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004985 req = ha->req_q_map[i];
4986 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004987 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004988 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004989 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004990 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004991 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4992 "%s Req que: %d init failed.\n",
4993 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004994 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004995 ql_dbg(ql_dbg_init, base_vha, 0x0102,
4996 "%s Req que: %d inited.\n",
4997 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004998 }
4999 }
5000 return ret;
5001}
5002
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003/*
5004* qla2x00_reset_adapter
5005* Reset adapter.
5006*
5007* Input:
5008* ha = adapter block pointer.
5009*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07005010void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005011qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005012{
5013 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005014 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07005015 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005017 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005018 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019
Linus Torvalds1da177e2005-04-16 15:20:36 -07005020 spin_lock_irqsave(&ha->hardware_lock, flags);
5021 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
5022 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
5023 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
5024 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
5025 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5026}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005027
5028void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005029qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005030{
5031 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005032 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005033 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
5034
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005035 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005036 return;
5037
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005038 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005039 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005040
5041 spin_lock_irqsave(&ha->hardware_lock, flags);
5042 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
5043 RD_REG_DWORD(&reg->hccr);
5044 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
5045 RD_REG_DWORD(&reg->hccr);
5046 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08005047
5048 if (IS_NOPOLLING_TYPE(ha))
5049 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005050}
5051
David Miller4e08df32007-04-16 12:37:43 -07005052/* On sparc systems, obtain port and node WWN from firmware
5053 * properties.
5054 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005055static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
5056 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07005057{
5058#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005059 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07005060 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07005061 struct device_node *dp = pci_device_to_OF_node(pdev);
5062 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07005063 int len;
5064
5065 val = of_get_property(dp, "port-wwn", &len);
5066 if (val && len >= WWN_SIZE)
5067 memcpy(nv->port_name, val, WWN_SIZE);
5068
5069 val = of_get_property(dp, "node-wwn", &len);
5070 if (val && len >= WWN_SIZE)
5071 memcpy(nv->node_name, val, WWN_SIZE);
5072#endif
5073}
5074
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005075int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005076qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005077{
David Miller4e08df32007-04-16 12:37:43 -07005078 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005079 struct init_cb_24xx *icb;
5080 struct nvram_24xx *nv;
5081 uint32_t *dptr;
5082 uint8_t *dptr1, *dptr2;
5083 uint32_t chksum;
5084 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005085 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005086
David Miller4e08df32007-04-16 12:37:43 -07005087 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005088 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07005089 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005090
5091 /* Determine NVRAM starting address. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05005092 if (ha->port_no == 0) {
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005093 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
5094 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
5095 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005096 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08005097 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
5098 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05005099
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005100 ha->nvram_size = sizeof(struct nvram_24xx);
5101 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005102
Seokmann Ju281afe12007-07-26 13:43:34 -07005103 /* Get VPD data into cache */
5104 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005105 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07005106 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
5107
5108 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005109 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005110 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005111 ha->nvram_size);
5112 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5113 chksum += le32_to_cpu(*dptr++);
5114
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005115 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
5116 "Contents of NVRAM\n");
5117 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
5118 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005119
5120 /* Bad NVRAM data, set defaults parameters. */
5121 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5122 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07005123 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005124 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005125 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04005126 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005127 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
5128 ql_log(ql_log_warn, vha, 0x006c,
5129 "Falling back to functioning (yet invalid -- WWPN) "
5130 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07005131
5132 /*
5133 * Set default initialization control block.
5134 */
5135 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07005136 nv->nvram_version = cpu_to_le16(ICB_VERSION);
5137 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04005138 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07005139 nv->execution_throttle = cpu_to_le16(0xFFFF);
5140 nv->exchange_count = cpu_to_le16(0);
5141 nv->hard_address = cpu_to_le16(124);
David Miller4e08df32007-04-16 12:37:43 -07005142 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005143 nv->port_name[1] = 0x00 + ha->port_no + 1;
David Miller4e08df32007-04-16 12:37:43 -07005144 nv->port_name[2] = 0x00;
5145 nv->port_name[3] = 0xe0;
5146 nv->port_name[4] = 0x8b;
5147 nv->port_name[5] = 0x1c;
5148 nv->port_name[6] = 0x55;
5149 nv->port_name[7] = 0x86;
5150 nv->node_name[0] = 0x20;
5151 nv->node_name[1] = 0x00;
5152 nv->node_name[2] = 0x00;
5153 nv->node_name[3] = 0xe0;
5154 nv->node_name[4] = 0x8b;
5155 nv->node_name[5] = 0x1c;
5156 nv->node_name[6] = 0x55;
5157 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005158 qla24xx_nvram_wwn_from_ofw(vha, nv);
Bart Van Asschead950362015-07-09 07:24:08 -07005159 nv->login_retry_count = cpu_to_le16(8);
5160 nv->interrupt_delay_timer = cpu_to_le16(0);
5161 nv->login_timeout = cpu_to_le16(0);
David Miller4e08df32007-04-16 12:37:43 -07005162 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07005163 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5164 nv->firmware_options_2 = cpu_to_le32(2 << 4);
5165 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
5166 nv->firmware_options_3 = cpu_to_le32(2 << 13);
5167 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
5168 nv->efi_parameters = cpu_to_le32(0);
David Miller4e08df32007-04-16 12:37:43 -07005169 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07005170 nv->max_luns_per_target = cpu_to_le16(128);
5171 nv->port_down_retry_count = cpu_to_le16(30);
5172 nv->link_down_timeout = cpu_to_le16(30);
David Miller4e08df32007-04-16 12:37:43 -07005173
5174 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005175 }
5176
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005177 if (!qla_ini_mode_enabled(vha)) {
5178 /* Don't enable full login after initial LIP */
Bart Van Asschead950362015-07-09 07:24:08 -07005179 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005180 /* Don't enable LIP full login for initiator */
Bart Van Asschead950362015-07-09 07:24:08 -07005181 nv->host_p &= cpu_to_le32(~BIT_10);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005182 }
5183
5184 qlt_24xx_config_nvram_stage1(vha, nv);
5185
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005186 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005187 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005188
5189 /* Copy 1st segment. */
5190 dptr1 = (uint8_t *)icb;
5191 dptr2 = (uint8_t *)&nv->version;
5192 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5193 while (cnt--)
5194 *dptr1++ = *dptr2++;
5195
5196 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07005197 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005198
5199 /* Copy 2nd segment. */
5200 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5201 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5202 cnt = (uint8_t *)&icb->reserved_3 -
5203 (uint8_t *)&icb->interrupt_delay_timer;
5204 while (cnt--)
5205 *dptr1++ = *dptr2++;
5206
5207 /*
5208 * Setup driver NVRAM options.
5209 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005210 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08005211 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005212
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005213 qlt_24xx_config_nvram_stage2(vha, icb);
5214
Bart Van Asschead950362015-07-09 07:24:08 -07005215 if (nv->host_p & cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005216 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07005217 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5218 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5219 }
5220
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005221 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07005222 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005223 /*
5224 * Firmware will apply the following mask if the nodename was
5225 * not provided.
5226 */
5227 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5228 icb->node_name[0] &= 0xF0;
5229 }
5230
5231 /* Set host adapter parameters. */
5232 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08005233 ha->flags.enable_lip_reset = 0;
5234 ha->flags.enable_lip_full_login =
5235 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5236 ha->flags.enable_target_reset =
5237 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005238 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07005239 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005240
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07005241 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5242 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005243
5244 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
5245 sizeof(ha->fw_seriallink_options24));
5246
5247 /* save HBA serial number */
5248 ha->serial0 = icb->port_name[5];
5249 ha->serial1 = icb->port_name[6];
5250 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005251 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5252 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005253
Bart Van Asschead950362015-07-09 07:24:08 -07005254 icb->execution_throttle = cpu_to_le16(0xFFFF);
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08005255
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005256 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5257
5258 /* Set minimum login_timeout to 4 seconds. */
5259 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5260 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5261 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07005262 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005263 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07005264 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005265
Andrew Vasquez00a537b2008-02-28 14:06:11 -08005266 /* Set minimum RATOV to 100 tenths of a second. */
5267 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005268
5269 ha->loop_reset_delay = nv->reset_delay;
5270
5271 /* Link Down Timeout = 0:
5272 *
5273 * When Port Down timer expires we will start returning
5274 * I/O's to OS with "DID_NO_CONNECT".
5275 *
5276 * Link Down Timeout != 0:
5277 *
5278 * The driver waits for the link to come up after link down
5279 * before returning I/Os to OS with "DID_NO_CONNECT".
5280 */
5281 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5282 ha->loop_down_abort_time =
5283 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5284 } else {
5285 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5286 ha->loop_down_abort_time =
5287 (LOOP_DOWN_TIME - ha->link_down_timeout);
5288 }
5289
5290 /* Need enough time to try and get the port back. */
5291 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5292 if (qlport_down_retry)
5293 ha->port_down_retry_count = qlport_down_retry;
5294
5295 /* Set login_retry_count */
5296 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5297 if (ha->port_down_retry_count ==
5298 le16_to_cpu(nv->port_down_retry_count) &&
5299 ha->port_down_retry_count > 3)
5300 ha->login_retry_count = ha->port_down_retry_count;
5301 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5302 ha->login_retry_count = ha->port_down_retry_count;
5303 if (ql2xloginretrycount)
5304 ha->login_retry_count = ql2xloginretrycount;
5305
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005306 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005307 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005308 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5309 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5310 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5311 le16_to_cpu(icb->interrupt_delay_timer): 2;
5312 }
Bart Van Asschead950362015-07-09 07:24:08 -07005313 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005314 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005315 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005316 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08005317 ha->zio_mode = QLA_ZIO_MODE_6;
5318
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005319 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005320 "ZIO mode %d enabled; timer delay (%d us).\n",
5321 ha->zio_mode, ha->zio_timer * 100);
5322
5323 icb->firmware_options_2 |= cpu_to_le32(
5324 (uint32_t)ha->zio_mode);
5325 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005326 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005327 }
5328
David Miller4e08df32007-04-16 12:37:43 -07005329 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005330 ql_log(ql_log_warn, vha, 0x0070,
5331 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07005332 }
5333 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005334}
5335
Adrian Bunk413975a2006-06-30 02:33:06 -07005336static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005337qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
5338 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005339{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005340 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005341 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005342 uint32_t *dcode, dlen;
5343 uint32_t risc_addr;
5344 uint32_t risc_size;
5345 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005346 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005347 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005348
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005349 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08005350 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005351
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005352 rval = QLA_SUCCESS;
5353
5354 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005355 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005356 *srisc_addr = 0;
5357
5358 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005359 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005360 for (i = 0; i < 4; i++)
5361 dcode[i] = be32_to_cpu(dcode[i]);
5362 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5363 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5364 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5365 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005366 ql_log(ql_log_fatal, vha, 0x008c,
5367 "Unable to verify the integrity of flash firmware "
5368 "image.\n");
5369 ql_log(ql_log_fatal, vha, 0x008d,
5370 "Firmware data: %08x %08x %08x %08x.\n",
5371 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005372
5373 return QLA_FUNCTION_FAILED;
5374 }
5375
5376 while (segments && rval == QLA_SUCCESS) {
5377 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005378 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005379
5380 risc_addr = be32_to_cpu(dcode[2]);
5381 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5382 risc_size = be32_to_cpu(dcode[3]);
5383
5384 fragment = 0;
5385 while (risc_size > 0 && rval == QLA_SUCCESS) {
5386 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5387 if (dlen > risc_size)
5388 dlen = risc_size;
5389
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005390 ql_dbg(ql_dbg_init, vha, 0x008e,
5391 "Loading risc segment@ risc addr %x "
5392 "number of dwords 0x%x offset 0x%x.\n",
5393 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005394
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005395 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005396 for (i = 0; i < dlen; i++)
5397 dcode[i] = swab32(dcode[i]);
5398
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005399 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005400 dlen);
5401 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005402 ql_log(ql_log_fatal, vha, 0x008f,
5403 "Failed to load segment %d of firmware.\n",
5404 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04005405 return QLA_FUNCTION_FAILED;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005406 }
5407
5408 faddr += dlen;
5409 risc_addr += dlen;
5410 risc_size -= dlen;
5411 fragment++;
5412 }
5413
5414 /* Next segment. */
5415 segments--;
5416 }
5417
Chad Dupuisf73cb692014-02-26 04:15:06 -05005418 if (!IS_QLA27XX(ha))
5419 return rval;
5420
5421 if (ha->fw_dump_template)
5422 vfree(ha->fw_dump_template);
5423 ha->fw_dump_template = NULL;
5424 ha->fw_dump_template_len = 0;
5425
5426 ql_dbg(ql_dbg_init, vha, 0x0161,
5427 "Loading fwdump template from %x\n", faddr);
5428 qla24xx_read_flash_data(vha, dcode, faddr, 7);
5429 risc_size = be32_to_cpu(dcode[2]);
5430 ql_dbg(ql_dbg_init, vha, 0x0162,
5431 "-> array size %x dwords\n", risc_size);
5432 if (risc_size == 0 || risc_size == ~0)
5433 goto default_template;
5434
5435 dlen = (risc_size - 8) * sizeof(*dcode);
5436 ql_dbg(ql_dbg_init, vha, 0x0163,
5437 "-> template allocating %x bytes...\n", dlen);
5438 ha->fw_dump_template = vmalloc(dlen);
5439 if (!ha->fw_dump_template) {
5440 ql_log(ql_log_warn, vha, 0x0164,
5441 "Failed fwdump template allocate %x bytes.\n", risc_size);
5442 goto default_template;
5443 }
5444
5445 faddr += 7;
5446 risc_size -= 8;
5447 dcode = ha->fw_dump_template;
5448 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
5449 for (i = 0; i < risc_size; i++)
5450 dcode[i] = le32_to_cpu(dcode[i]);
5451
5452 if (!qla27xx_fwdt_template_valid(dcode)) {
5453 ql_log(ql_log_warn, vha, 0x0165,
5454 "Failed fwdump template validate\n");
5455 goto default_template;
5456 }
5457
5458 dlen = qla27xx_fwdt_template_size(dcode);
5459 ql_dbg(ql_dbg_init, vha, 0x0166,
5460 "-> template size %x bytes\n", dlen);
5461 if (dlen > risc_size * sizeof(*dcode)) {
5462 ql_log(ql_log_warn, vha, 0x0167,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005463 "Failed fwdump template exceeds array by %x bytes\n",
5464 (uint32_t)(dlen - risc_size * sizeof(*dcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005465 goto default_template;
5466 }
5467 ha->fw_dump_template_len = dlen;
5468 return rval;
5469
5470default_template:
5471 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
5472 if (ha->fw_dump_template)
5473 vfree(ha->fw_dump_template);
5474 ha->fw_dump_template = NULL;
5475 ha->fw_dump_template_len = 0;
5476
5477 dlen = qla27xx_fwdt_template_default_size();
5478 ql_dbg(ql_dbg_init, vha, 0x0169,
5479 "-> template allocating %x bytes...\n", dlen);
5480 ha->fw_dump_template = vmalloc(dlen);
5481 if (!ha->fw_dump_template) {
5482 ql_log(ql_log_warn, vha, 0x016a,
5483 "Failed fwdump template allocate %x bytes.\n", risc_size);
5484 goto failed_template;
5485 }
5486
5487 dcode = ha->fw_dump_template;
5488 risc_size = dlen / sizeof(*dcode);
5489 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
5490 for (i = 0; i < risc_size; i++)
5491 dcode[i] = be32_to_cpu(dcode[i]);
5492
5493 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5494 ql_log(ql_log_warn, vha, 0x016b,
5495 "Failed fwdump template validate\n");
5496 goto failed_template;
5497 }
5498
5499 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5500 ql_dbg(ql_dbg_init, vha, 0x016c,
5501 "-> template size %x bytes\n", dlen);
5502 ha->fw_dump_template_len = dlen;
5503 return rval;
5504
5505failed_template:
5506 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
5507 if (ha->fw_dump_template)
5508 vfree(ha->fw_dump_template);
5509 ha->fw_dump_template = NULL;
5510 ha->fw_dump_template_len = 0;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005511 return rval;
5512}
5513
Giridhar Malavalie9454a82013-02-08 01:57:47 -05005514#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005515
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005516int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005517qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08005518{
5519 int rval;
5520 int i, fragment;
5521 uint16_t *wcode, *fwcode;
5522 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
5523 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005524 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005525 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08005526
5527 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005528 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005529 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005530 ql_log(ql_log_info, vha, 0x0083,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01005531 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005532 ql_log(ql_log_info, vha, 0x0084,
5533 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08005534 return QLA_FUNCTION_FAILED;
5535 }
5536
5537 rval = QLA_SUCCESS;
5538
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005539 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08005540 *srisc_addr = 0;
5541 fwcode = (uint16_t *)blob->fw->data;
5542 fwclen = 0;
5543
5544 /* Validate firmware image by checking version. */
5545 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005546 ql_log(ql_log_fatal, vha, 0x0085,
5547 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005548 blob->fw->size);
5549 goto fail_fw_integrity;
5550 }
5551 for (i = 0; i < 4; i++)
5552 wcode[i] = be16_to_cpu(fwcode[i + 4]);
5553 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
5554 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
5555 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005556 ql_log(ql_log_fatal, vha, 0x0086,
5557 "Unable to verify integrity of firmware image.\n");
5558 ql_log(ql_log_fatal, vha, 0x0087,
5559 "Firmware data: %04x %04x %04x %04x.\n",
5560 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08005561 goto fail_fw_integrity;
5562 }
5563
5564 seg = blob->segs;
5565 while (*seg && rval == QLA_SUCCESS) {
5566 risc_addr = *seg;
5567 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
5568 risc_size = be16_to_cpu(fwcode[3]);
5569
5570 /* Validate firmware image size. */
5571 fwclen += risc_size * sizeof(uint16_t);
5572 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005573 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08005574 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005575 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08005576 goto fail_fw_integrity;
5577 }
5578
5579 fragment = 0;
5580 while (risc_size > 0 && rval == QLA_SUCCESS) {
5581 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
5582 if (wlen > risc_size)
5583 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005584 ql_dbg(ql_dbg_init, vha, 0x0089,
5585 "Loading risc segment@ risc addr %x number of "
5586 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08005587
5588 for (i = 0; i < wlen; i++)
5589 wcode[i] = swab16(fwcode[i]);
5590
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005591 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08005592 wlen);
5593 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005594 ql_log(ql_log_fatal, vha, 0x008a,
5595 "Failed to load segment %d of firmware.\n",
5596 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08005597 break;
5598 }
5599
5600 fwcode += wlen;
5601 risc_addr += wlen;
5602 risc_size -= wlen;
5603 fragment++;
5604 }
5605
5606 /* Next segment. */
5607 seg++;
5608 }
5609 return rval;
5610
5611fail_fw_integrity:
5612 return QLA_FUNCTION_FAILED;
5613}
5614
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005615static int
5616qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005617{
5618 int rval;
5619 int segments, fragment;
5620 uint32_t *dcode, dlen;
5621 uint32_t risc_addr;
5622 uint32_t risc_size;
5623 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08005624 struct fw_blob *blob;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005625 const uint32_t *fwcode;
5626 uint32_t fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005627 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005628 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005629
Andrew Vasquez54333832005-11-09 15:49:04 -08005630 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005631 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005632 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005633 ql_log(ql_log_warn, vha, 0x0090,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01005634 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005635 ql_log(ql_log_warn, vha, 0x0091,
5636 "Firmware images can be retrieved from: "
5637 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005638
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005639 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005640 }
5641
Chad Dupuiscfb09192011-11-18 09:03:07 -08005642 ql_dbg(ql_dbg_init, vha, 0x0092,
5643 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005644
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005645 rval = QLA_SUCCESS;
5646
5647 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005648 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005649 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08005650 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005651 fwclen = 0;
5652
5653 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08005654 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005655 ql_log(ql_log_fatal, vha, 0x0093,
5656 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005657 blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005658 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005659 }
5660 for (i = 0; i < 4; i++)
5661 dcode[i] = be32_to_cpu(fwcode[i + 4]);
5662 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5663 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5664 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5665 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005666 ql_log(ql_log_fatal, vha, 0x0094,
5667 "Unable to verify integrity of firmware image (%Zd).\n",
5668 blob->fw->size);
5669 ql_log(ql_log_fatal, vha, 0x0095,
5670 "Firmware data: %08x %08x %08x %08x.\n",
5671 dcode[0], dcode[1], dcode[2], dcode[3]);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005672 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005673 }
5674
5675 while (segments && rval == QLA_SUCCESS) {
5676 risc_addr = be32_to_cpu(fwcode[2]);
5677 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5678 risc_size = be32_to_cpu(fwcode[3]);
5679
5680 /* Validate firmware image size. */
5681 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08005682 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005683 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08005684 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005685 "(%Zd).\n", blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005686 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005687 }
5688
5689 fragment = 0;
5690 while (risc_size > 0 && rval == QLA_SUCCESS) {
5691 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5692 if (dlen > risc_size)
5693 dlen = risc_size;
5694
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005695 ql_dbg(ql_dbg_init, vha, 0x0097,
5696 "Loading risc segment@ risc addr %x "
5697 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005698
5699 for (i = 0; i < dlen; i++)
5700 dcode[i] = swab32(fwcode[i]);
5701
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005702 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08005703 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005704 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005705 ql_log(ql_log_fatal, vha, 0x0098,
5706 "Failed to load segment %d of firmware.\n",
5707 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04005708 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005709 }
5710
5711 fwcode += dlen;
5712 risc_addr += dlen;
5713 risc_size -= dlen;
5714 fragment++;
5715 }
5716
5717 /* Next segment. */
5718 segments--;
5719 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05005720
5721 if (!IS_QLA27XX(ha))
5722 return rval;
5723
5724 if (ha->fw_dump_template)
5725 vfree(ha->fw_dump_template);
5726 ha->fw_dump_template = NULL;
5727 ha->fw_dump_template_len = 0;
5728
5729 ql_dbg(ql_dbg_init, vha, 0x171,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005730 "Loading fwdump template from %x\n",
5731 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005732 risc_size = be32_to_cpu(fwcode[2]);
5733 ql_dbg(ql_dbg_init, vha, 0x172,
5734 "-> array size %x dwords\n", risc_size);
5735 if (risc_size == 0 || risc_size == ~0)
5736 goto default_template;
5737
5738 dlen = (risc_size - 8) * sizeof(*fwcode);
5739 ql_dbg(ql_dbg_init, vha, 0x0173,
5740 "-> template allocating %x bytes...\n", dlen);
5741 ha->fw_dump_template = vmalloc(dlen);
5742 if (!ha->fw_dump_template) {
5743 ql_log(ql_log_warn, vha, 0x0174,
5744 "Failed fwdump template allocate %x bytes.\n", risc_size);
5745 goto default_template;
5746 }
5747
5748 fwcode += 7;
5749 risc_size -= 8;
5750 dcode = ha->fw_dump_template;
5751 for (i = 0; i < risc_size; i++)
5752 dcode[i] = le32_to_cpu(fwcode[i]);
5753
5754 if (!qla27xx_fwdt_template_valid(dcode)) {
5755 ql_log(ql_log_warn, vha, 0x0175,
5756 "Failed fwdump template validate\n");
5757 goto default_template;
5758 }
5759
5760 dlen = qla27xx_fwdt_template_size(dcode);
5761 ql_dbg(ql_dbg_init, vha, 0x0176,
5762 "-> template size %x bytes\n", dlen);
5763 if (dlen > risc_size * sizeof(*fwcode)) {
5764 ql_log(ql_log_warn, vha, 0x0177,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005765 "Failed fwdump template exceeds array by %x bytes\n",
5766 (uint32_t)(dlen - risc_size * sizeof(*fwcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005767 goto default_template;
5768 }
5769 ha->fw_dump_template_len = dlen;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005770 return rval;
5771
Chad Dupuisf73cb692014-02-26 04:15:06 -05005772default_template:
5773 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
5774 if (ha->fw_dump_template)
5775 vfree(ha->fw_dump_template);
5776 ha->fw_dump_template = NULL;
5777 ha->fw_dump_template_len = 0;
5778
5779 dlen = qla27xx_fwdt_template_default_size();
5780 ql_dbg(ql_dbg_init, vha, 0x0179,
5781 "-> template allocating %x bytes...\n", dlen);
5782 ha->fw_dump_template = vmalloc(dlen);
5783 if (!ha->fw_dump_template) {
5784 ql_log(ql_log_warn, vha, 0x017a,
5785 "Failed fwdump template allocate %x bytes.\n", risc_size);
5786 goto failed_template;
5787 }
5788
5789 dcode = ha->fw_dump_template;
5790 risc_size = dlen / sizeof(*fwcode);
5791 fwcode = qla27xx_fwdt_template_default();
5792 for (i = 0; i < risc_size; i++)
5793 dcode[i] = be32_to_cpu(fwcode[i]);
5794
5795 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5796 ql_log(ql_log_warn, vha, 0x017b,
5797 "Failed fwdump template validate\n");
5798 goto failed_template;
5799 }
5800
5801 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5802 ql_dbg(ql_dbg_init, vha, 0x017c,
5803 "-> template size %x bytes\n", dlen);
5804 ha->fw_dump_template_len = dlen;
5805 return rval;
5806
5807failed_template:
5808 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
5809 if (ha->fw_dump_template)
5810 vfree(ha->fw_dump_template);
5811 ha->fw_dump_template = NULL;
5812 ha->fw_dump_template_len = 0;
5813 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005814}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005815
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005816int
5817qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5818{
5819 int rval;
5820
Andrew Vasqueze337d902009-04-06 22:33:49 -07005821 if (ql2xfwloadbin == 1)
5822 return qla81xx_load_risc(vha, srisc_addr);
5823
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005824 /*
5825 * FW Load priority:
5826 * 1) Firmware via request-firmware interface (.bin file).
5827 * 2) Firmware residing in flash.
5828 */
5829 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5830 if (rval == QLA_SUCCESS)
5831 return rval;
5832
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005833 return qla24xx_load_risc_flash(vha, srisc_addr,
5834 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005835}
5836
5837int
5838qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5839{
5840 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005841 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005842
Andrew Vasqueze337d902009-04-06 22:33:49 -07005843 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005844 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07005845
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005846 /*
5847 * FW Load priority:
5848 * 1) Firmware residing in flash.
5849 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005850 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005851 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005852 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005853 if (rval == QLA_SUCCESS)
5854 return rval;
5855
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005856try_blob_fw:
5857 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5858 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
5859 return rval;
5860
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005861 ql_log(ql_log_info, vha, 0x0099,
5862 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005863 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
5864 if (rval != QLA_SUCCESS)
5865 return rval;
5866
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005867 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005868 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005869 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005870}
5871
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005872void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005873qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005874{
5875 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005876 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005877
Andrew Vasquez85880802009-12-15 21:29:46 -08005878 if (ha->flags.pci_channel_io_perm_failure)
5879 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07005880 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005881 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07005882 if (!ha->fw_major_version)
5883 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005884
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005885 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08005886 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07005887 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005888 ha->isp_ops->reset_chip(vha);
5889 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005890 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005891 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005892 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005893 ql_log(ql_log_info, vha, 0x8015,
5894 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005895 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005896 }
5897}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005898
5899int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005900qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005901{
5902 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08005903 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005904 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005905 struct qla_hw_data *ha = vha->hw;
5906 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005907 struct req_que *req;
5908 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005909
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005910 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005911 return -EINVAL;
5912
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005913 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07005914 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005915 req = ha->req_q_map[0];
5916 else
5917 req = vha->req;
5918 rsp = req->rsp;
5919
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005920 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005921 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005922 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005923 }
5924
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005925 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005926
5927 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08005928 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
5929 BIT_1);
5930 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5931 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
5932 ql_dbg(ql_dbg_init, vha, 0x0120,
5933 "Failed SNS login: loop_id=%x, rval2=%d\n",
5934 NPH_SNS, rval2);
5935 else
5936 ql_dbg(ql_dbg_init, vha, 0x0103,
5937 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5938 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
5939 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005940 return (QLA_FUNCTION_FAILED);
5941 }
5942
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005943 atomic_set(&vha->loop_down_timer, 0);
5944 atomic_set(&vha->loop_state, LOOP_UP);
5945 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5946 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5947 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005948
5949 return rval;
5950}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005951
5952/* 84XX Support **************************************************************/
5953
5954static LIST_HEAD(qla_cs84xx_list);
5955static DEFINE_MUTEX(qla_cs84xx_mutex);
5956
5957static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005958qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005959{
5960 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005961 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005962
5963 mutex_lock(&qla_cs84xx_mutex);
5964
5965 /* Find any shared 84xx chip. */
5966 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5967 if (cs84xx->bus == ha->pdev->bus) {
5968 kref_get(&cs84xx->kref);
5969 goto done;
5970 }
5971 }
5972
5973 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5974 if (!cs84xx)
5975 goto done;
5976
5977 kref_init(&cs84xx->kref);
5978 spin_lock_init(&cs84xx->access_lock);
5979 mutex_init(&cs84xx->fw_update_mutex);
5980 cs84xx->bus = ha->pdev->bus;
5981
5982 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5983done:
5984 mutex_unlock(&qla_cs84xx_mutex);
5985 return cs84xx;
5986}
5987
5988static void
5989__qla84xx_chip_release(struct kref *kref)
5990{
5991 struct qla_chip_state_84xx *cs84xx =
5992 container_of(kref, struct qla_chip_state_84xx, kref);
5993
5994 mutex_lock(&qla_cs84xx_mutex);
5995 list_del(&cs84xx->list);
5996 mutex_unlock(&qla_cs84xx_mutex);
5997 kfree(cs84xx);
5998}
5999
6000void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006001qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006002{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006003 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006004 if (ha->cs84xx)
6005 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
6006}
6007
6008static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006009qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006010{
6011 int rval;
6012 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006013 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006014
6015 mutex_lock(&ha->cs84xx->fw_update_mutex);
6016
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006017 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006018
6019 mutex_unlock(&ha->cs84xx->fw_update_mutex);
6020
6021 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
6022 QLA_SUCCESS;
6023}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006024
6025/* 81XX Support **************************************************************/
6026
6027int
6028qla81xx_nvram_config(scsi_qla_host_t *vha)
6029{
6030 int rval;
6031 struct init_cb_81xx *icb;
6032 struct nvram_81xx *nv;
6033 uint32_t *dptr;
6034 uint8_t *dptr1, *dptr2;
6035 uint32_t chksum;
6036 uint16_t cnt;
6037 struct qla_hw_data *ha = vha->hw;
6038
6039 rval = QLA_SUCCESS;
6040 icb = (struct init_cb_81xx *)ha->init_cb;
6041 nv = ha->nvram;
6042
6043 /* Determine NVRAM starting address. */
6044 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006045 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006046 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
6047 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006048
6049 /* Get VPD data into cache */
6050 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006051 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
6052 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006053
6054 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006055 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006056 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006057 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006058 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
6059 chksum += le32_to_cpu(*dptr++);
6060
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006061 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
6062 "Contents of NVRAM:\n");
6063 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
6064 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006065
6066 /* Bad NVRAM data, set defaults parameters. */
6067 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6068 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07006069 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006070 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006071 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04006072 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006073 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006074 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006075 ql_log(ql_log_info, vha, 0x0074,
6076 "Falling back to functioning (yet invalid -- WWPN) "
6077 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006078
6079 /*
6080 * Set default initialization control block.
6081 */
6082 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07006083 nv->nvram_version = cpu_to_le16(ICB_VERSION);
6084 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04006085 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07006086 nv->execution_throttle = cpu_to_le16(0xFFFF);
6087 nv->exchange_count = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006088 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006089 nv->port_name[1] = 0x00 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006090 nv->port_name[2] = 0x00;
6091 nv->port_name[3] = 0xe0;
6092 nv->port_name[4] = 0x8b;
6093 nv->port_name[5] = 0x1c;
6094 nv->port_name[6] = 0x55;
6095 nv->port_name[7] = 0x86;
6096 nv->node_name[0] = 0x20;
6097 nv->node_name[1] = 0x00;
6098 nv->node_name[2] = 0x00;
6099 nv->node_name[3] = 0xe0;
6100 nv->node_name[4] = 0x8b;
6101 nv->node_name[5] = 0x1c;
6102 nv->node_name[6] = 0x55;
6103 nv->node_name[7] = 0x86;
Bart Van Asschead950362015-07-09 07:24:08 -07006104 nv->login_retry_count = cpu_to_le16(8);
6105 nv->interrupt_delay_timer = cpu_to_le16(0);
6106 nv->login_timeout = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006107 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07006108 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6109 nv->firmware_options_2 = cpu_to_le32(2 << 4);
6110 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6111 nv->firmware_options_3 = cpu_to_le32(2 << 13);
6112 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6113 nv->efi_parameters = cpu_to_le32(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006114 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07006115 nv->max_luns_per_target = cpu_to_le16(128);
6116 nv->port_down_retry_count = cpu_to_le16(30);
6117 nv->link_down_timeout = cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07006118 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006119 nv->enode_mac[1] = 0xC0;
6120 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006121 nv->enode_mac[3] = 0x04;
6122 nv->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006123 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006124
6125 rval = 1;
6126 }
6127
Arun Easi9e522cd2012-08-22 14:21:31 -04006128 if (IS_T10_PI_CAPABLE(ha))
6129 nv->frame_payload_size &= ~7;
6130
Arun Easiaa230bc2013-01-30 03:34:39 -05006131 qlt_81xx_config_nvram_stage1(vha, nv);
6132
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006133 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07006134 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006135
6136 /* Copy 1st segment. */
6137 dptr1 = (uint8_t *)icb;
6138 dptr2 = (uint8_t *)&nv->version;
6139 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6140 while (cnt--)
6141 *dptr1++ = *dptr2++;
6142
6143 icb->login_retry_count = nv->login_retry_count;
6144
6145 /* Copy 2nd segment. */
6146 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6147 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6148 cnt = (uint8_t *)&icb->reserved_5 -
6149 (uint8_t *)&icb->interrupt_delay_timer;
6150 while (cnt--)
6151 *dptr1++ = *dptr2++;
6152
6153 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
6154 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
6155 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08006156 icb->enode_mac[0] = 0x00;
6157 icb->enode_mac[1] = 0xC0;
6158 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006159 icb->enode_mac[3] = 0x04;
6160 icb->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006161 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006162 }
6163
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07006164 /* Use extended-initialization control block. */
6165 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
6166
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006167 /*
6168 * Setup driver NVRAM options.
6169 */
6170 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07006171 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006172
Arun Easiaa230bc2013-01-30 03:34:39 -05006173 qlt_81xx_config_nvram_stage2(vha, icb);
6174
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006175 /* Use alternate WWN? */
Bart Van Asschead950362015-07-09 07:24:08 -07006176 if (nv->host_p & cpu_to_le32(BIT_15)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006177 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6178 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6179 }
6180
6181 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07006182 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006183 /*
6184 * Firmware will apply the following mask if the nodename was
6185 * not provided.
6186 */
6187 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6188 icb->node_name[0] &= 0xF0;
6189 }
6190
6191 /* Set host adapter parameters. */
6192 ha->flags.disable_risc_code_load = 0;
6193 ha->flags.enable_lip_reset = 0;
6194 ha->flags.enable_lip_full_login =
6195 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6196 ha->flags.enable_target_reset =
6197 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
6198 ha->flags.enable_led_scheme = 0;
6199 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
6200
6201 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6202 (BIT_6 | BIT_5 | BIT_4)) >> 4;
6203
6204 /* save HBA serial number */
6205 ha->serial0 = icb->port_name[5];
6206 ha->serial1 = icb->port_name[6];
6207 ha->serial2 = icb->port_name[7];
6208 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6209 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
6210
Bart Van Asschead950362015-07-09 07:24:08 -07006211 icb->execution_throttle = cpu_to_le16(0xFFFF);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006212
6213 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6214
6215 /* Set minimum login_timeout to 4 seconds. */
6216 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6217 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6218 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07006219 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006220 ha->login_timeout = le16_to_cpu(nv->login_timeout);
6221 icb->login_timeout = nv->login_timeout;
6222
6223 /* Set minimum RATOV to 100 tenths of a second. */
6224 ha->r_a_tov = 100;
6225
6226 ha->loop_reset_delay = nv->reset_delay;
6227
6228 /* Link Down Timeout = 0:
6229 *
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006230 * When Port Down timer expires we will start returning
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006231 * I/O's to OS with "DID_NO_CONNECT".
6232 *
6233 * Link Down Timeout != 0:
6234 *
6235 * The driver waits for the link to come up after link down
6236 * before returning I/Os to OS with "DID_NO_CONNECT".
6237 */
6238 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6239 ha->loop_down_abort_time =
6240 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6241 } else {
6242 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6243 ha->loop_down_abort_time =
6244 (LOOP_DOWN_TIME - ha->link_down_timeout);
6245 }
6246
6247 /* Need enough time to try and get the port back. */
6248 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6249 if (qlport_down_retry)
6250 ha->port_down_retry_count = qlport_down_retry;
6251
6252 /* Set login_retry_count */
6253 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6254 if (ha->port_down_retry_count ==
6255 le16_to_cpu(nv->port_down_retry_count) &&
6256 ha->port_down_retry_count > 3)
6257 ha->login_retry_count = ha->port_down_retry_count;
6258 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6259 ha->login_retry_count = ha->port_down_retry_count;
6260 if (ql2xloginretrycount)
6261 ha->login_retry_count = ql2xloginretrycount;
6262
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006263 /* if not running MSI-X we need handshaking on interrupts */
Chad Dupuisf73cb692014-02-26 04:15:06 -05006264 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
Bart Van Asschead950362015-07-09 07:24:08 -07006265 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006266
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006267 /* Enable ZIO. */
6268 if (!vha->flags.init_done) {
6269 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6270 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6271 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6272 le16_to_cpu(icb->interrupt_delay_timer): 2;
6273 }
Bart Van Asschead950362015-07-09 07:24:08 -07006274 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006275 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
6276 vha->flags.process_response_queue = 0;
6277 if (ha->zio_mode != QLA_ZIO_DISABLED) {
6278 ha->zio_mode = QLA_ZIO_MODE_6;
6279
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006280 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006281 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006282 ha->zio_mode,
6283 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006284
6285 icb->firmware_options_2 |= cpu_to_le32(
6286 (uint32_t)ha->zio_mode);
6287 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
6288 vha->flags.process_response_queue = 1;
6289 }
6290
6291 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006292 ql_log(ql_log_warn, vha, 0x0076,
6293 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006294 }
6295 return (rval);
6296}
6297
Giridhar Malavalia9083012010-04-12 17:59:55 -07006298int
6299qla82xx_restart_isp(scsi_qla_host_t *vha)
6300{
6301 int status, rval;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006302 struct qla_hw_data *ha = vha->hw;
6303 struct req_que *req = ha->req_q_map[0];
6304 struct rsp_que *rsp = ha->rsp_q_map[0];
6305 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07006306 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006307
6308 status = qla2x00_init_rings(vha);
6309 if (!status) {
6310 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6311 ha->flags.chip_reset_done = 1;
6312
6313 status = qla2x00_fw_ready(vha);
6314 if (!status) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07006315 /* Issue a marker after FW becomes ready. */
6316 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006317 vha->flags.online = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04006318 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006319 }
6320
6321 /* if no cable then assume it's good */
6322 if ((vha->device_flags & DFLG_NO_CABLE))
6323 status = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006324 }
6325
6326 if (!status) {
6327 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6328
6329 if (!atomic_read(&vha->loop_down_timer)) {
6330 /*
6331 * Issue marker command only when we are going
6332 * to start the I/O .
6333 */
6334 vha->marker_needed = 1;
6335 }
6336
Giridhar Malavalia9083012010-04-12 17:59:55 -07006337 ha->isp_ops->enable_intrs(ha);
6338
6339 ha->isp_abort_cnt = 0;
6340 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6341
Saurav Kashyap53296782011-05-10 11:30:06 -07006342 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07006343 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07006344
Giridhar Malavalia9083012010-04-12 17:59:55 -07006345 if (ha->fce) {
6346 ha->flags.fce_enabled = 1;
6347 memset(ha->fce, 0,
6348 fce_calc_size(ha->fce_bufs));
6349 rval = qla2x00_enable_fce_trace(vha,
6350 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6351 &ha->fce_bufs);
6352 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006353 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006354 "Unable to reinitialize FCE (%d).\n",
6355 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006356 ha->flags.fce_enabled = 0;
6357 }
6358 }
6359
6360 if (ha->eft) {
6361 memset(ha->eft, 0, EFT_SIZE);
6362 rval = qla2x00_enable_eft_trace(vha,
6363 ha->eft_dma, EFT_NUM_BUFFERS);
6364 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006365 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006366 "Unable to reinitialize EFT (%d).\n",
6367 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006368 }
6369 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006370 }
6371
6372 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006373 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006374 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07006375
6376 spin_lock_irqsave(&ha->vport_slock, flags);
6377 list_for_each_entry(vp, &ha->vp_list, list) {
6378 if (vp->vp_idx) {
6379 atomic_inc(&vp->vref_count);
6380 spin_unlock_irqrestore(&ha->vport_slock, flags);
6381
Giridhar Malavalia9083012010-04-12 17:59:55 -07006382 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07006383
6384 spin_lock_irqsave(&ha->vport_slock, flags);
6385 atomic_dec(&vp->vref_count);
6386 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006387 }
Arun Easifeafb7b2010-09-03 14:57:00 -07006388 spin_unlock_irqrestore(&ha->vport_slock, flags);
6389
Giridhar Malavalia9083012010-04-12 17:59:55 -07006390 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006391 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006392 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006393 }
6394
6395 return status;
6396}
6397
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006398void
Andrew Vasquezae97c912010-02-18 10:07:28 -08006399qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006400{
Andrew Vasquezae97c912010-02-18 10:07:28 -08006401 struct qla_hw_data *ha = vha->hw;
6402
6403 if (!ql2xetsenable)
6404 return;
6405
6406 /* Enable ETS Burst. */
6407 memset(ha->fw_options, 0, sizeof(ha->fw_options));
6408 ha->fw_options[2] |= BIT_9;
6409 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006410}
Sarang Radke09ff7012010-03-19 17:03:59 -07006411
6412/*
6413 * qla24xx_get_fcp_prio
6414 * Gets the fcp cmd priority value for the logged in port.
6415 * Looks for a match of the port descriptors within
6416 * each of the fcp prio config entries. If a match is found,
6417 * the tag (priority) value is returned.
6418 *
6419 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006420 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07006421 * fcport = port structure pointer.
6422 *
6423 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07006424 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006425 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07006426 *
6427 * Context:
6428 * Kernel context
6429 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006430static int
Sarang Radke09ff7012010-03-19 17:03:59 -07006431qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
6432{
6433 int i, entries;
6434 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006435 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07006436 uint32_t pid1, pid2;
6437 uint64_t wwn1, wwn2;
6438 struct qla_fcp_prio_entry *pri_entry;
6439 struct qla_hw_data *ha = vha->hw;
6440
6441 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006442 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07006443
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006444 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07006445 entries = ha->fcp_prio_cfg->num_entries;
6446 pri_entry = &ha->fcp_prio_cfg->entry[0];
6447
6448 for (i = 0; i < entries; i++) {
6449 pid_match = wwn_match = 0;
6450
6451 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
6452 pri_entry++;
6453 continue;
6454 }
6455
6456 /* check source pid for a match */
6457 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
6458 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
6459 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
6460 if (pid1 == INVALID_PORT_ID)
6461 pid_match++;
6462 else if (pid1 == pid2)
6463 pid_match++;
6464 }
6465
6466 /* check destination pid for a match */
6467 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
6468 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
6469 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
6470 if (pid1 == INVALID_PORT_ID)
6471 pid_match++;
6472 else if (pid1 == pid2)
6473 pid_match++;
6474 }
6475
6476 /* check source WWN for a match */
6477 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
6478 wwn1 = wwn_to_u64(vha->port_name);
6479 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
6480 if (wwn2 == (uint64_t)-1)
6481 wwn_match++;
6482 else if (wwn1 == wwn2)
6483 wwn_match++;
6484 }
6485
6486 /* check destination WWN for a match */
6487 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
6488 wwn1 = wwn_to_u64(fcport->port_name);
6489 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
6490 if (wwn2 == (uint64_t)-1)
6491 wwn_match++;
6492 else if (wwn1 == wwn2)
6493 wwn_match++;
6494 }
6495
6496 if (pid_match == 2 || wwn_match == 2) {
6497 /* Found a matching entry */
6498 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
6499 priority = pri_entry->tag;
6500 break;
6501 }
6502
6503 pri_entry++;
6504 }
6505
6506 return priority;
6507}
6508
6509/*
6510 * qla24xx_update_fcport_fcp_prio
6511 * Activates fcp priority for the logged in fc port
6512 *
6513 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006514 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07006515 * fcp = port structure pointer.
6516 *
6517 * Return:
6518 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6519 *
6520 * Context:
6521 * Kernel context.
6522 */
6523int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006524qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07006525{
6526 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006527 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07006528 uint16_t mb[5];
6529
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006530 if (fcport->port_type != FCT_TARGET ||
6531 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07006532 return QLA_FUNCTION_FAILED;
6533
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006534 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006535 if (priority < 0)
6536 return QLA_FUNCTION_FAILED;
6537
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006538 if (IS_P3P_TYPE(vha->hw)) {
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006539 fcport->fcp_prio = priority & 0xf;
6540 return QLA_SUCCESS;
6541 }
6542
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006543 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08006544 if (ret == QLA_SUCCESS) {
6545 if (fcport->fcp_prio != priority)
6546 ql_dbg(ql_dbg_user, vha, 0x709e,
6547 "Updated FCP_CMND priority - value=%d loop_id=%d "
6548 "port_id=%02x%02x%02x.\n", priority,
6549 fcport->loop_id, fcport->d_id.b.domain,
6550 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006551 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08006552 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006553 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006554 "Unable to update FCP_CMND priority - ret=0x%x for "
6555 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
6556 fcport->d_id.b.domain, fcport->d_id.b.area,
6557 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07006558 return ret;
6559}
6560
6561/*
6562 * qla24xx_update_all_fcp_prio
6563 * Activates fcp priority for all the logged in ports
6564 *
6565 * Input:
6566 * ha = adapter block pointer.
6567 *
6568 * Return:
6569 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6570 *
6571 * Context:
6572 * Kernel context.
6573 */
6574int
6575qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
6576{
6577 int ret;
6578 fc_port_t *fcport;
6579
6580 ret = QLA_FUNCTION_FAILED;
6581 /* We need to set priority for all logged in ports */
6582 list_for_each_entry(fcport, &vha->vp_fcports, list)
6583 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
6584
6585 return ret;
6586}