blob: b3ed3b3ff55ef2470facc489757acd2e3778b0f0 [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
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001849 if (ql2xexchoffld)
1850 ha->flags.exchoffld_enabled = 1;
1851
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001852 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001854 if (rval == QLA_SUCCESS) {
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05001855 rval = qla2x00_set_exlogins_buffer(vha);
1856 if (rval != QLA_SUCCESS)
1857 goto failed;
1858
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001859 rval = qla2x00_set_exchoffld_buffer(vha);
1860 if (rval != QLA_SUCCESS)
1861 goto failed;
1862
Giridhar Malavalia9083012010-04-12 17:59:55 -07001863enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001864 fw_major_version = ha->fw_major_version;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001865 if (IS_P3P_TYPE(ha))
Giridhar Malavali31731672011-08-16 11:31:54 -07001866 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001867 else
1868 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001869 if (rval != QLA_SUCCESS)
1870 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001871 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001872 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001873 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001874 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001875 if ((!ha->max_npiv_vports) ||
1876 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001877 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001878 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001879 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001880 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001881 qla2x00_get_resource_cnts(vha, NULL,
Chad Dupuis8d93f552013-01-30 03:34:37 -05001882 &ha->fw_xcb_count, NULL, &ha->fw_iocb_count,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001883 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001884
Chad Dupuis8d93f552013-01-30 03:34:37 -05001885 /*
1886 * Allocate the array of outstanding commands
1887 * now that we know the firmware resources.
1888 */
1889 rval = qla2x00_alloc_outstanding_cmds(ha,
1890 vha->req);
1891 if (rval != QLA_SUCCESS)
1892 goto failed;
1893
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08001894 if (!fw_major_version && ql2xallocfwdump
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001895 && !(IS_P3P_TYPE(ha)))
Giridhar Malavali08de2842011-08-16 11:31:44 -07001896 qla2x00_alloc_fw_dump(vha);
Chad Dupuis3b6e5b92013-10-30 03:38:09 -04001897 } else {
1898 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 }
1900 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001901 ql_log(ql_log_fatal, vha, 0x00cd,
1902 "ISP Firmware failed checksum.\n");
1903 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04001905 } else
1906 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907
Andrew Vasquez3db06522008-01-31 12:33:49 -08001908 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1909 /* Enable proper parity. */
1910 spin_lock_irqsave(&ha->hardware_lock, flags);
1911 if (IS_QLA2300(ha))
1912 /* SRAM parity */
1913 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1914 else
1915 /* SRAM, Instruction RAM and GP RAM parity */
1916 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1917 RD_REG_WORD(&reg->hccr);
1918 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1919 }
1920
Chad Dupuisf3982d82014-09-25 05:16:57 -04001921 if (IS_QLA27XX(ha))
1922 ha->flags.fac_supported = 1;
1923 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001924 uint32_t size;
1925
1926 rval = qla81xx_fac_get_sector_size(vha, &size);
1927 if (rval == QLA_SUCCESS) {
1928 ha->flags.fac_supported = 1;
1929 ha->fdt_block_size = size << 2;
1930 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001931 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001932 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1933 ha->fw_major_version, ha->fw_minor_version,
1934 ha->fw_subminor_version);
Joe Carnuccio1ca60e32014-02-26 04:15:02 -05001935
Chad Dupuisf73cb692014-02-26 04:15:06 -05001936 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001937 ha->flags.fac_supported = 0;
1938 rval = QLA_SUCCESS;
1939 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001940 }
1941 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001942failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001944 ql_log(ql_log_fatal, vha, 0x00cf,
1945 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 }
1947
1948 return (rval);
1949}
1950
1951/**
1952 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1953 * @ha: HA context
1954 *
1955 * Beginning of request ring has initialization control block already built
1956 * by nvram config routine.
1957 *
1958 * Returns 0 on success.
1959 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001960void
1961qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962{
1963 uint16_t cnt;
1964 response_t *pkt;
1965
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001966 rsp->ring_ptr = rsp->ring;
1967 rsp->ring_index = 0;
1968 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001969 pkt = rsp->ring_ptr;
1970 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 pkt->signature = RESPONSE_PROCESSED;
1972 pkt++;
1973 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974}
1975
1976/**
1977 * qla2x00_update_fw_options() - Read and process firmware options.
1978 * @ha: HA context
1979 *
1980 * Returns 0 on success.
1981 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001982void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001983qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984{
1985 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001986 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987
1988 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001989 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
1991 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1992 return;
1993
1994 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001995 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1996 "Serial link options.\n");
1997 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1998 (uint8_t *)&ha->fw_seriallink_options,
1999 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000
2001 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
2002 if (ha->fw_seriallink_options[3] & BIT_2) {
2003 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
2004
2005 /* 1G settings */
2006 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
2007 emphasis = (ha->fw_seriallink_options[2] &
2008 (BIT_4 | BIT_3)) >> 3;
2009 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002010 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 rx_sens = (ha->fw_seriallink_options[0] &
2012 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
2013 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
2014 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2015 if (rx_sens == 0x0)
2016 rx_sens = 0x3;
2017 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
2018 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2019 ha->fw_options[10] |= BIT_5 |
2020 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2021 (tx_sens & (BIT_1 | BIT_0));
2022
2023 /* 2G settings */
2024 swing = (ha->fw_seriallink_options[2] &
2025 (BIT_7 | BIT_6 | BIT_5)) >> 5;
2026 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
2027 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002028 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 rx_sens = (ha->fw_seriallink_options[1] &
2030 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
2031 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
2032 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2033 if (rx_sens == 0x0)
2034 rx_sens = 0x3;
2035 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
2036 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2037 ha->fw_options[11] |= BIT_5 |
2038 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2039 (tx_sens & (BIT_1 | BIT_0));
2040 }
2041
2042 /* FCP2 options. */
2043 /* Return command IOCBs without waiting for an ABTS to complete. */
2044 ha->fw_options[3] |= BIT_13;
2045
2046 /* LED scheme. */
2047 if (ha->flags.enable_led_scheme)
2048 ha->fw_options[2] |= BIT_12;
2049
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002050 /* Detect ISP6312. */
2051 if (IS_QLA6312(ha))
2052 ha->fw_options[2] |= BIT_13;
2053
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002055 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056}
2057
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002058void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002059qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002060{
2061 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002062 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002063
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002064 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07002065 return;
2066
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002067 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08002068 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002069 return;
2070
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002071 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08002072 le16_to_cpu(ha->fw_seriallink_options24[1]),
2073 le16_to_cpu(ha->fw_seriallink_options24[2]),
2074 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002075 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002076 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002077 "Unable to update Serial Link options (%x).\n", rval);
2078 }
2079}
2080
2081void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002082qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002083{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002084 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002085 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002086 struct req_que *req = ha->req_q_map[0];
2087 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002088
2089 /* Setup ring parameters in initialization control block. */
Bart Van Asschead950362015-07-09 07:24:08 -07002090 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
2091 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002092 ha->init_cb->request_q_length = cpu_to_le16(req->length);
2093 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
2094 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2095 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2096 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2097 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002098
2099 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
2100 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
2101 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
2102 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
2103 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
2104}
2105
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002106void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002107qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002108{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002109 struct qla_hw_data *ha = vha->hw;
Bart Van Assche118e2ef2015-07-09 07:24:27 -07002110 device_reg_t *reg = ISP_QUE_REG(ha, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002111 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
2112 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002113 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002114 uint16_t rid = 0;
2115 struct req_que *req = ha->req_q_map[0];
2116 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002117
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002118 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002119 icb = (struct init_cb_24xx *)ha->init_cb;
Bart Van Asschead950362015-07-09 07:24:08 -07002120 icb->request_q_outpointer = cpu_to_le16(0);
2121 icb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002122 icb->request_q_length = cpu_to_le16(req->length);
2123 icb->response_q_length = cpu_to_le16(rsp->length);
2124 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2125 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2126 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2127 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002128
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002129 /* Setup ATIO queue dma pointers for target mode */
Bart Van Asschead950362015-07-09 07:24:08 -07002130 icb->atio_q_inpointer = cpu_to_le16(0);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002131 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
2132 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
2133 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
2134
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002135 if (IS_SHADOW_REG_CAPABLE(ha))
Bart Van Asschead950362015-07-09 07:24:08 -07002136 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002137
Chad Dupuisf73cb692014-02-26 04:15:06 -05002138 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07002139 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
2140 icb->rid = cpu_to_le16(rid);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002141 if (ha->flags.msix_enabled) {
2142 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002143 ql_dbg(ql_dbg_init, vha, 0x00fd,
2144 "Registering vector 0x%x for base que.\n",
2145 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002146 icb->msix = cpu_to_le16(msix->entry);
2147 }
2148 /* Use alternate PCI bus number */
2149 if (MSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07002150 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002151 /* Use alternate PCI devfn */
2152 if (LSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07002153 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002154
Anirban Chakraborty31557542009-12-02 10:36:55 -08002155 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002156 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
2157 (ha->flags.msix_enabled)) {
Bart Van Asschead950362015-07-09 07:24:08 -07002158 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002159 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002160 ql_dbg(ql_dbg_init, vha, 0x00fe,
2161 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08002162 } else {
Bart Van Asschead950362015-07-09 07:24:08 -07002163 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002164 }
Bart Van Asschead950362015-07-09 07:24:08 -07002165 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002166
2167 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
2168 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
2169 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
2170 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
2171 } else {
2172 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
2173 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
2174 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
2175 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
2176 }
Arun Easiaa230bc2013-01-30 03:34:39 -05002177 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002178
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002179 /* PCI posting */
2180 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002181}
2182
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183/**
2184 * qla2x00_init_rings() - Initializes firmware.
2185 * @ha: HA context
2186 *
2187 * Beginning of request ring has initialization control block already built
2188 * by nvram config routine.
2189 *
2190 * Returns 0 on success.
2191 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002192int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002193qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194{
2195 int rval;
2196 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002197 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002198 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002199 struct req_que *req;
2200 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002201 struct mid_init_cb_24xx *mid_init_cb =
2202 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203
2204 spin_lock_irqsave(&ha->hardware_lock, flags);
2205
2206 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002207 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002208 req = ha->req_q_map[que];
2209 if (!req)
2210 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002211 req->out_ptr = (void *)(req->ring + req->length);
2212 *req->out_ptr = 0;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002213 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002214 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002216 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002217
2218 /* Initialize firmware. */
2219 req->ring_ptr = req->ring;
2220 req->ring_index = 0;
2221 req->cnt = req->length;
2222 }
2223
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002224 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002225 rsp = ha->rsp_q_map[que];
2226 if (!rsp)
2227 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002228 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
2229 *rsp->in_ptr = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002230 /* Initialize response queue entries */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002231 if (IS_QLAFX00(ha))
2232 qlafx00_init_response_q_entries(rsp);
2233 else
2234 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002235 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002237 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
2238 ha->tgt.atio_ring_index = 0;
2239 /* Initialize ATIO queue entries */
2240 qlt_init_atio_q_entries(vha);
2241
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002242 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243
2244 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2245
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002246 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
2247
2248 if (IS_QLAFX00(ha)) {
2249 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
2250 goto next_check;
2251 }
2252
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002254 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002256 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04002257 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002258 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08002259 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002260 }
2261
Andrew Vasquez24a08132009-03-24 09:08:16 -07002262 if (IS_FWI2_CAPABLE(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07002263 mid_init_cb->options = cpu_to_le16(BIT_1);
Andrew Vasquez24a08132009-03-24 09:08:16 -07002264 mid_init_cb->init_cb.execution_throttle =
2265 cpu_to_le16(ha->fw_xcb_count);
Himanshu Madhani25232cc2014-09-25 05:16:54 -04002266 /* D-Port Status */
2267 if (IS_DPORT_CAPABLE(ha))
2268 mid_init_cb->init_cb.firmware_options_1 |=
2269 cpu_to_le16(BIT_7);
Himanshu Madhani2486c622014-09-25 05:17:00 -04002270 /* Enable FA-WWPN */
2271 ha->flags.fawwpn_enabled =
2272 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) ? 1 : 0;
2273 ql_dbg(ql_dbg_init, vha, 0x0141, "FA-WWPN Support: %s.\n",
2274 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
Andrew Vasquez24a08132009-03-24 09:08:16 -07002275 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002276
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002277 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002278next_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002280 ql_log(ql_log_fatal, vha, 0x00d2,
2281 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002283 ql_dbg(ql_dbg_init, vha, 0x00d3,
2284 "Init Firmware -- success.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 }
2286
2287 return (rval);
2288}
2289
2290/**
2291 * qla2x00_fw_ready() - Waits for firmware ready.
2292 * @ha: HA context
2293 *
2294 * Returns 0 on success.
2295 */
2296static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002297qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298{
2299 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002300 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 uint16_t min_wait; /* Minimum wait time if loop is down */
2302 uint16_t wait_time; /* Wait time if loop is coming ready */
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002303 uint16_t state[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002304 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002306 if (IS_QLAFX00(vha->hw))
2307 return qlafx00_fw_ready(vha);
2308
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 rval = QLA_SUCCESS;
2310
Chad Dupuis334614912015-04-09 14:59:57 -04002311 /* Time to wait for loop down */
2312 if (IS_P3P_TYPE(ha))
2313 min_wait = 30;
2314 else
2315 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316
2317 /*
2318 * Firmware should take at most one RATOV to login, plus 5 seconds for
2319 * our own processing.
2320 */
2321 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
2322 wait_time = min_wait;
2323 }
2324
2325 /* Min wait time if loop down */
2326 mtime = jiffies + (min_wait * HZ);
2327
2328 /* wait time before firmware ready */
2329 wtime = jiffies + (wait_time * HZ);
2330
2331 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002332 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002333 ql_log(ql_log_info, vha, 0x801e,
2334 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335
2336 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05002337 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002338 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002340 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002341 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002343 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002344 ql_dbg(ql_dbg_taskm, vha, 0x801f,
2345 "fw_state=%x 84xx=%x.\n", state[0],
2346 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002347 if ((state[2] & FSTATE_LOGGED_IN) &&
2348 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002349 ql_dbg(ql_dbg_taskm, vha, 0x8028,
2350 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002351
2352 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002353 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002354 if (rval != QLA_SUCCESS) {
2355 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002356 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002357 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002358 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002359 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002360
2361 /* Add time taken to initialize. */
2362 cs84xx_time = jiffies - cs84xx_time;
2363 wtime += cs84xx_time;
2364 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002365 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002366 "Increasing wait time by %ld. "
2367 "New time %ld.\n", cs84xx_time,
2368 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002369 }
2370 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002371 ql_dbg(ql_dbg_taskm, vha, 0x8037,
2372 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002374 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 &ha->login_timeout, &ha->r_a_tov);
2376
2377 rval = QLA_SUCCESS;
2378 break;
2379 }
2380
2381 rval = QLA_FUNCTION_FAILED;
2382
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002383 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002384 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002386 * other than Wait for Login.
2387 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002389 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 "Cable is unplugged...\n");
2391
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002392 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 break;
2394 }
2395 }
2396 } else {
2397 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07002398 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08002399 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 break;
2401 }
2402
2403 if (time_after_eq(jiffies, wtime))
2404 break;
2405
2406 /* Delay for a while */
2407 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 } while (1);
2409
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002410 ql_dbg(ql_dbg_taskm, vha, 0x803a,
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002411 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
2412 state[1], state[2], state[3], state[4], state[5], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413
Chad Dupuiscfb09192011-11-18 09:03:07 -08002414 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002415 ql_log(ql_log_warn, vha, 0x803b,
2416 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 }
2418
2419 return (rval);
2420}
2421
2422/*
2423* qla2x00_configure_hba
2424* Setup adapter context.
2425*
2426* Input:
2427* ha = adapter state pointer.
2428*
2429* Returns:
2430* 0 = success
2431*
2432* Context:
2433* Kernel context.
2434*/
2435static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002436qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437{
2438 int rval;
2439 uint16_t loop_id;
2440 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002441 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 uint8_t al_pa;
2443 uint8_t area;
2444 uint8_t domain;
2445 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002446 struct qla_hw_data *ha = vha->hw;
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002447 unsigned long flags;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002448 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449
2450 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002451 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002452 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002454 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002455 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002456 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002457 ql_dbg(ql_dbg_disc, vha, 0x2008,
2458 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08002459 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002460 ql_log(ql_log_warn, vha, 0x2009,
2461 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002462 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
2463 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
2464 ql_log(ql_log_warn, vha, 0x1151,
2465 "Doing link init.\n");
2466 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
2467 return rval;
2468 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002469 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002470 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 return (rval);
2472 }
2473
2474 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002475 ql_log(ql_log_info, vha, 0x200a,
2476 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 return (QLA_FUNCTION_FAILED);
2478 }
2479
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002480 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481
2482 /* initialize */
2483 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2484 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002485 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
2487 switch (topo) {
2488 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002489 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 ha->current_topology = ISP_CFG_NL;
2491 strcpy(connect_type, "(Loop)");
2492 break;
2493
2494 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002495 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002496 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 ha->current_topology = ISP_CFG_FL;
2498 strcpy(connect_type, "(FL_Port)");
2499 break;
2500
2501 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002502 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 ha->operating_mode = P2P;
2504 ha->current_topology = ISP_CFG_N;
2505 strcpy(connect_type, "(N_Port-to-N_Port)");
2506 break;
2507
2508 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002509 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002510 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 ha->operating_mode = P2P;
2512 ha->current_topology = ISP_CFG_F;
2513 strcpy(connect_type, "(F_Port)");
2514 break;
2515
2516 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002517 ql_dbg(ql_dbg_disc, vha, 0x200f,
2518 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 ha->current_topology = ISP_CFG_NL;
2520 strcpy(connect_type, "(Loop)");
2521 break;
2522 }
2523
2524 /* Save Host port and loop ID. */
2525 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002526 vha->d_id.b.domain = domain;
2527 vha->d_id.b.area = area;
2528 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002530 spin_lock_irqsave(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002531 qlt_update_vp_map(vha, SET_AL_PA);
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002532 spin_unlock_irqrestore(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002533
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002534 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002535 ql_log(ql_log_info, vha, 0x2010,
2536 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002537 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 return(rval);
2540}
2541
Giridhar Malavalia9083012010-04-12 17:59:55 -07002542inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002543qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2544 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002545{
2546 char *st, *en;
2547 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002548 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002549 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002550 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002551
2552 if (memcmp(model, BINZERO, len) != 0) {
2553 strncpy(ha->model_number, model, len);
2554 st = en = ha->model_number;
2555 en += len - 1;
2556 while (en > st) {
2557 if (*en != 0x20 && *en != 0x00)
2558 break;
2559 *en-- = '\0';
2560 }
2561
2562 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002563 if (use_tbl &&
2564 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002565 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002566 strncpy(ha->model_desc,
2567 qla2x00_model_name[index * 2 + 1],
2568 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002569 } else {
2570 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002571 if (use_tbl &&
2572 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002573 index < QLA_MODEL_NAMES) {
2574 strcpy(ha->model_number,
2575 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002576 strncpy(ha->model_desc,
2577 qla2x00_model_name[index * 2 + 1],
2578 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002579 } else {
2580 strcpy(ha->model_number, def);
2581 }
2582 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002583 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002584 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002585 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002586}
2587
David Miller4e08df32007-04-16 12:37:43 -07002588/* On sparc systems, obtain port and node WWN from firmware
2589 * properties.
2590 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002591static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002592{
2593#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002594 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002595 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002596 struct device_node *dp = pci_device_to_OF_node(pdev);
2597 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002598 int len;
2599
2600 val = of_get_property(dp, "port-wwn", &len);
2601 if (val && len >= WWN_SIZE)
2602 memcpy(nv->port_name, val, WWN_SIZE);
2603
2604 val = of_get_property(dp, "node-wwn", &len);
2605 if (val && len >= WWN_SIZE)
2606 memcpy(nv->node_name, val, WWN_SIZE);
2607#endif
2608}
2609
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610/*
2611* NVRAM configuration for ISP 2xxx
2612*
2613* Input:
2614* ha = adapter block pointer.
2615*
2616* Output:
2617* initialization control block in response_ring
2618* host adapters parameters in host adapter block
2619*
2620* Returns:
2621* 0 = success.
2622*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002623int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002624qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625{
David Miller4e08df32007-04-16 12:37:43 -07002626 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002627 uint8_t chksum = 0;
2628 uint16_t cnt;
2629 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002630 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002631 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002632 nvram_t *nv = ha->nvram;
2633 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002634 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
David Miller4e08df32007-04-16 12:37:43 -07002636 rval = QLA_SUCCESS;
2637
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002639 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 ha->nvram_base = 0;
2641 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2642 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2643 ha->nvram_base = 0x80;
2644
2645 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002646 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002647 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2648 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002650 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2651 "Contents of NVRAM.\n");
2652 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2653 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654
2655 /* Bad NVRAM data, set defaults parameters. */
2656 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2657 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2658 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002659 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04002660 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002661 "detected: checksum=0x%x id=%c version=0x%x.\n",
2662 chksum, nv->id[0], nv->nvram_version);
2663 ql_log(ql_log_warn, vha, 0x0065,
2664 "Falling back to "
2665 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07002666
2667 /*
2668 * Set default initialization control block.
2669 */
2670 memset(nv, 0, ha->nvram_size);
2671 nv->parameter_block_version = ICB_VERSION;
2672
2673 if (IS_QLA23XX(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 = 2048;
David Miller4e08df32007-04-16 12:37:43 -07002679 nv->special_options[1] = BIT_7;
2680 } else if (IS_QLA2200(ha)) {
2681 nv->firmware_options[0] = BIT_2 | BIT_1;
2682 nv->firmware_options[1] = BIT_7 | BIT_5;
2683 nv->add_firmware_options[0] = BIT_5;
2684 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04002685 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07002686 } else if (IS_QLA2100(ha)) {
2687 nv->firmware_options[0] = BIT_3 | BIT_1;
2688 nv->firmware_options[1] = BIT_5;
Joe Carnuccio98aee702014-09-25 05:16:38 -04002689 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07002690 }
2691
Bart Van Asschead950362015-07-09 07:24:08 -07002692 nv->max_iocb_allocation = cpu_to_le16(256);
2693 nv->execution_throttle = cpu_to_le16(16);
David Miller4e08df32007-04-16 12:37:43 -07002694 nv->retry_count = 8;
2695 nv->retry_delay = 1;
2696
2697 nv->port_name[0] = 33;
2698 nv->port_name[3] = 224;
2699 nv->port_name[4] = 139;
2700
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002701 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002702
2703 nv->login_timeout = 4;
2704
2705 /*
2706 * Set default host adapter parameters
2707 */
2708 nv->host_p[1] = BIT_2;
2709 nv->reset_delay = 5;
2710 nv->port_down_retry_count = 8;
Bart Van Asschead950362015-07-09 07:24:08 -07002711 nv->max_luns_per_target = cpu_to_le16(8);
David Miller4e08df32007-04-16 12:37:43 -07002712 nv->link_down_timeout = 60;
2713
2714 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 }
2716
2717#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2718 /*
2719 * The SN2 does not provide BIOS emulation which means you can't change
2720 * potentially bogus BIOS settings. Force the use of default settings
2721 * for link rate and frame size. Hope that the rest of the settings
2722 * are valid.
2723 */
2724 if (ia64_platform_is("sn2")) {
Joe Carnuccio98aee702014-09-25 05:16:38 -04002725 nv->frame_payload_size = 2048;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 if (IS_QLA23XX(ha))
2727 nv->special_options[1] = BIT_7;
2728 }
2729#endif
2730
2731 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002732 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733
2734 /*
2735 * Setup driver NVRAM options.
2736 */
2737 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2738 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2739 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2740 nv->firmware_options[1] &= ~BIT_4;
2741
2742 if (IS_QLA23XX(ha)) {
2743 nv->firmware_options[0] |= BIT_2;
2744 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002745 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002746 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747
2748 if (IS_QLA2300(ha)) {
2749 if (ha->fb_rev == FPM_2310) {
2750 strcpy(ha->model_number, "QLA2310");
2751 } else {
2752 strcpy(ha->model_number, "QLA2300");
2753 }
2754 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002755 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002756 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 }
2758 } else if (IS_QLA2200(ha)) {
2759 nv->firmware_options[0] |= BIT_2;
2760 /*
2761 * 'Point-to-point preferred, else loop' is not a safe
2762 * connection mode setting.
2763 */
2764 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2765 (BIT_5 | BIT_4)) {
2766 /* Force 'loop preferred, else point-to-point'. */
2767 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2768 nv->add_firmware_options[0] |= BIT_5;
2769 }
2770 strcpy(ha->model_number, "QLA22xx");
2771 } else /*if (IS_QLA2100(ha))*/ {
2772 strcpy(ha->model_number, "QLA2100");
2773 }
2774
2775 /*
2776 * Copy over NVRAM RISC parameter block to initialization control block.
2777 */
2778 dptr1 = (uint8_t *)icb;
2779 dptr2 = (uint8_t *)&nv->parameter_block_version;
2780 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2781 while (cnt--)
2782 *dptr1++ = *dptr2++;
2783
2784 /* Copy 2nd half. */
2785 dptr1 = (uint8_t *)icb->add_firmware_options;
2786 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2787 while (cnt--)
2788 *dptr1++ = *dptr2++;
2789
Andrew Vasquez5341e862006-05-17 15:09:16 -07002790 /* Use alternate WWN? */
2791 if (nv->host_p[1] & BIT_7) {
2792 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2793 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2794 }
2795
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 /* Prepare nodename */
2797 if ((icb->firmware_options[1] & BIT_6) == 0) {
2798 /*
2799 * Firmware will apply the following mask if the nodename was
2800 * not provided.
2801 */
2802 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2803 icb->node_name[0] &= 0xF0;
2804 }
2805
2806 /*
2807 * Set host adapter parameters.
2808 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002809
2810 /*
2811 * BIT_7 in the host-parameters section allows for modification to
2812 * internal driver logging.
2813 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002814 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08002815 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2817 /* Always load RISC code on non ISP2[12]00 chips. */
2818 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2819 ha->flags.disable_risc_code_load = 0;
2820 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2821 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2822 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002823 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002824 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825
2826 ha->operating_mode =
2827 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2828
2829 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2830 sizeof(ha->fw_seriallink_options));
2831
2832 /* save HBA serial number */
2833 ha->serial0 = icb->port_name[5];
2834 ha->serial1 = icb->port_name[6];
2835 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002836 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2837 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838
Bart Van Asschead950362015-07-09 07:24:08 -07002839 icb->execution_throttle = cpu_to_le16(0xFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840
2841 ha->retry_count = nv->retry_count;
2842
2843 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002844 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 nv->login_timeout = ql2xlogintimeout;
2846 if (nv->login_timeout < 4)
2847 nv->login_timeout = 4;
2848 ha->login_timeout = nv->login_timeout;
2849 icb->login_timeout = nv->login_timeout;
2850
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002851 /* Set minimum RATOV to 100 tenths of a second. */
2852 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 ha->loop_reset_delay = nv->reset_delay;
2855
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 /* Link Down Timeout = 0:
2857 *
2858 * When Port Down timer expires we will start returning
2859 * I/O's to OS with "DID_NO_CONNECT".
2860 *
2861 * Link Down Timeout != 0:
2862 *
2863 * The driver waits for the link to come up after link down
2864 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002865 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 if (nv->link_down_timeout == 0) {
2867 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002868 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 } else {
2870 ha->link_down_timeout = nv->link_down_timeout;
2871 ha->loop_down_abort_time =
2872 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002873 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 /*
2876 * Need enough time to try and get the port back.
2877 */
2878 ha->port_down_retry_count = nv->port_down_retry_count;
2879 if (qlport_down_retry)
2880 ha->port_down_retry_count = qlport_down_retry;
2881 /* Set login_retry_count */
2882 ha->login_retry_count = nv->retry_count;
2883 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2884 ha->port_down_retry_count > 3)
2885 ha->login_retry_count = ha->port_down_retry_count;
2886 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2887 ha->login_retry_count = ha->port_down_retry_count;
2888 if (ql2xloginretrycount)
2889 ha->login_retry_count = ql2xloginretrycount;
2890
Bart Van Asschead950362015-07-09 07:24:08 -07002891 icb->lun_enables = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 icb->command_resource_count = 0;
2893 icb->immediate_notify_resource_count = 0;
Bart Van Asschead950362015-07-09 07:24:08 -07002894 icb->timeout = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895
2896 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2897 /* Enable RIO */
2898 icb->firmware_options[0] &= ~BIT_3;
2899 icb->add_firmware_options[0] &=
2900 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2901 icb->add_firmware_options[0] |= BIT_2;
2902 icb->response_accumulation_timer = 3;
2903 icb->interrupt_delay_timer = 5;
2904
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002905 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002907 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002908 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002909 ha->zio_mode = icb->add_firmware_options[0] &
2910 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2911 ha->zio_timer = icb->interrupt_delay_timer ?
2912 icb->interrupt_delay_timer: 2;
2913 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 icb->add_firmware_options[0] &=
2915 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002916 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002917 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002918 ha->zio_mode = QLA_ZIO_MODE_6;
2919
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002920 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002921 "ZIO mode %d enabled; timer delay (%d us).\n",
2922 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002924 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2925 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002926 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 }
2928 }
2929
David Miller4e08df32007-04-16 12:37:43 -07002930 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002931 ql_log(ql_log_warn, vha, 0x0069,
2932 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07002933 }
2934 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935}
2936
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002937static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002938qla2x00_rport_del(void *data)
2939{
2940 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002941 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002942 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002943
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002944 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002945 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002946 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002947 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04002948 if (rport)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002949 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002950}
2951
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952/**
2953 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2954 * @ha: HA context
2955 * @flags: allocation flags
2956 *
2957 * Returns a pointer to the allocated fcport, or NULL, if none available.
2958 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002959fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002960qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961{
2962 fc_port_t *fcport;
2963
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002964 fcport = kzalloc(sizeof(fc_port_t), flags);
2965 if (!fcport)
2966 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
2968 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002969 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 fcport->port_type = FCT_UNKNOWN;
2971 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07002972 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002973 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002975 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976}
2977
2978/*
2979 * qla2x00_configure_loop
2980 * Updates Fibre Channel Device Database with what is actually on loop.
2981 *
2982 * Input:
2983 * ha = adapter block pointer.
2984 *
2985 * Returns:
2986 * 0 = success.
2987 * 1 = error.
2988 * 2 = database was full and device was not configured.
2989 */
2990static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002991qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992{
2993 int rval;
2994 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002995 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 rval = QLA_SUCCESS;
2997
2998 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002999 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
3000 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003002 ql_dbg(ql_dbg_disc, vha, 0x2013,
3003 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 return (rval);
3005 }
3006 }
3007
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003008 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003009 ql_dbg(ql_dbg_disc, vha, 0x2014,
3010 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011
3012 /*
3013 * If we have both an RSCN and PORT UPDATE pending then handle them
3014 * both at the same time.
3015 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003016 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3017 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018
Michael Hernandez3064ff32009-12-15 21:29:44 -08003019 qla2x00_get_data_rate(vha);
3020
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 /* Determine what we need to do */
3022 if (ha->current_topology == ISP_CFG_FL &&
3023 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
3024
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 set_bit(RSCN_UPDATE, &flags);
3026
3027 } else if (ha->current_topology == ISP_CFG_F &&
3028 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
3029
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 set_bit(RSCN_UPDATE, &flags);
3031 clear_bit(LOCAL_LOOP_UPDATE, &flags);
3032
Andrew Vasquez21333b42006-05-17 15:09:56 -07003033 } else if (ha->current_topology == ISP_CFG_N) {
3034 clear_bit(RSCN_UPDATE, &flags);
3035
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003036 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
3038
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 set_bit(RSCN_UPDATE, &flags);
3040 set_bit(LOCAL_LOOP_UPDATE, &flags);
3041 }
3042
3043 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003044 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
3045 ql_dbg(ql_dbg_disc, vha, 0x2015,
3046 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08003048 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003049 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 }
3051
3052 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003053 if (LOOP_TRANSITION(vha)) {
3054 ql_dbg(ql_dbg_disc, vha, 0x201e,
3055 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003057 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003058 else
3059 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 }
3061
3062 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003063 if (atomic_read(&vha->loop_down_timer) ||
3064 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 rval = QLA_FUNCTION_FAILED;
3066 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003067 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003068 ql_dbg(ql_dbg_disc, vha, 0x2069,
3069 "LOOP READY.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 }
3071 }
3072
3073 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003074 ql_dbg(ql_dbg_disc, vha, 0x206a,
3075 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003077 ql_dbg(ql_dbg_disc, vha, 0x206b,
3078 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 }
3080
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07003081 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003082 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003084 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07003085 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003086 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07003087 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 }
3089
3090 return (rval);
3091}
3092
3093
3094
3095/*
3096 * qla2x00_configure_local_loop
3097 * Updates Fibre Channel Device Database with local loop devices.
3098 *
3099 * Input:
3100 * ha = adapter block pointer.
3101 *
3102 * Returns:
3103 * 0 = success.
3104 */
3105static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003106qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107{
3108 int rval, rval2;
3109 int found_devs;
3110 int found;
3111 fc_port_t *fcport, *new_fcport;
3112
3113 uint16_t index;
3114 uint16_t entries;
3115 char *id_iter;
3116 uint16_t loop_id;
3117 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003118 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119
3120 found_devs = 0;
3121 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08003122 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08003125 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003126 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 &entries);
3128 if (rval != QLA_SUCCESS)
3129 goto cleanup_allocation;
3130
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003131 ql_dbg(ql_dbg_disc, vha, 0x2017,
3132 "Entries in ID list (%d).\n", entries);
3133 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
3134 (uint8_t *)ha->gid_list,
3135 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136
3137 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003138 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003140 ql_log(ql_log_warn, vha, 0x2018,
3141 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 rval = QLA_MEMORY_ALLOC_FAILED;
3143 goto cleanup_allocation;
3144 }
3145 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3146
3147 /*
3148 * Mark local devices that were present with FCF_DEVICE_LOST for now.
3149 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003150 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 if (atomic_read(&fcport->state) == FCS_ONLINE &&
3152 fcport->port_type != FCT_BROADCAST &&
3153 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3154
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003155 ql_dbg(ql_dbg_disc, vha, 0x2019,
3156 "Marking port lost loop_id=0x%04x.\n",
3157 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158
Chad Dupuisec426e12011-03-30 11:46:32 -07003159 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 }
3161 }
3162
3163 /* Add devices to port list. */
3164 id_iter = (char *)ha->gid_list;
3165 for (index = 0; index < entries; index++) {
3166 domain = ((struct gid_list_info *)id_iter)->domain;
3167 area = ((struct gid_list_info *)id_iter)->area;
3168 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003169 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 loop_id = (uint16_t)
3171 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003172 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 loop_id = le16_to_cpu(
3174 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003175 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176
3177 /* Bypass reserved domain fields. */
3178 if ((domain & 0xf0) == 0xf0)
3179 continue;
3180
3181 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003182 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003183 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 continue;
3185
3186 /* Bypass invalid local loop ID. */
3187 if (loop_id > LAST_LOCAL_LOOP_ID)
3188 continue;
3189
Arun Easi370d5502012-08-22 14:21:10 -04003190 memset(new_fcport, 0, sizeof(fc_port_t));
3191
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 /* Fill in member data. */
3193 new_fcport->d_id.b.domain = domain;
3194 new_fcport->d_id.b.area = area;
3195 new_fcport->d_id.b.al_pa = al_pa;
3196 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003197 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003199 ql_dbg(ql_dbg_disc, vha, 0x201a,
3200 "Failed to retrieve fcport information "
3201 "-- get_port_database=%x, loop_id=0x%04x.\n",
3202 rval2, new_fcport->loop_id);
3203 ql_dbg(ql_dbg_disc, vha, 0x201b,
3204 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003205 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 continue;
3207 }
3208
3209 /* Check for matching device in port list. */
3210 found = 0;
3211 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003212 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 if (memcmp(new_fcport->port_name, fcport->port_name,
3214 WWN_SIZE))
3215 continue;
3216
Shyam Sundarddb9b122009-03-24 09:08:10 -07003217 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 fcport->loop_id = new_fcport->loop_id;
3219 fcport->port_type = new_fcport->port_type;
3220 fcport->d_id.b24 = new_fcport->d_id.b24;
3221 memcpy(fcport->node_name, new_fcport->node_name,
3222 WWN_SIZE);
3223
3224 found++;
3225 break;
3226 }
3227
3228 if (!found) {
3229 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003230 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231
3232 /* Allocate a new replacement fcport. */
3233 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003234 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003236 ql_log(ql_log_warn, vha, 0x201c,
3237 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 rval = QLA_MEMORY_ALLOC_FAILED;
3239 goto cleanup_allocation;
3240 }
3241 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3242 }
3243
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003244 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003245 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003246
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003247 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248
3249 found_devs++;
3250 }
3251
3252cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003253 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254
3255 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003256 ql_dbg(ql_dbg_disc, vha, 0x201d,
3257 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 }
3259
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 return (rval);
3261}
3262
3263static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003264qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003265{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003266 int rval;
Quinn Tran93f2bd62014-09-25 05:16:53 -04003267 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003268 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003269
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07003270 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003271 return;
3272
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07003273 if (atomic_read(&fcport->state) != FCS_ONLINE)
3274 return;
3275
Andrew Vasquez39bd9622007-09-20 14:07:34 -07003276 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
3277 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003278 return;
3279
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003280 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003281 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003282 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003283 ql_dbg(ql_dbg_disc, vha, 0x2004,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003284 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
3285 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003286 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003287 ql_dbg(ql_dbg_disc, vha, 0x2005,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003288 "iIDMA adjusted to %s GB/s on %8phN.\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -05003289 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003290 fcport->port_name);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003291 }
3292}
3293
Adrian Bunk23be3312006-11-24 02:46:01 +01003294static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003295qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05003296{
3297 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05003298 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003299 unsigned long flags;
8482e1182005-04-17 15:04:54 -05003300
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07003301 rport_ids.node_name = wwn_to_u64(fcport->node_name);
3302 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05003303 rport_ids.port_id = fcport->d_id.b.domain << 16 |
3304 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
3305 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003306 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07003307 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003308 ql_log(ql_log_warn, vha, 0x2006,
3309 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07003310 return;
3311 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003312 /*
3313 * Create target mode FC NEXUS in qla_target.c if target mode is
3314 * enabled..
3315 */
Saurav Kashyapba9f6f62015-06-10 11:05:17 -04003316
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003317 qlt_fc_port_added(vha, fcport);
3318
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003319 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003320 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003321 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003322
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003323 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003324
3325 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05003326 if (fcport->port_type == FCT_INITIATOR)
3327 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3328 if (fcport->port_type == FCT_TARGET)
3329 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003330 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05003331}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332
3333/*
Adrian Bunk23be3312006-11-24 02:46:01 +01003334 * qla2x00_update_fcport
3335 * Updates device on list.
3336 *
3337 * Input:
3338 * ha = adapter block pointer.
3339 * fcport = port structure pointer.
3340 *
3341 * Return:
3342 * 0 - Success
3343 * BIT_0 - error
3344 *
3345 * Context:
3346 * Kernel context.
3347 */
3348void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003349qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01003350{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003351 fcport->vha = vha;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003352
3353 if (IS_QLAFX00(vha->hw)) {
3354 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003355 goto reg_port;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003356 }
Adrian Bunk23be3312006-11-24 02:46:01 +01003357 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003358 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01003359
Joe Carnuccio1f93da522012-11-21 02:40:38 -05003360 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003361 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08003362 qla24xx_update_fcport_fcp_prio(vha, fcport);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003363
3364reg_port:
3365 if (qla_ini_mode_enabled(vha))
3366 qla2x00_reg_remote_port(vha, fcport);
3367 else {
3368 /*
3369 * Create target mode FC NEXUS in qla_target.c
3370 */
3371 qlt_fc_port_added(vha, fcport);
3372 }
Adrian Bunk23be3312006-11-24 02:46:01 +01003373}
3374
3375/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 * qla2x00_configure_fabric
3377 * Setup SNS devices with loop ID's.
3378 *
3379 * Input:
3380 * ha = adapter block pointer.
3381 *
3382 * Returns:
3383 * 0 = success.
3384 * BIT_0 = error
3385 */
3386static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003387qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388{
Arun Easib3b02e62012-02-09 11:15:39 -08003389 int rval;
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003390 fc_port_t *fcport, *fcptemp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 uint16_t next_loopid;
3392 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003393 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003395 struct qla_hw_data *ha = vha->hw;
3396 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003397 int discovery_gen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398
3399 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003400 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003401 loop_id = NPH_F_PORT;
3402 else
3403 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003404 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003406 ql_dbg(ql_dbg_disc, vha, 0x201f,
3407 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003409 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 return (QLA_SUCCESS);
3411 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003412 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07003415 /* FDMI support. */
3416 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003417 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
3418 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07003419
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003421 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003422 loop_id = NPH_SNS;
3423 else
3424 loop_id = SIMPLE_NAME_SERVER;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003425 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
3426 0xfc, mb, BIT_1|BIT_0);
3427 if (rval != QLA_SUCCESS) {
3428 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003429 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003430 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003432 ql_dbg(ql_dbg_disc, vha, 0x2042,
3433 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3434 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
3435 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 return (QLA_SUCCESS);
3437 }
3438
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003439 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3440 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003442 ql_dbg(ql_dbg_disc, vha, 0x2045,
3443 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003445 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003447 ql_dbg(ql_dbg_disc, vha, 0x2049,
3448 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003450 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003452 ql_dbg(ql_dbg_disc, vha, 0x204f,
3453 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003454 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003456 ql_dbg(ql_dbg_disc, vha, 0x2053,
3457 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458 }
3459 }
3460
Joe Carnuccio827210b2013-02-08 01:57:57 -05003461#define QLA_FCPORT_SCAN 1
3462#define QLA_FCPORT_FOUND 2
3463
3464 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3465 fcport->scan_state = QLA_FCPORT_SCAN;
3466 }
3467
Alexei Potashnikdf673272015-07-14 16:00:46 -04003468 /* Mark the time right before querying FW for connected ports.
3469 * This process is long, asynchronous and by the time it's done,
3470 * collected information might not be accurate anymore. E.g.
3471 * disconnected port might have re-connected and a brand new
3472 * session has been created. In this case session's generation
3473 * will be newer than discovery_gen. */
3474 qlt_do_generation_tick(vha, &discovery_gen);
3475
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003476 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 if (rval != QLA_SUCCESS)
3478 break;
3479
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003480 /*
3481 * Logout all previous fabric devices marked lost, except
3482 * FCP2 devices.
3483 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003484 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3485 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 break;
3487
3488 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3489 continue;
3490
Roland Dreierb2032fd2015-07-14 16:00:42 -04003491 if (fcport->scan_state == QLA_FCPORT_SCAN) {
3492 if (qla_ini_mode_enabled(base_vha) &&
3493 atomic_read(&fcport->state) == FCS_ONLINE) {
3494 qla2x00_mark_device_lost(vha, fcport,
3495 ql2xplogiabsentdevice, 0);
3496 if (fcport->loop_id != FC_NO_LOOP_ID &&
3497 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
3498 fcport->port_type != FCT_INITIATOR &&
3499 fcport->port_type != FCT_BROADCAST) {
3500 ha->isp_ops->fabric_logout(vha,
3501 fcport->loop_id,
3502 fcport->d_id.b.domain,
3503 fcport->d_id.b.area,
3504 fcport->d_id.b.al_pa);
3505 qla2x00_clear_loop_id(fcport);
3506 }
3507 } else if (!qla_ini_mode_enabled(base_vha)) {
3508 /*
3509 * In target mode, explicitly kill
3510 * sessions and log out of devices
3511 * that are gone, so that we don't
3512 * end up with an initiator using the
3513 * wrong ACL (if the fabric recycles
3514 * an FC address and we have a stale
3515 * session around) and so that we don't
3516 * report initiators that are no longer
3517 * on the fabric.
3518 */
3519 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf077,
3520 "port gone, logging out/killing session: "
3521 "%8phC state 0x%x flags 0x%x fc4_type 0x%x "
3522 "scan_state %d\n",
3523 fcport->port_name,
3524 atomic_read(&fcport->state),
3525 fcport->flags, fcport->fc4_type,
3526 fcport->scan_state);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003527 qlt_fc_port_deleted(vha, fcport,
3528 discovery_gen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 }
3530 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003531 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003533 /* Starting free loop ID. */
3534 next_loopid = ha->min_external_loopid;
3535
3536 /*
3537 * Scan through our port list and login entries that need to be
3538 * logged in.
3539 */
3540 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3541 if (atomic_read(&vha->loop_down_timer) ||
3542 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3543 break;
3544
3545 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3546 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3547 continue;
3548
Roland Dreierb2032fd2015-07-14 16:00:42 -04003549 /*
3550 * If we're not an initiator, skip looking for devices
3551 * and logging in. There's no reason for us to do it,
3552 * and it seems to actively cause problems in target
3553 * mode if we race with the initiator logging into us
3554 * (we might get the "port ID used" status back from
3555 * our login command and log out the initiator, which
3556 * seems to cause havoc).
3557 */
3558 if (!qla_ini_mode_enabled(base_vha)) {
3559 if (fcport->scan_state == QLA_FCPORT_FOUND) {
3560 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf078,
3561 "port %8phC state 0x%x flags 0x%x fc4_type 0x%x "
3562 "scan_state %d (initiator mode disabled; skipping "
3563 "login)\n", fcport->port_name,
3564 atomic_read(&fcport->state),
3565 fcport->flags, fcport->fc4_type,
3566 fcport->scan_state);
3567 }
3568 continue;
3569 }
3570
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003571 if (fcport->loop_id == FC_NO_LOOP_ID) {
3572 fcport->loop_id = next_loopid;
3573 rval = qla2x00_find_new_loop_id(
3574 base_vha, fcport);
3575 if (rval != QLA_SUCCESS) {
3576 /* Ran out of IDs to use */
3577 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 }
3579 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003580 /* Login and update database */
3581 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
3582 }
3583
3584 /* Exit if out of loop IDs. */
3585 if (rval != QLA_SUCCESS) {
3586 break;
3587 }
3588
3589 /*
3590 * Login and add the new devices to our port list.
3591 */
3592 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3593 if (atomic_read(&vha->loop_down_timer) ||
3594 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3595 break;
3596
Roland Dreierb2032fd2015-07-14 16:00:42 -04003597 /*
3598 * If we're not an initiator, skip looking for devices
3599 * and logging in. There's no reason for us to do it,
3600 * and it seems to actively cause problems in target
3601 * mode if we race with the initiator logging into us
3602 * (we might get the "port ID used" status back from
3603 * our login command and log out the initiator, which
3604 * seems to cause havoc).
3605 */
3606 if (qla_ini_mode_enabled(base_vha)) {
3607 /* Find a new loop ID to use. */
3608 fcport->loop_id = next_loopid;
3609 rval = qla2x00_find_new_loop_id(base_vha,
3610 fcport);
3611 if (rval != QLA_SUCCESS) {
3612 /* Ran out of IDs to use */
3613 break;
3614 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615
Roland Dreierb2032fd2015-07-14 16:00:42 -04003616 /* Login and update database */
3617 qla2x00_fabric_dev_login(vha, fcport,
3618 &next_loopid);
3619 } else {
3620 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf079,
3621 "new port %8phC state 0x%x flags 0x%x fc4_type "
3622 "0x%x scan_state %d (initiator mode disabled; "
3623 "skipping login)\n",
3624 fcport->port_name,
3625 atomic_read(&fcport->state),
3626 fcport->flags, fcport->fc4_type,
3627 fcport->scan_state);
3628 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003629
3630 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 }
3632 } while (0);
3633
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003634 /* Free all new device structures not processed. */
3635 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3636 list_del(&fcport->list);
3637 kfree(fcport);
3638 }
3639
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003641 ql_dbg(ql_dbg_disc, vha, 0x2068,
3642 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643 }
3644
3645 return (rval);
3646}
3647
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648/*
3649 * qla2x00_find_all_fabric_devs
3650 *
3651 * Input:
3652 * ha = adapter block pointer.
3653 * dev = database device entry pointer.
3654 *
3655 * Returns:
3656 * 0 = success.
3657 *
3658 * Context:
3659 * Kernel context.
3660 */
3661static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003662qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3663 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003664{
3665 int rval;
3666 uint16_t loop_id;
3667 fc_port_t *fcport, *new_fcport, *fcptemp;
3668 int found;
3669
3670 sw_info_t *swl;
3671 int swl_idx;
3672 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003673 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003674 struct qla_hw_data *ha = vha->hw;
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05003675 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676
3677 rval = QLA_SUCCESS;
3678
3679 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08003680 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08003681 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08003682 GFP_KERNEL);
3683 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003684 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003686 ql_dbg(ql_dbg_disc, vha, 0x2054,
3687 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08003689 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003690 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003691 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003692 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003694 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003696 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003697 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3698 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003700
3701 /* If other queries succeeded probe for FC-4 type */
3702 if (swl)
3703 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 }
3705 swl_idx = 0;
3706
3707 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003708 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003710 ql_log(ql_log_warn, vha, 0x205e,
3711 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 return (QLA_MEMORY_ALLOC_FAILED);
3713 }
3714 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 /* Set start port ID scan at adapter ID. */
3716 first_dev = 1;
3717 last_dev = 0;
3718
3719 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003720 loop_id = ha->min_external_loopid;
3721 for (; loop_id <= ha->max_loop_id; loop_id++) {
3722 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 continue;
3724
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003725 if (ha->current_topology == ISP_CFG_FL &&
3726 (atomic_read(&vha->loop_down_timer) ||
3727 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003728 atomic_set(&vha->loop_down_timer, 0);
3729 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3730 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003732 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733
3734 if (swl != NULL) {
3735 if (last_dev) {
3736 wrap.b24 = new_fcport->d_id.b24;
3737 } else {
3738 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3739 memcpy(new_fcport->node_name,
3740 swl[swl_idx].node_name, WWN_SIZE);
3741 memcpy(new_fcport->port_name,
3742 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003743 memcpy(new_fcport->fabric_port_name,
3744 swl[swl_idx].fabric_port_name, WWN_SIZE);
3745 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003746 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747
3748 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3749 last_dev = 1;
3750 }
3751 swl_idx++;
3752 }
3753 } else {
3754 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003755 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003757 ql_log(ql_log_warn, vha, 0x2064,
3758 "SNS scan failed -- assuming "
3759 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760 list_for_each_entry_safe(fcport, fcptemp,
3761 new_fcports, list) {
3762 list_del(&fcport->list);
3763 kfree(fcport);
3764 }
3765 rval = QLA_SUCCESS;
3766 break;
3767 }
3768 }
3769
3770 /* If wrap on switch device list, exit. */
3771 if (first_dev) {
3772 wrap.b24 = new_fcport->d_id.b24;
3773 first_dev = 0;
3774 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003775 ql_dbg(ql_dbg_disc, vha, 0x2065,
3776 "Device wrap (%02x%02x%02x).\n",
3777 new_fcport->d_id.b.domain,
3778 new_fcport->d_id.b.area,
3779 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780 break;
3781 }
3782
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003783 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003784 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 continue;
3786
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003787 /* Bypass virtual ports of the same host. */
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05003788 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
3789 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003790
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003791 /* Bypass if same domain and area of adapter. */
3792 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003793 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003794 ISP_CFG_FL)
3795 continue;
3796
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797 /* Bypass reserved domain fields. */
3798 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3799 continue;
3800
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003801 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003802 if (ql2xgffidenable &&
3803 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3804 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003805 continue;
3806
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 /* Locate matching device in database. */
3808 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003809 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 if (memcmp(new_fcport->port_name, fcport->port_name,
3811 WWN_SIZE))
3812 continue;
3813
Joe Carnuccio827210b2013-02-08 01:57:57 -05003814 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08003815
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 found++;
3817
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003818 /* Update port state. */
3819 memcpy(fcport->fabric_port_name,
3820 new_fcport->fabric_port_name, WWN_SIZE);
3821 fcport->fp_speed = new_fcport->fp_speed;
3822
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 /*
Roland Dreierb2032fd2015-07-14 16:00:42 -04003824 * If address the same and state FCS_ONLINE
3825 * (or in target mode), nothing changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 */
3827 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
Roland Dreierb2032fd2015-07-14 16:00:42 -04003828 (atomic_read(&fcport->state) == FCS_ONLINE ||
3829 !qla_ini_mode_enabled(base_vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830 break;
3831 }
3832
3833 /*
3834 * If device was not a fabric device before.
3835 */
3836 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3837 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04003838 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 fcport->flags |= (FCF_FABRIC_DEVICE |
3840 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 break;
3842 }
3843
3844 /*
3845 * Port ID changed or device was marked to be updated;
3846 * Log it out if still logged in and mark it for
3847 * relogin later.
3848 */
Roland Dreierb2032fd2015-07-14 16:00:42 -04003849 if (!qla_ini_mode_enabled(base_vha)) {
3850 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
3851 "port changed FC ID, %8phC"
3852 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
3853 fcport->port_name,
3854 fcport->d_id.b.domain,
3855 fcport->d_id.b.area,
3856 fcport->d_id.b.al_pa,
3857 fcport->loop_id,
3858 new_fcport->d_id.b.domain,
3859 new_fcport->d_id.b.area,
3860 new_fcport->d_id.b.al_pa);
3861 fcport->d_id.b24 = new_fcport->d_id.b24;
3862 break;
3863 }
3864
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865 fcport->d_id.b24 = new_fcport->d_id.b24;
3866 fcport->flags |= FCF_LOGIN_NEEDED;
3867 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003868 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Arun Easi0eba25d2012-02-09 11:15:58 -08003869 (fcport->flags & FCF_ASYNC_SENT) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 fcport->port_type != FCT_INITIATOR &&
3871 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003872 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003873 fcport->d_id.b.domain, fcport->d_id.b.area,
3874 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003875 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 }
3877
3878 break;
3879 }
3880
3881 if (found)
3882 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883 /* If device was not in our fcports list, then add it. */
Roland Dreierb2032fd2015-07-14 16:00:42 -04003884 new_fcport->scan_state = QLA_FCPORT_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 list_add_tail(&new_fcport->list, new_fcports);
3886
3887 /* Allocate a new replacement fcport. */
3888 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003889 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003891 ql_log(ql_log_warn, vha, 0x2066,
3892 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 return (QLA_MEMORY_ALLOC_FAILED);
3894 }
3895 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3896 new_fcport->d_id.b24 = nxt_d_id.b24;
3897 }
3898
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003899 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901 return (rval);
3902}
3903
3904/*
3905 * qla2x00_find_new_loop_id
3906 * Scan through our port list and find a new usable loop ID.
3907 *
3908 * Input:
3909 * ha: adapter state pointer.
3910 * dev: port structure pointer.
3911 *
3912 * Returns:
3913 * qla2x00 local function return status code.
3914 *
3915 * Context:
3916 * Kernel context.
3917 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003918int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003919qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920{
3921 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003922 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07003923 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924
3925 rval = QLA_SUCCESS;
3926
Chad Dupuis5f16b332012-08-22 14:21:00 -04003927 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928
Chad Dupuis5f16b332012-08-22 14:21:00 -04003929 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
3930 LOOPID_MAP_SIZE);
3931 if (dev->loop_id >= LOOPID_MAP_SIZE ||
3932 qla2x00_is_reserved_id(vha, dev->loop_id)) {
3933 dev->loop_id = FC_NO_LOOP_ID;
3934 rval = QLA_FUNCTION_FAILED;
3935 } else
3936 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937
Chad Dupuis5f16b332012-08-22 14:21:00 -04003938 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939
Chad Dupuis5f16b332012-08-22 14:21:00 -04003940 if (rval == QLA_SUCCESS)
3941 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
3942 "Assigning new loopid=%x, portid=%x.\n",
3943 dev->loop_id, dev->d_id.b24);
3944 else
3945 ql_log(ql_log_warn, dev->vha, 0x2087,
3946 "No loop_id's available, portid=%x.\n",
3947 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948
3949 return (rval);
3950}
3951
3952/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 * qla2x00_fabric_dev_login
3954 * Login fabric target device and update FC port database.
3955 *
3956 * Input:
3957 * ha: adapter state pointer.
3958 * fcport: port structure list pointer.
3959 * next_loopid: contains value of a new loop ID that can be used
3960 * by the next login attempt.
3961 *
3962 * Returns:
3963 * qla2x00 local function return status code.
3964 *
3965 * Context:
3966 * Kernel context.
3967 */
3968static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003969qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 uint16_t *next_loopid)
3971{
3972 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003973 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003974 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975
3976 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977
Andrew Vasquezac280b62009-08-20 11:06:05 -07003978 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003979 if (fcport->flags & FCF_ASYNC_SENT)
3980 return rval;
3981 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003982 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3983 if (!rval)
3984 return rval;
3985 }
3986
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003987 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003988 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003990 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003991 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003992 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003993 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003994 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003996 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003997 fcport->d_id.b.domain, fcport->d_id.b.area,
3998 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003999 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004001 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002 }
Chad Dupuis0b91d112012-02-09 11:15:42 -08004003 } else {
4004 /* Retry Login. */
4005 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 }
4007
4008 return (rval);
4009}
4010
4011/*
4012 * qla2x00_fabric_login
4013 * Issue fabric login command.
4014 *
4015 * Input:
4016 * ha = adapter block pointer.
4017 * device = pointer to FC device type structure.
4018 *
4019 * Returns:
4020 * 0 - Login successfully
4021 * 1 - Login failed
4022 * 2 - Initiator device
4023 * 3 - Fatal error
4024 */
4025int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004026qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027 uint16_t *next_loopid)
4028{
4029 int rval;
4030 int retry;
4031 uint16_t tmp_loopid;
4032 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004033 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034
4035 retry = 0;
4036 tmp_loopid = 0;
4037
4038 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004039 ql_dbg(ql_dbg_disc, vha, 0x2000,
4040 "Trying Fabric Login w/loop id 0x%04x for port "
4041 "%02x%02x%02x.\n",
4042 fcport->loop_id, fcport->d_id.b.domain,
4043 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044
4045 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08004046 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 fcport->d_id.b.domain, fcport->d_id.b.area,
4048 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08004049 if (rval != QLA_SUCCESS) {
4050 return rval;
4051 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 if (mb[0] == MBS_PORT_ID_USED) {
4053 /*
4054 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004055 * recommends the driver perform an implicit login with
4056 * the specified ID again. The ID we just used is save
4057 * here so we return with an ID that can be tried by
4058 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059 */
4060 retry++;
4061 tmp_loopid = fcport->loop_id;
4062 fcport->loop_id = mb[1];
4063
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004064 ql_dbg(ql_dbg_disc, vha, 0x2001,
4065 "Fabric Login: port in use - next loop "
4066 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004068 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069
4070 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
4071 /*
4072 * Login succeeded.
4073 */
4074 if (retry) {
4075 /* A retry occurred before. */
4076 *next_loopid = tmp_loopid;
4077 } else {
4078 /*
4079 * No retry occurred before. Just increment the
4080 * ID value for next login.
4081 */
4082 *next_loopid = (fcport->loop_id + 1);
4083 }
4084
4085 if (mb[1] & BIT_0) {
4086 fcport->port_type = FCT_INITIATOR;
4087 } else {
4088 fcport->port_type = FCT_TARGET;
4089 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07004090 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091 }
4092 }
4093
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004094 if (mb[10] & BIT_0)
4095 fcport->supported_classes |= FC_COS_CLASS2;
4096 if (mb[10] & BIT_1)
4097 fcport->supported_classes |= FC_COS_CLASS3;
4098
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004099 if (IS_FWI2_CAPABLE(ha)) {
4100 if (mb[10] & BIT_7)
4101 fcport->flags |=
4102 FCF_CONF_COMP_SUPPORTED;
4103 }
4104
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105 rval = QLA_SUCCESS;
4106 break;
4107 } else if (mb[0] == MBS_LOOP_ID_USED) {
4108 /*
4109 * Loop ID already used, try next loop ID.
4110 */
4111 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004112 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113 if (rval != QLA_SUCCESS) {
4114 /* Ran out of loop IDs to use */
4115 break;
4116 }
4117 } else if (mb[0] == MBS_COMMAND_ERROR) {
4118 /*
4119 * Firmware possibly timed out during login. If NO
4120 * retries are left to do then the device is declared
4121 * dead.
4122 */
4123 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004124 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07004125 fcport->d_id.b.domain, fcport->d_id.b.area,
4126 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004127 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128
4129 rval = 1;
4130 break;
4131 } else {
4132 /*
4133 * unrecoverable / not handled error
4134 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004135 ql_dbg(ql_dbg_disc, vha, 0x2002,
4136 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
4137 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
4138 fcport->d_id.b.area, fcport->d_id.b.al_pa,
4139 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140
4141 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004142 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07004143 fcport->d_id.b.domain, fcport->d_id.b.area,
4144 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004145 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07004146 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004147
4148 rval = 3;
4149 break;
4150 }
4151 }
4152
4153 return (rval);
4154}
4155
4156/*
4157 * qla2x00_local_device_login
4158 * Issue local device login command.
4159 *
4160 * Input:
4161 * ha = adapter block pointer.
4162 * loop_id = loop id of device to login to.
4163 *
4164 * Returns (Where's the #define!!!!):
4165 * 0 - Login successfully
4166 * 1 - Login failed
4167 * 3 - Fatal error
4168 */
4169int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004170qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004171{
4172 int rval;
4173 uint16_t mb[MAILBOX_REGISTER_COUNT];
4174
4175 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004176 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177 if (rval == QLA_SUCCESS) {
4178 /* Interrogate mailbox registers for any errors */
4179 if (mb[0] == MBS_COMMAND_ERROR)
4180 rval = 1;
4181 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
4182 /* device not in PCB table */
4183 rval = 3;
4184 }
4185
4186 return (rval);
4187}
4188
4189/*
4190 * qla2x00_loop_resync
4191 * Resync with fibre channel devices.
4192 *
4193 * Input:
4194 * ha = adapter block pointer.
4195 *
4196 * Returns:
4197 * 0 = success
4198 */
4199int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004200qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004202 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004204 struct req_que *req;
4205 struct rsp_que *rsp;
4206
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004207 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004208 req = vha->hw->req_q_map[0];
4209 else
4210 req = vha->req;
4211 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004213 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4214 if (vha->flags.online) {
4215 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4217 wait_time = 256;
4218 do {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004219 if (!IS_QLAFX00(vha->hw)) {
4220 /*
4221 * Issue a marker after FW becomes
4222 * ready.
4223 */
4224 qla2x00_marker(vha, req, rsp, 0, 0,
4225 MK_SYNC_ALL);
4226 vha->marker_needed = 0;
4227 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228
4229 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004230 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004232 if (IS_QLAFX00(vha->hw))
4233 qlafx00_configure_devices(vha);
4234 else
4235 qla2x00_configure_loop(vha);
4236
Linus Torvalds1da177e2005-04-16 15:20:36 -07004237 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004238 } while (!atomic_read(&vha->loop_down_timer) &&
4239 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4240 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4241 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004242 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243 }
4244
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004245 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004248 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004249 ql_dbg(ql_dbg_disc, vha, 0x206c,
4250 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004251
4252 return (rval);
4253}
4254
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004255/*
4256* qla2x00_perform_loop_resync
4257* Description: This function will set the appropriate flags and call
4258* qla2x00_loop_resync. If successful loop will be resynced
4259* Arguments : scsi_qla_host_t pointer
4260* returm : Success or Failure
4261*/
4262
4263int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
4264{
4265 int32_t rval = 0;
4266
4267 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
4268 /*Configure the flags so that resync happens properly*/
4269 atomic_set(&ha->loop_down_timer, 0);
4270 if (!(ha->device_flags & DFLG_NO_CABLE)) {
4271 atomic_set(&ha->loop_state, LOOP_UP);
4272 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4273 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
4274 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4275
4276 rval = qla2x00_loop_resync(ha);
4277 } else
4278 atomic_set(&ha->loop_state, LOOP_DEAD);
4279
4280 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
4281 }
4282
4283 return rval;
4284}
4285
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286void
Andrew Vasquez67becc02009-08-25 11:36:20 -07004287qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004288{
4289 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07004290 struct scsi_qla_host *vha;
4291 struct qla_hw_data *ha = base_vha->hw;
4292 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004293
Arun Easifeafb7b2010-09-03 14:57:00 -07004294 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004295 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07004296 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
4297 atomic_inc(&vha->vref_count);
4298 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08004299 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07004300 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
4301 spin_unlock_irqrestore(&ha->vport_slock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07004302 qla2x00_rport_del(fcport);
Alexei Potashnikdf673272015-07-14 16:00:46 -04004303
4304 /*
4305 * Release the target mode FC NEXUS in
4306 * qla_target.c, if target mod is enabled.
4307 */
4308 qlt_fc_port_deleted(vha, fcport,
4309 base_vha->total_fcport_update_gen);
4310
Arun Easifeafb7b2010-09-03 14:57:00 -07004311 spin_lock_irqsave(&ha->vport_slock, flags);
4312 }
4313 }
4314 atomic_dec(&vha->vref_count);
4315 }
4316 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004317}
4318
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004319/* Assumes idc_lock always held on entry */
4320void
4321qla83xx_reset_ownership(scsi_qla_host_t *vha)
4322{
4323 struct qla_hw_data *ha = vha->hw;
4324 uint32_t drv_presence, drv_presence_mask;
4325 uint32_t dev_part_info1, dev_part_info2, class_type;
4326 uint32_t class_type_mask = 0x3;
4327 uint16_t fcoe_other_function = 0xffff, i;
4328
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004329 if (IS_QLA8044(ha)) {
4330 drv_presence = qla8044_rd_direct(vha,
4331 QLA8044_CRB_DRV_ACTIVE_INDEX);
4332 dev_part_info1 = qla8044_rd_direct(vha,
4333 QLA8044_CRB_DEV_PART_INFO_INDEX);
4334 dev_part_info2 = qla8044_rd_direct(vha,
4335 QLA8044_CRB_DEV_PART_INFO2);
4336 } else {
4337 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4338 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
4339 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
4340 }
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004341 for (i = 0; i < 8; i++) {
4342 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
4343 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4344 (i != ha->portnum)) {
4345 fcoe_other_function = i;
4346 break;
4347 }
4348 }
4349 if (fcoe_other_function == 0xffff) {
4350 for (i = 0; i < 8; i++) {
4351 class_type = ((dev_part_info2 >> (i * 4)) &
4352 class_type_mask);
4353 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4354 ((i + 8) != ha->portnum)) {
4355 fcoe_other_function = i + 8;
4356 break;
4357 }
4358 }
4359 }
4360 /*
4361 * Prepare drv-presence mask based on fcoe functions present.
4362 * However consider only valid physical fcoe function numbers (0-15).
4363 */
4364 drv_presence_mask = ~((1 << (ha->portnum)) |
4365 ((fcoe_other_function == 0xffff) ?
4366 0 : (1 << (fcoe_other_function))));
4367
4368 /* We are the reset owner iff:
4369 * - No other protocol drivers present.
4370 * - This is the lowest among fcoe functions. */
4371 if (!(drv_presence & drv_presence_mask) &&
4372 (ha->portnum < fcoe_other_function)) {
4373 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
4374 "This host is Reset owner.\n");
4375 ha->flags.nic_core_reset_owner = 1;
4376 }
4377}
4378
Saurav Kashyapfa492632012-11-21 02:40:29 -05004379static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004380__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
4381{
4382 int rval = QLA_SUCCESS;
4383 struct qla_hw_data *ha = vha->hw;
4384 uint32_t drv_ack;
4385
4386 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4387 if (rval == QLA_SUCCESS) {
4388 drv_ack |= (1 << ha->portnum);
4389 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4390 }
4391
4392 return rval;
4393}
4394
Saurav Kashyapfa492632012-11-21 02:40:29 -05004395static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004396__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
4397{
4398 int rval = QLA_SUCCESS;
4399 struct qla_hw_data *ha = vha->hw;
4400 uint32_t drv_ack;
4401
4402 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4403 if (rval == QLA_SUCCESS) {
4404 drv_ack &= ~(1 << ha->portnum);
4405 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4406 }
4407
4408 return rval;
4409}
4410
Saurav Kashyapfa492632012-11-21 02:40:29 -05004411static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004412qla83xx_dev_state_to_string(uint32_t dev_state)
4413{
4414 switch (dev_state) {
4415 case QLA8XXX_DEV_COLD:
4416 return "COLD/RE-INIT";
4417 case QLA8XXX_DEV_INITIALIZING:
4418 return "INITIALIZING";
4419 case QLA8XXX_DEV_READY:
4420 return "READY";
4421 case QLA8XXX_DEV_NEED_RESET:
4422 return "NEED RESET";
4423 case QLA8XXX_DEV_NEED_QUIESCENT:
4424 return "NEED QUIESCENT";
4425 case QLA8XXX_DEV_FAILED:
4426 return "FAILED";
4427 case QLA8XXX_DEV_QUIESCENT:
4428 return "QUIESCENT";
4429 default:
4430 return "Unknown";
4431 }
4432}
4433
4434/* Assumes idc-lock always held on entry */
4435void
4436qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
4437{
4438 struct qla_hw_data *ha = vha->hw;
4439 uint32_t idc_audit_reg = 0, duration_secs = 0;
4440
4441 switch (audit_type) {
4442 case IDC_AUDIT_TIMESTAMP:
4443 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
4444 idc_audit_reg = (ha->portnum) |
4445 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
4446 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4447 break;
4448
4449 case IDC_AUDIT_COMPLETION:
4450 duration_secs = ((jiffies_to_msecs(jiffies) -
4451 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
4452 idc_audit_reg = (ha->portnum) |
4453 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
4454 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4455 break;
4456
4457 default:
4458 ql_log(ql_log_warn, vha, 0xb078,
4459 "Invalid audit type specified.\n");
4460 break;
4461 }
4462}
4463
4464/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05004465static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004466qla83xx_initiating_reset(scsi_qla_host_t *vha)
4467{
4468 struct qla_hw_data *ha = vha->hw;
4469 uint32_t idc_control, dev_state;
4470
4471 __qla83xx_get_idc_control(vha, &idc_control);
4472 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
4473 ql_log(ql_log_info, vha, 0xb080,
4474 "NIC Core reset has been disabled. idc-control=0x%x\n",
4475 idc_control);
4476 return QLA_FUNCTION_FAILED;
4477 }
4478
4479 /* Set NEED-RESET iff in READY state and we are the reset-owner */
4480 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4481 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
4482 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
4483 QLA8XXX_DEV_NEED_RESET);
4484 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
4485 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
4486 } else {
4487 const char *state = qla83xx_dev_state_to_string(dev_state);
4488 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
4489
4490 /* SV: XXX: Is timeout required here? */
4491 /* Wait for IDC state change READY -> NEED_RESET */
4492 while (dev_state == QLA8XXX_DEV_READY) {
4493 qla83xx_idc_unlock(vha, 0);
4494 msleep(200);
4495 qla83xx_idc_lock(vha, 0);
4496 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4497 }
4498 }
4499
4500 /* Send IDC ack by writing to drv-ack register */
4501 __qla83xx_set_drv_ack(vha);
4502
4503 return QLA_SUCCESS;
4504}
4505
4506int
4507__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
4508{
4509 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4510}
4511
4512int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004513__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
4514{
4515 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4516}
4517
Saurav Kashyapfa492632012-11-21 02:40:29 -05004518static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004519qla83xx_check_driver_presence(scsi_qla_host_t *vha)
4520{
4521 uint32_t drv_presence = 0;
4522 struct qla_hw_data *ha = vha->hw;
4523
4524 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4525 if (drv_presence & (1 << ha->portnum))
4526 return QLA_SUCCESS;
4527 else
4528 return QLA_TEST_FAILED;
4529}
4530
4531int
4532qla83xx_nic_core_reset(scsi_qla_host_t *vha)
4533{
4534 int rval = QLA_SUCCESS;
4535 struct qla_hw_data *ha = vha->hw;
4536
4537 ql_dbg(ql_dbg_p3p, vha, 0xb058,
4538 "Entered %s().\n", __func__);
4539
4540 if (vha->device_flags & DFLG_DEV_FAILED) {
4541 ql_log(ql_log_warn, vha, 0xb059,
4542 "Device in unrecoverable FAILED state.\n");
4543 return QLA_FUNCTION_FAILED;
4544 }
4545
4546 qla83xx_idc_lock(vha, 0);
4547
4548 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
4549 ql_log(ql_log_warn, vha, 0xb05a,
4550 "Function=0x%x has been removed from IDC participation.\n",
4551 ha->portnum);
4552 rval = QLA_FUNCTION_FAILED;
4553 goto exit;
4554 }
4555
4556 qla83xx_reset_ownership(vha);
4557
4558 rval = qla83xx_initiating_reset(vha);
4559
4560 /*
4561 * Perform reset if we are the reset-owner,
4562 * else wait till IDC state changes to READY/FAILED.
4563 */
4564 if (rval == QLA_SUCCESS) {
4565 rval = qla83xx_idc_state_handler(vha);
4566
4567 if (rval == QLA_SUCCESS)
4568 ha->flags.nic_core_hung = 0;
4569 __qla83xx_clear_drv_ack(vha);
4570 }
4571
4572exit:
4573 qla83xx_idc_unlock(vha, 0);
4574
4575 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
4576
4577 return rval;
4578}
4579
Saurav Kashyap81178772012-08-22 14:21:04 -04004580int
4581qla2xxx_mctp_dump(scsi_qla_host_t *vha)
4582{
4583 struct qla_hw_data *ha = vha->hw;
4584 int rval = QLA_FUNCTION_FAILED;
4585
4586 if (!IS_MCTP_CAPABLE(ha)) {
4587 /* This message can be removed from the final version */
4588 ql_log(ql_log_info, vha, 0x506d,
4589 "This board is not MCTP capable\n");
4590 return rval;
4591 }
4592
4593 if (!ha->mctp_dump) {
4594 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
4595 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
4596
4597 if (!ha->mctp_dump) {
4598 ql_log(ql_log_warn, vha, 0x506e,
4599 "Failed to allocate memory for mctp dump\n");
4600 return rval;
4601 }
4602 }
4603
4604#define MCTP_DUMP_STR_ADDR 0x00000000
4605 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
4606 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
4607 if (rval != QLA_SUCCESS) {
4608 ql_log(ql_log_warn, vha, 0x506f,
4609 "Failed to capture mctp dump\n");
4610 } else {
4611 ql_log(ql_log_info, vha, 0x5070,
4612 "Mctp dump capture for host (%ld/%p).\n",
4613 vha->host_no, ha->mctp_dump);
4614 ha->mctp_dumped = 1;
4615 }
4616
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04004617 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04004618 ha->flags.nic_core_reset_hdlr_active = 1;
4619 rval = qla83xx_restart_nic_firmware(vha);
4620 if (rval)
4621 /* NIC Core reset failed. */
4622 ql_log(ql_log_warn, vha, 0x5071,
4623 "Failed to restart nic firmware\n");
4624 else
4625 ql_dbg(ql_dbg_p3p, vha, 0xb084,
4626 "Restarted NIC firmware successfully.\n");
4627 ha->flags.nic_core_reset_hdlr_active = 0;
4628 }
4629
4630 return rval;
4631
4632}
4633
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004634/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004635* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004636* Description: This function will block the new I/Os
4637* Its not aborting any I/Os as context
4638* is not destroyed during quiescence
4639* Arguments: scsi_qla_host_t
4640* return : void
4641*/
4642void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004643qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004644{
4645 struct qla_hw_data *ha = vha->hw;
4646 struct scsi_qla_host *vp;
4647
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004648 ql_dbg(ql_dbg_dpc, vha, 0x401d,
4649 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004650
4651 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4652 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4653 atomic_set(&vha->loop_state, LOOP_DOWN);
4654 qla2x00_mark_all_devices_lost(vha, 0);
4655 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004656 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004657 } else {
4658 if (!atomic_read(&vha->loop_down_timer))
4659 atomic_set(&vha->loop_down_timer,
4660 LOOP_DOWN_TIME);
4661 }
4662 /* Wait for pending cmds to complete */
4663 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
4664}
4665
Giridhar Malavalia9083012010-04-12 17:59:55 -07004666void
4667qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
4668{
4669 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004670 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07004671 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004672 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004673
Saurav Kashyape46ef002011-02-23 15:27:16 -08004674 /* For ISP82XX, driver waits for completion of the commands.
4675 * online flag should be set.
4676 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004677 if (!(IS_P3P_TYPE(ha)))
Saurav Kashyape46ef002011-02-23 15:27:16 -08004678 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004679 ha->flags.chip_reset_done = 0;
4680 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04004681 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004682
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004683 ql_log(ql_log_info, vha, 0x00af,
4684 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004685
Saurav Kashyape46ef002011-02-23 15:27:16 -08004686 /* For ISP82XX, reset_chip is just disabling interrupts.
4687 * Driver waits for the completion of the commands.
4688 * the interrupts need to be enabled.
4689 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004690 if (!(IS_P3P_TYPE(ha)))
Giridhar Malavalia9083012010-04-12 17:59:55 -07004691 ha->isp_ops->reset_chip(vha);
4692
4693 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
4694 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4695 atomic_set(&vha->loop_state, LOOP_DOWN);
4696 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004697
4698 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004699 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07004700 atomic_inc(&vp->vref_count);
4701 spin_unlock_irqrestore(&ha->vport_slock, flags);
4702
Giridhar Malavalia9083012010-04-12 17:59:55 -07004703 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004704
4705 spin_lock_irqsave(&ha->vport_slock, flags);
4706 atomic_dec(&vp->vref_count);
4707 }
4708 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004709 } else {
4710 if (!atomic_read(&vha->loop_down_timer))
4711 atomic_set(&vha->loop_down_timer,
4712 LOOP_DOWN_TIME);
4713 }
4714
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004715 /* Clear all async request states across all VPs. */
4716 list_for_each_entry(fcport, &vha->vp_fcports, list)
4717 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4718 spin_lock_irqsave(&ha->vport_slock, flags);
4719 list_for_each_entry(vp, &ha->vp_list, list) {
4720 atomic_inc(&vp->vref_count);
4721 spin_unlock_irqrestore(&ha->vport_slock, flags);
4722
4723 list_for_each_entry(fcport, &vp->vp_fcports, list)
4724 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4725
4726 spin_lock_irqsave(&ha->vport_slock, flags);
4727 atomic_dec(&vp->vref_count);
4728 }
4729 spin_unlock_irqrestore(&ha->vport_slock, flags);
4730
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004731 if (!ha->flags.eeh_busy) {
4732 /* Make sure for ISP 82XX IO DMA is complete */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004733 if (IS_P3P_TYPE(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004734 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004735 ql_log(ql_log_info, vha, 0x00b4,
4736 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004737
Saurav Kashyape46ef002011-02-23 15:27:16 -08004738 /* Done waiting for pending commands.
4739 * Reset the online flag.
4740 */
4741 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004742 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004743
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004744 /* Requeue all commands in outstanding command list. */
4745 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4746 }
Arun Easib6a029e2014-09-25 06:14:52 -04004747
4748 ha->chip_reset++;
4749 /* memory barrier */
4750 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004751}
4752
4753/*
4754* qla2x00_abort_isp
4755* Resets ISP and aborts all outstanding commands.
4756*
4757* Input:
4758* ha = adapter block pointer.
4759*
4760* Returns:
4761* 0 = success
4762*/
4763int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004764qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004765{
Andrew Vasquez476e8972006-08-23 14:54:55 -07004766 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004767 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004768 struct qla_hw_data *ha = vha->hw;
4769 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004770 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07004771 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004772
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004773 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004774 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004775
Santosh Vernekara61712972012-08-22 14:21:13 -04004776 if (IS_QLA8031(ha)) {
4777 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
4778 "Clearing fcoe driver presence.\n");
4779 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
4780 ql_dbg(ql_dbg_p3p, vha, 0xb073,
4781 "Error while clearing DRV-Presence.\n");
4782 }
4783
Andrew Vasquez85880802009-12-15 21:29:46 -08004784 if (unlikely(pci_channel_offline(ha->pdev) &&
4785 ha->flags.pci_channel_io_perm_failure)) {
4786 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4787 status = 0;
4788 return status;
4789 }
4790
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004791 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08004792
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004793 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004795 if (!qla2x00_restart_isp(vha)) {
4796 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004798 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799 /*
4800 * Issue marker command only when we are going
4801 * to start the I/O .
4802 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004803 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004804 }
4805
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004806 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004807
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004808 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004809
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004810 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004811 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07004812
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004813 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
4814 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004815 if (ha->fce) {
4816 ha->flags.fce_enabled = 1;
4817 memset(ha->fce, 0,
4818 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004819 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004820 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4821 &ha->fce_bufs);
4822 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004823 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004824 "Unable to reinitialize FCE "
4825 "(%d).\n", rval);
4826 ha->flags.fce_enabled = 0;
4827 }
4828 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004829
4830 if (ha->eft) {
4831 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004832 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004833 ha->eft_dma, EFT_NUM_BUFFERS);
4834 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004835 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004836 "Unable to reinitialize EFT "
4837 "(%d).\n", rval);
4838 }
4839 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004841 vha->flags.online = 1;
4842 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004843 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004844 ql_log(ql_log_fatal, vha, 0x8035,
4845 "ISP error recover failed - "
4846 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004847 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004848 * The next call disables the board
4849 * completely.
4850 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004851 ha->isp_ops->reset_adapter(vha);
4852 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004853 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004854 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004855 status = 0;
4856 } else { /* schedule another ISP abort */
4857 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004858 ql_dbg(ql_dbg_taskm, vha, 0x8020,
4859 "ISP abort - retry remaining %d.\n",
4860 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004861 status = 1;
4862 }
4863 } else {
4864 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004865 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4866 "ISP error recovery - retrying (%d) "
4867 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004868 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004869 status = 1;
4870 }
4871 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004872
Linus Torvalds1da177e2005-04-16 15:20:36 -07004873 }
4874
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004875 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004876 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07004877
4878 spin_lock_irqsave(&ha->vport_slock, flags);
4879 list_for_each_entry(vp, &ha->vp_list, list) {
4880 if (vp->vp_idx) {
4881 atomic_inc(&vp->vref_count);
4882 spin_unlock_irqrestore(&ha->vport_slock, flags);
4883
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004884 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004885
4886 spin_lock_irqsave(&ha->vport_slock, flags);
4887 atomic_dec(&vp->vref_count);
4888 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004889 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004890 spin_unlock_irqrestore(&ha->vport_slock, flags);
4891
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004892 if (IS_QLA8031(ha)) {
4893 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
4894 "Setting back fcoe driver presence.\n");
4895 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
4896 ql_dbg(ql_dbg_p3p, vha, 0xb074,
4897 "Error while setting DRV-Presence.\n");
4898 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004899 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08004900 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
4901 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902 }
4903
4904 return(status);
4905}
4906
4907/*
4908* qla2x00_restart_isp
4909* restarts the ISP after a reset
4910*
4911* Input:
4912* ha = adapter block pointer.
4913*
4914* Returns:
4915* 0 = success
4916*/
4917static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004918qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004919{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004920 int status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004921 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004922 struct req_que *req = ha->req_q_map[0];
4923 struct rsp_que *rsp = ha->rsp_q_map[0];
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004924 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004925
4926 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004927 if (qla2x00_isp_firmware(vha)) {
4928 vha->flags.online = 0;
4929 status = ha->isp_ops->chip_diag(vha);
4930 if (!status)
4931 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004932 }
4933
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004934 if (!status && !(status = qla2x00_init_rings(vha))) {
4935 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004936 ha->flags.chip_reset_done = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04004937
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004938 /* Initialize the queues in use */
4939 qla25xx_init_queues(ha);
4940
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004941 status = qla2x00_fw_ready(vha);
4942 if (!status) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004943 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004944 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004945
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004946 vha->flags.online = 1;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004947
4948 /*
4949 * Process any ATIO queue entries that came in
4950 * while we weren't online.
4951 */
4952 spin_lock_irqsave(&ha->hardware_lock, flags);
4953 if (qla_tgt_mode_enabled(vha))
4954 qlt_24xx_process_atio_queue(vha);
4955 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4956
Chad Dupuis7108b762014-04-11 16:54:45 -04004957 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958 }
4959
4960 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004961 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004962 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004963 }
4964 return (status);
4965}
4966
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004967static int
4968qla25xx_init_queues(struct qla_hw_data *ha)
4969{
4970 struct rsp_que *rsp = NULL;
4971 struct req_que *req = NULL;
4972 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4973 int ret = -1;
4974 int i;
4975
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004976 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004977 rsp = ha->rsp_q_map[i];
4978 if (rsp) {
4979 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004980 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004981 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004982 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4983 "%s Rsp que: %d init failed.\n",
4984 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004985 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004986 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4987 "%s Rsp que: %d inited.\n",
4988 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004989 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004990 }
4991 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004992 req = ha->req_q_map[i];
4993 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004994 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004995 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004996 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004997 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004998 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4999 "%s Req que: %d init failed.\n",
5000 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005001 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005002 ql_dbg(ql_dbg_init, base_vha, 0x0102,
5003 "%s Req que: %d inited.\n",
5004 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005005 }
5006 }
5007 return ret;
5008}
5009
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010/*
5011* qla2x00_reset_adapter
5012* Reset adapter.
5013*
5014* Input:
5015* ha = adapter block pointer.
5016*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07005017void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005018qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019{
5020 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005021 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07005022 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005023
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005024 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005025 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026
Linus Torvalds1da177e2005-04-16 15:20:36 -07005027 spin_lock_irqsave(&ha->hardware_lock, flags);
5028 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
5029 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
5030 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
5031 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
5032 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5033}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005034
5035void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005036qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005037{
5038 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005039 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005040 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
5041
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005042 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005043 return;
5044
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005045 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005046 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005047
5048 spin_lock_irqsave(&ha->hardware_lock, flags);
5049 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
5050 RD_REG_DWORD(&reg->hccr);
5051 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
5052 RD_REG_DWORD(&reg->hccr);
5053 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08005054
5055 if (IS_NOPOLLING_TYPE(ha))
5056 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005057}
5058
David Miller4e08df32007-04-16 12:37:43 -07005059/* On sparc systems, obtain port and node WWN from firmware
5060 * properties.
5061 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005062static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
5063 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07005064{
5065#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005066 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07005067 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07005068 struct device_node *dp = pci_device_to_OF_node(pdev);
5069 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07005070 int len;
5071
5072 val = of_get_property(dp, "port-wwn", &len);
5073 if (val && len >= WWN_SIZE)
5074 memcpy(nv->port_name, val, WWN_SIZE);
5075
5076 val = of_get_property(dp, "node-wwn", &len);
5077 if (val && len >= WWN_SIZE)
5078 memcpy(nv->node_name, val, WWN_SIZE);
5079#endif
5080}
5081
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005082int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005083qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005084{
David Miller4e08df32007-04-16 12:37:43 -07005085 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005086 struct init_cb_24xx *icb;
5087 struct nvram_24xx *nv;
5088 uint32_t *dptr;
5089 uint8_t *dptr1, *dptr2;
5090 uint32_t chksum;
5091 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005092 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005093
David Miller4e08df32007-04-16 12:37:43 -07005094 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005095 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07005096 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005097
5098 /* Determine NVRAM starting address. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05005099 if (ha->port_no == 0) {
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005100 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
5101 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
5102 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005103 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08005104 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
5105 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05005106
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005107 ha->nvram_size = sizeof(struct nvram_24xx);
5108 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005109
Seokmann Ju281afe12007-07-26 13:43:34 -07005110 /* Get VPD data into cache */
5111 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005112 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07005113 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
5114
5115 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005116 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005117 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005118 ha->nvram_size);
5119 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5120 chksum += le32_to_cpu(*dptr++);
5121
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005122 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
5123 "Contents of NVRAM\n");
5124 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
5125 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005126
5127 /* Bad NVRAM data, set defaults parameters. */
5128 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5129 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07005130 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005131 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005132 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04005133 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005134 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
5135 ql_log(ql_log_warn, vha, 0x006c,
5136 "Falling back to functioning (yet invalid -- WWPN) "
5137 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07005138
5139 /*
5140 * Set default initialization control block.
5141 */
5142 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07005143 nv->nvram_version = cpu_to_le16(ICB_VERSION);
5144 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04005145 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07005146 nv->execution_throttle = cpu_to_le16(0xFFFF);
5147 nv->exchange_count = cpu_to_le16(0);
5148 nv->hard_address = cpu_to_le16(124);
David Miller4e08df32007-04-16 12:37:43 -07005149 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005150 nv->port_name[1] = 0x00 + ha->port_no + 1;
David Miller4e08df32007-04-16 12:37:43 -07005151 nv->port_name[2] = 0x00;
5152 nv->port_name[3] = 0xe0;
5153 nv->port_name[4] = 0x8b;
5154 nv->port_name[5] = 0x1c;
5155 nv->port_name[6] = 0x55;
5156 nv->port_name[7] = 0x86;
5157 nv->node_name[0] = 0x20;
5158 nv->node_name[1] = 0x00;
5159 nv->node_name[2] = 0x00;
5160 nv->node_name[3] = 0xe0;
5161 nv->node_name[4] = 0x8b;
5162 nv->node_name[5] = 0x1c;
5163 nv->node_name[6] = 0x55;
5164 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005165 qla24xx_nvram_wwn_from_ofw(vha, nv);
Bart Van Asschead950362015-07-09 07:24:08 -07005166 nv->login_retry_count = cpu_to_le16(8);
5167 nv->interrupt_delay_timer = cpu_to_le16(0);
5168 nv->login_timeout = cpu_to_le16(0);
David Miller4e08df32007-04-16 12:37:43 -07005169 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07005170 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5171 nv->firmware_options_2 = cpu_to_le32(2 << 4);
5172 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
5173 nv->firmware_options_3 = cpu_to_le32(2 << 13);
5174 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
5175 nv->efi_parameters = cpu_to_le32(0);
David Miller4e08df32007-04-16 12:37:43 -07005176 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07005177 nv->max_luns_per_target = cpu_to_le16(128);
5178 nv->port_down_retry_count = cpu_to_le16(30);
5179 nv->link_down_timeout = cpu_to_le16(30);
David Miller4e08df32007-04-16 12:37:43 -07005180
5181 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005182 }
5183
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005184 if (!qla_ini_mode_enabled(vha)) {
5185 /* Don't enable full login after initial LIP */
Bart Van Asschead950362015-07-09 07:24:08 -07005186 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005187 /* Don't enable LIP full login for initiator */
Bart Van Asschead950362015-07-09 07:24:08 -07005188 nv->host_p &= cpu_to_le32(~BIT_10);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005189 }
5190
5191 qlt_24xx_config_nvram_stage1(vha, nv);
5192
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005193 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005194 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005195
5196 /* Copy 1st segment. */
5197 dptr1 = (uint8_t *)icb;
5198 dptr2 = (uint8_t *)&nv->version;
5199 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5200 while (cnt--)
5201 *dptr1++ = *dptr2++;
5202
5203 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07005204 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005205
5206 /* Copy 2nd segment. */
5207 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5208 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5209 cnt = (uint8_t *)&icb->reserved_3 -
5210 (uint8_t *)&icb->interrupt_delay_timer;
5211 while (cnt--)
5212 *dptr1++ = *dptr2++;
5213
5214 /*
5215 * Setup driver NVRAM options.
5216 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005217 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08005218 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005219
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005220 qlt_24xx_config_nvram_stage2(vha, icb);
5221
Bart Van Asschead950362015-07-09 07:24:08 -07005222 if (nv->host_p & cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005223 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07005224 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5225 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5226 }
5227
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005228 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07005229 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005230 /*
5231 * Firmware will apply the following mask if the nodename was
5232 * not provided.
5233 */
5234 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5235 icb->node_name[0] &= 0xF0;
5236 }
5237
5238 /* Set host adapter parameters. */
5239 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08005240 ha->flags.enable_lip_reset = 0;
5241 ha->flags.enable_lip_full_login =
5242 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5243 ha->flags.enable_target_reset =
5244 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005245 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07005246 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005247
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07005248 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5249 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005250
5251 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
5252 sizeof(ha->fw_seriallink_options24));
5253
5254 /* save HBA serial number */
5255 ha->serial0 = icb->port_name[5];
5256 ha->serial1 = icb->port_name[6];
5257 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005258 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5259 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005260
Bart Van Asschead950362015-07-09 07:24:08 -07005261 icb->execution_throttle = cpu_to_le16(0xFFFF);
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08005262
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005263 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5264
5265 /* Set minimum login_timeout to 4 seconds. */
5266 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5267 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5268 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07005269 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005270 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07005271 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005272
Andrew Vasquez00a537b2008-02-28 14:06:11 -08005273 /* Set minimum RATOV to 100 tenths of a second. */
5274 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005275
5276 ha->loop_reset_delay = nv->reset_delay;
5277
5278 /* Link Down Timeout = 0:
5279 *
5280 * When Port Down timer expires we will start returning
5281 * I/O's to OS with "DID_NO_CONNECT".
5282 *
5283 * Link Down Timeout != 0:
5284 *
5285 * The driver waits for the link to come up after link down
5286 * before returning I/Os to OS with "DID_NO_CONNECT".
5287 */
5288 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5289 ha->loop_down_abort_time =
5290 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5291 } else {
5292 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5293 ha->loop_down_abort_time =
5294 (LOOP_DOWN_TIME - ha->link_down_timeout);
5295 }
5296
5297 /* Need enough time to try and get the port back. */
5298 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5299 if (qlport_down_retry)
5300 ha->port_down_retry_count = qlport_down_retry;
5301
5302 /* Set login_retry_count */
5303 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5304 if (ha->port_down_retry_count ==
5305 le16_to_cpu(nv->port_down_retry_count) &&
5306 ha->port_down_retry_count > 3)
5307 ha->login_retry_count = ha->port_down_retry_count;
5308 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5309 ha->login_retry_count = ha->port_down_retry_count;
5310 if (ql2xloginretrycount)
5311 ha->login_retry_count = ql2xloginretrycount;
5312
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005313 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005314 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005315 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5316 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5317 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5318 le16_to_cpu(icb->interrupt_delay_timer): 2;
5319 }
Bart Van Asschead950362015-07-09 07:24:08 -07005320 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005321 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005322 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005323 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08005324 ha->zio_mode = QLA_ZIO_MODE_6;
5325
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005326 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005327 "ZIO mode %d enabled; timer delay (%d us).\n",
5328 ha->zio_mode, ha->zio_timer * 100);
5329
5330 icb->firmware_options_2 |= cpu_to_le32(
5331 (uint32_t)ha->zio_mode);
5332 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005333 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005334 }
5335
David Miller4e08df32007-04-16 12:37:43 -07005336 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005337 ql_log(ql_log_warn, vha, 0x0070,
5338 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07005339 }
5340 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005341}
5342
Adrian Bunk413975a2006-06-30 02:33:06 -07005343static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005344qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
5345 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005346{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005347 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005348 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005349 uint32_t *dcode, dlen;
5350 uint32_t risc_addr;
5351 uint32_t risc_size;
5352 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005353 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005354 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005355
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005356 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08005357 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005358
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005359 rval = QLA_SUCCESS;
5360
5361 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005362 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005363 *srisc_addr = 0;
5364
5365 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005366 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005367 for (i = 0; i < 4; i++)
5368 dcode[i] = be32_to_cpu(dcode[i]);
5369 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5370 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5371 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5372 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005373 ql_log(ql_log_fatal, vha, 0x008c,
5374 "Unable to verify the integrity of flash firmware "
5375 "image.\n");
5376 ql_log(ql_log_fatal, vha, 0x008d,
5377 "Firmware data: %08x %08x %08x %08x.\n",
5378 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005379
5380 return QLA_FUNCTION_FAILED;
5381 }
5382
5383 while (segments && rval == QLA_SUCCESS) {
5384 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005385 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005386
5387 risc_addr = be32_to_cpu(dcode[2]);
5388 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5389 risc_size = be32_to_cpu(dcode[3]);
5390
5391 fragment = 0;
5392 while (risc_size > 0 && rval == QLA_SUCCESS) {
5393 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5394 if (dlen > risc_size)
5395 dlen = risc_size;
5396
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005397 ql_dbg(ql_dbg_init, vha, 0x008e,
5398 "Loading risc segment@ risc addr %x "
5399 "number of dwords 0x%x offset 0x%x.\n",
5400 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005401
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005402 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005403 for (i = 0; i < dlen; i++)
5404 dcode[i] = swab32(dcode[i]);
5405
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005406 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005407 dlen);
5408 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005409 ql_log(ql_log_fatal, vha, 0x008f,
5410 "Failed to load segment %d of firmware.\n",
5411 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04005412 return QLA_FUNCTION_FAILED;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005413 }
5414
5415 faddr += dlen;
5416 risc_addr += dlen;
5417 risc_size -= dlen;
5418 fragment++;
5419 }
5420
5421 /* Next segment. */
5422 segments--;
5423 }
5424
Chad Dupuisf73cb692014-02-26 04:15:06 -05005425 if (!IS_QLA27XX(ha))
5426 return rval;
5427
5428 if (ha->fw_dump_template)
5429 vfree(ha->fw_dump_template);
5430 ha->fw_dump_template = NULL;
5431 ha->fw_dump_template_len = 0;
5432
5433 ql_dbg(ql_dbg_init, vha, 0x0161,
5434 "Loading fwdump template from %x\n", faddr);
5435 qla24xx_read_flash_data(vha, dcode, faddr, 7);
5436 risc_size = be32_to_cpu(dcode[2]);
5437 ql_dbg(ql_dbg_init, vha, 0x0162,
5438 "-> array size %x dwords\n", risc_size);
5439 if (risc_size == 0 || risc_size == ~0)
5440 goto default_template;
5441
5442 dlen = (risc_size - 8) * sizeof(*dcode);
5443 ql_dbg(ql_dbg_init, vha, 0x0163,
5444 "-> template allocating %x bytes...\n", dlen);
5445 ha->fw_dump_template = vmalloc(dlen);
5446 if (!ha->fw_dump_template) {
5447 ql_log(ql_log_warn, vha, 0x0164,
5448 "Failed fwdump template allocate %x bytes.\n", risc_size);
5449 goto default_template;
5450 }
5451
5452 faddr += 7;
5453 risc_size -= 8;
5454 dcode = ha->fw_dump_template;
5455 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
5456 for (i = 0; i < risc_size; i++)
5457 dcode[i] = le32_to_cpu(dcode[i]);
5458
5459 if (!qla27xx_fwdt_template_valid(dcode)) {
5460 ql_log(ql_log_warn, vha, 0x0165,
5461 "Failed fwdump template validate\n");
5462 goto default_template;
5463 }
5464
5465 dlen = qla27xx_fwdt_template_size(dcode);
5466 ql_dbg(ql_dbg_init, vha, 0x0166,
5467 "-> template size %x bytes\n", dlen);
5468 if (dlen > risc_size * sizeof(*dcode)) {
5469 ql_log(ql_log_warn, vha, 0x0167,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005470 "Failed fwdump template exceeds array by %x bytes\n",
5471 (uint32_t)(dlen - risc_size * sizeof(*dcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005472 goto default_template;
5473 }
5474 ha->fw_dump_template_len = dlen;
5475 return rval;
5476
5477default_template:
5478 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
5479 if (ha->fw_dump_template)
5480 vfree(ha->fw_dump_template);
5481 ha->fw_dump_template = NULL;
5482 ha->fw_dump_template_len = 0;
5483
5484 dlen = qla27xx_fwdt_template_default_size();
5485 ql_dbg(ql_dbg_init, vha, 0x0169,
5486 "-> template allocating %x bytes...\n", dlen);
5487 ha->fw_dump_template = vmalloc(dlen);
5488 if (!ha->fw_dump_template) {
5489 ql_log(ql_log_warn, vha, 0x016a,
5490 "Failed fwdump template allocate %x bytes.\n", risc_size);
5491 goto failed_template;
5492 }
5493
5494 dcode = ha->fw_dump_template;
5495 risc_size = dlen / sizeof(*dcode);
5496 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
5497 for (i = 0; i < risc_size; i++)
5498 dcode[i] = be32_to_cpu(dcode[i]);
5499
5500 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5501 ql_log(ql_log_warn, vha, 0x016b,
5502 "Failed fwdump template validate\n");
5503 goto failed_template;
5504 }
5505
5506 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5507 ql_dbg(ql_dbg_init, vha, 0x016c,
5508 "-> template size %x bytes\n", dlen);
5509 ha->fw_dump_template_len = dlen;
5510 return rval;
5511
5512failed_template:
5513 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
5514 if (ha->fw_dump_template)
5515 vfree(ha->fw_dump_template);
5516 ha->fw_dump_template = NULL;
5517 ha->fw_dump_template_len = 0;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005518 return rval;
5519}
5520
Giridhar Malavalie9454a82013-02-08 01:57:47 -05005521#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005522
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005523int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005524qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08005525{
5526 int rval;
5527 int i, fragment;
5528 uint16_t *wcode, *fwcode;
5529 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
5530 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005531 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005532 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08005533
5534 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005535 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005536 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005537 ql_log(ql_log_info, vha, 0x0083,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01005538 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005539 ql_log(ql_log_info, vha, 0x0084,
5540 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08005541 return QLA_FUNCTION_FAILED;
5542 }
5543
5544 rval = QLA_SUCCESS;
5545
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005546 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08005547 *srisc_addr = 0;
5548 fwcode = (uint16_t *)blob->fw->data;
5549 fwclen = 0;
5550
5551 /* Validate firmware image by checking version. */
5552 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005553 ql_log(ql_log_fatal, vha, 0x0085,
5554 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005555 blob->fw->size);
5556 goto fail_fw_integrity;
5557 }
5558 for (i = 0; i < 4; i++)
5559 wcode[i] = be16_to_cpu(fwcode[i + 4]);
5560 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
5561 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
5562 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005563 ql_log(ql_log_fatal, vha, 0x0086,
5564 "Unable to verify integrity of firmware image.\n");
5565 ql_log(ql_log_fatal, vha, 0x0087,
5566 "Firmware data: %04x %04x %04x %04x.\n",
5567 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08005568 goto fail_fw_integrity;
5569 }
5570
5571 seg = blob->segs;
5572 while (*seg && rval == QLA_SUCCESS) {
5573 risc_addr = *seg;
5574 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
5575 risc_size = be16_to_cpu(fwcode[3]);
5576
5577 /* Validate firmware image size. */
5578 fwclen += risc_size * sizeof(uint16_t);
5579 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005580 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08005581 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005582 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08005583 goto fail_fw_integrity;
5584 }
5585
5586 fragment = 0;
5587 while (risc_size > 0 && rval == QLA_SUCCESS) {
5588 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
5589 if (wlen > risc_size)
5590 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005591 ql_dbg(ql_dbg_init, vha, 0x0089,
5592 "Loading risc segment@ risc addr %x number of "
5593 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08005594
5595 for (i = 0; i < wlen; i++)
5596 wcode[i] = swab16(fwcode[i]);
5597
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005598 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08005599 wlen);
5600 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005601 ql_log(ql_log_fatal, vha, 0x008a,
5602 "Failed to load segment %d of firmware.\n",
5603 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08005604 break;
5605 }
5606
5607 fwcode += wlen;
5608 risc_addr += wlen;
5609 risc_size -= wlen;
5610 fragment++;
5611 }
5612
5613 /* Next segment. */
5614 seg++;
5615 }
5616 return rval;
5617
5618fail_fw_integrity:
5619 return QLA_FUNCTION_FAILED;
5620}
5621
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005622static int
5623qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005624{
5625 int rval;
5626 int segments, fragment;
5627 uint32_t *dcode, dlen;
5628 uint32_t risc_addr;
5629 uint32_t risc_size;
5630 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08005631 struct fw_blob *blob;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005632 const uint32_t *fwcode;
5633 uint32_t fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005634 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005635 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005636
Andrew Vasquez54333832005-11-09 15:49:04 -08005637 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005638 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005639 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005640 ql_log(ql_log_warn, vha, 0x0090,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01005641 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005642 ql_log(ql_log_warn, vha, 0x0091,
5643 "Firmware images can be retrieved from: "
5644 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005645
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005646 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005647 }
5648
Chad Dupuiscfb09192011-11-18 09:03:07 -08005649 ql_dbg(ql_dbg_init, vha, 0x0092,
5650 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005651
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005652 rval = QLA_SUCCESS;
5653
5654 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005655 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005656 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08005657 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005658 fwclen = 0;
5659
5660 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08005661 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005662 ql_log(ql_log_fatal, vha, 0x0093,
5663 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005664 blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005665 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005666 }
5667 for (i = 0; i < 4; i++)
5668 dcode[i] = be32_to_cpu(fwcode[i + 4]);
5669 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5670 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5671 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5672 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005673 ql_log(ql_log_fatal, vha, 0x0094,
5674 "Unable to verify integrity of firmware image (%Zd).\n",
5675 blob->fw->size);
5676 ql_log(ql_log_fatal, vha, 0x0095,
5677 "Firmware data: %08x %08x %08x %08x.\n",
5678 dcode[0], dcode[1], dcode[2], dcode[3]);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005679 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005680 }
5681
5682 while (segments && rval == QLA_SUCCESS) {
5683 risc_addr = be32_to_cpu(fwcode[2]);
5684 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5685 risc_size = be32_to_cpu(fwcode[3]);
5686
5687 /* Validate firmware image size. */
5688 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08005689 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005690 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08005691 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005692 "(%Zd).\n", blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005693 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005694 }
5695
5696 fragment = 0;
5697 while (risc_size > 0 && rval == QLA_SUCCESS) {
5698 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5699 if (dlen > risc_size)
5700 dlen = risc_size;
5701
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005702 ql_dbg(ql_dbg_init, vha, 0x0097,
5703 "Loading risc segment@ risc addr %x "
5704 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005705
5706 for (i = 0; i < dlen; i++)
5707 dcode[i] = swab32(fwcode[i]);
5708
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005709 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08005710 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005711 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005712 ql_log(ql_log_fatal, vha, 0x0098,
5713 "Failed to load segment %d of firmware.\n",
5714 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04005715 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005716 }
5717
5718 fwcode += dlen;
5719 risc_addr += dlen;
5720 risc_size -= dlen;
5721 fragment++;
5722 }
5723
5724 /* Next segment. */
5725 segments--;
5726 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05005727
5728 if (!IS_QLA27XX(ha))
5729 return rval;
5730
5731 if (ha->fw_dump_template)
5732 vfree(ha->fw_dump_template);
5733 ha->fw_dump_template = NULL;
5734 ha->fw_dump_template_len = 0;
5735
5736 ql_dbg(ql_dbg_init, vha, 0x171,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005737 "Loading fwdump template from %x\n",
5738 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005739 risc_size = be32_to_cpu(fwcode[2]);
5740 ql_dbg(ql_dbg_init, vha, 0x172,
5741 "-> array size %x dwords\n", risc_size);
5742 if (risc_size == 0 || risc_size == ~0)
5743 goto default_template;
5744
5745 dlen = (risc_size - 8) * sizeof(*fwcode);
5746 ql_dbg(ql_dbg_init, vha, 0x0173,
5747 "-> template allocating %x bytes...\n", dlen);
5748 ha->fw_dump_template = vmalloc(dlen);
5749 if (!ha->fw_dump_template) {
5750 ql_log(ql_log_warn, vha, 0x0174,
5751 "Failed fwdump template allocate %x bytes.\n", risc_size);
5752 goto default_template;
5753 }
5754
5755 fwcode += 7;
5756 risc_size -= 8;
5757 dcode = ha->fw_dump_template;
5758 for (i = 0; i < risc_size; i++)
5759 dcode[i] = le32_to_cpu(fwcode[i]);
5760
5761 if (!qla27xx_fwdt_template_valid(dcode)) {
5762 ql_log(ql_log_warn, vha, 0x0175,
5763 "Failed fwdump template validate\n");
5764 goto default_template;
5765 }
5766
5767 dlen = qla27xx_fwdt_template_size(dcode);
5768 ql_dbg(ql_dbg_init, vha, 0x0176,
5769 "-> template size %x bytes\n", dlen);
5770 if (dlen > risc_size * sizeof(*fwcode)) {
5771 ql_log(ql_log_warn, vha, 0x0177,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005772 "Failed fwdump template exceeds array by %x bytes\n",
5773 (uint32_t)(dlen - risc_size * sizeof(*fwcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005774 goto default_template;
5775 }
5776 ha->fw_dump_template_len = dlen;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005777 return rval;
5778
Chad Dupuisf73cb692014-02-26 04:15:06 -05005779default_template:
5780 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
5781 if (ha->fw_dump_template)
5782 vfree(ha->fw_dump_template);
5783 ha->fw_dump_template = NULL;
5784 ha->fw_dump_template_len = 0;
5785
5786 dlen = qla27xx_fwdt_template_default_size();
5787 ql_dbg(ql_dbg_init, vha, 0x0179,
5788 "-> template allocating %x bytes...\n", dlen);
5789 ha->fw_dump_template = vmalloc(dlen);
5790 if (!ha->fw_dump_template) {
5791 ql_log(ql_log_warn, vha, 0x017a,
5792 "Failed fwdump template allocate %x bytes.\n", risc_size);
5793 goto failed_template;
5794 }
5795
5796 dcode = ha->fw_dump_template;
5797 risc_size = dlen / sizeof(*fwcode);
5798 fwcode = qla27xx_fwdt_template_default();
5799 for (i = 0; i < risc_size; i++)
5800 dcode[i] = be32_to_cpu(fwcode[i]);
5801
5802 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5803 ql_log(ql_log_warn, vha, 0x017b,
5804 "Failed fwdump template validate\n");
5805 goto failed_template;
5806 }
5807
5808 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5809 ql_dbg(ql_dbg_init, vha, 0x017c,
5810 "-> template size %x bytes\n", dlen);
5811 ha->fw_dump_template_len = dlen;
5812 return rval;
5813
5814failed_template:
5815 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
5816 if (ha->fw_dump_template)
5817 vfree(ha->fw_dump_template);
5818 ha->fw_dump_template = NULL;
5819 ha->fw_dump_template_len = 0;
5820 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005821}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005822
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005823int
5824qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5825{
5826 int rval;
5827
Andrew Vasqueze337d902009-04-06 22:33:49 -07005828 if (ql2xfwloadbin == 1)
5829 return qla81xx_load_risc(vha, srisc_addr);
5830
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005831 /*
5832 * FW Load priority:
5833 * 1) Firmware via request-firmware interface (.bin file).
5834 * 2) Firmware residing in flash.
5835 */
5836 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5837 if (rval == QLA_SUCCESS)
5838 return rval;
5839
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005840 return qla24xx_load_risc_flash(vha, srisc_addr,
5841 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005842}
5843
5844int
5845qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5846{
5847 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005848 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005849
Andrew Vasqueze337d902009-04-06 22:33:49 -07005850 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005851 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07005852
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005853 /*
5854 * FW Load priority:
5855 * 1) Firmware residing in flash.
5856 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005857 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005858 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005859 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005860 if (rval == QLA_SUCCESS)
5861 return rval;
5862
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005863try_blob_fw:
5864 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5865 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
5866 return rval;
5867
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005868 ql_log(ql_log_info, vha, 0x0099,
5869 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005870 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
5871 if (rval != QLA_SUCCESS)
5872 return rval;
5873
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005874 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005875 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005876 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005877}
5878
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005879void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005880qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005881{
5882 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005883 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005884
Andrew Vasquez85880802009-12-15 21:29:46 -08005885 if (ha->flags.pci_channel_io_perm_failure)
5886 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07005887 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005888 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07005889 if (!ha->fw_major_version)
5890 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005891
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005892 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08005893 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07005894 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005895 ha->isp_ops->reset_chip(vha);
5896 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005897 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005898 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005899 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005900 ql_log(ql_log_info, vha, 0x8015,
5901 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005902 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005903 }
5904}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005905
5906int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005907qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005908{
5909 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08005910 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005911 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005912 struct qla_hw_data *ha = vha->hw;
5913 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005914 struct req_que *req;
5915 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005916
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005917 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005918 return -EINVAL;
5919
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005920 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07005921 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005922 req = ha->req_q_map[0];
5923 else
5924 req = vha->req;
5925 rsp = req->rsp;
5926
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005927 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005928 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005929 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005930 }
5931
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005932 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005933
5934 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08005935 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
5936 BIT_1);
5937 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5938 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
5939 ql_dbg(ql_dbg_init, vha, 0x0120,
5940 "Failed SNS login: loop_id=%x, rval2=%d\n",
5941 NPH_SNS, rval2);
5942 else
5943 ql_dbg(ql_dbg_init, vha, 0x0103,
5944 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5945 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
5946 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005947 return (QLA_FUNCTION_FAILED);
5948 }
5949
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005950 atomic_set(&vha->loop_down_timer, 0);
5951 atomic_set(&vha->loop_state, LOOP_UP);
5952 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5953 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5954 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005955
5956 return rval;
5957}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005958
5959/* 84XX Support **************************************************************/
5960
5961static LIST_HEAD(qla_cs84xx_list);
5962static DEFINE_MUTEX(qla_cs84xx_mutex);
5963
5964static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005965qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005966{
5967 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005968 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005969
5970 mutex_lock(&qla_cs84xx_mutex);
5971
5972 /* Find any shared 84xx chip. */
5973 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5974 if (cs84xx->bus == ha->pdev->bus) {
5975 kref_get(&cs84xx->kref);
5976 goto done;
5977 }
5978 }
5979
5980 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5981 if (!cs84xx)
5982 goto done;
5983
5984 kref_init(&cs84xx->kref);
5985 spin_lock_init(&cs84xx->access_lock);
5986 mutex_init(&cs84xx->fw_update_mutex);
5987 cs84xx->bus = ha->pdev->bus;
5988
5989 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5990done:
5991 mutex_unlock(&qla_cs84xx_mutex);
5992 return cs84xx;
5993}
5994
5995static void
5996__qla84xx_chip_release(struct kref *kref)
5997{
5998 struct qla_chip_state_84xx *cs84xx =
5999 container_of(kref, struct qla_chip_state_84xx, kref);
6000
6001 mutex_lock(&qla_cs84xx_mutex);
6002 list_del(&cs84xx->list);
6003 mutex_unlock(&qla_cs84xx_mutex);
6004 kfree(cs84xx);
6005}
6006
6007void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006008qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006009{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006010 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006011 if (ha->cs84xx)
6012 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
6013}
6014
6015static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006016qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006017{
6018 int rval;
6019 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006020 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006021
6022 mutex_lock(&ha->cs84xx->fw_update_mutex);
6023
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006024 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006025
6026 mutex_unlock(&ha->cs84xx->fw_update_mutex);
6027
6028 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
6029 QLA_SUCCESS;
6030}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006031
6032/* 81XX Support **************************************************************/
6033
6034int
6035qla81xx_nvram_config(scsi_qla_host_t *vha)
6036{
6037 int rval;
6038 struct init_cb_81xx *icb;
6039 struct nvram_81xx *nv;
6040 uint32_t *dptr;
6041 uint8_t *dptr1, *dptr2;
6042 uint32_t chksum;
6043 uint16_t cnt;
6044 struct qla_hw_data *ha = vha->hw;
6045
6046 rval = QLA_SUCCESS;
6047 icb = (struct init_cb_81xx *)ha->init_cb;
6048 nv = ha->nvram;
6049
6050 /* Determine NVRAM starting address. */
6051 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006052 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006053 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
6054 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006055
6056 /* Get VPD data into cache */
6057 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006058 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
6059 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006060
6061 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006062 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006063 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006064 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006065 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
6066 chksum += le32_to_cpu(*dptr++);
6067
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006068 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
6069 "Contents of NVRAM:\n");
6070 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
6071 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006072
6073 /* Bad NVRAM data, set defaults parameters. */
6074 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6075 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07006076 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006077 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006078 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04006079 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006080 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006081 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006082 ql_log(ql_log_info, vha, 0x0074,
6083 "Falling back to functioning (yet invalid -- WWPN) "
6084 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006085
6086 /*
6087 * Set default initialization control block.
6088 */
6089 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07006090 nv->nvram_version = cpu_to_le16(ICB_VERSION);
6091 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04006092 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07006093 nv->execution_throttle = cpu_to_le16(0xFFFF);
6094 nv->exchange_count = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006095 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006096 nv->port_name[1] = 0x00 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006097 nv->port_name[2] = 0x00;
6098 nv->port_name[3] = 0xe0;
6099 nv->port_name[4] = 0x8b;
6100 nv->port_name[5] = 0x1c;
6101 nv->port_name[6] = 0x55;
6102 nv->port_name[7] = 0x86;
6103 nv->node_name[0] = 0x20;
6104 nv->node_name[1] = 0x00;
6105 nv->node_name[2] = 0x00;
6106 nv->node_name[3] = 0xe0;
6107 nv->node_name[4] = 0x8b;
6108 nv->node_name[5] = 0x1c;
6109 nv->node_name[6] = 0x55;
6110 nv->node_name[7] = 0x86;
Bart Van Asschead950362015-07-09 07:24:08 -07006111 nv->login_retry_count = cpu_to_le16(8);
6112 nv->interrupt_delay_timer = cpu_to_le16(0);
6113 nv->login_timeout = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006114 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07006115 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6116 nv->firmware_options_2 = cpu_to_le32(2 << 4);
6117 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6118 nv->firmware_options_3 = cpu_to_le32(2 << 13);
6119 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6120 nv->efi_parameters = cpu_to_le32(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006121 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07006122 nv->max_luns_per_target = cpu_to_le16(128);
6123 nv->port_down_retry_count = cpu_to_le16(30);
6124 nv->link_down_timeout = cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07006125 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006126 nv->enode_mac[1] = 0xC0;
6127 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006128 nv->enode_mac[3] = 0x04;
6129 nv->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006130 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006131
6132 rval = 1;
6133 }
6134
Arun Easi9e522cd2012-08-22 14:21:31 -04006135 if (IS_T10_PI_CAPABLE(ha))
6136 nv->frame_payload_size &= ~7;
6137
Arun Easiaa230bc2013-01-30 03:34:39 -05006138 qlt_81xx_config_nvram_stage1(vha, nv);
6139
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006140 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07006141 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006142
6143 /* Copy 1st segment. */
6144 dptr1 = (uint8_t *)icb;
6145 dptr2 = (uint8_t *)&nv->version;
6146 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6147 while (cnt--)
6148 *dptr1++ = *dptr2++;
6149
6150 icb->login_retry_count = nv->login_retry_count;
6151
6152 /* Copy 2nd segment. */
6153 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6154 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6155 cnt = (uint8_t *)&icb->reserved_5 -
6156 (uint8_t *)&icb->interrupt_delay_timer;
6157 while (cnt--)
6158 *dptr1++ = *dptr2++;
6159
6160 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
6161 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
6162 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08006163 icb->enode_mac[0] = 0x00;
6164 icb->enode_mac[1] = 0xC0;
6165 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006166 icb->enode_mac[3] = 0x04;
6167 icb->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006168 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006169 }
6170
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07006171 /* Use extended-initialization control block. */
6172 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
6173
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006174 /*
6175 * Setup driver NVRAM options.
6176 */
6177 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07006178 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006179
Arun Easiaa230bc2013-01-30 03:34:39 -05006180 qlt_81xx_config_nvram_stage2(vha, icb);
6181
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006182 /* Use alternate WWN? */
Bart Van Asschead950362015-07-09 07:24:08 -07006183 if (nv->host_p & cpu_to_le32(BIT_15)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006184 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6185 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6186 }
6187
6188 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07006189 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006190 /*
6191 * Firmware will apply the following mask if the nodename was
6192 * not provided.
6193 */
6194 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6195 icb->node_name[0] &= 0xF0;
6196 }
6197
6198 /* Set host adapter parameters. */
6199 ha->flags.disable_risc_code_load = 0;
6200 ha->flags.enable_lip_reset = 0;
6201 ha->flags.enable_lip_full_login =
6202 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6203 ha->flags.enable_target_reset =
6204 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
6205 ha->flags.enable_led_scheme = 0;
6206 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
6207
6208 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6209 (BIT_6 | BIT_5 | BIT_4)) >> 4;
6210
6211 /* save HBA serial number */
6212 ha->serial0 = icb->port_name[5];
6213 ha->serial1 = icb->port_name[6];
6214 ha->serial2 = icb->port_name[7];
6215 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6216 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
6217
Bart Van Asschead950362015-07-09 07:24:08 -07006218 icb->execution_throttle = cpu_to_le16(0xFFFF);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006219
6220 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6221
6222 /* Set minimum login_timeout to 4 seconds. */
6223 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6224 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6225 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07006226 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006227 ha->login_timeout = le16_to_cpu(nv->login_timeout);
6228 icb->login_timeout = nv->login_timeout;
6229
6230 /* Set minimum RATOV to 100 tenths of a second. */
6231 ha->r_a_tov = 100;
6232
6233 ha->loop_reset_delay = nv->reset_delay;
6234
6235 /* Link Down Timeout = 0:
6236 *
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006237 * When Port Down timer expires we will start returning
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006238 * I/O's to OS with "DID_NO_CONNECT".
6239 *
6240 * Link Down Timeout != 0:
6241 *
6242 * The driver waits for the link to come up after link down
6243 * before returning I/Os to OS with "DID_NO_CONNECT".
6244 */
6245 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6246 ha->loop_down_abort_time =
6247 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6248 } else {
6249 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6250 ha->loop_down_abort_time =
6251 (LOOP_DOWN_TIME - ha->link_down_timeout);
6252 }
6253
6254 /* Need enough time to try and get the port back. */
6255 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6256 if (qlport_down_retry)
6257 ha->port_down_retry_count = qlport_down_retry;
6258
6259 /* Set login_retry_count */
6260 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6261 if (ha->port_down_retry_count ==
6262 le16_to_cpu(nv->port_down_retry_count) &&
6263 ha->port_down_retry_count > 3)
6264 ha->login_retry_count = ha->port_down_retry_count;
6265 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6266 ha->login_retry_count = ha->port_down_retry_count;
6267 if (ql2xloginretrycount)
6268 ha->login_retry_count = ql2xloginretrycount;
6269
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006270 /* if not running MSI-X we need handshaking on interrupts */
Chad Dupuisf73cb692014-02-26 04:15:06 -05006271 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
Bart Van Asschead950362015-07-09 07:24:08 -07006272 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006273
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006274 /* Enable ZIO. */
6275 if (!vha->flags.init_done) {
6276 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6277 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6278 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6279 le16_to_cpu(icb->interrupt_delay_timer): 2;
6280 }
Bart Van Asschead950362015-07-09 07:24:08 -07006281 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006282 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
6283 vha->flags.process_response_queue = 0;
6284 if (ha->zio_mode != QLA_ZIO_DISABLED) {
6285 ha->zio_mode = QLA_ZIO_MODE_6;
6286
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006287 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006288 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006289 ha->zio_mode,
6290 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006291
6292 icb->firmware_options_2 |= cpu_to_le32(
6293 (uint32_t)ha->zio_mode);
6294 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
6295 vha->flags.process_response_queue = 1;
6296 }
6297
6298 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006299 ql_log(ql_log_warn, vha, 0x0076,
6300 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006301 }
6302 return (rval);
6303}
6304
Giridhar Malavalia9083012010-04-12 17:59:55 -07006305int
6306qla82xx_restart_isp(scsi_qla_host_t *vha)
6307{
6308 int status, rval;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006309 struct qla_hw_data *ha = vha->hw;
6310 struct req_que *req = ha->req_q_map[0];
6311 struct rsp_que *rsp = ha->rsp_q_map[0];
6312 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07006313 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006314
6315 status = qla2x00_init_rings(vha);
6316 if (!status) {
6317 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6318 ha->flags.chip_reset_done = 1;
6319
6320 status = qla2x00_fw_ready(vha);
6321 if (!status) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07006322 /* Issue a marker after FW becomes ready. */
6323 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006324 vha->flags.online = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04006325 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006326 }
6327
6328 /* if no cable then assume it's good */
6329 if ((vha->device_flags & DFLG_NO_CABLE))
6330 status = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006331 }
6332
6333 if (!status) {
6334 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6335
6336 if (!atomic_read(&vha->loop_down_timer)) {
6337 /*
6338 * Issue marker command only when we are going
6339 * to start the I/O .
6340 */
6341 vha->marker_needed = 1;
6342 }
6343
Giridhar Malavalia9083012010-04-12 17:59:55 -07006344 ha->isp_ops->enable_intrs(ha);
6345
6346 ha->isp_abort_cnt = 0;
6347 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6348
Saurav Kashyap53296782011-05-10 11:30:06 -07006349 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07006350 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07006351
Giridhar Malavalia9083012010-04-12 17:59:55 -07006352 if (ha->fce) {
6353 ha->flags.fce_enabled = 1;
6354 memset(ha->fce, 0,
6355 fce_calc_size(ha->fce_bufs));
6356 rval = qla2x00_enable_fce_trace(vha,
6357 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6358 &ha->fce_bufs);
6359 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006360 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006361 "Unable to reinitialize FCE (%d).\n",
6362 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006363 ha->flags.fce_enabled = 0;
6364 }
6365 }
6366
6367 if (ha->eft) {
6368 memset(ha->eft, 0, EFT_SIZE);
6369 rval = qla2x00_enable_eft_trace(vha,
6370 ha->eft_dma, EFT_NUM_BUFFERS);
6371 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006372 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006373 "Unable to reinitialize EFT (%d).\n",
6374 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006375 }
6376 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006377 }
6378
6379 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006380 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006381 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07006382
6383 spin_lock_irqsave(&ha->vport_slock, flags);
6384 list_for_each_entry(vp, &ha->vp_list, list) {
6385 if (vp->vp_idx) {
6386 atomic_inc(&vp->vref_count);
6387 spin_unlock_irqrestore(&ha->vport_slock, flags);
6388
Giridhar Malavalia9083012010-04-12 17:59:55 -07006389 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07006390
6391 spin_lock_irqsave(&ha->vport_slock, flags);
6392 atomic_dec(&vp->vref_count);
6393 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006394 }
Arun Easifeafb7b2010-09-03 14:57:00 -07006395 spin_unlock_irqrestore(&ha->vport_slock, flags);
6396
Giridhar Malavalia9083012010-04-12 17:59:55 -07006397 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006398 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006399 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006400 }
6401
6402 return status;
6403}
6404
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006405void
Andrew Vasquezae97c912010-02-18 10:07:28 -08006406qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006407{
Andrew Vasquezae97c912010-02-18 10:07:28 -08006408 struct qla_hw_data *ha = vha->hw;
6409
6410 if (!ql2xetsenable)
6411 return;
6412
6413 /* Enable ETS Burst. */
6414 memset(ha->fw_options, 0, sizeof(ha->fw_options));
6415 ha->fw_options[2] |= BIT_9;
6416 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006417}
Sarang Radke09ff7012010-03-19 17:03:59 -07006418
6419/*
6420 * qla24xx_get_fcp_prio
6421 * Gets the fcp cmd priority value for the logged in port.
6422 * Looks for a match of the port descriptors within
6423 * each of the fcp prio config entries. If a match is found,
6424 * the tag (priority) value is returned.
6425 *
6426 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006427 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07006428 * fcport = port structure pointer.
6429 *
6430 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07006431 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006432 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07006433 *
6434 * Context:
6435 * Kernel context
6436 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006437static int
Sarang Radke09ff7012010-03-19 17:03:59 -07006438qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
6439{
6440 int i, entries;
6441 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006442 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07006443 uint32_t pid1, pid2;
6444 uint64_t wwn1, wwn2;
6445 struct qla_fcp_prio_entry *pri_entry;
6446 struct qla_hw_data *ha = vha->hw;
6447
6448 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006449 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07006450
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006451 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07006452 entries = ha->fcp_prio_cfg->num_entries;
6453 pri_entry = &ha->fcp_prio_cfg->entry[0];
6454
6455 for (i = 0; i < entries; i++) {
6456 pid_match = wwn_match = 0;
6457
6458 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
6459 pri_entry++;
6460 continue;
6461 }
6462
6463 /* check source pid for a match */
6464 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
6465 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
6466 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
6467 if (pid1 == INVALID_PORT_ID)
6468 pid_match++;
6469 else if (pid1 == pid2)
6470 pid_match++;
6471 }
6472
6473 /* check destination pid for a match */
6474 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
6475 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
6476 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
6477 if (pid1 == INVALID_PORT_ID)
6478 pid_match++;
6479 else if (pid1 == pid2)
6480 pid_match++;
6481 }
6482
6483 /* check source WWN for a match */
6484 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
6485 wwn1 = wwn_to_u64(vha->port_name);
6486 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
6487 if (wwn2 == (uint64_t)-1)
6488 wwn_match++;
6489 else if (wwn1 == wwn2)
6490 wwn_match++;
6491 }
6492
6493 /* check destination WWN for a match */
6494 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
6495 wwn1 = wwn_to_u64(fcport->port_name);
6496 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
6497 if (wwn2 == (uint64_t)-1)
6498 wwn_match++;
6499 else if (wwn1 == wwn2)
6500 wwn_match++;
6501 }
6502
6503 if (pid_match == 2 || wwn_match == 2) {
6504 /* Found a matching entry */
6505 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
6506 priority = pri_entry->tag;
6507 break;
6508 }
6509
6510 pri_entry++;
6511 }
6512
6513 return priority;
6514}
6515
6516/*
6517 * qla24xx_update_fcport_fcp_prio
6518 * Activates fcp priority for the logged in fc port
6519 *
6520 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006521 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07006522 * fcp = port structure pointer.
6523 *
6524 * Return:
6525 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6526 *
6527 * Context:
6528 * Kernel context.
6529 */
6530int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006531qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07006532{
6533 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006534 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07006535 uint16_t mb[5];
6536
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006537 if (fcport->port_type != FCT_TARGET ||
6538 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07006539 return QLA_FUNCTION_FAILED;
6540
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006541 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006542 if (priority < 0)
6543 return QLA_FUNCTION_FAILED;
6544
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006545 if (IS_P3P_TYPE(vha->hw)) {
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006546 fcport->fcp_prio = priority & 0xf;
6547 return QLA_SUCCESS;
6548 }
6549
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006550 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08006551 if (ret == QLA_SUCCESS) {
6552 if (fcport->fcp_prio != priority)
6553 ql_dbg(ql_dbg_user, vha, 0x709e,
6554 "Updated FCP_CMND priority - value=%d loop_id=%d "
6555 "port_id=%02x%02x%02x.\n", priority,
6556 fcport->loop_id, fcport->d_id.b.domain,
6557 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006558 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08006559 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006560 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006561 "Unable to update FCP_CMND priority - ret=0x%x for "
6562 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
6563 fcport->d_id.b.domain, fcport->d_id.b.area,
6564 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07006565 return ret;
6566}
6567
6568/*
6569 * qla24xx_update_all_fcp_prio
6570 * Activates fcp priority for all the logged in ports
6571 *
6572 * Input:
6573 * ha = adapter block pointer.
6574 *
6575 * Return:
6576 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6577 *
6578 * Context:
6579 * Kernel context.
6580 */
6581int
6582qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
6583{
6584 int ret;
6585 fc_port_t *fcport;
6586
6587 ret = QLA_FUNCTION_FAILED;
6588 /* We need to set priority for all logged in ports */
6589 list_for_each_entry(fcport, &vha->vp_fcports, list)
6590 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
6591
6592 return ret;
6593}