blob: 38aeb54cd9d8076bdcb999811a2a068dd7e0962d [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 Kashyapa9b6f722012-08-22 14:21:01 -040077unsigned long
Andrew Vasquez5b914902010-05-28 15:08:30 -070078qla2x00_get_async_timeout(struct scsi_qla_host *vha)
79{
80 unsigned long tmo;
81 struct qla_hw_data *ha = vha->hw;
82
83 /* Firmware should use switch negotiated r_a_tov for timeout. */
84 tmo = ha->r_a_tov / 10 * 2;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040085 if (IS_QLAFX00(ha)) {
86 tmo = FX00_DEF_RATOV * 2;
87 } else if (!IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez5b914902010-05-28 15:08:30 -070088 /*
89 * Except for earlier ISPs where the timeout is seeded from the
90 * initialization control block.
91 */
92 tmo = ha->login_timeout;
93 }
94 return tmo;
95}
Andrew Vasquezac280b62009-08-20 11:06:05 -070096
97static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080098qla2x00_async_iocb_timeout(void *data)
Andrew Vasquezac280b62009-08-20 11:06:05 -070099{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800100 srb_t *sp = (srb_t *)data;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700101 fc_port_t *fcport = sp->fcport;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700102
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700103 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800104 "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800105 sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700106 fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700107
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700108 fcport->flags &= ~FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800109 if (sp->type == SRB_LOGIN_CMD) {
110 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700111 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700112 /* Retry as needed. */
113 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
114 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
115 QLA_LOGIO_LOGIN_RETRIED : 0;
116 qla2x00_post_async_login_done_work(fcport->vha, fcport,
117 lio->u.logio.data);
118 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700119}
120
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700121static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800122qla2x00_async_login_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700123{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800124 srb_t *sp = (srb_t *)ptr;
125 struct srb_iocb *lio = &sp->u.iocb_cmd;
126 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700127
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800128 if (!test_bit(UNLOADING, &vha->dpc_flags))
129 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
130 lio->u.logio.data);
131 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700132}
133
Andrew Vasquezac280b62009-08-20 11:06:05 -0700134int
135qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
136 uint16_t *data)
137{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700138 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700139 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700140 int rval;
141
142 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800143 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700144 if (!sp)
145 goto done;
146
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800147 sp->type = SRB_LOGIN_CMD;
148 sp->name = "login";
149 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
150
151 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700152 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800153 sp->done = qla2x00_async_login_sp_done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700154 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700155 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700156 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700157 rval = qla2x00_start_sp(sp);
158 if (rval != QLA_SUCCESS)
159 goto done_free_sp;
160
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700161 ql_dbg(ql_dbg_disc, vha, 0x2072,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800162 "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
163 "retries=%d.\n", sp->handle, fcport->loop_id,
164 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
165 fcport->login_retry);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700166 return rval;
167
168done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800169 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700170done:
171 return rval;
172}
173
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700174static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800175qla2x00_async_logout_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700176{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800177 srb_t *sp = (srb_t *)ptr;
178 struct srb_iocb *lio = &sp->u.iocb_cmd;
179 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700180
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800181 if (!test_bit(UNLOADING, &vha->dpc_flags))
182 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
183 lio->u.logio.data);
184 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700185}
186
Andrew Vasquezac280b62009-08-20 11:06:05 -0700187int
188qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
189{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700190 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700191 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700192 int rval;
193
194 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800195 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700196 if (!sp)
197 goto done;
198
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800199 sp->type = SRB_LOGOUT_CMD;
200 sp->name = "logout";
201 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
202
203 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700204 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800205 sp->done = qla2x00_async_logout_sp_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700206 rval = qla2x00_start_sp(sp);
207 if (rval != QLA_SUCCESS)
208 goto done_free_sp;
209
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700210 ql_dbg(ql_dbg_disc, vha, 0x2070,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800211 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
212 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
213 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700214 return rval;
215
216done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800217 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700218done:
219 return rval;
220}
221
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700222static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800223qla2x00_async_adisc_sp_done(void *data, void *ptr, int res)
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700224{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800225 srb_t *sp = (srb_t *)ptr;
226 struct srb_iocb *lio = &sp->u.iocb_cmd;
227 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700228
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800229 if (!test_bit(UNLOADING, &vha->dpc_flags))
230 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
231 lio->u.logio.data);
232 sp->free(sp->fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700233}
234
235int
236qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
237 uint16_t *data)
238{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700239 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700240 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700241 int rval;
242
243 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800244 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700245 if (!sp)
246 goto done;
247
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800248 sp->type = SRB_ADISC_CMD;
249 sp->name = "adisc";
250 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
251
252 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700253 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800254 sp->done = qla2x00_async_adisc_sp_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700255 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700256 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700257 rval = qla2x00_start_sp(sp);
258 if (rval != QLA_SUCCESS)
259 goto done_free_sp;
260
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700261 ql_dbg(ql_dbg_disc, vha, 0x206f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800262 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
263 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
264 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700265 return rval;
266
267done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800268 sp->free(fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700269done:
270 return rval;
271}
272
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700273static void
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500274qla2x00_tmf_iocb_timeout(void *data)
275{
276 srb_t *sp = (srb_t *)data;
277 struct srb_iocb *tmf = &sp->u.iocb_cmd;
278
279 tmf->u.tmf.comp_status = CS_TIMEOUT;
280 complete(&tmf->u.tmf.comp);
281}
282
283static void
284qla2x00_tmf_sp_done(void *data, void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700285{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800286 srb_t *sp = (srb_t *)ptr;
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500287 struct srb_iocb *tmf = &sp->u.iocb_cmd;
288 complete(&tmf->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700289}
290
291int
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500292qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700293 uint32_t tag)
294{
295 struct scsi_qla_host *vha = fcport->vha;
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500296 struct srb_iocb *tm_iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700297 srb_t *sp;
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500298 int rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700299
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800300 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700301 if (!sp)
302 goto done;
303
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500304 tm_iocb = &sp->u.iocb_cmd;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800305 sp->type = SRB_TM_CMD;
306 sp->name = "tmf";
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500307 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
308 tm_iocb->u.tmf.flags = flags;
309 tm_iocb->u.tmf.lun = lun;
310 tm_iocb->u.tmf.data = tag;
311 sp->done = qla2x00_tmf_sp_done;
312 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
313 init_completion(&tm_iocb->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700314
315 rval = qla2x00_start_sp(sp);
316 if (rval != QLA_SUCCESS)
317 goto done_free_sp;
318
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700319 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800320 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
321 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
322 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500323
324 wait_for_completion(&tm_iocb->u.tmf.comp);
325
326 rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
327 QLA_SUCCESS : QLA_FUNCTION_FAILED;
328
329 if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
330 ql_dbg(ql_dbg_taskm, vha, 0x8030,
331 "TM IOCB failed (%x).\n", rval);
332 }
333
334 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
335 flags = tm_iocb->u.tmf.flags;
336 lun = (uint16_t)tm_iocb->u.tmf.lun;
337
338 /* Issue Marker IOCB */
339 qla2x00_marker(vha, vha->hw->req_q_map[0],
340 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
341 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
342 }
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700343
344done_free_sp:
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500345 sp->free(vha, sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700346done:
347 return rval;
348}
349
Armen Baloyan4440e462014-02-26 04:15:18 -0500350static void
351qla24xx_abort_iocb_timeout(void *data)
352{
353 srb_t *sp = (srb_t *)data;
354 struct srb_iocb *abt = &sp->u.iocb_cmd;
355
356 abt->u.abt.comp_status = CS_TIMEOUT;
357 complete(&abt->u.abt.comp);
358}
359
360static void
361qla24xx_abort_sp_done(void *data, void *ptr, int res)
362{
363 srb_t *sp = (srb_t *)ptr;
364 struct srb_iocb *abt = &sp->u.iocb_cmd;
365
366 complete(&abt->u.abt.comp);
367}
368
369static int
370qla24xx_async_abort_cmd(srb_t *cmd_sp)
371{
372 scsi_qla_host_t *vha = cmd_sp->fcport->vha;
373 fc_port_t *fcport = cmd_sp->fcport;
374 struct srb_iocb *abt_iocb;
375 srb_t *sp;
376 int rval = QLA_FUNCTION_FAILED;
377
378 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
379 if (!sp)
380 goto done;
381
382 abt_iocb = &sp->u.iocb_cmd;
383 sp->type = SRB_ABT_CMD;
384 sp->name = "abort";
385 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
386 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
387 sp->done = qla24xx_abort_sp_done;
388 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
389 init_completion(&abt_iocb->u.abt.comp);
390
391 rval = qla2x00_start_sp(sp);
392 if (rval != QLA_SUCCESS)
393 goto done_free_sp;
394
395 ql_dbg(ql_dbg_async, vha, 0x507c,
396 "Abort command issued - hdl=%x, target_id=%x\n",
397 cmd_sp->handle, fcport->tgt_id);
398
399 wait_for_completion(&abt_iocb->u.abt.comp);
400
401 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
402 QLA_SUCCESS : QLA_FUNCTION_FAILED;
403
404done_free_sp:
405 sp->free(vha, sp);
406done:
407 return rval;
408}
409
410int
411qla24xx_async_abort_command(srb_t *sp)
412{
413 unsigned long flags = 0;
414
415 uint32_t handle;
416 fc_port_t *fcport = sp->fcport;
417 struct scsi_qla_host *vha = fcport->vha;
418 struct qla_hw_data *ha = vha->hw;
419 struct req_que *req = vha->req;
420
421 spin_lock_irqsave(&ha->hardware_lock, flags);
422 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
423 if (req->outstanding_cmds[handle] == sp)
424 break;
425 }
426 spin_unlock_irqrestore(&ha->hardware_lock, flags);
427 if (handle == req->num_outstanding_cmds) {
428 /* Command not found. */
429 return QLA_FUNCTION_FAILED;
430 }
431 if (sp->type == SRB_FXIOCB_DCMD)
432 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
433 FXDISC_ABORT_IOCTL);
434
435 return qla24xx_async_abort_cmd(sp);
436}
437
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700438void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700439qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
440 uint16_t *data)
441{
442 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700443
444 switch (data[0]) {
445 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700446 /*
447 * Driver must validate login state - If PRLI not complete,
448 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
449 * requests.
450 */
451 rval = qla2x00_get_port_database(vha, fcport, 0);
Arun Easi0eba25d2012-02-09 11:15:58 -0800452 if (rval == QLA_NOT_LOGGED_IN) {
453 fcport->flags &= ~FCF_ASYNC_SENT;
454 fcport->flags |= FCF_LOGIN_NEEDED;
455 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
456 break;
457 }
458
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700459 if (rval != QLA_SUCCESS) {
460 qla2x00_post_async_logout_work(vha, fcport, NULL);
461 qla2x00_post_async_login_work(vha, fcport, NULL);
462 break;
463 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700464 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700465 qla2x00_post_async_adisc_work(vha, fcport, data);
466 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700467 }
468 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700469 break;
470 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700471 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700472 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
473 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
474 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700475 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700476 break;
477 case MBS_PORT_ID_USED:
478 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700479 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700480 qla2x00_post_async_login_work(vha, fcport, NULL);
481 break;
482 case MBS_LOOP_ID_USED:
483 fcport->loop_id++;
484 rval = qla2x00_find_new_loop_id(vha, fcport);
485 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700486 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez80d79442011-03-30 11:46:17 -0700487 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700488 break;
489 }
490 qla2x00_post_async_login_work(vha, fcport, NULL);
491 break;
492 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700493 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700494}
495
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700496void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700497qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
498 uint16_t *data)
499{
500 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700501 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700502}
503
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700504void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700505qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
506 uint16_t *data)
507{
508 if (data[0] == MBS_COMMAND_COMPLETE) {
509 qla2x00_update_fcport(vha, fcport);
510
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700511 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700512 }
513
514 /* Retry login. */
515 fcport->flags &= ~FCF_ASYNC_SENT;
516 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
517 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
518 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700519 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700520
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700521 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700522}
523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524/****************************************************************************/
525/* QLogic ISP2x00 Hardware Support Functions. */
526/****************************************************************************/
527
Saurav Kashyapfa492632012-11-21 02:40:29 -0500528static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400529qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
530{
531 int rval = QLA_SUCCESS;
532 struct qla_hw_data *ha = vha->hw;
533 uint32_t idc_major_ver, idc_minor_ver;
Saurav Kashyap711aa7f2012-08-22 14:21:15 -0400534 uint16_t config[4];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400535
536 qla83xx_idc_lock(vha, 0);
537
538 /* SV: TODO: Assign initialization timeout from
539 * flash-info / other param
540 */
541 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
542 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
543
544 /* Set our fcoe function presence */
545 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
546 ql_dbg(ql_dbg_p3p, vha, 0xb077,
547 "Error while setting DRV-Presence.\n");
548 rval = QLA_FUNCTION_FAILED;
549 goto exit;
550 }
551
552 /* Decide the reset ownership */
553 qla83xx_reset_ownership(vha);
554
555 /*
556 * On first protocol driver load:
557 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
558 * register.
559 * Others: Check compatibility with current IDC Major version.
560 */
561 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
562 if (ha->flags.nic_core_reset_owner) {
563 /* Set IDC Major version */
564 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
565 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
566
567 /* Clearing IDC-Lock-Recovery register */
568 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
569 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
570 /*
571 * Clear further IDC participation if we are not compatible with
572 * the current IDC Major Version.
573 */
574 ql_log(ql_log_warn, vha, 0xb07d,
575 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
576 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
577 __qla83xx_clear_drv_presence(vha);
578 rval = QLA_FUNCTION_FAILED;
579 goto exit;
580 }
581 /* Each function sets its supported Minor version. */
582 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
583 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
584 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
585
Saurav Kashyap711aa7f2012-08-22 14:21:15 -0400586 if (ha->flags.nic_core_reset_owner) {
587 memset(config, 0, sizeof(config));
588 if (!qla81xx_get_port_config(vha, config))
589 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
590 QLA8XXX_DEV_READY);
591 }
592
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400593 rval = qla83xx_idc_state_handler(vha);
594
595exit:
596 qla83xx_idc_unlock(vha, 0);
597
598 return rval;
599}
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601/*
602* qla2x00_initialize_adapter
603* Initialize board.
604*
605* Input:
606* ha = adapter block pointer.
607*
608* Returns:
609* 0 = success
610*/
611int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800612qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
614 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800615 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800616 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800619 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700620 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800621 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800622 ha->flags.pci_channel_io_perm_failure = 0;
623 ha->flags.eeh_busy = 0;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -0400624 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800625 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
626 atomic_set(&vha->loop_state, LOOP_DOWN);
627 vha->device_flags = DFLG_NO_CABLE;
628 vha->dpc_flags = 0;
629 vha->flags.management_server_logged_in = 0;
630 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 ha->isp_abort_cnt = 0;
632 ha->beacon_blink_led = 0;
633
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800634 set_bit(0, ha->req_qid_map);
635 set_bit(0, ha->rsp_qid_map);
636
Chad Dupuiscfb09192011-11-18 09:03:07 -0800637 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700638 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800639 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700641 ql_log(ql_log_warn, vha, 0x0044,
642 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 return (rval);
644 }
645
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800646 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800648 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700649 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700650 ql_log(ql_log_fatal, vha, 0x004f,
651 "Unable to validate FLASH data.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400652 return rval;
653 }
654
655 if (IS_QLA8044(ha)) {
656 qla8044_read_reset_template(vha);
657
658 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
659 * If DONRESET_BIT0 is set, drivers should not set dev_state
660 * to NEED_RESET. But if NEED_RESET is set, drivers should
661 * should honor the reset. */
662 if (ql2xdontresethba == 1)
663 qla8044_set_idc_dontreset(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700664 }
665
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800666 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -0800667 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700668 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700669
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800670 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700672 if (ha->flags.disable_serdes) {
673 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700674 ql_log(ql_log_info, vha, 0x0077,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -0400675 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700676 return QLA_FUNCTION_FAILED;
677 }
678
Chad Dupuiscfb09192011-11-18 09:03:07 -0800679 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700680 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800682 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
683 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800684 if (rval)
685 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800686 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800687 if (rval)
688 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700690
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700691 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800692 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700693 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700694 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700695 "Unable to configure ISP84XX.\n");
696 return QLA_FUNCTION_FAILED;
697 }
698 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400699
700 if (qla_ini_mode_enabled(vha))
701 rval = qla2x00_init_rings(vha);
702
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700703 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800705 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700706 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800707 rval = qla84xx_init_chip(vha);
708 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700709 ql_log(ql_log_warn, vha, 0x00d4,
710 "Unable to initialize ISP84XX.\n");
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800711 qla84xx_put_chip(vha);
712 }
713 }
714
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400715 /* Load the NIC Core f/w if we are the first protocol driver. */
716 if (IS_QLA8031(ha)) {
717 rval = qla83xx_nic_core_fw_load(vha);
718 if (rval)
719 ql_log(ql_log_warn, vha, 0x0124,
720 "Error in initializing NIC Core f/w.\n");
721 }
722
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500723 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
724 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700725
Joe Carnuccioc46e65c2013-08-27 01:37:35 -0400726 if (IS_P3P_TYPE(ha))
727 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
728 else
729 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 return (rval);
732}
733
734/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700735 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 * @ha: HA context
737 *
738 * Returns 0 on success.
739 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700740int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800741qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700743 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700744 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800745 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700746 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700749 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700752 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
754
Andrew Vasquez737faec2008-10-24 15:13:45 -0700755 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700757 /* Get PCI bus information. */
758 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700759 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700760 spin_unlock_irqrestore(&ha->hardware_lock, flags);
761
762 return QLA_SUCCESS;
763}
764
765/**
766 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
767 * @ha: HA context
768 *
769 * Returns 0 on success.
770 */
771int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800772qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700773{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700774 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700775 unsigned long flags = 0;
776 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800777 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700778 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700779
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700780 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700781 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700782
783 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700784 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700785
786 if (IS_QLA2322(ha) || IS_QLA6322(ha))
787 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700788 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700789
790 /*
791 * If this is a 2300 card and not 2312, reset the
792 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
793 * the 2310 also reports itself as a 2300 so we need to get the
794 * fb revision level -- a 6 indicates it really is a 2300 and
795 * not a 2310.
796 */
797 if (IS_QLA2300(ha)) {
798 spin_lock_irqsave(&ha->hardware_lock, flags);
799
800 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700801 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700802 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700803 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700804 break;
805
806 udelay(10);
807 }
808
809 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700810 WRT_REG_WORD(&reg->ctrl_status, 0x20);
811 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700812
813 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700814 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700815
816 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700817 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700818
819 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700820 WRT_REG_WORD(&reg->ctrl_status, 0x0);
821 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700822
823 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700824 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700825 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700826 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700827 break;
828
829 udelay(10);
830 }
831
832 spin_unlock_irqrestore(&ha->hardware_lock, flags);
833 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700834
835 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
836
Andrew Vasquez737faec2008-10-24 15:13:45 -0700837 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700838
839 /* Get PCI bus information. */
840 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700841 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700842 spin_unlock_irqrestore(&ha->hardware_lock, flags);
843
844 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845}
846
847/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700848 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
849 * @ha: HA context
850 *
851 * Returns 0 on success.
852 */
853int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800854qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700855{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700856 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700857 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800858 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700859 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700860
861 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700862 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700863
864 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700865 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700866 w &= ~PCI_COMMAND_INTX_DISABLE;
867 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
868
869 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
870
871 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700872 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
873 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700874
875 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700876 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -0400877 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700878
Andrew Vasquez737faec2008-10-24 15:13:45 -0700879 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700880
Auke Kok44c10132007-06-08 15:46:36 -0700881 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800882
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700883 /* Get PCI bus information. */
884 spin_lock_irqsave(&ha->hardware_lock, flags);
885 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
886 spin_unlock_irqrestore(&ha->hardware_lock, flags);
887
888 return QLA_SUCCESS;
889}
890
891/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700892 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
893 * @ha: HA context
894 *
895 * Returns 0 on success.
896 */
897int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800898qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700899{
900 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800901 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700902
903 pci_set_master(ha->pdev);
904 pci_try_set_mwi(ha->pdev);
905
906 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
907 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
908 w &= ~PCI_COMMAND_INTX_DISABLE;
909 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
910
911 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700912 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -0400913 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700914
Andrew Vasquez737faec2008-10-24 15:13:45 -0700915 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700916
917 ha->chip_revision = ha->pdev->revision;
918
919 return QLA_SUCCESS;
920}
921
922/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 * qla2x00_isp_firmware() - Choose firmware image.
924 * @ha: HA context
925 *
926 * Returns 0 on success.
927 */
928static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800929qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930{
931 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700932 uint16_t loop_id, topo, sw_cap;
933 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800934 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
936 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700937 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
939 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700940 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
942 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800943 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700944 if (rval == QLA_SUCCESS) {
945 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800946 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700947 &area, &domain, &topo, &sw_cap);
948 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 }
950
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700951 if (rval)
952 ql_dbg(ql_dbg_init, vha, 0x007a,
953 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
955 return (rval);
956}
957
958/**
959 * qla2x00_reset_chip() - Reset ISP chip.
960 * @ha: HA context
961 *
962 * Returns 0 on success.
963 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700964void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800965qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
967 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800968 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700969 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 uint16_t cmd;
972
Andrew Vasquez85880802009-12-15 21:29:46 -0800973 if (unlikely(pci_channel_offline(ha->pdev)))
974 return;
975
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700976 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
978 spin_lock_irqsave(&ha->hardware_lock, flags);
979
980 /* Turn off master enable */
981 cmd = 0;
982 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
983 cmd &= ~PCI_COMMAND_MASTER;
984 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
985
986 if (!IS_QLA2100(ha)) {
987 /* Pause RISC. */
988 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
989 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
990 for (cnt = 0; cnt < 30000; cnt++) {
991 if ((RD_REG_WORD(&reg->hccr) &
992 HCCR_RISC_PAUSE) != 0)
993 break;
994 udelay(100);
995 }
996 } else {
997 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
998 udelay(10);
999 }
1000
1001 /* Select FPM registers. */
1002 WRT_REG_WORD(&reg->ctrl_status, 0x20);
1003 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1004
1005 /* FPM Soft Reset. */
1006 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
1007 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
1008
1009 /* Toggle Fpm Reset. */
1010 if (!IS_QLA2200(ha)) {
1011 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
1012 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
1013 }
1014
1015 /* Select frame buffer registers. */
1016 WRT_REG_WORD(&reg->ctrl_status, 0x10);
1017 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1018
1019 /* Reset frame buffer FIFOs. */
1020 if (IS_QLA2200(ha)) {
1021 WRT_FB_CMD_REG(ha, reg, 0xa000);
1022 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
1023 } else {
1024 WRT_FB_CMD_REG(ha, reg, 0x00fc);
1025
1026 /* Read back fb_cmd until zero or 3 seconds max */
1027 for (cnt = 0; cnt < 3000; cnt++) {
1028 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
1029 break;
1030 udelay(100);
1031 }
1032 }
1033
1034 /* Select RISC module registers. */
1035 WRT_REG_WORD(&reg->ctrl_status, 0);
1036 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1037
1038 /* Reset RISC processor. */
1039 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1040 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1041
1042 /* Release RISC processor. */
1043 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1044 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1045 }
1046
1047 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
1048 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
1049
1050 /* Reset ISP chip. */
1051 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1052
1053 /* Wait for RISC to recover from reset. */
1054 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1055 /*
1056 * It is necessary to for a delay here since the card doesn't
1057 * respond to PCI reads during a reset. On some architectures
1058 * this will result in an MCA.
1059 */
1060 udelay(20);
1061 for (cnt = 30000; cnt; cnt--) {
1062 if ((RD_REG_WORD(&reg->ctrl_status) &
1063 CSR_ISP_SOFT_RESET) == 0)
1064 break;
1065 udelay(100);
1066 }
1067 } else
1068 udelay(10);
1069
1070 /* Reset RISC processor. */
1071 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1072
1073 WRT_REG_WORD(&reg->semaphore, 0);
1074
1075 /* Release RISC processor. */
1076 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1077 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1078
1079 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1080 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -07001081 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
1084 udelay(100);
1085 }
1086 } else
1087 udelay(100);
1088
1089 /* Turn on master enable */
1090 cmd |= PCI_COMMAND_MASTER;
1091 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
1092
1093 /* Disable RISC pause on FPM parity error. */
1094 if (!IS_QLA2100(ha)) {
1095 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
1096 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1097 }
1098
1099 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1100}
1101
1102/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001103 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
1104 *
1105 * Returns 0 on success.
1106 */
Saurav Kashyapfa492632012-11-21 02:40:29 -05001107static int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001108qla81xx_reset_mpi(scsi_qla_host_t *vha)
1109{
1110 uint16_t mb[4] = {0x1010, 0, 1, 0};
1111
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001112 if (!IS_QLA81XX(vha->hw))
1113 return QLA_SUCCESS;
1114
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001115 return qla81xx_write_mpi_register(vha, mb);
1116}
1117
1118/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001119 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001120 * @ha: HA context
1121 *
1122 * Returns 0 on success.
1123 */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001124static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001125qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001126{
1127 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001128 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001129 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1130 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001131 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001132 static int abts_cnt; /* ISP abort retry counts */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001133
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001134 spin_lock_irqsave(&ha->hardware_lock, flags);
1135
1136 /* Reset RISC. */
1137 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1138 for (cnt = 0; cnt < 30000; cnt++) {
1139 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
1140 break;
1141
1142 udelay(10);
1143 }
1144
1145 WRT_REG_DWORD(&reg->ctrl_status,
1146 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001147 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001148
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001149 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001150 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001151 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1152 for (cnt = 10000 ; cnt && d2; cnt--) {
1153 udelay(5);
1154 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1155 barrier();
1156 }
1157
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001158 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001159 d2 = RD_REG_DWORD(&reg->ctrl_status);
1160 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1161 udelay(5);
1162 d2 = RD_REG_DWORD(&reg->ctrl_status);
1163 barrier();
1164 }
1165
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001166 /* If required, do an MPI FW reset now */
1167 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1168 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1169 if (++abts_cnt < 5) {
1170 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1171 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1172 } else {
1173 /*
1174 * We exhausted the ISP abort retries. We have to
1175 * set the board offline.
1176 */
1177 abts_cnt = 0;
1178 vha->flags.online = 0;
1179 }
1180 }
1181 }
1182
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001183 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1184 RD_REG_DWORD(&reg->hccr);
1185
1186 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1187 RD_REG_DWORD(&reg->hccr);
1188
1189 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1190 RD_REG_DWORD(&reg->hccr);
1191
1192 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1193 for (cnt = 6000000 ; cnt && d2; cnt--) {
1194 udelay(5);
1195 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1196 barrier();
1197 }
1198
1199 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001200
1201 if (IS_NOPOLLING_TYPE(ha))
1202 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001203}
1204
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001205static void
1206qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
1207{
1208 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1209
1210 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1211 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
1212
1213}
1214
1215static void
1216qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
1217{
1218 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1219
1220 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1221 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
1222}
1223
1224static void
1225qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
1226{
1227 struct qla_hw_data *ha = vha->hw;
1228 uint32_t wd32 = 0;
1229 uint delta_msec = 100;
1230 uint elapsed_msec = 0;
1231 uint timeout_msec;
1232 ulong n;
1233
1234 if (!IS_QLA25XX(ha) && !IS_QLA2031(ha))
1235 return;
1236
1237attempt:
1238 timeout_msec = TIMEOUT_SEMAPHORE;
1239 n = timeout_msec / delta_msec;
1240 while (n--) {
1241 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
1242 qla25xx_read_risc_sema_reg(vha, &wd32);
1243 if (wd32 & RISC_SEMAPHORE)
1244 break;
1245 msleep(delta_msec);
1246 elapsed_msec += delta_msec;
1247 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1248 goto force;
1249 }
1250
1251 if (!(wd32 & RISC_SEMAPHORE))
1252 goto force;
1253
1254 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1255 goto acquired;
1256
1257 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
1258 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
1259 n = timeout_msec / delta_msec;
1260 while (n--) {
1261 qla25xx_read_risc_sema_reg(vha, &wd32);
1262 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1263 break;
1264 msleep(delta_msec);
1265 elapsed_msec += delta_msec;
1266 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1267 goto force;
1268 }
1269
1270 if (wd32 & RISC_SEMAPHORE_FORCE)
1271 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
1272
1273 goto attempt;
1274
1275force:
1276 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
1277
1278acquired:
1279 return;
1280}
1281
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001282/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001283 * qla24xx_reset_chip() - Reset ISP24xx chip.
1284 * @ha: HA context
1285 *
1286 * Returns 0 on success.
1287 */
1288void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001289qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001290{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001291 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001292
1293 if (pci_channel_offline(ha->pdev) &&
1294 ha->flags.pci_channel_io_perm_failure) {
1295 return;
1296 }
1297
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001298 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001299
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001300 qla25xx_manipulate_risc_semaphore(vha);
1301
Andrew Vasquez88c26662005-07-08 17:59:26 -07001302 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001303 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001304}
1305
1306/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 * qla2x00_chip_diag() - Test chip for proper operation.
1308 * @ha: HA context
1309 *
1310 * Returns 0 on success.
1311 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001312int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001313qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314{
1315 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001316 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001317 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 unsigned long flags = 0;
1319 uint16_t data;
1320 uint32_t cnt;
1321 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001322 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
1324 /* Assume a failed state */
1325 rval = QLA_FUNCTION_FAILED;
1326
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001327 ql_dbg(ql_dbg_init, vha, 0x007b,
1328 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
1330 spin_lock_irqsave(&ha->hardware_lock, flags);
1331
1332 /* Reset ISP chip. */
1333 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1334
1335 /*
1336 * We need to have a delay here since the card will not respond while
1337 * in reset causing an MCA on some architectures.
1338 */
1339 udelay(20);
1340 data = qla2x00_debounce_register(&reg->ctrl_status);
1341 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1342 udelay(5);
1343 data = RD_REG_WORD(&reg->ctrl_status);
1344 barrier();
1345 }
1346
1347 if (!cnt)
1348 goto chip_diag_failed;
1349
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001350 ql_dbg(ql_dbg_init, vha, 0x007c,
1351 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
1353 /* Reset RISC processor. */
1354 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1355 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1356
1357 /* Workaround for QLA2312 PCI parity error */
1358 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1359 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1360 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1361 udelay(5);
1362 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001363 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 }
1365 } else
1366 udelay(10);
1367
1368 if (!cnt)
1369 goto chip_diag_failed;
1370
1371 /* Check product ID of chip */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001372 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
1374 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1375 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1376 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1377 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1378 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1379 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001380 ql_log(ql_log_warn, vha, 0x0062,
1381 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1382 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383
1384 goto chip_diag_failed;
1385 }
1386 ha->product_id[0] = mb[1];
1387 ha->product_id[1] = mb[2];
1388 ha->product_id[2] = mb[3];
1389 ha->product_id[3] = mb[4];
1390
1391 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001392 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1394 else
1395 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001396 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
1398 if (IS_QLA2200(ha) &&
1399 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1400 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001401 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001403 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 ha->fw_transfer_size = 128;
1405 }
1406
1407 /* Wrap Incoming Mailboxes Test. */
1408 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1409
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001410 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001411 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001412 if (rval)
1413 ql_log(ql_log_warn, vha, 0x0080,
1414 "Failed mailbox send register test.\n");
1415 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 /* Flag a successful rval */
1417 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 spin_lock_irqsave(&ha->hardware_lock, flags);
1419
1420chip_diag_failed:
1421 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001422 ql_log(ql_log_info, vha, 0x0081,
1423 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
1425 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1426
1427 return (rval);
1428}
1429
1430/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001431 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1432 * @ha: HA context
1433 *
1434 * Returns 0 on success.
1435 */
1436int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001437qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001438{
1439 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001440 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001441 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001442
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001443 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07001444 return QLA_SUCCESS;
1445
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001446 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001447
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001448 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001449 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001450 ql_log(ql_log_warn, vha, 0x0082,
1451 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001452 } else {
1453 /* Flag a successful rval */
1454 rval = QLA_SUCCESS;
1455 }
1456
1457 return rval;
1458}
1459
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001460void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001461qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001462{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001463 int rval;
1464 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001465 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001466 dma_addr_t tc_dma;
1467 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001468 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001469 struct req_que *req = ha->req_q_map[0];
1470 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001471
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001472 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001473 ql_dbg(ql_dbg_init, vha, 0x00bd,
1474 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001475 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001476 }
1477
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001478 ha->fw_dumped = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001479 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
1480 req_q_size = rsp_q_size = 0;
1481
1482 if (IS_QLA27XX(ha))
1483 goto try_fce;
1484
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001485 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1486 fixed_size = sizeof(struct qla2100_fw_dump);
1487 } else if (IS_QLA23XX(ha)) {
1488 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1489 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1490 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001491 } else if (IS_FWI2_CAPABLE(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001492 if (IS_QLA83XX(ha))
1493 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
1494 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001495 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1496 else if (IS_QLA25XX(ha))
1497 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1498 else
1499 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Chad Dupuisf73cb692014-02-26 04:15:06 -05001500
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001501 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1502 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001503 if (ha->mqenable) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001504 if (!IS_QLA83XX(ha))
1505 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001506 /*
1507 * Allocate maximum buffer size for all queues.
1508 * Resizing must be done at end-of-dump processing.
1509 */
1510 mq_size += ha->max_req_queues *
1511 (req->length * sizeof(request_t));
1512 mq_size += ha->max_rsp_queues *
1513 (rsp->length * sizeof(response_t));
1514 }
Arun Easi00876ae2013-03-25 02:21:37 -04001515 if (ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001516 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001517 /* Allocate memory for Fibre Channel Event Buffer. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05001518 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
1519 !IS_QLA27XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001520 goto try_eft;
1521
Chad Dupuisf73cb692014-02-26 04:15:06 -05001522try_fce:
1523 if (ha->fce)
1524 dma_free_coherent(&ha->pdev->dev,
1525 FCE_SIZE, ha->fce, ha->fce_dma);
1526
1527 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001528 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1529 GFP_KERNEL);
1530 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001531 ql_log(ql_log_warn, vha, 0x00be,
1532 "Unable to allocate (%d KB) for FCE.\n",
1533 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001534 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001535 }
1536
1537 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001538 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001539 ha->fce_mb, &ha->fce_bufs);
1540 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001541 ql_log(ql_log_warn, vha, 0x00bf,
1542 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001543 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1544 tc_dma);
1545 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001546 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001547 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001548 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001549 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001550
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001551 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001552 ha->flags.fce_enabled = 1;
1553 ha->fce_dma = tc_dma;
1554 ha->fce = tc;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001555
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001556try_eft:
Chad Dupuisf73cb692014-02-26 04:15:06 -05001557 if (ha->eft)
1558 dma_free_coherent(&ha->pdev->dev,
1559 EFT_SIZE, ha->eft, ha->eft_dma);
1560
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001561 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001562 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001563 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001564 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001565 ql_log(ql_log_warn, vha, 0x00c1,
1566 "Unable to allocate (%d KB) for EFT.\n",
1567 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001568 goto cont_alloc;
1569 }
1570
Andrew Vasquezfc447652008-01-17 09:02:18 -08001571 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001572 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001573 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001574 ql_log(ql_log_warn, vha, 0x00c2,
1575 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001576 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1577 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001578 goto cont_alloc;
1579 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001580 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001581 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001582
1583 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001584 ha->eft_dma = tc_dma;
1585 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001586 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05001587
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001588cont_alloc:
Chad Dupuisf73cb692014-02-26 04:15:06 -05001589 if (IS_QLA27XX(ha)) {
1590 if (!ha->fw_dump_template) {
1591 ql_log(ql_log_warn, vha, 0x00ba,
1592 "Failed missing fwdump template\n");
1593 return;
1594 }
1595 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
1596 ql_dbg(ql_dbg_init, vha, 0x00fa,
1597 "-> allocating fwdump (%x bytes)...\n", dump_size);
1598 goto allocate;
1599 }
1600
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001601 req_q_size = req->length * sizeof(request_t);
1602 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001603 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001604 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001605 ha->chain_offset = dump_size;
1606 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001607
Chad Dupuisf73cb692014-02-26 04:15:06 -05001608allocate:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001609 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001610 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001611 ql_log(ql_log_warn, vha, 0x00c4,
1612 "Unable to allocate (%d KB) for firmware dump.\n",
1613 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001614
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001615 if (ha->fce) {
1616 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1617 ha->fce_dma);
1618 ha->fce = NULL;
1619 ha->fce_dma = 0;
1620 }
1621
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001622 if (ha->eft) {
1623 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1624 ha->eft_dma);
1625 ha->eft = NULL;
1626 ha->eft_dma = 0;
1627 }
1628 return;
1629 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05001630 ha->fw_dump_len = dump_size;
Chad Dupuiscfb09192011-11-18 09:03:07 -08001631 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001632 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001633
Chad Dupuisf73cb692014-02-26 04:15:06 -05001634 if (IS_QLA27XX(ha))
1635 return;
1636
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001637 ha->fw_dump->signature[0] = 'Q';
1638 ha->fw_dump->signature[1] = 'L';
1639 ha->fw_dump->signature[2] = 'G';
1640 ha->fw_dump->signature[3] = 'C';
1641 ha->fw_dump->version = __constant_htonl(1);
1642
1643 ha->fw_dump->fixed_size = htonl(fixed_size);
1644 ha->fw_dump->mem_size = htonl(mem_size);
1645 ha->fw_dump->req_q_size = htonl(req_q_size);
1646 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1647
1648 ha->fw_dump->eft_size = htonl(eft_size);
1649 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1650 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1651
1652 ha->fw_dump->header_size =
1653 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001654}
1655
Andrew Vasquez18e75552009-06-03 09:55:30 -07001656static int
1657qla81xx_mpi_sync(scsi_qla_host_t *vha)
1658{
1659#define MPS_MASK 0xe0
1660 int rval;
1661 uint16_t dc;
1662 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07001663
1664 if (!IS_QLA81XX(vha->hw))
1665 return QLA_SUCCESS;
1666
1667 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1668 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001669 ql_log(ql_log_warn, vha, 0x0105,
1670 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001671 goto done;
1672 }
1673
1674 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1675 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1676 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001677 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001678 goto done_release;
1679 }
1680
1681 dc &= MPS_MASK;
1682 if (dc == (dw & MPS_MASK))
1683 goto done_release;
1684
1685 dw &= ~MPS_MASK;
1686 dw |= dc;
1687 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1688 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001689 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001690 }
1691
1692done_release:
1693 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1694 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001695 ql_log(ql_log_warn, vha, 0x006d,
1696 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001697 }
1698
1699done:
1700 return rval;
1701}
1702
Chad Dupuis8d93f552013-01-30 03:34:37 -05001703int
1704qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
1705{
1706 /* Don't try to reallocate the array */
1707 if (req->outstanding_cmds)
1708 return QLA_SUCCESS;
1709
1710 if (!IS_FWI2_CAPABLE(ha) || (ha->mqiobase &&
1711 (ql2xmultique_tag || ql2xmaxqueues > 1)))
1712 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
1713 else {
1714 if (ha->fw_xcb_count <= ha->fw_iocb_count)
1715 req->num_outstanding_cmds = ha->fw_xcb_count;
1716 else
1717 req->num_outstanding_cmds = ha->fw_iocb_count;
1718 }
1719
1720 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1721 req->num_outstanding_cmds, GFP_KERNEL);
1722
1723 if (!req->outstanding_cmds) {
1724 /*
1725 * Try to allocate a minimal size just so we can get through
1726 * initialization.
1727 */
1728 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
1729 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1730 req->num_outstanding_cmds, GFP_KERNEL);
1731
1732 if (!req->outstanding_cmds) {
1733 ql_log(ql_log_fatal, NULL, 0x0126,
1734 "Failed to allocate memory for "
1735 "outstanding_cmds for req_que %p.\n", req);
1736 req->num_outstanding_cmds = 0;
1737 return QLA_FUNCTION_FAILED;
1738 }
1739 }
1740
1741 return QLA_SUCCESS;
1742}
1743
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001744/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 * qla2x00_setup_chip() - Load and start RISC firmware.
1746 * @ha: HA context
1747 *
1748 * Returns 0 on success.
1749 */
1750static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001751qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001753 int rval;
1754 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001755 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001756 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1757 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001758 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001759
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001760 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001761 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001762 if (rval == QLA_SUCCESS) {
1763 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001764 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001765 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001766 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001767 }
1768
Andrew Vasquez3db06522008-01-31 12:33:49 -08001769 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1770 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1771 spin_lock_irqsave(&ha->hardware_lock, flags);
1772 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1773 RD_REG_WORD(&reg->hccr);
1774 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1775 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776
Andrew Vasquez18e75552009-06-03 09:55:30 -07001777 qla81xx_mpi_sync(vha);
1778
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001780 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001781 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001782 ql_dbg(ql_dbg_init, vha, 0x00c9,
1783 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001785 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 if (rval == QLA_SUCCESS) {
1787 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001788 ql_dbg(ql_dbg_init, vha, 0x00ca,
1789 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001791 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001793 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001794enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001795 fw_major_version = ha->fw_major_version;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001796 if (IS_P3P_TYPE(ha))
Giridhar Malavali31731672011-08-16 11:31:54 -07001797 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001798 else
1799 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001800 if (rval != QLA_SUCCESS)
1801 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001802 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001803 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001804 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001805 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001806 if ((!ha->max_npiv_vports) ||
1807 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001808 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001809 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001810 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001811 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001812 qla2x00_get_resource_cnts(vha, NULL,
Chad Dupuis8d93f552013-01-30 03:34:37 -05001813 &ha->fw_xcb_count, NULL, &ha->fw_iocb_count,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001814 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001815
Chad Dupuis8d93f552013-01-30 03:34:37 -05001816 /*
1817 * Allocate the array of outstanding commands
1818 * now that we know the firmware resources.
1819 */
1820 rval = qla2x00_alloc_outstanding_cmds(ha,
1821 vha->req);
1822 if (rval != QLA_SUCCESS)
1823 goto failed;
1824
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08001825 if (!fw_major_version && ql2xallocfwdump
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001826 && !(IS_P3P_TYPE(ha)))
Giridhar Malavali08de2842011-08-16 11:31:44 -07001827 qla2x00_alloc_fw_dump(vha);
Chad Dupuis3b6e5b92013-10-30 03:38:09 -04001828 } else {
1829 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 }
1831 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001832 ql_log(ql_log_fatal, vha, 0x00cd,
1833 "ISP Firmware failed checksum.\n");
1834 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04001836 } else
1837 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838
Andrew Vasquez3db06522008-01-31 12:33:49 -08001839 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1840 /* Enable proper parity. */
1841 spin_lock_irqsave(&ha->hardware_lock, flags);
1842 if (IS_QLA2300(ha))
1843 /* SRAM parity */
1844 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1845 else
1846 /* SRAM, Instruction RAM and GP RAM parity */
1847 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1848 RD_REG_WORD(&reg->hccr);
1849 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1850 }
1851
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001852 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1853 uint32_t size;
1854
1855 rval = qla81xx_fac_get_sector_size(vha, &size);
1856 if (rval == QLA_SUCCESS) {
1857 ha->flags.fac_supported = 1;
1858 ha->fdt_block_size = size << 2;
1859 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001860 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001861 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1862 ha->fw_major_version, ha->fw_minor_version,
1863 ha->fw_subminor_version);
Joe Carnuccio1ca60e32014-02-26 04:15:02 -05001864
Chad Dupuisf73cb692014-02-26 04:15:06 -05001865 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001866 ha->flags.fac_supported = 0;
1867 rval = QLA_SUCCESS;
1868 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001869 }
1870 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001871failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001873 ql_log(ql_log_fatal, vha, 0x00cf,
1874 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 }
1876
1877 return (rval);
1878}
1879
1880/**
1881 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1882 * @ha: HA context
1883 *
1884 * Beginning of request ring has initialization control block already built
1885 * by nvram config routine.
1886 *
1887 * Returns 0 on success.
1888 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001889void
1890qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891{
1892 uint16_t cnt;
1893 response_t *pkt;
1894
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001895 rsp->ring_ptr = rsp->ring;
1896 rsp->ring_index = 0;
1897 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001898 pkt = rsp->ring_ptr;
1899 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 pkt->signature = RESPONSE_PROCESSED;
1901 pkt++;
1902 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903}
1904
1905/**
1906 * qla2x00_update_fw_options() - Read and process firmware options.
1907 * @ha: HA context
1908 *
1909 * Returns 0 on success.
1910 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001911void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001912qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913{
1914 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001915 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916
1917 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001918 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919
1920 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1921 return;
1922
1923 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001924 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1925 "Serial link options.\n");
1926 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1927 (uint8_t *)&ha->fw_seriallink_options,
1928 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929
1930 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1931 if (ha->fw_seriallink_options[3] & BIT_2) {
1932 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1933
1934 /* 1G settings */
1935 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1936 emphasis = (ha->fw_seriallink_options[2] &
1937 (BIT_4 | BIT_3)) >> 3;
1938 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001939 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 rx_sens = (ha->fw_seriallink_options[0] &
1941 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1942 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1943 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1944 if (rx_sens == 0x0)
1945 rx_sens = 0x3;
1946 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1947 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1948 ha->fw_options[10] |= BIT_5 |
1949 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1950 (tx_sens & (BIT_1 | BIT_0));
1951
1952 /* 2G settings */
1953 swing = (ha->fw_seriallink_options[2] &
1954 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1955 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1956 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001957 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 rx_sens = (ha->fw_seriallink_options[1] &
1959 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1960 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1961 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1962 if (rx_sens == 0x0)
1963 rx_sens = 0x3;
1964 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1965 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1966 ha->fw_options[11] |= BIT_5 |
1967 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1968 (tx_sens & (BIT_1 | BIT_0));
1969 }
1970
1971 /* FCP2 options. */
1972 /* Return command IOCBs without waiting for an ABTS to complete. */
1973 ha->fw_options[3] |= BIT_13;
1974
1975 /* LED scheme. */
1976 if (ha->flags.enable_led_scheme)
1977 ha->fw_options[2] |= BIT_12;
1978
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001979 /* Detect ISP6312. */
1980 if (IS_QLA6312(ha))
1981 ha->fw_options[2] |= BIT_13;
1982
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001984 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985}
1986
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001987void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001988qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001989{
1990 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001991 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001992
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001993 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07001994 return;
1995
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001996 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001997 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001998 return;
1999
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002000 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08002001 le16_to_cpu(ha->fw_seriallink_options24[1]),
2002 le16_to_cpu(ha->fw_seriallink_options24[2]),
2003 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002004 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002005 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002006 "Unable to update Serial Link options (%x).\n", rval);
2007 }
2008}
2009
2010void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002011qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002012{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002013 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002014 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002015 struct req_que *req = ha->req_q_map[0];
2016 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002017
2018 /* Setup ring parameters in initialization control block. */
2019 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
2020 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002021 ha->init_cb->request_q_length = cpu_to_le16(req->length);
2022 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
2023 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2024 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2025 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2026 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002027
2028 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
2029 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
2030 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
2031 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
2032 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
2033}
2034
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002035void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002036qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002037{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002038 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002039 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
2040 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
2041 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002042 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002043 uint16_t rid = 0;
2044 struct req_que *req = ha->req_q_map[0];
2045 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002046
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002047 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002048 icb = (struct init_cb_24xx *)ha->init_cb;
2049 icb->request_q_outpointer = __constant_cpu_to_le16(0);
2050 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002051 icb->request_q_length = cpu_to_le16(req->length);
2052 icb->response_q_length = cpu_to_le16(rsp->length);
2053 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2054 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2055 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2056 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002057
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002058 /* Setup ATIO queue dma pointers for target mode */
2059 icb->atio_q_inpointer = __constant_cpu_to_le16(0);
2060 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
2061 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
2062 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
2063
Chad Dupuisf73cb692014-02-26 04:15:06 -05002064 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002065 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
2066 icb->rid = __constant_cpu_to_le16(rid);
2067 if (ha->flags.msix_enabled) {
2068 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002069 ql_dbg(ql_dbg_init, vha, 0x00fd,
2070 "Registering vector 0x%x for base que.\n",
2071 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002072 icb->msix = cpu_to_le16(msix->entry);
2073 }
2074 /* Use alternate PCI bus number */
2075 if (MSB(rid))
2076 icb->firmware_options_2 |=
2077 __constant_cpu_to_le32(BIT_19);
2078 /* Use alternate PCI devfn */
2079 if (LSB(rid))
2080 icb->firmware_options_2 |=
2081 __constant_cpu_to_le32(BIT_18);
2082
Anirban Chakraborty31557542009-12-02 10:36:55 -08002083 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002084 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
2085 (ha->flags.msix_enabled)) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08002086 icb->firmware_options_2 &=
2087 __constant_cpu_to_le32(~BIT_22);
2088 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002089 ql_dbg(ql_dbg_init, vha, 0x00fe,
2090 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08002091 } else {
2092 icb->firmware_options_2 |=
2093 __constant_cpu_to_le32(BIT_22);
2094 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002095 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002096
2097 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
2098 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
2099 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
2100 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
2101 } else {
2102 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
2103 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
2104 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
2105 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
2106 }
Arun Easiaa230bc2013-01-30 03:34:39 -05002107 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002108
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002109 /* PCI posting */
2110 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002111}
2112
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113/**
2114 * qla2x00_init_rings() - Initializes firmware.
2115 * @ha: HA context
2116 *
2117 * Beginning of request ring has initialization control block already built
2118 * by nvram config routine.
2119 *
2120 * Returns 0 on success.
2121 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002122int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002123qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124{
2125 int rval;
2126 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002127 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002128 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002129 struct req_que *req;
2130 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002131 struct mid_init_cb_24xx *mid_init_cb =
2132 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133
2134 spin_lock_irqsave(&ha->hardware_lock, flags);
2135
2136 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002137 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002138 req = ha->req_q_map[que];
2139 if (!req)
2140 continue;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002141 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002142 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002144 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002145
2146 /* Initialize firmware. */
2147 req->ring_ptr = req->ring;
2148 req->ring_index = 0;
2149 req->cnt = req->length;
2150 }
2151
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002152 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002153 rsp = ha->rsp_q_map[que];
2154 if (!rsp)
2155 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002156 /* Initialize response queue entries */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002157 if (IS_QLAFX00(ha))
2158 qlafx00_init_response_q_entries(rsp);
2159 else
2160 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002163 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
2164 ha->tgt.atio_ring_index = 0;
2165 /* Initialize ATIO queue entries */
2166 qlt_init_atio_q_entries(vha);
2167
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002168 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
2170 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2171
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002172 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
2173
2174 if (IS_QLAFX00(ha)) {
2175 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
2176 goto next_check;
2177 }
2178
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002180 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002182 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04002183 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002184 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08002185 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002186 }
2187
Andrew Vasquez24a08132009-03-24 09:08:16 -07002188 if (IS_FWI2_CAPABLE(ha)) {
2189 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
2190 mid_init_cb->init_cb.execution_throttle =
2191 cpu_to_le16(ha->fw_xcb_count);
2192 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002193
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002194 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002195next_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002197 ql_log(ql_log_fatal, vha, 0x00d2,
2198 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002200 ql_dbg(ql_dbg_init, vha, 0x00d3,
2201 "Init Firmware -- success.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 }
2203
2204 return (rval);
2205}
2206
2207/**
2208 * qla2x00_fw_ready() - Waits for firmware ready.
2209 * @ha: HA context
2210 *
2211 * Returns 0 on success.
2212 */
2213static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002214qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215{
2216 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002217 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 uint16_t min_wait; /* Minimum wait time if loop is down */
2219 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07002220 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002221 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002223 if (IS_QLAFX00(vha->hw))
2224 return qlafx00_fw_ready(vha);
2225
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 rval = QLA_SUCCESS;
2227
2228 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002229 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
2231 /*
2232 * Firmware should take at most one RATOV to login, plus 5 seconds for
2233 * our own processing.
2234 */
2235 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
2236 wait_time = min_wait;
2237 }
2238
2239 /* Min wait time if loop down */
2240 mtime = jiffies + (min_wait * HZ);
2241
2242 /* wait time before firmware ready */
2243 wtime = jiffies + (wait_time * HZ);
2244
2245 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002246 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002247 ql_log(ql_log_info, vha, 0x801e,
2248 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249
2250 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05002251 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002252 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002254 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002255 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002257 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002258 ql_dbg(ql_dbg_taskm, vha, 0x801f,
2259 "fw_state=%x 84xx=%x.\n", state[0],
2260 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002261 if ((state[2] & FSTATE_LOGGED_IN) &&
2262 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002263 ql_dbg(ql_dbg_taskm, vha, 0x8028,
2264 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002265
2266 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002267 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002268 if (rval != QLA_SUCCESS) {
2269 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002270 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002271 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002272 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002273 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002274
2275 /* Add time taken to initialize. */
2276 cs84xx_time = jiffies - cs84xx_time;
2277 wtime += cs84xx_time;
2278 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002279 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002280 "Increasing wait time by %ld. "
2281 "New time %ld.\n", cs84xx_time,
2282 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002283 }
2284 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002285 ql_dbg(ql_dbg_taskm, vha, 0x8037,
2286 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002288 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 &ha->login_timeout, &ha->r_a_tov);
2290
2291 rval = QLA_SUCCESS;
2292 break;
2293 }
2294
2295 rval = QLA_FUNCTION_FAILED;
2296
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002297 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002298 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002300 * other than Wait for Login.
2301 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002303 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 "Cable is unplugged...\n");
2305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002306 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 break;
2308 }
2309 }
2310 } else {
2311 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07002312 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08002313 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 break;
2315 }
2316
2317 if (time_after_eq(jiffies, wtime))
2318 break;
2319
2320 /* Delay for a while */
2321 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 } while (1);
2323
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002324 ql_dbg(ql_dbg_taskm, vha, 0x803a,
2325 "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0],
2326 state[1], state[2], state[3], state[4], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
Chad Dupuiscfb09192011-11-18 09:03:07 -08002328 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002329 ql_log(ql_log_warn, vha, 0x803b,
2330 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 }
2332
2333 return (rval);
2334}
2335
2336/*
2337* qla2x00_configure_hba
2338* Setup adapter context.
2339*
2340* Input:
2341* ha = adapter state pointer.
2342*
2343* Returns:
2344* 0 = success
2345*
2346* Context:
2347* Kernel context.
2348*/
2349static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002350qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351{
2352 int rval;
2353 uint16_t loop_id;
2354 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002355 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 uint8_t al_pa;
2357 uint8_t area;
2358 uint8_t domain;
2359 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002360 struct qla_hw_data *ha = vha->hw;
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002361 unsigned long flags;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002362 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363
2364 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002365 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002366 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002368 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002369 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002370 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002371 ql_dbg(ql_dbg_disc, vha, 0x2008,
2372 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08002373 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002374 ql_log(ql_log_warn, vha, 0x2009,
2375 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002376 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
2377 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
2378 ql_log(ql_log_warn, vha, 0x1151,
2379 "Doing link init.\n");
2380 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
2381 return rval;
2382 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002383 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002384 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 return (rval);
2386 }
2387
2388 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002389 ql_log(ql_log_info, vha, 0x200a,
2390 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 return (QLA_FUNCTION_FAILED);
2392 }
2393
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002394 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395
2396 /* initialize */
2397 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2398 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002399 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400
2401 switch (topo) {
2402 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002403 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 ha->current_topology = ISP_CFG_NL;
2405 strcpy(connect_type, "(Loop)");
2406 break;
2407
2408 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002409 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002410 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 ha->current_topology = ISP_CFG_FL;
2412 strcpy(connect_type, "(FL_Port)");
2413 break;
2414
2415 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002416 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 ha->operating_mode = P2P;
2418 ha->current_topology = ISP_CFG_N;
2419 strcpy(connect_type, "(N_Port-to-N_Port)");
2420 break;
2421
2422 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002423 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002424 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 ha->operating_mode = P2P;
2426 ha->current_topology = ISP_CFG_F;
2427 strcpy(connect_type, "(F_Port)");
2428 break;
2429
2430 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002431 ql_dbg(ql_dbg_disc, vha, 0x200f,
2432 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 ha->current_topology = ISP_CFG_NL;
2434 strcpy(connect_type, "(Loop)");
2435 break;
2436 }
2437
2438 /* Save Host port and loop ID. */
2439 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002440 vha->d_id.b.domain = domain;
2441 vha->d_id.b.area = area;
2442 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002444 spin_lock_irqsave(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002445 qlt_update_vp_map(vha, SET_AL_PA);
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002446 spin_unlock_irqrestore(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002447
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002448 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002449 ql_log(ql_log_info, vha, 0x2010,
2450 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002451 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 return(rval);
2454}
2455
Giridhar Malavalia9083012010-04-12 17:59:55 -07002456inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002457qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2458 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002459{
2460 char *st, *en;
2461 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002462 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002463 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002464 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002465
2466 if (memcmp(model, BINZERO, len) != 0) {
2467 strncpy(ha->model_number, model, len);
2468 st = en = ha->model_number;
2469 en += len - 1;
2470 while (en > st) {
2471 if (*en != 0x20 && *en != 0x00)
2472 break;
2473 *en-- = '\0';
2474 }
2475
2476 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002477 if (use_tbl &&
2478 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002479 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002480 strncpy(ha->model_desc,
2481 qla2x00_model_name[index * 2 + 1],
2482 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002483 } else {
2484 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002485 if (use_tbl &&
2486 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002487 index < QLA_MODEL_NAMES) {
2488 strcpy(ha->model_number,
2489 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002490 strncpy(ha->model_desc,
2491 qla2x00_model_name[index * 2 + 1],
2492 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002493 } else {
2494 strcpy(ha->model_number, def);
2495 }
2496 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002497 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002498 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002499 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002500}
2501
David Miller4e08df32007-04-16 12:37:43 -07002502/* On sparc systems, obtain port and node WWN from firmware
2503 * properties.
2504 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002505static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002506{
2507#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002508 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002509 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002510 struct device_node *dp = pci_device_to_OF_node(pdev);
2511 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002512 int len;
2513
2514 val = of_get_property(dp, "port-wwn", &len);
2515 if (val && len >= WWN_SIZE)
2516 memcpy(nv->port_name, val, WWN_SIZE);
2517
2518 val = of_get_property(dp, "node-wwn", &len);
2519 if (val && len >= WWN_SIZE)
2520 memcpy(nv->node_name, val, WWN_SIZE);
2521#endif
2522}
2523
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524/*
2525* NVRAM configuration for ISP 2xxx
2526*
2527* Input:
2528* ha = adapter block pointer.
2529*
2530* Output:
2531* initialization control block in response_ring
2532* host adapters parameters in host adapter block
2533*
2534* Returns:
2535* 0 = success.
2536*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002537int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002538qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539{
David Miller4e08df32007-04-16 12:37:43 -07002540 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002541 uint8_t chksum = 0;
2542 uint16_t cnt;
2543 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002544 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002545 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002546 nvram_t *nv = ha->nvram;
2547 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002548 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549
David Miller4e08df32007-04-16 12:37:43 -07002550 rval = QLA_SUCCESS;
2551
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002553 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 ha->nvram_base = 0;
2555 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2556 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2557 ha->nvram_base = 0x80;
2558
2559 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002560 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002561 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2562 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002564 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2565 "Contents of NVRAM.\n");
2566 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2567 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568
2569 /* Bad NVRAM data, set defaults parameters. */
2570 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2571 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2572 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002573 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04002574 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002575 "detected: checksum=0x%x id=%c version=0x%x.\n",
2576 chksum, nv->id[0], nv->nvram_version);
2577 ql_log(ql_log_warn, vha, 0x0065,
2578 "Falling back to "
2579 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07002580
2581 /*
2582 * Set default initialization control block.
2583 */
2584 memset(nv, 0, ha->nvram_size);
2585 nv->parameter_block_version = ICB_VERSION;
2586
2587 if (IS_QLA23XX(ha)) {
2588 nv->firmware_options[0] = BIT_2 | BIT_1;
2589 nv->firmware_options[1] = BIT_7 | BIT_5;
2590 nv->add_firmware_options[0] = BIT_5;
2591 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2592 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2593 nv->special_options[1] = BIT_7;
2594 } else if (IS_QLA2200(ha)) {
2595 nv->firmware_options[0] = BIT_2 | BIT_1;
2596 nv->firmware_options[1] = BIT_7 | BIT_5;
2597 nv->add_firmware_options[0] = BIT_5;
2598 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2599 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2600 } else if (IS_QLA2100(ha)) {
2601 nv->firmware_options[0] = BIT_3 | BIT_1;
2602 nv->firmware_options[1] = BIT_5;
2603 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2604 }
2605
2606 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2607 nv->execution_throttle = __constant_cpu_to_le16(16);
2608 nv->retry_count = 8;
2609 nv->retry_delay = 1;
2610
2611 nv->port_name[0] = 33;
2612 nv->port_name[3] = 224;
2613 nv->port_name[4] = 139;
2614
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002615 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002616
2617 nv->login_timeout = 4;
2618
2619 /*
2620 * Set default host adapter parameters
2621 */
2622 nv->host_p[1] = BIT_2;
2623 nv->reset_delay = 5;
2624 nv->port_down_retry_count = 8;
2625 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2626 nv->link_down_timeout = 60;
2627
2628 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 }
2630
2631#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2632 /*
2633 * The SN2 does not provide BIOS emulation which means you can't change
2634 * potentially bogus BIOS settings. Force the use of default settings
2635 * for link rate and frame size. Hope that the rest of the settings
2636 * are valid.
2637 */
2638 if (ia64_platform_is("sn2")) {
2639 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2640 if (IS_QLA23XX(ha))
2641 nv->special_options[1] = BIT_7;
2642 }
2643#endif
2644
2645 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002646 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
2648 /*
2649 * Setup driver NVRAM options.
2650 */
2651 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2652 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2653 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2654 nv->firmware_options[1] &= ~BIT_4;
2655
2656 if (IS_QLA23XX(ha)) {
2657 nv->firmware_options[0] |= BIT_2;
2658 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002659 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002660 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661
2662 if (IS_QLA2300(ha)) {
2663 if (ha->fb_rev == FPM_2310) {
2664 strcpy(ha->model_number, "QLA2310");
2665 } else {
2666 strcpy(ha->model_number, "QLA2300");
2667 }
2668 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002669 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002670 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 }
2672 } else if (IS_QLA2200(ha)) {
2673 nv->firmware_options[0] |= BIT_2;
2674 /*
2675 * 'Point-to-point preferred, else loop' is not a safe
2676 * connection mode setting.
2677 */
2678 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2679 (BIT_5 | BIT_4)) {
2680 /* Force 'loop preferred, else point-to-point'. */
2681 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2682 nv->add_firmware_options[0] |= BIT_5;
2683 }
2684 strcpy(ha->model_number, "QLA22xx");
2685 } else /*if (IS_QLA2100(ha))*/ {
2686 strcpy(ha->model_number, "QLA2100");
2687 }
2688
2689 /*
2690 * Copy over NVRAM RISC parameter block to initialization control block.
2691 */
2692 dptr1 = (uint8_t *)icb;
2693 dptr2 = (uint8_t *)&nv->parameter_block_version;
2694 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2695 while (cnt--)
2696 *dptr1++ = *dptr2++;
2697
2698 /* Copy 2nd half. */
2699 dptr1 = (uint8_t *)icb->add_firmware_options;
2700 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2701 while (cnt--)
2702 *dptr1++ = *dptr2++;
2703
Andrew Vasquez5341e862006-05-17 15:09:16 -07002704 /* Use alternate WWN? */
2705 if (nv->host_p[1] & BIT_7) {
2706 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2707 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2708 }
2709
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 /* Prepare nodename */
2711 if ((icb->firmware_options[1] & BIT_6) == 0) {
2712 /*
2713 * Firmware will apply the following mask if the nodename was
2714 * not provided.
2715 */
2716 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2717 icb->node_name[0] &= 0xF0;
2718 }
2719
2720 /*
2721 * Set host adapter parameters.
2722 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002723
2724 /*
2725 * BIT_7 in the host-parameters section allows for modification to
2726 * internal driver logging.
2727 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002728 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08002729 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2731 /* Always load RISC code on non ISP2[12]00 chips. */
2732 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2733 ha->flags.disable_risc_code_load = 0;
2734 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2735 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2736 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002737 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002738 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739
2740 ha->operating_mode =
2741 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2742
2743 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2744 sizeof(ha->fw_seriallink_options));
2745
2746 /* save HBA serial number */
2747 ha->serial0 = icb->port_name[5];
2748 ha->serial1 = icb->port_name[6];
2749 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002750 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2751 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752
2753 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2754
2755 ha->retry_count = nv->retry_count;
2756
2757 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002758 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 nv->login_timeout = ql2xlogintimeout;
2760 if (nv->login_timeout < 4)
2761 nv->login_timeout = 4;
2762 ha->login_timeout = nv->login_timeout;
2763 icb->login_timeout = nv->login_timeout;
2764
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002765 /* Set minimum RATOV to 100 tenths of a second. */
2766 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 ha->loop_reset_delay = nv->reset_delay;
2769
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 /* Link Down Timeout = 0:
2771 *
2772 * When Port Down timer expires we will start returning
2773 * I/O's to OS with "DID_NO_CONNECT".
2774 *
2775 * Link Down Timeout != 0:
2776 *
2777 * The driver waits for the link to come up after link down
2778 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002779 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 if (nv->link_down_timeout == 0) {
2781 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002782 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 } else {
2784 ha->link_down_timeout = nv->link_down_timeout;
2785 ha->loop_down_abort_time =
2786 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002787 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 /*
2790 * Need enough time to try and get the port back.
2791 */
2792 ha->port_down_retry_count = nv->port_down_retry_count;
2793 if (qlport_down_retry)
2794 ha->port_down_retry_count = qlport_down_retry;
2795 /* Set login_retry_count */
2796 ha->login_retry_count = nv->retry_count;
2797 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2798 ha->port_down_retry_count > 3)
2799 ha->login_retry_count = ha->port_down_retry_count;
2800 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2801 ha->login_retry_count = ha->port_down_retry_count;
2802 if (ql2xloginretrycount)
2803 ha->login_retry_count = ql2xloginretrycount;
2804
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 icb->lun_enables = __constant_cpu_to_le16(0);
2806 icb->command_resource_count = 0;
2807 icb->immediate_notify_resource_count = 0;
2808 icb->timeout = __constant_cpu_to_le16(0);
2809
2810 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2811 /* Enable RIO */
2812 icb->firmware_options[0] &= ~BIT_3;
2813 icb->add_firmware_options[0] &=
2814 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2815 icb->add_firmware_options[0] |= BIT_2;
2816 icb->response_accumulation_timer = 3;
2817 icb->interrupt_delay_timer = 5;
2818
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002819 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002821 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002822 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002823 ha->zio_mode = icb->add_firmware_options[0] &
2824 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2825 ha->zio_timer = icb->interrupt_delay_timer ?
2826 icb->interrupt_delay_timer: 2;
2827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 icb->add_firmware_options[0] &=
2829 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002830 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002831 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002832 ha->zio_mode = QLA_ZIO_MODE_6;
2833
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002834 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002835 "ZIO mode %d enabled; timer delay (%d us).\n",
2836 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002838 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2839 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002840 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 }
2842 }
2843
David Miller4e08df32007-04-16 12:37:43 -07002844 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002845 ql_log(ql_log_warn, vha, 0x0069,
2846 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07002847 }
2848 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849}
2850
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002851static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002852qla2x00_rport_del(void *data)
2853{
2854 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002855 struct fc_rport *rport;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002856 scsi_qla_host_t *vha = fcport->vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002857 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002858
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002859 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002860 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002861 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002862 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002863 if (rport) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002864 fc_remote_port_delete(rport);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002865 /*
2866 * Release the target mode FC NEXUS in qla_target.c code
2867 * if target mod is enabled.
2868 */
2869 qlt_fc_port_deleted(vha, fcport);
2870 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002871}
2872
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873/**
2874 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2875 * @ha: HA context
2876 * @flags: allocation flags
2877 *
2878 * Returns a pointer to the allocated fcport, or NULL, if none available.
2879 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002880fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002881qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882{
2883 fc_port_t *fcport;
2884
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002885 fcport = kzalloc(sizeof(fc_port_t), flags);
2886 if (!fcport)
2887 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888
2889 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002890 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 fcport->port_type = FCT_UNKNOWN;
2892 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07002893 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002894 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002896 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897}
2898
2899/*
2900 * qla2x00_configure_loop
2901 * Updates Fibre Channel Device Database with what is actually on loop.
2902 *
2903 * Input:
2904 * ha = adapter block pointer.
2905 *
2906 * Returns:
2907 * 0 = success.
2908 * 1 = error.
2909 * 2 = database was full and device was not configured.
2910 */
2911static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002912qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913{
2914 int rval;
2915 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002916 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 rval = QLA_SUCCESS;
2918
2919 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002920 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2921 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002923 ql_dbg(ql_dbg_disc, vha, 0x2013,
2924 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 return (rval);
2926 }
2927 }
2928
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002929 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002930 ql_dbg(ql_dbg_disc, vha, 0x2014,
2931 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932
2933 /*
2934 * If we have both an RSCN and PORT UPDATE pending then handle them
2935 * both at the same time.
2936 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002937 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2938 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939
Michael Hernandez3064ff32009-12-15 21:29:44 -08002940 qla2x00_get_data_rate(vha);
2941
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 /* Determine what we need to do */
2943 if (ha->current_topology == ISP_CFG_FL &&
2944 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2945
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 set_bit(RSCN_UPDATE, &flags);
2947
2948 } else if (ha->current_topology == ISP_CFG_F &&
2949 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2950
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 set_bit(RSCN_UPDATE, &flags);
2952 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2953
Andrew Vasquez21333b42006-05-17 15:09:56 -07002954 } else if (ha->current_topology == ISP_CFG_N) {
2955 clear_bit(RSCN_UPDATE, &flags);
2956
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002957 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2959
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 set_bit(RSCN_UPDATE, &flags);
2961 set_bit(LOCAL_LOOP_UPDATE, &flags);
2962 }
2963
2964 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002965 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2966 ql_dbg(ql_dbg_disc, vha, 0x2015,
2967 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08002969 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002970 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 }
2972
2973 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002974 if (LOOP_TRANSITION(vha)) {
2975 ql_dbg(ql_dbg_disc, vha, 0x201e,
2976 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002978 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002979 else
2980 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 }
2982
2983 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002984 if (atomic_read(&vha->loop_down_timer) ||
2985 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 rval = QLA_FUNCTION_FAILED;
2987 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002988 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002989 ql_dbg(ql_dbg_disc, vha, 0x2069,
2990 "LOOP READY.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 }
2992 }
2993
2994 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002995 ql_dbg(ql_dbg_disc, vha, 0x206a,
2996 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002998 ql_dbg(ql_dbg_disc, vha, 0x206b,
2999 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 }
3001
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07003002 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003003 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003005 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07003006 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003007 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07003008 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 }
3010
3011 return (rval);
3012}
3013
3014
3015
3016/*
3017 * qla2x00_configure_local_loop
3018 * Updates Fibre Channel Device Database with local loop devices.
3019 *
3020 * Input:
3021 * ha = adapter block pointer.
3022 *
3023 * Returns:
3024 * 0 = success.
3025 */
3026static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003027qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028{
3029 int rval, rval2;
3030 int found_devs;
3031 int found;
3032 fc_port_t *fcport, *new_fcport;
3033
3034 uint16_t index;
3035 uint16_t entries;
3036 char *id_iter;
3037 uint16_t loop_id;
3038 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003039 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040
3041 found_devs = 0;
3042 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08003043 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08003046 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003047 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 &entries);
3049 if (rval != QLA_SUCCESS)
3050 goto cleanup_allocation;
3051
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003052 ql_dbg(ql_dbg_disc, vha, 0x2017,
3053 "Entries in ID list (%d).\n", entries);
3054 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
3055 (uint8_t *)ha->gid_list,
3056 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057
3058 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003059 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003061 ql_log(ql_log_warn, vha, 0x2018,
3062 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 rval = QLA_MEMORY_ALLOC_FAILED;
3064 goto cleanup_allocation;
3065 }
3066 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3067
3068 /*
3069 * Mark local devices that were present with FCF_DEVICE_LOST for now.
3070 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003071 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 if (atomic_read(&fcport->state) == FCS_ONLINE &&
3073 fcport->port_type != FCT_BROADCAST &&
3074 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3075
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003076 ql_dbg(ql_dbg_disc, vha, 0x2019,
3077 "Marking port lost loop_id=0x%04x.\n",
3078 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079
Chad Dupuisec426e12011-03-30 11:46:32 -07003080 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 }
3082 }
3083
3084 /* Add devices to port list. */
3085 id_iter = (char *)ha->gid_list;
3086 for (index = 0; index < entries; index++) {
3087 domain = ((struct gid_list_info *)id_iter)->domain;
3088 area = ((struct gid_list_info *)id_iter)->area;
3089 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003090 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 loop_id = (uint16_t)
3092 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003093 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 loop_id = le16_to_cpu(
3095 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003096 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097
3098 /* Bypass reserved domain fields. */
3099 if ((domain & 0xf0) == 0xf0)
3100 continue;
3101
3102 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003103 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003104 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 continue;
3106
3107 /* Bypass invalid local loop ID. */
3108 if (loop_id > LAST_LOCAL_LOOP_ID)
3109 continue;
3110
Arun Easi370d5502012-08-22 14:21:10 -04003111 memset(new_fcport, 0, sizeof(fc_port_t));
3112
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 /* Fill in member data. */
3114 new_fcport->d_id.b.domain = domain;
3115 new_fcport->d_id.b.area = area;
3116 new_fcport->d_id.b.al_pa = al_pa;
3117 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003118 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003120 ql_dbg(ql_dbg_disc, vha, 0x201a,
3121 "Failed to retrieve fcport information "
3122 "-- get_port_database=%x, loop_id=0x%04x.\n",
3123 rval2, new_fcport->loop_id);
3124 ql_dbg(ql_dbg_disc, vha, 0x201b,
3125 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003126 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 continue;
3128 }
3129
3130 /* Check for matching device in port list. */
3131 found = 0;
3132 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003133 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 if (memcmp(new_fcport->port_name, fcport->port_name,
3135 WWN_SIZE))
3136 continue;
3137
Shyam Sundarddb9b122009-03-24 09:08:10 -07003138 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 fcport->loop_id = new_fcport->loop_id;
3140 fcport->port_type = new_fcport->port_type;
3141 fcport->d_id.b24 = new_fcport->d_id.b24;
3142 memcpy(fcport->node_name, new_fcport->node_name,
3143 WWN_SIZE);
3144
3145 found++;
3146 break;
3147 }
3148
3149 if (!found) {
3150 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003151 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152
3153 /* Allocate a new replacement fcport. */
3154 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003155 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003157 ql_log(ql_log_warn, vha, 0x201c,
3158 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 rval = QLA_MEMORY_ALLOC_FAILED;
3160 goto cleanup_allocation;
3161 }
3162 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3163 }
3164
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003165 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003166 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003167
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003168 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169
3170 found_devs++;
3171 }
3172
3173cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003174 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175
3176 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003177 ql_dbg(ql_dbg_disc, vha, 0x201d,
3178 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 }
3180
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 return (rval);
3182}
3183
3184static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003185qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003186{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003187 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003188 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003189 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003190
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07003191 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003192 return;
3193
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07003194 if (atomic_read(&fcport->state) != FCS_ONLINE)
3195 return;
3196
Andrew Vasquez39bd9622007-09-20 14:07:34 -07003197 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
3198 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003199 return;
3200
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003201 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003202 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003203 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003204 ql_dbg(ql_dbg_disc, vha, 0x2004,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003205 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
3206 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003207 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003208 ql_dbg(ql_dbg_disc, vha, 0x2005,
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003209 "iIDMA adjusted to %s GB/s on %8phN.\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -05003210 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Oleksandr Khoshaba7b8335582013-08-27 01:37:27 -04003211 fcport->port_name);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003212 }
3213}
3214
Adrian Bunk23be3312006-11-24 02:46:01 +01003215static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003216qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05003217{
3218 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05003219 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003220 unsigned long flags;
8482e1182005-04-17 15:04:54 -05003221
Andrew Vasquezac280b62009-08-20 11:06:05 -07003222 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05003223
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07003224 rport_ids.node_name = wwn_to_u64(fcport->node_name);
3225 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05003226 rport_ids.port_id = fcport->d_id.b.domain << 16 |
3227 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
3228 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003229 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07003230 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003231 ql_log(ql_log_warn, vha, 0x2006,
3232 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07003233 return;
3234 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003235 /*
3236 * Create target mode FC NEXUS in qla_target.c if target mode is
3237 * enabled..
3238 */
3239 qlt_fc_port_added(vha, fcport);
3240
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003241 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003242 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003243 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003244
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003245 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003246
3247 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05003248 if (fcport->port_type == FCT_INITIATOR)
3249 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3250 if (fcport->port_type == FCT_TARGET)
3251 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003252 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05003253}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254
3255/*
Adrian Bunk23be3312006-11-24 02:46:01 +01003256 * qla2x00_update_fcport
3257 * Updates device on list.
3258 *
3259 * Input:
3260 * ha = adapter block pointer.
3261 * fcport = port structure pointer.
3262 *
3263 * Return:
3264 * 0 - Success
3265 * BIT_0 - error
3266 *
3267 * Context:
3268 * Kernel context.
3269 */
3270void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003271qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01003272{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003273 fcport->vha = vha;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003274
3275 if (IS_QLAFX00(vha->hw)) {
3276 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
3277 qla2x00_reg_remote_port(vha, fcport);
3278 return;
3279 }
Adrian Bunk23be3312006-11-24 02:46:01 +01003280 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003281 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01003282
Joe Carnuccio1f93da522012-11-21 02:40:38 -05003283 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003284 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08003285 qla24xx_update_fcport_fcp_prio(vha, fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003286 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01003287}
3288
3289/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 * qla2x00_configure_fabric
3291 * Setup SNS devices with loop ID's.
3292 *
3293 * Input:
3294 * ha = adapter block pointer.
3295 *
3296 * Returns:
3297 * 0 = success.
3298 * BIT_0 = error
3299 */
3300static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003301qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302{
Arun Easib3b02e62012-02-09 11:15:39 -08003303 int rval;
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003304 fc_port_t *fcport, *fcptemp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 uint16_t next_loopid;
3306 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003307 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003309 struct qla_hw_data *ha = vha->hw;
3310 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311
3312 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003313 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003314 loop_id = NPH_F_PORT;
3315 else
3316 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003317 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003319 ql_dbg(ql_dbg_disc, vha, 0x201f,
3320 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003322 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 return (QLA_SUCCESS);
3324 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003325 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07003328 /* FDMI support. */
3329 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003330 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
3331 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07003332
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003334 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003335 loop_id = NPH_SNS;
3336 else
3337 loop_id = SIMPLE_NAME_SERVER;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003338 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
3339 0xfc, mb, BIT_1|BIT_0);
3340 if (rval != QLA_SUCCESS) {
3341 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003342 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003343 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003345 ql_dbg(ql_dbg_disc, vha, 0x2042,
3346 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3347 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
3348 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 return (QLA_SUCCESS);
3350 }
3351
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003352 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3353 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003355 ql_dbg(ql_dbg_disc, vha, 0x2045,
3356 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003358 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003360 ql_dbg(ql_dbg_disc, vha, 0x2049,
3361 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003363 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003365 ql_dbg(ql_dbg_disc, vha, 0x204f,
3366 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003367 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003369 ql_dbg(ql_dbg_disc, vha, 0x2053,
3370 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 }
3372 }
3373
Joe Carnuccio827210b2013-02-08 01:57:57 -05003374#define QLA_FCPORT_SCAN 1
3375#define QLA_FCPORT_FOUND 2
3376
3377 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3378 fcport->scan_state = QLA_FCPORT_SCAN;
3379 }
3380
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003381 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 if (rval != QLA_SUCCESS)
3383 break;
3384
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003385 /*
3386 * Logout all previous fabric devices marked lost, except
3387 * FCP2 devices.
3388 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003389 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3390 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 break;
3392
3393 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3394 continue;
3395
Joe Carnuccio827210b2013-02-08 01:57:57 -05003396 if (fcport->scan_state == QLA_FCPORT_SCAN &&
Arun Easib3b02e62012-02-09 11:15:39 -08003397 atomic_read(&fcport->state) == FCS_ONLINE) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003398 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003399 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003401 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402 fcport->port_type != FCT_INITIATOR &&
3403 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003404 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003405 fcport->loop_id,
3406 fcport->d_id.b.domain,
3407 fcport->d_id.b.area,
3408 fcport->d_id.b.al_pa);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003409 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 }
3411 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003414 /* Starting free loop ID. */
3415 next_loopid = ha->min_external_loopid;
3416
3417 /*
3418 * Scan through our port list and login entries that need to be
3419 * logged in.
3420 */
3421 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3422 if (atomic_read(&vha->loop_down_timer) ||
3423 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3424 break;
3425
3426 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3427 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3428 continue;
3429
3430 if (fcport->loop_id == FC_NO_LOOP_ID) {
3431 fcport->loop_id = next_loopid;
3432 rval = qla2x00_find_new_loop_id(
3433 base_vha, fcport);
3434 if (rval != QLA_SUCCESS) {
3435 /* Ran out of IDs to use */
3436 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 }
3438 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003439 /* Login and update database */
3440 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
3441 }
3442
3443 /* Exit if out of loop IDs. */
3444 if (rval != QLA_SUCCESS) {
3445 break;
3446 }
3447
3448 /*
3449 * Login and add the new devices to our port list.
3450 */
3451 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3452 if (atomic_read(&vha->loop_down_timer) ||
3453 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3454 break;
3455
3456 /* Find a new loop ID to use. */
3457 fcport->loop_id = next_loopid;
3458 rval = qla2x00_find_new_loop_id(base_vha, fcport);
3459 if (rval != QLA_SUCCESS) {
3460 /* Ran out of IDs to use */
3461 break;
3462 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463
bdf79622005-04-17 15:06:53 -05003464 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003465 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003466
3467 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468 }
3469 } while (0);
3470
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003471 /* Free all new device structures not processed. */
3472 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3473 list_del(&fcport->list);
3474 kfree(fcport);
3475 }
3476
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003478 ql_dbg(ql_dbg_disc, vha, 0x2068,
3479 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 }
3481
3482 return (rval);
3483}
3484
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485/*
3486 * qla2x00_find_all_fabric_devs
3487 *
3488 * Input:
3489 * ha = adapter block pointer.
3490 * dev = database device entry pointer.
3491 *
3492 * Returns:
3493 * 0 = success.
3494 *
3495 * Context:
3496 * Kernel context.
3497 */
3498static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003499qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3500 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501{
3502 int rval;
3503 uint16_t loop_id;
3504 fc_port_t *fcport, *new_fcport, *fcptemp;
3505 int found;
3506
3507 sw_info_t *swl;
3508 int swl_idx;
3509 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003510 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003511 struct qla_hw_data *ha = vha->hw;
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05003512 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513
3514 rval = QLA_SUCCESS;
3515
3516 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08003517 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08003518 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08003519 GFP_KERNEL);
3520 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003521 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003523 ql_dbg(ql_dbg_disc, vha, 0x2054,
3524 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08003526 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003527 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003529 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003531 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003533 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003534 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3535 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003537
3538 /* If other queries succeeded probe for FC-4 type */
3539 if (swl)
3540 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541 }
3542 swl_idx = 0;
3543
3544 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003545 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003547 ql_log(ql_log_warn, vha, 0x205e,
3548 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 return (QLA_MEMORY_ALLOC_FAILED);
3550 }
3551 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 /* Set start port ID scan at adapter ID. */
3553 first_dev = 1;
3554 last_dev = 0;
3555
3556 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003557 loop_id = ha->min_external_loopid;
3558 for (; loop_id <= ha->max_loop_id; loop_id++) {
3559 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560 continue;
3561
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003562 if (ha->current_topology == ISP_CFG_FL &&
3563 (atomic_read(&vha->loop_down_timer) ||
3564 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003565 atomic_set(&vha->loop_down_timer, 0);
3566 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3567 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003569 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570
3571 if (swl != NULL) {
3572 if (last_dev) {
3573 wrap.b24 = new_fcport->d_id.b24;
3574 } else {
3575 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3576 memcpy(new_fcport->node_name,
3577 swl[swl_idx].node_name, WWN_SIZE);
3578 memcpy(new_fcport->port_name,
3579 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003580 memcpy(new_fcport->fabric_port_name,
3581 swl[swl_idx].fabric_port_name, WWN_SIZE);
3582 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003583 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584
3585 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3586 last_dev = 1;
3587 }
3588 swl_idx++;
3589 }
3590 } else {
3591 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003592 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003594 ql_log(ql_log_warn, vha, 0x2064,
3595 "SNS scan failed -- assuming "
3596 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597 list_for_each_entry_safe(fcport, fcptemp,
3598 new_fcports, list) {
3599 list_del(&fcport->list);
3600 kfree(fcport);
3601 }
3602 rval = QLA_SUCCESS;
3603 break;
3604 }
3605 }
3606
3607 /* If wrap on switch device list, exit. */
3608 if (first_dev) {
3609 wrap.b24 = new_fcport->d_id.b24;
3610 first_dev = 0;
3611 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003612 ql_dbg(ql_dbg_disc, vha, 0x2065,
3613 "Device wrap (%02x%02x%02x).\n",
3614 new_fcport->d_id.b.domain,
3615 new_fcport->d_id.b.area,
3616 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 break;
3618 }
3619
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003620 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003621 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003622 continue;
3623
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003624 /* Bypass virtual ports of the same host. */
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05003625 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
3626 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003627
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003628 /* Bypass if same domain and area of adapter. */
3629 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003630 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003631 ISP_CFG_FL)
3632 continue;
3633
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 /* Bypass reserved domain fields. */
3635 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3636 continue;
3637
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003638 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003639 if (ql2xgffidenable &&
3640 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3641 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003642 continue;
3643
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644 /* Locate matching device in database. */
3645 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003646 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647 if (memcmp(new_fcport->port_name, fcport->port_name,
3648 WWN_SIZE))
3649 continue;
3650
Joe Carnuccio827210b2013-02-08 01:57:57 -05003651 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08003652
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653 found++;
3654
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003655 /* Update port state. */
3656 memcpy(fcport->fabric_port_name,
3657 new_fcport->fabric_port_name, WWN_SIZE);
3658 fcport->fp_speed = new_fcport->fp_speed;
3659
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660 /*
3661 * If address the same and state FCS_ONLINE, nothing
3662 * changed.
3663 */
3664 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3665 atomic_read(&fcport->state) == FCS_ONLINE) {
3666 break;
3667 }
3668
3669 /*
3670 * If device was not a fabric device before.
3671 */
3672 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3673 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04003674 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 fcport->flags |= (FCF_FABRIC_DEVICE |
3676 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677 break;
3678 }
3679
3680 /*
3681 * Port ID changed or device was marked to be updated;
3682 * Log it out if still logged in and mark it for
3683 * relogin later.
3684 */
3685 fcport->d_id.b24 = new_fcport->d_id.b24;
3686 fcport->flags |= FCF_LOGIN_NEEDED;
3687 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003688 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Arun Easi0eba25d2012-02-09 11:15:58 -08003689 (fcport->flags & FCF_ASYNC_SENT) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690 fcport->port_type != FCT_INITIATOR &&
3691 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003692 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003693 fcport->d_id.b.domain, fcport->d_id.b.area,
3694 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003695 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 }
3697
3698 break;
3699 }
3700
3701 if (found)
3702 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703 /* If device was not in our fcports list, then add it. */
3704 list_add_tail(&new_fcport->list, new_fcports);
3705
3706 /* Allocate a new replacement fcport. */
3707 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003708 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003710 ql_log(ql_log_warn, vha, 0x2066,
3711 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 return (QLA_MEMORY_ALLOC_FAILED);
3713 }
3714 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3715 new_fcport->d_id.b24 = nxt_d_id.b24;
3716 }
3717
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003718 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 return (rval);
3721}
3722
3723/*
3724 * qla2x00_find_new_loop_id
3725 * Scan through our port list and find a new usable loop ID.
3726 *
3727 * Input:
3728 * ha: adapter state pointer.
3729 * dev: port structure pointer.
3730 *
3731 * Returns:
3732 * qla2x00 local function return status code.
3733 *
3734 * Context:
3735 * Kernel context.
3736 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003737int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003738qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739{
3740 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003741 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07003742 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743
3744 rval = QLA_SUCCESS;
3745
Chad Dupuis5f16b332012-08-22 14:21:00 -04003746 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747
Chad Dupuis5f16b332012-08-22 14:21:00 -04003748 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
3749 LOOPID_MAP_SIZE);
3750 if (dev->loop_id >= LOOPID_MAP_SIZE ||
3751 qla2x00_is_reserved_id(vha, dev->loop_id)) {
3752 dev->loop_id = FC_NO_LOOP_ID;
3753 rval = QLA_FUNCTION_FAILED;
3754 } else
3755 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756
Chad Dupuis5f16b332012-08-22 14:21:00 -04003757 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758
Chad Dupuis5f16b332012-08-22 14:21:00 -04003759 if (rval == QLA_SUCCESS)
3760 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
3761 "Assigning new loopid=%x, portid=%x.\n",
3762 dev->loop_id, dev->d_id.b24);
3763 else
3764 ql_log(ql_log_warn, dev->vha, 0x2087,
3765 "No loop_id's available, portid=%x.\n",
3766 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767
3768 return (rval);
3769}
3770
3771/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 * qla2x00_fabric_dev_login
3773 * Login fabric target device and update FC port database.
3774 *
3775 * Input:
3776 * ha: adapter state pointer.
3777 * fcport: port structure list pointer.
3778 * next_loopid: contains value of a new loop ID that can be used
3779 * by the next login attempt.
3780 *
3781 * Returns:
3782 * qla2x00 local function return status code.
3783 *
3784 * Context:
3785 * Kernel context.
3786 */
3787static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003788qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 uint16_t *next_loopid)
3790{
3791 int rval;
3792 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003793 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003794 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795
3796 rval = QLA_SUCCESS;
3797 retry = 0;
3798
Andrew Vasquezac280b62009-08-20 11:06:05 -07003799 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003800 if (fcport->flags & FCF_ASYNC_SENT)
3801 return rval;
3802 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003803 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3804 if (!rval)
3805 return rval;
3806 }
3807
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003808 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003809 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003811 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003812 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003813 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003814 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003815 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003817 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003818 fcport->d_id.b.domain, fcport->d_id.b.area,
3819 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003820 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003822 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 }
Chad Dupuis0b91d112012-02-09 11:15:42 -08003824 } else {
3825 /* Retry Login. */
3826 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827 }
3828
3829 return (rval);
3830}
3831
3832/*
3833 * qla2x00_fabric_login
3834 * Issue fabric login command.
3835 *
3836 * Input:
3837 * ha = adapter block pointer.
3838 * device = pointer to FC device type structure.
3839 *
3840 * Returns:
3841 * 0 - Login successfully
3842 * 1 - Login failed
3843 * 2 - Initiator device
3844 * 3 - Fatal error
3845 */
3846int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003847qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 uint16_t *next_loopid)
3849{
3850 int rval;
3851 int retry;
3852 uint16_t tmp_loopid;
3853 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003854 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855
3856 retry = 0;
3857 tmp_loopid = 0;
3858
3859 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003860 ql_dbg(ql_dbg_disc, vha, 0x2000,
3861 "Trying Fabric Login w/loop id 0x%04x for port "
3862 "%02x%02x%02x.\n",
3863 fcport->loop_id, fcport->d_id.b.domain,
3864 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003865
3866 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08003867 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 fcport->d_id.b.domain, fcport->d_id.b.area,
3869 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08003870 if (rval != QLA_SUCCESS) {
3871 return rval;
3872 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873 if (mb[0] == MBS_PORT_ID_USED) {
3874 /*
3875 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003876 * recommends the driver perform an implicit login with
3877 * the specified ID again. The ID we just used is save
3878 * here so we return with an ID that can be tried by
3879 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880 */
3881 retry++;
3882 tmp_loopid = fcport->loop_id;
3883 fcport->loop_id = mb[1];
3884
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003885 ql_dbg(ql_dbg_disc, vha, 0x2001,
3886 "Fabric Login: port in use - next loop "
3887 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003889 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890
3891 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3892 /*
3893 * Login succeeded.
3894 */
3895 if (retry) {
3896 /* A retry occurred before. */
3897 *next_loopid = tmp_loopid;
3898 } else {
3899 /*
3900 * No retry occurred before. Just increment the
3901 * ID value for next login.
3902 */
3903 *next_loopid = (fcport->loop_id + 1);
3904 }
3905
3906 if (mb[1] & BIT_0) {
3907 fcport->port_type = FCT_INITIATOR;
3908 } else {
3909 fcport->port_type = FCT_TARGET;
3910 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003911 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 }
3913 }
3914
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003915 if (mb[10] & BIT_0)
3916 fcport->supported_classes |= FC_COS_CLASS2;
3917 if (mb[10] & BIT_1)
3918 fcport->supported_classes |= FC_COS_CLASS3;
3919
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003920 if (IS_FWI2_CAPABLE(ha)) {
3921 if (mb[10] & BIT_7)
3922 fcport->flags |=
3923 FCF_CONF_COMP_SUPPORTED;
3924 }
3925
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 rval = QLA_SUCCESS;
3927 break;
3928 } else if (mb[0] == MBS_LOOP_ID_USED) {
3929 /*
3930 * Loop ID already used, try next loop ID.
3931 */
3932 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003933 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 if (rval != QLA_SUCCESS) {
3935 /* Ran out of loop IDs to use */
3936 break;
3937 }
3938 } else if (mb[0] == MBS_COMMAND_ERROR) {
3939 /*
3940 * Firmware possibly timed out during login. If NO
3941 * retries are left to do then the device is declared
3942 * dead.
3943 */
3944 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003945 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003946 fcport->d_id.b.domain, fcport->d_id.b.area,
3947 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003948 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949
3950 rval = 1;
3951 break;
3952 } else {
3953 /*
3954 * unrecoverable / not handled error
3955 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003956 ql_dbg(ql_dbg_disc, vha, 0x2002,
3957 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
3958 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
3959 fcport->d_id.b.area, fcport->d_id.b.al_pa,
3960 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961
3962 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003963 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003964 fcport->d_id.b.domain, fcport->d_id.b.area,
3965 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003966 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003967 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968
3969 rval = 3;
3970 break;
3971 }
3972 }
3973
3974 return (rval);
3975}
3976
3977/*
3978 * qla2x00_local_device_login
3979 * Issue local device login command.
3980 *
3981 * Input:
3982 * ha = adapter block pointer.
3983 * loop_id = loop id of device to login to.
3984 *
3985 * Returns (Where's the #define!!!!):
3986 * 0 - Login successfully
3987 * 1 - Login failed
3988 * 3 - Fatal error
3989 */
3990int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003991qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992{
3993 int rval;
3994 uint16_t mb[MAILBOX_REGISTER_COUNT];
3995
3996 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003997 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 if (rval == QLA_SUCCESS) {
3999 /* Interrogate mailbox registers for any errors */
4000 if (mb[0] == MBS_COMMAND_ERROR)
4001 rval = 1;
4002 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
4003 /* device not in PCB table */
4004 rval = 3;
4005 }
4006
4007 return (rval);
4008}
4009
4010/*
4011 * qla2x00_loop_resync
4012 * Resync with fibre channel devices.
4013 *
4014 * Input:
4015 * ha = adapter block pointer.
4016 *
4017 * Returns:
4018 * 0 = success
4019 */
4020int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004021qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004023 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004025 struct req_que *req;
4026 struct rsp_que *rsp;
4027
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004028 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004029 req = vha->hw->req_q_map[0];
4030 else
4031 req = vha->req;
4032 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004034 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4035 if (vha->flags.online) {
4036 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4038 wait_time = 256;
4039 do {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004040 if (!IS_QLAFX00(vha->hw)) {
4041 /*
4042 * Issue a marker after FW becomes
4043 * ready.
4044 */
4045 qla2x00_marker(vha, req, rsp, 0, 0,
4046 MK_SYNC_ALL);
4047 vha->marker_needed = 0;
4048 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049
4050 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004051 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004053 if (IS_QLAFX00(vha->hw))
4054 qlafx00_configure_devices(vha);
4055 else
4056 qla2x00_configure_loop(vha);
4057
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004059 } while (!atomic_read(&vha->loop_down_timer) &&
4060 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4061 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4062 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 }
4065
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004066 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004069 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004070 ql_dbg(ql_dbg_disc, vha, 0x206c,
4071 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072
4073 return (rval);
4074}
4075
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004076/*
4077* qla2x00_perform_loop_resync
4078* Description: This function will set the appropriate flags and call
4079* qla2x00_loop_resync. If successful loop will be resynced
4080* Arguments : scsi_qla_host_t pointer
4081* returm : Success or Failure
4082*/
4083
4084int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
4085{
4086 int32_t rval = 0;
4087
4088 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
4089 /*Configure the flags so that resync happens properly*/
4090 atomic_set(&ha->loop_down_timer, 0);
4091 if (!(ha->device_flags & DFLG_NO_CABLE)) {
4092 atomic_set(&ha->loop_state, LOOP_UP);
4093 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4094 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
4095 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4096
4097 rval = qla2x00_loop_resync(ha);
4098 } else
4099 atomic_set(&ha->loop_state, LOOP_DEAD);
4100
4101 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
4102 }
4103
4104 return rval;
4105}
4106
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107void
Andrew Vasquez67becc02009-08-25 11:36:20 -07004108qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004109{
4110 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07004111 struct scsi_qla_host *vha;
4112 struct qla_hw_data *ha = base_vha->hw;
4113 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004114
Arun Easifeafb7b2010-09-03 14:57:00 -07004115 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004116 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07004117 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
4118 atomic_inc(&vha->vref_count);
4119 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08004120 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07004121 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
4122 spin_unlock_irqrestore(&ha->vport_slock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07004123 qla2x00_rport_del(fcport);
Arun Easifeafb7b2010-09-03 14:57:00 -07004124 spin_lock_irqsave(&ha->vport_slock, flags);
4125 }
4126 }
4127 atomic_dec(&vha->vref_count);
4128 }
4129 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004130}
4131
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004132/* Assumes idc_lock always held on entry */
4133void
4134qla83xx_reset_ownership(scsi_qla_host_t *vha)
4135{
4136 struct qla_hw_data *ha = vha->hw;
4137 uint32_t drv_presence, drv_presence_mask;
4138 uint32_t dev_part_info1, dev_part_info2, class_type;
4139 uint32_t class_type_mask = 0x3;
4140 uint16_t fcoe_other_function = 0xffff, i;
4141
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004142 if (IS_QLA8044(ha)) {
4143 drv_presence = qla8044_rd_direct(vha,
4144 QLA8044_CRB_DRV_ACTIVE_INDEX);
4145 dev_part_info1 = qla8044_rd_direct(vha,
4146 QLA8044_CRB_DEV_PART_INFO_INDEX);
4147 dev_part_info2 = qla8044_rd_direct(vha,
4148 QLA8044_CRB_DEV_PART_INFO2);
4149 } else {
4150 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4151 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
4152 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
4153 }
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004154 for (i = 0; i < 8; i++) {
4155 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
4156 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4157 (i != ha->portnum)) {
4158 fcoe_other_function = i;
4159 break;
4160 }
4161 }
4162 if (fcoe_other_function == 0xffff) {
4163 for (i = 0; i < 8; i++) {
4164 class_type = ((dev_part_info2 >> (i * 4)) &
4165 class_type_mask);
4166 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4167 ((i + 8) != ha->portnum)) {
4168 fcoe_other_function = i + 8;
4169 break;
4170 }
4171 }
4172 }
4173 /*
4174 * Prepare drv-presence mask based on fcoe functions present.
4175 * However consider only valid physical fcoe function numbers (0-15).
4176 */
4177 drv_presence_mask = ~((1 << (ha->portnum)) |
4178 ((fcoe_other_function == 0xffff) ?
4179 0 : (1 << (fcoe_other_function))));
4180
4181 /* We are the reset owner iff:
4182 * - No other protocol drivers present.
4183 * - This is the lowest among fcoe functions. */
4184 if (!(drv_presence & drv_presence_mask) &&
4185 (ha->portnum < fcoe_other_function)) {
4186 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
4187 "This host is Reset owner.\n");
4188 ha->flags.nic_core_reset_owner = 1;
4189 }
4190}
4191
Saurav Kashyapfa492632012-11-21 02:40:29 -05004192static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004193__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
4194{
4195 int rval = QLA_SUCCESS;
4196 struct qla_hw_data *ha = vha->hw;
4197 uint32_t drv_ack;
4198
4199 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4200 if (rval == QLA_SUCCESS) {
4201 drv_ack |= (1 << ha->portnum);
4202 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4203 }
4204
4205 return rval;
4206}
4207
Saurav Kashyapfa492632012-11-21 02:40:29 -05004208static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004209__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
4210{
4211 int rval = QLA_SUCCESS;
4212 struct qla_hw_data *ha = vha->hw;
4213 uint32_t drv_ack;
4214
4215 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4216 if (rval == QLA_SUCCESS) {
4217 drv_ack &= ~(1 << ha->portnum);
4218 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4219 }
4220
4221 return rval;
4222}
4223
Saurav Kashyapfa492632012-11-21 02:40:29 -05004224static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004225qla83xx_dev_state_to_string(uint32_t dev_state)
4226{
4227 switch (dev_state) {
4228 case QLA8XXX_DEV_COLD:
4229 return "COLD/RE-INIT";
4230 case QLA8XXX_DEV_INITIALIZING:
4231 return "INITIALIZING";
4232 case QLA8XXX_DEV_READY:
4233 return "READY";
4234 case QLA8XXX_DEV_NEED_RESET:
4235 return "NEED RESET";
4236 case QLA8XXX_DEV_NEED_QUIESCENT:
4237 return "NEED QUIESCENT";
4238 case QLA8XXX_DEV_FAILED:
4239 return "FAILED";
4240 case QLA8XXX_DEV_QUIESCENT:
4241 return "QUIESCENT";
4242 default:
4243 return "Unknown";
4244 }
4245}
4246
4247/* Assumes idc-lock always held on entry */
4248void
4249qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
4250{
4251 struct qla_hw_data *ha = vha->hw;
4252 uint32_t idc_audit_reg = 0, duration_secs = 0;
4253
4254 switch (audit_type) {
4255 case IDC_AUDIT_TIMESTAMP:
4256 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
4257 idc_audit_reg = (ha->portnum) |
4258 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
4259 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4260 break;
4261
4262 case IDC_AUDIT_COMPLETION:
4263 duration_secs = ((jiffies_to_msecs(jiffies) -
4264 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
4265 idc_audit_reg = (ha->portnum) |
4266 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
4267 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4268 break;
4269
4270 default:
4271 ql_log(ql_log_warn, vha, 0xb078,
4272 "Invalid audit type specified.\n");
4273 break;
4274 }
4275}
4276
4277/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05004278static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004279qla83xx_initiating_reset(scsi_qla_host_t *vha)
4280{
4281 struct qla_hw_data *ha = vha->hw;
4282 uint32_t idc_control, dev_state;
4283
4284 __qla83xx_get_idc_control(vha, &idc_control);
4285 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
4286 ql_log(ql_log_info, vha, 0xb080,
4287 "NIC Core reset has been disabled. idc-control=0x%x\n",
4288 idc_control);
4289 return QLA_FUNCTION_FAILED;
4290 }
4291
4292 /* Set NEED-RESET iff in READY state and we are the reset-owner */
4293 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4294 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
4295 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
4296 QLA8XXX_DEV_NEED_RESET);
4297 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
4298 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
4299 } else {
4300 const char *state = qla83xx_dev_state_to_string(dev_state);
4301 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
4302
4303 /* SV: XXX: Is timeout required here? */
4304 /* Wait for IDC state change READY -> NEED_RESET */
4305 while (dev_state == QLA8XXX_DEV_READY) {
4306 qla83xx_idc_unlock(vha, 0);
4307 msleep(200);
4308 qla83xx_idc_lock(vha, 0);
4309 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4310 }
4311 }
4312
4313 /* Send IDC ack by writing to drv-ack register */
4314 __qla83xx_set_drv_ack(vha);
4315
4316 return QLA_SUCCESS;
4317}
4318
4319int
4320__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
4321{
4322 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4323}
4324
4325int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004326__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
4327{
4328 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4329}
4330
Saurav Kashyapfa492632012-11-21 02:40:29 -05004331static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004332qla83xx_check_driver_presence(scsi_qla_host_t *vha)
4333{
4334 uint32_t drv_presence = 0;
4335 struct qla_hw_data *ha = vha->hw;
4336
4337 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4338 if (drv_presence & (1 << ha->portnum))
4339 return QLA_SUCCESS;
4340 else
4341 return QLA_TEST_FAILED;
4342}
4343
4344int
4345qla83xx_nic_core_reset(scsi_qla_host_t *vha)
4346{
4347 int rval = QLA_SUCCESS;
4348 struct qla_hw_data *ha = vha->hw;
4349
4350 ql_dbg(ql_dbg_p3p, vha, 0xb058,
4351 "Entered %s().\n", __func__);
4352
4353 if (vha->device_flags & DFLG_DEV_FAILED) {
4354 ql_log(ql_log_warn, vha, 0xb059,
4355 "Device in unrecoverable FAILED state.\n");
4356 return QLA_FUNCTION_FAILED;
4357 }
4358
4359 qla83xx_idc_lock(vha, 0);
4360
4361 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
4362 ql_log(ql_log_warn, vha, 0xb05a,
4363 "Function=0x%x has been removed from IDC participation.\n",
4364 ha->portnum);
4365 rval = QLA_FUNCTION_FAILED;
4366 goto exit;
4367 }
4368
4369 qla83xx_reset_ownership(vha);
4370
4371 rval = qla83xx_initiating_reset(vha);
4372
4373 /*
4374 * Perform reset if we are the reset-owner,
4375 * else wait till IDC state changes to READY/FAILED.
4376 */
4377 if (rval == QLA_SUCCESS) {
4378 rval = qla83xx_idc_state_handler(vha);
4379
4380 if (rval == QLA_SUCCESS)
4381 ha->flags.nic_core_hung = 0;
4382 __qla83xx_clear_drv_ack(vha);
4383 }
4384
4385exit:
4386 qla83xx_idc_unlock(vha, 0);
4387
4388 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
4389
4390 return rval;
4391}
4392
Saurav Kashyap81178772012-08-22 14:21:04 -04004393int
4394qla2xxx_mctp_dump(scsi_qla_host_t *vha)
4395{
4396 struct qla_hw_data *ha = vha->hw;
4397 int rval = QLA_FUNCTION_FAILED;
4398
4399 if (!IS_MCTP_CAPABLE(ha)) {
4400 /* This message can be removed from the final version */
4401 ql_log(ql_log_info, vha, 0x506d,
4402 "This board is not MCTP capable\n");
4403 return rval;
4404 }
4405
4406 if (!ha->mctp_dump) {
4407 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
4408 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
4409
4410 if (!ha->mctp_dump) {
4411 ql_log(ql_log_warn, vha, 0x506e,
4412 "Failed to allocate memory for mctp dump\n");
4413 return rval;
4414 }
4415 }
4416
4417#define MCTP_DUMP_STR_ADDR 0x00000000
4418 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
4419 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
4420 if (rval != QLA_SUCCESS) {
4421 ql_log(ql_log_warn, vha, 0x506f,
4422 "Failed to capture mctp dump\n");
4423 } else {
4424 ql_log(ql_log_info, vha, 0x5070,
4425 "Mctp dump capture for host (%ld/%p).\n",
4426 vha->host_no, ha->mctp_dump);
4427 ha->mctp_dumped = 1;
4428 }
4429
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04004430 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04004431 ha->flags.nic_core_reset_hdlr_active = 1;
4432 rval = qla83xx_restart_nic_firmware(vha);
4433 if (rval)
4434 /* NIC Core reset failed. */
4435 ql_log(ql_log_warn, vha, 0x5071,
4436 "Failed to restart nic firmware\n");
4437 else
4438 ql_dbg(ql_dbg_p3p, vha, 0xb084,
4439 "Restarted NIC firmware successfully.\n");
4440 ha->flags.nic_core_reset_hdlr_active = 0;
4441 }
4442
4443 return rval;
4444
4445}
4446
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004447/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004448* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004449* Description: This function will block the new I/Os
4450* Its not aborting any I/Os as context
4451* is not destroyed during quiescence
4452* Arguments: scsi_qla_host_t
4453* return : void
4454*/
4455void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004456qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004457{
4458 struct qla_hw_data *ha = vha->hw;
4459 struct scsi_qla_host *vp;
4460
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004461 ql_dbg(ql_dbg_dpc, vha, 0x401d,
4462 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004463
4464 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4465 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4466 atomic_set(&vha->loop_state, LOOP_DOWN);
4467 qla2x00_mark_all_devices_lost(vha, 0);
4468 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004469 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004470 } else {
4471 if (!atomic_read(&vha->loop_down_timer))
4472 atomic_set(&vha->loop_down_timer,
4473 LOOP_DOWN_TIME);
4474 }
4475 /* Wait for pending cmds to complete */
4476 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
4477}
4478
Giridhar Malavalia9083012010-04-12 17:59:55 -07004479void
4480qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
4481{
4482 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004483 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07004484 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004485 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004486
Saurav Kashyape46ef002011-02-23 15:27:16 -08004487 /* For ISP82XX, driver waits for completion of the commands.
4488 * online flag should be set.
4489 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004490 if (!(IS_P3P_TYPE(ha)))
Saurav Kashyape46ef002011-02-23 15:27:16 -08004491 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004492 ha->flags.chip_reset_done = 0;
4493 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04004494 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004495
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004496 ql_log(ql_log_info, vha, 0x00af,
4497 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004498
Saurav Kashyape46ef002011-02-23 15:27:16 -08004499 /* For ISP82XX, reset_chip is just disabling interrupts.
4500 * Driver waits for the completion of the commands.
4501 * the interrupts need to be enabled.
4502 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004503 if (!(IS_P3P_TYPE(ha)))
Giridhar Malavalia9083012010-04-12 17:59:55 -07004504 ha->isp_ops->reset_chip(vha);
4505
4506 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
4507 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4508 atomic_set(&vha->loop_state, LOOP_DOWN);
4509 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004510
4511 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004512 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07004513 atomic_inc(&vp->vref_count);
4514 spin_unlock_irqrestore(&ha->vport_slock, flags);
4515
Giridhar Malavalia9083012010-04-12 17:59:55 -07004516 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004517
4518 spin_lock_irqsave(&ha->vport_slock, flags);
4519 atomic_dec(&vp->vref_count);
4520 }
4521 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004522 } else {
4523 if (!atomic_read(&vha->loop_down_timer))
4524 atomic_set(&vha->loop_down_timer,
4525 LOOP_DOWN_TIME);
4526 }
4527
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004528 /* Clear all async request states across all VPs. */
4529 list_for_each_entry(fcport, &vha->vp_fcports, list)
4530 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4531 spin_lock_irqsave(&ha->vport_slock, flags);
4532 list_for_each_entry(vp, &ha->vp_list, list) {
4533 atomic_inc(&vp->vref_count);
4534 spin_unlock_irqrestore(&ha->vport_slock, flags);
4535
4536 list_for_each_entry(fcport, &vp->vp_fcports, list)
4537 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4538
4539 spin_lock_irqsave(&ha->vport_slock, flags);
4540 atomic_dec(&vp->vref_count);
4541 }
4542 spin_unlock_irqrestore(&ha->vport_slock, flags);
4543
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004544 if (!ha->flags.eeh_busy) {
4545 /* Make sure for ISP 82XX IO DMA is complete */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004546 if (IS_P3P_TYPE(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004547 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004548 ql_log(ql_log_info, vha, 0x00b4,
4549 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004550
Saurav Kashyape46ef002011-02-23 15:27:16 -08004551 /* Done waiting for pending commands.
4552 * Reset the online flag.
4553 */
4554 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004555 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004556
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004557 /* Requeue all commands in outstanding command list. */
4558 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560}
4561
4562/*
4563* qla2x00_abort_isp
4564* Resets ISP and aborts all outstanding commands.
4565*
4566* Input:
4567* ha = adapter block pointer.
4568*
4569* Returns:
4570* 0 = success
4571*/
4572int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004573qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574{
Andrew Vasquez476e8972006-08-23 14:54:55 -07004575 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004577 struct qla_hw_data *ha = vha->hw;
4578 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004579 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07004580 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004582 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004583 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004584
Santosh Vernekara61712972012-08-22 14:21:13 -04004585 if (IS_QLA8031(ha)) {
4586 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
4587 "Clearing fcoe driver presence.\n");
4588 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
4589 ql_dbg(ql_dbg_p3p, vha, 0xb073,
4590 "Error while clearing DRV-Presence.\n");
4591 }
4592
Andrew Vasquez85880802009-12-15 21:29:46 -08004593 if (unlikely(pci_channel_offline(ha->pdev) &&
4594 ha->flags.pci_channel_io_perm_failure)) {
4595 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4596 status = 0;
4597 return status;
4598 }
4599
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004600 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08004601
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004602 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004604 if (!qla2x00_restart_isp(vha)) {
4605 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004607 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 /*
4609 * Issue marker command only when we are going
4610 * to start the I/O .
4611 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004612 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004613 }
4614
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004615 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004617 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004618
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004619 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004620 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07004621
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004622 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
4623 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004624 if (ha->fce) {
4625 ha->flags.fce_enabled = 1;
4626 memset(ha->fce, 0,
4627 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004628 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004629 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4630 &ha->fce_bufs);
4631 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004632 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004633 "Unable to reinitialize FCE "
4634 "(%d).\n", rval);
4635 ha->flags.fce_enabled = 0;
4636 }
4637 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004638
4639 if (ha->eft) {
4640 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004641 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004642 ha->eft_dma, EFT_NUM_BUFFERS);
4643 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004644 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004645 "Unable to reinitialize EFT "
4646 "(%d).\n", rval);
4647 }
4648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004649 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004650 vha->flags.online = 1;
4651 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004653 ql_log(ql_log_fatal, vha, 0x8035,
4654 "ISP error recover failed - "
4655 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004656 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657 * The next call disables the board
4658 * completely.
4659 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004660 ha->isp_ops->reset_adapter(vha);
4661 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004663 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004664 status = 0;
4665 } else { /* schedule another ISP abort */
4666 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004667 ql_dbg(ql_dbg_taskm, vha, 0x8020,
4668 "ISP abort - retry remaining %d.\n",
4669 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670 status = 1;
4671 }
4672 } else {
4673 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004674 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4675 "ISP error recovery - retrying (%d) "
4676 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004677 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004678 status = 1;
4679 }
4680 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004681
Linus Torvalds1da177e2005-04-16 15:20:36 -07004682 }
4683
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004684 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004685 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07004686
4687 spin_lock_irqsave(&ha->vport_slock, flags);
4688 list_for_each_entry(vp, &ha->vp_list, list) {
4689 if (vp->vp_idx) {
4690 atomic_inc(&vp->vref_count);
4691 spin_unlock_irqrestore(&ha->vport_slock, flags);
4692
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004693 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004694
4695 spin_lock_irqsave(&ha->vport_slock, flags);
4696 atomic_dec(&vp->vref_count);
4697 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004698 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004699 spin_unlock_irqrestore(&ha->vport_slock, flags);
4700
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004701 if (IS_QLA8031(ha)) {
4702 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
4703 "Setting back fcoe driver presence.\n");
4704 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
4705 ql_dbg(ql_dbg_p3p, vha, 0xb074,
4706 "Error while setting DRV-Presence.\n");
4707 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004708 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08004709 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
4710 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711 }
4712
4713 return(status);
4714}
4715
4716/*
4717* qla2x00_restart_isp
4718* restarts the ISP after a reset
4719*
4720* Input:
4721* ha = adapter block pointer.
4722*
4723* Returns:
4724* 0 = success
4725*/
4726static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004727qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004729 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004731 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004732 struct req_que *req = ha->req_q_map[0];
4733 struct rsp_que *rsp = ha->rsp_q_map[0];
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004734 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735
4736 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004737 if (qla2x00_isp_firmware(vha)) {
4738 vha->flags.online = 0;
4739 status = ha->isp_ops->chip_diag(vha);
4740 if (!status)
4741 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004742 }
4743
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004744 if (!status && !(status = qla2x00_init_rings(vha))) {
4745 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004746 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004747 /* Initialize the queues in use */
4748 qla25xx_init_queues(ha);
4749
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004750 status = qla2x00_fw_ready(vha);
4751 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004752 ql_dbg(ql_dbg_taskm, vha, 0x8031,
4753 "Start configure loop status = %d.\n", status);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004754
4755 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004756 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004757
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004758 vha->flags.online = 1;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004759
4760 /*
4761 * Process any ATIO queue entries that came in
4762 * while we weren't online.
4763 */
4764 spin_lock_irqsave(&ha->hardware_lock, flags);
4765 if (qla_tgt_mode_enabled(vha))
4766 qlt_24xx_process_atio_queue(vha);
4767 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4768
Linus Torvalds1da177e2005-04-16 15:20:36 -07004769 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4770 wait_time = 256;
4771 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004772 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4773 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004775 } while (!atomic_read(&vha->loop_down_timer) &&
4776 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4777 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4778 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004779 }
4780
4781 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004782 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783 status = 0;
4784
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004785 ql_dbg(ql_dbg_taskm, vha, 0x8032,
4786 "Configure loop done, status = 0x%x.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004787 }
4788 return (status);
4789}
4790
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004791static int
4792qla25xx_init_queues(struct qla_hw_data *ha)
4793{
4794 struct rsp_que *rsp = NULL;
4795 struct req_que *req = NULL;
4796 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4797 int ret = -1;
4798 int i;
4799
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004800 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004801 rsp = ha->rsp_q_map[i];
4802 if (rsp) {
4803 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004804 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004805 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004806 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4807 "%s Rsp que: %d init failed.\n",
4808 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004809 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004810 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4811 "%s Rsp que: %d inited.\n",
4812 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004813 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004814 }
4815 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004816 req = ha->req_q_map[i];
4817 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004818 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004819 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004820 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004821 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004822 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4823 "%s Req que: %d init failed.\n",
4824 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004825 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004826 ql_dbg(ql_dbg_init, base_vha, 0x0102,
4827 "%s Req que: %d inited.\n",
4828 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004829 }
4830 }
4831 return ret;
4832}
4833
Linus Torvalds1da177e2005-04-16 15:20:36 -07004834/*
4835* qla2x00_reset_adapter
4836* Reset adapter.
4837*
4838* Input:
4839* ha = adapter block pointer.
4840*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004841void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004842qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004843{
4844 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004845 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004846 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004847
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004848 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004849 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004850
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851 spin_lock_irqsave(&ha->hardware_lock, flags);
4852 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4853 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4854 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4855 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4856 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4857}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004858
4859void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004860qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004861{
4862 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004863 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004864 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4865
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004866 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07004867 return;
4868
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004869 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004870 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004871
4872 spin_lock_irqsave(&ha->hardware_lock, flags);
4873 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4874 RD_REG_DWORD(&reg->hccr);
4875 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4876 RD_REG_DWORD(&reg->hccr);
4877 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004878
4879 if (IS_NOPOLLING_TYPE(ha))
4880 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004881}
4882
David Miller4e08df32007-04-16 12:37:43 -07004883/* On sparc systems, obtain port and node WWN from firmware
4884 * properties.
4885 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004886static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4887 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004888{
4889#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004890 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004891 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004892 struct device_node *dp = pci_device_to_OF_node(pdev);
4893 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004894 int len;
4895
4896 val = of_get_property(dp, "port-wwn", &len);
4897 if (val && len >= WWN_SIZE)
4898 memcpy(nv->port_name, val, WWN_SIZE);
4899
4900 val = of_get_property(dp, "node-wwn", &len);
4901 if (val && len >= WWN_SIZE)
4902 memcpy(nv->node_name, val, WWN_SIZE);
4903#endif
4904}
4905
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004906int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004907qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004908{
David Miller4e08df32007-04-16 12:37:43 -07004909 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004910 struct init_cb_24xx *icb;
4911 struct nvram_24xx *nv;
4912 uint32_t *dptr;
4913 uint8_t *dptr1, *dptr2;
4914 uint32_t chksum;
4915 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004916 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004917
David Miller4e08df32007-04-16 12:37:43 -07004918 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004919 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004920 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004921
4922 /* Determine NVRAM starting address. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05004923 if (ha->port_no == 0) {
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004924 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4925 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4926 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004927 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004928 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4929 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05004930
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004931 ha->nvram_size = sizeof(struct nvram_24xx);
4932 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004933
Seokmann Ju281afe12007-07-26 13:43:34 -07004934 /* Get VPD data into cache */
4935 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004936 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004937 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4938
4939 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004940 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004941 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004942 ha->nvram_size);
4943 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4944 chksum += le32_to_cpu(*dptr++);
4945
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004946 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
4947 "Contents of NVRAM\n");
4948 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
4949 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004950
4951 /* Bad NVRAM data, set defaults parameters. */
4952 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4953 || nv->id[3] != ' ' ||
4954 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4955 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004956 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04004957 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004958 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
4959 ql_log(ql_log_warn, vha, 0x006c,
4960 "Falling back to functioning (yet invalid -- WWPN) "
4961 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07004962
4963 /*
4964 * Set default initialization control block.
4965 */
4966 memset(nv, 0, ha->nvram_size);
4967 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4968 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4969 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4970 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4971 nv->exchange_count = __constant_cpu_to_le16(0);
4972 nv->hard_address = __constant_cpu_to_le16(124);
4973 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004974 nv->port_name[1] = 0x00 + ha->port_no + 1;
David Miller4e08df32007-04-16 12:37:43 -07004975 nv->port_name[2] = 0x00;
4976 nv->port_name[3] = 0xe0;
4977 nv->port_name[4] = 0x8b;
4978 nv->port_name[5] = 0x1c;
4979 nv->port_name[6] = 0x55;
4980 nv->port_name[7] = 0x86;
4981 nv->node_name[0] = 0x20;
4982 nv->node_name[1] = 0x00;
4983 nv->node_name[2] = 0x00;
4984 nv->node_name[3] = 0xe0;
4985 nv->node_name[4] = 0x8b;
4986 nv->node_name[5] = 0x1c;
4987 nv->node_name[6] = 0x55;
4988 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004989 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004990 nv->login_retry_count = __constant_cpu_to_le16(8);
4991 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4992 nv->login_timeout = __constant_cpu_to_le16(0);
4993 nv->firmware_options_1 =
4994 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4995 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4996 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4997 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4998 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4999 nv->efi_parameters = __constant_cpu_to_le32(0);
5000 nv->reset_delay = 5;
5001 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5002 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5003 nv->link_down_timeout = __constant_cpu_to_le16(30);
5004
5005 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005006 }
5007
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005008 if (!qla_ini_mode_enabled(vha)) {
5009 /* Don't enable full login after initial LIP */
5010 nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13);
5011 /* Don't enable LIP full login for initiator */
5012 nv->host_p &= __constant_cpu_to_le32(~BIT_10);
5013 }
5014
5015 qlt_24xx_config_nvram_stage1(vha, nv);
5016
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005017 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005018 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005019
5020 /* Copy 1st segment. */
5021 dptr1 = (uint8_t *)icb;
5022 dptr2 = (uint8_t *)&nv->version;
5023 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5024 while (cnt--)
5025 *dptr1++ = *dptr2++;
5026
5027 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07005028 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005029
5030 /* Copy 2nd segment. */
5031 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5032 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5033 cnt = (uint8_t *)&icb->reserved_3 -
5034 (uint8_t *)&icb->interrupt_delay_timer;
5035 while (cnt--)
5036 *dptr1++ = *dptr2++;
5037
5038 /*
5039 * Setup driver NVRAM options.
5040 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005041 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08005042 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005043
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005044 qlt_24xx_config_nvram_stage2(vha, icb);
5045
Andrew Vasquez5341e862006-05-17 15:09:16 -07005046 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005047 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07005048 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5049 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5050 }
5051
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005052 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07005053 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005054 /*
5055 * Firmware will apply the following mask if the nodename was
5056 * not provided.
5057 */
5058 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5059 icb->node_name[0] &= 0xF0;
5060 }
5061
5062 /* Set host adapter parameters. */
5063 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08005064 ha->flags.enable_lip_reset = 0;
5065 ha->flags.enable_lip_full_login =
5066 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5067 ha->flags.enable_target_reset =
5068 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005069 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07005070 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005071
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07005072 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5073 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005074
5075 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
5076 sizeof(ha->fw_seriallink_options24));
5077
5078 /* save HBA serial number */
5079 ha->serial0 = icb->port_name[5];
5080 ha->serial1 = icb->port_name[6];
5081 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005082 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5083 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005084
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08005085 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5086
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005087 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5088
5089 /* Set minimum login_timeout to 4 seconds. */
5090 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5091 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5092 if (le16_to_cpu(nv->login_timeout) < 4)
5093 nv->login_timeout = __constant_cpu_to_le16(4);
5094 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07005095 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005096
Andrew Vasquez00a537b2008-02-28 14:06:11 -08005097 /* Set minimum RATOV to 100 tenths of a second. */
5098 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005099
5100 ha->loop_reset_delay = nv->reset_delay;
5101
5102 /* Link Down Timeout = 0:
5103 *
5104 * When Port Down timer expires we will start returning
5105 * I/O's to OS with "DID_NO_CONNECT".
5106 *
5107 * Link Down Timeout != 0:
5108 *
5109 * The driver waits for the link to come up after link down
5110 * before returning I/Os to OS with "DID_NO_CONNECT".
5111 */
5112 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5113 ha->loop_down_abort_time =
5114 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5115 } else {
5116 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5117 ha->loop_down_abort_time =
5118 (LOOP_DOWN_TIME - ha->link_down_timeout);
5119 }
5120
5121 /* Need enough time to try and get the port back. */
5122 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5123 if (qlport_down_retry)
5124 ha->port_down_retry_count = qlport_down_retry;
5125
5126 /* Set login_retry_count */
5127 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5128 if (ha->port_down_retry_count ==
5129 le16_to_cpu(nv->port_down_retry_count) &&
5130 ha->port_down_retry_count > 3)
5131 ha->login_retry_count = ha->port_down_retry_count;
5132 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5133 ha->login_retry_count = ha->port_down_retry_count;
5134 if (ql2xloginretrycount)
5135 ha->login_retry_count = ql2xloginretrycount;
5136
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005137 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005138 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005139 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5140 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5141 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5142 le16_to_cpu(icb->interrupt_delay_timer): 2;
5143 }
5144 icb->firmware_options_2 &= __constant_cpu_to_le32(
5145 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005146 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005147 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08005148 ha->zio_mode = QLA_ZIO_MODE_6;
5149
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005150 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005151 "ZIO mode %d enabled; timer delay (%d us).\n",
5152 ha->zio_mode, ha->zio_timer * 100);
5153
5154 icb->firmware_options_2 |= cpu_to_le32(
5155 (uint32_t)ha->zio_mode);
5156 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005157 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005158 }
5159
David Miller4e08df32007-04-16 12:37:43 -07005160 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005161 ql_log(ql_log_warn, vha, 0x0070,
5162 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07005163 }
5164 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005165}
5166
Adrian Bunk413975a2006-06-30 02:33:06 -07005167static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005168qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
5169 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005170{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005171 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005172 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005173 uint32_t *dcode, dlen;
5174 uint32_t risc_addr;
5175 uint32_t risc_size;
5176 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005177 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005178 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005179
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005180 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08005181 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005182
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005183 rval = QLA_SUCCESS;
5184
5185 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005186 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005187 *srisc_addr = 0;
5188
5189 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005190 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005191 for (i = 0; i < 4; i++)
5192 dcode[i] = be32_to_cpu(dcode[i]);
5193 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5194 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5195 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5196 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005197 ql_log(ql_log_fatal, vha, 0x008c,
5198 "Unable to verify the integrity of flash firmware "
5199 "image.\n");
5200 ql_log(ql_log_fatal, vha, 0x008d,
5201 "Firmware data: %08x %08x %08x %08x.\n",
5202 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005203
5204 return QLA_FUNCTION_FAILED;
5205 }
5206
5207 while (segments && rval == QLA_SUCCESS) {
5208 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005209 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005210
5211 risc_addr = be32_to_cpu(dcode[2]);
5212 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5213 risc_size = be32_to_cpu(dcode[3]);
5214
5215 fragment = 0;
5216 while (risc_size > 0 && rval == QLA_SUCCESS) {
5217 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5218 if (dlen > risc_size)
5219 dlen = risc_size;
5220
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005221 ql_dbg(ql_dbg_init, vha, 0x008e,
5222 "Loading risc segment@ risc addr %x "
5223 "number of dwords 0x%x offset 0x%x.\n",
5224 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005225
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005226 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005227 for (i = 0; i < dlen; i++)
5228 dcode[i] = swab32(dcode[i]);
5229
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005230 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005231 dlen);
5232 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005233 ql_log(ql_log_fatal, vha, 0x008f,
5234 "Failed to load segment %d of firmware.\n",
5235 fragment);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005236 break;
5237 }
5238
5239 faddr += dlen;
5240 risc_addr += dlen;
5241 risc_size -= dlen;
5242 fragment++;
5243 }
5244
5245 /* Next segment. */
5246 segments--;
5247 }
5248
Chad Dupuisf73cb692014-02-26 04:15:06 -05005249 if (!IS_QLA27XX(ha))
5250 return rval;
5251
5252 if (ha->fw_dump_template)
5253 vfree(ha->fw_dump_template);
5254 ha->fw_dump_template = NULL;
5255 ha->fw_dump_template_len = 0;
5256
5257 ql_dbg(ql_dbg_init, vha, 0x0161,
5258 "Loading fwdump template from %x\n", faddr);
5259 qla24xx_read_flash_data(vha, dcode, faddr, 7);
5260 risc_size = be32_to_cpu(dcode[2]);
5261 ql_dbg(ql_dbg_init, vha, 0x0162,
5262 "-> array size %x dwords\n", risc_size);
5263 if (risc_size == 0 || risc_size == ~0)
5264 goto default_template;
5265
5266 dlen = (risc_size - 8) * sizeof(*dcode);
5267 ql_dbg(ql_dbg_init, vha, 0x0163,
5268 "-> template allocating %x bytes...\n", dlen);
5269 ha->fw_dump_template = vmalloc(dlen);
5270 if (!ha->fw_dump_template) {
5271 ql_log(ql_log_warn, vha, 0x0164,
5272 "Failed fwdump template allocate %x bytes.\n", risc_size);
5273 goto default_template;
5274 }
5275
5276 faddr += 7;
5277 risc_size -= 8;
5278 dcode = ha->fw_dump_template;
5279 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
5280 for (i = 0; i < risc_size; i++)
5281 dcode[i] = le32_to_cpu(dcode[i]);
5282
5283 if (!qla27xx_fwdt_template_valid(dcode)) {
5284 ql_log(ql_log_warn, vha, 0x0165,
5285 "Failed fwdump template validate\n");
5286 goto default_template;
5287 }
5288
5289 dlen = qla27xx_fwdt_template_size(dcode);
5290 ql_dbg(ql_dbg_init, vha, 0x0166,
5291 "-> template size %x bytes\n", dlen);
5292 if (dlen > risc_size * sizeof(*dcode)) {
5293 ql_log(ql_log_warn, vha, 0x0167,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005294 "Failed fwdump template exceeds array by %x bytes\n",
5295 (uint32_t)(dlen - risc_size * sizeof(*dcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005296 goto default_template;
5297 }
5298 ha->fw_dump_template_len = dlen;
5299 return rval;
5300
5301default_template:
5302 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
5303 if (ha->fw_dump_template)
5304 vfree(ha->fw_dump_template);
5305 ha->fw_dump_template = NULL;
5306 ha->fw_dump_template_len = 0;
5307
5308 dlen = qla27xx_fwdt_template_default_size();
5309 ql_dbg(ql_dbg_init, vha, 0x0169,
5310 "-> template allocating %x bytes...\n", dlen);
5311 ha->fw_dump_template = vmalloc(dlen);
5312 if (!ha->fw_dump_template) {
5313 ql_log(ql_log_warn, vha, 0x016a,
5314 "Failed fwdump template allocate %x bytes.\n", risc_size);
5315 goto failed_template;
5316 }
5317
5318 dcode = ha->fw_dump_template;
5319 risc_size = dlen / sizeof(*dcode);
5320 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
5321 for (i = 0; i < risc_size; i++)
5322 dcode[i] = be32_to_cpu(dcode[i]);
5323
5324 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5325 ql_log(ql_log_warn, vha, 0x016b,
5326 "Failed fwdump template validate\n");
5327 goto failed_template;
5328 }
5329
5330 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5331 ql_dbg(ql_dbg_init, vha, 0x016c,
5332 "-> template size %x bytes\n", dlen);
5333 ha->fw_dump_template_len = dlen;
5334 return rval;
5335
5336failed_template:
5337 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
5338 if (ha->fw_dump_template)
5339 vfree(ha->fw_dump_template);
5340 ha->fw_dump_template = NULL;
5341 ha->fw_dump_template_len = 0;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005342 return rval;
5343}
5344
Giridhar Malavalie9454a82013-02-08 01:57:47 -05005345#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005346
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005347int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005348qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08005349{
5350 int rval;
5351 int i, fragment;
5352 uint16_t *wcode, *fwcode;
5353 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
5354 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005355 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005356 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08005357
5358 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005359 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005360 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005361 ql_log(ql_log_info, vha, 0x0083,
5362 "Fimware image unavailable.\n");
5363 ql_log(ql_log_info, vha, 0x0084,
5364 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08005365 return QLA_FUNCTION_FAILED;
5366 }
5367
5368 rval = QLA_SUCCESS;
5369
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005370 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08005371 *srisc_addr = 0;
5372 fwcode = (uint16_t *)blob->fw->data;
5373 fwclen = 0;
5374
5375 /* Validate firmware image by checking version. */
5376 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005377 ql_log(ql_log_fatal, vha, 0x0085,
5378 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005379 blob->fw->size);
5380 goto fail_fw_integrity;
5381 }
5382 for (i = 0; i < 4; i++)
5383 wcode[i] = be16_to_cpu(fwcode[i + 4]);
5384 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
5385 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
5386 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005387 ql_log(ql_log_fatal, vha, 0x0086,
5388 "Unable to verify integrity of firmware image.\n");
5389 ql_log(ql_log_fatal, vha, 0x0087,
5390 "Firmware data: %04x %04x %04x %04x.\n",
5391 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08005392 goto fail_fw_integrity;
5393 }
5394
5395 seg = blob->segs;
5396 while (*seg && rval == QLA_SUCCESS) {
5397 risc_addr = *seg;
5398 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
5399 risc_size = be16_to_cpu(fwcode[3]);
5400
5401 /* Validate firmware image size. */
5402 fwclen += risc_size * sizeof(uint16_t);
5403 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005404 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08005405 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005406 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08005407 goto fail_fw_integrity;
5408 }
5409
5410 fragment = 0;
5411 while (risc_size > 0 && rval == QLA_SUCCESS) {
5412 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
5413 if (wlen > risc_size)
5414 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005415 ql_dbg(ql_dbg_init, vha, 0x0089,
5416 "Loading risc segment@ risc addr %x number of "
5417 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08005418
5419 for (i = 0; i < wlen; i++)
5420 wcode[i] = swab16(fwcode[i]);
5421
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005422 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08005423 wlen);
5424 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005425 ql_log(ql_log_fatal, vha, 0x008a,
5426 "Failed to load segment %d of firmware.\n",
5427 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08005428 break;
5429 }
5430
5431 fwcode += wlen;
5432 risc_addr += wlen;
5433 risc_size -= wlen;
5434 fragment++;
5435 }
5436
5437 /* Next segment. */
5438 seg++;
5439 }
5440 return rval;
5441
5442fail_fw_integrity:
5443 return QLA_FUNCTION_FAILED;
5444}
5445
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005446static int
5447qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005448{
5449 int rval;
5450 int segments, fragment;
5451 uint32_t *dcode, dlen;
5452 uint32_t risc_addr;
5453 uint32_t risc_size;
5454 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08005455 struct fw_blob *blob;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005456 const uint32_t *fwcode;
5457 uint32_t fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005458 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005459 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005460
Andrew Vasquez54333832005-11-09 15:49:04 -08005461 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005462 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005463 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005464 ql_log(ql_log_warn, vha, 0x0090,
5465 "Fimware image unavailable.\n");
5466 ql_log(ql_log_warn, vha, 0x0091,
5467 "Firmware images can be retrieved from: "
5468 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005469
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005470 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005471 }
5472
Chad Dupuiscfb09192011-11-18 09:03:07 -08005473 ql_dbg(ql_dbg_init, vha, 0x0092,
5474 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005475
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005476 rval = QLA_SUCCESS;
5477
5478 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005479 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005480 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08005481 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005482 fwclen = 0;
5483
5484 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08005485 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005486 ql_log(ql_log_fatal, vha, 0x0093,
5487 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005488 blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005489 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005490 }
5491 for (i = 0; i < 4; i++)
5492 dcode[i] = be32_to_cpu(fwcode[i + 4]);
5493 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5494 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5495 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5496 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005497 ql_log(ql_log_fatal, vha, 0x0094,
5498 "Unable to verify integrity of firmware image (%Zd).\n",
5499 blob->fw->size);
5500 ql_log(ql_log_fatal, vha, 0x0095,
5501 "Firmware data: %08x %08x %08x %08x.\n",
5502 dcode[0], dcode[1], dcode[2], dcode[3]);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005503 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005504 }
5505
5506 while (segments && rval == QLA_SUCCESS) {
5507 risc_addr = be32_to_cpu(fwcode[2]);
5508 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5509 risc_size = be32_to_cpu(fwcode[3]);
5510
5511 /* Validate firmware image size. */
5512 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08005513 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005514 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08005515 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005516 "(%Zd).\n", blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005517 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005518 }
5519
5520 fragment = 0;
5521 while (risc_size > 0 && rval == QLA_SUCCESS) {
5522 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5523 if (dlen > risc_size)
5524 dlen = risc_size;
5525
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005526 ql_dbg(ql_dbg_init, vha, 0x0097,
5527 "Loading risc segment@ risc addr %x "
5528 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005529
5530 for (i = 0; i < dlen; i++)
5531 dcode[i] = swab32(fwcode[i]);
5532
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005533 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08005534 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005535 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005536 ql_log(ql_log_fatal, vha, 0x0098,
5537 "Failed to load segment %d of firmware.\n",
5538 fragment);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005539 break;
5540 }
5541
5542 fwcode += dlen;
5543 risc_addr += dlen;
5544 risc_size -= dlen;
5545 fragment++;
5546 }
5547
5548 /* Next segment. */
5549 segments--;
5550 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05005551
5552 if (!IS_QLA27XX(ha))
5553 return rval;
5554
5555 if (ha->fw_dump_template)
5556 vfree(ha->fw_dump_template);
5557 ha->fw_dump_template = NULL;
5558 ha->fw_dump_template_len = 0;
5559
5560 ql_dbg(ql_dbg_init, vha, 0x171,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005561 "Loading fwdump template from %x\n",
5562 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005563 risc_size = be32_to_cpu(fwcode[2]);
5564 ql_dbg(ql_dbg_init, vha, 0x172,
5565 "-> array size %x dwords\n", risc_size);
5566 if (risc_size == 0 || risc_size == ~0)
5567 goto default_template;
5568
5569 dlen = (risc_size - 8) * sizeof(*fwcode);
5570 ql_dbg(ql_dbg_init, vha, 0x0173,
5571 "-> template allocating %x bytes...\n", dlen);
5572 ha->fw_dump_template = vmalloc(dlen);
5573 if (!ha->fw_dump_template) {
5574 ql_log(ql_log_warn, vha, 0x0174,
5575 "Failed fwdump template allocate %x bytes.\n", risc_size);
5576 goto default_template;
5577 }
5578
5579 fwcode += 7;
5580 risc_size -= 8;
5581 dcode = ha->fw_dump_template;
5582 for (i = 0; i < risc_size; i++)
5583 dcode[i] = le32_to_cpu(fwcode[i]);
5584
5585 if (!qla27xx_fwdt_template_valid(dcode)) {
5586 ql_log(ql_log_warn, vha, 0x0175,
5587 "Failed fwdump template validate\n");
5588 goto default_template;
5589 }
5590
5591 dlen = qla27xx_fwdt_template_size(dcode);
5592 ql_dbg(ql_dbg_init, vha, 0x0176,
5593 "-> template size %x bytes\n", dlen);
5594 if (dlen > risc_size * sizeof(*fwcode)) {
5595 ql_log(ql_log_warn, vha, 0x0177,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005596 "Failed fwdump template exceeds array by %x bytes\n",
5597 (uint32_t)(dlen - risc_size * sizeof(*fwcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005598 goto default_template;
5599 }
5600 ha->fw_dump_template_len = dlen;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005601 return rval;
5602
Chad Dupuisf73cb692014-02-26 04:15:06 -05005603default_template:
5604 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
5605 if (ha->fw_dump_template)
5606 vfree(ha->fw_dump_template);
5607 ha->fw_dump_template = NULL;
5608 ha->fw_dump_template_len = 0;
5609
5610 dlen = qla27xx_fwdt_template_default_size();
5611 ql_dbg(ql_dbg_init, vha, 0x0179,
5612 "-> template allocating %x bytes...\n", dlen);
5613 ha->fw_dump_template = vmalloc(dlen);
5614 if (!ha->fw_dump_template) {
5615 ql_log(ql_log_warn, vha, 0x017a,
5616 "Failed fwdump template allocate %x bytes.\n", risc_size);
5617 goto failed_template;
5618 }
5619
5620 dcode = ha->fw_dump_template;
5621 risc_size = dlen / sizeof(*fwcode);
5622 fwcode = qla27xx_fwdt_template_default();
5623 for (i = 0; i < risc_size; i++)
5624 dcode[i] = be32_to_cpu(fwcode[i]);
5625
5626 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5627 ql_log(ql_log_warn, vha, 0x017b,
5628 "Failed fwdump template validate\n");
5629 goto failed_template;
5630 }
5631
5632 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5633 ql_dbg(ql_dbg_init, vha, 0x017c,
5634 "-> template size %x bytes\n", dlen);
5635 ha->fw_dump_template_len = dlen;
5636 return rval;
5637
5638failed_template:
5639 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
5640 if (ha->fw_dump_template)
5641 vfree(ha->fw_dump_template);
5642 ha->fw_dump_template = NULL;
5643 ha->fw_dump_template_len = 0;
5644 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005645}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005646
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005647int
5648qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5649{
5650 int rval;
5651
Andrew Vasqueze337d902009-04-06 22:33:49 -07005652 if (ql2xfwloadbin == 1)
5653 return qla81xx_load_risc(vha, srisc_addr);
5654
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005655 /*
5656 * FW Load priority:
5657 * 1) Firmware via request-firmware interface (.bin file).
5658 * 2) Firmware residing in flash.
5659 */
5660 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5661 if (rval == QLA_SUCCESS)
5662 return rval;
5663
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005664 return qla24xx_load_risc_flash(vha, srisc_addr,
5665 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005666}
5667
5668int
5669qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5670{
5671 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005672 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005673
Andrew Vasqueze337d902009-04-06 22:33:49 -07005674 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005675 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07005676
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005677 /*
5678 * FW Load priority:
5679 * 1) Firmware residing in flash.
5680 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005681 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005682 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005683 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005684 if (rval == QLA_SUCCESS)
5685 return rval;
5686
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005687try_blob_fw:
5688 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5689 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
5690 return rval;
5691
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005692 ql_log(ql_log_info, vha, 0x0099,
5693 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005694 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
5695 if (rval != QLA_SUCCESS)
5696 return rval;
5697
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005698 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005699 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005700 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005701}
5702
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005703void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005704qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005705{
5706 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005707 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005708
Andrew Vasquez85880802009-12-15 21:29:46 -08005709 if (ha->flags.pci_channel_io_perm_failure)
5710 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07005711 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005712 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07005713 if (!ha->fw_major_version)
5714 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005715
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005716 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08005717 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07005718 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005719 ha->isp_ops->reset_chip(vha);
5720 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005721 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005722 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005723 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005724 ql_log(ql_log_info, vha, 0x8015,
5725 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005726 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005727 }
5728}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005729
5730int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005731qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005732{
5733 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08005734 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005735 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005736 struct qla_hw_data *ha = vha->hw;
5737 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005738 struct req_que *req;
5739 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005740
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005741 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005742 return -EINVAL;
5743
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005744 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07005745 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005746 req = ha->req_q_map[0];
5747 else
5748 req = vha->req;
5749 rsp = req->rsp;
5750
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005751 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005752 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005753 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005754 }
5755
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005756 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005757
5758 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08005759 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
5760 BIT_1);
5761 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5762 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
5763 ql_dbg(ql_dbg_init, vha, 0x0120,
5764 "Failed SNS login: loop_id=%x, rval2=%d\n",
5765 NPH_SNS, rval2);
5766 else
5767 ql_dbg(ql_dbg_init, vha, 0x0103,
5768 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5769 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
5770 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005771 return (QLA_FUNCTION_FAILED);
5772 }
5773
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005774 atomic_set(&vha->loop_down_timer, 0);
5775 atomic_set(&vha->loop_state, LOOP_UP);
5776 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5777 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5778 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005779
5780 return rval;
5781}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005782
5783/* 84XX Support **************************************************************/
5784
5785static LIST_HEAD(qla_cs84xx_list);
5786static DEFINE_MUTEX(qla_cs84xx_mutex);
5787
5788static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005789qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005790{
5791 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005792 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005793
5794 mutex_lock(&qla_cs84xx_mutex);
5795
5796 /* Find any shared 84xx chip. */
5797 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5798 if (cs84xx->bus == ha->pdev->bus) {
5799 kref_get(&cs84xx->kref);
5800 goto done;
5801 }
5802 }
5803
5804 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5805 if (!cs84xx)
5806 goto done;
5807
5808 kref_init(&cs84xx->kref);
5809 spin_lock_init(&cs84xx->access_lock);
5810 mutex_init(&cs84xx->fw_update_mutex);
5811 cs84xx->bus = ha->pdev->bus;
5812
5813 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5814done:
5815 mutex_unlock(&qla_cs84xx_mutex);
5816 return cs84xx;
5817}
5818
5819static void
5820__qla84xx_chip_release(struct kref *kref)
5821{
5822 struct qla_chip_state_84xx *cs84xx =
5823 container_of(kref, struct qla_chip_state_84xx, kref);
5824
5825 mutex_lock(&qla_cs84xx_mutex);
5826 list_del(&cs84xx->list);
5827 mutex_unlock(&qla_cs84xx_mutex);
5828 kfree(cs84xx);
5829}
5830
5831void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005832qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005833{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005834 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005835 if (ha->cs84xx)
5836 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
5837}
5838
5839static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005840qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005841{
5842 int rval;
5843 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005844 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005845
5846 mutex_lock(&ha->cs84xx->fw_update_mutex);
5847
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005848 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005849
5850 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5851
5852 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5853 QLA_SUCCESS;
5854}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005855
5856/* 81XX Support **************************************************************/
5857
5858int
5859qla81xx_nvram_config(scsi_qla_host_t *vha)
5860{
5861 int rval;
5862 struct init_cb_81xx *icb;
5863 struct nvram_81xx *nv;
5864 uint32_t *dptr;
5865 uint8_t *dptr1, *dptr2;
5866 uint32_t chksum;
5867 uint16_t cnt;
5868 struct qla_hw_data *ha = vha->hw;
5869
5870 rval = QLA_SUCCESS;
5871 icb = (struct init_cb_81xx *)ha->init_cb;
5872 nv = ha->nvram;
5873
5874 /* Determine NVRAM starting address. */
5875 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005876 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005877 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
5878 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005879
5880 /* Get VPD data into cache */
5881 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005882 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5883 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005884
5885 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005886 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005887 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005888 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005889 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5890 chksum += le32_to_cpu(*dptr++);
5891
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005892 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
5893 "Contents of NVRAM:\n");
5894 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
5895 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005896
5897 /* Bad NVRAM data, set defaults parameters. */
5898 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5899 || nv->id[3] != ' ' ||
5900 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5901 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005902 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04005903 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005904 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005905 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005906 ql_log(ql_log_info, vha, 0x0074,
5907 "Falling back to functioning (yet invalid -- WWPN) "
5908 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005909
5910 /*
5911 * Set default initialization control block.
5912 */
5913 memset(nv, 0, ha->nvram_size);
5914 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5915 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5916 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5917 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5918 nv->exchange_count = __constant_cpu_to_le16(0);
5919 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005920 nv->port_name[1] = 0x00 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005921 nv->port_name[2] = 0x00;
5922 nv->port_name[3] = 0xe0;
5923 nv->port_name[4] = 0x8b;
5924 nv->port_name[5] = 0x1c;
5925 nv->port_name[6] = 0x55;
5926 nv->port_name[7] = 0x86;
5927 nv->node_name[0] = 0x20;
5928 nv->node_name[1] = 0x00;
5929 nv->node_name[2] = 0x00;
5930 nv->node_name[3] = 0xe0;
5931 nv->node_name[4] = 0x8b;
5932 nv->node_name[5] = 0x1c;
5933 nv->node_name[6] = 0x55;
5934 nv->node_name[7] = 0x86;
5935 nv->login_retry_count = __constant_cpu_to_le16(8);
5936 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5937 nv->login_timeout = __constant_cpu_to_le16(0);
5938 nv->firmware_options_1 =
5939 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5940 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5941 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5942 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5943 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5944 nv->efi_parameters = __constant_cpu_to_le32(0);
5945 nv->reset_delay = 5;
5946 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5947 nv->port_down_retry_count = __constant_cpu_to_le16(30);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005948 nv->link_down_timeout = __constant_cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005949 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005950 nv->enode_mac[1] = 0xC0;
5951 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005952 nv->enode_mac[3] = 0x04;
5953 nv->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005954 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005955
5956 rval = 1;
5957 }
5958
Arun Easi9e522cd2012-08-22 14:21:31 -04005959 if (IS_T10_PI_CAPABLE(ha))
5960 nv->frame_payload_size &= ~7;
5961
Arun Easiaa230bc2013-01-30 03:34:39 -05005962 qlt_81xx_config_nvram_stage1(vha, nv);
5963
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005964 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07005965 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005966
5967 /* Copy 1st segment. */
5968 dptr1 = (uint8_t *)icb;
5969 dptr2 = (uint8_t *)&nv->version;
5970 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5971 while (cnt--)
5972 *dptr1++ = *dptr2++;
5973
5974 icb->login_retry_count = nv->login_retry_count;
5975
5976 /* Copy 2nd segment. */
5977 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5978 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5979 cnt = (uint8_t *)&icb->reserved_5 -
5980 (uint8_t *)&icb->interrupt_delay_timer;
5981 while (cnt--)
5982 *dptr1++ = *dptr2++;
5983
5984 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5985 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5986 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08005987 icb->enode_mac[0] = 0x00;
5988 icb->enode_mac[1] = 0xC0;
5989 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005990 icb->enode_mac[3] = 0x04;
5991 icb->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005992 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005993 }
5994
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005995 /* Use extended-initialization control block. */
5996 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5997
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005998 /*
5999 * Setup driver NVRAM options.
6000 */
6001 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07006002 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006003
Arun Easiaa230bc2013-01-30 03:34:39 -05006004 qlt_81xx_config_nvram_stage2(vha, icb);
6005
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006006 /* Use alternate WWN? */
6007 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
6008 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6009 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6010 }
6011
6012 /* Prepare nodename */
6013 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
6014 /*
6015 * Firmware will apply the following mask if the nodename was
6016 * not provided.
6017 */
6018 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6019 icb->node_name[0] &= 0xF0;
6020 }
6021
6022 /* Set host adapter parameters. */
6023 ha->flags.disable_risc_code_load = 0;
6024 ha->flags.enable_lip_reset = 0;
6025 ha->flags.enable_lip_full_login =
6026 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6027 ha->flags.enable_target_reset =
6028 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
6029 ha->flags.enable_led_scheme = 0;
6030 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
6031
6032 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6033 (BIT_6 | BIT_5 | BIT_4)) >> 4;
6034
6035 /* save HBA serial number */
6036 ha->serial0 = icb->port_name[5];
6037 ha->serial1 = icb->port_name[6];
6038 ha->serial2 = icb->port_name[7];
6039 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6040 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
6041
6042 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
6043
6044 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6045
6046 /* Set minimum login_timeout to 4 seconds. */
6047 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6048 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6049 if (le16_to_cpu(nv->login_timeout) < 4)
6050 nv->login_timeout = __constant_cpu_to_le16(4);
6051 ha->login_timeout = le16_to_cpu(nv->login_timeout);
6052 icb->login_timeout = nv->login_timeout;
6053
6054 /* Set minimum RATOV to 100 tenths of a second. */
6055 ha->r_a_tov = 100;
6056
6057 ha->loop_reset_delay = nv->reset_delay;
6058
6059 /* Link Down Timeout = 0:
6060 *
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006061 * When Port Down timer expires we will start returning
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006062 * I/O's to OS with "DID_NO_CONNECT".
6063 *
6064 * Link Down Timeout != 0:
6065 *
6066 * The driver waits for the link to come up after link down
6067 * before returning I/Os to OS with "DID_NO_CONNECT".
6068 */
6069 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6070 ha->loop_down_abort_time =
6071 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6072 } else {
6073 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6074 ha->loop_down_abort_time =
6075 (LOOP_DOWN_TIME - ha->link_down_timeout);
6076 }
6077
6078 /* Need enough time to try and get the port back. */
6079 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6080 if (qlport_down_retry)
6081 ha->port_down_retry_count = qlport_down_retry;
6082
6083 /* Set login_retry_count */
6084 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6085 if (ha->port_down_retry_count ==
6086 le16_to_cpu(nv->port_down_retry_count) &&
6087 ha->port_down_retry_count > 3)
6088 ha->login_retry_count = ha->port_down_retry_count;
6089 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6090 ha->login_retry_count = ha->port_down_retry_count;
6091 if (ql2xloginretrycount)
6092 ha->login_retry_count = ql2xloginretrycount;
6093
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006094 /* if not running MSI-X we need handshaking on interrupts */
Chad Dupuisf73cb692014-02-26 04:15:06 -05006095 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006096 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
6097
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006098 /* Enable ZIO. */
6099 if (!vha->flags.init_done) {
6100 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6101 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6102 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6103 le16_to_cpu(icb->interrupt_delay_timer): 2;
6104 }
6105 icb->firmware_options_2 &= __constant_cpu_to_le32(
6106 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
6107 vha->flags.process_response_queue = 0;
6108 if (ha->zio_mode != QLA_ZIO_DISABLED) {
6109 ha->zio_mode = QLA_ZIO_MODE_6;
6110
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006111 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006112 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006113 ha->zio_mode,
6114 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006115
6116 icb->firmware_options_2 |= cpu_to_le32(
6117 (uint32_t)ha->zio_mode);
6118 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
6119 vha->flags.process_response_queue = 1;
6120 }
6121
6122 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006123 ql_log(ql_log_warn, vha, 0x0076,
6124 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006125 }
6126 return (rval);
6127}
6128
Giridhar Malavalia9083012010-04-12 17:59:55 -07006129int
6130qla82xx_restart_isp(scsi_qla_host_t *vha)
6131{
6132 int status, rval;
6133 uint32_t wait_time;
6134 struct qla_hw_data *ha = vha->hw;
6135 struct req_que *req = ha->req_q_map[0];
6136 struct rsp_que *rsp = ha->rsp_q_map[0];
6137 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07006138 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006139
6140 status = qla2x00_init_rings(vha);
6141 if (!status) {
6142 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6143 ha->flags.chip_reset_done = 1;
6144
6145 status = qla2x00_fw_ready(vha);
6146 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006147 ql_log(ql_log_info, vha, 0x803c,
6148 "Start configure loop, status =%d.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006149
6150 /* Issue a marker after FW becomes ready. */
6151 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
6152
6153 vha->flags.online = 1;
6154 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6155 wait_time = 256;
6156 do {
6157 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6158 qla2x00_configure_loop(vha);
6159 wait_time--;
6160 } while (!atomic_read(&vha->loop_down_timer) &&
6161 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
6162 wait_time &&
6163 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
6164 }
6165
6166 /* if no cable then assume it's good */
6167 if ((vha->device_flags & DFLG_NO_CABLE))
6168 status = 0;
6169
Chad Dupuiscfb09192011-11-18 09:03:07 -08006170 ql_log(ql_log_info, vha, 0x8000,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006171 "Configure loop done, status = 0x%x.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006172 }
6173
6174 if (!status) {
6175 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6176
6177 if (!atomic_read(&vha->loop_down_timer)) {
6178 /*
6179 * Issue marker command only when we are going
6180 * to start the I/O .
6181 */
6182 vha->marker_needed = 1;
6183 }
6184
6185 vha->flags.online = 1;
6186
6187 ha->isp_ops->enable_intrs(ha);
6188
6189 ha->isp_abort_cnt = 0;
6190 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6191
Saurav Kashyap53296782011-05-10 11:30:06 -07006192 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07006193 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07006194
Giridhar Malavalia9083012010-04-12 17:59:55 -07006195 if (ha->fce) {
6196 ha->flags.fce_enabled = 1;
6197 memset(ha->fce, 0,
6198 fce_calc_size(ha->fce_bufs));
6199 rval = qla2x00_enable_fce_trace(vha,
6200 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6201 &ha->fce_bufs);
6202 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006203 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006204 "Unable to reinitialize FCE (%d).\n",
6205 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006206 ha->flags.fce_enabled = 0;
6207 }
6208 }
6209
6210 if (ha->eft) {
6211 memset(ha->eft, 0, EFT_SIZE);
6212 rval = qla2x00_enable_eft_trace(vha,
6213 ha->eft_dma, EFT_NUM_BUFFERS);
6214 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006215 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006216 "Unable to reinitialize EFT (%d).\n",
6217 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006218 }
6219 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006220 }
6221
6222 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006223 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006224 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07006225
6226 spin_lock_irqsave(&ha->vport_slock, flags);
6227 list_for_each_entry(vp, &ha->vp_list, list) {
6228 if (vp->vp_idx) {
6229 atomic_inc(&vp->vref_count);
6230 spin_unlock_irqrestore(&ha->vport_slock, flags);
6231
Giridhar Malavalia9083012010-04-12 17:59:55 -07006232 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07006233
6234 spin_lock_irqsave(&ha->vport_slock, flags);
6235 atomic_dec(&vp->vref_count);
6236 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006237 }
Arun Easifeafb7b2010-09-03 14:57:00 -07006238 spin_unlock_irqrestore(&ha->vport_slock, flags);
6239
Giridhar Malavalia9083012010-04-12 17:59:55 -07006240 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006241 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006242 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006243 }
6244
6245 return status;
6246}
6247
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006248void
Andrew Vasquezae97c912010-02-18 10:07:28 -08006249qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006250{
Andrew Vasquezae97c912010-02-18 10:07:28 -08006251 struct qla_hw_data *ha = vha->hw;
6252
6253 if (!ql2xetsenable)
6254 return;
6255
6256 /* Enable ETS Burst. */
6257 memset(ha->fw_options, 0, sizeof(ha->fw_options));
6258 ha->fw_options[2] |= BIT_9;
6259 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006260}
Sarang Radke09ff7012010-03-19 17:03:59 -07006261
6262/*
6263 * qla24xx_get_fcp_prio
6264 * Gets the fcp cmd priority value for the logged in port.
6265 * Looks for a match of the port descriptors within
6266 * each of the fcp prio config entries. If a match is found,
6267 * the tag (priority) value is returned.
6268 *
6269 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006270 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07006271 * fcport = port structure pointer.
6272 *
6273 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07006274 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006275 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07006276 *
6277 * Context:
6278 * Kernel context
6279 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006280static int
Sarang Radke09ff7012010-03-19 17:03:59 -07006281qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
6282{
6283 int i, entries;
6284 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006285 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07006286 uint32_t pid1, pid2;
6287 uint64_t wwn1, wwn2;
6288 struct qla_fcp_prio_entry *pri_entry;
6289 struct qla_hw_data *ha = vha->hw;
6290
6291 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006292 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07006293
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006294 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07006295 entries = ha->fcp_prio_cfg->num_entries;
6296 pri_entry = &ha->fcp_prio_cfg->entry[0];
6297
6298 for (i = 0; i < entries; i++) {
6299 pid_match = wwn_match = 0;
6300
6301 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
6302 pri_entry++;
6303 continue;
6304 }
6305
6306 /* check source pid for a match */
6307 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
6308 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
6309 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
6310 if (pid1 == INVALID_PORT_ID)
6311 pid_match++;
6312 else if (pid1 == pid2)
6313 pid_match++;
6314 }
6315
6316 /* check destination pid for a match */
6317 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
6318 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
6319 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
6320 if (pid1 == INVALID_PORT_ID)
6321 pid_match++;
6322 else if (pid1 == pid2)
6323 pid_match++;
6324 }
6325
6326 /* check source WWN for a match */
6327 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
6328 wwn1 = wwn_to_u64(vha->port_name);
6329 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
6330 if (wwn2 == (uint64_t)-1)
6331 wwn_match++;
6332 else if (wwn1 == wwn2)
6333 wwn_match++;
6334 }
6335
6336 /* check destination WWN for a match */
6337 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
6338 wwn1 = wwn_to_u64(fcport->port_name);
6339 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
6340 if (wwn2 == (uint64_t)-1)
6341 wwn_match++;
6342 else if (wwn1 == wwn2)
6343 wwn_match++;
6344 }
6345
6346 if (pid_match == 2 || wwn_match == 2) {
6347 /* Found a matching entry */
6348 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
6349 priority = pri_entry->tag;
6350 break;
6351 }
6352
6353 pri_entry++;
6354 }
6355
6356 return priority;
6357}
6358
6359/*
6360 * qla24xx_update_fcport_fcp_prio
6361 * Activates fcp priority for the logged in fc port
6362 *
6363 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006364 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07006365 * fcp = port structure pointer.
6366 *
6367 * Return:
6368 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6369 *
6370 * Context:
6371 * Kernel context.
6372 */
6373int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006374qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07006375{
6376 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006377 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07006378 uint16_t mb[5];
6379
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006380 if (fcport->port_type != FCT_TARGET ||
6381 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07006382 return QLA_FUNCTION_FAILED;
6383
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006384 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006385 if (priority < 0)
6386 return QLA_FUNCTION_FAILED;
6387
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006388 if (IS_P3P_TYPE(vha->hw)) {
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006389 fcport->fcp_prio = priority & 0xf;
6390 return QLA_SUCCESS;
6391 }
6392
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006393 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08006394 if (ret == QLA_SUCCESS) {
6395 if (fcport->fcp_prio != priority)
6396 ql_dbg(ql_dbg_user, vha, 0x709e,
6397 "Updated FCP_CMND priority - value=%d loop_id=%d "
6398 "port_id=%02x%02x%02x.\n", priority,
6399 fcport->loop_id, fcport->d_id.b.domain,
6400 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006401 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08006402 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006403 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006404 "Unable to update FCP_CMND priority - ret=0x%x for "
6405 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
6406 fcport->d_id.b.domain, fcport->d_id.b.area,
6407 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07006408 return ret;
6409}
6410
6411/*
6412 * qla24xx_update_all_fcp_prio
6413 * Activates fcp priority for all the logged in ports
6414 *
6415 * Input:
6416 * ha = adapter block pointer.
6417 *
6418 * Return:
6419 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6420 *
6421 * Context:
6422 * Kernel context.
6423 */
6424int
6425qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
6426{
6427 int ret;
6428 fc_port_t *fcport;
6429
6430 ret = QLA_FUNCTION_FAILED;
6431 /* We need to set priority for all logged in ports */
6432 list_for_each_entry(fcport, &vha->vp_fcports, list)
6433 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
6434
6435 return ret;
6436}