blob: a4dde7e80dbdb539c78367e3238d1352047b509b [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);
118 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700119}
120
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700121static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800122qla2x00_async_login_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700123{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800124 srb_t *sp = (srb_t *)ptr;
125 struct srb_iocb *lio = &sp->u.iocb_cmd;
126 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700127
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800128 if (!test_bit(UNLOADING, &vha->dpc_flags))
129 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
130 lio->u.logio.data);
131 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700132}
133
Andrew Vasquezac280b62009-08-20 11:06:05 -0700134int
135qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
136 uint16_t *data)
137{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700138 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700139 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700140 int rval;
141
142 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800143 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700144 if (!sp)
145 goto done;
146
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800147 sp->type = SRB_LOGIN_CMD;
148 sp->name = "login";
149 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
150
151 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700152 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800153 sp->done = qla2x00_async_login_sp_done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700154 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700155 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700156 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700157 rval = qla2x00_start_sp(sp);
158 if (rval != QLA_SUCCESS)
159 goto done_free_sp;
160
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700161 ql_dbg(ql_dbg_disc, vha, 0x2072,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800162 "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
163 "retries=%d.\n", sp->handle, fcport->loop_id,
164 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
165 fcport->login_retry);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700166 return rval;
167
168done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800169 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700170done:
171 return rval;
172}
173
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700174static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800175qla2x00_async_logout_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700176{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800177 srb_t *sp = (srb_t *)ptr;
178 struct srb_iocb *lio = &sp->u.iocb_cmd;
179 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700180
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800181 if (!test_bit(UNLOADING, &vha->dpc_flags))
182 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
183 lio->u.logio.data);
184 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700185}
186
Andrew Vasquezac280b62009-08-20 11:06:05 -0700187int
188qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
189{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700190 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700191 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700192 int rval;
193
194 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800195 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700196 if (!sp)
197 goto done;
198
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800199 sp->type = SRB_LOGOUT_CMD;
200 sp->name = "logout";
201 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
202
203 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700204 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800205 sp->done = qla2x00_async_logout_sp_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700206 rval = qla2x00_start_sp(sp);
207 if (rval != QLA_SUCCESS)
208 goto done_free_sp;
209
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700210 ql_dbg(ql_dbg_disc, vha, 0x2070,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800211 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
212 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
213 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700214 return rval;
215
216done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800217 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700218done:
219 return rval;
220}
221
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700222static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800223qla2x00_async_adisc_sp_done(void *data, void *ptr, int res)
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700224{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800225 srb_t *sp = (srb_t *)ptr;
226 struct srb_iocb *lio = &sp->u.iocb_cmd;
227 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700228
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800229 if (!test_bit(UNLOADING, &vha->dpc_flags))
230 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
231 lio->u.logio.data);
232 sp->free(sp->fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700233}
234
235int
236qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
237 uint16_t *data)
238{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700239 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700240 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700241 int rval;
242
243 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800244 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700245 if (!sp)
246 goto done;
247
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800248 sp->type = SRB_ADISC_CMD;
249 sp->name = "adisc";
250 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
251
252 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700253 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800254 sp->done = qla2x00_async_adisc_sp_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700255 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700256 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700257 rval = qla2x00_start_sp(sp);
258 if (rval != QLA_SUCCESS)
259 goto done_free_sp;
260
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700261 ql_dbg(ql_dbg_disc, vha, 0x206f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800262 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
263 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
264 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700265 return rval;
266
267done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800268 sp->free(fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700269done:
270 return rval;
271}
272
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700273static void
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500274qla2x00_tmf_iocb_timeout(void *data)
275{
276 srb_t *sp = (srb_t *)data;
277 struct srb_iocb *tmf = &sp->u.iocb_cmd;
278
279 tmf->u.tmf.comp_status = CS_TIMEOUT;
280 complete(&tmf->u.tmf.comp);
281}
282
283static void
284qla2x00_tmf_sp_done(void *data, void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700285{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800286 srb_t *sp = (srb_t *)ptr;
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500287 struct srb_iocb *tmf = &sp->u.iocb_cmd;
288 complete(&tmf->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700289}
290
291int
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500292qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700293 uint32_t tag)
294{
295 struct scsi_qla_host *vha = fcport->vha;
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500296 struct srb_iocb *tm_iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700297 srb_t *sp;
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500298 int rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700299
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800300 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700301 if (!sp)
302 goto done;
303
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500304 tm_iocb = &sp->u.iocb_cmd;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800305 sp->type = SRB_TM_CMD;
306 sp->name = "tmf";
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500307 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
308 tm_iocb->u.tmf.flags = flags;
309 tm_iocb->u.tmf.lun = lun;
310 tm_iocb->u.tmf.data = tag;
311 sp->done = qla2x00_tmf_sp_done;
312 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
313 init_completion(&tm_iocb->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700314
315 rval = qla2x00_start_sp(sp);
316 if (rval != QLA_SUCCESS)
317 goto done_free_sp;
318
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700319 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800320 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
321 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
322 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500323
324 wait_for_completion(&tm_iocb->u.tmf.comp);
325
326 rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
327 QLA_SUCCESS : QLA_FUNCTION_FAILED;
328
329 if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
330 ql_dbg(ql_dbg_taskm, vha, 0x8030,
331 "TM IOCB failed (%x).\n", rval);
332 }
333
334 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
335 flags = tm_iocb->u.tmf.flags;
336 lun = (uint16_t)tm_iocb->u.tmf.lun;
337
338 /* Issue Marker IOCB */
339 qla2x00_marker(vha, vha->hw->req_q_map[0],
340 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
341 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
342 }
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700343
344done_free_sp:
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500345 sp->free(vha, sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700346done:
347 return rval;
348}
349
Armen Baloyan4440e462014-02-26 04:15:18 -0500350static void
351qla24xx_abort_iocb_timeout(void *data)
352{
353 srb_t *sp = (srb_t *)data;
354 struct srb_iocb *abt = &sp->u.iocb_cmd;
355
356 abt->u.abt.comp_status = CS_TIMEOUT;
357 complete(&abt->u.abt.comp);
358}
359
360static void
361qla24xx_abort_sp_done(void *data, void *ptr, int res)
362{
363 srb_t *sp = (srb_t *)ptr;
364 struct srb_iocb *abt = &sp->u.iocb_cmd;
365
366 complete(&abt->u.abt.comp);
367}
368
369static int
370qla24xx_async_abort_cmd(srb_t *cmd_sp)
371{
372 scsi_qla_host_t *vha = cmd_sp->fcport->vha;
373 fc_port_t *fcport = cmd_sp->fcport;
374 struct srb_iocb *abt_iocb;
375 srb_t *sp;
376 int rval = QLA_FUNCTION_FAILED;
377
378 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
379 if (!sp)
380 goto done;
381
382 abt_iocb = &sp->u.iocb_cmd;
383 sp->type = SRB_ABT_CMD;
384 sp->name = "abort";
385 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
386 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
387 sp->done = qla24xx_abort_sp_done;
388 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
389 init_completion(&abt_iocb->u.abt.comp);
390
391 rval = qla2x00_start_sp(sp);
392 if (rval != QLA_SUCCESS)
393 goto done_free_sp;
394
395 ql_dbg(ql_dbg_async, vha, 0x507c,
396 "Abort command issued - hdl=%x, target_id=%x\n",
397 cmd_sp->handle, fcport->tgt_id);
398
399 wait_for_completion(&abt_iocb->u.abt.comp);
400
401 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
402 QLA_SUCCESS : QLA_FUNCTION_FAILED;
403
404done_free_sp:
405 sp->free(vha, sp);
406done:
407 return rval;
408}
409
410int
411qla24xx_async_abort_command(srb_t *sp)
412{
413 unsigned long flags = 0;
414
415 uint32_t handle;
416 fc_port_t *fcport = sp->fcport;
417 struct scsi_qla_host *vha = fcport->vha;
418 struct qla_hw_data *ha = vha->hw;
419 struct req_que *req = vha->req;
420
421 spin_lock_irqsave(&ha->hardware_lock, flags);
422 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
423 if (req->outstanding_cmds[handle] == sp)
424 break;
425 }
426 spin_unlock_irqrestore(&ha->hardware_lock, flags);
427 if (handle == req->num_outstanding_cmds) {
428 /* Command not found. */
429 return QLA_FUNCTION_FAILED;
430 }
431 if (sp->type == SRB_FXIOCB_DCMD)
432 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
433 FXDISC_ABORT_IOCTL);
434
435 return qla24xx_async_abort_cmd(sp);
436}
437
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700438void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700439qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
440 uint16_t *data)
441{
442 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700443
444 switch (data[0]) {
445 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700446 /*
447 * Driver must validate login state - If PRLI not complete,
448 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
449 * requests.
450 */
451 rval = qla2x00_get_port_database(vha, fcport, 0);
Arun Easi0eba25d2012-02-09 11:15:58 -0800452 if (rval == QLA_NOT_LOGGED_IN) {
453 fcport->flags &= ~FCF_ASYNC_SENT;
454 fcport->flags |= FCF_LOGIN_NEEDED;
455 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
456 break;
457 }
458
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700459 if (rval != QLA_SUCCESS) {
460 qla2x00_post_async_logout_work(vha, fcport, NULL);
461 qla2x00_post_async_login_work(vha, fcport, NULL);
462 break;
463 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700464 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700465 qla2x00_post_async_adisc_work(vha, fcport, data);
466 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700467 }
468 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700469 break;
470 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700471 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700472 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
473 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
474 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700475 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700476 break;
477 case MBS_PORT_ID_USED:
478 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700479 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700480 qla2x00_post_async_login_work(vha, fcport, NULL);
481 break;
482 case MBS_LOOP_ID_USED:
483 fcport->loop_id++;
484 rval = qla2x00_find_new_loop_id(vha, fcport);
485 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700486 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez80d79442011-03-30 11:46:17 -0700487 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700488 break;
489 }
490 qla2x00_post_async_login_work(vha, fcport, NULL);
491 break;
492 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700493 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700494}
495
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700496void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700497qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
498 uint16_t *data)
499{
500 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700501 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700502}
503
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700504void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700505qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
506 uint16_t *data)
507{
508 if (data[0] == MBS_COMMAND_COMPLETE) {
509 qla2x00_update_fcport(vha, fcport);
510
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700511 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700512 }
513
514 /* Retry login. */
515 fcport->flags &= ~FCF_ASYNC_SENT;
516 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
517 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
518 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700519 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700520
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700521 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700522}
523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524/****************************************************************************/
525/* QLogic ISP2x00 Hardware Support Functions. */
526/****************************************************************************/
527
Saurav Kashyapfa492632012-11-21 02:40:29 -0500528static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400529qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
530{
531 int rval = QLA_SUCCESS;
532 struct qla_hw_data *ha = vha->hw;
533 uint32_t idc_major_ver, idc_minor_ver;
Saurav Kashyap711aa7f2012-08-22 14:21:15 -0400534 uint16_t config[4];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400535
536 qla83xx_idc_lock(vha, 0);
537
538 /* SV: TODO: Assign initialization timeout from
539 * flash-info / other param
540 */
541 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
542 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
543
544 /* Set our fcoe function presence */
545 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
546 ql_dbg(ql_dbg_p3p, vha, 0xb077,
547 "Error while setting DRV-Presence.\n");
548 rval = QLA_FUNCTION_FAILED;
549 goto exit;
550 }
551
552 /* Decide the reset ownership */
553 qla83xx_reset_ownership(vha);
554
555 /*
556 * On first protocol driver load:
557 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
558 * register.
559 * Others: Check compatibility with current IDC Major version.
560 */
561 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
562 if (ha->flags.nic_core_reset_owner) {
563 /* Set IDC Major version */
564 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
565 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
566
567 /* Clearing IDC-Lock-Recovery register */
568 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
569 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
570 /*
571 * Clear further IDC participation if we are not compatible with
572 * the current IDC Major Version.
573 */
574 ql_log(ql_log_warn, vha, 0xb07d,
575 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
576 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
577 __qla83xx_clear_drv_presence(vha);
578 rval = QLA_FUNCTION_FAILED;
579 goto exit;
580 }
581 /* Each function sets its supported Minor version. */
582 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
583 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
584 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
585
Saurav Kashyap711aa7f2012-08-22 14:21:15 -0400586 if (ha->flags.nic_core_reset_owner) {
587 memset(config, 0, sizeof(config));
588 if (!qla81xx_get_port_config(vha, config))
589 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
590 QLA8XXX_DEV_READY);
591 }
592
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400593 rval = qla83xx_idc_state_handler(vha);
594
595exit:
596 qla83xx_idc_unlock(vha, 0);
597
598 return rval;
599}
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601/*
602* qla2x00_initialize_adapter
603* Initialize board.
604*
605* Input:
606* ha = adapter block pointer.
607*
608* Returns:
609* 0 = success
610*/
611int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800612qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
614 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800615 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800616 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800619 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700620 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800621 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800622 ha->flags.pci_channel_io_perm_failure = 0;
623 ha->flags.eeh_busy = 0;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -0400624 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800625 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
626 atomic_set(&vha->loop_state, LOOP_DOWN);
627 vha->device_flags = DFLG_NO_CABLE;
628 vha->dpc_flags = 0;
629 vha->flags.management_server_logged_in = 0;
630 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 ha->isp_abort_cnt = 0;
632 ha->beacon_blink_led = 0;
633
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800634 set_bit(0, ha->req_qid_map);
635 set_bit(0, ha->rsp_qid_map);
636
Chad Dupuiscfb09192011-11-18 09:03:07 -0800637 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700638 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800639 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700641 ql_log(ql_log_warn, vha, 0x0044,
642 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 return (rval);
644 }
645
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800646 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800648 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700649 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700650 ql_log(ql_log_fatal, vha, 0x004f,
651 "Unable to validate FLASH data.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400652 return rval;
653 }
654
655 if (IS_QLA8044(ha)) {
656 qla8044_read_reset_template(vha);
657
658 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
659 * If DONRESET_BIT0 is set, drivers should not set dev_state
660 * to NEED_RESET. But if NEED_RESET is set, drivers should
661 * should honor the reset. */
662 if (ql2xdontresethba == 1)
663 qla8044_set_idc_dontreset(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700664 }
665
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800666 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -0800667 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700668 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700669
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800670 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700672 if (ha->flags.disable_serdes) {
673 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700674 ql_log(ql_log_info, vha, 0x0077,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -0400675 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700676 return QLA_FUNCTION_FAILED;
677 }
678
Chad Dupuiscfb09192011-11-18 09:03:07 -0800679 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700680 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800682 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
683 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800684 if (rval)
685 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800686 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800687 if (rval)
688 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700690
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700691 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800692 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700693 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700694 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700695 "Unable to configure ISP84XX.\n");
696 return QLA_FUNCTION_FAILED;
697 }
698 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400699
700 if (qla_ini_mode_enabled(vha))
701 rval = qla2x00_init_rings(vha);
702
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700703 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800705 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700706 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800707 rval = qla84xx_init_chip(vha);
708 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700709 ql_log(ql_log_warn, vha, 0x00d4,
710 "Unable to initialize ISP84XX.\n");
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800711 qla84xx_put_chip(vha);
712 }
713 }
714
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400715 /* Load the NIC Core f/w if we are the first protocol driver. */
716 if (IS_QLA8031(ha)) {
717 rval = qla83xx_nic_core_fw_load(vha);
718 if (rval)
719 ql_log(ql_log_warn, vha, 0x0124,
720 "Error in initializing NIC Core f/w.\n");
721 }
722
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500723 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
724 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700725
Joe Carnuccioc46e65c2013-08-27 01:37:35 -0400726 if (IS_P3P_TYPE(ha))
727 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
728 else
729 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 return (rval);
732}
733
734/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700735 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 * @ha: HA context
737 *
738 * Returns 0 on success.
739 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700740int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800741qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700743 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700744 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800745 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700746 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700749 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700752 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
754
Andrew Vasquez737faec2008-10-24 15:13:45 -0700755 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700757 /* Get PCI bus information. */
758 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700759 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700760 spin_unlock_irqrestore(&ha->hardware_lock, flags);
761
762 return QLA_SUCCESS;
763}
764
765/**
766 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
767 * @ha: HA context
768 *
769 * Returns 0 on success.
770 */
771int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800772qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700773{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700774 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700775 unsigned long flags = 0;
776 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800777 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700778 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700779
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700780 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700781 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700782
783 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700784 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700785
786 if (IS_QLA2322(ha) || IS_QLA6322(ha))
787 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700788 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700789
790 /*
791 * If this is a 2300 card and not 2312, reset the
792 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
793 * the 2310 also reports itself as a 2300 so we need to get the
794 * fb revision level -- a 6 indicates it really is a 2300 and
795 * not a 2310.
796 */
797 if (IS_QLA2300(ha)) {
798 spin_lock_irqsave(&ha->hardware_lock, flags);
799
800 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700801 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700802 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700803 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700804 break;
805
806 udelay(10);
807 }
808
809 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700810 WRT_REG_WORD(&reg->ctrl_status, 0x20);
811 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700812
813 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700814 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700815
816 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700817 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700818
819 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700820 WRT_REG_WORD(&reg->ctrl_status, 0x0);
821 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700822
823 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700824 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700825 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700826 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700827 break;
828
829 udelay(10);
830 }
831
832 spin_unlock_irqrestore(&ha->hardware_lock, flags);
833 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700834
835 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
836
Andrew Vasquez737faec2008-10-24 15:13:45 -0700837 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700838
839 /* Get PCI bus information. */
840 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700841 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700842 spin_unlock_irqrestore(&ha->hardware_lock, flags);
843
844 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845}
846
847/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700848 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
849 * @ha: HA context
850 *
851 * Returns 0 on success.
852 */
853int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800854qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700855{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700856 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700857 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800858 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700859 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700860
861 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700862 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700863
864 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700865 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700866 w &= ~PCI_COMMAND_INTX_DISABLE;
867 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
868
869 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
870
871 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700872 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
873 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700874
875 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700876 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -0400877 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700878
Andrew Vasquez737faec2008-10-24 15:13:45 -0700879 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700880
Auke Kok44c10132007-06-08 15:46:36 -0700881 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800882
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700883 /* Get PCI bus information. */
884 spin_lock_irqsave(&ha->hardware_lock, flags);
885 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
886 spin_unlock_irqrestore(&ha->hardware_lock, flags);
887
888 return QLA_SUCCESS;
889}
890
891/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700892 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
893 * @ha: HA context
894 *
895 * Returns 0 on success.
896 */
897int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800898qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700899{
900 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800901 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700902
903 pci_set_master(ha->pdev);
904 pci_try_set_mwi(ha->pdev);
905
906 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
907 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
908 w &= ~PCI_COMMAND_INTX_DISABLE;
909 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
910
911 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700912 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -0400913 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700914
Andrew Vasquez737faec2008-10-24 15:13:45 -0700915 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700916
917 ha->chip_revision = ha->pdev->revision;
918
919 return QLA_SUCCESS;
920}
921
922/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 * qla2x00_isp_firmware() - Choose firmware image.
924 * @ha: HA context
925 *
926 * Returns 0 on success.
927 */
928static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800929qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930{
931 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700932 uint16_t loop_id, topo, sw_cap;
933 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800934 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
936 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700937 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
939 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700940 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
942 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800943 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700944 if (rval == QLA_SUCCESS) {
945 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800946 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700947 &area, &domain, &topo, &sw_cap);
948 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 }
950
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700951 if (rval)
952 ql_dbg(ql_dbg_init, vha, 0x007a,
953 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
955 return (rval);
956}
957
958/**
959 * qla2x00_reset_chip() - Reset ISP chip.
960 * @ha: HA context
961 *
962 * Returns 0 on success.
963 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700964void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800965qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
967 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800968 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700969 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 uint16_t cmd;
972
Andrew Vasquez85880802009-12-15 21:29:46 -0800973 if (unlikely(pci_channel_offline(ha->pdev)))
974 return;
975
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700976 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
978 spin_lock_irqsave(&ha->hardware_lock, flags);
979
980 /* Turn off master enable */
981 cmd = 0;
982 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
983 cmd &= ~PCI_COMMAND_MASTER;
984 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
985
986 if (!IS_QLA2100(ha)) {
987 /* Pause RISC. */
988 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
989 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
990 for (cnt = 0; cnt < 30000; cnt++) {
991 if ((RD_REG_WORD(&reg->hccr) &
992 HCCR_RISC_PAUSE) != 0)
993 break;
994 udelay(100);
995 }
996 } else {
997 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
998 udelay(10);
999 }
1000
1001 /* Select FPM registers. */
1002 WRT_REG_WORD(&reg->ctrl_status, 0x20);
1003 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1004
1005 /* FPM Soft Reset. */
1006 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
1007 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
1008
1009 /* Toggle Fpm Reset. */
1010 if (!IS_QLA2200(ha)) {
1011 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
1012 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
1013 }
1014
1015 /* Select frame buffer registers. */
1016 WRT_REG_WORD(&reg->ctrl_status, 0x10);
1017 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1018
1019 /* Reset frame buffer FIFOs. */
1020 if (IS_QLA2200(ha)) {
1021 WRT_FB_CMD_REG(ha, reg, 0xa000);
1022 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
1023 } else {
1024 WRT_FB_CMD_REG(ha, reg, 0x00fc);
1025
1026 /* Read back fb_cmd until zero or 3 seconds max */
1027 for (cnt = 0; cnt < 3000; cnt++) {
1028 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
1029 break;
1030 udelay(100);
1031 }
1032 }
1033
1034 /* Select RISC module registers. */
1035 WRT_REG_WORD(&reg->ctrl_status, 0);
1036 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1037
1038 /* Reset RISC processor. */
1039 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1040 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1041
1042 /* Release RISC processor. */
1043 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1044 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1045 }
1046
1047 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
1048 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
1049
1050 /* Reset ISP chip. */
1051 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1052
1053 /* Wait for RISC to recover from reset. */
1054 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1055 /*
1056 * It is necessary to for a delay here since the card doesn't
1057 * respond to PCI reads during a reset. On some architectures
1058 * this will result in an MCA.
1059 */
1060 udelay(20);
1061 for (cnt = 30000; cnt; cnt--) {
1062 if ((RD_REG_WORD(&reg->ctrl_status) &
1063 CSR_ISP_SOFT_RESET) == 0)
1064 break;
1065 udelay(100);
1066 }
1067 } else
1068 udelay(10);
1069
1070 /* Reset RISC processor. */
1071 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1072
1073 WRT_REG_WORD(&reg->semaphore, 0);
1074
1075 /* Release RISC processor. */
1076 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1077 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1078
1079 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1080 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -07001081 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
1084 udelay(100);
1085 }
1086 } else
1087 udelay(100);
1088
1089 /* Turn on master enable */
1090 cmd |= PCI_COMMAND_MASTER;
1091 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
1092
1093 /* Disable RISC pause on FPM parity error. */
1094 if (!IS_QLA2100(ha)) {
1095 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
1096 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1097 }
1098
1099 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1100}
1101
1102/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001103 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
1104 *
1105 * Returns 0 on success.
1106 */
Saurav Kashyapfa492632012-11-21 02:40:29 -05001107static int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001108qla81xx_reset_mpi(scsi_qla_host_t *vha)
1109{
1110 uint16_t mb[4] = {0x1010, 0, 1, 0};
1111
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001112 if (!IS_QLA81XX(vha->hw))
1113 return QLA_SUCCESS;
1114
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001115 return qla81xx_write_mpi_register(vha, mb);
1116}
1117
1118/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001119 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001120 * @ha: HA context
1121 *
1122 * Returns 0 on success.
1123 */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001124static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001125qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001126{
1127 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001128 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001129 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1130 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001131 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001132 static int abts_cnt; /* ISP abort retry counts */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001133
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001134 spin_lock_irqsave(&ha->hardware_lock, flags);
1135
1136 /* Reset RISC. */
1137 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1138 for (cnt = 0; cnt < 30000; cnt++) {
1139 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
1140 break;
1141
1142 udelay(10);
1143 }
1144
1145 WRT_REG_DWORD(&reg->ctrl_status,
1146 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001147 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001148
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001149 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001150 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001151 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1152 for (cnt = 10000 ; cnt && d2; cnt--) {
1153 udelay(5);
1154 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1155 barrier();
1156 }
1157
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001158 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001159 d2 = RD_REG_DWORD(&reg->ctrl_status);
1160 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1161 udelay(5);
1162 d2 = RD_REG_DWORD(&reg->ctrl_status);
1163 barrier();
1164 }
1165
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001166 /* If required, do an MPI FW reset now */
1167 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1168 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1169 if (++abts_cnt < 5) {
1170 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1171 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1172 } else {
1173 /*
1174 * We exhausted the ISP abort retries. We have to
1175 * set the board offline.
1176 */
1177 abts_cnt = 0;
1178 vha->flags.online = 0;
1179 }
1180 }
1181 }
1182
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001183 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1184 RD_REG_DWORD(&reg->hccr);
1185
1186 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1187 RD_REG_DWORD(&reg->hccr);
1188
1189 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1190 RD_REG_DWORD(&reg->hccr);
1191
1192 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1193 for (cnt = 6000000 ; cnt && d2; cnt--) {
1194 udelay(5);
1195 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1196 barrier();
1197 }
1198
1199 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001200
1201 if (IS_NOPOLLING_TYPE(ha))
1202 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001203}
1204
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001205static void
1206qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
1207{
1208 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1209
1210 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1211 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
1212
1213}
1214
1215static void
1216qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
1217{
1218 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1219
1220 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1221 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
1222}
1223
1224static void
1225qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
1226{
1227 struct qla_hw_data *ha = vha->hw;
1228 uint32_t wd32 = 0;
1229 uint delta_msec = 100;
1230 uint elapsed_msec = 0;
1231 uint timeout_msec;
1232 ulong n;
1233
1234 if (!IS_QLA25XX(ha) && !IS_QLA2031(ha))
1235 return;
1236
1237attempt:
1238 timeout_msec = TIMEOUT_SEMAPHORE;
1239 n = timeout_msec / delta_msec;
1240 while (n--) {
1241 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
1242 qla25xx_read_risc_sema_reg(vha, &wd32);
1243 if (wd32 & RISC_SEMAPHORE)
1244 break;
1245 msleep(delta_msec);
1246 elapsed_msec += delta_msec;
1247 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1248 goto force;
1249 }
1250
1251 if (!(wd32 & RISC_SEMAPHORE))
1252 goto force;
1253
1254 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1255 goto acquired;
1256
1257 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
1258 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
1259 n = timeout_msec / delta_msec;
1260 while (n--) {
1261 qla25xx_read_risc_sema_reg(vha, &wd32);
1262 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1263 break;
1264 msleep(delta_msec);
1265 elapsed_msec += delta_msec;
1266 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1267 goto force;
1268 }
1269
1270 if (wd32 & RISC_SEMAPHORE_FORCE)
1271 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
1272
1273 goto attempt;
1274
1275force:
1276 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
1277
1278acquired:
1279 return;
1280}
1281
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001282/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001283 * qla24xx_reset_chip() - Reset ISP24xx chip.
1284 * @ha: HA context
1285 *
1286 * Returns 0 on success.
1287 */
1288void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001289qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001290{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001291 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001292
1293 if (pci_channel_offline(ha->pdev) &&
1294 ha->flags.pci_channel_io_perm_failure) {
1295 return;
1296 }
1297
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001298 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001299
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001300 qla25xx_manipulate_risc_semaphore(vha);
1301
Andrew Vasquez88c26662005-07-08 17:59:26 -07001302 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001303 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001304}
1305
1306/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 * qla2x00_chip_diag() - Test chip for proper operation.
1308 * @ha: HA context
1309 *
1310 * Returns 0 on success.
1311 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001312int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001313qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314{
1315 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001316 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001317 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 unsigned long flags = 0;
1319 uint16_t data;
1320 uint32_t cnt;
1321 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001322 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
1324 /* Assume a failed state */
1325 rval = QLA_FUNCTION_FAILED;
1326
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001327 ql_dbg(ql_dbg_init, vha, 0x007b,
1328 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
1330 spin_lock_irqsave(&ha->hardware_lock, flags);
1331
1332 /* Reset ISP chip. */
1333 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1334
1335 /*
1336 * We need to have a delay here since the card will not respond while
1337 * in reset causing an MCA on some architectures.
1338 */
1339 udelay(20);
1340 data = qla2x00_debounce_register(&reg->ctrl_status);
1341 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1342 udelay(5);
1343 data = RD_REG_WORD(&reg->ctrl_status);
1344 barrier();
1345 }
1346
1347 if (!cnt)
1348 goto chip_diag_failed;
1349
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001350 ql_dbg(ql_dbg_init, vha, 0x007c,
1351 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
1353 /* Reset RISC processor. */
1354 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1355 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1356
1357 /* Workaround for QLA2312 PCI parity error */
1358 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1359 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1360 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1361 udelay(5);
1362 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001363 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 }
1365 } else
1366 udelay(10);
1367
1368 if (!cnt)
1369 goto chip_diag_failed;
1370
1371 /* Check product ID of chip */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001372 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
1374 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1375 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1376 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1377 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1378 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1379 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001380 ql_log(ql_log_warn, vha, 0x0062,
1381 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1382 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383
1384 goto chip_diag_failed;
1385 }
1386 ha->product_id[0] = mb[1];
1387 ha->product_id[1] = mb[2];
1388 ha->product_id[2] = mb[3];
1389 ha->product_id[3] = mb[4];
1390
1391 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001392 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1394 else
1395 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001396 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
1398 if (IS_QLA2200(ha) &&
1399 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1400 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001401 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001403 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 ha->fw_transfer_size = 128;
1405 }
1406
1407 /* Wrap Incoming Mailboxes Test. */
1408 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1409
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001410 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001411 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001412 if (rval)
1413 ql_log(ql_log_warn, vha, 0x0080,
1414 "Failed mailbox send register test.\n");
1415 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 /* Flag a successful rval */
1417 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 spin_lock_irqsave(&ha->hardware_lock, flags);
1419
1420chip_diag_failed:
1421 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001422 ql_log(ql_log_info, vha, 0x0081,
1423 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
1425 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1426
1427 return (rval);
1428}
1429
1430/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001431 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1432 * @ha: HA context
1433 *
1434 * Returns 0 on success.
1435 */
1436int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001437qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001438{
1439 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001440 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001441 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001442
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001443 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07001444 return QLA_SUCCESS;
1445
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001446 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001447
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001448 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001449 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001450 ql_log(ql_log_warn, vha, 0x0082,
1451 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001452 } else {
1453 /* Flag a successful rval */
1454 rval = QLA_SUCCESS;
1455 }
1456
1457 return rval;
1458}
1459
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001460void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001461qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001462{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001463 int rval;
1464 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001465 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001466 dma_addr_t tc_dma;
1467 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001468 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001469 struct req_que *req = ha->req_q_map[0];
1470 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001471
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001472 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001473 ql_dbg(ql_dbg_init, vha, 0x00bd,
1474 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001475 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001476 }
1477
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001478 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04001479 ha->fw_dump_cap_flags = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001480 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
1481 req_q_size = rsp_q_size = 0;
1482
1483 if (IS_QLA27XX(ha))
1484 goto try_fce;
1485
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001486 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1487 fixed_size = sizeof(struct qla2100_fw_dump);
1488 } else if (IS_QLA23XX(ha)) {
1489 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1490 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1491 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001492 } else if (IS_FWI2_CAPABLE(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001493 if (IS_QLA83XX(ha))
1494 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
1495 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001496 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1497 else if (IS_QLA25XX(ha))
1498 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1499 else
1500 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Chad Dupuisf73cb692014-02-26 04:15:06 -05001501
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001502 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1503 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001504 if (ha->mqenable) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001505 if (!IS_QLA83XX(ha))
1506 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001507 /*
1508 * Allocate maximum buffer size for all queues.
1509 * Resizing must be done at end-of-dump processing.
1510 */
1511 mq_size += ha->max_req_queues *
1512 (req->length * sizeof(request_t));
1513 mq_size += ha->max_rsp_queues *
1514 (rsp->length * sizeof(response_t));
1515 }
Arun Easi00876ae2013-03-25 02:21:37 -04001516 if (ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001517 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001518 /* Allocate memory for Fibre Channel Event Buffer. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05001519 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
1520 !IS_QLA27XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001521 goto try_eft;
1522
Chad Dupuisf73cb692014-02-26 04:15:06 -05001523try_fce:
1524 if (ha->fce)
1525 dma_free_coherent(&ha->pdev->dev,
1526 FCE_SIZE, ha->fce, ha->fce_dma);
1527
1528 /* Allocate memory for Fibre Channel Event Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07001529 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1530 GFP_KERNEL);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001531 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001532 ql_log(ql_log_warn, vha, 0x00be,
1533 "Unable to allocate (%d KB) for FCE.\n",
1534 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001535 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001536 }
1537
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001538 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001539 ha->fce_mb, &ha->fce_bufs);
1540 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001541 ql_log(ql_log_warn, vha, 0x00bf,
1542 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001543 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1544 tc_dma);
1545 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001546 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001547 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001548 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001549 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001550
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001551 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001552 ha->flags.fce_enabled = 1;
1553 ha->fce_dma = tc_dma;
1554 ha->fce = tc;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001555
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001556try_eft:
Chad Dupuisf73cb692014-02-26 04:15:06 -05001557 if (ha->eft)
1558 dma_free_coherent(&ha->pdev->dev,
1559 EFT_SIZE, ha->eft, ha->eft_dma);
1560
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001561 /* Allocate memory for Extended Trace Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07001562 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
1563 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001564 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001565 ql_log(ql_log_warn, vha, 0x00c1,
1566 "Unable to allocate (%d KB) for EFT.\n",
1567 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001568 goto cont_alloc;
1569 }
1570
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001571 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001572 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001573 ql_log(ql_log_warn, vha, 0x00c2,
1574 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001575 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1576 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001577 goto cont_alloc;
1578 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001579 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001580 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001581
1582 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001583 ha->eft_dma = tc_dma;
1584 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001585 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05001586
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001587cont_alloc:
Chad Dupuisf73cb692014-02-26 04:15:06 -05001588 if (IS_QLA27XX(ha)) {
1589 if (!ha->fw_dump_template) {
1590 ql_log(ql_log_warn, vha, 0x00ba,
1591 "Failed missing fwdump template\n");
1592 return;
1593 }
1594 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
1595 ql_dbg(ql_dbg_init, vha, 0x00fa,
1596 "-> allocating fwdump (%x bytes)...\n", dump_size);
1597 goto allocate;
1598 }
1599
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001600 req_q_size = req->length * sizeof(request_t);
1601 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001602 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001603 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001604 ha->chain_offset = dump_size;
1605 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001606
Chad Dupuisf73cb692014-02-26 04:15:06 -05001607allocate:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001608 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001609 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001610 ql_log(ql_log_warn, vha, 0x00c4,
1611 "Unable to allocate (%d KB) for firmware dump.\n",
1612 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001613
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001614 if (ha->fce) {
1615 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1616 ha->fce_dma);
1617 ha->fce = NULL;
1618 ha->fce_dma = 0;
1619 }
1620
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001621 if (ha->eft) {
1622 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1623 ha->eft_dma);
1624 ha->eft = NULL;
1625 ha->eft_dma = 0;
1626 }
1627 return;
1628 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05001629 ha->fw_dump_len = dump_size;
Chad Dupuiscfb09192011-11-18 09:03:07 -08001630 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001631 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001632
Chad Dupuisf73cb692014-02-26 04:15:06 -05001633 if (IS_QLA27XX(ha))
1634 return;
1635
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001636 ha->fw_dump->signature[0] = 'Q';
1637 ha->fw_dump->signature[1] = 'L';
1638 ha->fw_dump->signature[2] = 'G';
1639 ha->fw_dump->signature[3] = 'C';
1640 ha->fw_dump->version = __constant_htonl(1);
1641
1642 ha->fw_dump->fixed_size = htonl(fixed_size);
1643 ha->fw_dump->mem_size = htonl(mem_size);
1644 ha->fw_dump->req_q_size = htonl(req_q_size);
1645 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1646
1647 ha->fw_dump->eft_size = htonl(eft_size);
1648 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1649 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1650
1651 ha->fw_dump->header_size =
1652 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001653}
1654
Andrew Vasquez18e75552009-06-03 09:55:30 -07001655static int
1656qla81xx_mpi_sync(scsi_qla_host_t *vha)
1657{
1658#define MPS_MASK 0xe0
1659 int rval;
1660 uint16_t dc;
1661 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07001662
1663 if (!IS_QLA81XX(vha->hw))
1664 return QLA_SUCCESS;
1665
1666 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1667 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001668 ql_log(ql_log_warn, vha, 0x0105,
1669 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001670 goto done;
1671 }
1672
1673 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1674 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1675 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001676 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001677 goto done_release;
1678 }
1679
1680 dc &= MPS_MASK;
1681 if (dc == (dw & MPS_MASK))
1682 goto done_release;
1683
1684 dw &= ~MPS_MASK;
1685 dw |= dc;
1686 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1687 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001688 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001689 }
1690
1691done_release:
1692 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1693 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001694 ql_log(ql_log_warn, vha, 0x006d,
1695 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001696 }
1697
1698done:
1699 return rval;
1700}
1701
Chad Dupuis8d93f552013-01-30 03:34:37 -05001702int
1703qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
1704{
1705 /* Don't try to reallocate the array */
1706 if (req->outstanding_cmds)
1707 return QLA_SUCCESS;
1708
1709 if (!IS_FWI2_CAPABLE(ha) || (ha->mqiobase &&
1710 (ql2xmultique_tag || ql2xmaxqueues > 1)))
1711 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
1712 else {
1713 if (ha->fw_xcb_count <= ha->fw_iocb_count)
1714 req->num_outstanding_cmds = ha->fw_xcb_count;
1715 else
1716 req->num_outstanding_cmds = ha->fw_iocb_count;
1717 }
1718
1719 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1720 req->num_outstanding_cmds, GFP_KERNEL);
1721
1722 if (!req->outstanding_cmds) {
1723 /*
1724 * Try to allocate a minimal size just so we can get through
1725 * initialization.
1726 */
1727 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
1728 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1729 req->num_outstanding_cmds, GFP_KERNEL);
1730
1731 if (!req->outstanding_cmds) {
1732 ql_log(ql_log_fatal, NULL, 0x0126,
1733 "Failed to allocate memory for "
1734 "outstanding_cmds for req_que %p.\n", req);
1735 req->num_outstanding_cmds = 0;
1736 return QLA_FUNCTION_FAILED;
1737 }
1738 }
1739
1740 return QLA_SUCCESS;
1741}
1742
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001743/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 * qla2x00_setup_chip() - Load and start RISC firmware.
1745 * @ha: HA context
1746 *
1747 * Returns 0 on success.
1748 */
1749static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001750qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001752 int rval;
1753 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001754 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001755 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1756 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001757 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001758
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001759 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001760 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001761 if (rval == QLA_SUCCESS) {
1762 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001763 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001764 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001765 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001766 }
1767
Andrew Vasquez3db06522008-01-31 12:33:49 -08001768 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1769 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1770 spin_lock_irqsave(&ha->hardware_lock, flags);
1771 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1772 RD_REG_WORD(&reg->hccr);
1773 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1774 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775
Andrew Vasquez18e75552009-06-03 09:55:30 -07001776 qla81xx_mpi_sync(vha);
1777
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001779 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001780 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001781 ql_dbg(ql_dbg_init, vha, 0x00c9,
1782 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001784 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 if (rval == QLA_SUCCESS) {
1786 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001787 ql_dbg(ql_dbg_init, vha, 0x00ca,
1788 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001790 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001792 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001793enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001794 fw_major_version = ha->fw_major_version;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001795 if (IS_P3P_TYPE(ha))
Giridhar Malavali31731672011-08-16 11:31:54 -07001796 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001797 else
1798 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001799 if (rval != QLA_SUCCESS)
1800 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001801 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001802 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001803 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001804 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001805 if ((!ha->max_npiv_vports) ||
1806 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001807 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001808 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001809 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001810 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001811 qla2x00_get_resource_cnts(vha, NULL,
Chad Dupuis8d93f552013-01-30 03:34:37 -05001812 &ha->fw_xcb_count, NULL, &ha->fw_iocb_count,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001813 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001814
Chad Dupuis8d93f552013-01-30 03:34:37 -05001815 /*
1816 * Allocate the array of outstanding commands
1817 * now that we know the firmware resources.
1818 */
1819 rval = qla2x00_alloc_outstanding_cmds(ha,
1820 vha->req);
1821 if (rval != QLA_SUCCESS)
1822 goto failed;
1823
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08001824 if (!fw_major_version && ql2xallocfwdump
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001825 && !(IS_P3P_TYPE(ha)))
Giridhar Malavali08de2842011-08-16 11:31:44 -07001826 qla2x00_alloc_fw_dump(vha);
Chad Dupuis3b6e5b92013-10-30 03:38:09 -04001827 } else {
1828 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 }
1830 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001831 ql_log(ql_log_fatal, vha, 0x00cd,
1832 "ISP Firmware failed checksum.\n");
1833 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04001835 } else
1836 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
Andrew Vasquez3db06522008-01-31 12:33:49 -08001838 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1839 /* Enable proper parity. */
1840 spin_lock_irqsave(&ha->hardware_lock, flags);
1841 if (IS_QLA2300(ha))
1842 /* SRAM parity */
1843 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1844 else
1845 /* SRAM, Instruction RAM and GP RAM parity */
1846 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1847 RD_REG_WORD(&reg->hccr);
1848 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1849 }
1850
Chad Dupuisf3982d82014-09-25 05:16:57 -04001851 if (IS_QLA27XX(ha))
1852 ha->flags.fac_supported = 1;
1853 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001854 uint32_t size;
1855
1856 rval = qla81xx_fac_get_sector_size(vha, &size);
1857 if (rval == QLA_SUCCESS) {
1858 ha->flags.fac_supported = 1;
1859 ha->fdt_block_size = size << 2;
1860 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001861 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001862 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1863 ha->fw_major_version, ha->fw_minor_version,
1864 ha->fw_subminor_version);
Joe Carnuccio1ca60e32014-02-26 04:15:02 -05001865
Chad Dupuisf73cb692014-02-26 04:15:06 -05001866 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001867 ha->flags.fac_supported = 0;
1868 rval = QLA_SUCCESS;
1869 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001870 }
1871 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001872failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001874 ql_log(ql_log_fatal, vha, 0x00cf,
1875 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 }
1877
1878 return (rval);
1879}
1880
1881/**
1882 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1883 * @ha: HA context
1884 *
1885 * Beginning of request ring has initialization control block already built
1886 * by nvram config routine.
1887 *
1888 * Returns 0 on success.
1889 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001890void
1891qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892{
1893 uint16_t cnt;
1894 response_t *pkt;
1895
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001896 rsp->ring_ptr = rsp->ring;
1897 rsp->ring_index = 0;
1898 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001899 pkt = rsp->ring_ptr;
1900 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 pkt->signature = RESPONSE_PROCESSED;
1902 pkt++;
1903 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904}
1905
1906/**
1907 * qla2x00_update_fw_options() - Read and process firmware options.
1908 * @ha: HA context
1909 *
1910 * Returns 0 on success.
1911 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001912void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001913qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914{
1915 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001916 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917
1918 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001919 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920
1921 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1922 return;
1923
1924 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001925 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1926 "Serial link options.\n");
1927 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1928 (uint8_t *)&ha->fw_seriallink_options,
1929 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930
1931 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1932 if (ha->fw_seriallink_options[3] & BIT_2) {
1933 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1934
1935 /* 1G settings */
1936 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1937 emphasis = (ha->fw_seriallink_options[2] &
1938 (BIT_4 | BIT_3)) >> 3;
1939 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001940 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 rx_sens = (ha->fw_seriallink_options[0] &
1942 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1943 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1944 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1945 if (rx_sens == 0x0)
1946 rx_sens = 0x3;
1947 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1948 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1949 ha->fw_options[10] |= BIT_5 |
1950 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1951 (tx_sens & (BIT_1 | BIT_0));
1952
1953 /* 2G settings */
1954 swing = (ha->fw_seriallink_options[2] &
1955 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1956 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1957 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001958 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 rx_sens = (ha->fw_seriallink_options[1] &
1960 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1961 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1962 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1963 if (rx_sens == 0x0)
1964 rx_sens = 0x3;
1965 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1966 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1967 ha->fw_options[11] |= BIT_5 |
1968 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1969 (tx_sens & (BIT_1 | BIT_0));
1970 }
1971
1972 /* FCP2 options. */
1973 /* Return command IOCBs without waiting for an ABTS to complete. */
1974 ha->fw_options[3] |= BIT_13;
1975
1976 /* LED scheme. */
1977 if (ha->flags.enable_led_scheme)
1978 ha->fw_options[2] |= BIT_12;
1979
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001980 /* Detect ISP6312. */
1981 if (IS_QLA6312(ha))
1982 ha->fw_options[2] |= BIT_13;
1983
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001985 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986}
1987
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001988void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001989qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001990{
1991 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001992 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001993
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001994 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07001995 return;
1996
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001997 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001998 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001999 return;
2000
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002001 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08002002 le16_to_cpu(ha->fw_seriallink_options24[1]),
2003 le16_to_cpu(ha->fw_seriallink_options24[2]),
2004 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002005 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002006 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002007 "Unable to update Serial Link options (%x).\n", rval);
2008 }
2009}
2010
2011void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002012qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002013{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002014 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002015 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002016 struct req_que *req = ha->req_q_map[0];
2017 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002018
2019 /* Setup ring parameters in initialization control block. */
2020 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
2021 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002022 ha->init_cb->request_q_length = cpu_to_le16(req->length);
2023 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
2024 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2025 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2026 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2027 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002028
2029 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
2030 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
2031 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
2032 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
2033 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
2034}
2035
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002036void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002037qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002038{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002039 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002040 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
2041 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
2042 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002043 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002044 uint16_t rid = 0;
2045 struct req_que *req = ha->req_q_map[0];
2046 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002047
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002048 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002049 icb = (struct init_cb_24xx *)ha->init_cb;
2050 icb->request_q_outpointer = __constant_cpu_to_le16(0);
2051 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052 icb->request_q_length = cpu_to_le16(req->length);
2053 icb->response_q_length = cpu_to_le16(rsp->length);
2054 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2055 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2056 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2057 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002058
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002059 /* Setup ATIO queue dma pointers for target mode */
2060 icb->atio_q_inpointer = __constant_cpu_to_le16(0);
2061 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
2062 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
2063 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
2064
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002065 if (IS_SHADOW_REG_CAPABLE(ha))
2066 icb->firmware_options_2 |=
2067 __constant_cpu_to_le32(BIT_30|BIT_29);
2068
Chad Dupuisf73cb692014-02-26 04:15:06 -05002069 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002070 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
2071 icb->rid = __constant_cpu_to_le16(rid);
2072 if (ha->flags.msix_enabled) {
2073 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002074 ql_dbg(ql_dbg_init, vha, 0x00fd,
2075 "Registering vector 0x%x for base que.\n",
2076 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002077 icb->msix = cpu_to_le16(msix->entry);
2078 }
2079 /* Use alternate PCI bus number */
2080 if (MSB(rid))
2081 icb->firmware_options_2 |=
2082 __constant_cpu_to_le32(BIT_19);
2083 /* Use alternate PCI devfn */
2084 if (LSB(rid))
2085 icb->firmware_options_2 |=
2086 __constant_cpu_to_le32(BIT_18);
2087
Anirban Chakraborty31557542009-12-02 10:36:55 -08002088 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002089 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
2090 (ha->flags.msix_enabled)) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08002091 icb->firmware_options_2 &=
2092 __constant_cpu_to_le32(~BIT_22);
2093 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002094 ql_dbg(ql_dbg_init, vha, 0x00fe,
2095 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08002096 } else {
2097 icb->firmware_options_2 |=
2098 __constant_cpu_to_le32(BIT_22);
2099 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002100 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002101
2102 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
2103 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
2104 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
2105 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
2106 } else {
2107 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
2108 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
2109 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
2110 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
2111 }
Arun Easiaa230bc2013-01-30 03:34:39 -05002112 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002113
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002114 /* PCI posting */
2115 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002116}
2117
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118/**
2119 * qla2x00_init_rings() - Initializes firmware.
2120 * @ha: HA context
2121 *
2122 * Beginning of request ring has initialization control block already built
2123 * by nvram config routine.
2124 *
2125 * Returns 0 on success.
2126 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002127int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002128qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129{
2130 int rval;
2131 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002132 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002133 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002134 struct req_que *req;
2135 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002136 struct mid_init_cb_24xx *mid_init_cb =
2137 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
2139 spin_lock_irqsave(&ha->hardware_lock, flags);
2140
2141 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002142 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002143 req = ha->req_q_map[que];
2144 if (!req)
2145 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002146 req->out_ptr = (void *)(req->ring + req->length);
2147 *req->out_ptr = 0;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002148 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002149 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002151 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002152
2153 /* Initialize firmware. */
2154 req->ring_ptr = req->ring;
2155 req->ring_index = 0;
2156 req->cnt = req->length;
2157 }
2158
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002159 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002160 rsp = ha->rsp_q_map[que];
2161 if (!rsp)
2162 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002163 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
2164 *rsp->in_ptr = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002165 /* Initialize response queue entries */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002166 if (IS_QLAFX00(ha))
2167 qlafx00_init_response_q_entries(rsp);
2168 else
2169 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002170 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002172 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
2173 ha->tgt.atio_ring_index = 0;
2174 /* Initialize ATIO queue entries */
2175 qlt_init_atio_q_entries(vha);
2176
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002177 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
2179 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2180
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002181 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
2182
2183 if (IS_QLAFX00(ha)) {
2184 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
2185 goto next_check;
2186 }
2187
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002189 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002191 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04002192 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002193 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08002194 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002195 }
2196
Andrew Vasquez24a08132009-03-24 09:08:16 -07002197 if (IS_FWI2_CAPABLE(ha)) {
2198 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
2199 mid_init_cb->init_cb.execution_throttle =
2200 cpu_to_le16(ha->fw_xcb_count);
Himanshu Madhani25232cc2014-09-25 05:16:54 -04002201 /* D-Port Status */
2202 if (IS_DPORT_CAPABLE(ha))
2203 mid_init_cb->init_cb.firmware_options_1 |=
2204 cpu_to_le16(BIT_7);
Himanshu Madhani2486c622014-09-25 05:17:00 -04002205 /* Enable FA-WWPN */
2206 ha->flags.fawwpn_enabled =
2207 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) ? 1 : 0;
2208 ql_dbg(ql_dbg_init, vha, 0x0141, "FA-WWPN Support: %s.\n",
2209 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
Andrew Vasquez24a08132009-03-24 09:08:16 -07002210 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002211
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002212 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002213next_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002215 ql_log(ql_log_fatal, vha, 0x00d2,
2216 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002218 ql_dbg(ql_dbg_init, vha, 0x00d3,
2219 "Init Firmware -- success.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 }
2221
2222 return (rval);
2223}
2224
2225/**
2226 * qla2x00_fw_ready() - Waits for firmware ready.
2227 * @ha: HA context
2228 *
2229 * Returns 0 on success.
2230 */
2231static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002232qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233{
2234 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002235 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 uint16_t min_wait; /* Minimum wait time if loop is down */
2237 uint16_t wait_time; /* Wait time if loop is coming ready */
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002238 uint16_t state[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002239 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002241 if (IS_QLAFX00(vha->hw))
2242 return qlafx00_fw_ready(vha);
2243
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 rval = QLA_SUCCESS;
2245
2246 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002247 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
2249 /*
2250 * Firmware should take at most one RATOV to login, plus 5 seconds for
2251 * our own processing.
2252 */
2253 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
2254 wait_time = min_wait;
2255 }
2256
2257 /* Min wait time if loop down */
2258 mtime = jiffies + (min_wait * HZ);
2259
2260 /* wait time before firmware ready */
2261 wtime = jiffies + (wait_time * HZ);
2262
2263 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002264 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002265 ql_log(ql_log_info, vha, 0x801e,
2266 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267
2268 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05002269 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002270 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002272 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002273 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002275 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002276 ql_dbg(ql_dbg_taskm, vha, 0x801f,
2277 "fw_state=%x 84xx=%x.\n", state[0],
2278 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002279 if ((state[2] & FSTATE_LOGGED_IN) &&
2280 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002281 ql_dbg(ql_dbg_taskm, vha, 0x8028,
2282 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002283
2284 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002285 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002286 if (rval != QLA_SUCCESS) {
2287 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002288 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002289 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002290 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002291 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002292
2293 /* Add time taken to initialize. */
2294 cs84xx_time = jiffies - cs84xx_time;
2295 wtime += cs84xx_time;
2296 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002297 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002298 "Increasing wait time by %ld. "
2299 "New time %ld.\n", cs84xx_time,
2300 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002301 }
2302 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002303 ql_dbg(ql_dbg_taskm, vha, 0x8037,
2304 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002306 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 &ha->login_timeout, &ha->r_a_tov);
2308
2309 rval = QLA_SUCCESS;
2310 break;
2311 }
2312
2313 rval = QLA_FUNCTION_FAILED;
2314
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002315 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002316 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002318 * other than Wait for Login.
2319 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002321 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 "Cable is unplugged...\n");
2323
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002324 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 break;
2326 }
2327 }
2328 } else {
2329 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07002330 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08002331 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 break;
2333 }
2334
2335 if (time_after_eq(jiffies, wtime))
2336 break;
2337
2338 /* Delay for a while */
2339 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 } while (1);
2341
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002342 ql_dbg(ql_dbg_taskm, vha, 0x803a,
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002343 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
2344 state[1], state[2], state[3], state[4], state[5], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
Chad Dupuiscfb09192011-11-18 09:03:07 -08002346 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002347 ql_log(ql_log_warn, vha, 0x803b,
2348 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 }
2350
2351 return (rval);
2352}
2353
2354/*
2355* qla2x00_configure_hba
2356* Setup adapter context.
2357*
2358* Input:
2359* ha = adapter state pointer.
2360*
2361* Returns:
2362* 0 = success
2363*
2364* Context:
2365* Kernel context.
2366*/
2367static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002368qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369{
2370 int rval;
2371 uint16_t loop_id;
2372 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002373 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 uint8_t al_pa;
2375 uint8_t area;
2376 uint8_t domain;
2377 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002378 struct qla_hw_data *ha = vha->hw;
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002379 unsigned long flags;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002380 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
2382 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002383 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002384 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002386 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002387 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002388 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002389 ql_dbg(ql_dbg_disc, vha, 0x2008,
2390 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08002391 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002392 ql_log(ql_log_warn, vha, 0x2009,
2393 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002394 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
2395 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
2396 ql_log(ql_log_warn, vha, 0x1151,
2397 "Doing link init.\n");
2398 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
2399 return rval;
2400 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002401 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002402 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 return (rval);
2404 }
2405
2406 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002407 ql_log(ql_log_info, vha, 0x200a,
2408 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 return (QLA_FUNCTION_FAILED);
2410 }
2411
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002412 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413
2414 /* initialize */
2415 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2416 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002417 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418
2419 switch (topo) {
2420 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002421 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 ha->current_topology = ISP_CFG_NL;
2423 strcpy(connect_type, "(Loop)");
2424 break;
2425
2426 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002427 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002428 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 ha->current_topology = ISP_CFG_FL;
2430 strcpy(connect_type, "(FL_Port)");
2431 break;
2432
2433 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002434 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 ha->operating_mode = P2P;
2436 ha->current_topology = ISP_CFG_N;
2437 strcpy(connect_type, "(N_Port-to-N_Port)");
2438 break;
2439
2440 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002441 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002442 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 ha->operating_mode = P2P;
2444 ha->current_topology = ISP_CFG_F;
2445 strcpy(connect_type, "(F_Port)");
2446 break;
2447
2448 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002449 ql_dbg(ql_dbg_disc, vha, 0x200f,
2450 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 ha->current_topology = ISP_CFG_NL;
2452 strcpy(connect_type, "(Loop)");
2453 break;
2454 }
2455
2456 /* Save Host port and loop ID. */
2457 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002458 vha->d_id.b.domain = domain;
2459 vha->d_id.b.area = area;
2460 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002462 spin_lock_irqsave(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002463 qlt_update_vp_map(vha, SET_AL_PA);
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002464 spin_unlock_irqrestore(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002465
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002466 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002467 ql_log(ql_log_info, vha, 0x2010,
2468 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002469 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 return(rval);
2472}
2473
Giridhar Malavalia9083012010-04-12 17:59:55 -07002474inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002475qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2476 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002477{
2478 char *st, *en;
2479 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002480 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002481 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002482 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002483
2484 if (memcmp(model, BINZERO, len) != 0) {
2485 strncpy(ha->model_number, model, len);
2486 st = en = ha->model_number;
2487 en += len - 1;
2488 while (en > st) {
2489 if (*en != 0x20 && *en != 0x00)
2490 break;
2491 *en-- = '\0';
2492 }
2493
2494 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002495 if (use_tbl &&
2496 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002497 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002498 strncpy(ha->model_desc,
2499 qla2x00_model_name[index * 2 + 1],
2500 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002501 } else {
2502 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002503 if (use_tbl &&
2504 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002505 index < QLA_MODEL_NAMES) {
2506 strcpy(ha->model_number,
2507 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002508 strncpy(ha->model_desc,
2509 qla2x00_model_name[index * 2 + 1],
2510 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002511 } else {
2512 strcpy(ha->model_number, def);
2513 }
2514 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002515 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002516 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002517 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002518}
2519
David Miller4e08df32007-04-16 12:37:43 -07002520/* On sparc systems, obtain port and node WWN from firmware
2521 * properties.
2522 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002523static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002524{
2525#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002526 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002527 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002528 struct device_node *dp = pci_device_to_OF_node(pdev);
2529 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002530 int len;
2531
2532 val = of_get_property(dp, "port-wwn", &len);
2533 if (val && len >= WWN_SIZE)
2534 memcpy(nv->port_name, val, WWN_SIZE);
2535
2536 val = of_get_property(dp, "node-wwn", &len);
2537 if (val && len >= WWN_SIZE)
2538 memcpy(nv->node_name, val, WWN_SIZE);
2539#endif
2540}
2541
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542/*
2543* NVRAM configuration for ISP 2xxx
2544*
2545* Input:
2546* ha = adapter block pointer.
2547*
2548* Output:
2549* initialization control block in response_ring
2550* host adapters parameters in host adapter block
2551*
2552* Returns:
2553* 0 = success.
2554*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002555int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002556qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557{
David Miller4e08df32007-04-16 12:37:43 -07002558 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002559 uint8_t chksum = 0;
2560 uint16_t cnt;
2561 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002562 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002563 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002564 nvram_t *nv = ha->nvram;
2565 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002566 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567
David Miller4e08df32007-04-16 12:37:43 -07002568 rval = QLA_SUCCESS;
2569
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002571 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 ha->nvram_base = 0;
2573 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2574 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2575 ha->nvram_base = 0x80;
2576
2577 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002578 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002579 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2580 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002582 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2583 "Contents of NVRAM.\n");
2584 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2585 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586
2587 /* Bad NVRAM data, set defaults parameters. */
2588 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2589 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2590 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002591 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04002592 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002593 "detected: checksum=0x%x id=%c version=0x%x.\n",
2594 chksum, nv->id[0], nv->nvram_version);
2595 ql_log(ql_log_warn, vha, 0x0065,
2596 "Falling back to "
2597 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07002598
2599 /*
2600 * Set default initialization control block.
2601 */
2602 memset(nv, 0, ha->nvram_size);
2603 nv->parameter_block_version = ICB_VERSION;
2604
2605 if (IS_QLA23XX(ha)) {
2606 nv->firmware_options[0] = BIT_2 | BIT_1;
2607 nv->firmware_options[1] = BIT_7 | BIT_5;
2608 nv->add_firmware_options[0] = BIT_5;
2609 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04002610 nv->frame_payload_size = 2048;
David Miller4e08df32007-04-16 12:37:43 -07002611 nv->special_options[1] = BIT_7;
2612 } else if (IS_QLA2200(ha)) {
2613 nv->firmware_options[0] = BIT_2 | BIT_1;
2614 nv->firmware_options[1] = BIT_7 | BIT_5;
2615 nv->add_firmware_options[0] = BIT_5;
2616 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04002617 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07002618 } else if (IS_QLA2100(ha)) {
2619 nv->firmware_options[0] = BIT_3 | BIT_1;
2620 nv->firmware_options[1] = BIT_5;
Joe Carnuccio98aee702014-09-25 05:16:38 -04002621 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07002622 }
2623
2624 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2625 nv->execution_throttle = __constant_cpu_to_le16(16);
2626 nv->retry_count = 8;
2627 nv->retry_delay = 1;
2628
2629 nv->port_name[0] = 33;
2630 nv->port_name[3] = 224;
2631 nv->port_name[4] = 139;
2632
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002633 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002634
2635 nv->login_timeout = 4;
2636
2637 /*
2638 * Set default host adapter parameters
2639 */
2640 nv->host_p[1] = BIT_2;
2641 nv->reset_delay = 5;
2642 nv->port_down_retry_count = 8;
2643 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2644 nv->link_down_timeout = 60;
2645
2646 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 }
2648
2649#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2650 /*
2651 * The SN2 does not provide BIOS emulation which means you can't change
2652 * potentially bogus BIOS settings. Force the use of default settings
2653 * for link rate and frame size. Hope that the rest of the settings
2654 * are valid.
2655 */
2656 if (ia64_platform_is("sn2")) {
Joe Carnuccio98aee702014-09-25 05:16:38 -04002657 nv->frame_payload_size = 2048;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 if (IS_QLA23XX(ha))
2659 nv->special_options[1] = BIT_7;
2660 }
2661#endif
2662
2663 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002664 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665
2666 /*
2667 * Setup driver NVRAM options.
2668 */
2669 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2670 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2671 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2672 nv->firmware_options[1] &= ~BIT_4;
2673
2674 if (IS_QLA23XX(ha)) {
2675 nv->firmware_options[0] |= BIT_2;
2676 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002677 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002678 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679
2680 if (IS_QLA2300(ha)) {
2681 if (ha->fb_rev == FPM_2310) {
2682 strcpy(ha->model_number, "QLA2310");
2683 } else {
2684 strcpy(ha->model_number, "QLA2300");
2685 }
2686 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002687 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002688 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 }
2690 } else if (IS_QLA2200(ha)) {
2691 nv->firmware_options[0] |= BIT_2;
2692 /*
2693 * 'Point-to-point preferred, else loop' is not a safe
2694 * connection mode setting.
2695 */
2696 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2697 (BIT_5 | BIT_4)) {
2698 /* Force 'loop preferred, else point-to-point'. */
2699 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2700 nv->add_firmware_options[0] |= BIT_5;
2701 }
2702 strcpy(ha->model_number, "QLA22xx");
2703 } else /*if (IS_QLA2100(ha))*/ {
2704 strcpy(ha->model_number, "QLA2100");
2705 }
2706
2707 /*
2708 * Copy over NVRAM RISC parameter block to initialization control block.
2709 */
2710 dptr1 = (uint8_t *)icb;
2711 dptr2 = (uint8_t *)&nv->parameter_block_version;
2712 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2713 while (cnt--)
2714 *dptr1++ = *dptr2++;
2715
2716 /* Copy 2nd half. */
2717 dptr1 = (uint8_t *)icb->add_firmware_options;
2718 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2719 while (cnt--)
2720 *dptr1++ = *dptr2++;
2721
Andrew Vasquez5341e862006-05-17 15:09:16 -07002722 /* Use alternate WWN? */
2723 if (nv->host_p[1] & BIT_7) {
2724 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2725 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2726 }
2727
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 /* Prepare nodename */
2729 if ((icb->firmware_options[1] & BIT_6) == 0) {
2730 /*
2731 * Firmware will apply the following mask if the nodename was
2732 * not provided.
2733 */
2734 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2735 icb->node_name[0] &= 0xF0;
2736 }
2737
2738 /*
2739 * Set host adapter parameters.
2740 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002741
2742 /*
2743 * BIT_7 in the host-parameters section allows for modification to
2744 * internal driver logging.
2745 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002746 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08002747 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2749 /* Always load RISC code on non ISP2[12]00 chips. */
2750 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2751 ha->flags.disable_risc_code_load = 0;
2752 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2753 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2754 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002755 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002756 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757
2758 ha->operating_mode =
2759 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2760
2761 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2762 sizeof(ha->fw_seriallink_options));
2763
2764 /* save HBA serial number */
2765 ha->serial0 = icb->port_name[5];
2766 ha->serial1 = icb->port_name[6];
2767 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002768 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2769 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770
2771 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2772
2773 ha->retry_count = nv->retry_count;
2774
2775 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002776 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 nv->login_timeout = ql2xlogintimeout;
2778 if (nv->login_timeout < 4)
2779 nv->login_timeout = 4;
2780 ha->login_timeout = nv->login_timeout;
2781 icb->login_timeout = nv->login_timeout;
2782
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002783 /* Set minimum RATOV to 100 tenths of a second. */
2784 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 ha->loop_reset_delay = nv->reset_delay;
2787
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 /* Link Down Timeout = 0:
2789 *
2790 * When Port Down timer expires we will start returning
2791 * I/O's to OS with "DID_NO_CONNECT".
2792 *
2793 * Link Down Timeout != 0:
2794 *
2795 * The driver waits for the link to come up after link down
2796 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002797 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 if (nv->link_down_timeout == 0) {
2799 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002800 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 } else {
2802 ha->link_down_timeout = nv->link_down_timeout;
2803 ha->loop_down_abort_time =
2804 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002805 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 /*
2808 * Need enough time to try and get the port back.
2809 */
2810 ha->port_down_retry_count = nv->port_down_retry_count;
2811 if (qlport_down_retry)
2812 ha->port_down_retry_count = qlport_down_retry;
2813 /* Set login_retry_count */
2814 ha->login_retry_count = nv->retry_count;
2815 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2816 ha->port_down_retry_count > 3)
2817 ha->login_retry_count = ha->port_down_retry_count;
2818 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2819 ha->login_retry_count = ha->port_down_retry_count;
2820 if (ql2xloginretrycount)
2821 ha->login_retry_count = ql2xloginretrycount;
2822
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 icb->lun_enables = __constant_cpu_to_le16(0);
2824 icb->command_resource_count = 0;
2825 icb->immediate_notify_resource_count = 0;
2826 icb->timeout = __constant_cpu_to_le16(0);
2827
2828 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2829 /* Enable RIO */
2830 icb->firmware_options[0] &= ~BIT_3;
2831 icb->add_firmware_options[0] &=
2832 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2833 icb->add_firmware_options[0] |= BIT_2;
2834 icb->response_accumulation_timer = 3;
2835 icb->interrupt_delay_timer = 5;
2836
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002837 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002839 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002840 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002841 ha->zio_mode = icb->add_firmware_options[0] &
2842 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2843 ha->zio_timer = icb->interrupt_delay_timer ?
2844 icb->interrupt_delay_timer: 2;
2845 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 icb->add_firmware_options[0] &=
2847 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002848 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002849 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002850 ha->zio_mode = QLA_ZIO_MODE_6;
2851
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002852 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002853 "ZIO mode %d enabled; timer delay (%d us).\n",
2854 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002856 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2857 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002858 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 }
2860 }
2861
David Miller4e08df32007-04-16 12:37:43 -07002862 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002863 ql_log(ql_log_warn, vha, 0x0069,
2864 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07002865 }
2866 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867}
2868
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002869static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002870qla2x00_rport_del(void *data)
2871{
2872 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002873 struct fc_rport *rport;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002874 scsi_qla_host_t *vha = fcport->vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002875 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002876
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002877 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002878 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002879 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002880 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002881 if (rport) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002882 fc_remote_port_delete(rport);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002883 /*
2884 * Release the target mode FC NEXUS in qla_target.c code
2885 * if target mod is enabled.
2886 */
2887 qlt_fc_port_deleted(vha, fcport);
2888 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002889}
2890
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891/**
2892 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2893 * @ha: HA context
2894 * @flags: allocation flags
2895 *
2896 * Returns a pointer to the allocated fcport, or NULL, if none available.
2897 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002898fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002899qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900{
2901 fc_port_t *fcport;
2902
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002903 fcport = kzalloc(sizeof(fc_port_t), flags);
2904 if (!fcport)
2905 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906
2907 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002908 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 fcport->port_type = FCT_UNKNOWN;
2910 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07002911 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002912 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002914 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915}
2916
2917/*
2918 * qla2x00_configure_loop
2919 * Updates Fibre Channel Device Database with what is actually on loop.
2920 *
2921 * Input:
2922 * ha = adapter block pointer.
2923 *
2924 * Returns:
2925 * 0 = success.
2926 * 1 = error.
2927 * 2 = database was full and device was not configured.
2928 */
2929static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002930qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931{
2932 int rval;
2933 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002934 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 rval = QLA_SUCCESS;
2936
2937 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002938 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2939 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002941 ql_dbg(ql_dbg_disc, vha, 0x2013,
2942 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 return (rval);
2944 }
2945 }
2946
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002947 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002948 ql_dbg(ql_dbg_disc, vha, 0x2014,
2949 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950
2951 /*
2952 * If we have both an RSCN and PORT UPDATE pending then handle them
2953 * both at the same time.
2954 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002955 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2956 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957
Michael Hernandez3064ff32009-12-15 21:29:44 -08002958 qla2x00_get_data_rate(vha);
2959
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 /* Determine what we need to do */
2961 if (ha->current_topology == ISP_CFG_FL &&
2962 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2963
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 set_bit(RSCN_UPDATE, &flags);
2965
2966 } else if (ha->current_topology == ISP_CFG_F &&
2967 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2968
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 set_bit(RSCN_UPDATE, &flags);
2970 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2971
Andrew Vasquez21333b42006-05-17 15:09:56 -07002972 } else if (ha->current_topology == ISP_CFG_N) {
2973 clear_bit(RSCN_UPDATE, &flags);
2974
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002975 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2977
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 set_bit(RSCN_UPDATE, &flags);
2979 set_bit(LOCAL_LOOP_UPDATE, &flags);
2980 }
2981
2982 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002983 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2984 ql_dbg(ql_dbg_disc, vha, 0x2015,
2985 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08002987 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002988 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 }
2990
2991 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002992 if (LOOP_TRANSITION(vha)) {
2993 ql_dbg(ql_dbg_disc, vha, 0x201e,
2994 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002996 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002997 else
2998 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 }
3000
3001 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003002 if (atomic_read(&vha->loop_down_timer) ||
3003 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 rval = QLA_FUNCTION_FAILED;
3005 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003006 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003007 ql_dbg(ql_dbg_disc, vha, 0x2069,
3008 "LOOP READY.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 }
3010 }
3011
3012 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003013 ql_dbg(ql_dbg_disc, vha, 0x206a,
3014 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003016 ql_dbg(ql_dbg_disc, vha, 0x206b,
3017 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 }
3019
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07003020 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003021 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003023 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07003024 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003025 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07003026 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 }
3028
3029 return (rval);
3030}
3031
3032
3033
3034/*
3035 * qla2x00_configure_local_loop
3036 * Updates Fibre Channel Device Database with local loop devices.
3037 *
3038 * Input:
3039 * ha = adapter block pointer.
3040 *
3041 * Returns:
3042 * 0 = success.
3043 */
3044static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003045qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046{
3047 int rval, rval2;
3048 int found_devs;
3049 int found;
3050 fc_port_t *fcport, *new_fcport;
3051
3052 uint16_t index;
3053 uint16_t entries;
3054 char *id_iter;
3055 uint16_t loop_id;
3056 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003057 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058
3059 found_devs = 0;
3060 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08003061 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08003064 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003065 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 &entries);
3067 if (rval != QLA_SUCCESS)
3068 goto cleanup_allocation;
3069
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003070 ql_dbg(ql_dbg_disc, vha, 0x2017,
3071 "Entries in ID list (%d).\n", entries);
3072 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
3073 (uint8_t *)ha->gid_list,
3074 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075
3076 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003077 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003079 ql_log(ql_log_warn, vha, 0x2018,
3080 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 rval = QLA_MEMORY_ALLOC_FAILED;
3082 goto cleanup_allocation;
3083 }
3084 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3085
3086 /*
3087 * Mark local devices that were present with FCF_DEVICE_LOST for now.
3088 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003089 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 if (atomic_read(&fcport->state) == FCS_ONLINE &&
3091 fcport->port_type != FCT_BROADCAST &&
3092 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3093
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003094 ql_dbg(ql_dbg_disc, vha, 0x2019,
3095 "Marking port lost loop_id=0x%04x.\n",
3096 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097
Chad Dupuisec426e12011-03-30 11:46:32 -07003098 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 }
3100 }
3101
3102 /* Add devices to port list. */
3103 id_iter = (char *)ha->gid_list;
3104 for (index = 0; index < entries; index++) {
3105 domain = ((struct gid_list_info *)id_iter)->domain;
3106 area = ((struct gid_list_info *)id_iter)->area;
3107 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003108 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 loop_id = (uint16_t)
3110 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003111 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 loop_id = le16_to_cpu(
3113 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003114 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115
3116 /* Bypass reserved domain fields. */
3117 if ((domain & 0xf0) == 0xf0)
3118 continue;
3119
3120 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003121 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003122 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 continue;
3124
3125 /* Bypass invalid local loop ID. */
3126 if (loop_id > LAST_LOCAL_LOOP_ID)
3127 continue;
3128
Arun Easi370d5502012-08-22 14:21:10 -04003129 memset(new_fcport, 0, sizeof(fc_port_t));
3130
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 /* Fill in member data. */
3132 new_fcport->d_id.b.domain = domain;
3133 new_fcport->d_id.b.area = area;
3134 new_fcport->d_id.b.al_pa = al_pa;
3135 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003136 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003138 ql_dbg(ql_dbg_disc, vha, 0x201a,
3139 "Failed to retrieve fcport information "
3140 "-- get_port_database=%x, loop_id=0x%04x.\n",
3141 rval2, new_fcport->loop_id);
3142 ql_dbg(ql_dbg_disc, vha, 0x201b,
3143 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003144 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145 continue;
3146 }
3147
3148 /* Check for matching device in port list. */
3149 found = 0;
3150 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003151 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 if (memcmp(new_fcport->port_name, fcport->port_name,
3153 WWN_SIZE))
3154 continue;
3155
Shyam Sundarddb9b122009-03-24 09:08:10 -07003156 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 fcport->loop_id = new_fcport->loop_id;
3158 fcport->port_type = new_fcport->port_type;
3159 fcport->d_id.b24 = new_fcport->d_id.b24;
3160 memcpy(fcport->node_name, new_fcport->node_name,
3161 WWN_SIZE);
3162
3163 found++;
3164 break;
3165 }
3166
3167 if (!found) {
3168 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003169 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170
3171 /* Allocate a new replacement fcport. */
3172 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003173 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003175 ql_log(ql_log_warn, vha, 0x201c,
3176 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 rval = QLA_MEMORY_ALLOC_FAILED;
3178 goto cleanup_allocation;
3179 }
3180 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3181 }
3182
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003183 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003184 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003185
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003186 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187
3188 found_devs++;
3189 }
3190
3191cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003192 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193
3194 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003195 ql_dbg(ql_dbg_disc, vha, 0x201d,
3196 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 }
3198
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 return (rval);
3200}
3201
3202static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003203qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003204{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003205 int rval;
Quinn Tran93f2bd62014-09-25 05:16:53 -04003206 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003207 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003208
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07003209 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003210 return;
3211
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07003212 if (atomic_read(&fcport->state) != FCS_ONLINE)
3213 return;
3214
Andrew Vasquez39bd9622007-09-20 14:07:34 -07003215 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
3216 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003217 return;
3218
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003219 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003220 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003221 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003222 ql_dbg(ql_dbg_disc, vha, 0x2004,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04003223 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
3224 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003225 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003226 ql_dbg(ql_dbg_disc, vha, 0x2005,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04003227 "iIDMA adjusted to %s GB/s on %8phN.\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -05003228 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04003229 fcport->port_name);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003230 }
3231}
3232
Adrian Bunk23be3312006-11-24 02:46:01 +01003233static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003234qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05003235{
3236 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05003237 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003238 unsigned long flags;
8482e1182005-04-17 15:04:54 -05003239
Andrew Vasquezac280b62009-08-20 11:06:05 -07003240 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05003241
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07003242 rport_ids.node_name = wwn_to_u64(fcport->node_name);
3243 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05003244 rport_ids.port_id = fcport->d_id.b.domain << 16 |
3245 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
3246 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003247 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07003248 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003249 ql_log(ql_log_warn, vha, 0x2006,
3250 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07003251 return;
3252 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003253 /*
3254 * Create target mode FC NEXUS in qla_target.c if target mode is
3255 * enabled..
3256 */
3257 qlt_fc_port_added(vha, fcport);
3258
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003259 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003260 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003261 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003262
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003263 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003264
3265 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05003266 if (fcport->port_type == FCT_INITIATOR)
3267 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3268 if (fcport->port_type == FCT_TARGET)
3269 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003270 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05003271}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272
3273/*
Adrian Bunk23be3312006-11-24 02:46:01 +01003274 * qla2x00_update_fcport
3275 * Updates device on list.
3276 *
3277 * Input:
3278 * ha = adapter block pointer.
3279 * fcport = port structure pointer.
3280 *
3281 * Return:
3282 * 0 - Success
3283 * BIT_0 - error
3284 *
3285 * Context:
3286 * Kernel context.
3287 */
3288void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003289qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01003290{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003291 fcport->vha = vha;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003292
3293 if (IS_QLAFX00(vha->hw)) {
3294 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
3295 qla2x00_reg_remote_port(vha, fcport);
3296 return;
3297 }
Adrian Bunk23be3312006-11-24 02:46:01 +01003298 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003299 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01003300
Joe Carnuccio1f93da522012-11-21 02:40:38 -05003301 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003302 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08003303 qla24xx_update_fcport_fcp_prio(vha, fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003304 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01003305}
3306
3307/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 * qla2x00_configure_fabric
3309 * Setup SNS devices with loop ID's.
3310 *
3311 * Input:
3312 * ha = adapter block pointer.
3313 *
3314 * Returns:
3315 * 0 = success.
3316 * BIT_0 = error
3317 */
3318static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003319qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320{
Arun Easib3b02e62012-02-09 11:15:39 -08003321 int rval;
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003322 fc_port_t *fcport, *fcptemp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 uint16_t next_loopid;
3324 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003325 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003327 struct qla_hw_data *ha = vha->hw;
3328 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329
3330 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003331 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003332 loop_id = NPH_F_PORT;
3333 else
3334 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003335 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003337 ql_dbg(ql_dbg_disc, vha, 0x201f,
3338 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003340 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 return (QLA_SUCCESS);
3342 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003343 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07003346 /* FDMI support. */
3347 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003348 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
3349 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07003350
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003352 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003353 loop_id = NPH_SNS;
3354 else
3355 loop_id = SIMPLE_NAME_SERVER;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003356 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
3357 0xfc, mb, BIT_1|BIT_0);
3358 if (rval != QLA_SUCCESS) {
3359 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003360 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003361 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003363 ql_dbg(ql_dbg_disc, vha, 0x2042,
3364 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3365 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
3366 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 return (QLA_SUCCESS);
3368 }
3369
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003370 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3371 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003373 ql_dbg(ql_dbg_disc, vha, 0x2045,
3374 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003376 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003378 ql_dbg(ql_dbg_disc, vha, 0x2049,
3379 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003381 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003383 ql_dbg(ql_dbg_disc, vha, 0x204f,
3384 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003385 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003387 ql_dbg(ql_dbg_disc, vha, 0x2053,
3388 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 }
3390 }
3391
Joe Carnuccio827210b2013-02-08 01:57:57 -05003392#define QLA_FCPORT_SCAN 1
3393#define QLA_FCPORT_FOUND 2
3394
3395 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3396 fcport->scan_state = QLA_FCPORT_SCAN;
3397 }
3398
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003399 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 if (rval != QLA_SUCCESS)
3401 break;
3402
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003403 /*
3404 * Logout all previous fabric devices marked lost, except
3405 * FCP2 devices.
3406 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003407 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3408 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 break;
3410
3411 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3412 continue;
3413
Joe Carnuccio827210b2013-02-08 01:57:57 -05003414 if (fcport->scan_state == QLA_FCPORT_SCAN &&
Arun Easib3b02e62012-02-09 11:15:39 -08003415 atomic_read(&fcport->state) == FCS_ONLINE) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003416 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003417 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003419 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 fcport->port_type != FCT_INITIATOR &&
3421 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003422 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003423 fcport->loop_id,
3424 fcport->d_id.b.domain,
3425 fcport->d_id.b.area,
3426 fcport->d_id.b.al_pa);
Chad Dupuis1a5c69b2014-04-11 16:54:33 -04003427 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 }
3429 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003430 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003432 /* Starting free loop ID. */
3433 next_loopid = ha->min_external_loopid;
3434
3435 /*
3436 * Scan through our port list and login entries that need to be
3437 * logged in.
3438 */
3439 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3440 if (atomic_read(&vha->loop_down_timer) ||
3441 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3442 break;
3443
3444 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3445 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3446 continue;
3447
3448 if (fcport->loop_id == FC_NO_LOOP_ID) {
3449 fcport->loop_id = next_loopid;
3450 rval = qla2x00_find_new_loop_id(
3451 base_vha, fcport);
3452 if (rval != QLA_SUCCESS) {
3453 /* Ran out of IDs to use */
3454 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 }
3456 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003457 /* Login and update database */
3458 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
3459 }
3460
3461 /* Exit if out of loop IDs. */
3462 if (rval != QLA_SUCCESS) {
3463 break;
3464 }
3465
3466 /*
3467 * Login and add the new devices to our port list.
3468 */
3469 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3470 if (atomic_read(&vha->loop_down_timer) ||
3471 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3472 break;
3473
3474 /* Find a new loop ID to use. */
3475 fcport->loop_id = next_loopid;
3476 rval = qla2x00_find_new_loop_id(base_vha, fcport);
3477 if (rval != QLA_SUCCESS) {
3478 /* Ran out of IDs to use */
3479 break;
3480 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481
bdf79622005-04-17 15:06:53 -05003482 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003483 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003484
3485 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 }
3487 } while (0);
3488
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003489 /* Free all new device structures not processed. */
3490 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3491 list_del(&fcport->list);
3492 kfree(fcport);
3493 }
3494
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003496 ql_dbg(ql_dbg_disc, vha, 0x2068,
3497 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 }
3499
3500 return (rval);
3501}
3502
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503/*
3504 * qla2x00_find_all_fabric_devs
3505 *
3506 * Input:
3507 * ha = adapter block pointer.
3508 * dev = database device entry pointer.
3509 *
3510 * Returns:
3511 * 0 = success.
3512 *
3513 * Context:
3514 * Kernel context.
3515 */
3516static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003517qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3518 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519{
3520 int rval;
3521 uint16_t loop_id;
3522 fc_port_t *fcport, *new_fcport, *fcptemp;
3523 int found;
3524
3525 sw_info_t *swl;
3526 int swl_idx;
3527 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003528 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003529 struct qla_hw_data *ha = vha->hw;
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05003530 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531
3532 rval = QLA_SUCCESS;
3533
3534 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08003535 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08003536 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08003537 GFP_KERNEL);
3538 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003539 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003541 ql_dbg(ql_dbg_disc, vha, 0x2054,
3542 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08003544 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003545 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003547 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003549 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003551 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003552 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3553 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003555
3556 /* If other queries succeeded probe for FC-4 type */
3557 if (swl)
3558 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 }
3560 swl_idx = 0;
3561
3562 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003563 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003565 ql_log(ql_log_warn, vha, 0x205e,
3566 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 return (QLA_MEMORY_ALLOC_FAILED);
3568 }
3569 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570 /* Set start port ID scan at adapter ID. */
3571 first_dev = 1;
3572 last_dev = 0;
3573
3574 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003575 loop_id = ha->min_external_loopid;
3576 for (; loop_id <= ha->max_loop_id; loop_id++) {
3577 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 continue;
3579
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003580 if (ha->current_topology == ISP_CFG_FL &&
3581 (atomic_read(&vha->loop_down_timer) ||
3582 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003583 atomic_set(&vha->loop_down_timer, 0);
3584 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3585 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003587 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588
3589 if (swl != NULL) {
3590 if (last_dev) {
3591 wrap.b24 = new_fcport->d_id.b24;
3592 } else {
3593 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3594 memcpy(new_fcport->node_name,
3595 swl[swl_idx].node_name, WWN_SIZE);
3596 memcpy(new_fcport->port_name,
3597 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003598 memcpy(new_fcport->fabric_port_name,
3599 swl[swl_idx].fabric_port_name, WWN_SIZE);
3600 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003601 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602
3603 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3604 last_dev = 1;
3605 }
3606 swl_idx++;
3607 }
3608 } else {
3609 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003610 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003612 ql_log(ql_log_warn, vha, 0x2064,
3613 "SNS scan failed -- assuming "
3614 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 list_for_each_entry_safe(fcport, fcptemp,
3616 new_fcports, list) {
3617 list_del(&fcport->list);
3618 kfree(fcport);
3619 }
3620 rval = QLA_SUCCESS;
3621 break;
3622 }
3623 }
3624
3625 /* If wrap on switch device list, exit. */
3626 if (first_dev) {
3627 wrap.b24 = new_fcport->d_id.b24;
3628 first_dev = 0;
3629 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003630 ql_dbg(ql_dbg_disc, vha, 0x2065,
3631 "Device wrap (%02x%02x%02x).\n",
3632 new_fcport->d_id.b.domain,
3633 new_fcport->d_id.b.area,
3634 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 break;
3636 }
3637
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003638 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003639 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640 continue;
3641
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003642 /* Bypass virtual ports of the same host. */
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05003643 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
3644 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003645
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003646 /* Bypass if same domain and area of adapter. */
3647 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003648 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003649 ISP_CFG_FL)
3650 continue;
3651
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652 /* Bypass reserved domain fields. */
3653 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3654 continue;
3655
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003656 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003657 if (ql2xgffidenable &&
3658 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3659 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003660 continue;
3661
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662 /* Locate matching device in database. */
3663 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003664 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665 if (memcmp(new_fcport->port_name, fcport->port_name,
3666 WWN_SIZE))
3667 continue;
3668
Joe Carnuccio827210b2013-02-08 01:57:57 -05003669 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08003670
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671 found++;
3672
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003673 /* Update port state. */
3674 memcpy(fcport->fabric_port_name,
3675 new_fcport->fabric_port_name, WWN_SIZE);
3676 fcport->fp_speed = new_fcport->fp_speed;
3677
Linus Torvalds1da177e2005-04-16 15:20:36 -07003678 /*
3679 * If address the same and state FCS_ONLINE, nothing
3680 * changed.
3681 */
3682 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3683 atomic_read(&fcport->state) == FCS_ONLINE) {
3684 break;
3685 }
3686
3687 /*
3688 * If device was not a fabric device before.
3689 */
3690 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3691 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04003692 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 fcport->flags |= (FCF_FABRIC_DEVICE |
3694 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 break;
3696 }
3697
3698 /*
3699 * Port ID changed or device was marked to be updated;
3700 * Log it out if still logged in and mark it for
3701 * relogin later.
3702 */
3703 fcport->d_id.b24 = new_fcport->d_id.b24;
3704 fcport->flags |= FCF_LOGIN_NEEDED;
3705 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003706 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Arun Easi0eba25d2012-02-09 11:15:58 -08003707 (fcport->flags & FCF_ASYNC_SENT) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 fcport->port_type != FCT_INITIATOR &&
3709 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003710 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003711 fcport->d_id.b.domain, fcport->d_id.b.area,
3712 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003713 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 }
3715
3716 break;
3717 }
3718
3719 if (found)
3720 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 /* If device was not in our fcports list, then add it. */
3722 list_add_tail(&new_fcport->list, new_fcports);
3723
3724 /* Allocate a new replacement fcport. */
3725 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003726 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003728 ql_log(ql_log_warn, vha, 0x2066,
3729 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 return (QLA_MEMORY_ALLOC_FAILED);
3731 }
3732 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3733 new_fcport->d_id.b24 = nxt_d_id.b24;
3734 }
3735
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003736 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 return (rval);
3739}
3740
3741/*
3742 * qla2x00_find_new_loop_id
3743 * Scan through our port list and find a new usable loop ID.
3744 *
3745 * Input:
3746 * ha: adapter state pointer.
3747 * dev: port structure pointer.
3748 *
3749 * Returns:
3750 * qla2x00 local function return status code.
3751 *
3752 * Context:
3753 * Kernel context.
3754 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003755int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003756qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757{
3758 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003759 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07003760 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761
3762 rval = QLA_SUCCESS;
3763
Chad Dupuis5f16b332012-08-22 14:21:00 -04003764 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765
Chad Dupuis5f16b332012-08-22 14:21:00 -04003766 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
3767 LOOPID_MAP_SIZE);
3768 if (dev->loop_id >= LOOPID_MAP_SIZE ||
3769 qla2x00_is_reserved_id(vha, dev->loop_id)) {
3770 dev->loop_id = FC_NO_LOOP_ID;
3771 rval = QLA_FUNCTION_FAILED;
3772 } else
3773 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774
Chad Dupuis5f16b332012-08-22 14:21:00 -04003775 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776
Chad Dupuis5f16b332012-08-22 14:21:00 -04003777 if (rval == QLA_SUCCESS)
3778 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
3779 "Assigning new loopid=%x, portid=%x.\n",
3780 dev->loop_id, dev->d_id.b24);
3781 else
3782 ql_log(ql_log_warn, dev->vha, 0x2087,
3783 "No loop_id's available, portid=%x.\n",
3784 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785
3786 return (rval);
3787}
3788
3789/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790 * qla2x00_fabric_dev_login
3791 * Login fabric target device and update FC port database.
3792 *
3793 * Input:
3794 * ha: adapter state pointer.
3795 * fcport: port structure list pointer.
3796 * next_loopid: contains value of a new loop ID that can be used
3797 * by the next login attempt.
3798 *
3799 * Returns:
3800 * qla2x00 local function return status code.
3801 *
3802 * Context:
3803 * Kernel context.
3804 */
3805static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003806qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 uint16_t *next_loopid)
3808{
3809 int rval;
3810 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003811 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003812 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813
3814 rval = QLA_SUCCESS;
3815 retry = 0;
3816
Andrew Vasquezac280b62009-08-20 11:06:05 -07003817 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003818 if (fcport->flags & FCF_ASYNC_SENT)
3819 return rval;
3820 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003821 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3822 if (!rval)
3823 return rval;
3824 }
3825
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003826 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003827 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003829 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003830 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003831 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003832 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003833 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003835 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003836 fcport->d_id.b.domain, fcport->d_id.b.area,
3837 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003838 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003840 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 }
Chad Dupuis0b91d112012-02-09 11:15:42 -08003842 } else {
3843 /* Retry Login. */
3844 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 }
3846
3847 return (rval);
3848}
3849
3850/*
3851 * qla2x00_fabric_login
3852 * Issue fabric login command.
3853 *
3854 * Input:
3855 * ha = adapter block pointer.
3856 * device = pointer to FC device type structure.
3857 *
3858 * Returns:
3859 * 0 - Login successfully
3860 * 1 - Login failed
3861 * 2 - Initiator device
3862 * 3 - Fatal error
3863 */
3864int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003865qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866 uint16_t *next_loopid)
3867{
3868 int rval;
3869 int retry;
3870 uint16_t tmp_loopid;
3871 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003872 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873
3874 retry = 0;
3875 tmp_loopid = 0;
3876
3877 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003878 ql_dbg(ql_dbg_disc, vha, 0x2000,
3879 "Trying Fabric Login w/loop id 0x%04x for port "
3880 "%02x%02x%02x.\n",
3881 fcport->loop_id, fcport->d_id.b.domain,
3882 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883
3884 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08003885 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886 fcport->d_id.b.domain, fcport->d_id.b.area,
3887 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08003888 if (rval != QLA_SUCCESS) {
3889 return rval;
3890 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891 if (mb[0] == MBS_PORT_ID_USED) {
3892 /*
3893 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003894 * recommends the driver perform an implicit login with
3895 * the specified ID again. The ID we just used is save
3896 * here so we return with an ID that can be tried by
3897 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 */
3899 retry++;
3900 tmp_loopid = fcport->loop_id;
3901 fcport->loop_id = mb[1];
3902
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003903 ql_dbg(ql_dbg_disc, vha, 0x2001,
3904 "Fabric Login: port in use - next loop "
3905 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003907 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003908
3909 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3910 /*
3911 * Login succeeded.
3912 */
3913 if (retry) {
3914 /* A retry occurred before. */
3915 *next_loopid = tmp_loopid;
3916 } else {
3917 /*
3918 * No retry occurred before. Just increment the
3919 * ID value for next login.
3920 */
3921 *next_loopid = (fcport->loop_id + 1);
3922 }
3923
3924 if (mb[1] & BIT_0) {
3925 fcport->port_type = FCT_INITIATOR;
3926 } else {
3927 fcport->port_type = FCT_TARGET;
3928 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003929 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930 }
3931 }
3932
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003933 if (mb[10] & BIT_0)
3934 fcport->supported_classes |= FC_COS_CLASS2;
3935 if (mb[10] & BIT_1)
3936 fcport->supported_classes |= FC_COS_CLASS3;
3937
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003938 if (IS_FWI2_CAPABLE(ha)) {
3939 if (mb[10] & BIT_7)
3940 fcport->flags |=
3941 FCF_CONF_COMP_SUPPORTED;
3942 }
3943
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 rval = QLA_SUCCESS;
3945 break;
3946 } else if (mb[0] == MBS_LOOP_ID_USED) {
3947 /*
3948 * Loop ID already used, try next loop ID.
3949 */
3950 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003951 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003952 if (rval != QLA_SUCCESS) {
3953 /* Ran out of loop IDs to use */
3954 break;
3955 }
3956 } else if (mb[0] == MBS_COMMAND_ERROR) {
3957 /*
3958 * Firmware possibly timed out during login. If NO
3959 * retries are left to do then the device is declared
3960 * dead.
3961 */
3962 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003963 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003964 fcport->d_id.b.domain, fcport->d_id.b.area,
3965 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003966 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967
3968 rval = 1;
3969 break;
3970 } else {
3971 /*
3972 * unrecoverable / not handled error
3973 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003974 ql_dbg(ql_dbg_disc, vha, 0x2002,
3975 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
3976 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
3977 fcport->d_id.b.area, fcport->d_id.b.al_pa,
3978 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979
3980 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003981 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003982 fcport->d_id.b.domain, fcport->d_id.b.area,
3983 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003984 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003985 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986
3987 rval = 3;
3988 break;
3989 }
3990 }
3991
3992 return (rval);
3993}
3994
3995/*
3996 * qla2x00_local_device_login
3997 * Issue local device login command.
3998 *
3999 * Input:
4000 * ha = adapter block pointer.
4001 * loop_id = loop id of device to login to.
4002 *
4003 * Returns (Where's the #define!!!!):
4004 * 0 - Login successfully
4005 * 1 - Login failed
4006 * 3 - Fatal error
4007 */
4008int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004009qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010{
4011 int rval;
4012 uint16_t mb[MAILBOX_REGISTER_COUNT];
4013
4014 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004015 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 if (rval == QLA_SUCCESS) {
4017 /* Interrogate mailbox registers for any errors */
4018 if (mb[0] == MBS_COMMAND_ERROR)
4019 rval = 1;
4020 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
4021 /* device not in PCB table */
4022 rval = 3;
4023 }
4024
4025 return (rval);
4026}
4027
4028/*
4029 * qla2x00_loop_resync
4030 * Resync with fibre channel devices.
4031 *
4032 * Input:
4033 * ha = adapter block pointer.
4034 *
4035 * Returns:
4036 * 0 = success
4037 */
4038int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004039qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004041 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004043 struct req_que *req;
4044 struct rsp_que *rsp;
4045
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004046 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004047 req = vha->hw->req_q_map[0];
4048 else
4049 req = vha->req;
4050 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004051
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004052 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4053 if (vha->flags.online) {
4054 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4056 wait_time = 256;
4057 do {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004058 if (!IS_QLAFX00(vha->hw)) {
4059 /*
4060 * Issue a marker after FW becomes
4061 * ready.
4062 */
4063 qla2x00_marker(vha, req, rsp, 0, 0,
4064 MK_SYNC_ALL);
4065 vha->marker_needed = 0;
4066 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067
4068 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004069 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004071 if (IS_QLAFX00(vha->hw))
4072 qlafx00_configure_devices(vha);
4073 else
4074 qla2x00_configure_loop(vha);
4075
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004077 } while (!atomic_read(&vha->loop_down_timer) &&
4078 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4079 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4080 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 }
4083
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004084 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004087 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004088 ql_dbg(ql_dbg_disc, vha, 0x206c,
4089 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090
4091 return (rval);
4092}
4093
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004094/*
4095* qla2x00_perform_loop_resync
4096* Description: This function will set the appropriate flags and call
4097* qla2x00_loop_resync. If successful loop will be resynced
4098* Arguments : scsi_qla_host_t pointer
4099* returm : Success or Failure
4100*/
4101
4102int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
4103{
4104 int32_t rval = 0;
4105
4106 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
4107 /*Configure the flags so that resync happens properly*/
4108 atomic_set(&ha->loop_down_timer, 0);
4109 if (!(ha->device_flags & DFLG_NO_CABLE)) {
4110 atomic_set(&ha->loop_state, LOOP_UP);
4111 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4112 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
4113 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4114
4115 rval = qla2x00_loop_resync(ha);
4116 } else
4117 atomic_set(&ha->loop_state, LOOP_DEAD);
4118
4119 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
4120 }
4121
4122 return rval;
4123}
4124
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125void
Andrew Vasquez67becc02009-08-25 11:36:20 -07004126qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004127{
4128 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07004129 struct scsi_qla_host *vha;
4130 struct qla_hw_data *ha = base_vha->hw;
4131 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004132
Arun Easifeafb7b2010-09-03 14:57:00 -07004133 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004134 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07004135 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
4136 atomic_inc(&vha->vref_count);
4137 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08004138 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07004139 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
4140 spin_unlock_irqrestore(&ha->vport_slock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07004141 qla2x00_rport_del(fcport);
Arun Easifeafb7b2010-09-03 14:57:00 -07004142 spin_lock_irqsave(&ha->vport_slock, flags);
4143 }
4144 }
4145 atomic_dec(&vha->vref_count);
4146 }
4147 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004148}
4149
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004150/* Assumes idc_lock always held on entry */
4151void
4152qla83xx_reset_ownership(scsi_qla_host_t *vha)
4153{
4154 struct qla_hw_data *ha = vha->hw;
4155 uint32_t drv_presence, drv_presence_mask;
4156 uint32_t dev_part_info1, dev_part_info2, class_type;
4157 uint32_t class_type_mask = 0x3;
4158 uint16_t fcoe_other_function = 0xffff, i;
4159
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004160 if (IS_QLA8044(ha)) {
4161 drv_presence = qla8044_rd_direct(vha,
4162 QLA8044_CRB_DRV_ACTIVE_INDEX);
4163 dev_part_info1 = qla8044_rd_direct(vha,
4164 QLA8044_CRB_DEV_PART_INFO_INDEX);
4165 dev_part_info2 = qla8044_rd_direct(vha,
4166 QLA8044_CRB_DEV_PART_INFO2);
4167 } else {
4168 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4169 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
4170 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
4171 }
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004172 for (i = 0; i < 8; i++) {
4173 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
4174 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4175 (i != ha->portnum)) {
4176 fcoe_other_function = i;
4177 break;
4178 }
4179 }
4180 if (fcoe_other_function == 0xffff) {
4181 for (i = 0; i < 8; i++) {
4182 class_type = ((dev_part_info2 >> (i * 4)) &
4183 class_type_mask);
4184 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4185 ((i + 8) != ha->portnum)) {
4186 fcoe_other_function = i + 8;
4187 break;
4188 }
4189 }
4190 }
4191 /*
4192 * Prepare drv-presence mask based on fcoe functions present.
4193 * However consider only valid physical fcoe function numbers (0-15).
4194 */
4195 drv_presence_mask = ~((1 << (ha->portnum)) |
4196 ((fcoe_other_function == 0xffff) ?
4197 0 : (1 << (fcoe_other_function))));
4198
4199 /* We are the reset owner iff:
4200 * - No other protocol drivers present.
4201 * - This is the lowest among fcoe functions. */
4202 if (!(drv_presence & drv_presence_mask) &&
4203 (ha->portnum < fcoe_other_function)) {
4204 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
4205 "This host is Reset owner.\n");
4206 ha->flags.nic_core_reset_owner = 1;
4207 }
4208}
4209
Saurav Kashyapfa492632012-11-21 02:40:29 -05004210static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004211__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
4212{
4213 int rval = QLA_SUCCESS;
4214 struct qla_hw_data *ha = vha->hw;
4215 uint32_t drv_ack;
4216
4217 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4218 if (rval == QLA_SUCCESS) {
4219 drv_ack |= (1 << ha->portnum);
4220 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4221 }
4222
4223 return rval;
4224}
4225
Saurav Kashyapfa492632012-11-21 02:40:29 -05004226static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004227__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
4228{
4229 int rval = QLA_SUCCESS;
4230 struct qla_hw_data *ha = vha->hw;
4231 uint32_t drv_ack;
4232
4233 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4234 if (rval == QLA_SUCCESS) {
4235 drv_ack &= ~(1 << ha->portnum);
4236 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4237 }
4238
4239 return rval;
4240}
4241
Saurav Kashyapfa492632012-11-21 02:40:29 -05004242static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004243qla83xx_dev_state_to_string(uint32_t dev_state)
4244{
4245 switch (dev_state) {
4246 case QLA8XXX_DEV_COLD:
4247 return "COLD/RE-INIT";
4248 case QLA8XXX_DEV_INITIALIZING:
4249 return "INITIALIZING";
4250 case QLA8XXX_DEV_READY:
4251 return "READY";
4252 case QLA8XXX_DEV_NEED_RESET:
4253 return "NEED RESET";
4254 case QLA8XXX_DEV_NEED_QUIESCENT:
4255 return "NEED QUIESCENT";
4256 case QLA8XXX_DEV_FAILED:
4257 return "FAILED";
4258 case QLA8XXX_DEV_QUIESCENT:
4259 return "QUIESCENT";
4260 default:
4261 return "Unknown";
4262 }
4263}
4264
4265/* Assumes idc-lock always held on entry */
4266void
4267qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
4268{
4269 struct qla_hw_data *ha = vha->hw;
4270 uint32_t idc_audit_reg = 0, duration_secs = 0;
4271
4272 switch (audit_type) {
4273 case IDC_AUDIT_TIMESTAMP:
4274 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
4275 idc_audit_reg = (ha->portnum) |
4276 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
4277 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4278 break;
4279
4280 case IDC_AUDIT_COMPLETION:
4281 duration_secs = ((jiffies_to_msecs(jiffies) -
4282 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
4283 idc_audit_reg = (ha->portnum) |
4284 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
4285 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4286 break;
4287
4288 default:
4289 ql_log(ql_log_warn, vha, 0xb078,
4290 "Invalid audit type specified.\n");
4291 break;
4292 }
4293}
4294
4295/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05004296static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004297qla83xx_initiating_reset(scsi_qla_host_t *vha)
4298{
4299 struct qla_hw_data *ha = vha->hw;
4300 uint32_t idc_control, dev_state;
4301
4302 __qla83xx_get_idc_control(vha, &idc_control);
4303 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
4304 ql_log(ql_log_info, vha, 0xb080,
4305 "NIC Core reset has been disabled. idc-control=0x%x\n",
4306 idc_control);
4307 return QLA_FUNCTION_FAILED;
4308 }
4309
4310 /* Set NEED-RESET iff in READY state and we are the reset-owner */
4311 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4312 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
4313 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
4314 QLA8XXX_DEV_NEED_RESET);
4315 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
4316 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
4317 } else {
4318 const char *state = qla83xx_dev_state_to_string(dev_state);
4319 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
4320
4321 /* SV: XXX: Is timeout required here? */
4322 /* Wait for IDC state change READY -> NEED_RESET */
4323 while (dev_state == QLA8XXX_DEV_READY) {
4324 qla83xx_idc_unlock(vha, 0);
4325 msleep(200);
4326 qla83xx_idc_lock(vha, 0);
4327 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4328 }
4329 }
4330
4331 /* Send IDC ack by writing to drv-ack register */
4332 __qla83xx_set_drv_ack(vha);
4333
4334 return QLA_SUCCESS;
4335}
4336
4337int
4338__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
4339{
4340 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4341}
4342
4343int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004344__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
4345{
4346 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4347}
4348
Saurav Kashyapfa492632012-11-21 02:40:29 -05004349static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004350qla83xx_check_driver_presence(scsi_qla_host_t *vha)
4351{
4352 uint32_t drv_presence = 0;
4353 struct qla_hw_data *ha = vha->hw;
4354
4355 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4356 if (drv_presence & (1 << ha->portnum))
4357 return QLA_SUCCESS;
4358 else
4359 return QLA_TEST_FAILED;
4360}
4361
4362int
4363qla83xx_nic_core_reset(scsi_qla_host_t *vha)
4364{
4365 int rval = QLA_SUCCESS;
4366 struct qla_hw_data *ha = vha->hw;
4367
4368 ql_dbg(ql_dbg_p3p, vha, 0xb058,
4369 "Entered %s().\n", __func__);
4370
4371 if (vha->device_flags & DFLG_DEV_FAILED) {
4372 ql_log(ql_log_warn, vha, 0xb059,
4373 "Device in unrecoverable FAILED state.\n");
4374 return QLA_FUNCTION_FAILED;
4375 }
4376
4377 qla83xx_idc_lock(vha, 0);
4378
4379 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
4380 ql_log(ql_log_warn, vha, 0xb05a,
4381 "Function=0x%x has been removed from IDC participation.\n",
4382 ha->portnum);
4383 rval = QLA_FUNCTION_FAILED;
4384 goto exit;
4385 }
4386
4387 qla83xx_reset_ownership(vha);
4388
4389 rval = qla83xx_initiating_reset(vha);
4390
4391 /*
4392 * Perform reset if we are the reset-owner,
4393 * else wait till IDC state changes to READY/FAILED.
4394 */
4395 if (rval == QLA_SUCCESS) {
4396 rval = qla83xx_idc_state_handler(vha);
4397
4398 if (rval == QLA_SUCCESS)
4399 ha->flags.nic_core_hung = 0;
4400 __qla83xx_clear_drv_ack(vha);
4401 }
4402
4403exit:
4404 qla83xx_idc_unlock(vha, 0);
4405
4406 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
4407
4408 return rval;
4409}
4410
Saurav Kashyap81178772012-08-22 14:21:04 -04004411int
4412qla2xxx_mctp_dump(scsi_qla_host_t *vha)
4413{
4414 struct qla_hw_data *ha = vha->hw;
4415 int rval = QLA_FUNCTION_FAILED;
4416
4417 if (!IS_MCTP_CAPABLE(ha)) {
4418 /* This message can be removed from the final version */
4419 ql_log(ql_log_info, vha, 0x506d,
4420 "This board is not MCTP capable\n");
4421 return rval;
4422 }
4423
4424 if (!ha->mctp_dump) {
4425 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
4426 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
4427
4428 if (!ha->mctp_dump) {
4429 ql_log(ql_log_warn, vha, 0x506e,
4430 "Failed to allocate memory for mctp dump\n");
4431 return rval;
4432 }
4433 }
4434
4435#define MCTP_DUMP_STR_ADDR 0x00000000
4436 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
4437 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
4438 if (rval != QLA_SUCCESS) {
4439 ql_log(ql_log_warn, vha, 0x506f,
4440 "Failed to capture mctp dump\n");
4441 } else {
4442 ql_log(ql_log_info, vha, 0x5070,
4443 "Mctp dump capture for host (%ld/%p).\n",
4444 vha->host_no, ha->mctp_dump);
4445 ha->mctp_dumped = 1;
4446 }
4447
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04004448 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04004449 ha->flags.nic_core_reset_hdlr_active = 1;
4450 rval = qla83xx_restart_nic_firmware(vha);
4451 if (rval)
4452 /* NIC Core reset failed. */
4453 ql_log(ql_log_warn, vha, 0x5071,
4454 "Failed to restart nic firmware\n");
4455 else
4456 ql_dbg(ql_dbg_p3p, vha, 0xb084,
4457 "Restarted NIC firmware successfully.\n");
4458 ha->flags.nic_core_reset_hdlr_active = 0;
4459 }
4460
4461 return rval;
4462
4463}
4464
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004465/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004466* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004467* Description: This function will block the new I/Os
4468* Its not aborting any I/Os as context
4469* is not destroyed during quiescence
4470* Arguments: scsi_qla_host_t
4471* return : void
4472*/
4473void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004474qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004475{
4476 struct qla_hw_data *ha = vha->hw;
4477 struct scsi_qla_host *vp;
4478
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004479 ql_dbg(ql_dbg_dpc, vha, 0x401d,
4480 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004481
4482 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4483 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4484 atomic_set(&vha->loop_state, LOOP_DOWN);
4485 qla2x00_mark_all_devices_lost(vha, 0);
4486 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004487 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004488 } else {
4489 if (!atomic_read(&vha->loop_down_timer))
4490 atomic_set(&vha->loop_down_timer,
4491 LOOP_DOWN_TIME);
4492 }
4493 /* Wait for pending cmds to complete */
4494 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
4495}
4496
Giridhar Malavalia9083012010-04-12 17:59:55 -07004497void
4498qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
4499{
4500 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004501 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07004502 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004503 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004504
Saurav Kashyape46ef002011-02-23 15:27:16 -08004505 /* For ISP82XX, driver waits for completion of the commands.
4506 * online flag should be set.
4507 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004508 if (!(IS_P3P_TYPE(ha)))
Saurav Kashyape46ef002011-02-23 15:27:16 -08004509 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004510 ha->flags.chip_reset_done = 0;
4511 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04004512 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004513
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004514 ql_log(ql_log_info, vha, 0x00af,
4515 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004516
Saurav Kashyape46ef002011-02-23 15:27:16 -08004517 /* For ISP82XX, reset_chip is just disabling interrupts.
4518 * Driver waits for the completion of the commands.
4519 * the interrupts need to be enabled.
4520 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004521 if (!(IS_P3P_TYPE(ha)))
Giridhar Malavalia9083012010-04-12 17:59:55 -07004522 ha->isp_ops->reset_chip(vha);
4523
4524 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
4525 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4526 atomic_set(&vha->loop_state, LOOP_DOWN);
4527 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004528
4529 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004530 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07004531 atomic_inc(&vp->vref_count);
4532 spin_unlock_irqrestore(&ha->vport_slock, flags);
4533
Giridhar Malavalia9083012010-04-12 17:59:55 -07004534 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004535
4536 spin_lock_irqsave(&ha->vport_slock, flags);
4537 atomic_dec(&vp->vref_count);
4538 }
4539 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004540 } else {
4541 if (!atomic_read(&vha->loop_down_timer))
4542 atomic_set(&vha->loop_down_timer,
4543 LOOP_DOWN_TIME);
4544 }
4545
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004546 /* Clear all async request states across all VPs. */
4547 list_for_each_entry(fcport, &vha->vp_fcports, list)
4548 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4549 spin_lock_irqsave(&ha->vport_slock, flags);
4550 list_for_each_entry(vp, &ha->vp_list, list) {
4551 atomic_inc(&vp->vref_count);
4552 spin_unlock_irqrestore(&ha->vport_slock, flags);
4553
4554 list_for_each_entry(fcport, &vp->vp_fcports, list)
4555 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4556
4557 spin_lock_irqsave(&ha->vport_slock, flags);
4558 atomic_dec(&vp->vref_count);
4559 }
4560 spin_unlock_irqrestore(&ha->vport_slock, flags);
4561
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004562 if (!ha->flags.eeh_busy) {
4563 /* Make sure for ISP 82XX IO DMA is complete */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004564 if (IS_P3P_TYPE(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004565 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004566 ql_log(ql_log_info, vha, 0x00b4,
4567 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004568
Saurav Kashyape46ef002011-02-23 15:27:16 -08004569 /* Done waiting for pending commands.
4570 * Reset the online flag.
4571 */
4572 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004573 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004575 /* Requeue all commands in outstanding command list. */
4576 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4577 }
Arun Easib6a029e2014-09-25 06:14:52 -04004578
4579 ha->chip_reset++;
4580 /* memory barrier */
4581 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582}
4583
4584/*
4585* qla2x00_abort_isp
4586* Resets ISP and aborts all outstanding commands.
4587*
4588* Input:
4589* ha = adapter block pointer.
4590*
4591* Returns:
4592* 0 = success
4593*/
4594int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004595qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004596{
Andrew Vasquez476e8972006-08-23 14:54:55 -07004597 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004599 struct qla_hw_data *ha = vha->hw;
4600 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004601 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07004602 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004604 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004605 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606
Santosh Vernekara61712972012-08-22 14:21:13 -04004607 if (IS_QLA8031(ha)) {
4608 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
4609 "Clearing fcoe driver presence.\n");
4610 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
4611 ql_dbg(ql_dbg_p3p, vha, 0xb073,
4612 "Error while clearing DRV-Presence.\n");
4613 }
4614
Andrew Vasquez85880802009-12-15 21:29:46 -08004615 if (unlikely(pci_channel_offline(ha->pdev) &&
4616 ha->flags.pci_channel_io_perm_failure)) {
4617 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4618 status = 0;
4619 return status;
4620 }
4621
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004622 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08004623
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004624 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004626 if (!qla2x00_restart_isp(vha)) {
4627 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004629 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630 /*
4631 * Issue marker command only when we are going
4632 * to start the I/O .
4633 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004634 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004635 }
4636
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004637 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004638
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004639 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004641 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004642 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07004643
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004644 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
4645 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004646 if (ha->fce) {
4647 ha->flags.fce_enabled = 1;
4648 memset(ha->fce, 0,
4649 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004650 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004651 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4652 &ha->fce_bufs);
4653 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004654 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004655 "Unable to reinitialize FCE "
4656 "(%d).\n", rval);
4657 ha->flags.fce_enabled = 0;
4658 }
4659 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004660
4661 if (ha->eft) {
4662 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004663 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004664 ha->eft_dma, EFT_NUM_BUFFERS);
4665 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004666 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004667 "Unable to reinitialize EFT "
4668 "(%d).\n", rval);
4669 }
4670 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004671 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004672 vha->flags.online = 1;
4673 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004675 ql_log(ql_log_fatal, vha, 0x8035,
4676 "ISP error recover failed - "
4677 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004678 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004679 * The next call disables the board
4680 * completely.
4681 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004682 ha->isp_ops->reset_adapter(vha);
4683 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004685 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686 status = 0;
4687 } else { /* schedule another ISP abort */
4688 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004689 ql_dbg(ql_dbg_taskm, vha, 0x8020,
4690 "ISP abort - retry remaining %d.\n",
4691 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004692 status = 1;
4693 }
4694 } else {
4695 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004696 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4697 "ISP error recovery - retrying (%d) "
4698 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004699 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004700 status = 1;
4701 }
4702 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004703
Linus Torvalds1da177e2005-04-16 15:20:36 -07004704 }
4705
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004706 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004707 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07004708
4709 spin_lock_irqsave(&ha->vport_slock, flags);
4710 list_for_each_entry(vp, &ha->vp_list, list) {
4711 if (vp->vp_idx) {
4712 atomic_inc(&vp->vref_count);
4713 spin_unlock_irqrestore(&ha->vport_slock, flags);
4714
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004715 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004716
4717 spin_lock_irqsave(&ha->vport_slock, flags);
4718 atomic_dec(&vp->vref_count);
4719 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004720 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004721 spin_unlock_irqrestore(&ha->vport_slock, flags);
4722
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004723 if (IS_QLA8031(ha)) {
4724 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
4725 "Setting back fcoe driver presence.\n");
4726 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
4727 ql_dbg(ql_dbg_p3p, vha, 0xb074,
4728 "Error while setting DRV-Presence.\n");
4729 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004730 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08004731 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
4732 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004733 }
4734
4735 return(status);
4736}
4737
4738/*
4739* qla2x00_restart_isp
4740* restarts the ISP after a reset
4741*
4742* Input:
4743* ha = adapter block pointer.
4744*
4745* Returns:
4746* 0 = success
4747*/
4748static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004749qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004751 int status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004752 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004753 struct req_que *req = ha->req_q_map[0];
4754 struct rsp_que *rsp = ha->rsp_q_map[0];
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004755 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004756
4757 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004758 if (qla2x00_isp_firmware(vha)) {
4759 vha->flags.online = 0;
4760 status = ha->isp_ops->chip_diag(vha);
4761 if (!status)
4762 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004763 }
4764
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004765 if (!status && !(status = qla2x00_init_rings(vha))) {
4766 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004767 ha->flags.chip_reset_done = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04004768
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004769 /* Initialize the queues in use */
4770 qla25xx_init_queues(ha);
4771
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004772 status = qla2x00_fw_ready(vha);
4773 if (!status) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004774 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004775 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004776
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004777 vha->flags.online = 1;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004778
4779 /*
4780 * Process any ATIO queue entries that came in
4781 * while we weren't online.
4782 */
4783 spin_lock_irqsave(&ha->hardware_lock, flags);
4784 if (qla_tgt_mode_enabled(vha))
4785 qlt_24xx_process_atio_queue(vha);
4786 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4787
Chad Dupuis7108b762014-04-11 16:54:45 -04004788 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004789 }
4790
4791 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004792 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004793 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794 }
4795 return (status);
4796}
4797
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004798static int
4799qla25xx_init_queues(struct qla_hw_data *ha)
4800{
4801 struct rsp_que *rsp = NULL;
4802 struct req_que *req = NULL;
4803 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4804 int ret = -1;
4805 int i;
4806
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004807 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004808 rsp = ha->rsp_q_map[i];
4809 if (rsp) {
4810 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004811 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004812 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004813 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4814 "%s Rsp que: %d init failed.\n",
4815 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004816 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004817 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4818 "%s Rsp que: %d inited.\n",
4819 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004820 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004821 }
4822 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004823 req = ha->req_q_map[i];
4824 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004825 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004826 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004827 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004828 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004829 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4830 "%s Req que: %d init failed.\n",
4831 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004832 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004833 ql_dbg(ql_dbg_init, base_vha, 0x0102,
4834 "%s Req que: %d inited.\n",
4835 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004836 }
4837 }
4838 return ret;
4839}
4840
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841/*
4842* qla2x00_reset_adapter
4843* Reset adapter.
4844*
4845* Input:
4846* ha = adapter block pointer.
4847*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004848void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004849qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850{
4851 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004852 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004853 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004855 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004856 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858 spin_lock_irqsave(&ha->hardware_lock, flags);
4859 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4860 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4861 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4862 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4863 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4864}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004865
4866void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004867qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004868{
4869 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004870 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004871 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4872
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004873 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07004874 return;
4875
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004876 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004877 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004878
4879 spin_lock_irqsave(&ha->hardware_lock, flags);
4880 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4881 RD_REG_DWORD(&reg->hccr);
4882 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4883 RD_REG_DWORD(&reg->hccr);
4884 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004885
4886 if (IS_NOPOLLING_TYPE(ha))
4887 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004888}
4889
David Miller4e08df32007-04-16 12:37:43 -07004890/* On sparc systems, obtain port and node WWN from firmware
4891 * properties.
4892 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004893static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4894 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004895{
4896#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004897 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004898 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004899 struct device_node *dp = pci_device_to_OF_node(pdev);
4900 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004901 int len;
4902
4903 val = of_get_property(dp, "port-wwn", &len);
4904 if (val && len >= WWN_SIZE)
4905 memcpy(nv->port_name, val, WWN_SIZE);
4906
4907 val = of_get_property(dp, "node-wwn", &len);
4908 if (val && len >= WWN_SIZE)
4909 memcpy(nv->node_name, val, WWN_SIZE);
4910#endif
4911}
4912
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004913int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004914qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004915{
David Miller4e08df32007-04-16 12:37:43 -07004916 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004917 struct init_cb_24xx *icb;
4918 struct nvram_24xx *nv;
4919 uint32_t *dptr;
4920 uint8_t *dptr1, *dptr2;
4921 uint32_t chksum;
4922 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004923 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004924
David Miller4e08df32007-04-16 12:37:43 -07004925 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004926 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004927 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004928
4929 /* Determine NVRAM starting address. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05004930 if (ha->port_no == 0) {
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004931 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4932 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4933 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004934 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004935 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4936 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05004937
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004938 ha->nvram_size = sizeof(struct nvram_24xx);
4939 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004940
Seokmann Ju281afe12007-07-26 13:43:34 -07004941 /* Get VPD data into cache */
4942 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004943 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004944 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4945
4946 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004947 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004948 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004949 ha->nvram_size);
4950 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4951 chksum += le32_to_cpu(*dptr++);
4952
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004953 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
4954 "Contents of NVRAM\n");
4955 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
4956 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004957
4958 /* Bad NVRAM data, set defaults parameters. */
4959 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4960 || nv->id[3] != ' ' ||
4961 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4962 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004963 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04004964 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004965 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
4966 ql_log(ql_log_warn, vha, 0x006c,
4967 "Falling back to functioning (yet invalid -- WWPN) "
4968 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07004969
4970 /*
4971 * Set default initialization control block.
4972 */
4973 memset(nv, 0, ha->nvram_size);
4974 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4975 nv->version = __constant_cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04004976 nv->frame_payload_size = 2048;
David Miller4e08df32007-04-16 12:37:43 -07004977 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4978 nv->exchange_count = __constant_cpu_to_le16(0);
4979 nv->hard_address = __constant_cpu_to_le16(124);
4980 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004981 nv->port_name[1] = 0x00 + ha->port_no + 1;
David Miller4e08df32007-04-16 12:37:43 -07004982 nv->port_name[2] = 0x00;
4983 nv->port_name[3] = 0xe0;
4984 nv->port_name[4] = 0x8b;
4985 nv->port_name[5] = 0x1c;
4986 nv->port_name[6] = 0x55;
4987 nv->port_name[7] = 0x86;
4988 nv->node_name[0] = 0x20;
4989 nv->node_name[1] = 0x00;
4990 nv->node_name[2] = 0x00;
4991 nv->node_name[3] = 0xe0;
4992 nv->node_name[4] = 0x8b;
4993 nv->node_name[5] = 0x1c;
4994 nv->node_name[6] = 0x55;
4995 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004996 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004997 nv->login_retry_count = __constant_cpu_to_le16(8);
4998 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4999 nv->login_timeout = __constant_cpu_to_le16(0);
5000 nv->firmware_options_1 =
5001 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5002 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5003 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5004 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5005 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5006 nv->efi_parameters = __constant_cpu_to_le32(0);
5007 nv->reset_delay = 5;
5008 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5009 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5010 nv->link_down_timeout = __constant_cpu_to_le16(30);
5011
5012 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005013 }
5014
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005015 if (!qla_ini_mode_enabled(vha)) {
5016 /* Don't enable full login after initial LIP */
5017 nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13);
5018 /* Don't enable LIP full login for initiator */
5019 nv->host_p &= __constant_cpu_to_le32(~BIT_10);
5020 }
5021
5022 qlt_24xx_config_nvram_stage1(vha, nv);
5023
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005024 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005025 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005026
5027 /* Copy 1st segment. */
5028 dptr1 = (uint8_t *)icb;
5029 dptr2 = (uint8_t *)&nv->version;
5030 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5031 while (cnt--)
5032 *dptr1++ = *dptr2++;
5033
5034 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07005035 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005036
5037 /* Copy 2nd segment. */
5038 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5039 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5040 cnt = (uint8_t *)&icb->reserved_3 -
5041 (uint8_t *)&icb->interrupt_delay_timer;
5042 while (cnt--)
5043 *dptr1++ = *dptr2++;
5044
5045 /*
5046 * Setup driver NVRAM options.
5047 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005048 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08005049 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005050
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005051 qlt_24xx_config_nvram_stage2(vha, icb);
5052
Andrew Vasquez5341e862006-05-17 15:09:16 -07005053 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005054 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07005055 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5056 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5057 }
5058
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005059 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07005060 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005061 /*
5062 * Firmware will apply the following mask if the nodename was
5063 * not provided.
5064 */
5065 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5066 icb->node_name[0] &= 0xF0;
5067 }
5068
5069 /* Set host adapter parameters. */
5070 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08005071 ha->flags.enable_lip_reset = 0;
5072 ha->flags.enable_lip_full_login =
5073 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5074 ha->flags.enable_target_reset =
5075 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005076 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07005077 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005078
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07005079 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5080 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005081
5082 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
5083 sizeof(ha->fw_seriallink_options24));
5084
5085 /* save HBA serial number */
5086 ha->serial0 = icb->port_name[5];
5087 ha->serial1 = icb->port_name[6];
5088 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005089 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5090 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005091
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08005092 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5093
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005094 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5095
5096 /* Set minimum login_timeout to 4 seconds. */
5097 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5098 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5099 if (le16_to_cpu(nv->login_timeout) < 4)
5100 nv->login_timeout = __constant_cpu_to_le16(4);
5101 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07005102 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005103
Andrew Vasquez00a537b2008-02-28 14:06:11 -08005104 /* Set minimum RATOV to 100 tenths of a second. */
5105 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005106
5107 ha->loop_reset_delay = nv->reset_delay;
5108
5109 /* Link Down Timeout = 0:
5110 *
5111 * When Port Down timer expires we will start returning
5112 * I/O's to OS with "DID_NO_CONNECT".
5113 *
5114 * Link Down Timeout != 0:
5115 *
5116 * The driver waits for the link to come up after link down
5117 * before returning I/Os to OS with "DID_NO_CONNECT".
5118 */
5119 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5120 ha->loop_down_abort_time =
5121 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5122 } else {
5123 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5124 ha->loop_down_abort_time =
5125 (LOOP_DOWN_TIME - ha->link_down_timeout);
5126 }
5127
5128 /* Need enough time to try and get the port back. */
5129 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5130 if (qlport_down_retry)
5131 ha->port_down_retry_count = qlport_down_retry;
5132
5133 /* Set login_retry_count */
5134 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5135 if (ha->port_down_retry_count ==
5136 le16_to_cpu(nv->port_down_retry_count) &&
5137 ha->port_down_retry_count > 3)
5138 ha->login_retry_count = ha->port_down_retry_count;
5139 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5140 ha->login_retry_count = ha->port_down_retry_count;
5141 if (ql2xloginretrycount)
5142 ha->login_retry_count = ql2xloginretrycount;
5143
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005144 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005145 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005146 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5147 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5148 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5149 le16_to_cpu(icb->interrupt_delay_timer): 2;
5150 }
5151 icb->firmware_options_2 &= __constant_cpu_to_le32(
5152 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005153 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005154 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08005155 ha->zio_mode = QLA_ZIO_MODE_6;
5156
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005157 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005158 "ZIO mode %d enabled; timer delay (%d us).\n",
5159 ha->zio_mode, ha->zio_timer * 100);
5160
5161 icb->firmware_options_2 |= cpu_to_le32(
5162 (uint32_t)ha->zio_mode);
5163 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005164 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005165 }
5166
David Miller4e08df32007-04-16 12:37:43 -07005167 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005168 ql_log(ql_log_warn, vha, 0x0070,
5169 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07005170 }
5171 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005172}
5173
Adrian Bunk413975a2006-06-30 02:33:06 -07005174static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005175qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
5176 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005177{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005178 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005179 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005180 uint32_t *dcode, dlen;
5181 uint32_t risc_addr;
5182 uint32_t risc_size;
5183 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005184 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005185 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005186
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005187 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08005188 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005189
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005190 rval = QLA_SUCCESS;
5191
5192 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005193 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005194 *srisc_addr = 0;
5195
5196 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005197 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005198 for (i = 0; i < 4; i++)
5199 dcode[i] = be32_to_cpu(dcode[i]);
5200 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5201 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5202 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5203 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005204 ql_log(ql_log_fatal, vha, 0x008c,
5205 "Unable to verify the integrity of flash firmware "
5206 "image.\n");
5207 ql_log(ql_log_fatal, vha, 0x008d,
5208 "Firmware data: %08x %08x %08x %08x.\n",
5209 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005210
5211 return QLA_FUNCTION_FAILED;
5212 }
5213
5214 while (segments && rval == QLA_SUCCESS) {
5215 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005216 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005217
5218 risc_addr = be32_to_cpu(dcode[2]);
5219 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5220 risc_size = be32_to_cpu(dcode[3]);
5221
5222 fragment = 0;
5223 while (risc_size > 0 && rval == QLA_SUCCESS) {
5224 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5225 if (dlen > risc_size)
5226 dlen = risc_size;
5227
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005228 ql_dbg(ql_dbg_init, vha, 0x008e,
5229 "Loading risc segment@ risc addr %x "
5230 "number of dwords 0x%x offset 0x%x.\n",
5231 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005232
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005233 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005234 for (i = 0; i < dlen; i++)
5235 dcode[i] = swab32(dcode[i]);
5236
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005237 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005238 dlen);
5239 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005240 ql_log(ql_log_fatal, vha, 0x008f,
5241 "Failed to load segment %d of firmware.\n",
5242 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04005243 return QLA_FUNCTION_FAILED;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005244 }
5245
5246 faddr += dlen;
5247 risc_addr += dlen;
5248 risc_size -= dlen;
5249 fragment++;
5250 }
5251
5252 /* Next segment. */
5253 segments--;
5254 }
5255
Chad Dupuisf73cb692014-02-26 04:15:06 -05005256 if (!IS_QLA27XX(ha))
5257 return rval;
5258
5259 if (ha->fw_dump_template)
5260 vfree(ha->fw_dump_template);
5261 ha->fw_dump_template = NULL;
5262 ha->fw_dump_template_len = 0;
5263
5264 ql_dbg(ql_dbg_init, vha, 0x0161,
5265 "Loading fwdump template from %x\n", faddr);
5266 qla24xx_read_flash_data(vha, dcode, faddr, 7);
5267 risc_size = be32_to_cpu(dcode[2]);
5268 ql_dbg(ql_dbg_init, vha, 0x0162,
5269 "-> array size %x dwords\n", risc_size);
5270 if (risc_size == 0 || risc_size == ~0)
5271 goto default_template;
5272
5273 dlen = (risc_size - 8) * sizeof(*dcode);
5274 ql_dbg(ql_dbg_init, vha, 0x0163,
5275 "-> template allocating %x bytes...\n", dlen);
5276 ha->fw_dump_template = vmalloc(dlen);
5277 if (!ha->fw_dump_template) {
5278 ql_log(ql_log_warn, vha, 0x0164,
5279 "Failed fwdump template allocate %x bytes.\n", risc_size);
5280 goto default_template;
5281 }
5282
5283 faddr += 7;
5284 risc_size -= 8;
5285 dcode = ha->fw_dump_template;
5286 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
5287 for (i = 0; i < risc_size; i++)
5288 dcode[i] = le32_to_cpu(dcode[i]);
5289
5290 if (!qla27xx_fwdt_template_valid(dcode)) {
5291 ql_log(ql_log_warn, vha, 0x0165,
5292 "Failed fwdump template validate\n");
5293 goto default_template;
5294 }
5295
5296 dlen = qla27xx_fwdt_template_size(dcode);
5297 ql_dbg(ql_dbg_init, vha, 0x0166,
5298 "-> template size %x bytes\n", dlen);
5299 if (dlen > risc_size * sizeof(*dcode)) {
5300 ql_log(ql_log_warn, vha, 0x0167,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005301 "Failed fwdump template exceeds array by %x bytes\n",
5302 (uint32_t)(dlen - risc_size * sizeof(*dcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005303 goto default_template;
5304 }
5305 ha->fw_dump_template_len = dlen;
5306 return rval;
5307
5308default_template:
5309 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
5310 if (ha->fw_dump_template)
5311 vfree(ha->fw_dump_template);
5312 ha->fw_dump_template = NULL;
5313 ha->fw_dump_template_len = 0;
5314
5315 dlen = qla27xx_fwdt_template_default_size();
5316 ql_dbg(ql_dbg_init, vha, 0x0169,
5317 "-> template allocating %x bytes...\n", dlen);
5318 ha->fw_dump_template = vmalloc(dlen);
5319 if (!ha->fw_dump_template) {
5320 ql_log(ql_log_warn, vha, 0x016a,
5321 "Failed fwdump template allocate %x bytes.\n", risc_size);
5322 goto failed_template;
5323 }
5324
5325 dcode = ha->fw_dump_template;
5326 risc_size = dlen / sizeof(*dcode);
5327 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
5328 for (i = 0; i < risc_size; i++)
5329 dcode[i] = be32_to_cpu(dcode[i]);
5330
5331 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5332 ql_log(ql_log_warn, vha, 0x016b,
5333 "Failed fwdump template validate\n");
5334 goto failed_template;
5335 }
5336
5337 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5338 ql_dbg(ql_dbg_init, vha, 0x016c,
5339 "-> template size %x bytes\n", dlen);
5340 ha->fw_dump_template_len = dlen;
5341 return rval;
5342
5343failed_template:
5344 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
5345 if (ha->fw_dump_template)
5346 vfree(ha->fw_dump_template);
5347 ha->fw_dump_template = NULL;
5348 ha->fw_dump_template_len = 0;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005349 return rval;
5350}
5351
Giridhar Malavalie9454a82013-02-08 01:57:47 -05005352#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005353
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005354int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005355qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08005356{
5357 int rval;
5358 int i, fragment;
5359 uint16_t *wcode, *fwcode;
5360 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
5361 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005362 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005363 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08005364
5365 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005366 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005367 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005368 ql_log(ql_log_info, vha, 0x0083,
5369 "Fimware image unavailable.\n");
5370 ql_log(ql_log_info, vha, 0x0084,
5371 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08005372 return QLA_FUNCTION_FAILED;
5373 }
5374
5375 rval = QLA_SUCCESS;
5376
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005377 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08005378 *srisc_addr = 0;
5379 fwcode = (uint16_t *)blob->fw->data;
5380 fwclen = 0;
5381
5382 /* Validate firmware image by checking version. */
5383 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005384 ql_log(ql_log_fatal, vha, 0x0085,
5385 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005386 blob->fw->size);
5387 goto fail_fw_integrity;
5388 }
5389 for (i = 0; i < 4; i++)
5390 wcode[i] = be16_to_cpu(fwcode[i + 4]);
5391 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
5392 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
5393 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005394 ql_log(ql_log_fatal, vha, 0x0086,
5395 "Unable to verify integrity of firmware image.\n");
5396 ql_log(ql_log_fatal, vha, 0x0087,
5397 "Firmware data: %04x %04x %04x %04x.\n",
5398 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08005399 goto fail_fw_integrity;
5400 }
5401
5402 seg = blob->segs;
5403 while (*seg && rval == QLA_SUCCESS) {
5404 risc_addr = *seg;
5405 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
5406 risc_size = be16_to_cpu(fwcode[3]);
5407
5408 /* Validate firmware image size. */
5409 fwclen += risc_size * sizeof(uint16_t);
5410 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005411 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08005412 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005413 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08005414 goto fail_fw_integrity;
5415 }
5416
5417 fragment = 0;
5418 while (risc_size > 0 && rval == QLA_SUCCESS) {
5419 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
5420 if (wlen > risc_size)
5421 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005422 ql_dbg(ql_dbg_init, vha, 0x0089,
5423 "Loading risc segment@ risc addr %x number of "
5424 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08005425
5426 for (i = 0; i < wlen; i++)
5427 wcode[i] = swab16(fwcode[i]);
5428
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005429 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08005430 wlen);
5431 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005432 ql_log(ql_log_fatal, vha, 0x008a,
5433 "Failed to load segment %d of firmware.\n",
5434 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08005435 break;
5436 }
5437
5438 fwcode += wlen;
5439 risc_addr += wlen;
5440 risc_size -= wlen;
5441 fragment++;
5442 }
5443
5444 /* Next segment. */
5445 seg++;
5446 }
5447 return rval;
5448
5449fail_fw_integrity:
5450 return QLA_FUNCTION_FAILED;
5451}
5452
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005453static int
5454qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005455{
5456 int rval;
5457 int segments, fragment;
5458 uint32_t *dcode, dlen;
5459 uint32_t risc_addr;
5460 uint32_t risc_size;
5461 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08005462 struct fw_blob *blob;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005463 const uint32_t *fwcode;
5464 uint32_t fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005465 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005466 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005467
Andrew Vasquez54333832005-11-09 15:49:04 -08005468 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005469 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005470 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005471 ql_log(ql_log_warn, vha, 0x0090,
5472 "Fimware image unavailable.\n");
5473 ql_log(ql_log_warn, vha, 0x0091,
5474 "Firmware images can be retrieved from: "
5475 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005476
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005477 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005478 }
5479
Chad Dupuiscfb09192011-11-18 09:03:07 -08005480 ql_dbg(ql_dbg_init, vha, 0x0092,
5481 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005482
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005483 rval = QLA_SUCCESS;
5484
5485 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005486 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005487 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08005488 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005489 fwclen = 0;
5490
5491 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08005492 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005493 ql_log(ql_log_fatal, vha, 0x0093,
5494 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005495 blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005496 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005497 }
5498 for (i = 0; i < 4; i++)
5499 dcode[i] = be32_to_cpu(fwcode[i + 4]);
5500 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5501 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5502 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5503 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005504 ql_log(ql_log_fatal, vha, 0x0094,
5505 "Unable to verify integrity of firmware image (%Zd).\n",
5506 blob->fw->size);
5507 ql_log(ql_log_fatal, vha, 0x0095,
5508 "Firmware data: %08x %08x %08x %08x.\n",
5509 dcode[0], dcode[1], dcode[2], dcode[3]);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005510 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005511 }
5512
5513 while (segments && rval == QLA_SUCCESS) {
5514 risc_addr = be32_to_cpu(fwcode[2]);
5515 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5516 risc_size = be32_to_cpu(fwcode[3]);
5517
5518 /* Validate firmware image size. */
5519 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08005520 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005521 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08005522 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005523 "(%Zd).\n", blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005524 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005525 }
5526
5527 fragment = 0;
5528 while (risc_size > 0 && rval == QLA_SUCCESS) {
5529 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5530 if (dlen > risc_size)
5531 dlen = risc_size;
5532
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005533 ql_dbg(ql_dbg_init, vha, 0x0097,
5534 "Loading risc segment@ risc addr %x "
5535 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005536
5537 for (i = 0; i < dlen; i++)
5538 dcode[i] = swab32(fwcode[i]);
5539
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005540 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08005541 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005542 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005543 ql_log(ql_log_fatal, vha, 0x0098,
5544 "Failed to load segment %d of firmware.\n",
5545 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04005546 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005547 }
5548
5549 fwcode += dlen;
5550 risc_addr += dlen;
5551 risc_size -= dlen;
5552 fragment++;
5553 }
5554
5555 /* Next segment. */
5556 segments--;
5557 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05005558
5559 if (!IS_QLA27XX(ha))
5560 return rval;
5561
5562 if (ha->fw_dump_template)
5563 vfree(ha->fw_dump_template);
5564 ha->fw_dump_template = NULL;
5565 ha->fw_dump_template_len = 0;
5566
5567 ql_dbg(ql_dbg_init, vha, 0x171,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005568 "Loading fwdump template from %x\n",
5569 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005570 risc_size = be32_to_cpu(fwcode[2]);
5571 ql_dbg(ql_dbg_init, vha, 0x172,
5572 "-> array size %x dwords\n", risc_size);
5573 if (risc_size == 0 || risc_size == ~0)
5574 goto default_template;
5575
5576 dlen = (risc_size - 8) * sizeof(*fwcode);
5577 ql_dbg(ql_dbg_init, vha, 0x0173,
5578 "-> template allocating %x bytes...\n", dlen);
5579 ha->fw_dump_template = vmalloc(dlen);
5580 if (!ha->fw_dump_template) {
5581 ql_log(ql_log_warn, vha, 0x0174,
5582 "Failed fwdump template allocate %x bytes.\n", risc_size);
5583 goto default_template;
5584 }
5585
5586 fwcode += 7;
5587 risc_size -= 8;
5588 dcode = ha->fw_dump_template;
5589 for (i = 0; i < risc_size; i++)
5590 dcode[i] = le32_to_cpu(fwcode[i]);
5591
5592 if (!qla27xx_fwdt_template_valid(dcode)) {
5593 ql_log(ql_log_warn, vha, 0x0175,
5594 "Failed fwdump template validate\n");
5595 goto default_template;
5596 }
5597
5598 dlen = qla27xx_fwdt_template_size(dcode);
5599 ql_dbg(ql_dbg_init, vha, 0x0176,
5600 "-> template size %x bytes\n", dlen);
5601 if (dlen > risc_size * sizeof(*fwcode)) {
5602 ql_log(ql_log_warn, vha, 0x0177,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005603 "Failed fwdump template exceeds array by %x bytes\n",
5604 (uint32_t)(dlen - risc_size * sizeof(*fwcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005605 goto default_template;
5606 }
5607 ha->fw_dump_template_len = dlen;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005608 return rval;
5609
Chad Dupuisf73cb692014-02-26 04:15:06 -05005610default_template:
5611 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
5612 if (ha->fw_dump_template)
5613 vfree(ha->fw_dump_template);
5614 ha->fw_dump_template = NULL;
5615 ha->fw_dump_template_len = 0;
5616
5617 dlen = qla27xx_fwdt_template_default_size();
5618 ql_dbg(ql_dbg_init, vha, 0x0179,
5619 "-> template allocating %x bytes...\n", dlen);
5620 ha->fw_dump_template = vmalloc(dlen);
5621 if (!ha->fw_dump_template) {
5622 ql_log(ql_log_warn, vha, 0x017a,
5623 "Failed fwdump template allocate %x bytes.\n", risc_size);
5624 goto failed_template;
5625 }
5626
5627 dcode = ha->fw_dump_template;
5628 risc_size = dlen / sizeof(*fwcode);
5629 fwcode = qla27xx_fwdt_template_default();
5630 for (i = 0; i < risc_size; i++)
5631 dcode[i] = be32_to_cpu(fwcode[i]);
5632
5633 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5634 ql_log(ql_log_warn, vha, 0x017b,
5635 "Failed fwdump template validate\n");
5636 goto failed_template;
5637 }
5638
5639 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5640 ql_dbg(ql_dbg_init, vha, 0x017c,
5641 "-> template size %x bytes\n", dlen);
5642 ha->fw_dump_template_len = dlen;
5643 return rval;
5644
5645failed_template:
5646 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
5647 if (ha->fw_dump_template)
5648 vfree(ha->fw_dump_template);
5649 ha->fw_dump_template = NULL;
5650 ha->fw_dump_template_len = 0;
5651 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005652}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005653
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005654int
5655qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5656{
5657 int rval;
5658
Andrew Vasqueze337d902009-04-06 22:33:49 -07005659 if (ql2xfwloadbin == 1)
5660 return qla81xx_load_risc(vha, srisc_addr);
5661
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005662 /*
5663 * FW Load priority:
5664 * 1) Firmware via request-firmware interface (.bin file).
5665 * 2) Firmware residing in flash.
5666 */
5667 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5668 if (rval == QLA_SUCCESS)
5669 return rval;
5670
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005671 return qla24xx_load_risc_flash(vha, srisc_addr,
5672 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005673}
5674
5675int
5676qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5677{
5678 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005679 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005680
Andrew Vasqueze337d902009-04-06 22:33:49 -07005681 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005682 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07005683
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005684 /*
5685 * FW Load priority:
5686 * 1) Firmware residing in flash.
5687 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005688 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005689 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005690 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005691 if (rval == QLA_SUCCESS)
5692 return rval;
5693
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005694try_blob_fw:
5695 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5696 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
5697 return rval;
5698
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005699 ql_log(ql_log_info, vha, 0x0099,
5700 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005701 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
5702 if (rval != QLA_SUCCESS)
5703 return rval;
5704
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005705 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005706 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005707 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005708}
5709
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005710void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005711qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005712{
5713 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005714 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005715
Andrew Vasquez85880802009-12-15 21:29:46 -08005716 if (ha->flags.pci_channel_io_perm_failure)
5717 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07005718 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005719 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07005720 if (!ha->fw_major_version)
5721 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005722
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005723 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08005724 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07005725 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005726 ha->isp_ops->reset_chip(vha);
5727 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005728 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005729 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005730 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005731 ql_log(ql_log_info, vha, 0x8015,
5732 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005733 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005734 }
5735}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005736
5737int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005738qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005739{
5740 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08005741 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005742 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005743 struct qla_hw_data *ha = vha->hw;
5744 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005745 struct req_que *req;
5746 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005747
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005748 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005749 return -EINVAL;
5750
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005751 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07005752 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005753 req = ha->req_q_map[0];
5754 else
5755 req = vha->req;
5756 rsp = req->rsp;
5757
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005758 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005759 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005760 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005761 }
5762
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005763 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005764
5765 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08005766 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
5767 BIT_1);
5768 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5769 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
5770 ql_dbg(ql_dbg_init, vha, 0x0120,
5771 "Failed SNS login: loop_id=%x, rval2=%d\n",
5772 NPH_SNS, rval2);
5773 else
5774 ql_dbg(ql_dbg_init, vha, 0x0103,
5775 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5776 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
5777 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005778 return (QLA_FUNCTION_FAILED);
5779 }
5780
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005781 atomic_set(&vha->loop_down_timer, 0);
5782 atomic_set(&vha->loop_state, LOOP_UP);
5783 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5784 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5785 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005786
5787 return rval;
5788}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005789
5790/* 84XX Support **************************************************************/
5791
5792static LIST_HEAD(qla_cs84xx_list);
5793static DEFINE_MUTEX(qla_cs84xx_mutex);
5794
5795static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005796qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005797{
5798 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005799 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005800
5801 mutex_lock(&qla_cs84xx_mutex);
5802
5803 /* Find any shared 84xx chip. */
5804 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5805 if (cs84xx->bus == ha->pdev->bus) {
5806 kref_get(&cs84xx->kref);
5807 goto done;
5808 }
5809 }
5810
5811 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5812 if (!cs84xx)
5813 goto done;
5814
5815 kref_init(&cs84xx->kref);
5816 spin_lock_init(&cs84xx->access_lock);
5817 mutex_init(&cs84xx->fw_update_mutex);
5818 cs84xx->bus = ha->pdev->bus;
5819
5820 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5821done:
5822 mutex_unlock(&qla_cs84xx_mutex);
5823 return cs84xx;
5824}
5825
5826static void
5827__qla84xx_chip_release(struct kref *kref)
5828{
5829 struct qla_chip_state_84xx *cs84xx =
5830 container_of(kref, struct qla_chip_state_84xx, kref);
5831
5832 mutex_lock(&qla_cs84xx_mutex);
5833 list_del(&cs84xx->list);
5834 mutex_unlock(&qla_cs84xx_mutex);
5835 kfree(cs84xx);
5836}
5837
5838void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005839qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005840{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005841 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005842 if (ha->cs84xx)
5843 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
5844}
5845
5846static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005847qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005848{
5849 int rval;
5850 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005851 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005852
5853 mutex_lock(&ha->cs84xx->fw_update_mutex);
5854
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005855 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005856
5857 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5858
5859 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5860 QLA_SUCCESS;
5861}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005862
5863/* 81XX Support **************************************************************/
5864
5865int
5866qla81xx_nvram_config(scsi_qla_host_t *vha)
5867{
5868 int rval;
5869 struct init_cb_81xx *icb;
5870 struct nvram_81xx *nv;
5871 uint32_t *dptr;
5872 uint8_t *dptr1, *dptr2;
5873 uint32_t chksum;
5874 uint16_t cnt;
5875 struct qla_hw_data *ha = vha->hw;
5876
5877 rval = QLA_SUCCESS;
5878 icb = (struct init_cb_81xx *)ha->init_cb;
5879 nv = ha->nvram;
5880
5881 /* Determine NVRAM starting address. */
5882 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005883 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005884 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
5885 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005886
5887 /* Get VPD data into cache */
5888 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005889 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5890 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005891
5892 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005893 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005894 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005895 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005896 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5897 chksum += le32_to_cpu(*dptr++);
5898
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005899 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
5900 "Contents of NVRAM:\n");
5901 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
5902 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005903
5904 /* Bad NVRAM data, set defaults parameters. */
5905 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5906 || nv->id[3] != ' ' ||
5907 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5908 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005909 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04005910 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005911 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005912 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005913 ql_log(ql_log_info, vha, 0x0074,
5914 "Falling back to functioning (yet invalid -- WWPN) "
5915 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005916
5917 /*
5918 * Set default initialization control block.
5919 */
5920 memset(nv, 0, ha->nvram_size);
5921 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5922 nv->version = __constant_cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04005923 nv->frame_payload_size = 2048;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005924 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5925 nv->exchange_count = __constant_cpu_to_le16(0);
5926 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005927 nv->port_name[1] = 0x00 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005928 nv->port_name[2] = 0x00;
5929 nv->port_name[3] = 0xe0;
5930 nv->port_name[4] = 0x8b;
5931 nv->port_name[5] = 0x1c;
5932 nv->port_name[6] = 0x55;
5933 nv->port_name[7] = 0x86;
5934 nv->node_name[0] = 0x20;
5935 nv->node_name[1] = 0x00;
5936 nv->node_name[2] = 0x00;
5937 nv->node_name[3] = 0xe0;
5938 nv->node_name[4] = 0x8b;
5939 nv->node_name[5] = 0x1c;
5940 nv->node_name[6] = 0x55;
5941 nv->node_name[7] = 0x86;
5942 nv->login_retry_count = __constant_cpu_to_le16(8);
5943 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5944 nv->login_timeout = __constant_cpu_to_le16(0);
5945 nv->firmware_options_1 =
5946 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5947 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5948 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5949 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5950 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5951 nv->efi_parameters = __constant_cpu_to_le32(0);
5952 nv->reset_delay = 5;
5953 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5954 nv->port_down_retry_count = __constant_cpu_to_le16(30);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005955 nv->link_down_timeout = __constant_cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005956 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005957 nv->enode_mac[1] = 0xC0;
5958 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005959 nv->enode_mac[3] = 0x04;
5960 nv->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005961 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005962
5963 rval = 1;
5964 }
5965
Arun Easi9e522cd2012-08-22 14:21:31 -04005966 if (IS_T10_PI_CAPABLE(ha))
5967 nv->frame_payload_size &= ~7;
5968
Arun Easiaa230bc2013-01-30 03:34:39 -05005969 qlt_81xx_config_nvram_stage1(vha, nv);
5970
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005971 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07005972 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005973
5974 /* Copy 1st segment. */
5975 dptr1 = (uint8_t *)icb;
5976 dptr2 = (uint8_t *)&nv->version;
5977 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5978 while (cnt--)
5979 *dptr1++ = *dptr2++;
5980
5981 icb->login_retry_count = nv->login_retry_count;
5982
5983 /* Copy 2nd segment. */
5984 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5985 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5986 cnt = (uint8_t *)&icb->reserved_5 -
5987 (uint8_t *)&icb->interrupt_delay_timer;
5988 while (cnt--)
5989 *dptr1++ = *dptr2++;
5990
5991 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5992 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5993 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08005994 icb->enode_mac[0] = 0x00;
5995 icb->enode_mac[1] = 0xC0;
5996 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005997 icb->enode_mac[3] = 0x04;
5998 icb->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005999 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006000 }
6001
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07006002 /* Use extended-initialization control block. */
6003 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
6004
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006005 /*
6006 * Setup driver NVRAM options.
6007 */
6008 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07006009 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006010
Arun Easiaa230bc2013-01-30 03:34:39 -05006011 qlt_81xx_config_nvram_stage2(vha, icb);
6012
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006013 /* Use alternate WWN? */
6014 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
6015 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6016 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6017 }
6018
6019 /* Prepare nodename */
6020 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
6021 /*
6022 * Firmware will apply the following mask if the nodename was
6023 * not provided.
6024 */
6025 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6026 icb->node_name[0] &= 0xF0;
6027 }
6028
6029 /* Set host adapter parameters. */
6030 ha->flags.disable_risc_code_load = 0;
6031 ha->flags.enable_lip_reset = 0;
6032 ha->flags.enable_lip_full_login =
6033 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6034 ha->flags.enable_target_reset =
6035 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
6036 ha->flags.enable_led_scheme = 0;
6037 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
6038
6039 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6040 (BIT_6 | BIT_5 | BIT_4)) >> 4;
6041
6042 /* save HBA serial number */
6043 ha->serial0 = icb->port_name[5];
6044 ha->serial1 = icb->port_name[6];
6045 ha->serial2 = icb->port_name[7];
6046 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6047 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
6048
6049 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
6050
6051 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6052
6053 /* Set minimum login_timeout to 4 seconds. */
6054 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6055 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6056 if (le16_to_cpu(nv->login_timeout) < 4)
6057 nv->login_timeout = __constant_cpu_to_le16(4);
6058 ha->login_timeout = le16_to_cpu(nv->login_timeout);
6059 icb->login_timeout = nv->login_timeout;
6060
6061 /* Set minimum RATOV to 100 tenths of a second. */
6062 ha->r_a_tov = 100;
6063
6064 ha->loop_reset_delay = nv->reset_delay;
6065
6066 /* Link Down Timeout = 0:
6067 *
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006068 * When Port Down timer expires we will start returning
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006069 * I/O's to OS with "DID_NO_CONNECT".
6070 *
6071 * Link Down Timeout != 0:
6072 *
6073 * The driver waits for the link to come up after link down
6074 * before returning I/Os to OS with "DID_NO_CONNECT".
6075 */
6076 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6077 ha->loop_down_abort_time =
6078 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6079 } else {
6080 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6081 ha->loop_down_abort_time =
6082 (LOOP_DOWN_TIME - ha->link_down_timeout);
6083 }
6084
6085 /* Need enough time to try and get the port back. */
6086 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6087 if (qlport_down_retry)
6088 ha->port_down_retry_count = qlport_down_retry;
6089
6090 /* Set login_retry_count */
6091 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6092 if (ha->port_down_retry_count ==
6093 le16_to_cpu(nv->port_down_retry_count) &&
6094 ha->port_down_retry_count > 3)
6095 ha->login_retry_count = ha->port_down_retry_count;
6096 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6097 ha->login_retry_count = ha->port_down_retry_count;
6098 if (ql2xloginretrycount)
6099 ha->login_retry_count = ql2xloginretrycount;
6100
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006101 /* if not running MSI-X we need handshaking on interrupts */
Chad Dupuisf73cb692014-02-26 04:15:06 -05006102 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006103 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
6104
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006105 /* Enable ZIO. */
6106 if (!vha->flags.init_done) {
6107 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6108 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6109 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6110 le16_to_cpu(icb->interrupt_delay_timer): 2;
6111 }
6112 icb->firmware_options_2 &= __constant_cpu_to_le32(
6113 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
6114 vha->flags.process_response_queue = 0;
6115 if (ha->zio_mode != QLA_ZIO_DISABLED) {
6116 ha->zio_mode = QLA_ZIO_MODE_6;
6117
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006118 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006119 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006120 ha->zio_mode,
6121 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006122
6123 icb->firmware_options_2 |= cpu_to_le32(
6124 (uint32_t)ha->zio_mode);
6125 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
6126 vha->flags.process_response_queue = 1;
6127 }
6128
6129 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006130 ql_log(ql_log_warn, vha, 0x0076,
6131 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006132 }
6133 return (rval);
6134}
6135
Giridhar Malavalia9083012010-04-12 17:59:55 -07006136int
6137qla82xx_restart_isp(scsi_qla_host_t *vha)
6138{
6139 int status, rval;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006140 struct qla_hw_data *ha = vha->hw;
6141 struct req_que *req = ha->req_q_map[0];
6142 struct rsp_que *rsp = ha->rsp_q_map[0];
6143 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07006144 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006145
6146 status = qla2x00_init_rings(vha);
6147 if (!status) {
6148 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6149 ha->flags.chip_reset_done = 1;
6150
6151 status = qla2x00_fw_ready(vha);
6152 if (!status) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07006153 /* Issue a marker after FW becomes ready. */
6154 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006155 vha->flags.online = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04006156 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006157 }
6158
6159 /* if no cable then assume it's good */
6160 if ((vha->device_flags & DFLG_NO_CABLE))
6161 status = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006162 }
6163
6164 if (!status) {
6165 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6166
6167 if (!atomic_read(&vha->loop_down_timer)) {
6168 /*
6169 * Issue marker command only when we are going
6170 * to start the I/O .
6171 */
6172 vha->marker_needed = 1;
6173 }
6174
Giridhar Malavalia9083012010-04-12 17:59:55 -07006175 ha->isp_ops->enable_intrs(ha);
6176
6177 ha->isp_abort_cnt = 0;
6178 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6179
Saurav Kashyap53296782011-05-10 11:30:06 -07006180 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07006181 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07006182
Giridhar Malavalia9083012010-04-12 17:59:55 -07006183 if (ha->fce) {
6184 ha->flags.fce_enabled = 1;
6185 memset(ha->fce, 0,
6186 fce_calc_size(ha->fce_bufs));
6187 rval = qla2x00_enable_fce_trace(vha,
6188 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6189 &ha->fce_bufs);
6190 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006191 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006192 "Unable to reinitialize FCE (%d).\n",
6193 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006194 ha->flags.fce_enabled = 0;
6195 }
6196 }
6197
6198 if (ha->eft) {
6199 memset(ha->eft, 0, EFT_SIZE);
6200 rval = qla2x00_enable_eft_trace(vha,
6201 ha->eft_dma, EFT_NUM_BUFFERS);
6202 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006203 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006204 "Unable to reinitialize EFT (%d).\n",
6205 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006206 }
6207 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006208 }
6209
6210 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006211 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006212 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07006213
6214 spin_lock_irqsave(&ha->vport_slock, flags);
6215 list_for_each_entry(vp, &ha->vp_list, list) {
6216 if (vp->vp_idx) {
6217 atomic_inc(&vp->vref_count);
6218 spin_unlock_irqrestore(&ha->vport_slock, flags);
6219
Giridhar Malavalia9083012010-04-12 17:59:55 -07006220 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07006221
6222 spin_lock_irqsave(&ha->vport_slock, flags);
6223 atomic_dec(&vp->vref_count);
6224 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006225 }
Arun Easifeafb7b2010-09-03 14:57:00 -07006226 spin_unlock_irqrestore(&ha->vport_slock, flags);
6227
Giridhar Malavalia9083012010-04-12 17:59:55 -07006228 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006229 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006230 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006231 }
6232
6233 return status;
6234}
6235
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006236void
Andrew Vasquezae97c912010-02-18 10:07:28 -08006237qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006238{
Andrew Vasquezae97c912010-02-18 10:07:28 -08006239 struct qla_hw_data *ha = vha->hw;
6240
6241 if (!ql2xetsenable)
6242 return;
6243
6244 /* Enable ETS Burst. */
6245 memset(ha->fw_options, 0, sizeof(ha->fw_options));
6246 ha->fw_options[2] |= BIT_9;
6247 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006248}
Sarang Radke09ff7012010-03-19 17:03:59 -07006249
6250/*
6251 * qla24xx_get_fcp_prio
6252 * Gets the fcp cmd priority value for the logged in port.
6253 * Looks for a match of the port descriptors within
6254 * each of the fcp prio config entries. If a match is found,
6255 * the tag (priority) value is returned.
6256 *
6257 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006258 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07006259 * fcport = port structure pointer.
6260 *
6261 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07006262 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006263 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07006264 *
6265 * Context:
6266 * Kernel context
6267 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006268static int
Sarang Radke09ff7012010-03-19 17:03:59 -07006269qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
6270{
6271 int i, entries;
6272 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006273 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07006274 uint32_t pid1, pid2;
6275 uint64_t wwn1, wwn2;
6276 struct qla_fcp_prio_entry *pri_entry;
6277 struct qla_hw_data *ha = vha->hw;
6278
6279 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006280 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07006281
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006282 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07006283 entries = ha->fcp_prio_cfg->num_entries;
6284 pri_entry = &ha->fcp_prio_cfg->entry[0];
6285
6286 for (i = 0; i < entries; i++) {
6287 pid_match = wwn_match = 0;
6288
6289 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
6290 pri_entry++;
6291 continue;
6292 }
6293
6294 /* check source pid for a match */
6295 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
6296 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
6297 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
6298 if (pid1 == INVALID_PORT_ID)
6299 pid_match++;
6300 else if (pid1 == pid2)
6301 pid_match++;
6302 }
6303
6304 /* check destination pid for a match */
6305 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
6306 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
6307 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
6308 if (pid1 == INVALID_PORT_ID)
6309 pid_match++;
6310 else if (pid1 == pid2)
6311 pid_match++;
6312 }
6313
6314 /* check source WWN for a match */
6315 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
6316 wwn1 = wwn_to_u64(vha->port_name);
6317 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
6318 if (wwn2 == (uint64_t)-1)
6319 wwn_match++;
6320 else if (wwn1 == wwn2)
6321 wwn_match++;
6322 }
6323
6324 /* check destination WWN for a match */
6325 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
6326 wwn1 = wwn_to_u64(fcport->port_name);
6327 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
6328 if (wwn2 == (uint64_t)-1)
6329 wwn_match++;
6330 else if (wwn1 == wwn2)
6331 wwn_match++;
6332 }
6333
6334 if (pid_match == 2 || wwn_match == 2) {
6335 /* Found a matching entry */
6336 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
6337 priority = pri_entry->tag;
6338 break;
6339 }
6340
6341 pri_entry++;
6342 }
6343
6344 return priority;
6345}
6346
6347/*
6348 * qla24xx_update_fcport_fcp_prio
6349 * Activates fcp priority for the logged in fc port
6350 *
6351 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006352 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07006353 * fcp = port structure pointer.
6354 *
6355 * Return:
6356 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6357 *
6358 * Context:
6359 * Kernel context.
6360 */
6361int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006362qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07006363{
6364 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006365 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07006366 uint16_t mb[5];
6367
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006368 if (fcport->port_type != FCT_TARGET ||
6369 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07006370 return QLA_FUNCTION_FAILED;
6371
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006372 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006373 if (priority < 0)
6374 return QLA_FUNCTION_FAILED;
6375
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006376 if (IS_P3P_TYPE(vha->hw)) {
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006377 fcport->fcp_prio = priority & 0xf;
6378 return QLA_SUCCESS;
6379 }
6380
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006381 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08006382 if (ret == QLA_SUCCESS) {
6383 if (fcport->fcp_prio != priority)
6384 ql_dbg(ql_dbg_user, vha, 0x709e,
6385 "Updated FCP_CMND priority - value=%d loop_id=%d "
6386 "port_id=%02x%02x%02x.\n", priority,
6387 fcport->loop_id, fcport->d_id.b.domain,
6388 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006389 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08006390 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006391 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006392 "Unable to update FCP_CMND priority - ret=0x%x for "
6393 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
6394 fcport->d_id.b.domain, fcport->d_id.b.area,
6395 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07006396 return ret;
6397}
6398
6399/*
6400 * qla24xx_update_all_fcp_prio
6401 * Activates fcp priority for all the logged in ports
6402 *
6403 * Input:
6404 * ha = adapter block pointer.
6405 *
6406 * Return:
6407 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6408 *
6409 * Context:
6410 * Kernel context.
6411 */
6412int
6413qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
6414{
6415 int ret;
6416 fc_port_t *fcport;
6417
6418 ret = QLA_FUNCTION_FAILED;
6419 /* We need to set priority for all logged in ports */
6420 list_for_each_entry(fcport, &vha->vp_fcports, list)
6421 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
6422
6423 return ret;
6424}