blob: 27248425f86c182fc6ab4ca80a17185643a845ff [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Saurav Kashyap1e633952013-02-08 01:57:54 -05003 * Copyright (c) 2003-2013 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 Kashyapa9b6f7222012-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
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700350void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700351qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
352 uint16_t *data)
353{
354 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700355
356 switch (data[0]) {
357 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700358 /*
359 * Driver must validate login state - If PRLI not complete,
360 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
361 * requests.
362 */
363 rval = qla2x00_get_port_database(vha, fcport, 0);
Arun Easi0eba25d2012-02-09 11:15:58 -0800364 if (rval == QLA_NOT_LOGGED_IN) {
365 fcport->flags &= ~FCF_ASYNC_SENT;
366 fcport->flags |= FCF_LOGIN_NEEDED;
367 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
368 break;
369 }
370
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700371 if (rval != QLA_SUCCESS) {
372 qla2x00_post_async_logout_work(vha, fcport, NULL);
373 qla2x00_post_async_login_work(vha, fcport, NULL);
374 break;
375 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700376 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700377 qla2x00_post_async_adisc_work(vha, fcport, data);
378 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700379 }
380 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700381 break;
382 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700383 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700384 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
385 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
386 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700387 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700388 break;
389 case MBS_PORT_ID_USED:
390 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700391 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700392 qla2x00_post_async_login_work(vha, fcport, NULL);
393 break;
394 case MBS_LOOP_ID_USED:
395 fcport->loop_id++;
396 rval = qla2x00_find_new_loop_id(vha, fcport);
397 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700398 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez80d79442011-03-30 11:46:17 -0700399 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700400 break;
401 }
402 qla2x00_post_async_login_work(vha, fcport, NULL);
403 break;
404 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700405 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700406}
407
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700408void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700409qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
410 uint16_t *data)
411{
412 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700413 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700414}
415
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700416void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700417qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
418 uint16_t *data)
419{
420 if (data[0] == MBS_COMMAND_COMPLETE) {
421 qla2x00_update_fcport(vha, fcport);
422
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700423 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700424 }
425
426 /* Retry login. */
427 fcport->flags &= ~FCF_ASYNC_SENT;
428 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
429 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
430 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700431 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700432
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700433 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700434}
435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436/****************************************************************************/
437/* QLogic ISP2x00 Hardware Support Functions. */
438/****************************************************************************/
439
Saurav Kashyapfa492632012-11-21 02:40:29 -0500440static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400441qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
442{
443 int rval = QLA_SUCCESS;
444 struct qla_hw_data *ha = vha->hw;
445 uint32_t idc_major_ver, idc_minor_ver;
Saurav Kashyap711aa7f2012-08-22 14:21:15 -0400446 uint16_t config[4];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400447
448 qla83xx_idc_lock(vha, 0);
449
450 /* SV: TODO: Assign initialization timeout from
451 * flash-info / other param
452 */
453 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
454 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
455
456 /* Set our fcoe function presence */
457 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
458 ql_dbg(ql_dbg_p3p, vha, 0xb077,
459 "Error while setting DRV-Presence.\n");
460 rval = QLA_FUNCTION_FAILED;
461 goto exit;
462 }
463
464 /* Decide the reset ownership */
465 qla83xx_reset_ownership(vha);
466
467 /*
468 * On first protocol driver load:
469 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
470 * register.
471 * Others: Check compatibility with current IDC Major version.
472 */
473 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
474 if (ha->flags.nic_core_reset_owner) {
475 /* Set IDC Major version */
476 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
477 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
478
479 /* Clearing IDC-Lock-Recovery register */
480 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
481 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
482 /*
483 * Clear further IDC participation if we are not compatible with
484 * the current IDC Major Version.
485 */
486 ql_log(ql_log_warn, vha, 0xb07d,
487 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
488 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
489 __qla83xx_clear_drv_presence(vha);
490 rval = QLA_FUNCTION_FAILED;
491 goto exit;
492 }
493 /* Each function sets its supported Minor version. */
494 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
495 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
496 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
497
Saurav Kashyap711aa7f2012-08-22 14:21:15 -0400498 if (ha->flags.nic_core_reset_owner) {
499 memset(config, 0, sizeof(config));
500 if (!qla81xx_get_port_config(vha, config))
501 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
502 QLA8XXX_DEV_READY);
503 }
504
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400505 rval = qla83xx_idc_state_handler(vha);
506
507exit:
508 qla83xx_idc_unlock(vha, 0);
509
510 return rval;
511}
512
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513/*
514* qla2x00_initialize_adapter
515* Initialize board.
516*
517* Input:
518* ha = adapter block pointer.
519*
520* Returns:
521* 0 = success
522*/
523int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800524qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
526 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800527 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800528 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700529
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800531 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700532 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800533 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800534 ha->flags.pci_channel_io_perm_failure = 0;
535 ha->flags.eeh_busy = 0;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -0400536 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800537 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
538 atomic_set(&vha->loop_state, LOOP_DOWN);
539 vha->device_flags = DFLG_NO_CABLE;
540 vha->dpc_flags = 0;
541 vha->flags.management_server_logged_in = 0;
542 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 ha->isp_abort_cnt = 0;
544 ha->beacon_blink_led = 0;
545
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800546 set_bit(0, ha->req_qid_map);
547 set_bit(0, ha->rsp_qid_map);
548
Chad Dupuiscfb09192011-11-18 09:03:07 -0800549 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700550 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800551 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700553 ql_log(ql_log_warn, vha, 0x0044,
554 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 return (rval);
556 }
557
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800558 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800560 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700561 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700562 ql_log(ql_log_fatal, vha, 0x004f,
563 "Unable to validate FLASH data.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400564 return rval;
565 }
566
567 if (IS_QLA8044(ha)) {
568 qla8044_read_reset_template(vha);
569
570 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
571 * If DONRESET_BIT0 is set, drivers should not set dev_state
572 * to NEED_RESET. But if NEED_RESET is set, drivers should
573 * should honor the reset. */
574 if (ql2xdontresethba == 1)
575 qla8044_set_idc_dontreset(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700576 }
577
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800578 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -0800579 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700580 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700581
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800582 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700584 if (ha->flags.disable_serdes) {
585 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700586 ql_log(ql_log_info, vha, 0x0077,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -0400587 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700588 return QLA_FUNCTION_FAILED;
589 }
590
Chad Dupuiscfb09192011-11-18 09:03:07 -0800591 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700592 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800594 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
595 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800596 if (rval)
597 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800598 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800599 if (rval)
600 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700602
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700603 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800604 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700605 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700606 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700607 "Unable to configure ISP84XX.\n");
608 return QLA_FUNCTION_FAILED;
609 }
610 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400611
612 if (qla_ini_mode_enabled(vha))
613 rval = qla2x00_init_rings(vha);
614
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700615 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800617 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700618 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800619 rval = qla84xx_init_chip(vha);
620 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700621 ql_log(ql_log_warn, vha, 0x00d4,
622 "Unable to initialize ISP84XX.\n");
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800623 qla84xx_put_chip(vha);
624 }
625 }
626
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400627 /* Load the NIC Core f/w if we are the first protocol driver. */
628 if (IS_QLA8031(ha)) {
629 rval = qla83xx_nic_core_fw_load(vha);
630 if (rval)
631 ql_log(ql_log_warn, vha, 0x0124,
632 "Error in initializing NIC Core f/w.\n");
633 }
634
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500635 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
636 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700637
Joe Carnuccioc46e65c2013-08-27 01:37:35 -0400638 if (IS_P3P_TYPE(ha))
639 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
640 else
641 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
642
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 return (rval);
644}
645
646/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700647 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 * @ha: HA context
649 *
650 * Returns 0 on success.
651 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700652int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800653qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700655 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700656 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800657 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700658 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700661 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700664 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
666
Andrew Vasquez737faec2008-10-24 15:13:45 -0700667 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700669 /* Get PCI bus information. */
670 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700671 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700672 spin_unlock_irqrestore(&ha->hardware_lock, flags);
673
674 return QLA_SUCCESS;
675}
676
677/**
678 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
679 * @ha: HA context
680 *
681 * Returns 0 on success.
682 */
683int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800684qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700685{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700686 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700687 unsigned long flags = 0;
688 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800689 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700690 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700691
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700692 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700693 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700694
695 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700696 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700697
698 if (IS_QLA2322(ha) || IS_QLA6322(ha))
699 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700700 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700701
702 /*
703 * If this is a 2300 card and not 2312, reset the
704 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
705 * the 2310 also reports itself as a 2300 so we need to get the
706 * fb revision level -- a 6 indicates it really is a 2300 and
707 * not a 2310.
708 */
709 if (IS_QLA2300(ha)) {
710 spin_lock_irqsave(&ha->hardware_lock, flags);
711
712 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700713 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700714 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700715 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700716 break;
717
718 udelay(10);
719 }
720
721 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700722 WRT_REG_WORD(&reg->ctrl_status, 0x20);
723 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700724
725 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700726 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700727
728 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700729 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700730
731 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700732 WRT_REG_WORD(&reg->ctrl_status, 0x0);
733 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700734
735 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700736 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700737 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700738 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700739 break;
740
741 udelay(10);
742 }
743
744 spin_unlock_irqrestore(&ha->hardware_lock, flags);
745 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700746
747 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
748
Andrew Vasquez737faec2008-10-24 15:13:45 -0700749 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700750
751 /* Get PCI bus information. */
752 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700753 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700754 spin_unlock_irqrestore(&ha->hardware_lock, flags);
755
756 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757}
758
759/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700760 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
761 * @ha: HA context
762 *
763 * Returns 0 on success.
764 */
765int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800766qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700767{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700768 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700769 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800770 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700771 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700772
773 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700774 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700775
776 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700777 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700778 w &= ~PCI_COMMAND_INTX_DISABLE;
779 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
780
781 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
782
783 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700784 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
785 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700786
787 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700788 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -0400789 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700790
Andrew Vasquez737faec2008-10-24 15:13:45 -0700791 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700792
Auke Kok44c10132007-06-08 15:46:36 -0700793 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800794
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700795 /* Get PCI bus information. */
796 spin_lock_irqsave(&ha->hardware_lock, flags);
797 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
798 spin_unlock_irqrestore(&ha->hardware_lock, flags);
799
800 return QLA_SUCCESS;
801}
802
803/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700804 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
805 * @ha: HA context
806 *
807 * Returns 0 on success.
808 */
809int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800810qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700811{
812 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800813 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700814
815 pci_set_master(ha->pdev);
816 pci_try_set_mwi(ha->pdev);
817
818 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
819 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
820 w &= ~PCI_COMMAND_INTX_DISABLE;
821 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
822
823 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700824 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -0400825 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700826
Andrew Vasquez737faec2008-10-24 15:13:45 -0700827 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700828
829 ha->chip_revision = ha->pdev->revision;
830
831 return QLA_SUCCESS;
832}
833
834/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 * qla2x00_isp_firmware() - Choose firmware image.
836 * @ha: HA context
837 *
838 * Returns 0 on success.
839 */
840static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800841qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842{
843 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700844 uint16_t loop_id, topo, sw_cap;
845 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800846 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
848 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700849 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700852 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800855 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700856 if (rval == QLA_SUCCESS) {
857 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800858 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700859 &area, &domain, &topo, &sw_cap);
860 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 }
862
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700863 if (rval)
864 ql_dbg(ql_dbg_init, vha, 0x007a,
865 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
867 return (rval);
868}
869
870/**
871 * qla2x00_reset_chip() - Reset ISP chip.
872 * @ha: HA context
873 *
874 * Returns 0 on success.
875 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700876void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800877qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878{
879 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800880 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700881 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 uint16_t cmd;
884
Andrew Vasquez85880802009-12-15 21:29:46 -0800885 if (unlikely(pci_channel_offline(ha->pdev)))
886 return;
887
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700888 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890 spin_lock_irqsave(&ha->hardware_lock, flags);
891
892 /* Turn off master enable */
893 cmd = 0;
894 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
895 cmd &= ~PCI_COMMAND_MASTER;
896 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
897
898 if (!IS_QLA2100(ha)) {
899 /* Pause RISC. */
900 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
901 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
902 for (cnt = 0; cnt < 30000; cnt++) {
903 if ((RD_REG_WORD(&reg->hccr) &
904 HCCR_RISC_PAUSE) != 0)
905 break;
906 udelay(100);
907 }
908 } else {
909 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
910 udelay(10);
911 }
912
913 /* Select FPM registers. */
914 WRT_REG_WORD(&reg->ctrl_status, 0x20);
915 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
916
917 /* FPM Soft Reset. */
918 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
919 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
920
921 /* Toggle Fpm Reset. */
922 if (!IS_QLA2200(ha)) {
923 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
924 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
925 }
926
927 /* Select frame buffer registers. */
928 WRT_REG_WORD(&reg->ctrl_status, 0x10);
929 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
930
931 /* Reset frame buffer FIFOs. */
932 if (IS_QLA2200(ha)) {
933 WRT_FB_CMD_REG(ha, reg, 0xa000);
934 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
935 } else {
936 WRT_FB_CMD_REG(ha, reg, 0x00fc);
937
938 /* Read back fb_cmd until zero or 3 seconds max */
939 for (cnt = 0; cnt < 3000; cnt++) {
940 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
941 break;
942 udelay(100);
943 }
944 }
945
946 /* Select RISC module registers. */
947 WRT_REG_WORD(&reg->ctrl_status, 0);
948 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
949
950 /* Reset RISC processor. */
951 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
952 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
953
954 /* Release RISC processor. */
955 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
956 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
957 }
958
959 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
960 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
961
962 /* Reset ISP chip. */
963 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
964
965 /* Wait for RISC to recover from reset. */
966 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
967 /*
968 * It is necessary to for a delay here since the card doesn't
969 * respond to PCI reads during a reset. On some architectures
970 * this will result in an MCA.
971 */
972 udelay(20);
973 for (cnt = 30000; cnt; cnt--) {
974 if ((RD_REG_WORD(&reg->ctrl_status) &
975 CSR_ISP_SOFT_RESET) == 0)
976 break;
977 udelay(100);
978 }
979 } else
980 udelay(10);
981
982 /* Reset RISC processor. */
983 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
984
985 WRT_REG_WORD(&reg->semaphore, 0);
986
987 /* Release RISC processor. */
988 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
989 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
990
991 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
992 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700993 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
996 udelay(100);
997 }
998 } else
999 udelay(100);
1000
1001 /* Turn on master enable */
1002 cmd |= PCI_COMMAND_MASTER;
1003 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
1004
1005 /* Disable RISC pause on FPM parity error. */
1006 if (!IS_QLA2100(ha)) {
1007 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
1008 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1009 }
1010
1011 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1012}
1013
1014/**
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001015 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
1016 *
1017 * Returns 0 on success.
1018 */
Saurav Kashyapfa492632012-11-21 02:40:29 -05001019static int
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001020qla81xx_reset_mpi(scsi_qla_host_t *vha)
1021{
1022 uint16_t mb[4] = {0x1010, 0, 1, 0};
1023
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001024 if (!IS_QLA81XX(vha->hw))
1025 return QLA_SUCCESS;
1026
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001027 return qla81xx_write_mpi_register(vha, mb);
1028}
1029
1030/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001031 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001032 * @ha: HA context
1033 *
1034 * Returns 0 on success.
1035 */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001036static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001037qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001038{
1039 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001040 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001041 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1042 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001043 uint16_t wd;
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001044 static int abts_cnt; /* ISP abort retry counts */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001045
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001046 spin_lock_irqsave(&ha->hardware_lock, flags);
1047
1048 /* Reset RISC. */
1049 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1050 for (cnt = 0; cnt < 30000; cnt++) {
1051 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
1052 break;
1053
1054 udelay(10);
1055 }
1056
1057 WRT_REG_DWORD(&reg->ctrl_status,
1058 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001059 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001060
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001061 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001062 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001063 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1064 for (cnt = 10000 ; cnt && d2; cnt--) {
1065 udelay(5);
1066 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1067 barrier();
1068 }
1069
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001070 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001071 d2 = RD_REG_DWORD(&reg->ctrl_status);
1072 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1073 udelay(5);
1074 d2 = RD_REG_DWORD(&reg->ctrl_status);
1075 barrier();
1076 }
1077
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001078 /* If required, do an MPI FW reset now */
1079 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1080 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1081 if (++abts_cnt < 5) {
1082 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1083 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1084 } else {
1085 /*
1086 * We exhausted the ISP abort retries. We have to
1087 * set the board offline.
1088 */
1089 abts_cnt = 0;
1090 vha->flags.online = 0;
1091 }
1092 }
1093 }
1094
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001095 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1096 RD_REG_DWORD(&reg->hccr);
1097
1098 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1099 RD_REG_DWORD(&reg->hccr);
1100
1101 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1102 RD_REG_DWORD(&reg->hccr);
1103
1104 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1105 for (cnt = 6000000 ; cnt && d2; cnt--) {
1106 udelay(5);
1107 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1108 barrier();
1109 }
1110
1111 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001112
1113 if (IS_NOPOLLING_TYPE(ha))
1114 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001115}
1116
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001117static void
1118qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
1119{
1120 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1121
1122 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1123 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
1124
1125}
1126
1127static void
1128qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
1129{
1130 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1131
1132 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1133 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
1134}
1135
1136static void
1137qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
1138{
1139 struct qla_hw_data *ha = vha->hw;
1140 uint32_t wd32 = 0;
1141 uint delta_msec = 100;
1142 uint elapsed_msec = 0;
1143 uint timeout_msec;
1144 ulong n;
1145
1146 if (!IS_QLA25XX(ha) && !IS_QLA2031(ha))
1147 return;
1148
1149attempt:
1150 timeout_msec = TIMEOUT_SEMAPHORE;
1151 n = timeout_msec / delta_msec;
1152 while (n--) {
1153 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
1154 qla25xx_read_risc_sema_reg(vha, &wd32);
1155 if (wd32 & RISC_SEMAPHORE)
1156 break;
1157 msleep(delta_msec);
1158 elapsed_msec += delta_msec;
1159 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1160 goto force;
1161 }
1162
1163 if (!(wd32 & RISC_SEMAPHORE))
1164 goto force;
1165
1166 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1167 goto acquired;
1168
1169 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
1170 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
1171 n = timeout_msec / delta_msec;
1172 while (n--) {
1173 qla25xx_read_risc_sema_reg(vha, &wd32);
1174 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1175 break;
1176 msleep(delta_msec);
1177 elapsed_msec += delta_msec;
1178 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1179 goto force;
1180 }
1181
1182 if (wd32 & RISC_SEMAPHORE_FORCE)
1183 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
1184
1185 goto attempt;
1186
1187force:
1188 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
1189
1190acquired:
1191 return;
1192}
1193
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001194/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001195 * qla24xx_reset_chip() - Reset ISP24xx chip.
1196 * @ha: HA context
1197 *
1198 * Returns 0 on success.
1199 */
1200void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001201qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001202{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001203 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001204
1205 if (pci_channel_offline(ha->pdev) &&
1206 ha->flags.pci_channel_io_perm_failure) {
1207 return;
1208 }
1209
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001210 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001211
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001212 qla25xx_manipulate_risc_semaphore(vha);
1213
Andrew Vasquez88c26662005-07-08 17:59:26 -07001214 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001215 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001216}
1217
1218/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 * qla2x00_chip_diag() - Test chip for proper operation.
1220 * @ha: HA context
1221 *
1222 * Returns 0 on success.
1223 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001224int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001225qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226{
1227 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001228 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001229 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 unsigned long flags = 0;
1231 uint16_t data;
1232 uint32_t cnt;
1233 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001234 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
1236 /* Assume a failed state */
1237 rval = QLA_FUNCTION_FAILED;
1238
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001239 ql_dbg(ql_dbg_init, vha, 0x007b,
1240 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
1242 spin_lock_irqsave(&ha->hardware_lock, flags);
1243
1244 /* Reset ISP chip. */
1245 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1246
1247 /*
1248 * We need to have a delay here since the card will not respond while
1249 * in reset causing an MCA on some architectures.
1250 */
1251 udelay(20);
1252 data = qla2x00_debounce_register(&reg->ctrl_status);
1253 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1254 udelay(5);
1255 data = RD_REG_WORD(&reg->ctrl_status);
1256 barrier();
1257 }
1258
1259 if (!cnt)
1260 goto chip_diag_failed;
1261
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001262 ql_dbg(ql_dbg_init, vha, 0x007c,
1263 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
1265 /* Reset RISC processor. */
1266 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1267 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1268
1269 /* Workaround for QLA2312 PCI parity error */
1270 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1271 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1272 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1273 udelay(5);
1274 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001275 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 }
1277 } else
1278 udelay(10);
1279
1280 if (!cnt)
1281 goto chip_diag_failed;
1282
1283 /* Check product ID of chip */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001284 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
1286 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1287 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1288 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1289 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1290 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1291 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001292 ql_log(ql_log_warn, vha, 0x0062,
1293 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1294 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
1296 goto chip_diag_failed;
1297 }
1298 ha->product_id[0] = mb[1];
1299 ha->product_id[1] = mb[2];
1300 ha->product_id[2] = mb[3];
1301 ha->product_id[3] = mb[4];
1302
1303 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001304 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1306 else
1307 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001308 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
1310 if (IS_QLA2200(ha) &&
1311 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1312 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001313 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001315 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 ha->fw_transfer_size = 128;
1317 }
1318
1319 /* Wrap Incoming Mailboxes Test. */
1320 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1321
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001322 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001323 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001324 if (rval)
1325 ql_log(ql_log_warn, vha, 0x0080,
1326 "Failed mailbox send register test.\n");
1327 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 /* Flag a successful rval */
1329 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 spin_lock_irqsave(&ha->hardware_lock, flags);
1331
1332chip_diag_failed:
1333 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001334 ql_log(ql_log_info, vha, 0x0081,
1335 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
1337 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1338
1339 return (rval);
1340}
1341
1342/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001343 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1344 * @ha: HA context
1345 *
1346 * Returns 0 on success.
1347 */
1348int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001349qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001350{
1351 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001352 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001353 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001354
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001355 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07001356 return QLA_SUCCESS;
1357
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001358 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001359
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001360 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001361 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001362 ql_log(ql_log_warn, vha, 0x0082,
1363 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001364 } else {
1365 /* Flag a successful rval */
1366 rval = QLA_SUCCESS;
1367 }
1368
1369 return rval;
1370}
1371
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001372void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001373qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001374{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001375 int rval;
1376 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001377 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001378 dma_addr_t tc_dma;
1379 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001380 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001381 struct req_que *req = ha->req_q_map[0];
1382 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001383
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001384 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001385 ql_dbg(ql_dbg_init, vha, 0x00bd,
1386 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001387 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001388 }
1389
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001390 ha->fw_dumped = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001391 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
1392 req_q_size = rsp_q_size = 0;
1393
1394 if (IS_QLA27XX(ha))
1395 goto try_fce;
1396
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001397 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1398 fixed_size = sizeof(struct qla2100_fw_dump);
1399 } else if (IS_QLA23XX(ha)) {
1400 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1401 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1402 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001403 } else if (IS_FWI2_CAPABLE(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001404 if (IS_QLA83XX(ha))
1405 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
1406 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001407 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1408 else if (IS_QLA25XX(ha))
1409 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1410 else
1411 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Chad Dupuisf73cb692014-02-26 04:15:06 -05001412
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001413 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1414 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001415 if (ha->mqenable) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001416 if (!IS_QLA83XX(ha))
1417 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001418 /*
1419 * Allocate maximum buffer size for all queues.
1420 * Resizing must be done at end-of-dump processing.
1421 */
1422 mq_size += ha->max_req_queues *
1423 (req->length * sizeof(request_t));
1424 mq_size += ha->max_rsp_queues *
1425 (rsp->length * sizeof(response_t));
1426 }
Arun Easi00876ae2013-03-25 02:21:37 -04001427 if (ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001428 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001429 /* Allocate memory for Fibre Channel Event Buffer. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05001430 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
1431 !IS_QLA27XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001432 goto try_eft;
1433
Chad Dupuisf73cb692014-02-26 04:15:06 -05001434try_fce:
1435 if (ha->fce)
1436 dma_free_coherent(&ha->pdev->dev,
1437 FCE_SIZE, ha->fce, ha->fce_dma);
1438
1439 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001440 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1441 GFP_KERNEL);
1442 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001443 ql_log(ql_log_warn, vha, 0x00be,
1444 "Unable to allocate (%d KB) for FCE.\n",
1445 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001446 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001447 }
1448
1449 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001450 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001451 ha->fce_mb, &ha->fce_bufs);
1452 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001453 ql_log(ql_log_warn, vha, 0x00bf,
1454 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001455 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1456 tc_dma);
1457 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001458 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001459 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001460 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001461 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001462
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001463 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001464 ha->flags.fce_enabled = 1;
1465 ha->fce_dma = tc_dma;
1466 ha->fce = tc;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001467
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001468try_eft:
Chad Dupuisf73cb692014-02-26 04:15:06 -05001469 if (ha->eft)
1470 dma_free_coherent(&ha->pdev->dev,
1471 EFT_SIZE, ha->eft, ha->eft_dma);
1472
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001473 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001474 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001475 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001476 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001477 ql_log(ql_log_warn, vha, 0x00c1,
1478 "Unable to allocate (%d KB) for EFT.\n",
1479 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001480 goto cont_alloc;
1481 }
1482
Andrew Vasquezfc447652008-01-17 09:02:18 -08001483 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001484 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001485 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001486 ql_log(ql_log_warn, vha, 0x00c2,
1487 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001488 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1489 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001490 goto cont_alloc;
1491 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001492 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001493 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001494
1495 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001496 ha->eft_dma = tc_dma;
1497 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001498 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05001499
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001500cont_alloc:
Chad Dupuisf73cb692014-02-26 04:15:06 -05001501 if (IS_QLA27XX(ha)) {
1502 if (!ha->fw_dump_template) {
1503 ql_log(ql_log_warn, vha, 0x00ba,
1504 "Failed missing fwdump template\n");
1505 return;
1506 }
1507 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
1508 ql_dbg(ql_dbg_init, vha, 0x00fa,
1509 "-> allocating fwdump (%x bytes)...\n", dump_size);
1510 goto allocate;
1511 }
1512
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001513 req_q_size = req->length * sizeof(request_t);
1514 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001515 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001516 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001517 ha->chain_offset = dump_size;
1518 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001519
Chad Dupuisf73cb692014-02-26 04:15:06 -05001520allocate:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001521 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001522 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001523 ql_log(ql_log_warn, vha, 0x00c4,
1524 "Unable to allocate (%d KB) for firmware dump.\n",
1525 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001526
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001527 if (ha->fce) {
1528 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1529 ha->fce_dma);
1530 ha->fce = NULL;
1531 ha->fce_dma = 0;
1532 }
1533
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001534 if (ha->eft) {
1535 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1536 ha->eft_dma);
1537 ha->eft = NULL;
1538 ha->eft_dma = 0;
1539 }
1540 return;
1541 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05001542 ha->fw_dump_len = dump_size;
Chad Dupuiscfb09192011-11-18 09:03:07 -08001543 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001544 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001545
Chad Dupuisf73cb692014-02-26 04:15:06 -05001546 if (IS_QLA27XX(ha))
1547 return;
1548
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001549 ha->fw_dump->signature[0] = 'Q';
1550 ha->fw_dump->signature[1] = 'L';
1551 ha->fw_dump->signature[2] = 'G';
1552 ha->fw_dump->signature[3] = 'C';
1553 ha->fw_dump->version = __constant_htonl(1);
1554
1555 ha->fw_dump->fixed_size = htonl(fixed_size);
1556 ha->fw_dump->mem_size = htonl(mem_size);
1557 ha->fw_dump->req_q_size = htonl(req_q_size);
1558 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1559
1560 ha->fw_dump->eft_size = htonl(eft_size);
1561 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1562 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1563
1564 ha->fw_dump->header_size =
1565 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001566}
1567
Andrew Vasquez18e75552009-06-03 09:55:30 -07001568static int
1569qla81xx_mpi_sync(scsi_qla_host_t *vha)
1570{
1571#define MPS_MASK 0xe0
1572 int rval;
1573 uint16_t dc;
1574 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07001575
1576 if (!IS_QLA81XX(vha->hw))
1577 return QLA_SUCCESS;
1578
1579 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1580 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001581 ql_log(ql_log_warn, vha, 0x0105,
1582 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001583 goto done;
1584 }
1585
1586 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1587 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1588 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001589 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001590 goto done_release;
1591 }
1592
1593 dc &= MPS_MASK;
1594 if (dc == (dw & MPS_MASK))
1595 goto done_release;
1596
1597 dw &= ~MPS_MASK;
1598 dw |= dc;
1599 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1600 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001601 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001602 }
1603
1604done_release:
1605 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1606 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001607 ql_log(ql_log_warn, vha, 0x006d,
1608 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001609 }
1610
1611done:
1612 return rval;
1613}
1614
Chad Dupuis8d93f552013-01-30 03:34:37 -05001615int
1616qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
1617{
1618 /* Don't try to reallocate the array */
1619 if (req->outstanding_cmds)
1620 return QLA_SUCCESS;
1621
1622 if (!IS_FWI2_CAPABLE(ha) || (ha->mqiobase &&
1623 (ql2xmultique_tag || ql2xmaxqueues > 1)))
1624 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
1625 else {
1626 if (ha->fw_xcb_count <= ha->fw_iocb_count)
1627 req->num_outstanding_cmds = ha->fw_xcb_count;
1628 else
1629 req->num_outstanding_cmds = ha->fw_iocb_count;
1630 }
1631
1632 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1633 req->num_outstanding_cmds, GFP_KERNEL);
1634
1635 if (!req->outstanding_cmds) {
1636 /*
1637 * Try to allocate a minimal size just so we can get through
1638 * initialization.
1639 */
1640 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
1641 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1642 req->num_outstanding_cmds, GFP_KERNEL);
1643
1644 if (!req->outstanding_cmds) {
1645 ql_log(ql_log_fatal, NULL, 0x0126,
1646 "Failed to allocate memory for "
1647 "outstanding_cmds for req_que %p.\n", req);
1648 req->num_outstanding_cmds = 0;
1649 return QLA_FUNCTION_FAILED;
1650 }
1651 }
1652
1653 return QLA_SUCCESS;
1654}
1655
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001656/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 * qla2x00_setup_chip() - Load and start RISC firmware.
1658 * @ha: HA context
1659 *
1660 * Returns 0 on success.
1661 */
1662static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001663qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001665 int rval;
1666 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001667 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001668 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1669 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001670 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001671
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001672 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001673 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001674 if (rval == QLA_SUCCESS) {
1675 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001676 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001677 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001678 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001679 }
1680
Andrew Vasquez3db06522008-01-31 12:33:49 -08001681 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1682 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1683 spin_lock_irqsave(&ha->hardware_lock, flags);
1684 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1685 RD_REG_WORD(&reg->hccr);
1686 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1687 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
Andrew Vasquez18e75552009-06-03 09:55:30 -07001689 qla81xx_mpi_sync(vha);
1690
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001692 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001693 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001694 ql_dbg(ql_dbg_init, vha, 0x00c9,
1695 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001697 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 if (rval == QLA_SUCCESS) {
1699 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001700 ql_dbg(ql_dbg_init, vha, 0x00ca,
1701 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001703 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001705 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001706enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001707 fw_major_version = ha->fw_major_version;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001708 if (IS_P3P_TYPE(ha))
Giridhar Malavali31731672011-08-16 11:31:54 -07001709 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001710 else
1711 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001712 if (rval != QLA_SUCCESS)
1713 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001714 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001715 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001716 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001717 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001718 if ((!ha->max_npiv_vports) ||
1719 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001720 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001721 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001722 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001723 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001724 qla2x00_get_resource_cnts(vha, NULL,
Chad Dupuis8d93f552013-01-30 03:34:37 -05001725 &ha->fw_xcb_count, NULL, &ha->fw_iocb_count,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001726 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001727
Chad Dupuis8d93f552013-01-30 03:34:37 -05001728 /*
1729 * Allocate the array of outstanding commands
1730 * now that we know the firmware resources.
1731 */
1732 rval = qla2x00_alloc_outstanding_cmds(ha,
1733 vha->req);
1734 if (rval != QLA_SUCCESS)
1735 goto failed;
1736
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08001737 if (!fw_major_version && ql2xallocfwdump
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001738 && !(IS_P3P_TYPE(ha)))
Giridhar Malavali08de2842011-08-16 11:31:44 -07001739 qla2x00_alloc_fw_dump(vha);
Chad Dupuis3b6e5b92013-10-30 03:38:09 -04001740 } else {
1741 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 }
1743 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001744 ql_log(ql_log_fatal, vha, 0x00cd,
1745 "ISP Firmware failed checksum.\n");
1746 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04001748 } else
1749 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
Andrew Vasquez3db06522008-01-31 12:33:49 -08001751 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1752 /* Enable proper parity. */
1753 spin_lock_irqsave(&ha->hardware_lock, flags);
1754 if (IS_QLA2300(ha))
1755 /* SRAM parity */
1756 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1757 else
1758 /* SRAM, Instruction RAM and GP RAM parity */
1759 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1760 RD_REG_WORD(&reg->hccr);
1761 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1762 }
1763
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001764 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1765 uint32_t size;
1766
1767 rval = qla81xx_fac_get_sector_size(vha, &size);
1768 if (rval == QLA_SUCCESS) {
1769 ha->flags.fac_supported = 1;
1770 ha->fdt_block_size = size << 2;
1771 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001772 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001773 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1774 ha->fw_major_version, ha->fw_minor_version,
1775 ha->fw_subminor_version);
Joe Carnuccio1ca60e32014-02-26 04:15:02 -05001776
Chad Dupuisf73cb692014-02-26 04:15:06 -05001777 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001778 ha->flags.fac_supported = 0;
1779 rval = QLA_SUCCESS;
1780 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001781 }
1782 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001783failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001785 ql_log(ql_log_fatal, vha, 0x00cf,
1786 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 }
1788
1789 return (rval);
1790}
1791
1792/**
1793 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1794 * @ha: HA context
1795 *
1796 * Beginning of request ring has initialization control block already built
1797 * by nvram config routine.
1798 *
1799 * Returns 0 on success.
1800 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001801void
1802qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803{
1804 uint16_t cnt;
1805 response_t *pkt;
1806
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001807 rsp->ring_ptr = rsp->ring;
1808 rsp->ring_index = 0;
1809 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001810 pkt = rsp->ring_ptr;
1811 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 pkt->signature = RESPONSE_PROCESSED;
1813 pkt++;
1814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815}
1816
1817/**
1818 * qla2x00_update_fw_options() - Read and process firmware options.
1819 * @ha: HA context
1820 *
1821 * Returns 0 on success.
1822 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001823void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001824qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825{
1826 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001827 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
1829 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001830 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
1832 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1833 return;
1834
1835 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001836 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1837 "Serial link options.\n");
1838 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1839 (uint8_t *)&ha->fw_seriallink_options,
1840 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841
1842 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1843 if (ha->fw_seriallink_options[3] & BIT_2) {
1844 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1845
1846 /* 1G settings */
1847 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1848 emphasis = (ha->fw_seriallink_options[2] &
1849 (BIT_4 | BIT_3)) >> 3;
1850 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001851 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 rx_sens = (ha->fw_seriallink_options[0] &
1853 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1854 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1855 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1856 if (rx_sens == 0x0)
1857 rx_sens = 0x3;
1858 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1859 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1860 ha->fw_options[10] |= BIT_5 |
1861 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1862 (tx_sens & (BIT_1 | BIT_0));
1863
1864 /* 2G settings */
1865 swing = (ha->fw_seriallink_options[2] &
1866 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1867 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1868 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001869 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 rx_sens = (ha->fw_seriallink_options[1] &
1871 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1872 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1873 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1874 if (rx_sens == 0x0)
1875 rx_sens = 0x3;
1876 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1877 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1878 ha->fw_options[11] |= BIT_5 |
1879 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1880 (tx_sens & (BIT_1 | BIT_0));
1881 }
1882
1883 /* FCP2 options. */
1884 /* Return command IOCBs without waiting for an ABTS to complete. */
1885 ha->fw_options[3] |= BIT_13;
1886
1887 /* LED scheme. */
1888 if (ha->flags.enable_led_scheme)
1889 ha->fw_options[2] |= BIT_12;
1890
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001891 /* Detect ISP6312. */
1892 if (IS_QLA6312(ha))
1893 ha->fw_options[2] |= BIT_13;
1894
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001896 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897}
1898
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001899void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001900qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001901{
1902 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001903 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001904
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001905 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07001906 return;
1907
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001908 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001909 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001910 return;
1911
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001912 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001913 le16_to_cpu(ha->fw_seriallink_options24[1]),
1914 le16_to_cpu(ha->fw_seriallink_options24[2]),
1915 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001916 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001917 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001918 "Unable to update Serial Link options (%x).\n", rval);
1919 }
1920}
1921
1922void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001923qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001924{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001925 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001926 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001927 struct req_que *req = ha->req_q_map[0];
1928 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001929
1930 /* Setup ring parameters in initialization control block. */
1931 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1932 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001933 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1934 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1935 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1936 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1937 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1938 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001939
1940 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1941 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1942 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1943 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1944 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1945}
1946
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001947void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001948qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001949{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001950 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001951 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1952 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1953 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001954 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001955 uint16_t rid = 0;
1956 struct req_que *req = ha->req_q_map[0];
1957 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001958
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001959 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001960 icb = (struct init_cb_24xx *)ha->init_cb;
1961 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1962 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001963 icb->request_q_length = cpu_to_le16(req->length);
1964 icb->response_q_length = cpu_to_le16(rsp->length);
1965 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1966 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1967 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1968 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001969
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001970 /* Setup ATIO queue dma pointers for target mode */
1971 icb->atio_q_inpointer = __constant_cpu_to_le16(0);
1972 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
1973 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
1974 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
1975
Chad Dupuisf73cb692014-02-26 04:15:06 -05001976 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001977 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1978 icb->rid = __constant_cpu_to_le16(rid);
1979 if (ha->flags.msix_enabled) {
1980 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001981 ql_dbg(ql_dbg_init, vha, 0x00fd,
1982 "Registering vector 0x%x for base que.\n",
1983 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001984 icb->msix = cpu_to_le16(msix->entry);
1985 }
1986 /* Use alternate PCI bus number */
1987 if (MSB(rid))
1988 icb->firmware_options_2 |=
1989 __constant_cpu_to_le32(BIT_19);
1990 /* Use alternate PCI devfn */
1991 if (LSB(rid))
1992 icb->firmware_options_2 |=
1993 __constant_cpu_to_le32(BIT_18);
1994
Anirban Chakraborty31557542009-12-02 10:36:55 -08001995 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001996 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
1997 (ha->flags.msix_enabled)) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08001998 icb->firmware_options_2 &=
1999 __constant_cpu_to_le32(~BIT_22);
2000 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002001 ql_dbg(ql_dbg_init, vha, 0x00fe,
2002 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08002003 } else {
2004 icb->firmware_options_2 |=
2005 __constant_cpu_to_le32(BIT_22);
2006 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002007 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002008
2009 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
2010 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
2011 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
2012 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
2013 } else {
2014 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
2015 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
2016 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
2017 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
2018 }
Arun Easiaa230bc2013-01-30 03:34:39 -05002019 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002020
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002021 /* PCI posting */
2022 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002023}
2024
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025/**
2026 * qla2x00_init_rings() - Initializes firmware.
2027 * @ha: HA context
2028 *
2029 * Beginning of request ring has initialization control block already built
2030 * by nvram config routine.
2031 *
2032 * Returns 0 on success.
2033 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002034int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002035qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036{
2037 int rval;
2038 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002039 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002040 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002041 struct req_que *req;
2042 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002043 struct mid_init_cb_24xx *mid_init_cb =
2044 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
2046 spin_lock_irqsave(&ha->hardware_lock, flags);
2047
2048 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002049 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002050 req = ha->req_q_map[que];
2051 if (!req)
2052 continue;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002053 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002054 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002056 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002057
2058 /* Initialize firmware. */
2059 req->ring_ptr = req->ring;
2060 req->ring_index = 0;
2061 req->cnt = req->length;
2062 }
2063
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002064 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002065 rsp = ha->rsp_q_map[que];
2066 if (!rsp)
2067 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002068 /* Initialize response queue entries */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002069 if (IS_QLAFX00(ha))
2070 qlafx00_init_response_q_entries(rsp);
2071 else
2072 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002073 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002075 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
2076 ha->tgt.atio_ring_index = 0;
2077 /* Initialize ATIO queue entries */
2078 qlt_init_atio_q_entries(vha);
2079
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002080 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
2082 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2083
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002084 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
2085
2086 if (IS_QLAFX00(ha)) {
2087 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
2088 goto next_check;
2089 }
2090
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002092 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002094 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04002095 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002096 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08002097 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002098 }
2099
Andrew Vasquez24a08132009-03-24 09:08:16 -07002100 if (IS_FWI2_CAPABLE(ha)) {
2101 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
2102 mid_init_cb->init_cb.execution_throttle =
2103 cpu_to_le16(ha->fw_xcb_count);
2104 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002105
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002106 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002107next_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002109 ql_log(ql_log_fatal, vha, 0x00d2,
2110 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002112 ql_dbg(ql_dbg_init, vha, 0x00d3,
2113 "Init Firmware -- success.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 }
2115
2116 return (rval);
2117}
2118
2119/**
2120 * qla2x00_fw_ready() - Waits for firmware ready.
2121 * @ha: HA context
2122 *
2123 * Returns 0 on success.
2124 */
2125static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002126qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127{
2128 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002129 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 uint16_t min_wait; /* Minimum wait time if loop is down */
2131 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07002132 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002133 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002135 if (IS_QLAFX00(vha->hw))
2136 return qlafx00_fw_ready(vha);
2137
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 rval = QLA_SUCCESS;
2139
2140 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002141 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142
2143 /*
2144 * Firmware should take at most one RATOV to login, plus 5 seconds for
2145 * our own processing.
2146 */
2147 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
2148 wait_time = min_wait;
2149 }
2150
2151 /* Min wait time if loop down */
2152 mtime = jiffies + (min_wait * HZ);
2153
2154 /* wait time before firmware ready */
2155 wtime = jiffies + (wait_time * HZ);
2156
2157 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002158 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002159 ql_log(ql_log_info, vha, 0x801e,
2160 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
2162 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05002163 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002164 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002166 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002167 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002169 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002170 ql_dbg(ql_dbg_taskm, vha, 0x801f,
2171 "fw_state=%x 84xx=%x.\n", state[0],
2172 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002173 if ((state[2] & FSTATE_LOGGED_IN) &&
2174 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002175 ql_dbg(ql_dbg_taskm, vha, 0x8028,
2176 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002177
2178 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002179 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002180 if (rval != QLA_SUCCESS) {
2181 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002182 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002183 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002184 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002185 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002186
2187 /* Add time taken to initialize. */
2188 cs84xx_time = jiffies - cs84xx_time;
2189 wtime += cs84xx_time;
2190 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002191 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002192 "Increasing wait time by %ld. "
2193 "New time %ld.\n", cs84xx_time,
2194 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002195 }
2196 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002197 ql_dbg(ql_dbg_taskm, vha, 0x8037,
2198 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002200 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 &ha->login_timeout, &ha->r_a_tov);
2202
2203 rval = QLA_SUCCESS;
2204 break;
2205 }
2206
2207 rval = QLA_FUNCTION_FAILED;
2208
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002209 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002210 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002212 * other than Wait for Login.
2213 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002215 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 "Cable is unplugged...\n");
2217
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002218 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 break;
2220 }
2221 }
2222 } else {
2223 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07002224 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08002225 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 break;
2227 }
2228
2229 if (time_after_eq(jiffies, wtime))
2230 break;
2231
2232 /* Delay for a while */
2233 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 } while (1);
2235
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002236 ql_dbg(ql_dbg_taskm, vha, 0x803a,
2237 "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0],
2238 state[1], state[2], state[3], state[4], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239
Chad Dupuiscfb09192011-11-18 09:03:07 -08002240 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002241 ql_log(ql_log_warn, vha, 0x803b,
2242 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 }
2244
2245 return (rval);
2246}
2247
2248/*
2249* qla2x00_configure_hba
2250* Setup adapter context.
2251*
2252* Input:
2253* ha = adapter state pointer.
2254*
2255* Returns:
2256* 0 = success
2257*
2258* Context:
2259* Kernel context.
2260*/
2261static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002262qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263{
2264 int rval;
2265 uint16_t loop_id;
2266 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002267 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 uint8_t al_pa;
2269 uint8_t area;
2270 uint8_t domain;
2271 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002272 struct qla_hw_data *ha = vha->hw;
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002273 unsigned long flags;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002274 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
2276 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002277 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002278 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002280 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002281 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002282 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002283 ql_dbg(ql_dbg_disc, vha, 0x2008,
2284 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08002285 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002286 ql_log(ql_log_warn, vha, 0x2009,
2287 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002288 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
2289 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
2290 ql_log(ql_log_warn, vha, 0x1151,
2291 "Doing link init.\n");
2292 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
2293 return rval;
2294 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002295 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 return (rval);
2298 }
2299
2300 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002301 ql_log(ql_log_info, vha, 0x200a,
2302 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 return (QLA_FUNCTION_FAILED);
2304 }
2305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002306 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307
2308 /* initialize */
2309 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2310 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002311 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
2313 switch (topo) {
2314 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002315 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 ha->current_topology = ISP_CFG_NL;
2317 strcpy(connect_type, "(Loop)");
2318 break;
2319
2320 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002321 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002322 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 ha->current_topology = ISP_CFG_FL;
2324 strcpy(connect_type, "(FL_Port)");
2325 break;
2326
2327 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002328 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 ha->operating_mode = P2P;
2330 ha->current_topology = ISP_CFG_N;
2331 strcpy(connect_type, "(N_Port-to-N_Port)");
2332 break;
2333
2334 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002335 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002336 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 ha->operating_mode = P2P;
2338 ha->current_topology = ISP_CFG_F;
2339 strcpy(connect_type, "(F_Port)");
2340 break;
2341
2342 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002343 ql_dbg(ql_dbg_disc, vha, 0x200f,
2344 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 ha->current_topology = ISP_CFG_NL;
2346 strcpy(connect_type, "(Loop)");
2347 break;
2348 }
2349
2350 /* Save Host port and loop ID. */
2351 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002352 vha->d_id.b.domain = domain;
2353 vha->d_id.b.area = area;
2354 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002356 spin_lock_irqsave(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002357 qlt_update_vp_map(vha, SET_AL_PA);
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002358 spin_unlock_irqrestore(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002359
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002360 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002361 ql_log(ql_log_info, vha, 0x2010,
2362 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002363 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 return(rval);
2366}
2367
Giridhar Malavalia9083012010-04-12 17:59:55 -07002368inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002369qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2370 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002371{
2372 char *st, *en;
2373 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002374 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002375 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002376 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002377
2378 if (memcmp(model, BINZERO, len) != 0) {
2379 strncpy(ha->model_number, model, len);
2380 st = en = ha->model_number;
2381 en += len - 1;
2382 while (en > st) {
2383 if (*en != 0x20 && *en != 0x00)
2384 break;
2385 *en-- = '\0';
2386 }
2387
2388 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002389 if (use_tbl &&
2390 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002391 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002392 strncpy(ha->model_desc,
2393 qla2x00_model_name[index * 2 + 1],
2394 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002395 } else {
2396 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002397 if (use_tbl &&
2398 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002399 index < QLA_MODEL_NAMES) {
2400 strcpy(ha->model_number,
2401 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002402 strncpy(ha->model_desc,
2403 qla2x00_model_name[index * 2 + 1],
2404 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002405 } else {
2406 strcpy(ha->model_number, def);
2407 }
2408 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002409 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002410 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002411 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002412}
2413
David Miller4e08df32007-04-16 12:37:43 -07002414/* On sparc systems, obtain port and node WWN from firmware
2415 * properties.
2416 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002417static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002418{
2419#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002420 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002421 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002422 struct device_node *dp = pci_device_to_OF_node(pdev);
2423 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002424 int len;
2425
2426 val = of_get_property(dp, "port-wwn", &len);
2427 if (val && len >= WWN_SIZE)
2428 memcpy(nv->port_name, val, WWN_SIZE);
2429
2430 val = of_get_property(dp, "node-wwn", &len);
2431 if (val && len >= WWN_SIZE)
2432 memcpy(nv->node_name, val, WWN_SIZE);
2433#endif
2434}
2435
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436/*
2437* NVRAM configuration for ISP 2xxx
2438*
2439* Input:
2440* ha = adapter block pointer.
2441*
2442* Output:
2443* initialization control block in response_ring
2444* host adapters parameters in host adapter block
2445*
2446* Returns:
2447* 0 = success.
2448*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002449int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002450qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451{
David Miller4e08df32007-04-16 12:37:43 -07002452 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002453 uint8_t chksum = 0;
2454 uint16_t cnt;
2455 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002456 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002457 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002458 nvram_t *nv = ha->nvram;
2459 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002460 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461
David Miller4e08df32007-04-16 12:37:43 -07002462 rval = QLA_SUCCESS;
2463
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002465 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 ha->nvram_base = 0;
2467 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2468 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2469 ha->nvram_base = 0x80;
2470
2471 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002472 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002473 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2474 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002476 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2477 "Contents of NVRAM.\n");
2478 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2479 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480
2481 /* Bad NVRAM data, set defaults parameters. */
2482 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2483 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2484 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002485 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04002486 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002487 "detected: checksum=0x%x id=%c version=0x%x.\n",
2488 chksum, nv->id[0], nv->nvram_version);
2489 ql_log(ql_log_warn, vha, 0x0065,
2490 "Falling back to "
2491 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07002492
2493 /*
2494 * Set default initialization control block.
2495 */
2496 memset(nv, 0, ha->nvram_size);
2497 nv->parameter_block_version = ICB_VERSION;
2498
2499 if (IS_QLA23XX(ha)) {
2500 nv->firmware_options[0] = BIT_2 | BIT_1;
2501 nv->firmware_options[1] = BIT_7 | BIT_5;
2502 nv->add_firmware_options[0] = BIT_5;
2503 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2504 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2505 nv->special_options[1] = BIT_7;
2506 } else if (IS_QLA2200(ha)) {
2507 nv->firmware_options[0] = BIT_2 | BIT_1;
2508 nv->firmware_options[1] = BIT_7 | BIT_5;
2509 nv->add_firmware_options[0] = BIT_5;
2510 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2511 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2512 } else if (IS_QLA2100(ha)) {
2513 nv->firmware_options[0] = BIT_3 | BIT_1;
2514 nv->firmware_options[1] = BIT_5;
2515 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2516 }
2517
2518 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2519 nv->execution_throttle = __constant_cpu_to_le16(16);
2520 nv->retry_count = 8;
2521 nv->retry_delay = 1;
2522
2523 nv->port_name[0] = 33;
2524 nv->port_name[3] = 224;
2525 nv->port_name[4] = 139;
2526
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002527 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002528
2529 nv->login_timeout = 4;
2530
2531 /*
2532 * Set default host adapter parameters
2533 */
2534 nv->host_p[1] = BIT_2;
2535 nv->reset_delay = 5;
2536 nv->port_down_retry_count = 8;
2537 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2538 nv->link_down_timeout = 60;
2539
2540 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 }
2542
2543#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2544 /*
2545 * The SN2 does not provide BIOS emulation which means you can't change
2546 * potentially bogus BIOS settings. Force the use of default settings
2547 * for link rate and frame size. Hope that the rest of the settings
2548 * are valid.
2549 */
2550 if (ia64_platform_is("sn2")) {
2551 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2552 if (IS_QLA23XX(ha))
2553 nv->special_options[1] = BIT_7;
2554 }
2555#endif
2556
2557 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002558 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559
2560 /*
2561 * Setup driver NVRAM options.
2562 */
2563 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2564 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2565 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2566 nv->firmware_options[1] &= ~BIT_4;
2567
2568 if (IS_QLA23XX(ha)) {
2569 nv->firmware_options[0] |= BIT_2;
2570 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002571 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002572 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573
2574 if (IS_QLA2300(ha)) {
2575 if (ha->fb_rev == FPM_2310) {
2576 strcpy(ha->model_number, "QLA2310");
2577 } else {
2578 strcpy(ha->model_number, "QLA2300");
2579 }
2580 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002581 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002582 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 }
2584 } else if (IS_QLA2200(ha)) {
2585 nv->firmware_options[0] |= BIT_2;
2586 /*
2587 * 'Point-to-point preferred, else loop' is not a safe
2588 * connection mode setting.
2589 */
2590 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2591 (BIT_5 | BIT_4)) {
2592 /* Force 'loop preferred, else point-to-point'. */
2593 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2594 nv->add_firmware_options[0] |= BIT_5;
2595 }
2596 strcpy(ha->model_number, "QLA22xx");
2597 } else /*if (IS_QLA2100(ha))*/ {
2598 strcpy(ha->model_number, "QLA2100");
2599 }
2600
2601 /*
2602 * Copy over NVRAM RISC parameter block to initialization control block.
2603 */
2604 dptr1 = (uint8_t *)icb;
2605 dptr2 = (uint8_t *)&nv->parameter_block_version;
2606 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2607 while (cnt--)
2608 *dptr1++ = *dptr2++;
2609
2610 /* Copy 2nd half. */
2611 dptr1 = (uint8_t *)icb->add_firmware_options;
2612 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2613 while (cnt--)
2614 *dptr1++ = *dptr2++;
2615
Andrew Vasquez5341e862006-05-17 15:09:16 -07002616 /* Use alternate WWN? */
2617 if (nv->host_p[1] & BIT_7) {
2618 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2619 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2620 }
2621
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 /* Prepare nodename */
2623 if ((icb->firmware_options[1] & BIT_6) == 0) {
2624 /*
2625 * Firmware will apply the following mask if the nodename was
2626 * not provided.
2627 */
2628 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2629 icb->node_name[0] &= 0xF0;
2630 }
2631
2632 /*
2633 * Set host adapter parameters.
2634 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002635
2636 /*
2637 * BIT_7 in the host-parameters section allows for modification to
2638 * internal driver logging.
2639 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002640 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08002641 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2643 /* Always load RISC code on non ISP2[12]00 chips. */
2644 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2645 ha->flags.disable_risc_code_load = 0;
2646 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2647 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2648 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002649 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002650 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
2652 ha->operating_mode =
2653 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2654
2655 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2656 sizeof(ha->fw_seriallink_options));
2657
2658 /* save HBA serial number */
2659 ha->serial0 = icb->port_name[5];
2660 ha->serial1 = icb->port_name[6];
2661 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002662 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2663 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664
2665 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2666
2667 ha->retry_count = nv->retry_count;
2668
2669 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002670 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 nv->login_timeout = ql2xlogintimeout;
2672 if (nv->login_timeout < 4)
2673 nv->login_timeout = 4;
2674 ha->login_timeout = nv->login_timeout;
2675 icb->login_timeout = nv->login_timeout;
2676
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002677 /* Set minimum RATOV to 100 tenths of a second. */
2678 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 ha->loop_reset_delay = nv->reset_delay;
2681
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 /* Link Down Timeout = 0:
2683 *
2684 * When Port Down timer expires we will start returning
2685 * I/O's to OS with "DID_NO_CONNECT".
2686 *
2687 * Link Down Timeout != 0:
2688 *
2689 * The driver waits for the link to come up after link down
2690 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002691 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 if (nv->link_down_timeout == 0) {
2693 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002694 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 } else {
2696 ha->link_down_timeout = nv->link_down_timeout;
2697 ha->loop_down_abort_time =
2698 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002699 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 /*
2702 * Need enough time to try and get the port back.
2703 */
2704 ha->port_down_retry_count = nv->port_down_retry_count;
2705 if (qlport_down_retry)
2706 ha->port_down_retry_count = qlport_down_retry;
2707 /* Set login_retry_count */
2708 ha->login_retry_count = nv->retry_count;
2709 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2710 ha->port_down_retry_count > 3)
2711 ha->login_retry_count = ha->port_down_retry_count;
2712 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2713 ha->login_retry_count = ha->port_down_retry_count;
2714 if (ql2xloginretrycount)
2715 ha->login_retry_count = ql2xloginretrycount;
2716
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 icb->lun_enables = __constant_cpu_to_le16(0);
2718 icb->command_resource_count = 0;
2719 icb->immediate_notify_resource_count = 0;
2720 icb->timeout = __constant_cpu_to_le16(0);
2721
2722 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2723 /* Enable RIO */
2724 icb->firmware_options[0] &= ~BIT_3;
2725 icb->add_firmware_options[0] &=
2726 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2727 icb->add_firmware_options[0] |= BIT_2;
2728 icb->response_accumulation_timer = 3;
2729 icb->interrupt_delay_timer = 5;
2730
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002731 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002733 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002734 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002735 ha->zio_mode = icb->add_firmware_options[0] &
2736 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2737 ha->zio_timer = icb->interrupt_delay_timer ?
2738 icb->interrupt_delay_timer: 2;
2739 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 icb->add_firmware_options[0] &=
2741 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002742 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002743 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002744 ha->zio_mode = QLA_ZIO_MODE_6;
2745
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002746 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002747 "ZIO mode %d enabled; timer delay (%d us).\n",
2748 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002750 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2751 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002752 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 }
2754 }
2755
David Miller4e08df32007-04-16 12:37:43 -07002756 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002757 ql_log(ql_log_warn, vha, 0x0069,
2758 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07002759 }
2760 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761}
2762
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002763static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002764qla2x00_rport_del(void *data)
2765{
2766 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002767 struct fc_rport *rport;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002768 scsi_qla_host_t *vha = fcport->vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002769 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002770
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002771 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002772 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002773 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002774 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002775 if (rport) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002776 fc_remote_port_delete(rport);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002777 /*
2778 * Release the target mode FC NEXUS in qla_target.c code
2779 * if target mod is enabled.
2780 */
2781 qlt_fc_port_deleted(vha, fcport);
2782 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002783}
2784
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785/**
2786 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2787 * @ha: HA context
2788 * @flags: allocation flags
2789 *
2790 * Returns a pointer to the allocated fcport, or NULL, if none available.
2791 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002792fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002793qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794{
2795 fc_port_t *fcport;
2796
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002797 fcport = kzalloc(sizeof(fc_port_t), flags);
2798 if (!fcport)
2799 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800
2801 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002802 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 fcport->port_type = FCT_UNKNOWN;
2804 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07002805 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002806 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002808 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809}
2810
2811/*
2812 * qla2x00_configure_loop
2813 * Updates Fibre Channel Device Database with what is actually on loop.
2814 *
2815 * Input:
2816 * ha = adapter block pointer.
2817 *
2818 * Returns:
2819 * 0 = success.
2820 * 1 = error.
2821 * 2 = database was full and device was not configured.
2822 */
2823static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002824qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825{
2826 int rval;
2827 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002828 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 rval = QLA_SUCCESS;
2830
2831 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002832 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2833 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002835 ql_dbg(ql_dbg_disc, vha, 0x2013,
2836 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 return (rval);
2838 }
2839 }
2840
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002841 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002842 ql_dbg(ql_dbg_disc, vha, 0x2014,
2843 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844
2845 /*
2846 * If we have both an RSCN and PORT UPDATE pending then handle them
2847 * both at the same time.
2848 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002849 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2850 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851
Michael Hernandez3064ff32009-12-15 21:29:44 -08002852 qla2x00_get_data_rate(vha);
2853
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 /* Determine what we need to do */
2855 if (ha->current_topology == ISP_CFG_FL &&
2856 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2857
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 set_bit(RSCN_UPDATE, &flags);
2859
2860 } else if (ha->current_topology == ISP_CFG_F &&
2861 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2862
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 set_bit(RSCN_UPDATE, &flags);
2864 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2865
Andrew Vasquez21333b42006-05-17 15:09:56 -07002866 } else if (ha->current_topology == ISP_CFG_N) {
2867 clear_bit(RSCN_UPDATE, &flags);
2868
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002869 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2871
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 set_bit(RSCN_UPDATE, &flags);
2873 set_bit(LOCAL_LOOP_UPDATE, &flags);
2874 }
2875
2876 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002877 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2878 ql_dbg(ql_dbg_disc, vha, 0x2015,
2879 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08002881 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002882 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 }
2884
2885 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002886 if (LOOP_TRANSITION(vha)) {
2887 ql_dbg(ql_dbg_disc, vha, 0x201e,
2888 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002890 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002891 else
2892 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 }
2894
2895 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002896 if (atomic_read(&vha->loop_down_timer) ||
2897 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 rval = QLA_FUNCTION_FAILED;
2899 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002900 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002901 ql_dbg(ql_dbg_disc, vha, 0x2069,
2902 "LOOP READY.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 }
2904 }
2905
2906 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002907 ql_dbg(ql_dbg_disc, vha, 0x206a,
2908 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002910 ql_dbg(ql_dbg_disc, vha, 0x206b,
2911 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 }
2913
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002914 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002915 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002917 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002918 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002919 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002920 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 }
2922
2923 return (rval);
2924}
2925
2926
2927
2928/*
2929 * qla2x00_configure_local_loop
2930 * Updates Fibre Channel Device Database with local loop devices.
2931 *
2932 * Input:
2933 * ha = adapter block pointer.
2934 *
2935 * Returns:
2936 * 0 = success.
2937 */
2938static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002939qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940{
2941 int rval, rval2;
2942 int found_devs;
2943 int found;
2944 fc_port_t *fcport, *new_fcport;
2945
2946 uint16_t index;
2947 uint16_t entries;
2948 char *id_iter;
2949 uint16_t loop_id;
2950 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002951 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952
2953 found_devs = 0;
2954 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08002955 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08002958 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002959 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 &entries);
2961 if (rval != QLA_SUCCESS)
2962 goto cleanup_allocation;
2963
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002964 ql_dbg(ql_dbg_disc, vha, 0x2017,
2965 "Entries in ID list (%d).\n", entries);
2966 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
2967 (uint8_t *)ha->gid_list,
2968 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969
2970 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002971 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002973 ql_log(ql_log_warn, vha, 0x2018,
2974 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 rval = QLA_MEMORY_ALLOC_FAILED;
2976 goto cleanup_allocation;
2977 }
2978 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2979
2980 /*
2981 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2982 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002983 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2985 fcport->port_type != FCT_BROADCAST &&
2986 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2987
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002988 ql_dbg(ql_dbg_disc, vha, 0x2019,
2989 "Marking port lost loop_id=0x%04x.\n",
2990 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991
Chad Dupuisec426e12011-03-30 11:46:32 -07002992 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 }
2994 }
2995
2996 /* Add devices to port list. */
2997 id_iter = (char *)ha->gid_list;
2998 for (index = 0; index < entries; index++) {
2999 domain = ((struct gid_list_info *)id_iter)->domain;
3000 area = ((struct gid_list_info *)id_iter)->area;
3001 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003002 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 loop_id = (uint16_t)
3004 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003005 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 loop_id = le16_to_cpu(
3007 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003008 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009
3010 /* Bypass reserved domain fields. */
3011 if ((domain & 0xf0) == 0xf0)
3012 continue;
3013
3014 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003015 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003016 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 continue;
3018
3019 /* Bypass invalid local loop ID. */
3020 if (loop_id > LAST_LOCAL_LOOP_ID)
3021 continue;
3022
Arun Easi370d5502012-08-22 14:21:10 -04003023 memset(new_fcport, 0, sizeof(fc_port_t));
3024
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 /* Fill in member data. */
3026 new_fcport->d_id.b.domain = domain;
3027 new_fcport->d_id.b.area = area;
3028 new_fcport->d_id.b.al_pa = al_pa;
3029 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003030 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003032 ql_dbg(ql_dbg_disc, vha, 0x201a,
3033 "Failed to retrieve fcport information "
3034 "-- get_port_database=%x, loop_id=0x%04x.\n",
3035 rval2, new_fcport->loop_id);
3036 ql_dbg(ql_dbg_disc, vha, 0x201b,
3037 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003038 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 continue;
3040 }
3041
3042 /* Check for matching device in port list. */
3043 found = 0;
3044 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003045 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 if (memcmp(new_fcport->port_name, fcport->port_name,
3047 WWN_SIZE))
3048 continue;
3049
Shyam Sundarddb9b122009-03-24 09:08:10 -07003050 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 fcport->loop_id = new_fcport->loop_id;
3052 fcport->port_type = new_fcport->port_type;
3053 fcport->d_id.b24 = new_fcport->d_id.b24;
3054 memcpy(fcport->node_name, new_fcport->node_name,
3055 WWN_SIZE);
3056
3057 found++;
3058 break;
3059 }
3060
3061 if (!found) {
3062 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003063 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064
3065 /* Allocate a new replacement fcport. */
3066 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003067 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003069 ql_log(ql_log_warn, vha, 0x201c,
3070 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 rval = QLA_MEMORY_ALLOC_FAILED;
3072 goto cleanup_allocation;
3073 }
3074 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3075 }
3076
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003077 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003078 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003079
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003080 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081
3082 found_devs++;
3083 }
3084
3085cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003086 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087
3088 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003089 ql_dbg(ql_dbg_disc, vha, 0x201d,
3090 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 }
3092
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 return (rval);
3094}
3095
3096static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003097qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003098{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003099 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003100 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003101 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003102
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07003103 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003104 return;
3105
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07003106 if (atomic_read(&fcport->state) != FCS_ONLINE)
3107 return;
3108
Andrew Vasquez39bd9622007-09-20 14:07:34 -07003109 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
3110 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003111 return;
3112
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003113 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003114 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003115 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003116 ql_dbg(ql_dbg_disc, vha, 0x2004,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04003117 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
3118 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003119 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003120 ql_dbg(ql_dbg_disc, vha, 0x2005,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04003121 "iIDMA adjusted to %s GB/s on %8phN.\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -05003122 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04003123 fcport->port_name);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003124 }
3125}
3126
Adrian Bunk23be3312006-11-24 02:46:01 +01003127static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003128qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05003129{
3130 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05003131 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003132 unsigned long flags;
8482e1182005-04-17 15:04:54 -05003133
Andrew Vasquezac280b62009-08-20 11:06:05 -07003134 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05003135
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07003136 rport_ids.node_name = wwn_to_u64(fcport->node_name);
3137 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05003138 rport_ids.port_id = fcport->d_id.b.domain << 16 |
3139 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
3140 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003141 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07003142 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003143 ql_log(ql_log_warn, vha, 0x2006,
3144 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07003145 return;
3146 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003147 /*
3148 * Create target mode FC NEXUS in qla_target.c if target mode is
3149 * enabled..
3150 */
3151 qlt_fc_port_added(vha, fcport);
3152
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003153 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003154 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003155 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003156
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003157 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003158
3159 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05003160 if (fcport->port_type == FCT_INITIATOR)
3161 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3162 if (fcport->port_type == FCT_TARGET)
3163 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003164 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05003165}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166
3167/*
Adrian Bunk23be3312006-11-24 02:46:01 +01003168 * qla2x00_update_fcport
3169 * Updates device on list.
3170 *
3171 * Input:
3172 * ha = adapter block pointer.
3173 * fcport = port structure pointer.
3174 *
3175 * Return:
3176 * 0 - Success
3177 * BIT_0 - error
3178 *
3179 * Context:
3180 * Kernel context.
3181 */
3182void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003183qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01003184{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003185 fcport->vha = vha;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003186
3187 if (IS_QLAFX00(vha->hw)) {
3188 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
3189 qla2x00_reg_remote_port(vha, fcport);
3190 return;
3191 }
Adrian Bunk23be3312006-11-24 02:46:01 +01003192 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003193 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01003194
Joe Carnuccio1f93da52012-11-21 02:40:38 -05003195 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003196 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08003197 qla24xx_update_fcport_fcp_prio(vha, fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003198 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01003199}
3200
3201/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 * qla2x00_configure_fabric
3203 * Setup SNS devices with loop ID's.
3204 *
3205 * Input:
3206 * ha = adapter block pointer.
3207 *
3208 * Returns:
3209 * 0 = success.
3210 * BIT_0 = error
3211 */
3212static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003213qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214{
Arun Easib3b02e62012-02-09 11:15:39 -08003215 int rval;
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003216 fc_port_t *fcport, *fcptemp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 uint16_t next_loopid;
3218 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003219 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003221 struct qla_hw_data *ha = vha->hw;
3222 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223
3224 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003225 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003226 loop_id = NPH_F_PORT;
3227 else
3228 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003229 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003231 ql_dbg(ql_dbg_disc, vha, 0x201f,
3232 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003234 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 return (QLA_SUCCESS);
3236 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003237 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07003240 /* FDMI support. */
3241 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003242 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
3243 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07003244
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003246 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003247 loop_id = NPH_SNS;
3248 else
3249 loop_id = SIMPLE_NAME_SERVER;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003250 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
3251 0xfc, mb, BIT_1|BIT_0);
3252 if (rval != QLA_SUCCESS) {
3253 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003254 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003255 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003257 ql_dbg(ql_dbg_disc, vha, 0x2042,
3258 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3259 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
3260 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 return (QLA_SUCCESS);
3262 }
3263
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003264 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3265 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003267 ql_dbg(ql_dbg_disc, vha, 0x2045,
3268 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003270 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003272 ql_dbg(ql_dbg_disc, vha, 0x2049,
3273 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003275 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003277 ql_dbg(ql_dbg_disc, vha, 0x204f,
3278 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003279 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003281 ql_dbg(ql_dbg_disc, vha, 0x2053,
3282 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 }
3284 }
3285
Joe Carnuccio827210b2013-02-08 01:57:57 -05003286#define QLA_FCPORT_SCAN 1
3287#define QLA_FCPORT_FOUND 2
3288
3289 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3290 fcport->scan_state = QLA_FCPORT_SCAN;
3291 }
3292
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003293 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 if (rval != QLA_SUCCESS)
3295 break;
3296
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003297 /*
3298 * Logout all previous fabric devices marked lost, except
3299 * FCP2 devices.
3300 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003301 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3302 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 break;
3304
3305 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3306 continue;
3307
Joe Carnuccio827210b2013-02-08 01:57:57 -05003308 if (fcport->scan_state == QLA_FCPORT_SCAN &&
Arun Easib3b02e62012-02-09 11:15:39 -08003309 atomic_read(&fcport->state) == FCS_ONLINE) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003310 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003311 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003313 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 fcport->port_type != FCT_INITIATOR &&
3315 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003316 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003317 fcport->loop_id,
3318 fcport->d_id.b.domain,
3319 fcport->d_id.b.area,
3320 fcport->d_id.b.al_pa);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003321 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 }
3323 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003326 /* Starting free loop ID. */
3327 next_loopid = ha->min_external_loopid;
3328
3329 /*
3330 * Scan through our port list and login entries that need to be
3331 * logged in.
3332 */
3333 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3334 if (atomic_read(&vha->loop_down_timer) ||
3335 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3336 break;
3337
3338 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3339 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3340 continue;
3341
3342 if (fcport->loop_id == FC_NO_LOOP_ID) {
3343 fcport->loop_id = next_loopid;
3344 rval = qla2x00_find_new_loop_id(
3345 base_vha, fcport);
3346 if (rval != QLA_SUCCESS) {
3347 /* Ran out of IDs to use */
3348 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 }
3350 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003351 /* Login and update database */
3352 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
3353 }
3354
3355 /* Exit if out of loop IDs. */
3356 if (rval != QLA_SUCCESS) {
3357 break;
3358 }
3359
3360 /*
3361 * Login and add the new devices to our port list.
3362 */
3363 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3364 if (atomic_read(&vha->loop_down_timer) ||
3365 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3366 break;
3367
3368 /* Find a new loop ID to use. */
3369 fcport->loop_id = next_loopid;
3370 rval = qla2x00_find_new_loop_id(base_vha, fcport);
3371 if (rval != QLA_SUCCESS) {
3372 /* Ran out of IDs to use */
3373 break;
3374 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375
bdf79622005-04-17 15:06:53 -05003376 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003377 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003378
3379 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 }
3381 } while (0);
3382
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003383 /* Free all new device structures not processed. */
3384 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3385 list_del(&fcport->list);
3386 kfree(fcport);
3387 }
3388
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003390 ql_dbg(ql_dbg_disc, vha, 0x2068,
3391 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 }
3393
3394 return (rval);
3395}
3396
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397/*
3398 * qla2x00_find_all_fabric_devs
3399 *
3400 * Input:
3401 * ha = adapter block pointer.
3402 * dev = database device entry pointer.
3403 *
3404 * Returns:
3405 * 0 = success.
3406 *
3407 * Context:
3408 * Kernel context.
3409 */
3410static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003411qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3412 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413{
3414 int rval;
3415 uint16_t loop_id;
3416 fc_port_t *fcport, *new_fcport, *fcptemp;
3417 int found;
3418
3419 sw_info_t *swl;
3420 int swl_idx;
3421 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003422 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003423 struct qla_hw_data *ha = vha->hw;
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05003424 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425
3426 rval = QLA_SUCCESS;
3427
3428 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08003429 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08003430 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08003431 GFP_KERNEL);
3432 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003433 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003435 ql_dbg(ql_dbg_disc, vha, 0x2054,
3436 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08003438 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003439 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003441 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003443 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003445 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003446 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3447 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003449
3450 /* If other queries succeeded probe for FC-4 type */
3451 if (swl)
3452 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 }
3454 swl_idx = 0;
3455
3456 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003457 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003458 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003459 ql_log(ql_log_warn, vha, 0x205e,
3460 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461 return (QLA_MEMORY_ALLOC_FAILED);
3462 }
3463 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 /* Set start port ID scan at adapter ID. */
3465 first_dev = 1;
3466 last_dev = 0;
3467
3468 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003469 loop_id = ha->min_external_loopid;
3470 for (; loop_id <= ha->max_loop_id; loop_id++) {
3471 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 continue;
3473
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003474 if (ha->current_topology == ISP_CFG_FL &&
3475 (atomic_read(&vha->loop_down_timer) ||
3476 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003477 atomic_set(&vha->loop_down_timer, 0);
3478 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3479 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003481 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482
3483 if (swl != NULL) {
3484 if (last_dev) {
3485 wrap.b24 = new_fcport->d_id.b24;
3486 } else {
3487 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3488 memcpy(new_fcport->node_name,
3489 swl[swl_idx].node_name, WWN_SIZE);
3490 memcpy(new_fcport->port_name,
3491 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003492 memcpy(new_fcport->fabric_port_name,
3493 swl[swl_idx].fabric_port_name, WWN_SIZE);
3494 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003495 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496
3497 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3498 last_dev = 1;
3499 }
3500 swl_idx++;
3501 }
3502 } else {
3503 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003504 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003506 ql_log(ql_log_warn, vha, 0x2064,
3507 "SNS scan failed -- assuming "
3508 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509 list_for_each_entry_safe(fcport, fcptemp,
3510 new_fcports, list) {
3511 list_del(&fcport->list);
3512 kfree(fcport);
3513 }
3514 rval = QLA_SUCCESS;
3515 break;
3516 }
3517 }
3518
3519 /* If wrap on switch device list, exit. */
3520 if (first_dev) {
3521 wrap.b24 = new_fcport->d_id.b24;
3522 first_dev = 0;
3523 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003524 ql_dbg(ql_dbg_disc, vha, 0x2065,
3525 "Device wrap (%02x%02x%02x).\n",
3526 new_fcport->d_id.b.domain,
3527 new_fcport->d_id.b.area,
3528 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 break;
3530 }
3531
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003532 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003533 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534 continue;
3535
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003536 /* Bypass virtual ports of the same host. */
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05003537 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
3538 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003539
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003540 /* Bypass if same domain and area of adapter. */
3541 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003542 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003543 ISP_CFG_FL)
3544 continue;
3545
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 /* Bypass reserved domain fields. */
3547 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3548 continue;
3549
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003550 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003551 if (ql2xgffidenable &&
3552 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3553 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003554 continue;
3555
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 /* Locate matching device in database. */
3557 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003558 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 if (memcmp(new_fcport->port_name, fcport->port_name,
3560 WWN_SIZE))
3561 continue;
3562
Joe Carnuccio827210b2013-02-08 01:57:57 -05003563 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08003564
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565 found++;
3566
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003567 /* Update port state. */
3568 memcpy(fcport->fabric_port_name,
3569 new_fcport->fabric_port_name, WWN_SIZE);
3570 fcport->fp_speed = new_fcport->fp_speed;
3571
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 /*
3573 * If address the same and state FCS_ONLINE, nothing
3574 * changed.
3575 */
3576 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3577 atomic_read(&fcport->state) == FCS_ONLINE) {
3578 break;
3579 }
3580
3581 /*
3582 * If device was not a fabric device before.
3583 */
3584 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3585 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04003586 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587 fcport->flags |= (FCF_FABRIC_DEVICE |
3588 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589 break;
3590 }
3591
3592 /*
3593 * Port ID changed or device was marked to be updated;
3594 * Log it out if still logged in and mark it for
3595 * relogin later.
3596 */
3597 fcport->d_id.b24 = new_fcport->d_id.b24;
3598 fcport->flags |= FCF_LOGIN_NEEDED;
3599 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003600 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Arun Easi0eba25d2012-02-09 11:15:58 -08003601 (fcport->flags & FCF_ASYNC_SENT) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602 fcport->port_type != FCT_INITIATOR &&
3603 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003604 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003605 fcport->d_id.b.domain, fcport->d_id.b.area,
3606 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003607 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608 }
3609
3610 break;
3611 }
3612
3613 if (found)
3614 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 /* If device was not in our fcports list, then add it. */
3616 list_add_tail(&new_fcport->list, new_fcports);
3617
3618 /* Allocate a new replacement fcport. */
3619 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003620 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003622 ql_log(ql_log_warn, vha, 0x2066,
3623 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 return (QLA_MEMORY_ALLOC_FAILED);
3625 }
3626 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3627 new_fcport->d_id.b24 = nxt_d_id.b24;
3628 }
3629
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003630 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632 return (rval);
3633}
3634
3635/*
3636 * qla2x00_find_new_loop_id
3637 * Scan through our port list and find a new usable loop ID.
3638 *
3639 * Input:
3640 * ha: adapter state pointer.
3641 * dev: port structure pointer.
3642 *
3643 * Returns:
3644 * qla2x00 local function return status code.
3645 *
3646 * Context:
3647 * Kernel context.
3648 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003649int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003650qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651{
3652 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003653 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07003654 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655
3656 rval = QLA_SUCCESS;
3657
Chad Dupuis5f16b332012-08-22 14:21:00 -04003658 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659
Chad Dupuis5f16b332012-08-22 14:21:00 -04003660 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
3661 LOOPID_MAP_SIZE);
3662 if (dev->loop_id >= LOOPID_MAP_SIZE ||
3663 qla2x00_is_reserved_id(vha, dev->loop_id)) {
3664 dev->loop_id = FC_NO_LOOP_ID;
3665 rval = QLA_FUNCTION_FAILED;
3666 } else
3667 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668
Chad Dupuis5f16b332012-08-22 14:21:00 -04003669 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670
Chad Dupuis5f16b332012-08-22 14:21:00 -04003671 if (rval == QLA_SUCCESS)
3672 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
3673 "Assigning new loopid=%x, portid=%x.\n",
3674 dev->loop_id, dev->d_id.b24);
3675 else
3676 ql_log(ql_log_warn, dev->vha, 0x2087,
3677 "No loop_id's available, portid=%x.\n",
3678 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679
3680 return (rval);
3681}
3682
3683/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684 * qla2x00_fabric_dev_login
3685 * Login fabric target device and update FC port database.
3686 *
3687 * Input:
3688 * ha: adapter state pointer.
3689 * fcport: port structure list pointer.
3690 * next_loopid: contains value of a new loop ID that can be used
3691 * by the next login attempt.
3692 *
3693 * Returns:
3694 * qla2x00 local function return status code.
3695 *
3696 * Context:
3697 * Kernel context.
3698 */
3699static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003700qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 uint16_t *next_loopid)
3702{
3703 int rval;
3704 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003705 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003706 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707
3708 rval = QLA_SUCCESS;
3709 retry = 0;
3710
Andrew Vasquezac280b62009-08-20 11:06:05 -07003711 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003712 if (fcport->flags & FCF_ASYNC_SENT)
3713 return rval;
3714 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003715 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3716 if (!rval)
3717 return rval;
3718 }
3719
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003720 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003721 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003723 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003724 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003725 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003726 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003727 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003729 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003730 fcport->d_id.b.domain, fcport->d_id.b.area,
3731 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003732 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003733 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003734 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735 }
Chad Dupuis0b91d112012-02-09 11:15:42 -08003736 } else {
3737 /* Retry Login. */
3738 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 }
3740
3741 return (rval);
3742}
3743
3744/*
3745 * qla2x00_fabric_login
3746 * Issue fabric login command.
3747 *
3748 * Input:
3749 * ha = adapter block pointer.
3750 * device = pointer to FC device type structure.
3751 *
3752 * Returns:
3753 * 0 - Login successfully
3754 * 1 - Login failed
3755 * 2 - Initiator device
3756 * 3 - Fatal error
3757 */
3758int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003759qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760 uint16_t *next_loopid)
3761{
3762 int rval;
3763 int retry;
3764 uint16_t tmp_loopid;
3765 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003766 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767
3768 retry = 0;
3769 tmp_loopid = 0;
3770
3771 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003772 ql_dbg(ql_dbg_disc, vha, 0x2000,
3773 "Trying Fabric Login w/loop id 0x%04x for port "
3774 "%02x%02x%02x.\n",
3775 fcport->loop_id, fcport->d_id.b.domain,
3776 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777
3778 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08003779 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780 fcport->d_id.b.domain, fcport->d_id.b.area,
3781 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08003782 if (rval != QLA_SUCCESS) {
3783 return rval;
3784 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785 if (mb[0] == MBS_PORT_ID_USED) {
3786 /*
3787 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003788 * recommends the driver perform an implicit login with
3789 * the specified ID again. The ID we just used is save
3790 * here so we return with an ID that can be tried by
3791 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 */
3793 retry++;
3794 tmp_loopid = fcport->loop_id;
3795 fcport->loop_id = mb[1];
3796
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003797 ql_dbg(ql_dbg_disc, vha, 0x2001,
3798 "Fabric Login: port in use - next loop "
3799 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003801 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802
3803 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3804 /*
3805 * Login succeeded.
3806 */
3807 if (retry) {
3808 /* A retry occurred before. */
3809 *next_loopid = tmp_loopid;
3810 } else {
3811 /*
3812 * No retry occurred before. Just increment the
3813 * ID value for next login.
3814 */
3815 *next_loopid = (fcport->loop_id + 1);
3816 }
3817
3818 if (mb[1] & BIT_0) {
3819 fcport->port_type = FCT_INITIATOR;
3820 } else {
3821 fcport->port_type = FCT_TARGET;
3822 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003823 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 }
3825 }
3826
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003827 if (mb[10] & BIT_0)
3828 fcport->supported_classes |= FC_COS_CLASS2;
3829 if (mb[10] & BIT_1)
3830 fcport->supported_classes |= FC_COS_CLASS3;
3831
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003832 if (IS_FWI2_CAPABLE(ha)) {
3833 if (mb[10] & BIT_7)
3834 fcport->flags |=
3835 FCF_CONF_COMP_SUPPORTED;
3836 }
3837
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 rval = QLA_SUCCESS;
3839 break;
3840 } else if (mb[0] == MBS_LOOP_ID_USED) {
3841 /*
3842 * Loop ID already used, try next loop ID.
3843 */
3844 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003845 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846 if (rval != QLA_SUCCESS) {
3847 /* Ran out of loop IDs to use */
3848 break;
3849 }
3850 } else if (mb[0] == MBS_COMMAND_ERROR) {
3851 /*
3852 * Firmware possibly timed out during login. If NO
3853 * retries are left to do then the device is declared
3854 * dead.
3855 */
3856 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003857 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003858 fcport->d_id.b.domain, fcport->d_id.b.area,
3859 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003860 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861
3862 rval = 1;
3863 break;
3864 } else {
3865 /*
3866 * unrecoverable / not handled error
3867 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003868 ql_dbg(ql_dbg_disc, vha, 0x2002,
3869 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
3870 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
3871 fcport->d_id.b.area, fcport->d_id.b.al_pa,
3872 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873
3874 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003875 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003876 fcport->d_id.b.domain, fcport->d_id.b.area,
3877 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003878 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003879 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880
3881 rval = 3;
3882 break;
3883 }
3884 }
3885
3886 return (rval);
3887}
3888
3889/*
3890 * qla2x00_local_device_login
3891 * Issue local device login command.
3892 *
3893 * Input:
3894 * ha = adapter block pointer.
3895 * loop_id = loop id of device to login to.
3896 *
3897 * Returns (Where's the #define!!!!):
3898 * 0 - Login successfully
3899 * 1 - Login failed
3900 * 3 - Fatal error
3901 */
3902int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003903qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904{
3905 int rval;
3906 uint16_t mb[MAILBOX_REGISTER_COUNT];
3907
3908 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003909 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910 if (rval == QLA_SUCCESS) {
3911 /* Interrogate mailbox registers for any errors */
3912 if (mb[0] == MBS_COMMAND_ERROR)
3913 rval = 1;
3914 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3915 /* device not in PCB table */
3916 rval = 3;
3917 }
3918
3919 return (rval);
3920}
3921
3922/*
3923 * qla2x00_loop_resync
3924 * Resync with fibre channel devices.
3925 *
3926 * Input:
3927 * ha = adapter block pointer.
3928 *
3929 * Returns:
3930 * 0 = success
3931 */
3932int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003933qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003935 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003937 struct req_que *req;
3938 struct rsp_que *rsp;
3939
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003940 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003941 req = vha->hw->req_q_map[0];
3942 else
3943 req = vha->req;
3944 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003946 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3947 if (vha->flags.online) {
3948 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3950 wait_time = 256;
3951 do {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003952 if (!IS_QLAFX00(vha->hw)) {
3953 /*
3954 * Issue a marker after FW becomes
3955 * ready.
3956 */
3957 qla2x00_marker(vha, req, rsp, 0, 0,
3958 MK_SYNC_ALL);
3959 vha->marker_needed = 0;
3960 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961
3962 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003963 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003965 if (IS_QLAFX00(vha->hw))
3966 qlafx00_configure_devices(vha);
3967 else
3968 qla2x00_configure_loop(vha);
3969
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003971 } while (!atomic_read(&vha->loop_down_timer) &&
3972 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3973 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3974 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 }
3977
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003978 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003981 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003982 ql_dbg(ql_dbg_disc, vha, 0x206c,
3983 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984
3985 return (rval);
3986}
3987
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003988/*
3989* qla2x00_perform_loop_resync
3990* Description: This function will set the appropriate flags and call
3991* qla2x00_loop_resync. If successful loop will be resynced
3992* Arguments : scsi_qla_host_t pointer
3993* returm : Success or Failure
3994*/
3995
3996int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
3997{
3998 int32_t rval = 0;
3999
4000 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
4001 /*Configure the flags so that resync happens properly*/
4002 atomic_set(&ha->loop_down_timer, 0);
4003 if (!(ha->device_flags & DFLG_NO_CABLE)) {
4004 atomic_set(&ha->loop_state, LOOP_UP);
4005 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4006 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
4007 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4008
4009 rval = qla2x00_loop_resync(ha);
4010 } else
4011 atomic_set(&ha->loop_state, LOOP_DEAD);
4012
4013 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
4014 }
4015
4016 return rval;
4017}
4018
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019void
Andrew Vasquez67becc02009-08-25 11:36:20 -07004020qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004021{
4022 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07004023 struct scsi_qla_host *vha;
4024 struct qla_hw_data *ha = base_vha->hw;
4025 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004026
Arun Easifeafb7b2010-09-03 14:57:00 -07004027 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004028 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07004029 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
4030 atomic_inc(&vha->vref_count);
4031 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08004032 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07004033 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
4034 spin_unlock_irqrestore(&ha->vport_slock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07004035 qla2x00_rport_del(fcport);
Arun Easifeafb7b2010-09-03 14:57:00 -07004036 spin_lock_irqsave(&ha->vport_slock, flags);
4037 }
4038 }
4039 atomic_dec(&vha->vref_count);
4040 }
4041 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004042}
4043
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004044/* Assumes idc_lock always held on entry */
4045void
4046qla83xx_reset_ownership(scsi_qla_host_t *vha)
4047{
4048 struct qla_hw_data *ha = vha->hw;
4049 uint32_t drv_presence, drv_presence_mask;
4050 uint32_t dev_part_info1, dev_part_info2, class_type;
4051 uint32_t class_type_mask = 0x3;
4052 uint16_t fcoe_other_function = 0xffff, i;
4053
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004054 if (IS_QLA8044(ha)) {
4055 drv_presence = qla8044_rd_direct(vha,
4056 QLA8044_CRB_DRV_ACTIVE_INDEX);
4057 dev_part_info1 = qla8044_rd_direct(vha,
4058 QLA8044_CRB_DEV_PART_INFO_INDEX);
4059 dev_part_info2 = qla8044_rd_direct(vha,
4060 QLA8044_CRB_DEV_PART_INFO2);
4061 } else {
4062 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4063 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
4064 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
4065 }
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004066 for (i = 0; i < 8; i++) {
4067 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
4068 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4069 (i != ha->portnum)) {
4070 fcoe_other_function = i;
4071 break;
4072 }
4073 }
4074 if (fcoe_other_function == 0xffff) {
4075 for (i = 0; i < 8; i++) {
4076 class_type = ((dev_part_info2 >> (i * 4)) &
4077 class_type_mask);
4078 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4079 ((i + 8) != ha->portnum)) {
4080 fcoe_other_function = i + 8;
4081 break;
4082 }
4083 }
4084 }
4085 /*
4086 * Prepare drv-presence mask based on fcoe functions present.
4087 * However consider only valid physical fcoe function numbers (0-15).
4088 */
4089 drv_presence_mask = ~((1 << (ha->portnum)) |
4090 ((fcoe_other_function == 0xffff) ?
4091 0 : (1 << (fcoe_other_function))));
4092
4093 /* We are the reset owner iff:
4094 * - No other protocol drivers present.
4095 * - This is the lowest among fcoe functions. */
4096 if (!(drv_presence & drv_presence_mask) &&
4097 (ha->portnum < fcoe_other_function)) {
4098 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
4099 "This host is Reset owner.\n");
4100 ha->flags.nic_core_reset_owner = 1;
4101 }
4102}
4103
Saurav Kashyapfa492632012-11-21 02:40:29 -05004104static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004105__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
4106{
4107 int rval = QLA_SUCCESS;
4108 struct qla_hw_data *ha = vha->hw;
4109 uint32_t drv_ack;
4110
4111 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4112 if (rval == QLA_SUCCESS) {
4113 drv_ack |= (1 << ha->portnum);
4114 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4115 }
4116
4117 return rval;
4118}
4119
Saurav Kashyapfa492632012-11-21 02:40:29 -05004120static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004121__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
4122{
4123 int rval = QLA_SUCCESS;
4124 struct qla_hw_data *ha = vha->hw;
4125 uint32_t drv_ack;
4126
4127 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4128 if (rval == QLA_SUCCESS) {
4129 drv_ack &= ~(1 << ha->portnum);
4130 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4131 }
4132
4133 return rval;
4134}
4135
Saurav Kashyapfa492632012-11-21 02:40:29 -05004136static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004137qla83xx_dev_state_to_string(uint32_t dev_state)
4138{
4139 switch (dev_state) {
4140 case QLA8XXX_DEV_COLD:
4141 return "COLD/RE-INIT";
4142 case QLA8XXX_DEV_INITIALIZING:
4143 return "INITIALIZING";
4144 case QLA8XXX_DEV_READY:
4145 return "READY";
4146 case QLA8XXX_DEV_NEED_RESET:
4147 return "NEED RESET";
4148 case QLA8XXX_DEV_NEED_QUIESCENT:
4149 return "NEED QUIESCENT";
4150 case QLA8XXX_DEV_FAILED:
4151 return "FAILED";
4152 case QLA8XXX_DEV_QUIESCENT:
4153 return "QUIESCENT";
4154 default:
4155 return "Unknown";
4156 }
4157}
4158
4159/* Assumes idc-lock always held on entry */
4160void
4161qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
4162{
4163 struct qla_hw_data *ha = vha->hw;
4164 uint32_t idc_audit_reg = 0, duration_secs = 0;
4165
4166 switch (audit_type) {
4167 case IDC_AUDIT_TIMESTAMP:
4168 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
4169 idc_audit_reg = (ha->portnum) |
4170 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
4171 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4172 break;
4173
4174 case IDC_AUDIT_COMPLETION:
4175 duration_secs = ((jiffies_to_msecs(jiffies) -
4176 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
4177 idc_audit_reg = (ha->portnum) |
4178 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
4179 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4180 break;
4181
4182 default:
4183 ql_log(ql_log_warn, vha, 0xb078,
4184 "Invalid audit type specified.\n");
4185 break;
4186 }
4187}
4188
4189/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05004190static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004191qla83xx_initiating_reset(scsi_qla_host_t *vha)
4192{
4193 struct qla_hw_data *ha = vha->hw;
4194 uint32_t idc_control, dev_state;
4195
4196 __qla83xx_get_idc_control(vha, &idc_control);
4197 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
4198 ql_log(ql_log_info, vha, 0xb080,
4199 "NIC Core reset has been disabled. idc-control=0x%x\n",
4200 idc_control);
4201 return QLA_FUNCTION_FAILED;
4202 }
4203
4204 /* Set NEED-RESET iff in READY state and we are the reset-owner */
4205 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4206 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
4207 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
4208 QLA8XXX_DEV_NEED_RESET);
4209 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
4210 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
4211 } else {
4212 const char *state = qla83xx_dev_state_to_string(dev_state);
4213 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
4214
4215 /* SV: XXX: Is timeout required here? */
4216 /* Wait for IDC state change READY -> NEED_RESET */
4217 while (dev_state == QLA8XXX_DEV_READY) {
4218 qla83xx_idc_unlock(vha, 0);
4219 msleep(200);
4220 qla83xx_idc_lock(vha, 0);
4221 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4222 }
4223 }
4224
4225 /* Send IDC ack by writing to drv-ack register */
4226 __qla83xx_set_drv_ack(vha);
4227
4228 return QLA_SUCCESS;
4229}
4230
4231int
4232__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
4233{
4234 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4235}
4236
4237int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004238__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
4239{
4240 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4241}
4242
Saurav Kashyapfa492632012-11-21 02:40:29 -05004243static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004244qla83xx_check_driver_presence(scsi_qla_host_t *vha)
4245{
4246 uint32_t drv_presence = 0;
4247 struct qla_hw_data *ha = vha->hw;
4248
4249 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4250 if (drv_presence & (1 << ha->portnum))
4251 return QLA_SUCCESS;
4252 else
4253 return QLA_TEST_FAILED;
4254}
4255
4256int
4257qla83xx_nic_core_reset(scsi_qla_host_t *vha)
4258{
4259 int rval = QLA_SUCCESS;
4260 struct qla_hw_data *ha = vha->hw;
4261
4262 ql_dbg(ql_dbg_p3p, vha, 0xb058,
4263 "Entered %s().\n", __func__);
4264
4265 if (vha->device_flags & DFLG_DEV_FAILED) {
4266 ql_log(ql_log_warn, vha, 0xb059,
4267 "Device in unrecoverable FAILED state.\n");
4268 return QLA_FUNCTION_FAILED;
4269 }
4270
4271 qla83xx_idc_lock(vha, 0);
4272
4273 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
4274 ql_log(ql_log_warn, vha, 0xb05a,
4275 "Function=0x%x has been removed from IDC participation.\n",
4276 ha->portnum);
4277 rval = QLA_FUNCTION_FAILED;
4278 goto exit;
4279 }
4280
4281 qla83xx_reset_ownership(vha);
4282
4283 rval = qla83xx_initiating_reset(vha);
4284
4285 /*
4286 * Perform reset if we are the reset-owner,
4287 * else wait till IDC state changes to READY/FAILED.
4288 */
4289 if (rval == QLA_SUCCESS) {
4290 rval = qla83xx_idc_state_handler(vha);
4291
4292 if (rval == QLA_SUCCESS)
4293 ha->flags.nic_core_hung = 0;
4294 __qla83xx_clear_drv_ack(vha);
4295 }
4296
4297exit:
4298 qla83xx_idc_unlock(vha, 0);
4299
4300 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
4301
4302 return rval;
4303}
4304
Saurav Kashyap81178772012-08-22 14:21:04 -04004305int
4306qla2xxx_mctp_dump(scsi_qla_host_t *vha)
4307{
4308 struct qla_hw_data *ha = vha->hw;
4309 int rval = QLA_FUNCTION_FAILED;
4310
4311 if (!IS_MCTP_CAPABLE(ha)) {
4312 /* This message can be removed from the final version */
4313 ql_log(ql_log_info, vha, 0x506d,
4314 "This board is not MCTP capable\n");
4315 return rval;
4316 }
4317
4318 if (!ha->mctp_dump) {
4319 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
4320 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
4321
4322 if (!ha->mctp_dump) {
4323 ql_log(ql_log_warn, vha, 0x506e,
4324 "Failed to allocate memory for mctp dump\n");
4325 return rval;
4326 }
4327 }
4328
4329#define MCTP_DUMP_STR_ADDR 0x00000000
4330 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
4331 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
4332 if (rval != QLA_SUCCESS) {
4333 ql_log(ql_log_warn, vha, 0x506f,
4334 "Failed to capture mctp dump\n");
4335 } else {
4336 ql_log(ql_log_info, vha, 0x5070,
4337 "Mctp dump capture for host (%ld/%p).\n",
4338 vha->host_no, ha->mctp_dump);
4339 ha->mctp_dumped = 1;
4340 }
4341
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04004342 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04004343 ha->flags.nic_core_reset_hdlr_active = 1;
4344 rval = qla83xx_restart_nic_firmware(vha);
4345 if (rval)
4346 /* NIC Core reset failed. */
4347 ql_log(ql_log_warn, vha, 0x5071,
4348 "Failed to restart nic firmware\n");
4349 else
4350 ql_dbg(ql_dbg_p3p, vha, 0xb084,
4351 "Restarted NIC firmware successfully.\n");
4352 ha->flags.nic_core_reset_hdlr_active = 0;
4353 }
4354
4355 return rval;
4356
4357}
4358
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004359/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004360* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004361* Description: This function will block the new I/Os
4362* Its not aborting any I/Os as context
4363* is not destroyed during quiescence
4364* Arguments: scsi_qla_host_t
4365* return : void
4366*/
4367void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004368qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004369{
4370 struct qla_hw_data *ha = vha->hw;
4371 struct scsi_qla_host *vp;
4372
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004373 ql_dbg(ql_dbg_dpc, vha, 0x401d,
4374 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004375
4376 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4377 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4378 atomic_set(&vha->loop_state, LOOP_DOWN);
4379 qla2x00_mark_all_devices_lost(vha, 0);
4380 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004381 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004382 } else {
4383 if (!atomic_read(&vha->loop_down_timer))
4384 atomic_set(&vha->loop_down_timer,
4385 LOOP_DOWN_TIME);
4386 }
4387 /* Wait for pending cmds to complete */
4388 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
4389}
4390
Giridhar Malavalia9083012010-04-12 17:59:55 -07004391void
4392qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
4393{
4394 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004395 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07004396 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004397 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004398
Saurav Kashyape46ef002011-02-23 15:27:16 -08004399 /* For ISP82XX, driver waits for completion of the commands.
4400 * online flag should be set.
4401 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004402 if (!(IS_P3P_TYPE(ha)))
Saurav Kashyape46ef002011-02-23 15:27:16 -08004403 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004404 ha->flags.chip_reset_done = 0;
4405 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04004406 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004407
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004408 ql_log(ql_log_info, vha, 0x00af,
4409 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004410
Saurav Kashyape46ef002011-02-23 15:27:16 -08004411 /* For ISP82XX, reset_chip is just disabling interrupts.
4412 * Driver waits for the completion of the commands.
4413 * the interrupts need to be enabled.
4414 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004415 if (!(IS_P3P_TYPE(ha)))
Giridhar Malavalia9083012010-04-12 17:59:55 -07004416 ha->isp_ops->reset_chip(vha);
4417
4418 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
4419 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4420 atomic_set(&vha->loop_state, LOOP_DOWN);
4421 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004422
4423 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004424 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07004425 atomic_inc(&vp->vref_count);
4426 spin_unlock_irqrestore(&ha->vport_slock, flags);
4427
Giridhar Malavalia9083012010-04-12 17:59:55 -07004428 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004429
4430 spin_lock_irqsave(&ha->vport_slock, flags);
4431 atomic_dec(&vp->vref_count);
4432 }
4433 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004434 } else {
4435 if (!atomic_read(&vha->loop_down_timer))
4436 atomic_set(&vha->loop_down_timer,
4437 LOOP_DOWN_TIME);
4438 }
4439
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004440 /* Clear all async request states across all VPs. */
4441 list_for_each_entry(fcport, &vha->vp_fcports, list)
4442 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4443 spin_lock_irqsave(&ha->vport_slock, flags);
4444 list_for_each_entry(vp, &ha->vp_list, list) {
4445 atomic_inc(&vp->vref_count);
4446 spin_unlock_irqrestore(&ha->vport_slock, flags);
4447
4448 list_for_each_entry(fcport, &vp->vp_fcports, list)
4449 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4450
4451 spin_lock_irqsave(&ha->vport_slock, flags);
4452 atomic_dec(&vp->vref_count);
4453 }
4454 spin_unlock_irqrestore(&ha->vport_slock, flags);
4455
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004456 if (!ha->flags.eeh_busy) {
4457 /* Make sure for ISP 82XX IO DMA is complete */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004458 if (IS_P3P_TYPE(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004459 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004460 ql_log(ql_log_info, vha, 0x00b4,
4461 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004462
Saurav Kashyape46ef002011-02-23 15:27:16 -08004463 /* Done waiting for pending commands.
4464 * Reset the online flag.
4465 */
4466 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004467 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004469 /* Requeue all commands in outstanding command list. */
4470 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4471 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472}
4473
4474/*
4475* qla2x00_abort_isp
4476* Resets ISP and aborts all outstanding commands.
4477*
4478* Input:
4479* ha = adapter block pointer.
4480*
4481* Returns:
4482* 0 = success
4483*/
4484int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004485qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004486{
Andrew Vasquez476e8972006-08-23 14:54:55 -07004487 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004488 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004489 struct qla_hw_data *ha = vha->hw;
4490 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004491 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07004492 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004493
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004494 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004495 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496
Santosh Vernekara61712972012-08-22 14:21:13 -04004497 if (IS_QLA8031(ha)) {
4498 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
4499 "Clearing fcoe driver presence.\n");
4500 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
4501 ql_dbg(ql_dbg_p3p, vha, 0xb073,
4502 "Error while clearing DRV-Presence.\n");
4503 }
4504
Andrew Vasquez85880802009-12-15 21:29:46 -08004505 if (unlikely(pci_channel_offline(ha->pdev) &&
4506 ha->flags.pci_channel_io_perm_failure)) {
4507 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4508 status = 0;
4509 return status;
4510 }
4511
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004512 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08004513
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004514 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004516 if (!qla2x00_restart_isp(vha)) {
4517 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004518
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004519 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004520 /*
4521 * Issue marker command only when we are going
4522 * to start the I/O .
4523 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004524 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 }
4526
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004527 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004528
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004529 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004531 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004532 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07004533
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004534 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
4535 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004536 if (ha->fce) {
4537 ha->flags.fce_enabled = 1;
4538 memset(ha->fce, 0,
4539 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004540 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004541 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4542 &ha->fce_bufs);
4543 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004544 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004545 "Unable to reinitialize FCE "
4546 "(%d).\n", rval);
4547 ha->flags.fce_enabled = 0;
4548 }
4549 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004550
4551 if (ha->eft) {
4552 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004553 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004554 ha->eft_dma, EFT_NUM_BUFFERS);
4555 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004556 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004557 "Unable to reinitialize EFT "
4558 "(%d).\n", rval);
4559 }
4560 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004561 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004562 vha->flags.online = 1;
4563 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004564 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004565 ql_log(ql_log_fatal, vha, 0x8035,
4566 "ISP error recover failed - "
4567 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004568 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004569 * The next call disables the board
4570 * completely.
4571 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004572 ha->isp_ops->reset_adapter(vha);
4573 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004575 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576 status = 0;
4577 } else { /* schedule another ISP abort */
4578 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004579 ql_dbg(ql_dbg_taskm, vha, 0x8020,
4580 "ISP abort - retry remaining %d.\n",
4581 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582 status = 1;
4583 }
4584 } else {
4585 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004586 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4587 "ISP error recovery - retrying (%d) "
4588 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004589 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590 status = 1;
4591 }
4592 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004593
Linus Torvalds1da177e2005-04-16 15:20:36 -07004594 }
4595
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004596 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004597 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07004598
4599 spin_lock_irqsave(&ha->vport_slock, flags);
4600 list_for_each_entry(vp, &ha->vp_list, list) {
4601 if (vp->vp_idx) {
4602 atomic_inc(&vp->vref_count);
4603 spin_unlock_irqrestore(&ha->vport_slock, flags);
4604
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004605 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004606
4607 spin_lock_irqsave(&ha->vport_slock, flags);
4608 atomic_dec(&vp->vref_count);
4609 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004610 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004611 spin_unlock_irqrestore(&ha->vport_slock, flags);
4612
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004613 if (IS_QLA8031(ha)) {
4614 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
4615 "Setting back fcoe driver presence.\n");
4616 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
4617 ql_dbg(ql_dbg_p3p, vha, 0xb074,
4618 "Error while setting DRV-Presence.\n");
4619 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004620 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08004621 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
4622 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004623 }
4624
4625 return(status);
4626}
4627
4628/*
4629* qla2x00_restart_isp
4630* restarts the ISP after a reset
4631*
4632* Input:
4633* ha = adapter block pointer.
4634*
4635* Returns:
4636* 0 = success
4637*/
4638static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004639qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004641 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004643 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004644 struct req_que *req = ha->req_q_map[0];
4645 struct rsp_que *rsp = ha->rsp_q_map[0];
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004646 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647
4648 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004649 if (qla2x00_isp_firmware(vha)) {
4650 vha->flags.online = 0;
4651 status = ha->isp_ops->chip_diag(vha);
4652 if (!status)
4653 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004654 }
4655
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004656 if (!status && !(status = qla2x00_init_rings(vha))) {
4657 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004658 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004659 /* Initialize the queues in use */
4660 qla25xx_init_queues(ha);
4661
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004662 status = qla2x00_fw_ready(vha);
4663 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004664 ql_dbg(ql_dbg_taskm, vha, 0x8031,
4665 "Start configure loop status = %d.\n", status);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004666
4667 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004668 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004669
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004670 vha->flags.online = 1;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004671
4672 /*
4673 * Process any ATIO queue entries that came in
4674 * while we weren't online.
4675 */
4676 spin_lock_irqsave(&ha->hardware_lock, flags);
4677 if (qla_tgt_mode_enabled(vha))
4678 qlt_24xx_process_atio_queue(vha);
4679 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4680
Linus Torvalds1da177e2005-04-16 15:20:36 -07004681 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4682 wait_time = 256;
4683 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004684 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4685 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004686 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004687 } while (!atomic_read(&vha->loop_down_timer) &&
4688 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4689 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4690 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004691 }
4692
4693 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004694 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004695 status = 0;
4696
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004697 ql_dbg(ql_dbg_taskm, vha, 0x8032,
4698 "Configure loop done, status = 0x%x.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004699 }
4700 return (status);
4701}
4702
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004703static int
4704qla25xx_init_queues(struct qla_hw_data *ha)
4705{
4706 struct rsp_que *rsp = NULL;
4707 struct req_que *req = NULL;
4708 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4709 int ret = -1;
4710 int i;
4711
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004712 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004713 rsp = ha->rsp_q_map[i];
4714 if (rsp) {
4715 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004716 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004717 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004718 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4719 "%s Rsp que: %d init failed.\n",
4720 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004721 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004722 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4723 "%s Rsp que: %d inited.\n",
4724 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004725 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004726 }
4727 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004728 req = ha->req_q_map[i];
4729 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004730 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004731 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004732 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004733 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004734 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4735 "%s Req que: %d init failed.\n",
4736 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004737 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004738 ql_dbg(ql_dbg_init, base_vha, 0x0102,
4739 "%s Req que: %d inited.\n",
4740 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004741 }
4742 }
4743 return ret;
4744}
4745
Linus Torvalds1da177e2005-04-16 15:20:36 -07004746/*
4747* qla2x00_reset_adapter
4748* Reset adapter.
4749*
4750* Input:
4751* ha = adapter block pointer.
4752*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004753void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004754qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755{
4756 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004757 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004758 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004760 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004761 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762
Linus Torvalds1da177e2005-04-16 15:20:36 -07004763 spin_lock_irqsave(&ha->hardware_lock, flags);
4764 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4765 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4766 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4767 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4768 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4769}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004770
4771void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004772qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004773{
4774 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004775 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004776 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4777
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004778 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07004779 return;
4780
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004781 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004782 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004783
4784 spin_lock_irqsave(&ha->hardware_lock, flags);
4785 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4786 RD_REG_DWORD(&reg->hccr);
4787 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4788 RD_REG_DWORD(&reg->hccr);
4789 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004790
4791 if (IS_NOPOLLING_TYPE(ha))
4792 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004793}
4794
David Miller4e08df32007-04-16 12:37:43 -07004795/* On sparc systems, obtain port and node WWN from firmware
4796 * properties.
4797 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004798static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4799 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004800{
4801#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004802 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004803 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004804 struct device_node *dp = pci_device_to_OF_node(pdev);
4805 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004806 int len;
4807
4808 val = of_get_property(dp, "port-wwn", &len);
4809 if (val && len >= WWN_SIZE)
4810 memcpy(nv->port_name, val, WWN_SIZE);
4811
4812 val = of_get_property(dp, "node-wwn", &len);
4813 if (val && len >= WWN_SIZE)
4814 memcpy(nv->node_name, val, WWN_SIZE);
4815#endif
4816}
4817
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004818int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004819qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004820{
David Miller4e08df32007-04-16 12:37:43 -07004821 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004822 struct init_cb_24xx *icb;
4823 struct nvram_24xx *nv;
4824 uint32_t *dptr;
4825 uint8_t *dptr1, *dptr2;
4826 uint32_t chksum;
4827 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004828 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004829
David Miller4e08df32007-04-16 12:37:43 -07004830 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004831 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004832 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004833
4834 /* Determine NVRAM starting address. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05004835 if (ha->port_no == 0) {
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004836 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4837 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4838 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004839 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004840 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4841 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05004842
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004843 ha->nvram_size = sizeof(struct nvram_24xx);
4844 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004845
Seokmann Ju281afe12007-07-26 13:43:34 -07004846 /* Get VPD data into cache */
4847 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004848 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004849 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4850
4851 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004852 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004853 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004854 ha->nvram_size);
4855 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4856 chksum += le32_to_cpu(*dptr++);
4857
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004858 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
4859 "Contents of NVRAM\n");
4860 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
4861 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004862
4863 /* Bad NVRAM data, set defaults parameters. */
4864 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4865 || nv->id[3] != ' ' ||
4866 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4867 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004868 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04004869 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004870 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
4871 ql_log(ql_log_warn, vha, 0x006c,
4872 "Falling back to functioning (yet invalid -- WWPN) "
4873 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07004874
4875 /*
4876 * Set default initialization control block.
4877 */
4878 memset(nv, 0, ha->nvram_size);
4879 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4880 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4881 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4882 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4883 nv->exchange_count = __constant_cpu_to_le16(0);
4884 nv->hard_address = __constant_cpu_to_le16(124);
4885 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004886 nv->port_name[1] = 0x00 + ha->port_no + 1;
David Miller4e08df32007-04-16 12:37:43 -07004887 nv->port_name[2] = 0x00;
4888 nv->port_name[3] = 0xe0;
4889 nv->port_name[4] = 0x8b;
4890 nv->port_name[5] = 0x1c;
4891 nv->port_name[6] = 0x55;
4892 nv->port_name[7] = 0x86;
4893 nv->node_name[0] = 0x20;
4894 nv->node_name[1] = 0x00;
4895 nv->node_name[2] = 0x00;
4896 nv->node_name[3] = 0xe0;
4897 nv->node_name[4] = 0x8b;
4898 nv->node_name[5] = 0x1c;
4899 nv->node_name[6] = 0x55;
4900 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004901 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004902 nv->login_retry_count = __constant_cpu_to_le16(8);
4903 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4904 nv->login_timeout = __constant_cpu_to_le16(0);
4905 nv->firmware_options_1 =
4906 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4907 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4908 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4909 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4910 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4911 nv->efi_parameters = __constant_cpu_to_le32(0);
4912 nv->reset_delay = 5;
4913 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4914 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4915 nv->link_down_timeout = __constant_cpu_to_le16(30);
4916
4917 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004918 }
4919
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004920 if (!qla_ini_mode_enabled(vha)) {
4921 /* Don't enable full login after initial LIP */
4922 nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13);
4923 /* Don't enable LIP full login for initiator */
4924 nv->host_p &= __constant_cpu_to_le32(~BIT_10);
4925 }
4926
4927 qlt_24xx_config_nvram_stage1(vha, nv);
4928
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004929 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004930 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004931
4932 /* Copy 1st segment. */
4933 dptr1 = (uint8_t *)icb;
4934 dptr2 = (uint8_t *)&nv->version;
4935 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4936 while (cnt--)
4937 *dptr1++ = *dptr2++;
4938
4939 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004940 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004941
4942 /* Copy 2nd segment. */
4943 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4944 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4945 cnt = (uint8_t *)&icb->reserved_3 -
4946 (uint8_t *)&icb->interrupt_delay_timer;
4947 while (cnt--)
4948 *dptr1++ = *dptr2++;
4949
4950 /*
4951 * Setup driver NVRAM options.
4952 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004953 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004954 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004955
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004956 qlt_24xx_config_nvram_stage2(vha, icb);
4957
Andrew Vasquez5341e862006-05-17 15:09:16 -07004958 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004959 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07004960 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4961 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4962 }
4963
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004964 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004965 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004966 /*
4967 * Firmware will apply the following mask if the nodename was
4968 * not provided.
4969 */
4970 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4971 icb->node_name[0] &= 0xF0;
4972 }
4973
4974 /* Set host adapter parameters. */
4975 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004976 ha->flags.enable_lip_reset = 0;
4977 ha->flags.enable_lip_full_login =
4978 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4979 ha->flags.enable_target_reset =
4980 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004981 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004982 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004983
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004984 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4985 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004986
4987 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4988 sizeof(ha->fw_seriallink_options24));
4989
4990 /* save HBA serial number */
4991 ha->serial0 = icb->port_name[5];
4992 ha->serial1 = icb->port_name[6];
4993 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004994 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4995 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004996
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004997 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4998
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004999 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5000
5001 /* Set minimum login_timeout to 4 seconds. */
5002 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5003 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5004 if (le16_to_cpu(nv->login_timeout) < 4)
5005 nv->login_timeout = __constant_cpu_to_le16(4);
5006 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07005007 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005008
Andrew Vasquez00a537b2008-02-28 14:06:11 -08005009 /* Set minimum RATOV to 100 tenths of a second. */
5010 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005011
5012 ha->loop_reset_delay = nv->reset_delay;
5013
5014 /* Link Down Timeout = 0:
5015 *
5016 * When Port Down timer expires we will start returning
5017 * I/O's to OS with "DID_NO_CONNECT".
5018 *
5019 * Link Down Timeout != 0:
5020 *
5021 * The driver waits for the link to come up after link down
5022 * before returning I/Os to OS with "DID_NO_CONNECT".
5023 */
5024 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5025 ha->loop_down_abort_time =
5026 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5027 } else {
5028 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5029 ha->loop_down_abort_time =
5030 (LOOP_DOWN_TIME - ha->link_down_timeout);
5031 }
5032
5033 /* Need enough time to try and get the port back. */
5034 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5035 if (qlport_down_retry)
5036 ha->port_down_retry_count = qlport_down_retry;
5037
5038 /* Set login_retry_count */
5039 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5040 if (ha->port_down_retry_count ==
5041 le16_to_cpu(nv->port_down_retry_count) &&
5042 ha->port_down_retry_count > 3)
5043 ha->login_retry_count = ha->port_down_retry_count;
5044 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5045 ha->login_retry_count = ha->port_down_retry_count;
5046 if (ql2xloginretrycount)
5047 ha->login_retry_count = ql2xloginretrycount;
5048
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005049 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005050 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005051 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5052 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5053 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5054 le16_to_cpu(icb->interrupt_delay_timer): 2;
5055 }
5056 icb->firmware_options_2 &= __constant_cpu_to_le32(
5057 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005058 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005059 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08005060 ha->zio_mode = QLA_ZIO_MODE_6;
5061
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005062 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005063 "ZIO mode %d enabled; timer delay (%d us).\n",
5064 ha->zio_mode, ha->zio_timer * 100);
5065
5066 icb->firmware_options_2 |= cpu_to_le32(
5067 (uint32_t)ha->zio_mode);
5068 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005069 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005070 }
5071
David Miller4e08df32007-04-16 12:37:43 -07005072 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005073 ql_log(ql_log_warn, vha, 0x0070,
5074 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07005075 }
5076 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005077}
5078
Adrian Bunk413975a2006-06-30 02:33:06 -07005079static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005080qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
5081 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005082{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005083 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005084 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005085 uint32_t *dcode, dlen;
5086 uint32_t risc_addr;
5087 uint32_t risc_size;
5088 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005089 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005090 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005091
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005092 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08005093 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005094
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005095 rval = QLA_SUCCESS;
5096
5097 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005098 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005099 *srisc_addr = 0;
5100
5101 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005102 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005103 for (i = 0; i < 4; i++)
5104 dcode[i] = be32_to_cpu(dcode[i]);
5105 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5106 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5107 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5108 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005109 ql_log(ql_log_fatal, vha, 0x008c,
5110 "Unable to verify the integrity of flash firmware "
5111 "image.\n");
5112 ql_log(ql_log_fatal, vha, 0x008d,
5113 "Firmware data: %08x %08x %08x %08x.\n",
5114 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005115
5116 return QLA_FUNCTION_FAILED;
5117 }
5118
5119 while (segments && rval == QLA_SUCCESS) {
5120 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005121 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005122
5123 risc_addr = be32_to_cpu(dcode[2]);
5124 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5125 risc_size = be32_to_cpu(dcode[3]);
5126
5127 fragment = 0;
5128 while (risc_size > 0 && rval == QLA_SUCCESS) {
5129 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5130 if (dlen > risc_size)
5131 dlen = risc_size;
5132
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005133 ql_dbg(ql_dbg_init, vha, 0x008e,
5134 "Loading risc segment@ risc addr %x "
5135 "number of dwords 0x%x offset 0x%x.\n",
5136 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005137
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005138 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005139 for (i = 0; i < dlen; i++)
5140 dcode[i] = swab32(dcode[i]);
5141
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005142 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005143 dlen);
5144 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005145 ql_log(ql_log_fatal, vha, 0x008f,
5146 "Failed to load segment %d of firmware.\n",
5147 fragment);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005148 break;
5149 }
5150
5151 faddr += dlen;
5152 risc_addr += dlen;
5153 risc_size -= dlen;
5154 fragment++;
5155 }
5156
5157 /* Next segment. */
5158 segments--;
5159 }
5160
Chad Dupuisf73cb692014-02-26 04:15:06 -05005161 if (!IS_QLA27XX(ha))
5162 return rval;
5163
5164 if (ha->fw_dump_template)
5165 vfree(ha->fw_dump_template);
5166 ha->fw_dump_template = NULL;
5167 ha->fw_dump_template_len = 0;
5168
5169 ql_dbg(ql_dbg_init, vha, 0x0161,
5170 "Loading fwdump template from %x\n", faddr);
5171 qla24xx_read_flash_data(vha, dcode, faddr, 7);
5172 risc_size = be32_to_cpu(dcode[2]);
5173 ql_dbg(ql_dbg_init, vha, 0x0162,
5174 "-> array size %x dwords\n", risc_size);
5175 if (risc_size == 0 || risc_size == ~0)
5176 goto default_template;
5177
5178 dlen = (risc_size - 8) * sizeof(*dcode);
5179 ql_dbg(ql_dbg_init, vha, 0x0163,
5180 "-> template allocating %x bytes...\n", dlen);
5181 ha->fw_dump_template = vmalloc(dlen);
5182 if (!ha->fw_dump_template) {
5183 ql_log(ql_log_warn, vha, 0x0164,
5184 "Failed fwdump template allocate %x bytes.\n", risc_size);
5185 goto default_template;
5186 }
5187
5188 faddr += 7;
5189 risc_size -= 8;
5190 dcode = ha->fw_dump_template;
5191 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
5192 for (i = 0; i < risc_size; i++)
5193 dcode[i] = le32_to_cpu(dcode[i]);
5194
5195 if (!qla27xx_fwdt_template_valid(dcode)) {
5196 ql_log(ql_log_warn, vha, 0x0165,
5197 "Failed fwdump template validate\n");
5198 goto default_template;
5199 }
5200
5201 dlen = qla27xx_fwdt_template_size(dcode);
5202 ql_dbg(ql_dbg_init, vha, 0x0166,
5203 "-> template size %x bytes\n", dlen);
5204 if (dlen > risc_size * sizeof(*dcode)) {
5205 ql_log(ql_log_warn, vha, 0x0167,
5206 "Failed fwdump template exceeds array by %lx bytes\n",
5207 dlen - risc_size * sizeof(*dcode));
5208 goto default_template;
5209 }
5210 ha->fw_dump_template_len = dlen;
5211 return rval;
5212
5213default_template:
5214 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
5215 if (ha->fw_dump_template)
5216 vfree(ha->fw_dump_template);
5217 ha->fw_dump_template = NULL;
5218 ha->fw_dump_template_len = 0;
5219
5220 dlen = qla27xx_fwdt_template_default_size();
5221 ql_dbg(ql_dbg_init, vha, 0x0169,
5222 "-> template allocating %x bytes...\n", dlen);
5223 ha->fw_dump_template = vmalloc(dlen);
5224 if (!ha->fw_dump_template) {
5225 ql_log(ql_log_warn, vha, 0x016a,
5226 "Failed fwdump template allocate %x bytes.\n", risc_size);
5227 goto failed_template;
5228 }
5229
5230 dcode = ha->fw_dump_template;
5231 risc_size = dlen / sizeof(*dcode);
5232 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
5233 for (i = 0; i < risc_size; i++)
5234 dcode[i] = be32_to_cpu(dcode[i]);
5235
5236 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5237 ql_log(ql_log_warn, vha, 0x016b,
5238 "Failed fwdump template validate\n");
5239 goto failed_template;
5240 }
5241
5242 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5243 ql_dbg(ql_dbg_init, vha, 0x016c,
5244 "-> template size %x bytes\n", dlen);
5245 ha->fw_dump_template_len = dlen;
5246 return rval;
5247
5248failed_template:
5249 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
5250 if (ha->fw_dump_template)
5251 vfree(ha->fw_dump_template);
5252 ha->fw_dump_template = NULL;
5253 ha->fw_dump_template_len = 0;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005254 return rval;
5255}
5256
Giridhar Malavalie9454a82013-02-08 01:57:47 -05005257#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005258
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005259int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005260qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08005261{
5262 int rval;
5263 int i, fragment;
5264 uint16_t *wcode, *fwcode;
5265 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
5266 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005267 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005268 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08005269
5270 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005271 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005272 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005273 ql_log(ql_log_info, vha, 0x0083,
5274 "Fimware image unavailable.\n");
5275 ql_log(ql_log_info, vha, 0x0084,
5276 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08005277 return QLA_FUNCTION_FAILED;
5278 }
5279
5280 rval = QLA_SUCCESS;
5281
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005282 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08005283 *srisc_addr = 0;
5284 fwcode = (uint16_t *)blob->fw->data;
5285 fwclen = 0;
5286
5287 /* Validate firmware image by checking version. */
5288 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005289 ql_log(ql_log_fatal, vha, 0x0085,
5290 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005291 blob->fw->size);
5292 goto fail_fw_integrity;
5293 }
5294 for (i = 0; i < 4; i++)
5295 wcode[i] = be16_to_cpu(fwcode[i + 4]);
5296 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
5297 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
5298 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005299 ql_log(ql_log_fatal, vha, 0x0086,
5300 "Unable to verify integrity of firmware image.\n");
5301 ql_log(ql_log_fatal, vha, 0x0087,
5302 "Firmware data: %04x %04x %04x %04x.\n",
5303 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08005304 goto fail_fw_integrity;
5305 }
5306
5307 seg = blob->segs;
5308 while (*seg && rval == QLA_SUCCESS) {
5309 risc_addr = *seg;
5310 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
5311 risc_size = be16_to_cpu(fwcode[3]);
5312
5313 /* Validate firmware image size. */
5314 fwclen += risc_size * sizeof(uint16_t);
5315 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005316 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08005317 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005318 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08005319 goto fail_fw_integrity;
5320 }
5321
5322 fragment = 0;
5323 while (risc_size > 0 && rval == QLA_SUCCESS) {
5324 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
5325 if (wlen > risc_size)
5326 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005327 ql_dbg(ql_dbg_init, vha, 0x0089,
5328 "Loading risc segment@ risc addr %x number of "
5329 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08005330
5331 for (i = 0; i < wlen; i++)
5332 wcode[i] = swab16(fwcode[i]);
5333
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005334 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08005335 wlen);
5336 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005337 ql_log(ql_log_fatal, vha, 0x008a,
5338 "Failed to load segment %d of firmware.\n",
5339 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08005340 break;
5341 }
5342
5343 fwcode += wlen;
5344 risc_addr += wlen;
5345 risc_size -= wlen;
5346 fragment++;
5347 }
5348
5349 /* Next segment. */
5350 seg++;
5351 }
5352 return rval;
5353
5354fail_fw_integrity:
5355 return QLA_FUNCTION_FAILED;
5356}
5357
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005358static int
5359qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005360{
5361 int rval;
5362 int segments, fragment;
5363 uint32_t *dcode, dlen;
5364 uint32_t risc_addr;
5365 uint32_t risc_size;
5366 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08005367 struct fw_blob *blob;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005368 const uint32_t *fwcode;
5369 uint32_t fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005370 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005371 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005372
Andrew Vasquez54333832005-11-09 15:49:04 -08005373 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005374 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005375 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005376 ql_log(ql_log_warn, vha, 0x0090,
5377 "Fimware image unavailable.\n");
5378 ql_log(ql_log_warn, vha, 0x0091,
5379 "Firmware images can be retrieved from: "
5380 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005381
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005382 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005383 }
5384
Chad Dupuiscfb09192011-11-18 09:03:07 -08005385 ql_dbg(ql_dbg_init, vha, 0x0092,
5386 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005387
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005388 rval = QLA_SUCCESS;
5389
5390 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005391 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005392 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08005393 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005394 fwclen = 0;
5395
5396 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08005397 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005398 ql_log(ql_log_fatal, vha, 0x0093,
5399 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005400 blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005401 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005402 }
5403 for (i = 0; i < 4; i++)
5404 dcode[i] = be32_to_cpu(fwcode[i + 4]);
5405 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5406 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5407 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5408 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005409 ql_log(ql_log_fatal, vha, 0x0094,
5410 "Unable to verify integrity of firmware image (%Zd).\n",
5411 blob->fw->size);
5412 ql_log(ql_log_fatal, vha, 0x0095,
5413 "Firmware data: %08x %08x %08x %08x.\n",
5414 dcode[0], dcode[1], dcode[2], dcode[3]);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005415 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005416 }
5417
5418 while (segments && rval == QLA_SUCCESS) {
5419 risc_addr = be32_to_cpu(fwcode[2]);
5420 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5421 risc_size = be32_to_cpu(fwcode[3]);
5422
5423 /* Validate firmware image size. */
5424 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08005425 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005426 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08005427 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005428 "(%Zd).\n", blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005429 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005430 }
5431
5432 fragment = 0;
5433 while (risc_size > 0 && rval == QLA_SUCCESS) {
5434 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5435 if (dlen > risc_size)
5436 dlen = risc_size;
5437
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005438 ql_dbg(ql_dbg_init, vha, 0x0097,
5439 "Loading risc segment@ risc addr %x "
5440 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005441
5442 for (i = 0; i < dlen; i++)
5443 dcode[i] = swab32(fwcode[i]);
5444
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005445 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08005446 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005447 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005448 ql_log(ql_log_fatal, vha, 0x0098,
5449 "Failed to load segment %d of firmware.\n",
5450 fragment);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005451 break;
5452 }
5453
5454 fwcode += dlen;
5455 risc_addr += dlen;
5456 risc_size -= dlen;
5457 fragment++;
5458 }
5459
5460 /* Next segment. */
5461 segments--;
5462 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05005463
5464 if (!IS_QLA27XX(ha))
5465 return rval;
5466
5467 if (ha->fw_dump_template)
5468 vfree(ha->fw_dump_template);
5469 ha->fw_dump_template = NULL;
5470 ha->fw_dump_template_len = 0;
5471
5472 ql_dbg(ql_dbg_init, vha, 0x171,
5473 "Loading fwdump template from %lx\n",
5474 (void *)fwcode - (void *)blob->fw->data);
5475 risc_size = be32_to_cpu(fwcode[2]);
5476 ql_dbg(ql_dbg_init, vha, 0x172,
5477 "-> array size %x dwords\n", risc_size);
5478 if (risc_size == 0 || risc_size == ~0)
5479 goto default_template;
5480
5481 dlen = (risc_size - 8) * sizeof(*fwcode);
5482 ql_dbg(ql_dbg_init, vha, 0x0173,
5483 "-> template allocating %x bytes...\n", dlen);
5484 ha->fw_dump_template = vmalloc(dlen);
5485 if (!ha->fw_dump_template) {
5486 ql_log(ql_log_warn, vha, 0x0174,
5487 "Failed fwdump template allocate %x bytes.\n", risc_size);
5488 goto default_template;
5489 }
5490
5491 fwcode += 7;
5492 risc_size -= 8;
5493 dcode = ha->fw_dump_template;
5494 for (i = 0; i < risc_size; i++)
5495 dcode[i] = le32_to_cpu(fwcode[i]);
5496
5497 if (!qla27xx_fwdt_template_valid(dcode)) {
5498 ql_log(ql_log_warn, vha, 0x0175,
5499 "Failed fwdump template validate\n");
5500 goto default_template;
5501 }
5502
5503 dlen = qla27xx_fwdt_template_size(dcode);
5504 ql_dbg(ql_dbg_init, vha, 0x0176,
5505 "-> template size %x bytes\n", dlen);
5506 if (dlen > risc_size * sizeof(*fwcode)) {
5507 ql_log(ql_log_warn, vha, 0x0177,
5508 "Failed fwdump template exceeds array by %lx bytes\n",
5509 dlen - risc_size * sizeof(*fwcode));
5510 goto default_template;
5511 }
5512 ha->fw_dump_template_len = dlen;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005513 return rval;
5514
Chad Dupuisf73cb692014-02-26 04:15:06 -05005515default_template:
5516 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
5517 if (ha->fw_dump_template)
5518 vfree(ha->fw_dump_template);
5519 ha->fw_dump_template = NULL;
5520 ha->fw_dump_template_len = 0;
5521
5522 dlen = qla27xx_fwdt_template_default_size();
5523 ql_dbg(ql_dbg_init, vha, 0x0179,
5524 "-> template allocating %x bytes...\n", dlen);
5525 ha->fw_dump_template = vmalloc(dlen);
5526 if (!ha->fw_dump_template) {
5527 ql_log(ql_log_warn, vha, 0x017a,
5528 "Failed fwdump template allocate %x bytes.\n", risc_size);
5529 goto failed_template;
5530 }
5531
5532 dcode = ha->fw_dump_template;
5533 risc_size = dlen / sizeof(*fwcode);
5534 fwcode = qla27xx_fwdt_template_default();
5535 for (i = 0; i < risc_size; i++)
5536 dcode[i] = be32_to_cpu(fwcode[i]);
5537
5538 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5539 ql_log(ql_log_warn, vha, 0x017b,
5540 "Failed fwdump template validate\n");
5541 goto failed_template;
5542 }
5543
5544 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5545 ql_dbg(ql_dbg_init, vha, 0x017c,
5546 "-> template size %x bytes\n", dlen);
5547 ha->fw_dump_template_len = dlen;
5548 return rval;
5549
5550failed_template:
5551 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
5552 if (ha->fw_dump_template)
5553 vfree(ha->fw_dump_template);
5554 ha->fw_dump_template = NULL;
5555 ha->fw_dump_template_len = 0;
5556 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005557}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005558
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005559int
5560qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5561{
5562 int rval;
5563
Andrew Vasqueze337d902009-04-06 22:33:49 -07005564 if (ql2xfwloadbin == 1)
5565 return qla81xx_load_risc(vha, srisc_addr);
5566
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005567 /*
5568 * FW Load priority:
5569 * 1) Firmware via request-firmware interface (.bin file).
5570 * 2) Firmware residing in flash.
5571 */
5572 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5573 if (rval == QLA_SUCCESS)
5574 return rval;
5575
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005576 return qla24xx_load_risc_flash(vha, srisc_addr,
5577 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005578}
5579
5580int
5581qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5582{
5583 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005584 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005585
Andrew Vasqueze337d902009-04-06 22:33:49 -07005586 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005587 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07005588
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005589 /*
5590 * FW Load priority:
5591 * 1) Firmware residing in flash.
5592 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005593 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005594 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005595 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005596 if (rval == QLA_SUCCESS)
5597 return rval;
5598
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005599try_blob_fw:
5600 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5601 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
5602 return rval;
5603
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005604 ql_log(ql_log_info, vha, 0x0099,
5605 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005606 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
5607 if (rval != QLA_SUCCESS)
5608 return rval;
5609
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005610 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005611 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005612 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005613}
5614
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005615void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005616qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005617{
5618 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005619 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005620
Andrew Vasquez85880802009-12-15 21:29:46 -08005621 if (ha->flags.pci_channel_io_perm_failure)
5622 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07005623 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005624 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07005625 if (!ha->fw_major_version)
5626 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005627
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005628 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08005629 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07005630 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005631 ha->isp_ops->reset_chip(vha);
5632 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005633 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005634 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005635 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005636 ql_log(ql_log_info, vha, 0x8015,
5637 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005638 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005639 }
5640}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005641
5642int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005643qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005644{
5645 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08005646 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005647 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005648 struct qla_hw_data *ha = vha->hw;
5649 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005650 struct req_que *req;
5651 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005652
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005653 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005654 return -EINVAL;
5655
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005656 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07005657 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005658 req = ha->req_q_map[0];
5659 else
5660 req = vha->req;
5661 rsp = req->rsp;
5662
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005663 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005664 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005665 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005666 }
5667
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005668 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005669
5670 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08005671 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
5672 BIT_1);
5673 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5674 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
5675 ql_dbg(ql_dbg_init, vha, 0x0120,
5676 "Failed SNS login: loop_id=%x, rval2=%d\n",
5677 NPH_SNS, rval2);
5678 else
5679 ql_dbg(ql_dbg_init, vha, 0x0103,
5680 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5681 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
5682 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005683 return (QLA_FUNCTION_FAILED);
5684 }
5685
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005686 atomic_set(&vha->loop_down_timer, 0);
5687 atomic_set(&vha->loop_state, LOOP_UP);
5688 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5689 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5690 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005691
5692 return rval;
5693}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005694
5695/* 84XX Support **************************************************************/
5696
5697static LIST_HEAD(qla_cs84xx_list);
5698static DEFINE_MUTEX(qla_cs84xx_mutex);
5699
5700static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005701qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005702{
5703 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005704 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005705
5706 mutex_lock(&qla_cs84xx_mutex);
5707
5708 /* Find any shared 84xx chip. */
5709 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5710 if (cs84xx->bus == ha->pdev->bus) {
5711 kref_get(&cs84xx->kref);
5712 goto done;
5713 }
5714 }
5715
5716 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5717 if (!cs84xx)
5718 goto done;
5719
5720 kref_init(&cs84xx->kref);
5721 spin_lock_init(&cs84xx->access_lock);
5722 mutex_init(&cs84xx->fw_update_mutex);
5723 cs84xx->bus = ha->pdev->bus;
5724
5725 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5726done:
5727 mutex_unlock(&qla_cs84xx_mutex);
5728 return cs84xx;
5729}
5730
5731static void
5732__qla84xx_chip_release(struct kref *kref)
5733{
5734 struct qla_chip_state_84xx *cs84xx =
5735 container_of(kref, struct qla_chip_state_84xx, kref);
5736
5737 mutex_lock(&qla_cs84xx_mutex);
5738 list_del(&cs84xx->list);
5739 mutex_unlock(&qla_cs84xx_mutex);
5740 kfree(cs84xx);
5741}
5742
5743void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005744qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005745{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005746 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005747 if (ha->cs84xx)
5748 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
5749}
5750
5751static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005752qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005753{
5754 int rval;
5755 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005756 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005757
5758 mutex_lock(&ha->cs84xx->fw_update_mutex);
5759
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005760 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005761
5762 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5763
5764 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5765 QLA_SUCCESS;
5766}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005767
5768/* 81XX Support **************************************************************/
5769
5770int
5771qla81xx_nvram_config(scsi_qla_host_t *vha)
5772{
5773 int rval;
5774 struct init_cb_81xx *icb;
5775 struct nvram_81xx *nv;
5776 uint32_t *dptr;
5777 uint8_t *dptr1, *dptr2;
5778 uint32_t chksum;
5779 uint16_t cnt;
5780 struct qla_hw_data *ha = vha->hw;
5781
5782 rval = QLA_SUCCESS;
5783 icb = (struct init_cb_81xx *)ha->init_cb;
5784 nv = ha->nvram;
5785
5786 /* Determine NVRAM starting address. */
5787 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005788 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005789 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
5790 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005791
5792 /* Get VPD data into cache */
5793 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005794 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5795 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005796
5797 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005798 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005799 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005800 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005801 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5802 chksum += le32_to_cpu(*dptr++);
5803
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005804 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
5805 "Contents of NVRAM:\n");
5806 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
5807 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005808
5809 /* Bad NVRAM data, set defaults parameters. */
5810 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5811 || nv->id[3] != ' ' ||
5812 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5813 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005814 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04005815 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005816 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005817 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005818 ql_log(ql_log_info, vha, 0x0074,
5819 "Falling back to functioning (yet invalid -- WWPN) "
5820 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005821
5822 /*
5823 * Set default initialization control block.
5824 */
5825 memset(nv, 0, ha->nvram_size);
5826 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5827 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5828 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5829 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5830 nv->exchange_count = __constant_cpu_to_le16(0);
5831 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005832 nv->port_name[1] = 0x00 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005833 nv->port_name[2] = 0x00;
5834 nv->port_name[3] = 0xe0;
5835 nv->port_name[4] = 0x8b;
5836 nv->port_name[5] = 0x1c;
5837 nv->port_name[6] = 0x55;
5838 nv->port_name[7] = 0x86;
5839 nv->node_name[0] = 0x20;
5840 nv->node_name[1] = 0x00;
5841 nv->node_name[2] = 0x00;
5842 nv->node_name[3] = 0xe0;
5843 nv->node_name[4] = 0x8b;
5844 nv->node_name[5] = 0x1c;
5845 nv->node_name[6] = 0x55;
5846 nv->node_name[7] = 0x86;
5847 nv->login_retry_count = __constant_cpu_to_le16(8);
5848 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5849 nv->login_timeout = __constant_cpu_to_le16(0);
5850 nv->firmware_options_1 =
5851 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5852 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5853 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5854 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5855 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5856 nv->efi_parameters = __constant_cpu_to_le32(0);
5857 nv->reset_delay = 5;
5858 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5859 nv->port_down_retry_count = __constant_cpu_to_le16(30);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005860 nv->link_down_timeout = __constant_cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005861 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005862 nv->enode_mac[1] = 0xC0;
5863 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005864 nv->enode_mac[3] = 0x04;
5865 nv->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005866 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005867
5868 rval = 1;
5869 }
5870
Arun Easi9e522cd2012-08-22 14:21:31 -04005871 if (IS_T10_PI_CAPABLE(ha))
5872 nv->frame_payload_size &= ~7;
5873
Arun Easiaa230bc2013-01-30 03:34:39 -05005874 qlt_81xx_config_nvram_stage1(vha, nv);
5875
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005876 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07005877 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005878
5879 /* Copy 1st segment. */
5880 dptr1 = (uint8_t *)icb;
5881 dptr2 = (uint8_t *)&nv->version;
5882 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5883 while (cnt--)
5884 *dptr1++ = *dptr2++;
5885
5886 icb->login_retry_count = nv->login_retry_count;
5887
5888 /* Copy 2nd segment. */
5889 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5890 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5891 cnt = (uint8_t *)&icb->reserved_5 -
5892 (uint8_t *)&icb->interrupt_delay_timer;
5893 while (cnt--)
5894 *dptr1++ = *dptr2++;
5895
5896 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5897 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5898 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08005899 icb->enode_mac[0] = 0x00;
5900 icb->enode_mac[1] = 0xC0;
5901 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005902 icb->enode_mac[3] = 0x04;
5903 icb->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005904 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005905 }
5906
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005907 /* Use extended-initialization control block. */
5908 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5909
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005910 /*
5911 * Setup driver NVRAM options.
5912 */
5913 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005914 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005915
Arun Easiaa230bc2013-01-30 03:34:39 -05005916 qlt_81xx_config_nvram_stage2(vha, icb);
5917
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005918 /* Use alternate WWN? */
5919 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5920 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5921 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5922 }
5923
5924 /* Prepare nodename */
5925 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5926 /*
5927 * Firmware will apply the following mask if the nodename was
5928 * not provided.
5929 */
5930 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5931 icb->node_name[0] &= 0xF0;
5932 }
5933
5934 /* Set host adapter parameters. */
5935 ha->flags.disable_risc_code_load = 0;
5936 ha->flags.enable_lip_reset = 0;
5937 ha->flags.enable_lip_full_login =
5938 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5939 ha->flags.enable_target_reset =
5940 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5941 ha->flags.enable_led_scheme = 0;
5942 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5943
5944 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5945 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5946
5947 /* save HBA serial number */
5948 ha->serial0 = icb->port_name[5];
5949 ha->serial1 = icb->port_name[6];
5950 ha->serial2 = icb->port_name[7];
5951 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5952 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5953
5954 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5955
5956 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5957
5958 /* Set minimum login_timeout to 4 seconds. */
5959 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5960 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5961 if (le16_to_cpu(nv->login_timeout) < 4)
5962 nv->login_timeout = __constant_cpu_to_le16(4);
5963 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5964 icb->login_timeout = nv->login_timeout;
5965
5966 /* Set minimum RATOV to 100 tenths of a second. */
5967 ha->r_a_tov = 100;
5968
5969 ha->loop_reset_delay = nv->reset_delay;
5970
5971 /* Link Down Timeout = 0:
5972 *
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005973 * When Port Down timer expires we will start returning
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005974 * I/O's to OS with "DID_NO_CONNECT".
5975 *
5976 * Link Down Timeout != 0:
5977 *
5978 * The driver waits for the link to come up after link down
5979 * before returning I/Os to OS with "DID_NO_CONNECT".
5980 */
5981 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5982 ha->loop_down_abort_time =
5983 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5984 } else {
5985 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5986 ha->loop_down_abort_time =
5987 (LOOP_DOWN_TIME - ha->link_down_timeout);
5988 }
5989
5990 /* Need enough time to try and get the port back. */
5991 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5992 if (qlport_down_retry)
5993 ha->port_down_retry_count = qlport_down_retry;
5994
5995 /* Set login_retry_count */
5996 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5997 if (ha->port_down_retry_count ==
5998 le16_to_cpu(nv->port_down_retry_count) &&
5999 ha->port_down_retry_count > 3)
6000 ha->login_retry_count = ha->port_down_retry_count;
6001 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6002 ha->login_retry_count = ha->port_down_retry_count;
6003 if (ql2xloginretrycount)
6004 ha->login_retry_count = ql2xloginretrycount;
6005
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006006 /* if not running MSI-X we need handshaking on interrupts */
Chad Dupuisf73cb692014-02-26 04:15:06 -05006007 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006008 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
6009
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006010 /* Enable ZIO. */
6011 if (!vha->flags.init_done) {
6012 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6013 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6014 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6015 le16_to_cpu(icb->interrupt_delay_timer): 2;
6016 }
6017 icb->firmware_options_2 &= __constant_cpu_to_le32(
6018 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
6019 vha->flags.process_response_queue = 0;
6020 if (ha->zio_mode != QLA_ZIO_DISABLED) {
6021 ha->zio_mode = QLA_ZIO_MODE_6;
6022
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006023 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006024 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006025 ha->zio_mode,
6026 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006027
6028 icb->firmware_options_2 |= cpu_to_le32(
6029 (uint32_t)ha->zio_mode);
6030 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
6031 vha->flags.process_response_queue = 1;
6032 }
6033
6034 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006035 ql_log(ql_log_warn, vha, 0x0076,
6036 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006037 }
6038 return (rval);
6039}
6040
Giridhar Malavalia9083012010-04-12 17:59:55 -07006041int
6042qla82xx_restart_isp(scsi_qla_host_t *vha)
6043{
6044 int status, rval;
6045 uint32_t wait_time;
6046 struct qla_hw_data *ha = vha->hw;
6047 struct req_que *req = ha->req_q_map[0];
6048 struct rsp_que *rsp = ha->rsp_q_map[0];
6049 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07006050 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006051
6052 status = qla2x00_init_rings(vha);
6053 if (!status) {
6054 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6055 ha->flags.chip_reset_done = 1;
6056
6057 status = qla2x00_fw_ready(vha);
6058 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006059 ql_log(ql_log_info, vha, 0x803c,
6060 "Start configure loop, status =%d.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006061
6062 /* Issue a marker after FW becomes ready. */
6063 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
6064
6065 vha->flags.online = 1;
6066 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6067 wait_time = 256;
6068 do {
6069 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6070 qla2x00_configure_loop(vha);
6071 wait_time--;
6072 } while (!atomic_read(&vha->loop_down_timer) &&
6073 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
6074 wait_time &&
6075 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
6076 }
6077
6078 /* if no cable then assume it's good */
6079 if ((vha->device_flags & DFLG_NO_CABLE))
6080 status = 0;
6081
Chad Dupuiscfb09192011-11-18 09:03:07 -08006082 ql_log(ql_log_info, vha, 0x8000,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006083 "Configure loop done, status = 0x%x.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006084 }
6085
6086 if (!status) {
6087 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6088
6089 if (!atomic_read(&vha->loop_down_timer)) {
6090 /*
6091 * Issue marker command only when we are going
6092 * to start the I/O .
6093 */
6094 vha->marker_needed = 1;
6095 }
6096
6097 vha->flags.online = 1;
6098
6099 ha->isp_ops->enable_intrs(ha);
6100
6101 ha->isp_abort_cnt = 0;
6102 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6103
Saurav Kashyap53296782011-05-10 11:30:06 -07006104 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07006105 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07006106
Giridhar Malavalia9083012010-04-12 17:59:55 -07006107 if (ha->fce) {
6108 ha->flags.fce_enabled = 1;
6109 memset(ha->fce, 0,
6110 fce_calc_size(ha->fce_bufs));
6111 rval = qla2x00_enable_fce_trace(vha,
6112 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6113 &ha->fce_bufs);
6114 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006115 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006116 "Unable to reinitialize FCE (%d).\n",
6117 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006118 ha->flags.fce_enabled = 0;
6119 }
6120 }
6121
6122 if (ha->eft) {
6123 memset(ha->eft, 0, EFT_SIZE);
6124 rval = qla2x00_enable_eft_trace(vha,
6125 ha->eft_dma, EFT_NUM_BUFFERS);
6126 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006127 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006128 "Unable to reinitialize EFT (%d).\n",
6129 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006130 }
6131 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006132 }
6133
6134 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006135 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006136 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07006137
6138 spin_lock_irqsave(&ha->vport_slock, flags);
6139 list_for_each_entry(vp, &ha->vp_list, list) {
6140 if (vp->vp_idx) {
6141 atomic_inc(&vp->vref_count);
6142 spin_unlock_irqrestore(&ha->vport_slock, flags);
6143
Giridhar Malavalia9083012010-04-12 17:59:55 -07006144 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07006145
6146 spin_lock_irqsave(&ha->vport_slock, flags);
6147 atomic_dec(&vp->vref_count);
6148 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006149 }
Arun Easifeafb7b2010-09-03 14:57:00 -07006150 spin_unlock_irqrestore(&ha->vport_slock, flags);
6151
Giridhar Malavalia9083012010-04-12 17:59:55 -07006152 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006153 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006154 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006155 }
6156
6157 return status;
6158}
6159
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006160void
Andrew Vasquezae97c912010-02-18 10:07:28 -08006161qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006162{
Andrew Vasquezae97c912010-02-18 10:07:28 -08006163 struct qla_hw_data *ha = vha->hw;
6164
6165 if (!ql2xetsenable)
6166 return;
6167
6168 /* Enable ETS Burst. */
6169 memset(ha->fw_options, 0, sizeof(ha->fw_options));
6170 ha->fw_options[2] |= BIT_9;
6171 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006172}
Sarang Radke09ff7012010-03-19 17:03:59 -07006173
6174/*
6175 * qla24xx_get_fcp_prio
6176 * Gets the fcp cmd priority value for the logged in port.
6177 * Looks for a match of the port descriptors within
6178 * each of the fcp prio config entries. If a match is found,
6179 * the tag (priority) value is returned.
6180 *
6181 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006182 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07006183 * fcport = port structure pointer.
6184 *
6185 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07006186 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006187 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07006188 *
6189 * Context:
6190 * Kernel context
6191 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006192static int
Sarang Radke09ff7012010-03-19 17:03:59 -07006193qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
6194{
6195 int i, entries;
6196 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006197 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07006198 uint32_t pid1, pid2;
6199 uint64_t wwn1, wwn2;
6200 struct qla_fcp_prio_entry *pri_entry;
6201 struct qla_hw_data *ha = vha->hw;
6202
6203 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006204 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07006205
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006206 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07006207 entries = ha->fcp_prio_cfg->num_entries;
6208 pri_entry = &ha->fcp_prio_cfg->entry[0];
6209
6210 for (i = 0; i < entries; i++) {
6211 pid_match = wwn_match = 0;
6212
6213 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
6214 pri_entry++;
6215 continue;
6216 }
6217
6218 /* check source pid for a match */
6219 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
6220 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
6221 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
6222 if (pid1 == INVALID_PORT_ID)
6223 pid_match++;
6224 else if (pid1 == pid2)
6225 pid_match++;
6226 }
6227
6228 /* check destination pid for a match */
6229 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
6230 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
6231 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
6232 if (pid1 == INVALID_PORT_ID)
6233 pid_match++;
6234 else if (pid1 == pid2)
6235 pid_match++;
6236 }
6237
6238 /* check source WWN for a match */
6239 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
6240 wwn1 = wwn_to_u64(vha->port_name);
6241 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
6242 if (wwn2 == (uint64_t)-1)
6243 wwn_match++;
6244 else if (wwn1 == wwn2)
6245 wwn_match++;
6246 }
6247
6248 /* check destination WWN for a match */
6249 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
6250 wwn1 = wwn_to_u64(fcport->port_name);
6251 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
6252 if (wwn2 == (uint64_t)-1)
6253 wwn_match++;
6254 else if (wwn1 == wwn2)
6255 wwn_match++;
6256 }
6257
6258 if (pid_match == 2 || wwn_match == 2) {
6259 /* Found a matching entry */
6260 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
6261 priority = pri_entry->tag;
6262 break;
6263 }
6264
6265 pri_entry++;
6266 }
6267
6268 return priority;
6269}
6270
6271/*
6272 * qla24xx_update_fcport_fcp_prio
6273 * Activates fcp priority for the logged in fc port
6274 *
6275 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006276 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07006277 * fcp = port structure pointer.
6278 *
6279 * Return:
6280 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6281 *
6282 * Context:
6283 * Kernel context.
6284 */
6285int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006286qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07006287{
6288 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006289 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07006290 uint16_t mb[5];
6291
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006292 if (fcport->port_type != FCT_TARGET ||
6293 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07006294 return QLA_FUNCTION_FAILED;
6295
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006296 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006297 if (priority < 0)
6298 return QLA_FUNCTION_FAILED;
6299
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006300 if (IS_P3P_TYPE(vha->hw)) {
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006301 fcport->fcp_prio = priority & 0xf;
6302 return QLA_SUCCESS;
6303 }
6304
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006305 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08006306 if (ret == QLA_SUCCESS) {
6307 if (fcport->fcp_prio != priority)
6308 ql_dbg(ql_dbg_user, vha, 0x709e,
6309 "Updated FCP_CMND priority - value=%d loop_id=%d "
6310 "port_id=%02x%02x%02x.\n", priority,
6311 fcport->loop_id, fcport->d_id.b.domain,
6312 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006313 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08006314 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006315 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006316 "Unable to update FCP_CMND priority - ret=0x%x for "
6317 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
6318 fcport->d_id.b.domain, fcport->d_id.b.area,
6319 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07006320 return ret;
6321}
6322
6323/*
6324 * qla24xx_update_all_fcp_prio
6325 * Activates fcp priority for all the logged in ports
6326 *
6327 * Input:
6328 * ha = adapter block pointer.
6329 *
6330 * Return:
6331 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6332 *
6333 * Context:
6334 * Kernel context.
6335 */
6336int
6337qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
6338{
6339 int ret;
6340 fc_port_t *fcport;
6341
6342 ret = QLA_FUNCTION_FAILED;
6343 /* We need to set priority for all logged in ports */
6344 list_for_each_entry(fcport, &vha->vp_fcports, list)
6345 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
6346
6347 return ret;
6348}