blob: 014f44f7a7c44689ec4b023287a25da05e2c7bed [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 Khoshaba7b8335582013-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");
Bart Van Assche8d2b21d2015-06-04 15:58:09 -0700711 qla84xx_put_chip(vha);
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800712 }
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 */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001124static inline int
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;
Bart Van Assche52c82822015-07-09 07:23:26 -07001130 uint32_t cnt;
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 */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001133 int rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001134
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001135 spin_lock_irqsave(&ha->hardware_lock, flags);
1136
1137 /* Reset RISC. */
1138 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1139 for (cnt = 0; cnt < 30000; cnt++) {
1140 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
1141 break;
1142
1143 udelay(10);
1144 }
1145
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001146 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE))
1147 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
1148
1149 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
1150 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
1151 RD_REG_DWORD(&reg->hccr),
1152 RD_REG_DWORD(&reg->ctrl_status),
1153 (RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE));
1154
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001155 WRT_REG_DWORD(&reg->ctrl_status,
1156 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001157 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001158
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001159 udelay(100);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001160
Andrew Vasquez88c26662005-07-08 17:59:26 -07001161 /* Wait for firmware to complete NVRAM accesses. */
Bart Van Assche52c82822015-07-09 07:23:26 -07001162 RD_REG_WORD(&reg->mailbox0);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001163 for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
1164 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez88c26662005-07-08 17:59:26 -07001165 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001166 if (cnt)
1167 udelay(5);
1168 else
1169 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez88c26662005-07-08 17:59:26 -07001170 }
1171
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001172 if (rval == QLA_SUCCESS)
1173 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
1174
1175 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
1176 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
1177 RD_REG_DWORD(&reg->hccr),
1178 RD_REG_DWORD(&reg->mailbox0));
1179
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001180 /* Wait for soft-reset to complete. */
Bart Van Assche52c82822015-07-09 07:23:26 -07001181 RD_REG_DWORD(&reg->ctrl_status);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001182 for (cnt = 0; cnt < 6000000; cnt++) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001183 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001184 if ((RD_REG_DWORD(&reg->ctrl_status) &
1185 CSRX_ISP_SOFT_RESET) == 0)
1186 break;
1187
1188 udelay(5);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001189 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001190 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_ISP_SOFT_RESET))
1191 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
1192
1193 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
1194 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
1195 RD_REG_DWORD(&reg->hccr),
1196 RD_REG_DWORD(&reg->ctrl_status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001197
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001198 /* If required, do an MPI FW reset now */
1199 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1200 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1201 if (++abts_cnt < 5) {
1202 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1203 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1204 } else {
1205 /*
1206 * We exhausted the ISP abort retries. We have to
1207 * set the board offline.
1208 */
1209 abts_cnt = 0;
1210 vha->flags.online = 0;
1211 }
1212 }
1213 }
1214
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001215 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1216 RD_REG_DWORD(&reg->hccr);
1217
1218 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1219 RD_REG_DWORD(&reg->hccr);
1220
1221 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1222 RD_REG_DWORD(&reg->hccr);
1223
Bart Van Assche52c82822015-07-09 07:23:26 -07001224 RD_REG_WORD(&reg->mailbox0);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001225 for (cnt = 6000000; RD_REG_WORD(&reg->mailbox0) != 0 &&
1226 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001227 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001228 if (cnt)
1229 udelay(5);
1230 else
1231 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001232 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001233 if (rval == QLA_SUCCESS)
1234 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
1235
1236 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
1237 "Host Risc 0x%x, mailbox0 0x%x\n",
1238 RD_REG_DWORD(&reg->hccr),
1239 RD_REG_WORD(&reg->mailbox0));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001240
1241 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001242
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001243 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
1244 "Driver in %s mode\n",
1245 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
1246
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001247 if (IS_NOPOLLING_TYPE(ha))
1248 ha->isp_ops->enable_intrs(ha);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001249
1250 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001251}
1252
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001253static void
1254qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
1255{
1256 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1257
1258 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1259 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
1260
1261}
1262
1263static void
1264qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
1265{
1266 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1267
1268 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1269 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
1270}
1271
1272static void
1273qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
1274{
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001275 uint32_t wd32 = 0;
1276 uint delta_msec = 100;
1277 uint elapsed_msec = 0;
1278 uint timeout_msec;
1279 ulong n;
1280
Joe Carnucciocc790762015-08-04 13:37:53 -04001281 if (vha->hw->pdev->subsystem_device != 0x0175 &&
1282 vha->hw->pdev->subsystem_device != 0x0240)
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001283 return;
1284
Joe Carnuccio8dd7e3a2015-08-04 13:37:54 -04001285 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
1286 udelay(100);
1287
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001288attempt:
1289 timeout_msec = TIMEOUT_SEMAPHORE;
1290 n = timeout_msec / delta_msec;
1291 while (n--) {
1292 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
1293 qla25xx_read_risc_sema_reg(vha, &wd32);
1294 if (wd32 & RISC_SEMAPHORE)
1295 break;
1296 msleep(delta_msec);
1297 elapsed_msec += delta_msec;
1298 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1299 goto force;
1300 }
1301
1302 if (!(wd32 & RISC_SEMAPHORE))
1303 goto force;
1304
1305 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1306 goto acquired;
1307
1308 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
1309 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
1310 n = timeout_msec / delta_msec;
1311 while (n--) {
1312 qla25xx_read_risc_sema_reg(vha, &wd32);
1313 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1314 break;
1315 msleep(delta_msec);
1316 elapsed_msec += delta_msec;
1317 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1318 goto force;
1319 }
1320
1321 if (wd32 & RISC_SEMAPHORE_FORCE)
1322 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
1323
1324 goto attempt;
1325
1326force:
1327 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
1328
1329acquired:
1330 return;
1331}
1332
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001333/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001334 * qla24xx_reset_chip() - Reset ISP24xx chip.
1335 * @ha: HA context
1336 *
1337 * Returns 0 on success.
1338 */
1339void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001340qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001341{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001342 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001343
1344 if (pci_channel_offline(ha->pdev) &&
1345 ha->flags.pci_channel_io_perm_failure) {
1346 return;
1347 }
1348
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001349 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001350
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001351 qla25xx_manipulate_risc_semaphore(vha);
1352
Andrew Vasquez88c26662005-07-08 17:59:26 -07001353 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001354 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001355}
1356
1357/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 * qla2x00_chip_diag() - Test chip for proper operation.
1359 * @ha: HA context
1360 *
1361 * Returns 0 on success.
1362 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001363int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001364qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365{
1366 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001367 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001368 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 unsigned long flags = 0;
1370 uint16_t data;
1371 uint32_t cnt;
1372 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001373 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
1375 /* Assume a failed state */
1376 rval = QLA_FUNCTION_FAILED;
1377
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001378 ql_dbg(ql_dbg_init, vha, 0x007b,
1379 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
1381 spin_lock_irqsave(&ha->hardware_lock, flags);
1382
1383 /* Reset ISP chip. */
1384 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1385
1386 /*
1387 * We need to have a delay here since the card will not respond while
1388 * in reset causing an MCA on some architectures.
1389 */
1390 udelay(20);
1391 data = qla2x00_debounce_register(&reg->ctrl_status);
1392 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1393 udelay(5);
1394 data = RD_REG_WORD(&reg->ctrl_status);
1395 barrier();
1396 }
1397
1398 if (!cnt)
1399 goto chip_diag_failed;
1400
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001401 ql_dbg(ql_dbg_init, vha, 0x007c,
1402 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
1404 /* Reset RISC processor. */
1405 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1406 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1407
1408 /* Workaround for QLA2312 PCI parity error */
1409 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1410 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1411 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1412 udelay(5);
1413 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001414 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 }
1416 } else
1417 udelay(10);
1418
1419 if (!cnt)
1420 goto chip_diag_failed;
1421
1422 /* Check product ID of chip */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001423 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
1425 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1426 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1427 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1428 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1429 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1430 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001431 ql_log(ql_log_warn, vha, 0x0062,
1432 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1433 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
1435 goto chip_diag_failed;
1436 }
1437 ha->product_id[0] = mb[1];
1438 ha->product_id[1] = mb[2];
1439 ha->product_id[2] = mb[3];
1440 ha->product_id[3] = mb[4];
1441
1442 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001443 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1445 else
1446 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001447 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
1449 if (IS_QLA2200(ha) &&
1450 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1451 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001452 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001454 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 ha->fw_transfer_size = 128;
1456 }
1457
1458 /* Wrap Incoming Mailboxes Test. */
1459 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1460
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001461 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001462 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001463 if (rval)
1464 ql_log(ql_log_warn, vha, 0x0080,
1465 "Failed mailbox send register test.\n");
1466 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 /* Flag a successful rval */
1468 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 spin_lock_irqsave(&ha->hardware_lock, flags);
1470
1471chip_diag_failed:
1472 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001473 ql_log(ql_log_info, vha, 0x0081,
1474 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
1476 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1477
1478 return (rval);
1479}
1480
1481/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001482 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1483 * @ha: HA context
1484 *
1485 * Returns 0 on success.
1486 */
1487int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001488qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001489{
1490 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001491 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001492 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001493
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001494 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07001495 return QLA_SUCCESS;
1496
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001497 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001498
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001499 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001500 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001501 ql_log(ql_log_warn, vha, 0x0082,
1502 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001503 } else {
1504 /* Flag a successful rval */
1505 rval = QLA_SUCCESS;
1506 }
1507
1508 return rval;
1509}
1510
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001511void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001512qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001513{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001514 int rval;
1515 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001516 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001517 dma_addr_t tc_dma;
1518 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001519 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001520 struct req_que *req = ha->req_q_map[0];
1521 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001522
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001523 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001524 ql_dbg(ql_dbg_init, vha, 0x00bd,
1525 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001526 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001527 }
1528
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001529 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04001530 ha->fw_dump_cap_flags = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001531 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
1532 req_q_size = rsp_q_size = 0;
1533
1534 if (IS_QLA27XX(ha))
1535 goto try_fce;
1536
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001537 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1538 fixed_size = sizeof(struct qla2100_fw_dump);
1539 } else if (IS_QLA23XX(ha)) {
1540 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1541 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1542 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001543 } else if (IS_FWI2_CAPABLE(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001544 if (IS_QLA83XX(ha))
1545 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
1546 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001547 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1548 else if (IS_QLA25XX(ha))
1549 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1550 else
1551 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Chad Dupuisf73cb692014-02-26 04:15:06 -05001552
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001553 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1554 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001555 if (ha->mqenable) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001556 if (!IS_QLA83XX(ha))
1557 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001558 /*
1559 * Allocate maximum buffer size for all queues.
1560 * Resizing must be done at end-of-dump processing.
1561 */
1562 mq_size += ha->max_req_queues *
1563 (req->length * sizeof(request_t));
1564 mq_size += ha->max_rsp_queues *
1565 (rsp->length * sizeof(response_t));
1566 }
Arun Easi00876ae2013-03-25 02:21:37 -04001567 if (ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001568 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001569 /* Allocate memory for Fibre Channel Event Buffer. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05001570 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
1571 !IS_QLA27XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001572 goto try_eft;
1573
Chad Dupuisf73cb692014-02-26 04:15:06 -05001574try_fce:
1575 if (ha->fce)
1576 dma_free_coherent(&ha->pdev->dev,
1577 FCE_SIZE, ha->fce, ha->fce_dma);
1578
1579 /* Allocate memory for Fibre Channel Event Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07001580 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1581 GFP_KERNEL);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001582 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001583 ql_log(ql_log_warn, vha, 0x00be,
1584 "Unable to allocate (%d KB) for FCE.\n",
1585 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001586 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001587 }
1588
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001589 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001590 ha->fce_mb, &ha->fce_bufs);
1591 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001592 ql_log(ql_log_warn, vha, 0x00bf,
1593 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001594 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1595 tc_dma);
1596 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001597 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001598 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001599 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001600 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001601
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001602 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001603 ha->flags.fce_enabled = 1;
1604 ha->fce_dma = tc_dma;
1605 ha->fce = tc;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001606
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001607try_eft:
Chad Dupuisf73cb692014-02-26 04:15:06 -05001608 if (ha->eft)
1609 dma_free_coherent(&ha->pdev->dev,
1610 EFT_SIZE, ha->eft, ha->eft_dma);
1611
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001612 /* Allocate memory for Extended Trace Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07001613 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
1614 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001615 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001616 ql_log(ql_log_warn, vha, 0x00c1,
1617 "Unable to allocate (%d KB) for EFT.\n",
1618 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001619 goto cont_alloc;
1620 }
1621
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001622 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001623 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001624 ql_log(ql_log_warn, vha, 0x00c2,
1625 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001626 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1627 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001628 goto cont_alloc;
1629 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001630 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001631 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001632
1633 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001634 ha->eft_dma = tc_dma;
1635 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001636 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05001637
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001638cont_alloc:
Chad Dupuisf73cb692014-02-26 04:15:06 -05001639 if (IS_QLA27XX(ha)) {
1640 if (!ha->fw_dump_template) {
1641 ql_log(ql_log_warn, vha, 0x00ba,
1642 "Failed missing fwdump template\n");
1643 return;
1644 }
1645 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
1646 ql_dbg(ql_dbg_init, vha, 0x00fa,
1647 "-> allocating fwdump (%x bytes)...\n", dump_size);
1648 goto allocate;
1649 }
1650
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001651 req_q_size = req->length * sizeof(request_t);
1652 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001653 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001654 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001655 ha->chain_offset = dump_size;
1656 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001657
Chad Dupuisf73cb692014-02-26 04:15:06 -05001658allocate:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001659 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001660 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001661 ql_log(ql_log_warn, vha, 0x00c4,
1662 "Unable to allocate (%d KB) for firmware dump.\n",
1663 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001664
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001665 if (ha->fce) {
1666 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1667 ha->fce_dma);
1668 ha->fce = NULL;
1669 ha->fce_dma = 0;
1670 }
1671
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001672 if (ha->eft) {
1673 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1674 ha->eft_dma);
1675 ha->eft = NULL;
1676 ha->eft_dma = 0;
1677 }
1678 return;
1679 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05001680 ha->fw_dump_len = dump_size;
Chad Dupuiscfb09192011-11-18 09:03:07 -08001681 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001682 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001683
Chad Dupuisf73cb692014-02-26 04:15:06 -05001684 if (IS_QLA27XX(ha))
1685 return;
1686
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001687 ha->fw_dump->signature[0] = 'Q';
1688 ha->fw_dump->signature[1] = 'L';
1689 ha->fw_dump->signature[2] = 'G';
1690 ha->fw_dump->signature[3] = 'C';
Bart Van Asschead950362015-07-09 07:24:08 -07001691 ha->fw_dump->version = htonl(1);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001692
1693 ha->fw_dump->fixed_size = htonl(fixed_size);
1694 ha->fw_dump->mem_size = htonl(mem_size);
1695 ha->fw_dump->req_q_size = htonl(req_q_size);
1696 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1697
1698 ha->fw_dump->eft_size = htonl(eft_size);
1699 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1700 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1701
1702 ha->fw_dump->header_size =
1703 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001704}
1705
Andrew Vasquez18e75552009-06-03 09:55:30 -07001706static int
1707qla81xx_mpi_sync(scsi_qla_host_t *vha)
1708{
1709#define MPS_MASK 0xe0
1710 int rval;
1711 uint16_t dc;
1712 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07001713
1714 if (!IS_QLA81XX(vha->hw))
1715 return QLA_SUCCESS;
1716
1717 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1718 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001719 ql_log(ql_log_warn, vha, 0x0105,
1720 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001721 goto done;
1722 }
1723
1724 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1725 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1726 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001727 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001728 goto done_release;
1729 }
1730
1731 dc &= MPS_MASK;
1732 if (dc == (dw & MPS_MASK))
1733 goto done_release;
1734
1735 dw &= ~MPS_MASK;
1736 dw |= dc;
1737 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1738 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001739 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001740 }
1741
1742done_release:
1743 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1744 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001745 ql_log(ql_log_warn, vha, 0x006d,
1746 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001747 }
1748
1749done:
1750 return rval;
1751}
1752
Chad Dupuis8d93f552013-01-30 03:34:37 -05001753int
1754qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
1755{
1756 /* Don't try to reallocate the array */
1757 if (req->outstanding_cmds)
1758 return QLA_SUCCESS;
1759
1760 if (!IS_FWI2_CAPABLE(ha) || (ha->mqiobase &&
1761 (ql2xmultique_tag || ql2xmaxqueues > 1)))
1762 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
1763 else {
1764 if (ha->fw_xcb_count <= ha->fw_iocb_count)
1765 req->num_outstanding_cmds = ha->fw_xcb_count;
1766 else
1767 req->num_outstanding_cmds = ha->fw_iocb_count;
1768 }
1769
1770 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1771 req->num_outstanding_cmds, GFP_KERNEL);
1772
1773 if (!req->outstanding_cmds) {
1774 /*
1775 * Try to allocate a minimal size just so we can get through
1776 * initialization.
1777 */
1778 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
1779 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1780 req->num_outstanding_cmds, GFP_KERNEL);
1781
1782 if (!req->outstanding_cmds) {
1783 ql_log(ql_log_fatal, NULL, 0x0126,
1784 "Failed to allocate memory for "
1785 "outstanding_cmds for req_que %p.\n", req);
1786 req->num_outstanding_cmds = 0;
1787 return QLA_FUNCTION_FAILED;
1788 }
1789 }
1790
1791 return QLA_SUCCESS;
1792}
1793
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001794/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 * qla2x00_setup_chip() - Load and start RISC firmware.
1796 * @ha: HA context
1797 *
1798 * Returns 0 on success.
1799 */
1800static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001801qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001803 int rval;
1804 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001805 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001806 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1807 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001808 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001809
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001810 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001811 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001812 if (rval == QLA_SUCCESS) {
1813 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001814 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001815 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001816 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001817 }
1818
Andrew Vasquez3db06522008-01-31 12:33:49 -08001819 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1820 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1821 spin_lock_irqsave(&ha->hardware_lock, flags);
1822 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1823 RD_REG_WORD(&reg->hccr);
1824 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1825 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826
Andrew Vasquez18e75552009-06-03 09:55:30 -07001827 qla81xx_mpi_sync(vha);
1828
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001830 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001831 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001832 ql_dbg(ql_dbg_init, vha, 0x00c9,
1833 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001835 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 if (rval == QLA_SUCCESS) {
1837 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001838 ql_dbg(ql_dbg_init, vha, 0x00ca,
1839 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001841 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001843 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001844enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001845 fw_major_version = ha->fw_major_version;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001846 if (IS_P3P_TYPE(ha))
Giridhar Malavali31731672011-08-16 11:31:54 -07001847 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001848 else
1849 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001850 if (rval != QLA_SUCCESS)
1851 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001852 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001853 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001854 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001855 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001856 if ((!ha->max_npiv_vports) ||
1857 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001858 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001859 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001860 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001861 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001862 qla2x00_get_resource_cnts(vha, NULL,
Chad Dupuis8d93f552013-01-30 03:34:37 -05001863 &ha->fw_xcb_count, NULL, &ha->fw_iocb_count,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001864 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001865
Chad Dupuis8d93f552013-01-30 03:34:37 -05001866 /*
1867 * Allocate the array of outstanding commands
1868 * now that we know the firmware resources.
1869 */
1870 rval = qla2x00_alloc_outstanding_cmds(ha,
1871 vha->req);
1872 if (rval != QLA_SUCCESS)
1873 goto failed;
1874
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08001875 if (!fw_major_version && ql2xallocfwdump
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001876 && !(IS_P3P_TYPE(ha)))
Giridhar Malavali08de2842011-08-16 11:31:44 -07001877 qla2x00_alloc_fw_dump(vha);
Chad Dupuis3b6e5b92013-10-30 03:38:09 -04001878 } else {
1879 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 }
1881 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001882 ql_log(ql_log_fatal, vha, 0x00cd,
1883 "ISP Firmware failed checksum.\n");
1884 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04001886 } else
1887 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
Andrew Vasquez3db06522008-01-31 12:33:49 -08001889 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1890 /* Enable proper parity. */
1891 spin_lock_irqsave(&ha->hardware_lock, flags);
1892 if (IS_QLA2300(ha))
1893 /* SRAM parity */
1894 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1895 else
1896 /* SRAM, Instruction RAM and GP RAM parity */
1897 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1898 RD_REG_WORD(&reg->hccr);
1899 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1900 }
1901
Chad Dupuisf3982d82014-09-25 05:16:57 -04001902 if (IS_QLA27XX(ha))
1903 ha->flags.fac_supported = 1;
1904 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001905 uint32_t size;
1906
1907 rval = qla81xx_fac_get_sector_size(vha, &size);
1908 if (rval == QLA_SUCCESS) {
1909 ha->flags.fac_supported = 1;
1910 ha->fdt_block_size = size << 2;
1911 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001912 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001913 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1914 ha->fw_major_version, ha->fw_minor_version,
1915 ha->fw_subminor_version);
Joe Carnuccio1ca60e32014-02-26 04:15:02 -05001916
Chad Dupuisf73cb692014-02-26 04:15:06 -05001917 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001918 ha->flags.fac_supported = 0;
1919 rval = QLA_SUCCESS;
1920 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001921 }
1922 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001923failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001925 ql_log(ql_log_fatal, vha, 0x00cf,
1926 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 }
1928
1929 return (rval);
1930}
1931
1932/**
1933 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1934 * @ha: HA context
1935 *
1936 * Beginning of request ring has initialization control block already built
1937 * by nvram config routine.
1938 *
1939 * Returns 0 on success.
1940 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001941void
1942qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943{
1944 uint16_t cnt;
1945 response_t *pkt;
1946
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001947 rsp->ring_ptr = rsp->ring;
1948 rsp->ring_index = 0;
1949 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001950 pkt = rsp->ring_ptr;
1951 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 pkt->signature = RESPONSE_PROCESSED;
1953 pkt++;
1954 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955}
1956
1957/**
1958 * qla2x00_update_fw_options() - Read and process firmware options.
1959 * @ha: HA context
1960 *
1961 * Returns 0 on success.
1962 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001963void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001964qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965{
1966 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001967 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968
1969 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001970 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971
1972 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1973 return;
1974
1975 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001976 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1977 "Serial link options.\n");
1978 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1979 (uint8_t *)&ha->fw_seriallink_options,
1980 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981
1982 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1983 if (ha->fw_seriallink_options[3] & BIT_2) {
1984 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1985
1986 /* 1G settings */
1987 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1988 emphasis = (ha->fw_seriallink_options[2] &
1989 (BIT_4 | BIT_3)) >> 3;
1990 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001991 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 rx_sens = (ha->fw_seriallink_options[0] &
1993 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1994 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1995 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1996 if (rx_sens == 0x0)
1997 rx_sens = 0x3;
1998 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1999 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2000 ha->fw_options[10] |= BIT_5 |
2001 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2002 (tx_sens & (BIT_1 | BIT_0));
2003
2004 /* 2G settings */
2005 swing = (ha->fw_seriallink_options[2] &
2006 (BIT_7 | BIT_6 | BIT_5)) >> 5;
2007 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
2008 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002009 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 rx_sens = (ha->fw_seriallink_options[1] &
2011 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
2012 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
2013 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2014 if (rx_sens == 0x0)
2015 rx_sens = 0x3;
2016 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
2017 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2018 ha->fw_options[11] |= BIT_5 |
2019 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2020 (tx_sens & (BIT_1 | BIT_0));
2021 }
2022
2023 /* FCP2 options. */
2024 /* Return command IOCBs without waiting for an ABTS to complete. */
2025 ha->fw_options[3] |= BIT_13;
2026
2027 /* LED scheme. */
2028 if (ha->flags.enable_led_scheme)
2029 ha->fw_options[2] |= BIT_12;
2030
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002031 /* Detect ISP6312. */
2032 if (IS_QLA6312(ha))
2033 ha->fw_options[2] |= BIT_13;
2034
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002036 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037}
2038
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002039void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002040qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002041{
2042 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002043 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002044
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002045 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07002046 return;
2047
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002048 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08002049 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002050 return;
2051
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08002053 le16_to_cpu(ha->fw_seriallink_options24[1]),
2054 le16_to_cpu(ha->fw_seriallink_options24[2]),
2055 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002056 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002057 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002058 "Unable to update Serial Link options (%x).\n", rval);
2059 }
2060}
2061
2062void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002063qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002064{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002065 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002066 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002067 struct req_que *req = ha->req_q_map[0];
2068 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002069
2070 /* Setup ring parameters in initialization control block. */
Bart Van Asschead950362015-07-09 07:24:08 -07002071 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
2072 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002073 ha->init_cb->request_q_length = cpu_to_le16(req->length);
2074 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
2075 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2076 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2077 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2078 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002079
2080 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
2081 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
2082 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
2083 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
2084 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
2085}
2086
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002087void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002088qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002089{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002090 struct qla_hw_data *ha = vha->hw;
Bart Van Assche118e2ef2015-07-09 07:24:27 -07002091 device_reg_t *reg = ISP_QUE_REG(ha, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002092 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
2093 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002094 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002095 uint16_t rid = 0;
2096 struct req_que *req = ha->req_q_map[0];
2097 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002098
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002099 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002100 icb = (struct init_cb_24xx *)ha->init_cb;
Bart Van Asschead950362015-07-09 07:24:08 -07002101 icb->request_q_outpointer = cpu_to_le16(0);
2102 icb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002103 icb->request_q_length = cpu_to_le16(req->length);
2104 icb->response_q_length = cpu_to_le16(rsp->length);
2105 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2106 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2107 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2108 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002109
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002110 /* Setup ATIO queue dma pointers for target mode */
Bart Van Asschead950362015-07-09 07:24:08 -07002111 icb->atio_q_inpointer = cpu_to_le16(0);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002112 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
2113 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
2114 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
2115
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002116 if (IS_SHADOW_REG_CAPABLE(ha))
Bart Van Asschead950362015-07-09 07:24:08 -07002117 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002118
Chad Dupuisf73cb692014-02-26 04:15:06 -05002119 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07002120 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
2121 icb->rid = cpu_to_le16(rid);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002122 if (ha->flags.msix_enabled) {
2123 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002124 ql_dbg(ql_dbg_init, vha, 0x00fd,
2125 "Registering vector 0x%x for base que.\n",
2126 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002127 icb->msix = cpu_to_le16(msix->entry);
2128 }
2129 /* Use alternate PCI bus number */
2130 if (MSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07002131 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002132 /* Use alternate PCI devfn */
2133 if (LSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07002134 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002135
Anirban Chakraborty31557542009-12-02 10:36:55 -08002136 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002137 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
2138 (ha->flags.msix_enabled)) {
Bart Van Asschead950362015-07-09 07:24:08 -07002139 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002140 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002141 ql_dbg(ql_dbg_init, vha, 0x00fe,
2142 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08002143 } else {
Bart Van Asschead950362015-07-09 07:24:08 -07002144 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002145 }
Bart Van Asschead950362015-07-09 07:24:08 -07002146 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002147
2148 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
2149 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
2150 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
2151 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
2152 } else {
2153 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
2154 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
2155 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
2156 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
2157 }
Arun Easiaa230bc2013-01-30 03:34:39 -05002158 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002159
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002160 /* PCI posting */
2161 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002162}
2163
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164/**
2165 * qla2x00_init_rings() - Initializes firmware.
2166 * @ha: HA context
2167 *
2168 * Beginning of request ring has initialization control block already built
2169 * by nvram config routine.
2170 *
2171 * Returns 0 on success.
2172 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002173int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002174qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175{
2176 int rval;
2177 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002178 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002179 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002180 struct req_que *req;
2181 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002182 struct mid_init_cb_24xx *mid_init_cb =
2183 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184
2185 spin_lock_irqsave(&ha->hardware_lock, flags);
2186
2187 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002188 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002189 req = ha->req_q_map[que];
2190 if (!req)
2191 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002192 req->out_ptr = (void *)(req->ring + req->length);
2193 *req->out_ptr = 0;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002194 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002195 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002197 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002198
2199 /* Initialize firmware. */
2200 req->ring_ptr = req->ring;
2201 req->ring_index = 0;
2202 req->cnt = req->length;
2203 }
2204
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002205 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002206 rsp = ha->rsp_q_map[que];
2207 if (!rsp)
2208 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002209 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
2210 *rsp->in_ptr = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002211 /* Initialize response queue entries */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002212 if (IS_QLAFX00(ha))
2213 qlafx00_init_response_q_entries(rsp);
2214 else
2215 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002216 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002218 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
2219 ha->tgt.atio_ring_index = 0;
2220 /* Initialize ATIO queue entries */
2221 qlt_init_atio_q_entries(vha);
2222
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002223 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
2225 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2226
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002227 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
2228
2229 if (IS_QLAFX00(ha)) {
2230 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
2231 goto next_check;
2232 }
2233
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002235 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002237 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04002238 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002239 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08002240 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002241 }
2242
Andrew Vasquez24a08132009-03-24 09:08:16 -07002243 if (IS_FWI2_CAPABLE(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07002244 mid_init_cb->options = cpu_to_le16(BIT_1);
Andrew Vasquez24a08132009-03-24 09:08:16 -07002245 mid_init_cb->init_cb.execution_throttle =
2246 cpu_to_le16(ha->fw_xcb_count);
Himanshu Madhani25232cc2014-09-25 05:16:54 -04002247 /* D-Port Status */
2248 if (IS_DPORT_CAPABLE(ha))
2249 mid_init_cb->init_cb.firmware_options_1 |=
2250 cpu_to_le16(BIT_7);
Himanshu Madhani2486c622014-09-25 05:17:00 -04002251 /* Enable FA-WWPN */
2252 ha->flags.fawwpn_enabled =
2253 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) ? 1 : 0;
2254 ql_dbg(ql_dbg_init, vha, 0x0141, "FA-WWPN Support: %s.\n",
2255 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
Andrew Vasquez24a08132009-03-24 09:08:16 -07002256 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002257
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002258 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002259next_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002261 ql_log(ql_log_fatal, vha, 0x00d2,
2262 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002264 ql_dbg(ql_dbg_init, vha, 0x00d3,
2265 "Init Firmware -- success.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 }
2267
2268 return (rval);
2269}
2270
2271/**
2272 * qla2x00_fw_ready() - Waits for firmware ready.
2273 * @ha: HA context
2274 *
2275 * Returns 0 on success.
2276 */
2277static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002278qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279{
2280 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002281 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 uint16_t min_wait; /* Minimum wait time if loop is down */
2283 uint16_t wait_time; /* Wait time if loop is coming ready */
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002284 uint16_t state[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002285 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002287 if (IS_QLAFX00(vha->hw))
2288 return qlafx00_fw_ready(vha);
2289
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 rval = QLA_SUCCESS;
2291
Chad Dupuis334614912015-04-09 14:59:57 -04002292 /* Time to wait for loop down */
2293 if (IS_P3P_TYPE(ha))
2294 min_wait = 30;
2295 else
2296 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297
2298 /*
2299 * Firmware should take at most one RATOV to login, plus 5 seconds for
2300 * our own processing.
2301 */
2302 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
2303 wait_time = min_wait;
2304 }
2305
2306 /* Min wait time if loop down */
2307 mtime = jiffies + (min_wait * HZ);
2308
2309 /* wait time before firmware ready */
2310 wtime = jiffies + (wait_time * HZ);
2311
2312 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002313 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002314 ql_log(ql_log_info, vha, 0x801e,
2315 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316
2317 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05002318 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002319 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002321 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002322 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002324 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002325 ql_dbg(ql_dbg_taskm, vha, 0x801f,
2326 "fw_state=%x 84xx=%x.\n", state[0],
2327 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002328 if ((state[2] & FSTATE_LOGGED_IN) &&
2329 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002330 ql_dbg(ql_dbg_taskm, vha, 0x8028,
2331 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002332
2333 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002334 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002335 if (rval != QLA_SUCCESS) {
2336 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002337 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002338 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002339 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002340 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002341
2342 /* Add time taken to initialize. */
2343 cs84xx_time = jiffies - cs84xx_time;
2344 wtime += cs84xx_time;
2345 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002346 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002347 "Increasing wait time by %ld. "
2348 "New time %ld.\n", cs84xx_time,
2349 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002350 }
2351 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002352 ql_dbg(ql_dbg_taskm, vha, 0x8037,
2353 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002355 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 &ha->login_timeout, &ha->r_a_tov);
2357
2358 rval = QLA_SUCCESS;
2359 break;
2360 }
2361
2362 rval = QLA_FUNCTION_FAILED;
2363
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002364 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002365 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002367 * other than Wait for Login.
2368 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002370 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 "Cable is unplugged...\n");
2372
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002373 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 break;
2375 }
2376 }
2377 } else {
2378 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07002379 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08002380 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 break;
2382 }
2383
2384 if (time_after_eq(jiffies, wtime))
2385 break;
2386
2387 /* Delay for a while */
2388 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 } while (1);
2390
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002391 ql_dbg(ql_dbg_taskm, vha, 0x803a,
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002392 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
2393 state[1], state[2], state[3], state[4], state[5], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
Chad Dupuiscfb09192011-11-18 09:03:07 -08002395 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002396 ql_log(ql_log_warn, vha, 0x803b,
2397 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 }
2399
2400 return (rval);
2401}
2402
2403/*
2404* qla2x00_configure_hba
2405* Setup adapter context.
2406*
2407* Input:
2408* ha = adapter state pointer.
2409*
2410* Returns:
2411* 0 = success
2412*
2413* Context:
2414* Kernel context.
2415*/
2416static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002417qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418{
2419 int rval;
2420 uint16_t loop_id;
2421 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002422 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 uint8_t al_pa;
2424 uint8_t area;
2425 uint8_t domain;
2426 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002427 struct qla_hw_data *ha = vha->hw;
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002428 unsigned long flags;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002429 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430
2431 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002432 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002433 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002435 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002436 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002437 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002438 ql_dbg(ql_dbg_disc, vha, 0x2008,
2439 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08002440 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002441 ql_log(ql_log_warn, vha, 0x2009,
2442 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002443 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
2444 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
2445 ql_log(ql_log_warn, vha, 0x1151,
2446 "Doing link init.\n");
2447 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
2448 return rval;
2449 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002450 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002451 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 return (rval);
2453 }
2454
2455 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002456 ql_log(ql_log_info, vha, 0x200a,
2457 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 return (QLA_FUNCTION_FAILED);
2459 }
2460
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002461 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462
2463 /* initialize */
2464 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2465 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002466 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467
2468 switch (topo) {
2469 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002470 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 ha->current_topology = ISP_CFG_NL;
2472 strcpy(connect_type, "(Loop)");
2473 break;
2474
2475 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002476 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002477 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 ha->current_topology = ISP_CFG_FL;
2479 strcpy(connect_type, "(FL_Port)");
2480 break;
2481
2482 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002483 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 ha->operating_mode = P2P;
2485 ha->current_topology = ISP_CFG_N;
2486 strcpy(connect_type, "(N_Port-to-N_Port)");
2487 break;
2488
2489 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002490 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002491 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 ha->operating_mode = P2P;
2493 ha->current_topology = ISP_CFG_F;
2494 strcpy(connect_type, "(F_Port)");
2495 break;
2496
2497 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002498 ql_dbg(ql_dbg_disc, vha, 0x200f,
2499 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 ha->current_topology = ISP_CFG_NL;
2501 strcpy(connect_type, "(Loop)");
2502 break;
2503 }
2504
2505 /* Save Host port and loop ID. */
2506 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002507 vha->d_id.b.domain = domain;
2508 vha->d_id.b.area = area;
2509 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002511 spin_lock_irqsave(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002512 qlt_update_vp_map(vha, SET_AL_PA);
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002513 spin_unlock_irqrestore(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002514
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002515 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002516 ql_log(ql_log_info, vha, 0x2010,
2517 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002518 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 return(rval);
2521}
2522
Giridhar Malavalia9083012010-04-12 17:59:55 -07002523inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002524qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2525 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002526{
2527 char *st, *en;
2528 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002529 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002530 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002531 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002532
2533 if (memcmp(model, BINZERO, len) != 0) {
2534 strncpy(ha->model_number, model, len);
2535 st = en = ha->model_number;
2536 en += len - 1;
2537 while (en > st) {
2538 if (*en != 0x20 && *en != 0x00)
2539 break;
2540 *en-- = '\0';
2541 }
2542
2543 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002544 if (use_tbl &&
2545 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002546 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002547 strncpy(ha->model_desc,
2548 qla2x00_model_name[index * 2 + 1],
2549 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002550 } else {
2551 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002552 if (use_tbl &&
2553 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002554 index < QLA_MODEL_NAMES) {
2555 strcpy(ha->model_number,
2556 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002557 strncpy(ha->model_desc,
2558 qla2x00_model_name[index * 2 + 1],
2559 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002560 } else {
2561 strcpy(ha->model_number, def);
2562 }
2563 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002564 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002565 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002566 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002567}
2568
David Miller4e08df32007-04-16 12:37:43 -07002569/* On sparc systems, obtain port and node WWN from firmware
2570 * properties.
2571 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002572static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002573{
2574#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002575 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002576 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002577 struct device_node *dp = pci_device_to_OF_node(pdev);
2578 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002579 int len;
2580
2581 val = of_get_property(dp, "port-wwn", &len);
2582 if (val && len >= WWN_SIZE)
2583 memcpy(nv->port_name, val, WWN_SIZE);
2584
2585 val = of_get_property(dp, "node-wwn", &len);
2586 if (val && len >= WWN_SIZE)
2587 memcpy(nv->node_name, val, WWN_SIZE);
2588#endif
2589}
2590
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591/*
2592* NVRAM configuration for ISP 2xxx
2593*
2594* Input:
2595* ha = adapter block pointer.
2596*
2597* Output:
2598* initialization control block in response_ring
2599* host adapters parameters in host adapter block
2600*
2601* Returns:
2602* 0 = success.
2603*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002604int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002605qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606{
David Miller4e08df32007-04-16 12:37:43 -07002607 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002608 uint8_t chksum = 0;
2609 uint16_t cnt;
2610 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002611 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002612 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002613 nvram_t *nv = ha->nvram;
2614 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002615 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616
David Miller4e08df32007-04-16 12:37:43 -07002617 rval = QLA_SUCCESS;
2618
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002620 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 ha->nvram_base = 0;
2622 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2623 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2624 ha->nvram_base = 0x80;
2625
2626 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002627 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002628 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2629 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002631 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2632 "Contents of NVRAM.\n");
2633 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2634 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
2636 /* Bad NVRAM data, set defaults parameters. */
2637 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2638 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2639 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002640 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04002641 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002642 "detected: checksum=0x%x id=%c version=0x%x.\n",
2643 chksum, nv->id[0], nv->nvram_version);
2644 ql_log(ql_log_warn, vha, 0x0065,
2645 "Falling back to "
2646 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07002647
2648 /*
2649 * Set default initialization control block.
2650 */
2651 memset(nv, 0, ha->nvram_size);
2652 nv->parameter_block_version = ICB_VERSION;
2653
2654 if (IS_QLA23XX(ha)) {
2655 nv->firmware_options[0] = BIT_2 | BIT_1;
2656 nv->firmware_options[1] = BIT_7 | BIT_5;
2657 nv->add_firmware_options[0] = BIT_5;
2658 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04002659 nv->frame_payload_size = 2048;
David Miller4e08df32007-04-16 12:37:43 -07002660 nv->special_options[1] = BIT_7;
2661 } else if (IS_QLA2200(ha)) {
2662 nv->firmware_options[0] = BIT_2 | BIT_1;
2663 nv->firmware_options[1] = BIT_7 | BIT_5;
2664 nv->add_firmware_options[0] = BIT_5;
2665 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04002666 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07002667 } else if (IS_QLA2100(ha)) {
2668 nv->firmware_options[0] = BIT_3 | BIT_1;
2669 nv->firmware_options[1] = BIT_5;
Joe Carnuccio98aee702014-09-25 05:16:38 -04002670 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07002671 }
2672
Bart Van Asschead950362015-07-09 07:24:08 -07002673 nv->max_iocb_allocation = cpu_to_le16(256);
2674 nv->execution_throttle = cpu_to_le16(16);
David Miller4e08df32007-04-16 12:37:43 -07002675 nv->retry_count = 8;
2676 nv->retry_delay = 1;
2677
2678 nv->port_name[0] = 33;
2679 nv->port_name[3] = 224;
2680 nv->port_name[4] = 139;
2681
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002682 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002683
2684 nv->login_timeout = 4;
2685
2686 /*
2687 * Set default host adapter parameters
2688 */
2689 nv->host_p[1] = BIT_2;
2690 nv->reset_delay = 5;
2691 nv->port_down_retry_count = 8;
Bart Van Asschead950362015-07-09 07:24:08 -07002692 nv->max_luns_per_target = cpu_to_le16(8);
David Miller4e08df32007-04-16 12:37:43 -07002693 nv->link_down_timeout = 60;
2694
2695 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 }
2697
2698#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2699 /*
2700 * The SN2 does not provide BIOS emulation which means you can't change
2701 * potentially bogus BIOS settings. Force the use of default settings
2702 * for link rate and frame size. Hope that the rest of the settings
2703 * are valid.
2704 */
2705 if (ia64_platform_is("sn2")) {
Joe Carnuccio98aee702014-09-25 05:16:38 -04002706 nv->frame_payload_size = 2048;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 if (IS_QLA23XX(ha))
2708 nv->special_options[1] = BIT_7;
2709 }
2710#endif
2711
2712 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002713 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714
2715 /*
2716 * Setup driver NVRAM options.
2717 */
2718 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2719 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2720 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2721 nv->firmware_options[1] &= ~BIT_4;
2722
2723 if (IS_QLA23XX(ha)) {
2724 nv->firmware_options[0] |= BIT_2;
2725 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002726 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002727 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728
2729 if (IS_QLA2300(ha)) {
2730 if (ha->fb_rev == FPM_2310) {
2731 strcpy(ha->model_number, "QLA2310");
2732 } else {
2733 strcpy(ha->model_number, "QLA2300");
2734 }
2735 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002736 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002737 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 }
2739 } else if (IS_QLA2200(ha)) {
2740 nv->firmware_options[0] |= BIT_2;
2741 /*
2742 * 'Point-to-point preferred, else loop' is not a safe
2743 * connection mode setting.
2744 */
2745 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2746 (BIT_5 | BIT_4)) {
2747 /* Force 'loop preferred, else point-to-point'. */
2748 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2749 nv->add_firmware_options[0] |= BIT_5;
2750 }
2751 strcpy(ha->model_number, "QLA22xx");
2752 } else /*if (IS_QLA2100(ha))*/ {
2753 strcpy(ha->model_number, "QLA2100");
2754 }
2755
2756 /*
2757 * Copy over NVRAM RISC parameter block to initialization control block.
2758 */
2759 dptr1 = (uint8_t *)icb;
2760 dptr2 = (uint8_t *)&nv->parameter_block_version;
2761 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2762 while (cnt--)
2763 *dptr1++ = *dptr2++;
2764
2765 /* Copy 2nd half. */
2766 dptr1 = (uint8_t *)icb->add_firmware_options;
2767 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2768 while (cnt--)
2769 *dptr1++ = *dptr2++;
2770
Andrew Vasquez5341e862006-05-17 15:09:16 -07002771 /* Use alternate WWN? */
2772 if (nv->host_p[1] & BIT_7) {
2773 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2774 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2775 }
2776
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 /* Prepare nodename */
2778 if ((icb->firmware_options[1] & BIT_6) == 0) {
2779 /*
2780 * Firmware will apply the following mask if the nodename was
2781 * not provided.
2782 */
2783 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2784 icb->node_name[0] &= 0xF0;
2785 }
2786
2787 /*
2788 * Set host adapter parameters.
2789 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002790
2791 /*
2792 * BIT_7 in the host-parameters section allows for modification to
2793 * internal driver logging.
2794 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002795 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08002796 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2798 /* Always load RISC code on non ISP2[12]00 chips. */
2799 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2800 ha->flags.disable_risc_code_load = 0;
2801 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2802 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2803 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002804 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002805 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806
2807 ha->operating_mode =
2808 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2809
2810 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2811 sizeof(ha->fw_seriallink_options));
2812
2813 /* save HBA serial number */
2814 ha->serial0 = icb->port_name[5];
2815 ha->serial1 = icb->port_name[6];
2816 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002817 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2818 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819
Bart Van Asschead950362015-07-09 07:24:08 -07002820 icb->execution_throttle = cpu_to_le16(0xFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821
2822 ha->retry_count = nv->retry_count;
2823
2824 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002825 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 nv->login_timeout = ql2xlogintimeout;
2827 if (nv->login_timeout < 4)
2828 nv->login_timeout = 4;
2829 ha->login_timeout = nv->login_timeout;
2830 icb->login_timeout = nv->login_timeout;
2831
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002832 /* Set minimum RATOV to 100 tenths of a second. */
2833 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 ha->loop_reset_delay = nv->reset_delay;
2836
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 /* Link Down Timeout = 0:
2838 *
2839 * When Port Down timer expires we will start returning
2840 * I/O's to OS with "DID_NO_CONNECT".
2841 *
2842 * Link Down Timeout != 0:
2843 *
2844 * The driver waits for the link to come up after link down
2845 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002846 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 if (nv->link_down_timeout == 0) {
2848 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002849 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 } else {
2851 ha->link_down_timeout = nv->link_down_timeout;
2852 ha->loop_down_abort_time =
2853 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 /*
2857 * Need enough time to try and get the port back.
2858 */
2859 ha->port_down_retry_count = nv->port_down_retry_count;
2860 if (qlport_down_retry)
2861 ha->port_down_retry_count = qlport_down_retry;
2862 /* Set login_retry_count */
2863 ha->login_retry_count = nv->retry_count;
2864 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2865 ha->port_down_retry_count > 3)
2866 ha->login_retry_count = ha->port_down_retry_count;
2867 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2868 ha->login_retry_count = ha->port_down_retry_count;
2869 if (ql2xloginretrycount)
2870 ha->login_retry_count = ql2xloginretrycount;
2871
Bart Van Asschead950362015-07-09 07:24:08 -07002872 icb->lun_enables = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 icb->command_resource_count = 0;
2874 icb->immediate_notify_resource_count = 0;
Bart Van Asschead950362015-07-09 07:24:08 -07002875 icb->timeout = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876
2877 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2878 /* Enable RIO */
2879 icb->firmware_options[0] &= ~BIT_3;
2880 icb->add_firmware_options[0] &=
2881 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2882 icb->add_firmware_options[0] |= BIT_2;
2883 icb->response_accumulation_timer = 3;
2884 icb->interrupt_delay_timer = 5;
2885
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002886 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002888 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002889 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002890 ha->zio_mode = icb->add_firmware_options[0] &
2891 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2892 ha->zio_timer = icb->interrupt_delay_timer ?
2893 icb->interrupt_delay_timer: 2;
2894 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 icb->add_firmware_options[0] &=
2896 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002897 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002898 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002899 ha->zio_mode = QLA_ZIO_MODE_6;
2900
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002901 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002902 "ZIO mode %d enabled; timer delay (%d us).\n",
2903 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002905 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2906 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002907 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 }
2909 }
2910
David Miller4e08df32007-04-16 12:37:43 -07002911 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002912 ql_log(ql_log_warn, vha, 0x0069,
2913 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07002914 }
2915 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916}
2917
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002918static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002919qla2x00_rport_del(void *data)
2920{
2921 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002922 struct fc_rport *rport;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002923 scsi_qla_host_t *vha = fcport->vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002924 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002925
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002926 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002927 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002928 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002929 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002930 if (rport) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002931 fc_remote_port_delete(rport);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002932 /*
2933 * Release the target mode FC NEXUS in qla_target.c code
2934 * if target mod is enabled.
2935 */
2936 qlt_fc_port_deleted(vha, fcport);
2937 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002938}
2939
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940/**
2941 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2942 * @ha: HA context
2943 * @flags: allocation flags
2944 *
2945 * Returns a pointer to the allocated fcport, or NULL, if none available.
2946 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002947fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002948qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949{
2950 fc_port_t *fcport;
2951
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002952 fcport = kzalloc(sizeof(fc_port_t), flags);
2953 if (!fcport)
2954 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955
2956 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002957 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 fcport->port_type = FCT_UNKNOWN;
2959 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07002960 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002961 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002963 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964}
2965
2966/*
2967 * qla2x00_configure_loop
2968 * Updates Fibre Channel Device Database with what is actually on loop.
2969 *
2970 * Input:
2971 * ha = adapter block pointer.
2972 *
2973 * Returns:
2974 * 0 = success.
2975 * 1 = error.
2976 * 2 = database was full and device was not configured.
2977 */
2978static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002979qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980{
2981 int rval;
2982 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002983 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 rval = QLA_SUCCESS;
2985
2986 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002987 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2988 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002990 ql_dbg(ql_dbg_disc, vha, 0x2013,
2991 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 return (rval);
2993 }
2994 }
2995
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002996 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002997 ql_dbg(ql_dbg_disc, vha, 0x2014,
2998 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999
3000 /*
3001 * If we have both an RSCN and PORT UPDATE pending then handle them
3002 * both at the same time.
3003 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003004 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3005 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006
Michael Hernandez3064ff32009-12-15 21:29:44 -08003007 qla2x00_get_data_rate(vha);
3008
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 /* Determine what we need to do */
3010 if (ha->current_topology == ISP_CFG_FL &&
3011 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
3012
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 set_bit(RSCN_UPDATE, &flags);
3014
3015 } else if (ha->current_topology == ISP_CFG_F &&
3016 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
3017
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 set_bit(RSCN_UPDATE, &flags);
3019 clear_bit(LOCAL_LOOP_UPDATE, &flags);
3020
Andrew Vasquez21333b42006-05-17 15:09:56 -07003021 } else if (ha->current_topology == ISP_CFG_N) {
3022 clear_bit(RSCN_UPDATE, &flags);
3023
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003024 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
3026
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 set_bit(RSCN_UPDATE, &flags);
3028 set_bit(LOCAL_LOOP_UPDATE, &flags);
3029 }
3030
3031 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003032 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
3033 ql_dbg(ql_dbg_disc, vha, 0x2015,
3034 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08003036 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003037 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 }
3039
3040 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003041 if (LOOP_TRANSITION(vha)) {
3042 ql_dbg(ql_dbg_disc, vha, 0x201e,
3043 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003045 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003046 else
3047 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 }
3049
3050 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003051 if (atomic_read(&vha->loop_down_timer) ||
3052 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 rval = QLA_FUNCTION_FAILED;
3054 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003055 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003056 ql_dbg(ql_dbg_disc, vha, 0x2069,
3057 "LOOP READY.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 }
3059 }
3060
3061 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003062 ql_dbg(ql_dbg_disc, vha, 0x206a,
3063 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003065 ql_dbg(ql_dbg_disc, vha, 0x206b,
3066 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 }
3068
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07003069 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003070 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003072 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07003073 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003074 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07003075 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 }
3077
3078 return (rval);
3079}
3080
3081
3082
3083/*
3084 * qla2x00_configure_local_loop
3085 * Updates Fibre Channel Device Database with local loop devices.
3086 *
3087 * Input:
3088 * ha = adapter block pointer.
3089 *
3090 * Returns:
3091 * 0 = success.
3092 */
3093static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003094qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095{
3096 int rval, rval2;
3097 int found_devs;
3098 int found;
3099 fc_port_t *fcport, *new_fcport;
3100
3101 uint16_t index;
3102 uint16_t entries;
3103 char *id_iter;
3104 uint16_t loop_id;
3105 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003106 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107
3108 found_devs = 0;
3109 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08003110 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08003113 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003114 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115 &entries);
3116 if (rval != QLA_SUCCESS)
3117 goto cleanup_allocation;
3118
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003119 ql_dbg(ql_dbg_disc, vha, 0x2017,
3120 "Entries in ID list (%d).\n", entries);
3121 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
3122 (uint8_t *)ha->gid_list,
3123 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124
3125 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003126 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003128 ql_log(ql_log_warn, vha, 0x2018,
3129 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 rval = QLA_MEMORY_ALLOC_FAILED;
3131 goto cleanup_allocation;
3132 }
3133 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3134
3135 /*
3136 * Mark local devices that were present with FCF_DEVICE_LOST for now.
3137 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003138 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 if (atomic_read(&fcport->state) == FCS_ONLINE &&
3140 fcport->port_type != FCT_BROADCAST &&
3141 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3142
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003143 ql_dbg(ql_dbg_disc, vha, 0x2019,
3144 "Marking port lost loop_id=0x%04x.\n",
3145 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146
Chad Dupuisec426e12011-03-30 11:46:32 -07003147 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148 }
3149 }
3150
3151 /* Add devices to port list. */
3152 id_iter = (char *)ha->gid_list;
3153 for (index = 0; index < entries; index++) {
3154 domain = ((struct gid_list_info *)id_iter)->domain;
3155 area = ((struct gid_list_info *)id_iter)->area;
3156 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003157 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 loop_id = (uint16_t)
3159 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003160 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 loop_id = le16_to_cpu(
3162 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003163 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164
3165 /* Bypass reserved domain fields. */
3166 if ((domain & 0xf0) == 0xf0)
3167 continue;
3168
3169 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003170 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003171 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 continue;
3173
3174 /* Bypass invalid local loop ID. */
3175 if (loop_id > LAST_LOCAL_LOOP_ID)
3176 continue;
3177
Arun Easi370d5502012-08-22 14:21:10 -04003178 memset(new_fcport, 0, sizeof(fc_port_t));
3179
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 /* Fill in member data. */
3181 new_fcport->d_id.b.domain = domain;
3182 new_fcport->d_id.b.area = area;
3183 new_fcport->d_id.b.al_pa = al_pa;
3184 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003185 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003187 ql_dbg(ql_dbg_disc, vha, 0x201a,
3188 "Failed to retrieve fcport information "
3189 "-- get_port_database=%x, loop_id=0x%04x.\n",
3190 rval2, new_fcport->loop_id);
3191 ql_dbg(ql_dbg_disc, vha, 0x201b,
3192 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003193 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 continue;
3195 }
3196
3197 /* Check for matching device in port list. */
3198 found = 0;
3199 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003200 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 if (memcmp(new_fcport->port_name, fcport->port_name,
3202 WWN_SIZE))
3203 continue;
3204
Shyam Sundarddb9b122009-03-24 09:08:10 -07003205 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 fcport->loop_id = new_fcport->loop_id;
3207 fcport->port_type = new_fcport->port_type;
3208 fcport->d_id.b24 = new_fcport->d_id.b24;
3209 memcpy(fcport->node_name, new_fcport->node_name,
3210 WWN_SIZE);
3211
3212 found++;
3213 break;
3214 }
3215
3216 if (!found) {
3217 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003218 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219
3220 /* Allocate a new replacement fcport. */
3221 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003222 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003224 ql_log(ql_log_warn, vha, 0x201c,
3225 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 rval = QLA_MEMORY_ALLOC_FAILED;
3227 goto cleanup_allocation;
3228 }
3229 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3230 }
3231
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003232 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003233 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003234
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003235 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236
3237 found_devs++;
3238 }
3239
3240cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003241 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242
3243 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003244 ql_dbg(ql_dbg_disc, vha, 0x201d,
3245 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 }
3247
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 return (rval);
3249}
3250
3251static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003252qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003253{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003254 int rval;
Quinn Tran93f2bd62014-09-25 05:16:53 -04003255 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003256 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003257
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07003258 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003259 return;
3260
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07003261 if (atomic_read(&fcport->state) != FCS_ONLINE)
3262 return;
3263
Andrew Vasquez39bd9622007-09-20 14:07:34 -07003264 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
3265 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003266 return;
3267
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003268 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003269 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003270 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003271 ql_dbg(ql_dbg_disc, vha, 0x2004,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003272 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
3273 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003274 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003275 ql_dbg(ql_dbg_disc, vha, 0x2005,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003276 "iIDMA adjusted to %s GB/s on %8phN.\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -05003277 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003278 fcport->port_name);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003279 }
3280}
3281
Adrian Bunk23be3312006-11-24 02:46:01 +01003282static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003283qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05003284{
3285 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05003286 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003287 unsigned long flags;
8482e1182005-04-17 15:04:54 -05003288
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07003289 rport_ids.node_name = wwn_to_u64(fcport->node_name);
3290 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05003291 rport_ids.port_id = fcport->d_id.b.domain << 16 |
3292 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
3293 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003294 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07003295 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003296 ql_log(ql_log_warn, vha, 0x2006,
3297 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07003298 return;
3299 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003300 /*
3301 * Create target mode FC NEXUS in qla_target.c if target mode is
3302 * enabled..
3303 */
3304 qlt_fc_port_added(vha, fcport);
3305
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003306 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003307 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003308 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003309
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003310 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003311
3312 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05003313 if (fcport->port_type == FCT_INITIATOR)
3314 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3315 if (fcport->port_type == FCT_TARGET)
3316 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003317 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05003318}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319
3320/*
Adrian Bunk23be3312006-11-24 02:46:01 +01003321 * qla2x00_update_fcport
3322 * Updates device on list.
3323 *
3324 * Input:
3325 * ha = adapter block pointer.
3326 * fcport = port structure pointer.
3327 *
3328 * Return:
3329 * 0 - Success
3330 * BIT_0 - error
3331 *
3332 * Context:
3333 * Kernel context.
3334 */
3335void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003336qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01003337{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003338 fcport->vha = vha;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003339
3340 if (IS_QLAFX00(vha->hw)) {
3341 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
3342 qla2x00_reg_remote_port(vha, fcport);
3343 return;
3344 }
Adrian Bunk23be3312006-11-24 02:46:01 +01003345 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003346 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01003347
Joe Carnuccio1f93da522012-11-21 02:40:38 -05003348 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003349 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08003350 qla24xx_update_fcport_fcp_prio(vha, fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003351 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01003352}
3353
3354/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 * qla2x00_configure_fabric
3356 * Setup SNS devices with loop ID's.
3357 *
3358 * Input:
3359 * ha = adapter block pointer.
3360 *
3361 * Returns:
3362 * 0 = success.
3363 * BIT_0 = error
3364 */
3365static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003366qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367{
Arun Easib3b02e62012-02-09 11:15:39 -08003368 int rval;
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003369 fc_port_t *fcport, *fcptemp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 uint16_t next_loopid;
3371 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003372 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003374 struct qla_hw_data *ha = vha->hw;
3375 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376
3377 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003378 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003379 loop_id = NPH_F_PORT;
3380 else
3381 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003382 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003384 ql_dbg(ql_dbg_disc, vha, 0x201f,
3385 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003387 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 return (QLA_SUCCESS);
3389 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003390 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07003393 /* FDMI support. */
3394 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003395 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
3396 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07003397
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003399 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003400 loop_id = NPH_SNS;
3401 else
3402 loop_id = SIMPLE_NAME_SERVER;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003403 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
3404 0xfc, mb, BIT_1|BIT_0);
3405 if (rval != QLA_SUCCESS) {
3406 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003407 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003408 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003410 ql_dbg(ql_dbg_disc, vha, 0x2042,
3411 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3412 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
3413 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 return (QLA_SUCCESS);
3415 }
3416
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003417 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3418 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003420 ql_dbg(ql_dbg_disc, vha, 0x2045,
3421 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003423 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003425 ql_dbg(ql_dbg_disc, vha, 0x2049,
3426 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003428 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003430 ql_dbg(ql_dbg_disc, vha, 0x204f,
3431 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003432 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003434 ql_dbg(ql_dbg_disc, vha, 0x2053,
3435 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 }
3437 }
3438
Joe Carnuccio827210b2013-02-08 01:57:57 -05003439#define QLA_FCPORT_SCAN 1
3440#define QLA_FCPORT_FOUND 2
3441
3442 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3443 fcport->scan_state = QLA_FCPORT_SCAN;
3444 }
3445
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003446 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447 if (rval != QLA_SUCCESS)
3448 break;
3449
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003450 /*
3451 * Logout all previous fabric devices marked lost, except
3452 * FCP2 devices.
3453 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003454 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3455 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456 break;
3457
3458 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3459 continue;
3460
Joe Carnuccio827210b2013-02-08 01:57:57 -05003461 if (fcport->scan_state == QLA_FCPORT_SCAN &&
Arun Easib3b02e62012-02-09 11:15:39 -08003462 atomic_read(&fcport->state) == FCS_ONLINE) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003463 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003464 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003466 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 fcport->port_type != FCT_INITIATOR &&
3468 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003469 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003470 fcport->loop_id,
3471 fcport->d_id.b.domain,
3472 fcport->d_id.b.area,
3473 fcport->d_id.b.al_pa);
Chad Dupuis1a5c69b2014-04-11 16:54:33 -04003474 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 }
3476 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003479 /* Starting free loop ID. */
3480 next_loopid = ha->min_external_loopid;
3481
3482 /*
3483 * Scan through our port list and login entries that need to be
3484 * logged in.
3485 */
3486 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3487 if (atomic_read(&vha->loop_down_timer) ||
3488 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3489 break;
3490
3491 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3492 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3493 continue;
3494
3495 if (fcport->loop_id == FC_NO_LOOP_ID) {
3496 fcport->loop_id = next_loopid;
3497 rval = qla2x00_find_new_loop_id(
3498 base_vha, fcport);
3499 if (rval != QLA_SUCCESS) {
3500 /* Ran out of IDs to use */
3501 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502 }
3503 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003504 /* Login and update database */
3505 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
3506 }
3507
3508 /* Exit if out of loop IDs. */
3509 if (rval != QLA_SUCCESS) {
3510 break;
3511 }
3512
3513 /*
3514 * Login and add the new devices to our port list.
3515 */
3516 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3517 if (atomic_read(&vha->loop_down_timer) ||
3518 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3519 break;
3520
3521 /* Find a new loop ID to use. */
3522 fcport->loop_id = next_loopid;
3523 rval = qla2x00_find_new_loop_id(base_vha, fcport);
3524 if (rval != QLA_SUCCESS) {
3525 /* Ran out of IDs to use */
3526 break;
3527 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528
bdf79622005-04-17 15:06:53 -05003529 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003530 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003531
3532 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 }
3534 } while (0);
3535
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003536 /* Free all new device structures not processed. */
3537 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3538 list_del(&fcport->list);
3539 kfree(fcport);
3540 }
3541
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003543 ql_dbg(ql_dbg_disc, vha, 0x2068,
3544 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 }
3546
3547 return (rval);
3548}
3549
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550/*
3551 * qla2x00_find_all_fabric_devs
3552 *
3553 * Input:
3554 * ha = adapter block pointer.
3555 * dev = database device entry pointer.
3556 *
3557 * Returns:
3558 * 0 = success.
3559 *
3560 * Context:
3561 * Kernel context.
3562 */
3563static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003564qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3565 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566{
3567 int rval;
3568 uint16_t loop_id;
3569 fc_port_t *fcport, *new_fcport, *fcptemp;
3570 int found;
3571
3572 sw_info_t *swl;
3573 int swl_idx;
3574 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003575 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003576 struct qla_hw_data *ha = vha->hw;
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05003577 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578
3579 rval = QLA_SUCCESS;
3580
3581 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08003582 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08003583 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08003584 GFP_KERNEL);
3585 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003586 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003588 ql_dbg(ql_dbg_disc, vha, 0x2054,
3589 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08003591 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003592 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003594 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003596 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003598 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003599 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3600 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003602
3603 /* If other queries succeeded probe for FC-4 type */
3604 if (swl)
3605 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606 }
3607 swl_idx = 0;
3608
3609 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003610 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003612 ql_log(ql_log_warn, vha, 0x205e,
3613 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614 return (QLA_MEMORY_ALLOC_FAILED);
3615 }
3616 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 /* Set start port ID scan at adapter ID. */
3618 first_dev = 1;
3619 last_dev = 0;
3620
3621 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003622 loop_id = ha->min_external_loopid;
3623 for (; loop_id <= ha->max_loop_id; loop_id++) {
3624 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 continue;
3626
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003627 if (ha->current_topology == ISP_CFG_FL &&
3628 (atomic_read(&vha->loop_down_timer) ||
3629 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003630 atomic_set(&vha->loop_down_timer, 0);
3631 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3632 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003634 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635
3636 if (swl != NULL) {
3637 if (last_dev) {
3638 wrap.b24 = new_fcport->d_id.b24;
3639 } else {
3640 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3641 memcpy(new_fcport->node_name,
3642 swl[swl_idx].node_name, WWN_SIZE);
3643 memcpy(new_fcport->port_name,
3644 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003645 memcpy(new_fcport->fabric_port_name,
3646 swl[swl_idx].fabric_port_name, WWN_SIZE);
3647 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003648 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649
3650 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3651 last_dev = 1;
3652 }
3653 swl_idx++;
3654 }
3655 } else {
3656 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003657 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003659 ql_log(ql_log_warn, vha, 0x2064,
3660 "SNS scan failed -- assuming "
3661 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662 list_for_each_entry_safe(fcport, fcptemp,
3663 new_fcports, list) {
3664 list_del(&fcport->list);
3665 kfree(fcport);
3666 }
3667 rval = QLA_SUCCESS;
3668 break;
3669 }
3670 }
3671
3672 /* If wrap on switch device list, exit. */
3673 if (first_dev) {
3674 wrap.b24 = new_fcport->d_id.b24;
3675 first_dev = 0;
3676 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003677 ql_dbg(ql_dbg_disc, vha, 0x2065,
3678 "Device wrap (%02x%02x%02x).\n",
3679 new_fcport->d_id.b.domain,
3680 new_fcport->d_id.b.area,
3681 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 break;
3683 }
3684
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003685 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003686 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687 continue;
3688
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003689 /* Bypass virtual ports of the same host. */
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05003690 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
3691 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003692
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003693 /* Bypass if same domain and area of adapter. */
3694 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003695 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003696 ISP_CFG_FL)
3697 continue;
3698
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 /* Bypass reserved domain fields. */
3700 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3701 continue;
3702
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003703 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003704 if (ql2xgffidenable &&
3705 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3706 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003707 continue;
3708
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709 /* Locate matching device in database. */
3710 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003711 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 if (memcmp(new_fcport->port_name, fcport->port_name,
3713 WWN_SIZE))
3714 continue;
3715
Joe Carnuccio827210b2013-02-08 01:57:57 -05003716 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08003717
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718 found++;
3719
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003720 /* Update port state. */
3721 memcpy(fcport->fabric_port_name,
3722 new_fcport->fabric_port_name, WWN_SIZE);
3723 fcport->fp_speed = new_fcport->fp_speed;
3724
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725 /*
3726 * If address the same and state FCS_ONLINE, nothing
3727 * changed.
3728 */
3729 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3730 atomic_read(&fcport->state) == FCS_ONLINE) {
3731 break;
3732 }
3733
3734 /*
3735 * If device was not a fabric device before.
3736 */
3737 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3738 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04003739 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740 fcport->flags |= (FCF_FABRIC_DEVICE |
3741 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 break;
3743 }
3744
3745 /*
3746 * Port ID changed or device was marked to be updated;
3747 * Log it out if still logged in and mark it for
3748 * relogin later.
3749 */
3750 fcport->d_id.b24 = new_fcport->d_id.b24;
3751 fcport->flags |= FCF_LOGIN_NEEDED;
3752 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003753 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Arun Easi0eba25d2012-02-09 11:15:58 -08003754 (fcport->flags & FCF_ASYNC_SENT) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 fcport->port_type != FCT_INITIATOR &&
3756 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003757 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003758 fcport->d_id.b.domain, fcport->d_id.b.area,
3759 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003760 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 }
3762
3763 break;
3764 }
3765
3766 if (found)
3767 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 /* If device was not in our fcports list, then add it. */
3769 list_add_tail(&new_fcport->list, new_fcports);
3770
3771 /* Allocate a new replacement fcport. */
3772 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003773 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003775 ql_log(ql_log_warn, vha, 0x2066,
3776 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 return (QLA_MEMORY_ALLOC_FAILED);
3778 }
3779 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3780 new_fcport->d_id.b24 = nxt_d_id.b24;
3781 }
3782
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003783 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 return (rval);
3786}
3787
3788/*
3789 * qla2x00_find_new_loop_id
3790 * Scan through our port list and find a new usable loop ID.
3791 *
3792 * Input:
3793 * ha: adapter state pointer.
3794 * dev: port structure pointer.
3795 *
3796 * Returns:
3797 * qla2x00 local function return status code.
3798 *
3799 * Context:
3800 * Kernel context.
3801 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003802int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003803qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804{
3805 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003806 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07003807 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808
3809 rval = QLA_SUCCESS;
3810
Chad Dupuis5f16b332012-08-22 14:21:00 -04003811 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812
Chad Dupuis5f16b332012-08-22 14:21:00 -04003813 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
3814 LOOPID_MAP_SIZE);
3815 if (dev->loop_id >= LOOPID_MAP_SIZE ||
3816 qla2x00_is_reserved_id(vha, dev->loop_id)) {
3817 dev->loop_id = FC_NO_LOOP_ID;
3818 rval = QLA_FUNCTION_FAILED;
3819 } else
3820 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821
Chad Dupuis5f16b332012-08-22 14:21:00 -04003822 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823
Chad Dupuis5f16b332012-08-22 14:21:00 -04003824 if (rval == QLA_SUCCESS)
3825 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
3826 "Assigning new loopid=%x, portid=%x.\n",
3827 dev->loop_id, dev->d_id.b24);
3828 else
3829 ql_log(ql_log_warn, dev->vha, 0x2087,
3830 "No loop_id's available, portid=%x.\n",
3831 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832
3833 return (rval);
3834}
3835
3836/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837 * qla2x00_fabric_dev_login
3838 * Login fabric target device and update FC port database.
3839 *
3840 * Input:
3841 * ha: adapter state pointer.
3842 * fcport: port structure list pointer.
3843 * next_loopid: contains value of a new loop ID that can be used
3844 * by the next login attempt.
3845 *
3846 * Returns:
3847 * qla2x00 local function return status code.
3848 *
3849 * Context:
3850 * Kernel context.
3851 */
3852static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003853qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 uint16_t *next_loopid)
3855{
3856 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003857 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003858 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859
3860 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861
Andrew Vasquezac280b62009-08-20 11:06:05 -07003862 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003863 if (fcport->flags & FCF_ASYNC_SENT)
3864 return rval;
3865 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003866 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3867 if (!rval)
3868 return rval;
3869 }
3870
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003871 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003872 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003874 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003875 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003876 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003877 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003878 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003880 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003881 fcport->d_id.b.domain, fcport->d_id.b.area,
3882 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003883 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003885 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886 }
Chad Dupuis0b91d112012-02-09 11:15:42 -08003887 } else {
3888 /* Retry Login. */
3889 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 }
3891
3892 return (rval);
3893}
3894
3895/*
3896 * qla2x00_fabric_login
3897 * Issue fabric login command.
3898 *
3899 * Input:
3900 * ha = adapter block pointer.
3901 * device = pointer to FC device type structure.
3902 *
3903 * Returns:
3904 * 0 - Login successfully
3905 * 1 - Login failed
3906 * 2 - Initiator device
3907 * 3 - Fatal error
3908 */
3909int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003910qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 uint16_t *next_loopid)
3912{
3913 int rval;
3914 int retry;
3915 uint16_t tmp_loopid;
3916 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003917 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918
3919 retry = 0;
3920 tmp_loopid = 0;
3921
3922 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003923 ql_dbg(ql_dbg_disc, vha, 0x2000,
3924 "Trying Fabric Login w/loop id 0x%04x for port "
3925 "%02x%02x%02x.\n",
3926 fcport->loop_id, fcport->d_id.b.domain,
3927 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928
3929 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08003930 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931 fcport->d_id.b.domain, fcport->d_id.b.area,
3932 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08003933 if (rval != QLA_SUCCESS) {
3934 return rval;
3935 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 if (mb[0] == MBS_PORT_ID_USED) {
3937 /*
3938 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003939 * recommends the driver perform an implicit login with
3940 * the specified ID again. The ID we just used is save
3941 * here so we return with an ID that can be tried by
3942 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 */
3944 retry++;
3945 tmp_loopid = fcport->loop_id;
3946 fcport->loop_id = mb[1];
3947
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003948 ql_dbg(ql_dbg_disc, vha, 0x2001,
3949 "Fabric Login: port in use - next loop "
3950 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003952 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953
3954 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3955 /*
3956 * Login succeeded.
3957 */
3958 if (retry) {
3959 /* A retry occurred before. */
3960 *next_loopid = tmp_loopid;
3961 } else {
3962 /*
3963 * No retry occurred before. Just increment the
3964 * ID value for next login.
3965 */
3966 *next_loopid = (fcport->loop_id + 1);
3967 }
3968
3969 if (mb[1] & BIT_0) {
3970 fcport->port_type = FCT_INITIATOR;
3971 } else {
3972 fcport->port_type = FCT_TARGET;
3973 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003974 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975 }
3976 }
3977
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003978 if (mb[10] & BIT_0)
3979 fcport->supported_classes |= FC_COS_CLASS2;
3980 if (mb[10] & BIT_1)
3981 fcport->supported_classes |= FC_COS_CLASS3;
3982
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003983 if (IS_FWI2_CAPABLE(ha)) {
3984 if (mb[10] & BIT_7)
3985 fcport->flags |=
3986 FCF_CONF_COMP_SUPPORTED;
3987 }
3988
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 rval = QLA_SUCCESS;
3990 break;
3991 } else if (mb[0] == MBS_LOOP_ID_USED) {
3992 /*
3993 * Loop ID already used, try next loop ID.
3994 */
3995 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003996 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997 if (rval != QLA_SUCCESS) {
3998 /* Ran out of loop IDs to use */
3999 break;
4000 }
4001 } else if (mb[0] == MBS_COMMAND_ERROR) {
4002 /*
4003 * Firmware possibly timed out during login. If NO
4004 * retries are left to do then the device is declared
4005 * dead.
4006 */
4007 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004008 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07004009 fcport->d_id.b.domain, fcport->d_id.b.area,
4010 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004011 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012
4013 rval = 1;
4014 break;
4015 } else {
4016 /*
4017 * unrecoverable / not handled error
4018 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004019 ql_dbg(ql_dbg_disc, vha, 0x2002,
4020 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
4021 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
4022 fcport->d_id.b.area, fcport->d_id.b.al_pa,
4023 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024
4025 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004026 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07004027 fcport->d_id.b.domain, fcport->d_id.b.area,
4028 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004029 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07004030 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031
4032 rval = 3;
4033 break;
4034 }
4035 }
4036
4037 return (rval);
4038}
4039
4040/*
4041 * qla2x00_local_device_login
4042 * Issue local device login command.
4043 *
4044 * Input:
4045 * ha = adapter block pointer.
4046 * loop_id = loop id of device to login to.
4047 *
4048 * Returns (Where's the #define!!!!):
4049 * 0 - Login successfully
4050 * 1 - Login failed
4051 * 3 - Fatal error
4052 */
4053int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004054qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055{
4056 int rval;
4057 uint16_t mb[MAILBOX_REGISTER_COUNT];
4058
4059 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004060 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061 if (rval == QLA_SUCCESS) {
4062 /* Interrogate mailbox registers for any errors */
4063 if (mb[0] == MBS_COMMAND_ERROR)
4064 rval = 1;
4065 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
4066 /* device not in PCB table */
4067 rval = 3;
4068 }
4069
4070 return (rval);
4071}
4072
4073/*
4074 * qla2x00_loop_resync
4075 * Resync with fibre channel devices.
4076 *
4077 * Input:
4078 * ha = adapter block pointer.
4079 *
4080 * Returns:
4081 * 0 = success
4082 */
4083int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004084qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004086 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004088 struct req_que *req;
4089 struct rsp_que *rsp;
4090
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004091 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004092 req = vha->hw->req_q_map[0];
4093 else
4094 req = vha->req;
4095 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004097 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4098 if (vha->flags.online) {
4099 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4101 wait_time = 256;
4102 do {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004103 if (!IS_QLAFX00(vha->hw)) {
4104 /*
4105 * Issue a marker after FW becomes
4106 * ready.
4107 */
4108 qla2x00_marker(vha, req, rsp, 0, 0,
4109 MK_SYNC_ALL);
4110 vha->marker_needed = 0;
4111 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112
4113 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004114 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004116 if (IS_QLAFX00(vha->hw))
4117 qlafx00_configure_devices(vha);
4118 else
4119 qla2x00_configure_loop(vha);
4120
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004122 } while (!atomic_read(&vha->loop_down_timer) &&
4123 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4124 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4125 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127 }
4128
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004129 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004132 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004133 ql_dbg(ql_dbg_disc, vha, 0x206c,
4134 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135
4136 return (rval);
4137}
4138
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004139/*
4140* qla2x00_perform_loop_resync
4141* Description: This function will set the appropriate flags and call
4142* qla2x00_loop_resync. If successful loop will be resynced
4143* Arguments : scsi_qla_host_t pointer
4144* returm : Success or Failure
4145*/
4146
4147int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
4148{
4149 int32_t rval = 0;
4150
4151 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
4152 /*Configure the flags so that resync happens properly*/
4153 atomic_set(&ha->loop_down_timer, 0);
4154 if (!(ha->device_flags & DFLG_NO_CABLE)) {
4155 atomic_set(&ha->loop_state, LOOP_UP);
4156 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4157 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
4158 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4159
4160 rval = qla2x00_loop_resync(ha);
4161 } else
4162 atomic_set(&ha->loop_state, LOOP_DEAD);
4163
4164 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
4165 }
4166
4167 return rval;
4168}
4169
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170void
Andrew Vasquez67becc02009-08-25 11:36:20 -07004171qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004172{
4173 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07004174 struct scsi_qla_host *vha;
4175 struct qla_hw_data *ha = base_vha->hw;
4176 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004177
Arun Easifeafb7b2010-09-03 14:57:00 -07004178 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004179 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07004180 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
4181 atomic_inc(&vha->vref_count);
4182 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08004183 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07004184 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
4185 spin_unlock_irqrestore(&ha->vport_slock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07004186 qla2x00_rport_del(fcport);
Arun Easifeafb7b2010-09-03 14:57:00 -07004187 spin_lock_irqsave(&ha->vport_slock, flags);
4188 }
4189 }
4190 atomic_dec(&vha->vref_count);
4191 }
4192 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004193}
4194
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004195/* Assumes idc_lock always held on entry */
4196void
4197qla83xx_reset_ownership(scsi_qla_host_t *vha)
4198{
4199 struct qla_hw_data *ha = vha->hw;
4200 uint32_t drv_presence, drv_presence_mask;
4201 uint32_t dev_part_info1, dev_part_info2, class_type;
4202 uint32_t class_type_mask = 0x3;
4203 uint16_t fcoe_other_function = 0xffff, i;
4204
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004205 if (IS_QLA8044(ha)) {
4206 drv_presence = qla8044_rd_direct(vha,
4207 QLA8044_CRB_DRV_ACTIVE_INDEX);
4208 dev_part_info1 = qla8044_rd_direct(vha,
4209 QLA8044_CRB_DEV_PART_INFO_INDEX);
4210 dev_part_info2 = qla8044_rd_direct(vha,
4211 QLA8044_CRB_DEV_PART_INFO2);
4212 } else {
4213 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4214 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
4215 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
4216 }
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004217 for (i = 0; i < 8; i++) {
4218 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
4219 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4220 (i != ha->portnum)) {
4221 fcoe_other_function = i;
4222 break;
4223 }
4224 }
4225 if (fcoe_other_function == 0xffff) {
4226 for (i = 0; i < 8; i++) {
4227 class_type = ((dev_part_info2 >> (i * 4)) &
4228 class_type_mask);
4229 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4230 ((i + 8) != ha->portnum)) {
4231 fcoe_other_function = i + 8;
4232 break;
4233 }
4234 }
4235 }
4236 /*
4237 * Prepare drv-presence mask based on fcoe functions present.
4238 * However consider only valid physical fcoe function numbers (0-15).
4239 */
4240 drv_presence_mask = ~((1 << (ha->portnum)) |
4241 ((fcoe_other_function == 0xffff) ?
4242 0 : (1 << (fcoe_other_function))));
4243
4244 /* We are the reset owner iff:
4245 * - No other protocol drivers present.
4246 * - This is the lowest among fcoe functions. */
4247 if (!(drv_presence & drv_presence_mask) &&
4248 (ha->portnum < fcoe_other_function)) {
4249 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
4250 "This host is Reset owner.\n");
4251 ha->flags.nic_core_reset_owner = 1;
4252 }
4253}
4254
Saurav Kashyapfa492632012-11-21 02:40:29 -05004255static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004256__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
4257{
4258 int rval = QLA_SUCCESS;
4259 struct qla_hw_data *ha = vha->hw;
4260 uint32_t drv_ack;
4261
4262 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4263 if (rval == QLA_SUCCESS) {
4264 drv_ack |= (1 << ha->portnum);
4265 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4266 }
4267
4268 return rval;
4269}
4270
Saurav Kashyapfa492632012-11-21 02:40:29 -05004271static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004272__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
4273{
4274 int rval = QLA_SUCCESS;
4275 struct qla_hw_data *ha = vha->hw;
4276 uint32_t drv_ack;
4277
4278 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4279 if (rval == QLA_SUCCESS) {
4280 drv_ack &= ~(1 << ha->portnum);
4281 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4282 }
4283
4284 return rval;
4285}
4286
Saurav Kashyapfa492632012-11-21 02:40:29 -05004287static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004288qla83xx_dev_state_to_string(uint32_t dev_state)
4289{
4290 switch (dev_state) {
4291 case QLA8XXX_DEV_COLD:
4292 return "COLD/RE-INIT";
4293 case QLA8XXX_DEV_INITIALIZING:
4294 return "INITIALIZING";
4295 case QLA8XXX_DEV_READY:
4296 return "READY";
4297 case QLA8XXX_DEV_NEED_RESET:
4298 return "NEED RESET";
4299 case QLA8XXX_DEV_NEED_QUIESCENT:
4300 return "NEED QUIESCENT";
4301 case QLA8XXX_DEV_FAILED:
4302 return "FAILED";
4303 case QLA8XXX_DEV_QUIESCENT:
4304 return "QUIESCENT";
4305 default:
4306 return "Unknown";
4307 }
4308}
4309
4310/* Assumes idc-lock always held on entry */
4311void
4312qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
4313{
4314 struct qla_hw_data *ha = vha->hw;
4315 uint32_t idc_audit_reg = 0, duration_secs = 0;
4316
4317 switch (audit_type) {
4318 case IDC_AUDIT_TIMESTAMP:
4319 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
4320 idc_audit_reg = (ha->portnum) |
4321 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
4322 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4323 break;
4324
4325 case IDC_AUDIT_COMPLETION:
4326 duration_secs = ((jiffies_to_msecs(jiffies) -
4327 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
4328 idc_audit_reg = (ha->portnum) |
4329 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
4330 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4331 break;
4332
4333 default:
4334 ql_log(ql_log_warn, vha, 0xb078,
4335 "Invalid audit type specified.\n");
4336 break;
4337 }
4338}
4339
4340/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05004341static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004342qla83xx_initiating_reset(scsi_qla_host_t *vha)
4343{
4344 struct qla_hw_data *ha = vha->hw;
4345 uint32_t idc_control, dev_state;
4346
4347 __qla83xx_get_idc_control(vha, &idc_control);
4348 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
4349 ql_log(ql_log_info, vha, 0xb080,
4350 "NIC Core reset has been disabled. idc-control=0x%x\n",
4351 idc_control);
4352 return QLA_FUNCTION_FAILED;
4353 }
4354
4355 /* Set NEED-RESET iff in READY state and we are the reset-owner */
4356 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4357 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
4358 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
4359 QLA8XXX_DEV_NEED_RESET);
4360 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
4361 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
4362 } else {
4363 const char *state = qla83xx_dev_state_to_string(dev_state);
4364 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
4365
4366 /* SV: XXX: Is timeout required here? */
4367 /* Wait for IDC state change READY -> NEED_RESET */
4368 while (dev_state == QLA8XXX_DEV_READY) {
4369 qla83xx_idc_unlock(vha, 0);
4370 msleep(200);
4371 qla83xx_idc_lock(vha, 0);
4372 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4373 }
4374 }
4375
4376 /* Send IDC ack by writing to drv-ack register */
4377 __qla83xx_set_drv_ack(vha);
4378
4379 return QLA_SUCCESS;
4380}
4381
4382int
4383__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
4384{
4385 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4386}
4387
4388int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004389__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
4390{
4391 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4392}
4393
Saurav Kashyapfa492632012-11-21 02:40:29 -05004394static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004395qla83xx_check_driver_presence(scsi_qla_host_t *vha)
4396{
4397 uint32_t drv_presence = 0;
4398 struct qla_hw_data *ha = vha->hw;
4399
4400 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4401 if (drv_presence & (1 << ha->portnum))
4402 return QLA_SUCCESS;
4403 else
4404 return QLA_TEST_FAILED;
4405}
4406
4407int
4408qla83xx_nic_core_reset(scsi_qla_host_t *vha)
4409{
4410 int rval = QLA_SUCCESS;
4411 struct qla_hw_data *ha = vha->hw;
4412
4413 ql_dbg(ql_dbg_p3p, vha, 0xb058,
4414 "Entered %s().\n", __func__);
4415
4416 if (vha->device_flags & DFLG_DEV_FAILED) {
4417 ql_log(ql_log_warn, vha, 0xb059,
4418 "Device in unrecoverable FAILED state.\n");
4419 return QLA_FUNCTION_FAILED;
4420 }
4421
4422 qla83xx_idc_lock(vha, 0);
4423
4424 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
4425 ql_log(ql_log_warn, vha, 0xb05a,
4426 "Function=0x%x has been removed from IDC participation.\n",
4427 ha->portnum);
4428 rval = QLA_FUNCTION_FAILED;
4429 goto exit;
4430 }
4431
4432 qla83xx_reset_ownership(vha);
4433
4434 rval = qla83xx_initiating_reset(vha);
4435
4436 /*
4437 * Perform reset if we are the reset-owner,
4438 * else wait till IDC state changes to READY/FAILED.
4439 */
4440 if (rval == QLA_SUCCESS) {
4441 rval = qla83xx_idc_state_handler(vha);
4442
4443 if (rval == QLA_SUCCESS)
4444 ha->flags.nic_core_hung = 0;
4445 __qla83xx_clear_drv_ack(vha);
4446 }
4447
4448exit:
4449 qla83xx_idc_unlock(vha, 0);
4450
4451 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
4452
4453 return rval;
4454}
4455
Saurav Kashyap81178772012-08-22 14:21:04 -04004456int
4457qla2xxx_mctp_dump(scsi_qla_host_t *vha)
4458{
4459 struct qla_hw_data *ha = vha->hw;
4460 int rval = QLA_FUNCTION_FAILED;
4461
4462 if (!IS_MCTP_CAPABLE(ha)) {
4463 /* This message can be removed from the final version */
4464 ql_log(ql_log_info, vha, 0x506d,
4465 "This board is not MCTP capable\n");
4466 return rval;
4467 }
4468
4469 if (!ha->mctp_dump) {
4470 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
4471 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
4472
4473 if (!ha->mctp_dump) {
4474 ql_log(ql_log_warn, vha, 0x506e,
4475 "Failed to allocate memory for mctp dump\n");
4476 return rval;
4477 }
4478 }
4479
4480#define MCTP_DUMP_STR_ADDR 0x00000000
4481 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
4482 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
4483 if (rval != QLA_SUCCESS) {
4484 ql_log(ql_log_warn, vha, 0x506f,
4485 "Failed to capture mctp dump\n");
4486 } else {
4487 ql_log(ql_log_info, vha, 0x5070,
4488 "Mctp dump capture for host (%ld/%p).\n",
4489 vha->host_no, ha->mctp_dump);
4490 ha->mctp_dumped = 1;
4491 }
4492
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04004493 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04004494 ha->flags.nic_core_reset_hdlr_active = 1;
4495 rval = qla83xx_restart_nic_firmware(vha);
4496 if (rval)
4497 /* NIC Core reset failed. */
4498 ql_log(ql_log_warn, vha, 0x5071,
4499 "Failed to restart nic firmware\n");
4500 else
4501 ql_dbg(ql_dbg_p3p, vha, 0xb084,
4502 "Restarted NIC firmware successfully.\n");
4503 ha->flags.nic_core_reset_hdlr_active = 0;
4504 }
4505
4506 return rval;
4507
4508}
4509
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004510/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004511* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004512* Description: This function will block the new I/Os
4513* Its not aborting any I/Os as context
4514* is not destroyed during quiescence
4515* Arguments: scsi_qla_host_t
4516* return : void
4517*/
4518void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004519qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004520{
4521 struct qla_hw_data *ha = vha->hw;
4522 struct scsi_qla_host *vp;
4523
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004524 ql_dbg(ql_dbg_dpc, vha, 0x401d,
4525 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004526
4527 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4528 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4529 atomic_set(&vha->loop_state, LOOP_DOWN);
4530 qla2x00_mark_all_devices_lost(vha, 0);
4531 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004532 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004533 } else {
4534 if (!atomic_read(&vha->loop_down_timer))
4535 atomic_set(&vha->loop_down_timer,
4536 LOOP_DOWN_TIME);
4537 }
4538 /* Wait for pending cmds to complete */
4539 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
4540}
4541
Giridhar Malavalia9083012010-04-12 17:59:55 -07004542void
4543qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
4544{
4545 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004546 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07004547 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004548 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004549
Saurav Kashyape46ef002011-02-23 15:27:16 -08004550 /* For ISP82XX, driver waits for completion of the commands.
4551 * online flag should be set.
4552 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004553 if (!(IS_P3P_TYPE(ha)))
Saurav Kashyape46ef002011-02-23 15:27:16 -08004554 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004555 ha->flags.chip_reset_done = 0;
4556 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04004557 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004558
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004559 ql_log(ql_log_info, vha, 0x00af,
4560 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004561
Saurav Kashyape46ef002011-02-23 15:27:16 -08004562 /* For ISP82XX, reset_chip is just disabling interrupts.
4563 * Driver waits for the completion of the commands.
4564 * the interrupts need to be enabled.
4565 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004566 if (!(IS_P3P_TYPE(ha)))
Giridhar Malavalia9083012010-04-12 17:59:55 -07004567 ha->isp_ops->reset_chip(vha);
4568
4569 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
4570 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4571 atomic_set(&vha->loop_state, LOOP_DOWN);
4572 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004573
4574 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004575 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07004576 atomic_inc(&vp->vref_count);
4577 spin_unlock_irqrestore(&ha->vport_slock, flags);
4578
Giridhar Malavalia9083012010-04-12 17:59:55 -07004579 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004580
4581 spin_lock_irqsave(&ha->vport_slock, flags);
4582 atomic_dec(&vp->vref_count);
4583 }
4584 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004585 } else {
4586 if (!atomic_read(&vha->loop_down_timer))
4587 atomic_set(&vha->loop_down_timer,
4588 LOOP_DOWN_TIME);
4589 }
4590
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004591 /* Clear all async request states across all VPs. */
4592 list_for_each_entry(fcport, &vha->vp_fcports, list)
4593 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4594 spin_lock_irqsave(&ha->vport_slock, flags);
4595 list_for_each_entry(vp, &ha->vp_list, list) {
4596 atomic_inc(&vp->vref_count);
4597 spin_unlock_irqrestore(&ha->vport_slock, flags);
4598
4599 list_for_each_entry(fcport, &vp->vp_fcports, list)
4600 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4601
4602 spin_lock_irqsave(&ha->vport_slock, flags);
4603 atomic_dec(&vp->vref_count);
4604 }
4605 spin_unlock_irqrestore(&ha->vport_slock, flags);
4606
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004607 if (!ha->flags.eeh_busy) {
4608 /* Make sure for ISP 82XX IO DMA is complete */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004609 if (IS_P3P_TYPE(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004610 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004611 ql_log(ql_log_info, vha, 0x00b4,
4612 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004613
Saurav Kashyape46ef002011-02-23 15:27:16 -08004614 /* Done waiting for pending commands.
4615 * Reset the online flag.
4616 */
4617 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004618 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004619
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004620 /* Requeue all commands in outstanding command list. */
4621 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4622 }
Arun Easib6a029e2014-09-25 06:14:52 -04004623
4624 ha->chip_reset++;
4625 /* memory barrier */
4626 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004627}
4628
4629/*
4630* qla2x00_abort_isp
4631* Resets ISP and aborts all outstanding commands.
4632*
4633* Input:
4634* ha = adapter block pointer.
4635*
4636* Returns:
4637* 0 = success
4638*/
4639int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004640qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641{
Andrew Vasquez476e8972006-08-23 14:54:55 -07004642 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004643 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004644 struct qla_hw_data *ha = vha->hw;
4645 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004646 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07004647 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004649 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004650 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651
Santosh Vernekara61712972012-08-22 14:21:13 -04004652 if (IS_QLA8031(ha)) {
4653 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
4654 "Clearing fcoe driver presence.\n");
4655 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
4656 ql_dbg(ql_dbg_p3p, vha, 0xb073,
4657 "Error while clearing DRV-Presence.\n");
4658 }
4659
Andrew Vasquez85880802009-12-15 21:29:46 -08004660 if (unlikely(pci_channel_offline(ha->pdev) &&
4661 ha->flags.pci_channel_io_perm_failure)) {
4662 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4663 status = 0;
4664 return status;
4665 }
4666
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004667 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08004668
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004669 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004671 if (!qla2x00_restart_isp(vha)) {
4672 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004673
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004674 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004675 /*
4676 * Issue marker command only when we are going
4677 * to start the I/O .
4678 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004679 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004680 }
4681
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004682 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004683
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004684 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004686 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004687 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07004688
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004689 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
4690 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004691 if (ha->fce) {
4692 ha->flags.fce_enabled = 1;
4693 memset(ha->fce, 0,
4694 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004695 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004696 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4697 &ha->fce_bufs);
4698 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004699 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004700 "Unable to reinitialize FCE "
4701 "(%d).\n", rval);
4702 ha->flags.fce_enabled = 0;
4703 }
4704 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004705
4706 if (ha->eft) {
4707 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004708 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004709 ha->eft_dma, EFT_NUM_BUFFERS);
4710 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004711 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004712 "Unable to reinitialize EFT "
4713 "(%d).\n", rval);
4714 }
4715 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004717 vha->flags.online = 1;
4718 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004719 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004720 ql_log(ql_log_fatal, vha, 0x8035,
4721 "ISP error recover failed - "
4722 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004723 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724 * The next call disables the board
4725 * completely.
4726 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004727 ha->isp_ops->reset_adapter(vha);
4728 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004729 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004730 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731 status = 0;
4732 } else { /* schedule another ISP abort */
4733 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004734 ql_dbg(ql_dbg_taskm, vha, 0x8020,
4735 "ISP abort - retry remaining %d.\n",
4736 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004737 status = 1;
4738 }
4739 } else {
4740 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004741 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4742 "ISP error recovery - retrying (%d) "
4743 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004744 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745 status = 1;
4746 }
4747 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004748
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749 }
4750
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004751 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004752 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07004753
4754 spin_lock_irqsave(&ha->vport_slock, flags);
4755 list_for_each_entry(vp, &ha->vp_list, list) {
4756 if (vp->vp_idx) {
4757 atomic_inc(&vp->vref_count);
4758 spin_unlock_irqrestore(&ha->vport_slock, flags);
4759
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004760 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004761
4762 spin_lock_irqsave(&ha->vport_slock, flags);
4763 atomic_dec(&vp->vref_count);
4764 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004765 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004766 spin_unlock_irqrestore(&ha->vport_slock, flags);
4767
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004768 if (IS_QLA8031(ha)) {
4769 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
4770 "Setting back fcoe driver presence.\n");
4771 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
4772 ql_dbg(ql_dbg_p3p, vha, 0xb074,
4773 "Error while setting DRV-Presence.\n");
4774 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004775 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08004776 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
4777 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004778 }
4779
4780 return(status);
4781}
4782
4783/*
4784* qla2x00_restart_isp
4785* restarts the ISP after a reset
4786*
4787* Input:
4788* ha = adapter block pointer.
4789*
4790* Returns:
4791* 0 = success
4792*/
4793static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004794qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004795{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004796 int status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004797 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004798 struct req_que *req = ha->req_q_map[0];
4799 struct rsp_que *rsp = ha->rsp_q_map[0];
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004800 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004801
4802 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004803 if (qla2x00_isp_firmware(vha)) {
4804 vha->flags.online = 0;
4805 status = ha->isp_ops->chip_diag(vha);
4806 if (!status)
4807 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004808 }
4809
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004810 if (!status && !(status = qla2x00_init_rings(vha))) {
4811 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004812 ha->flags.chip_reset_done = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04004813
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004814 /* Initialize the queues in use */
4815 qla25xx_init_queues(ha);
4816
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004817 status = qla2x00_fw_ready(vha);
4818 if (!status) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004819 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004820 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004821
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004822 vha->flags.online = 1;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004823
4824 /*
4825 * Process any ATIO queue entries that came in
4826 * while we weren't online.
4827 */
4828 spin_lock_irqsave(&ha->hardware_lock, flags);
4829 if (qla_tgt_mode_enabled(vha))
4830 qlt_24xx_process_atio_queue(vha);
4831 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4832
Chad Dupuis7108b762014-04-11 16:54:45 -04004833 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004834 }
4835
4836 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004837 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004838 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004839 }
4840 return (status);
4841}
4842
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004843static int
4844qla25xx_init_queues(struct qla_hw_data *ha)
4845{
4846 struct rsp_que *rsp = NULL;
4847 struct req_que *req = NULL;
4848 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4849 int ret = -1;
4850 int i;
4851
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004852 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004853 rsp = ha->rsp_q_map[i];
4854 if (rsp) {
4855 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004856 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004857 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004858 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4859 "%s Rsp que: %d init failed.\n",
4860 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004861 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004862 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4863 "%s Rsp que: %d inited.\n",
4864 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004865 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004866 }
4867 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004868 req = ha->req_q_map[i];
4869 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004870 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004871 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004872 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004873 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004874 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4875 "%s Req que: %d init failed.\n",
4876 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004877 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004878 ql_dbg(ql_dbg_init, base_vha, 0x0102,
4879 "%s Req que: %d inited.\n",
4880 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004881 }
4882 }
4883 return ret;
4884}
4885
Linus Torvalds1da177e2005-04-16 15:20:36 -07004886/*
4887* qla2x00_reset_adapter
4888* Reset adapter.
4889*
4890* Input:
4891* ha = adapter block pointer.
4892*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004893void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004894qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895{
4896 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004897 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004898 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004900 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004901 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902
Linus Torvalds1da177e2005-04-16 15:20:36 -07004903 spin_lock_irqsave(&ha->hardware_lock, flags);
4904 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4905 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4906 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4907 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4908 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4909}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004910
4911void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004912qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004913{
4914 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004915 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004916 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4917
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004918 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07004919 return;
4920
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004921 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004922 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004923
4924 spin_lock_irqsave(&ha->hardware_lock, flags);
4925 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4926 RD_REG_DWORD(&reg->hccr);
4927 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4928 RD_REG_DWORD(&reg->hccr);
4929 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004930
4931 if (IS_NOPOLLING_TYPE(ha))
4932 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004933}
4934
David Miller4e08df32007-04-16 12:37:43 -07004935/* On sparc systems, obtain port and node WWN from firmware
4936 * properties.
4937 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004938static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4939 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004940{
4941#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004942 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004943 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004944 struct device_node *dp = pci_device_to_OF_node(pdev);
4945 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004946 int len;
4947
4948 val = of_get_property(dp, "port-wwn", &len);
4949 if (val && len >= WWN_SIZE)
4950 memcpy(nv->port_name, val, WWN_SIZE);
4951
4952 val = of_get_property(dp, "node-wwn", &len);
4953 if (val && len >= WWN_SIZE)
4954 memcpy(nv->node_name, val, WWN_SIZE);
4955#endif
4956}
4957
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004958int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004959qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004960{
David Miller4e08df32007-04-16 12:37:43 -07004961 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004962 struct init_cb_24xx *icb;
4963 struct nvram_24xx *nv;
4964 uint32_t *dptr;
4965 uint8_t *dptr1, *dptr2;
4966 uint32_t chksum;
4967 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004968 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004969
David Miller4e08df32007-04-16 12:37:43 -07004970 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004971 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004972 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004973
4974 /* Determine NVRAM starting address. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05004975 if (ha->port_no == 0) {
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004976 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4977 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4978 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004979 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004980 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4981 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05004982
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004983 ha->nvram_size = sizeof(struct nvram_24xx);
4984 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004985
Seokmann Ju281afe12007-07-26 13:43:34 -07004986 /* Get VPD data into cache */
4987 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004988 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004989 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4990
4991 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004992 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004993 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004994 ha->nvram_size);
4995 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4996 chksum += le32_to_cpu(*dptr++);
4997
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004998 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
4999 "Contents of NVRAM\n");
5000 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
5001 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005002
5003 /* Bad NVRAM data, set defaults parameters. */
5004 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5005 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07005006 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005007 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005008 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04005009 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005010 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
5011 ql_log(ql_log_warn, vha, 0x006c,
5012 "Falling back to functioning (yet invalid -- WWPN) "
5013 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07005014
5015 /*
5016 * Set default initialization control block.
5017 */
5018 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07005019 nv->nvram_version = cpu_to_le16(ICB_VERSION);
5020 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04005021 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07005022 nv->execution_throttle = cpu_to_le16(0xFFFF);
5023 nv->exchange_count = cpu_to_le16(0);
5024 nv->hard_address = cpu_to_le16(124);
David Miller4e08df32007-04-16 12:37:43 -07005025 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005026 nv->port_name[1] = 0x00 + ha->port_no + 1;
David Miller4e08df32007-04-16 12:37:43 -07005027 nv->port_name[2] = 0x00;
5028 nv->port_name[3] = 0xe0;
5029 nv->port_name[4] = 0x8b;
5030 nv->port_name[5] = 0x1c;
5031 nv->port_name[6] = 0x55;
5032 nv->port_name[7] = 0x86;
5033 nv->node_name[0] = 0x20;
5034 nv->node_name[1] = 0x00;
5035 nv->node_name[2] = 0x00;
5036 nv->node_name[3] = 0xe0;
5037 nv->node_name[4] = 0x8b;
5038 nv->node_name[5] = 0x1c;
5039 nv->node_name[6] = 0x55;
5040 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005041 qla24xx_nvram_wwn_from_ofw(vha, nv);
Bart Van Asschead950362015-07-09 07:24:08 -07005042 nv->login_retry_count = cpu_to_le16(8);
5043 nv->interrupt_delay_timer = cpu_to_le16(0);
5044 nv->login_timeout = cpu_to_le16(0);
David Miller4e08df32007-04-16 12:37:43 -07005045 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07005046 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5047 nv->firmware_options_2 = cpu_to_le32(2 << 4);
5048 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
5049 nv->firmware_options_3 = cpu_to_le32(2 << 13);
5050 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
5051 nv->efi_parameters = cpu_to_le32(0);
David Miller4e08df32007-04-16 12:37:43 -07005052 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07005053 nv->max_luns_per_target = cpu_to_le16(128);
5054 nv->port_down_retry_count = cpu_to_le16(30);
5055 nv->link_down_timeout = cpu_to_le16(30);
David Miller4e08df32007-04-16 12:37:43 -07005056
5057 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005058 }
5059
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005060 if (!qla_ini_mode_enabled(vha)) {
5061 /* Don't enable full login after initial LIP */
Bart Van Asschead950362015-07-09 07:24:08 -07005062 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005063 /* Don't enable LIP full login for initiator */
Bart Van Asschead950362015-07-09 07:24:08 -07005064 nv->host_p &= cpu_to_le32(~BIT_10);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005065 }
5066
5067 qlt_24xx_config_nvram_stage1(vha, nv);
5068
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005069 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005070 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005071
5072 /* Copy 1st segment. */
5073 dptr1 = (uint8_t *)icb;
5074 dptr2 = (uint8_t *)&nv->version;
5075 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5076 while (cnt--)
5077 *dptr1++ = *dptr2++;
5078
5079 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07005080 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005081
5082 /* Copy 2nd segment. */
5083 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5084 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5085 cnt = (uint8_t *)&icb->reserved_3 -
5086 (uint8_t *)&icb->interrupt_delay_timer;
5087 while (cnt--)
5088 *dptr1++ = *dptr2++;
5089
5090 /*
5091 * Setup driver NVRAM options.
5092 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005093 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08005094 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005095
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005096 qlt_24xx_config_nvram_stage2(vha, icb);
5097
Bart Van Asschead950362015-07-09 07:24:08 -07005098 if (nv->host_p & cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005099 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07005100 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5101 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5102 }
5103
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005104 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07005105 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005106 /*
5107 * Firmware will apply the following mask if the nodename was
5108 * not provided.
5109 */
5110 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5111 icb->node_name[0] &= 0xF0;
5112 }
5113
5114 /* Set host adapter parameters. */
5115 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08005116 ha->flags.enable_lip_reset = 0;
5117 ha->flags.enable_lip_full_login =
5118 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5119 ha->flags.enable_target_reset =
5120 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005121 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07005122 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005123
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07005124 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5125 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005126
5127 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
5128 sizeof(ha->fw_seriallink_options24));
5129
5130 /* save HBA serial number */
5131 ha->serial0 = icb->port_name[5];
5132 ha->serial1 = icb->port_name[6];
5133 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005134 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5135 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005136
Bart Van Asschead950362015-07-09 07:24:08 -07005137 icb->execution_throttle = cpu_to_le16(0xFFFF);
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08005138
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005139 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5140
5141 /* Set minimum login_timeout to 4 seconds. */
5142 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5143 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5144 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07005145 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005146 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07005147 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005148
Andrew Vasquez00a537b2008-02-28 14:06:11 -08005149 /* Set minimum RATOV to 100 tenths of a second. */
5150 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005151
5152 ha->loop_reset_delay = nv->reset_delay;
5153
5154 /* Link Down Timeout = 0:
5155 *
5156 * When Port Down timer expires we will start returning
5157 * I/O's to OS with "DID_NO_CONNECT".
5158 *
5159 * Link Down Timeout != 0:
5160 *
5161 * The driver waits for the link to come up after link down
5162 * before returning I/Os to OS with "DID_NO_CONNECT".
5163 */
5164 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5165 ha->loop_down_abort_time =
5166 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5167 } else {
5168 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5169 ha->loop_down_abort_time =
5170 (LOOP_DOWN_TIME - ha->link_down_timeout);
5171 }
5172
5173 /* Need enough time to try and get the port back. */
5174 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5175 if (qlport_down_retry)
5176 ha->port_down_retry_count = qlport_down_retry;
5177
5178 /* Set login_retry_count */
5179 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5180 if (ha->port_down_retry_count ==
5181 le16_to_cpu(nv->port_down_retry_count) &&
5182 ha->port_down_retry_count > 3)
5183 ha->login_retry_count = ha->port_down_retry_count;
5184 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5185 ha->login_retry_count = ha->port_down_retry_count;
5186 if (ql2xloginretrycount)
5187 ha->login_retry_count = ql2xloginretrycount;
5188
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005189 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005190 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005191 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5192 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5193 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5194 le16_to_cpu(icb->interrupt_delay_timer): 2;
5195 }
Bart Van Asschead950362015-07-09 07:24:08 -07005196 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005197 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005198 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005199 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08005200 ha->zio_mode = QLA_ZIO_MODE_6;
5201
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005202 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005203 "ZIO mode %d enabled; timer delay (%d us).\n",
5204 ha->zio_mode, ha->zio_timer * 100);
5205
5206 icb->firmware_options_2 |= cpu_to_le32(
5207 (uint32_t)ha->zio_mode);
5208 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005209 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005210 }
5211
David Miller4e08df32007-04-16 12:37:43 -07005212 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005213 ql_log(ql_log_warn, vha, 0x0070,
5214 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07005215 }
5216 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005217}
5218
Adrian Bunk413975a2006-06-30 02:33:06 -07005219static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005220qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
5221 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005222{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005223 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005224 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005225 uint32_t *dcode, dlen;
5226 uint32_t risc_addr;
5227 uint32_t risc_size;
5228 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005229 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005230 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005231
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005232 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08005233 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005234
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005235 rval = QLA_SUCCESS;
5236
5237 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005238 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005239 *srisc_addr = 0;
5240
5241 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005242 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005243 for (i = 0; i < 4; i++)
5244 dcode[i] = be32_to_cpu(dcode[i]);
5245 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5246 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5247 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5248 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005249 ql_log(ql_log_fatal, vha, 0x008c,
5250 "Unable to verify the integrity of flash firmware "
5251 "image.\n");
5252 ql_log(ql_log_fatal, vha, 0x008d,
5253 "Firmware data: %08x %08x %08x %08x.\n",
5254 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005255
5256 return QLA_FUNCTION_FAILED;
5257 }
5258
5259 while (segments && rval == QLA_SUCCESS) {
5260 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005261 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005262
5263 risc_addr = be32_to_cpu(dcode[2]);
5264 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5265 risc_size = be32_to_cpu(dcode[3]);
5266
5267 fragment = 0;
5268 while (risc_size > 0 && rval == QLA_SUCCESS) {
5269 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5270 if (dlen > risc_size)
5271 dlen = risc_size;
5272
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005273 ql_dbg(ql_dbg_init, vha, 0x008e,
5274 "Loading risc segment@ risc addr %x "
5275 "number of dwords 0x%x offset 0x%x.\n",
5276 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005277
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005278 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005279 for (i = 0; i < dlen; i++)
5280 dcode[i] = swab32(dcode[i]);
5281
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005282 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005283 dlen);
5284 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005285 ql_log(ql_log_fatal, vha, 0x008f,
5286 "Failed to load segment %d of firmware.\n",
5287 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04005288 return QLA_FUNCTION_FAILED;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005289 }
5290
5291 faddr += dlen;
5292 risc_addr += dlen;
5293 risc_size -= dlen;
5294 fragment++;
5295 }
5296
5297 /* Next segment. */
5298 segments--;
5299 }
5300
Chad Dupuisf73cb692014-02-26 04:15:06 -05005301 if (!IS_QLA27XX(ha))
5302 return rval;
5303
5304 if (ha->fw_dump_template)
5305 vfree(ha->fw_dump_template);
5306 ha->fw_dump_template = NULL;
5307 ha->fw_dump_template_len = 0;
5308
5309 ql_dbg(ql_dbg_init, vha, 0x0161,
5310 "Loading fwdump template from %x\n", faddr);
5311 qla24xx_read_flash_data(vha, dcode, faddr, 7);
5312 risc_size = be32_to_cpu(dcode[2]);
5313 ql_dbg(ql_dbg_init, vha, 0x0162,
5314 "-> array size %x dwords\n", risc_size);
5315 if (risc_size == 0 || risc_size == ~0)
5316 goto default_template;
5317
5318 dlen = (risc_size - 8) * sizeof(*dcode);
5319 ql_dbg(ql_dbg_init, vha, 0x0163,
5320 "-> template allocating %x bytes...\n", dlen);
5321 ha->fw_dump_template = vmalloc(dlen);
5322 if (!ha->fw_dump_template) {
5323 ql_log(ql_log_warn, vha, 0x0164,
5324 "Failed fwdump template allocate %x bytes.\n", risc_size);
5325 goto default_template;
5326 }
5327
5328 faddr += 7;
5329 risc_size -= 8;
5330 dcode = ha->fw_dump_template;
5331 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
5332 for (i = 0; i < risc_size; i++)
5333 dcode[i] = le32_to_cpu(dcode[i]);
5334
5335 if (!qla27xx_fwdt_template_valid(dcode)) {
5336 ql_log(ql_log_warn, vha, 0x0165,
5337 "Failed fwdump template validate\n");
5338 goto default_template;
5339 }
5340
5341 dlen = qla27xx_fwdt_template_size(dcode);
5342 ql_dbg(ql_dbg_init, vha, 0x0166,
5343 "-> template size %x bytes\n", dlen);
5344 if (dlen > risc_size * sizeof(*dcode)) {
5345 ql_log(ql_log_warn, vha, 0x0167,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005346 "Failed fwdump template exceeds array by %x bytes\n",
5347 (uint32_t)(dlen - risc_size * sizeof(*dcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005348 goto default_template;
5349 }
5350 ha->fw_dump_template_len = dlen;
5351 return rval;
5352
5353default_template:
5354 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
5355 if (ha->fw_dump_template)
5356 vfree(ha->fw_dump_template);
5357 ha->fw_dump_template = NULL;
5358 ha->fw_dump_template_len = 0;
5359
5360 dlen = qla27xx_fwdt_template_default_size();
5361 ql_dbg(ql_dbg_init, vha, 0x0169,
5362 "-> template allocating %x bytes...\n", dlen);
5363 ha->fw_dump_template = vmalloc(dlen);
5364 if (!ha->fw_dump_template) {
5365 ql_log(ql_log_warn, vha, 0x016a,
5366 "Failed fwdump template allocate %x bytes.\n", risc_size);
5367 goto failed_template;
5368 }
5369
5370 dcode = ha->fw_dump_template;
5371 risc_size = dlen / sizeof(*dcode);
5372 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
5373 for (i = 0; i < risc_size; i++)
5374 dcode[i] = be32_to_cpu(dcode[i]);
5375
5376 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5377 ql_log(ql_log_warn, vha, 0x016b,
5378 "Failed fwdump template validate\n");
5379 goto failed_template;
5380 }
5381
5382 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5383 ql_dbg(ql_dbg_init, vha, 0x016c,
5384 "-> template size %x bytes\n", dlen);
5385 ha->fw_dump_template_len = dlen;
5386 return rval;
5387
5388failed_template:
5389 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
5390 if (ha->fw_dump_template)
5391 vfree(ha->fw_dump_template);
5392 ha->fw_dump_template = NULL;
5393 ha->fw_dump_template_len = 0;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005394 return rval;
5395}
5396
Giridhar Malavalie9454a82013-02-08 01:57:47 -05005397#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005398
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005399int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005400qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08005401{
5402 int rval;
5403 int i, fragment;
5404 uint16_t *wcode, *fwcode;
5405 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
5406 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005407 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005408 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08005409
5410 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005411 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005412 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005413 ql_log(ql_log_info, vha, 0x0083,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01005414 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005415 ql_log(ql_log_info, vha, 0x0084,
5416 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08005417 return QLA_FUNCTION_FAILED;
5418 }
5419
5420 rval = QLA_SUCCESS;
5421
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005422 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08005423 *srisc_addr = 0;
5424 fwcode = (uint16_t *)blob->fw->data;
5425 fwclen = 0;
5426
5427 /* Validate firmware image by checking version. */
5428 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005429 ql_log(ql_log_fatal, vha, 0x0085,
5430 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005431 blob->fw->size);
5432 goto fail_fw_integrity;
5433 }
5434 for (i = 0; i < 4; i++)
5435 wcode[i] = be16_to_cpu(fwcode[i + 4]);
5436 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
5437 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
5438 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005439 ql_log(ql_log_fatal, vha, 0x0086,
5440 "Unable to verify integrity of firmware image.\n");
5441 ql_log(ql_log_fatal, vha, 0x0087,
5442 "Firmware data: %04x %04x %04x %04x.\n",
5443 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08005444 goto fail_fw_integrity;
5445 }
5446
5447 seg = blob->segs;
5448 while (*seg && rval == QLA_SUCCESS) {
5449 risc_addr = *seg;
5450 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
5451 risc_size = be16_to_cpu(fwcode[3]);
5452
5453 /* Validate firmware image size. */
5454 fwclen += risc_size * sizeof(uint16_t);
5455 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005456 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08005457 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005458 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08005459 goto fail_fw_integrity;
5460 }
5461
5462 fragment = 0;
5463 while (risc_size > 0 && rval == QLA_SUCCESS) {
5464 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
5465 if (wlen > risc_size)
5466 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005467 ql_dbg(ql_dbg_init, vha, 0x0089,
5468 "Loading risc segment@ risc addr %x number of "
5469 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08005470
5471 for (i = 0; i < wlen; i++)
5472 wcode[i] = swab16(fwcode[i]);
5473
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005474 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08005475 wlen);
5476 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005477 ql_log(ql_log_fatal, vha, 0x008a,
5478 "Failed to load segment %d of firmware.\n",
5479 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08005480 break;
5481 }
5482
5483 fwcode += wlen;
5484 risc_addr += wlen;
5485 risc_size -= wlen;
5486 fragment++;
5487 }
5488
5489 /* Next segment. */
5490 seg++;
5491 }
5492 return rval;
5493
5494fail_fw_integrity:
5495 return QLA_FUNCTION_FAILED;
5496}
5497
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005498static int
5499qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005500{
5501 int rval;
5502 int segments, fragment;
5503 uint32_t *dcode, dlen;
5504 uint32_t risc_addr;
5505 uint32_t risc_size;
5506 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08005507 struct fw_blob *blob;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005508 const uint32_t *fwcode;
5509 uint32_t fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005510 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005511 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005512
Andrew Vasquez54333832005-11-09 15:49:04 -08005513 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005514 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005515 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005516 ql_log(ql_log_warn, vha, 0x0090,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01005517 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005518 ql_log(ql_log_warn, vha, 0x0091,
5519 "Firmware images can be retrieved from: "
5520 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005521
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005522 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005523 }
5524
Chad Dupuiscfb09192011-11-18 09:03:07 -08005525 ql_dbg(ql_dbg_init, vha, 0x0092,
5526 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005527
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005528 rval = QLA_SUCCESS;
5529
5530 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005531 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005532 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08005533 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005534 fwclen = 0;
5535
5536 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08005537 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005538 ql_log(ql_log_fatal, vha, 0x0093,
5539 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005540 blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005541 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005542 }
5543 for (i = 0; i < 4; i++)
5544 dcode[i] = be32_to_cpu(fwcode[i + 4]);
5545 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5546 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5547 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5548 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005549 ql_log(ql_log_fatal, vha, 0x0094,
5550 "Unable to verify integrity of firmware image (%Zd).\n",
5551 blob->fw->size);
5552 ql_log(ql_log_fatal, vha, 0x0095,
5553 "Firmware data: %08x %08x %08x %08x.\n",
5554 dcode[0], dcode[1], dcode[2], dcode[3]);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005555 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005556 }
5557
5558 while (segments && rval == QLA_SUCCESS) {
5559 risc_addr = be32_to_cpu(fwcode[2]);
5560 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5561 risc_size = be32_to_cpu(fwcode[3]);
5562
5563 /* Validate firmware image size. */
5564 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08005565 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005566 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08005567 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005568 "(%Zd).\n", blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005569 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005570 }
5571
5572 fragment = 0;
5573 while (risc_size > 0 && rval == QLA_SUCCESS) {
5574 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5575 if (dlen > risc_size)
5576 dlen = risc_size;
5577
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005578 ql_dbg(ql_dbg_init, vha, 0x0097,
5579 "Loading risc segment@ risc addr %x "
5580 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005581
5582 for (i = 0; i < dlen; i++)
5583 dcode[i] = swab32(fwcode[i]);
5584
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005585 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08005586 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005587 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005588 ql_log(ql_log_fatal, vha, 0x0098,
5589 "Failed to load segment %d of firmware.\n",
5590 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04005591 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005592 }
5593
5594 fwcode += dlen;
5595 risc_addr += dlen;
5596 risc_size -= dlen;
5597 fragment++;
5598 }
5599
5600 /* Next segment. */
5601 segments--;
5602 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05005603
5604 if (!IS_QLA27XX(ha))
5605 return rval;
5606
5607 if (ha->fw_dump_template)
5608 vfree(ha->fw_dump_template);
5609 ha->fw_dump_template = NULL;
5610 ha->fw_dump_template_len = 0;
5611
5612 ql_dbg(ql_dbg_init, vha, 0x171,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005613 "Loading fwdump template from %x\n",
5614 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005615 risc_size = be32_to_cpu(fwcode[2]);
5616 ql_dbg(ql_dbg_init, vha, 0x172,
5617 "-> array size %x dwords\n", risc_size);
5618 if (risc_size == 0 || risc_size == ~0)
5619 goto default_template;
5620
5621 dlen = (risc_size - 8) * sizeof(*fwcode);
5622 ql_dbg(ql_dbg_init, vha, 0x0173,
5623 "-> template allocating %x bytes...\n", dlen);
5624 ha->fw_dump_template = vmalloc(dlen);
5625 if (!ha->fw_dump_template) {
5626 ql_log(ql_log_warn, vha, 0x0174,
5627 "Failed fwdump template allocate %x bytes.\n", risc_size);
5628 goto default_template;
5629 }
5630
5631 fwcode += 7;
5632 risc_size -= 8;
5633 dcode = ha->fw_dump_template;
5634 for (i = 0; i < risc_size; i++)
5635 dcode[i] = le32_to_cpu(fwcode[i]);
5636
5637 if (!qla27xx_fwdt_template_valid(dcode)) {
5638 ql_log(ql_log_warn, vha, 0x0175,
5639 "Failed fwdump template validate\n");
5640 goto default_template;
5641 }
5642
5643 dlen = qla27xx_fwdt_template_size(dcode);
5644 ql_dbg(ql_dbg_init, vha, 0x0176,
5645 "-> template size %x bytes\n", dlen);
5646 if (dlen > risc_size * sizeof(*fwcode)) {
5647 ql_log(ql_log_warn, vha, 0x0177,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005648 "Failed fwdump template exceeds array by %x bytes\n",
5649 (uint32_t)(dlen - risc_size * sizeof(*fwcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005650 goto default_template;
5651 }
5652 ha->fw_dump_template_len = dlen;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005653 return rval;
5654
Chad Dupuisf73cb692014-02-26 04:15:06 -05005655default_template:
5656 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
5657 if (ha->fw_dump_template)
5658 vfree(ha->fw_dump_template);
5659 ha->fw_dump_template = NULL;
5660 ha->fw_dump_template_len = 0;
5661
5662 dlen = qla27xx_fwdt_template_default_size();
5663 ql_dbg(ql_dbg_init, vha, 0x0179,
5664 "-> template allocating %x bytes...\n", dlen);
5665 ha->fw_dump_template = vmalloc(dlen);
5666 if (!ha->fw_dump_template) {
5667 ql_log(ql_log_warn, vha, 0x017a,
5668 "Failed fwdump template allocate %x bytes.\n", risc_size);
5669 goto failed_template;
5670 }
5671
5672 dcode = ha->fw_dump_template;
5673 risc_size = dlen / sizeof(*fwcode);
5674 fwcode = qla27xx_fwdt_template_default();
5675 for (i = 0; i < risc_size; i++)
5676 dcode[i] = be32_to_cpu(fwcode[i]);
5677
5678 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5679 ql_log(ql_log_warn, vha, 0x017b,
5680 "Failed fwdump template validate\n");
5681 goto failed_template;
5682 }
5683
5684 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5685 ql_dbg(ql_dbg_init, vha, 0x017c,
5686 "-> template size %x bytes\n", dlen);
5687 ha->fw_dump_template_len = dlen;
5688 return rval;
5689
5690failed_template:
5691 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
5692 if (ha->fw_dump_template)
5693 vfree(ha->fw_dump_template);
5694 ha->fw_dump_template = NULL;
5695 ha->fw_dump_template_len = 0;
5696 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005697}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005698
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005699int
5700qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5701{
5702 int rval;
5703
Andrew Vasqueze337d902009-04-06 22:33:49 -07005704 if (ql2xfwloadbin == 1)
5705 return qla81xx_load_risc(vha, srisc_addr);
5706
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005707 /*
5708 * FW Load priority:
5709 * 1) Firmware via request-firmware interface (.bin file).
5710 * 2) Firmware residing in flash.
5711 */
5712 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5713 if (rval == QLA_SUCCESS)
5714 return rval;
5715
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005716 return qla24xx_load_risc_flash(vha, srisc_addr,
5717 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005718}
5719
5720int
5721qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5722{
5723 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005724 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005725
Andrew Vasqueze337d902009-04-06 22:33:49 -07005726 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005727 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07005728
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005729 /*
5730 * FW Load priority:
5731 * 1) Firmware residing in flash.
5732 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005733 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005734 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005735 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005736 if (rval == QLA_SUCCESS)
5737 return rval;
5738
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005739try_blob_fw:
5740 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5741 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
5742 return rval;
5743
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005744 ql_log(ql_log_info, vha, 0x0099,
5745 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005746 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
5747 if (rval != QLA_SUCCESS)
5748 return rval;
5749
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005750 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005751 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005752 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005753}
5754
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005755void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005756qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005757{
5758 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005759 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005760
Andrew Vasquez85880802009-12-15 21:29:46 -08005761 if (ha->flags.pci_channel_io_perm_failure)
5762 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07005763 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005764 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07005765 if (!ha->fw_major_version)
5766 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005767
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005768 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08005769 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07005770 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005771 ha->isp_ops->reset_chip(vha);
5772 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005773 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005774 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005775 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005776 ql_log(ql_log_info, vha, 0x8015,
5777 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005778 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005779 }
5780}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005781
5782int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005783qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005784{
5785 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08005786 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005787 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005788 struct qla_hw_data *ha = vha->hw;
5789 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005790 struct req_que *req;
5791 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005792
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005793 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005794 return -EINVAL;
5795
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005796 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07005797 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005798 req = ha->req_q_map[0];
5799 else
5800 req = vha->req;
5801 rsp = req->rsp;
5802
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005803 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005804 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005805 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005806 }
5807
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005808 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005809
5810 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08005811 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
5812 BIT_1);
5813 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5814 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
5815 ql_dbg(ql_dbg_init, vha, 0x0120,
5816 "Failed SNS login: loop_id=%x, rval2=%d\n",
5817 NPH_SNS, rval2);
5818 else
5819 ql_dbg(ql_dbg_init, vha, 0x0103,
5820 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5821 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
5822 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005823 return (QLA_FUNCTION_FAILED);
5824 }
5825
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005826 atomic_set(&vha->loop_down_timer, 0);
5827 atomic_set(&vha->loop_state, LOOP_UP);
5828 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5829 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5830 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005831
5832 return rval;
5833}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005834
5835/* 84XX Support **************************************************************/
5836
5837static LIST_HEAD(qla_cs84xx_list);
5838static DEFINE_MUTEX(qla_cs84xx_mutex);
5839
5840static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005841qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005842{
5843 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005844 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005845
5846 mutex_lock(&qla_cs84xx_mutex);
5847
5848 /* Find any shared 84xx chip. */
5849 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5850 if (cs84xx->bus == ha->pdev->bus) {
5851 kref_get(&cs84xx->kref);
5852 goto done;
5853 }
5854 }
5855
5856 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5857 if (!cs84xx)
5858 goto done;
5859
5860 kref_init(&cs84xx->kref);
5861 spin_lock_init(&cs84xx->access_lock);
5862 mutex_init(&cs84xx->fw_update_mutex);
5863 cs84xx->bus = ha->pdev->bus;
5864
5865 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5866done:
5867 mutex_unlock(&qla_cs84xx_mutex);
5868 return cs84xx;
5869}
5870
5871static void
5872__qla84xx_chip_release(struct kref *kref)
5873{
5874 struct qla_chip_state_84xx *cs84xx =
5875 container_of(kref, struct qla_chip_state_84xx, kref);
5876
5877 mutex_lock(&qla_cs84xx_mutex);
5878 list_del(&cs84xx->list);
5879 mutex_unlock(&qla_cs84xx_mutex);
5880 kfree(cs84xx);
5881}
5882
5883void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005884qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005885{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005886 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005887 if (ha->cs84xx)
5888 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
5889}
5890
5891static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005892qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005893{
5894 int rval;
5895 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005896 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005897
5898 mutex_lock(&ha->cs84xx->fw_update_mutex);
5899
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005900 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005901
5902 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5903
5904 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5905 QLA_SUCCESS;
5906}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005907
5908/* 81XX Support **************************************************************/
5909
5910int
5911qla81xx_nvram_config(scsi_qla_host_t *vha)
5912{
5913 int rval;
5914 struct init_cb_81xx *icb;
5915 struct nvram_81xx *nv;
5916 uint32_t *dptr;
5917 uint8_t *dptr1, *dptr2;
5918 uint32_t chksum;
5919 uint16_t cnt;
5920 struct qla_hw_data *ha = vha->hw;
5921
5922 rval = QLA_SUCCESS;
5923 icb = (struct init_cb_81xx *)ha->init_cb;
5924 nv = ha->nvram;
5925
5926 /* Determine NVRAM starting address. */
5927 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005928 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005929 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
5930 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005931
5932 /* Get VPD data into cache */
5933 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005934 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5935 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005936
5937 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005938 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005939 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005940 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005941 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5942 chksum += le32_to_cpu(*dptr++);
5943
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005944 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
5945 "Contents of NVRAM:\n");
5946 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
5947 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005948
5949 /* Bad NVRAM data, set defaults parameters. */
5950 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5951 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07005952 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005953 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005954 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04005955 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005956 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005957 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005958 ql_log(ql_log_info, vha, 0x0074,
5959 "Falling back to functioning (yet invalid -- WWPN) "
5960 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005961
5962 /*
5963 * Set default initialization control block.
5964 */
5965 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07005966 nv->nvram_version = cpu_to_le16(ICB_VERSION);
5967 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04005968 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07005969 nv->execution_throttle = cpu_to_le16(0xFFFF);
5970 nv->exchange_count = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005971 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005972 nv->port_name[1] = 0x00 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005973 nv->port_name[2] = 0x00;
5974 nv->port_name[3] = 0xe0;
5975 nv->port_name[4] = 0x8b;
5976 nv->port_name[5] = 0x1c;
5977 nv->port_name[6] = 0x55;
5978 nv->port_name[7] = 0x86;
5979 nv->node_name[0] = 0x20;
5980 nv->node_name[1] = 0x00;
5981 nv->node_name[2] = 0x00;
5982 nv->node_name[3] = 0xe0;
5983 nv->node_name[4] = 0x8b;
5984 nv->node_name[5] = 0x1c;
5985 nv->node_name[6] = 0x55;
5986 nv->node_name[7] = 0x86;
Bart Van Asschead950362015-07-09 07:24:08 -07005987 nv->login_retry_count = cpu_to_le16(8);
5988 nv->interrupt_delay_timer = cpu_to_le16(0);
5989 nv->login_timeout = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005990 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07005991 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5992 nv->firmware_options_2 = cpu_to_le32(2 << 4);
5993 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
5994 nv->firmware_options_3 = cpu_to_le32(2 << 13);
5995 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
5996 nv->efi_parameters = cpu_to_le32(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005997 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07005998 nv->max_luns_per_target = cpu_to_le16(128);
5999 nv->port_down_retry_count = cpu_to_le16(30);
6000 nv->link_down_timeout = cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07006001 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006002 nv->enode_mac[1] = 0xC0;
6003 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006004 nv->enode_mac[3] = 0x04;
6005 nv->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006006 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006007
6008 rval = 1;
6009 }
6010
Arun Easi9e522cd2012-08-22 14:21:31 -04006011 if (IS_T10_PI_CAPABLE(ha))
6012 nv->frame_payload_size &= ~7;
6013
Arun Easiaa230bc2013-01-30 03:34:39 -05006014 qlt_81xx_config_nvram_stage1(vha, nv);
6015
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006016 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07006017 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006018
6019 /* Copy 1st segment. */
6020 dptr1 = (uint8_t *)icb;
6021 dptr2 = (uint8_t *)&nv->version;
6022 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6023 while (cnt--)
6024 *dptr1++ = *dptr2++;
6025
6026 icb->login_retry_count = nv->login_retry_count;
6027
6028 /* Copy 2nd segment. */
6029 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6030 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6031 cnt = (uint8_t *)&icb->reserved_5 -
6032 (uint8_t *)&icb->interrupt_delay_timer;
6033 while (cnt--)
6034 *dptr1++ = *dptr2++;
6035
6036 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
6037 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
6038 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08006039 icb->enode_mac[0] = 0x00;
6040 icb->enode_mac[1] = 0xC0;
6041 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006042 icb->enode_mac[3] = 0x04;
6043 icb->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006044 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006045 }
6046
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07006047 /* Use extended-initialization control block. */
6048 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
6049
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006050 /*
6051 * Setup driver NVRAM options.
6052 */
6053 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07006054 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006055
Arun Easiaa230bc2013-01-30 03:34:39 -05006056 qlt_81xx_config_nvram_stage2(vha, icb);
6057
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006058 /* Use alternate WWN? */
Bart Van Asschead950362015-07-09 07:24:08 -07006059 if (nv->host_p & cpu_to_le32(BIT_15)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006060 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6061 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6062 }
6063
6064 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07006065 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006066 /*
6067 * Firmware will apply the following mask if the nodename was
6068 * not provided.
6069 */
6070 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6071 icb->node_name[0] &= 0xF0;
6072 }
6073
6074 /* Set host adapter parameters. */
6075 ha->flags.disable_risc_code_load = 0;
6076 ha->flags.enable_lip_reset = 0;
6077 ha->flags.enable_lip_full_login =
6078 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6079 ha->flags.enable_target_reset =
6080 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
6081 ha->flags.enable_led_scheme = 0;
6082 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
6083
6084 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6085 (BIT_6 | BIT_5 | BIT_4)) >> 4;
6086
6087 /* save HBA serial number */
6088 ha->serial0 = icb->port_name[5];
6089 ha->serial1 = icb->port_name[6];
6090 ha->serial2 = icb->port_name[7];
6091 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6092 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
6093
Bart Van Asschead950362015-07-09 07:24:08 -07006094 icb->execution_throttle = cpu_to_le16(0xFFFF);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006095
6096 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6097
6098 /* Set minimum login_timeout to 4 seconds. */
6099 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6100 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6101 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07006102 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006103 ha->login_timeout = le16_to_cpu(nv->login_timeout);
6104 icb->login_timeout = nv->login_timeout;
6105
6106 /* Set minimum RATOV to 100 tenths of a second. */
6107 ha->r_a_tov = 100;
6108
6109 ha->loop_reset_delay = nv->reset_delay;
6110
6111 /* Link Down Timeout = 0:
6112 *
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006113 * When Port Down timer expires we will start returning
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006114 * I/O's to OS with "DID_NO_CONNECT".
6115 *
6116 * Link Down Timeout != 0:
6117 *
6118 * The driver waits for the link to come up after link down
6119 * before returning I/Os to OS with "DID_NO_CONNECT".
6120 */
6121 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6122 ha->loop_down_abort_time =
6123 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6124 } else {
6125 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6126 ha->loop_down_abort_time =
6127 (LOOP_DOWN_TIME - ha->link_down_timeout);
6128 }
6129
6130 /* Need enough time to try and get the port back. */
6131 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6132 if (qlport_down_retry)
6133 ha->port_down_retry_count = qlport_down_retry;
6134
6135 /* Set login_retry_count */
6136 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6137 if (ha->port_down_retry_count ==
6138 le16_to_cpu(nv->port_down_retry_count) &&
6139 ha->port_down_retry_count > 3)
6140 ha->login_retry_count = ha->port_down_retry_count;
6141 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6142 ha->login_retry_count = ha->port_down_retry_count;
6143 if (ql2xloginretrycount)
6144 ha->login_retry_count = ql2xloginretrycount;
6145
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006146 /* if not running MSI-X we need handshaking on interrupts */
Chad Dupuisf73cb692014-02-26 04:15:06 -05006147 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
Bart Van Asschead950362015-07-09 07:24:08 -07006148 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006149
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006150 /* Enable ZIO. */
6151 if (!vha->flags.init_done) {
6152 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6153 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6154 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6155 le16_to_cpu(icb->interrupt_delay_timer): 2;
6156 }
Bart Van Asschead950362015-07-09 07:24:08 -07006157 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006158 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
6159 vha->flags.process_response_queue = 0;
6160 if (ha->zio_mode != QLA_ZIO_DISABLED) {
6161 ha->zio_mode = QLA_ZIO_MODE_6;
6162
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006163 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006164 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006165 ha->zio_mode,
6166 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006167
6168 icb->firmware_options_2 |= cpu_to_le32(
6169 (uint32_t)ha->zio_mode);
6170 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
6171 vha->flags.process_response_queue = 1;
6172 }
6173
6174 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006175 ql_log(ql_log_warn, vha, 0x0076,
6176 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006177 }
6178 return (rval);
6179}
6180
Giridhar Malavalia9083012010-04-12 17:59:55 -07006181int
6182qla82xx_restart_isp(scsi_qla_host_t *vha)
6183{
6184 int status, rval;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006185 struct qla_hw_data *ha = vha->hw;
6186 struct req_que *req = ha->req_q_map[0];
6187 struct rsp_que *rsp = ha->rsp_q_map[0];
6188 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07006189 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006190
6191 status = qla2x00_init_rings(vha);
6192 if (!status) {
6193 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6194 ha->flags.chip_reset_done = 1;
6195
6196 status = qla2x00_fw_ready(vha);
6197 if (!status) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07006198 /* Issue a marker after FW becomes ready. */
6199 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006200 vha->flags.online = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04006201 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006202 }
6203
6204 /* if no cable then assume it's good */
6205 if ((vha->device_flags & DFLG_NO_CABLE))
6206 status = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006207 }
6208
6209 if (!status) {
6210 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6211
6212 if (!atomic_read(&vha->loop_down_timer)) {
6213 /*
6214 * Issue marker command only when we are going
6215 * to start the I/O .
6216 */
6217 vha->marker_needed = 1;
6218 }
6219
Giridhar Malavalia9083012010-04-12 17:59:55 -07006220 ha->isp_ops->enable_intrs(ha);
6221
6222 ha->isp_abort_cnt = 0;
6223 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6224
Saurav Kashyap53296782011-05-10 11:30:06 -07006225 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07006226 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07006227
Giridhar Malavalia9083012010-04-12 17:59:55 -07006228 if (ha->fce) {
6229 ha->flags.fce_enabled = 1;
6230 memset(ha->fce, 0,
6231 fce_calc_size(ha->fce_bufs));
6232 rval = qla2x00_enable_fce_trace(vha,
6233 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6234 &ha->fce_bufs);
6235 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006236 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006237 "Unable to reinitialize FCE (%d).\n",
6238 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006239 ha->flags.fce_enabled = 0;
6240 }
6241 }
6242
6243 if (ha->eft) {
6244 memset(ha->eft, 0, EFT_SIZE);
6245 rval = qla2x00_enable_eft_trace(vha,
6246 ha->eft_dma, EFT_NUM_BUFFERS);
6247 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006248 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006249 "Unable to reinitialize EFT (%d).\n",
6250 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006251 }
6252 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006253 }
6254
6255 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006256 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006257 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07006258
6259 spin_lock_irqsave(&ha->vport_slock, flags);
6260 list_for_each_entry(vp, &ha->vp_list, list) {
6261 if (vp->vp_idx) {
6262 atomic_inc(&vp->vref_count);
6263 spin_unlock_irqrestore(&ha->vport_slock, flags);
6264
Giridhar Malavalia9083012010-04-12 17:59:55 -07006265 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07006266
6267 spin_lock_irqsave(&ha->vport_slock, flags);
6268 atomic_dec(&vp->vref_count);
6269 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006270 }
Arun Easifeafb7b2010-09-03 14:57:00 -07006271 spin_unlock_irqrestore(&ha->vport_slock, flags);
6272
Giridhar Malavalia9083012010-04-12 17:59:55 -07006273 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006274 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006275 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006276 }
6277
6278 return status;
6279}
6280
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006281void
Andrew Vasquezae97c912010-02-18 10:07:28 -08006282qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006283{
Andrew Vasquezae97c912010-02-18 10:07:28 -08006284 struct qla_hw_data *ha = vha->hw;
6285
6286 if (!ql2xetsenable)
6287 return;
6288
6289 /* Enable ETS Burst. */
6290 memset(ha->fw_options, 0, sizeof(ha->fw_options));
6291 ha->fw_options[2] |= BIT_9;
6292 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006293}
Sarang Radke09ff7012010-03-19 17:03:59 -07006294
6295/*
6296 * qla24xx_get_fcp_prio
6297 * Gets the fcp cmd priority value for the logged in port.
6298 * Looks for a match of the port descriptors within
6299 * each of the fcp prio config entries. If a match is found,
6300 * the tag (priority) value is returned.
6301 *
6302 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006303 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07006304 * fcport = port structure pointer.
6305 *
6306 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07006307 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006308 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07006309 *
6310 * Context:
6311 * Kernel context
6312 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006313static int
Sarang Radke09ff7012010-03-19 17:03:59 -07006314qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
6315{
6316 int i, entries;
6317 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006318 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07006319 uint32_t pid1, pid2;
6320 uint64_t wwn1, wwn2;
6321 struct qla_fcp_prio_entry *pri_entry;
6322 struct qla_hw_data *ha = vha->hw;
6323
6324 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006325 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07006326
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006327 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07006328 entries = ha->fcp_prio_cfg->num_entries;
6329 pri_entry = &ha->fcp_prio_cfg->entry[0];
6330
6331 for (i = 0; i < entries; i++) {
6332 pid_match = wwn_match = 0;
6333
6334 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
6335 pri_entry++;
6336 continue;
6337 }
6338
6339 /* check source pid for a match */
6340 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
6341 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
6342 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
6343 if (pid1 == INVALID_PORT_ID)
6344 pid_match++;
6345 else if (pid1 == pid2)
6346 pid_match++;
6347 }
6348
6349 /* check destination pid for a match */
6350 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
6351 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
6352 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
6353 if (pid1 == INVALID_PORT_ID)
6354 pid_match++;
6355 else if (pid1 == pid2)
6356 pid_match++;
6357 }
6358
6359 /* check source WWN for a match */
6360 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
6361 wwn1 = wwn_to_u64(vha->port_name);
6362 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
6363 if (wwn2 == (uint64_t)-1)
6364 wwn_match++;
6365 else if (wwn1 == wwn2)
6366 wwn_match++;
6367 }
6368
6369 /* check destination WWN for a match */
6370 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
6371 wwn1 = wwn_to_u64(fcport->port_name);
6372 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
6373 if (wwn2 == (uint64_t)-1)
6374 wwn_match++;
6375 else if (wwn1 == wwn2)
6376 wwn_match++;
6377 }
6378
6379 if (pid_match == 2 || wwn_match == 2) {
6380 /* Found a matching entry */
6381 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
6382 priority = pri_entry->tag;
6383 break;
6384 }
6385
6386 pri_entry++;
6387 }
6388
6389 return priority;
6390}
6391
6392/*
6393 * qla24xx_update_fcport_fcp_prio
6394 * Activates fcp priority for the logged in fc port
6395 *
6396 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006397 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07006398 * fcp = port structure pointer.
6399 *
6400 * Return:
6401 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6402 *
6403 * Context:
6404 * Kernel context.
6405 */
6406int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006407qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07006408{
6409 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006410 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07006411 uint16_t mb[5];
6412
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006413 if (fcport->port_type != FCT_TARGET ||
6414 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07006415 return QLA_FUNCTION_FAILED;
6416
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006417 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006418 if (priority < 0)
6419 return QLA_FUNCTION_FAILED;
6420
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006421 if (IS_P3P_TYPE(vha->hw)) {
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006422 fcport->fcp_prio = priority & 0xf;
6423 return QLA_SUCCESS;
6424 }
6425
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006426 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08006427 if (ret == QLA_SUCCESS) {
6428 if (fcport->fcp_prio != priority)
6429 ql_dbg(ql_dbg_user, vha, 0x709e,
6430 "Updated FCP_CMND priority - value=%d loop_id=%d "
6431 "port_id=%02x%02x%02x.\n", priority,
6432 fcport->loop_id, fcport->d_id.b.domain,
6433 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006434 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08006435 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006436 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006437 "Unable to update FCP_CMND priority - ret=0x%x for "
6438 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
6439 fcport->d_id.b.domain, fcport->d_id.b.area,
6440 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07006441 return ret;
6442}
6443
6444/*
6445 * qla24xx_update_all_fcp_prio
6446 * Activates fcp priority for all the logged in ports
6447 *
6448 * Input:
6449 * ha = adapter block pointer.
6450 *
6451 * Return:
6452 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6453 *
6454 * Context:
6455 * Kernel context.
6456 */
6457int
6458qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
6459{
6460 int ret;
6461 fc_port_t *fcport;
6462
6463 ret = QLA_FUNCTION_FAILED;
6464 /* We need to set priority for all logged in ports */
6465 list_for_each_entry(fcport, &vha->vp_fcports, list)
6466 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
6467
6468 return ret;
6469}