blob: 34bbcfcae67ccd90295ab3fbf6aad506102ca159 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Armen Baloyanbd21eaf2014-04-11 16:54:24 -04003 * Copyright (c) 2003-2014 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
Anirban Chakraborty73208df2008-12-09 16:45:39 -08008#include "qla_gbl.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Andrew Vasquez0107109e2005-07-06 10:31:37 -070012#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#include "qla_devtbl.h"
15
David Miller4e08df32007-04-16 12:37:43 -070016#ifdef CONFIG_SPARC
17#include <asm/prom.h>
David Miller4e08df32007-04-16 12:37:43 -070018#endif
19
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040020#include <target/target_core_base.h>
21#include "qla_target.h"
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023/*
24* QLogic ISP2x00 Hardware Support Function Prototypes.
25*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070026static int qla2x00_isp_firmware(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027static int qla2x00_setup_chip(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028static int qla2x00_fw_ready(scsi_qla_host_t *);
29static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static int qla2x00_configure_loop(scsi_qla_host_t *);
31static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032static int qla2x00_configure_fabric(scsi_qla_host_t *);
33static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
35 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Harihara Kadayam4d4df192008-04-03 13:13:26 -070039static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
40static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080041static int qla25xx_init_queues(struct qla_hw_data *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070042
Andrew Vasquezac280b62009-08-20 11:06:05 -070043/* SRB Extensions ---------------------------------------------------------- */
44
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080045void
46qla2x00_sp_timeout(unsigned long __data)
Andrew Vasquezac280b62009-08-20 11:06:05 -070047{
48 srb_t *sp = (srb_t *)__data;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070049 struct srb_iocb *iocb;
Andrew Vasquezac280b62009-08-20 11:06:05 -070050 fc_port_t *fcport = sp->fcport;
51 struct qla_hw_data *ha = fcport->vha->hw;
52 struct req_que *req;
53 unsigned long flags;
54
55 spin_lock_irqsave(&ha->hardware_lock, flags);
56 req = ha->req_q_map[0];
57 req->outstanding_cmds[sp->handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080058 iocb = &sp->u.iocb_cmd;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070059 iocb->timeout(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080060 sp->free(fcport->vha, sp);
Andrew Vasquez6ac52602010-05-28 15:08:19 -070061 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -070062}
63
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080064void
65qla2x00_sp_free(void *data, void *ptr)
Andrew Vasquezac280b62009-08-20 11:06:05 -070066{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080067 srb_t *sp = (srb_t *)ptr;
68 struct srb_iocb *iocb = &sp->u.iocb_cmd;
69 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquezac280b62009-08-20 11:06:05 -070070
Chad Dupuis4d97cc52010-10-15 11:27:41 -070071 del_timer(&iocb->timer);
Chad Dupuisb00ee7d2013-02-08 01:57:50 -050072 qla2x00_rel_sp(vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -070073}
74
Andrew Vasquezac280b62009-08-20 11:06:05 -070075/* Asynchronous Login/Logout Routines -------------------------------------- */
76
Saurav Kashyapa9b6f7222012-08-22 14:21:01 -040077unsigned long
Andrew Vasquez5b914902010-05-28 15:08:30 -070078qla2x00_get_async_timeout(struct scsi_qla_host *vha)
79{
80 unsigned long tmo;
81 struct qla_hw_data *ha = vha->hw;
82
83 /* Firmware should use switch negotiated r_a_tov for timeout. */
84 tmo = ha->r_a_tov / 10 * 2;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040085 if (IS_QLAFX00(ha)) {
86 tmo = FX00_DEF_RATOV * 2;
87 } else if (!IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez5b914902010-05-28 15:08:30 -070088 /*
89 * Except for earlier ISPs where the timeout is seeded from the
90 * initialization control block.
91 */
92 tmo = ha->login_timeout;
93 }
94 return tmo;
95}
Andrew Vasquezac280b62009-08-20 11:06:05 -070096
97static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080098qla2x00_async_iocb_timeout(void *data)
Andrew Vasquezac280b62009-08-20 11:06:05 -070099{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800100 srb_t *sp = (srb_t *)data;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700101 fc_port_t *fcport = sp->fcport;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700102
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700103 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800104 "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800105 sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700106 fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700107
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700108 fcport->flags &= ~FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800109 if (sp->type == SRB_LOGIN_CMD) {
110 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700111 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700112 /* Retry as needed. */
113 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
114 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
115 QLA_LOGIO_LOGIN_RETRIED : 0;
116 qla2x00_post_async_login_done_work(fcport->vha, fcport,
117 lio->u.logio.data);
Alexei Potashnika6ca8872015-07-14 16:00:44 -0400118 } else if (sp->type == SRB_LOGOUT_CMD) {
119 qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT);
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700120 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700121}
122
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700123static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800124qla2x00_async_login_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700125{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800126 srb_t *sp = (srb_t *)ptr;
127 struct srb_iocb *lio = &sp->u.iocb_cmd;
128 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700129
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800130 if (!test_bit(UNLOADING, &vha->dpc_flags))
131 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
132 lio->u.logio.data);
133 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700134}
135
Andrew Vasquezac280b62009-08-20 11:06:05 -0700136int
137qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
138 uint16_t *data)
139{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700140 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700141 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700142 int rval;
143
144 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800145 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700146 if (!sp)
147 goto done;
148
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800149 sp->type = SRB_LOGIN_CMD;
150 sp->name = "login";
151 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
152
153 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700154 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800155 sp->done = qla2x00_async_login_sp_done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700156 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700157 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700158 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700159 rval = qla2x00_start_sp(sp);
Chad Dupuis080c9512016-01-27 12:03:37 -0500160 if (rval != QLA_SUCCESS) {
161 fcport->flags &= ~FCF_ASYNC_SENT;
162 fcport->flags |= FCF_LOGIN_NEEDED;
163 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700164 goto done_free_sp;
Chad Dupuis080c9512016-01-27 12:03:37 -0500165 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700166
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700167 ql_dbg(ql_dbg_disc, vha, 0x2072,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800168 "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
169 "retries=%d.\n", sp->handle, fcport->loop_id,
170 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
171 fcport->login_retry);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700172 return rval;
173
174done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800175 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700176done:
177 return rval;
178}
179
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700180static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800181qla2x00_async_logout_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700182{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800183 srb_t *sp = (srb_t *)ptr;
184 struct srb_iocb *lio = &sp->u.iocb_cmd;
185 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700186
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800187 if (!test_bit(UNLOADING, &vha->dpc_flags))
188 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
189 lio->u.logio.data);
190 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700191}
192
Andrew Vasquezac280b62009-08-20 11:06:05 -0700193int
194qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
195{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700196 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700197 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700198 int rval;
199
200 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800201 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700202 if (!sp)
203 goto done;
204
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800205 sp->type = SRB_LOGOUT_CMD;
206 sp->name = "logout";
207 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
208
209 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700210 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800211 sp->done = qla2x00_async_logout_sp_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700212 rval = qla2x00_start_sp(sp);
213 if (rval != QLA_SUCCESS)
214 goto done_free_sp;
215
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700216 ql_dbg(ql_dbg_disc, vha, 0x2070,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800217 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
218 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
219 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700220 return rval;
221
222done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800223 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700224done:
225 return rval;
226}
227
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700228static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800229qla2x00_async_adisc_sp_done(void *data, void *ptr, int res)
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700230{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800231 srb_t *sp = (srb_t *)ptr;
232 struct srb_iocb *lio = &sp->u.iocb_cmd;
233 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700234
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800235 if (!test_bit(UNLOADING, &vha->dpc_flags))
236 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
237 lio->u.logio.data);
238 sp->free(sp->fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700239}
240
241int
242qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
243 uint16_t *data)
244{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700245 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700246 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700247 int rval;
248
249 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800250 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700251 if (!sp)
252 goto done;
253
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800254 sp->type = SRB_ADISC_CMD;
255 sp->name = "adisc";
256 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
257
258 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700259 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800260 sp->done = qla2x00_async_adisc_sp_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700261 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700262 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700263 rval = qla2x00_start_sp(sp);
264 if (rval != QLA_SUCCESS)
265 goto done_free_sp;
266
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700267 ql_dbg(ql_dbg_disc, vha, 0x206f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800268 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
269 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
270 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700271 return rval;
272
273done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800274 sp->free(fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700275done:
276 return rval;
277}
278
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700279static void
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500280qla2x00_tmf_iocb_timeout(void *data)
281{
282 srb_t *sp = (srb_t *)data;
283 struct srb_iocb *tmf = &sp->u.iocb_cmd;
284
285 tmf->u.tmf.comp_status = CS_TIMEOUT;
286 complete(&tmf->u.tmf.comp);
287}
288
289static void
290qla2x00_tmf_sp_done(void *data, void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700291{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800292 srb_t *sp = (srb_t *)ptr;
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500293 struct srb_iocb *tmf = &sp->u.iocb_cmd;
294 complete(&tmf->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700295}
296
297int
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500298qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700299 uint32_t tag)
300{
301 struct scsi_qla_host *vha = fcport->vha;
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500302 struct srb_iocb *tm_iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700303 srb_t *sp;
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500304 int rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700305
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800306 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700307 if (!sp)
308 goto done;
309
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500310 tm_iocb = &sp->u.iocb_cmd;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800311 sp->type = SRB_TM_CMD;
312 sp->name = "tmf";
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500313 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
314 tm_iocb->u.tmf.flags = flags;
315 tm_iocb->u.tmf.lun = lun;
316 tm_iocb->u.tmf.data = tag;
317 sp->done = qla2x00_tmf_sp_done;
318 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
319 init_completion(&tm_iocb->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700320
321 rval = qla2x00_start_sp(sp);
322 if (rval != QLA_SUCCESS)
323 goto done_free_sp;
324
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700325 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800326 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
327 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
328 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500329
330 wait_for_completion(&tm_iocb->u.tmf.comp);
331
332 rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
333 QLA_SUCCESS : QLA_FUNCTION_FAILED;
334
335 if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
336 ql_dbg(ql_dbg_taskm, vha, 0x8030,
337 "TM IOCB failed (%x).\n", rval);
338 }
339
340 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
341 flags = tm_iocb->u.tmf.flags;
342 lun = (uint16_t)tm_iocb->u.tmf.lun;
343
344 /* Issue Marker IOCB */
345 qla2x00_marker(vha, vha->hw->req_q_map[0],
346 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
347 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
348 }
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700349
350done_free_sp:
Armen Baloyanfaef62d2014-02-26 04:15:17 -0500351 sp->free(vha, sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700352done:
353 return rval;
354}
355
Armen Baloyan4440e462014-02-26 04:15:18 -0500356static void
357qla24xx_abort_iocb_timeout(void *data)
358{
359 srb_t *sp = (srb_t *)data;
360 struct srb_iocb *abt = &sp->u.iocb_cmd;
361
362 abt->u.abt.comp_status = CS_TIMEOUT;
363 complete(&abt->u.abt.comp);
364}
365
366static void
367qla24xx_abort_sp_done(void *data, void *ptr, int res)
368{
369 srb_t *sp = (srb_t *)ptr;
370 struct srb_iocb *abt = &sp->u.iocb_cmd;
371
himanshu.madhani@cavium.com8f16e7d2018-02-12 10:28:14 -0800372 del_timer(&sp->u.iocb_cmd.timer);
Armen Baloyan4440e462014-02-26 04:15:18 -0500373 complete(&abt->u.abt.comp);
374}
375
376static int
377qla24xx_async_abort_cmd(srb_t *cmd_sp)
378{
379 scsi_qla_host_t *vha = cmd_sp->fcport->vha;
380 fc_port_t *fcport = cmd_sp->fcport;
381 struct srb_iocb *abt_iocb;
382 srb_t *sp;
383 int rval = QLA_FUNCTION_FAILED;
384
385 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
386 if (!sp)
387 goto done;
388
389 abt_iocb = &sp->u.iocb_cmd;
390 sp->type = SRB_ABT_CMD;
391 sp->name = "abort";
392 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
393 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
394 sp->done = qla24xx_abort_sp_done;
395 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
396 init_completion(&abt_iocb->u.abt.comp);
397
398 rval = qla2x00_start_sp(sp);
399 if (rval != QLA_SUCCESS)
400 goto done_free_sp;
401
402 ql_dbg(ql_dbg_async, vha, 0x507c,
403 "Abort command issued - hdl=%x, target_id=%x\n",
404 cmd_sp->handle, fcport->tgt_id);
405
406 wait_for_completion(&abt_iocb->u.abt.comp);
407
408 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
409 QLA_SUCCESS : QLA_FUNCTION_FAILED;
410
411done_free_sp:
412 sp->free(vha, sp);
413done:
414 return rval;
415}
416
417int
418qla24xx_async_abort_command(srb_t *sp)
419{
420 unsigned long flags = 0;
421
422 uint32_t handle;
423 fc_port_t *fcport = sp->fcport;
424 struct scsi_qla_host *vha = fcport->vha;
425 struct qla_hw_data *ha = vha->hw;
426 struct req_que *req = vha->req;
427
428 spin_lock_irqsave(&ha->hardware_lock, flags);
429 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
430 if (req->outstanding_cmds[handle] == sp)
431 break;
432 }
433 spin_unlock_irqrestore(&ha->hardware_lock, flags);
434 if (handle == req->num_outstanding_cmds) {
435 /* Command not found. */
436 return QLA_FUNCTION_FAILED;
437 }
438 if (sp->type == SRB_FXIOCB_DCMD)
439 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
440 FXDISC_ABORT_IOCTL);
441
442 return qla24xx_async_abort_cmd(sp);
443}
444
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700445void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700446qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
447 uint16_t *data)
448{
449 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700450
451 switch (data[0]) {
452 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700453 /*
454 * Driver must validate login state - If PRLI not complete,
455 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
456 * requests.
457 */
458 rval = qla2x00_get_port_database(vha, fcport, 0);
Arun Easi0eba25d2012-02-09 11:15:58 -0800459 if (rval == QLA_NOT_LOGGED_IN) {
460 fcport->flags &= ~FCF_ASYNC_SENT;
461 fcport->flags |= FCF_LOGIN_NEEDED;
462 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
463 break;
464 }
465
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700466 if (rval != QLA_SUCCESS) {
467 qla2x00_post_async_logout_work(vha, fcport, NULL);
468 qla2x00_post_async_login_work(vha, fcport, NULL);
469 break;
470 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700471 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700472 qla2x00_post_async_adisc_work(vha, fcport, data);
473 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700474 }
475 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700476 break;
477 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700478 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700479 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
480 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
481 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700482 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700483 break;
484 case MBS_PORT_ID_USED:
485 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700486 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700487 qla2x00_post_async_login_work(vha, fcport, NULL);
488 break;
489 case MBS_LOOP_ID_USED:
490 fcport->loop_id++;
491 rval = qla2x00_find_new_loop_id(vha, fcport);
492 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700493 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez80d79442011-03-30 11:46:17 -0700494 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700495 break;
496 }
497 qla2x00_post_async_login_work(vha, fcport, NULL);
498 break;
499 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700500 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700501}
502
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700503void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700504qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
505 uint16_t *data)
506{
Alexei Potashnika6ca8872015-07-14 16:00:44 -0400507 /* Don't re-login in target mode */
508 if (!fcport->tgt_session)
509 qla2x00_mark_device_lost(vha, fcport, 1, 0);
510 qlt_logo_completion_handler(fcport, data[0]);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700511 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700512}
513
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700514void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700515qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
516 uint16_t *data)
517{
518 if (data[0] == MBS_COMMAND_COMPLETE) {
519 qla2x00_update_fcport(vha, fcport);
520
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700521 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700522 }
523
524 /* Retry login. */
525 fcport->flags &= ~FCF_ASYNC_SENT;
526 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
527 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
528 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700529 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700530
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700531 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700532}
533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534/****************************************************************************/
535/* QLogic ISP2x00 Hardware Support Functions. */
536/****************************************************************************/
537
Saurav Kashyapfa492632012-11-21 02:40:29 -0500538static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400539qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
540{
541 int rval = QLA_SUCCESS;
542 struct qla_hw_data *ha = vha->hw;
543 uint32_t idc_major_ver, idc_minor_ver;
Saurav Kashyap711aa7f2012-08-22 14:21:15 -0400544 uint16_t config[4];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400545
546 qla83xx_idc_lock(vha, 0);
547
548 /* SV: TODO: Assign initialization timeout from
549 * flash-info / other param
550 */
551 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
552 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
553
554 /* Set our fcoe function presence */
555 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
556 ql_dbg(ql_dbg_p3p, vha, 0xb077,
557 "Error while setting DRV-Presence.\n");
558 rval = QLA_FUNCTION_FAILED;
559 goto exit;
560 }
561
562 /* Decide the reset ownership */
563 qla83xx_reset_ownership(vha);
564
565 /*
566 * On first protocol driver load:
567 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
568 * register.
569 * Others: Check compatibility with current IDC Major version.
570 */
571 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
572 if (ha->flags.nic_core_reset_owner) {
573 /* Set IDC Major version */
574 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
575 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
576
577 /* Clearing IDC-Lock-Recovery register */
578 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
579 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
580 /*
581 * Clear further IDC participation if we are not compatible with
582 * the current IDC Major Version.
583 */
584 ql_log(ql_log_warn, vha, 0xb07d,
585 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
586 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
587 __qla83xx_clear_drv_presence(vha);
588 rval = QLA_FUNCTION_FAILED;
589 goto exit;
590 }
591 /* Each function sets its supported Minor version. */
592 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
593 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
594 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
595
Saurav Kashyap711aa7f2012-08-22 14:21:15 -0400596 if (ha->flags.nic_core_reset_owner) {
597 memset(config, 0, sizeof(config));
598 if (!qla81xx_get_port_config(vha, config))
599 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
600 QLA8XXX_DEV_READY);
601 }
602
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400603 rval = qla83xx_idc_state_handler(vha);
604
605exit:
606 qla83xx_idc_unlock(vha, 0);
607
608 return rval;
609}
610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611/*
612* qla2x00_initialize_adapter
613* Initialize board.
614*
615* Input:
616* ha = adapter block pointer.
617*
618* Returns:
619* 0 = success
620*/
621int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800622qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623{
624 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800625 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800626 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700627
Joe Carnucciofc90ada2016-07-06 11:14:23 -0400628 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
629 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800632 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700633 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800634 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800635 ha->flags.pci_channel_io_perm_failure = 0;
636 ha->flags.eeh_busy = 0;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -0400637 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800638 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
639 atomic_set(&vha->loop_state, LOOP_DOWN);
640 vha->device_flags = DFLG_NO_CABLE;
641 vha->dpc_flags = 0;
642 vha->flags.management_server_logged_in = 0;
643 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 ha->isp_abort_cnt = 0;
645 ha->beacon_blink_led = 0;
646
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800647 set_bit(0, ha->req_qid_map);
648 set_bit(0, ha->rsp_qid_map);
649
Chad Dupuiscfb09192011-11-18 09:03:07 -0800650 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700651 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800652 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700654 ql_log(ql_log_warn, vha, 0x0044,
655 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 return (rval);
657 }
658
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800659 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800661 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700662 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700663 ql_log(ql_log_fatal, vha, 0x004f,
664 "Unable to validate FLASH data.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400665 return rval;
666 }
667
668 if (IS_QLA8044(ha)) {
669 qla8044_read_reset_template(vha);
670
671 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
672 * If DONRESET_BIT0 is set, drivers should not set dev_state
673 * to NEED_RESET. But if NEED_RESET is set, drivers should
674 * should honor the reset. */
675 if (ql2xdontresethba == 1)
676 qla8044_set_idc_dontreset(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700677 }
678
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800679 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -0800680 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700681 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700682
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800683 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700685 if (ha->flags.disable_serdes) {
686 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700687 ql_log(ql_log_info, vha, 0x0077,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -0400688 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700689 return QLA_FUNCTION_FAILED;
690 }
691
Chad Dupuiscfb09192011-11-18 09:03:07 -0800692 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700693 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800695 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
696 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800697 if (rval)
698 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800699 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800700 if (rval)
701 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700703
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700704 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800705 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700706 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700707 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700708 "Unable to configure ISP84XX.\n");
709 return QLA_FUNCTION_FAILED;
710 }
711 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400712
713 if (qla_ini_mode_enabled(vha))
714 rval = qla2x00_init_rings(vha);
715
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700716 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800718 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700719 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800720 rval = qla84xx_init_chip(vha);
721 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700722 ql_log(ql_log_warn, vha, 0x00d4,
723 "Unable to initialize ISP84XX.\n");
Bart Van Assche8d2b21d2015-06-04 15:58:09 -0700724 qla84xx_put_chip(vha);
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800725 }
726 }
727
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400728 /* Load the NIC Core f/w if we are the first protocol driver. */
729 if (IS_QLA8031(ha)) {
730 rval = qla83xx_nic_core_fw_load(vha);
731 if (rval)
732 ql_log(ql_log_warn, vha, 0x0124,
733 "Error in initializing NIC Core f/w.\n");
734 }
735
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500736 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
737 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700738
Joe Carnuccioc46e65c2013-08-27 01:37:35 -0400739 if (IS_P3P_TYPE(ha))
740 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
741 else
742 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 return (rval);
745}
746
747/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700748 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 * @ha: HA context
750 *
751 * Returns 0 on success.
752 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700753int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800754qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700756 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700757 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800758 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700759 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700762 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700765 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
767
Andrew Vasquez737faec2008-10-24 15:13:45 -0700768 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700770 /* Get PCI bus information. */
771 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700772 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700773 spin_unlock_irqrestore(&ha->hardware_lock, flags);
774
775 return QLA_SUCCESS;
776}
777
778/**
779 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
780 * @ha: HA context
781 *
782 * Returns 0 on success.
783 */
784int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800785qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700786{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700787 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700788 unsigned long flags = 0;
789 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800790 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700791 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700792
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700793 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700794 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700795
796 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700797 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700798
799 if (IS_QLA2322(ha) || IS_QLA6322(ha))
800 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700801 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700802
803 /*
804 * If this is a 2300 card and not 2312, reset the
805 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
806 * the 2310 also reports itself as a 2300 so we need to get the
807 * fb revision level -- a 6 indicates it really is a 2300 and
808 * not a 2310.
809 */
810 if (IS_QLA2300(ha)) {
811 spin_lock_irqsave(&ha->hardware_lock, flags);
812
813 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700814 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700815 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700816 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700817 break;
818
819 udelay(10);
820 }
821
822 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700823 WRT_REG_WORD(&reg->ctrl_status, 0x20);
824 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700825
826 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700827 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700828
829 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700830 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700831
832 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700833 WRT_REG_WORD(&reg->ctrl_status, 0x0);
834 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700835
836 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700837 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700838 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700839 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700840 break;
841
842 udelay(10);
843 }
844
845 spin_unlock_irqrestore(&ha->hardware_lock, flags);
846 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700847
848 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
849
Andrew Vasquez737faec2008-10-24 15:13:45 -0700850 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700851
852 /* Get PCI bus information. */
853 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700854 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700855 spin_unlock_irqrestore(&ha->hardware_lock, flags);
856
857 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858}
859
860/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700861 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
862 * @ha: HA context
863 *
864 * Returns 0 on success.
865 */
866int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800867qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700868{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700869 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700870 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800871 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700872 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700873
874 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700875 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700876
877 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700878 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700879 w &= ~PCI_COMMAND_INTX_DISABLE;
880 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
881
882 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
883
884 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700885 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
886 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700887
888 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700889 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -0400890 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700891
Andrew Vasquez737faec2008-10-24 15:13:45 -0700892 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700893
Auke Kok44c10132007-06-08 15:46:36 -0700894 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800895
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700896 /* Get PCI bus information. */
897 spin_lock_irqsave(&ha->hardware_lock, flags);
898 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
899 spin_unlock_irqrestore(&ha->hardware_lock, flags);
900
901 return QLA_SUCCESS;
902}
903
904/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700905 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
906 * @ha: HA context
907 *
908 * Returns 0 on success.
909 */
910int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800911qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700912{
913 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800914 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700915
916 pci_set_master(ha->pdev);
917 pci_try_set_mwi(ha->pdev);
918
919 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
920 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
921 w &= ~PCI_COMMAND_INTX_DISABLE;
922 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
923
924 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700925 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -0400926 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700927
Andrew Vasquez737faec2008-10-24 15:13:45 -0700928 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700929
930 ha->chip_revision = ha->pdev->revision;
931
932 return QLA_SUCCESS;
933}
934
935/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 * qla2x00_isp_firmware() - Choose firmware image.
937 * @ha: HA context
938 *
939 * Returns 0 on success.
940 */
941static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800942qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943{
944 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700945 uint16_t loop_id, topo, sw_cap;
946 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800947 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
949 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700950 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700953 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
955 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800956 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700957 if (rval == QLA_SUCCESS) {
958 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800959 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700960 &area, &domain, &topo, &sw_cap);
961 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 }
963
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700964 if (rval)
965 ql_dbg(ql_dbg_init, vha, 0x007a,
966 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
968 return (rval);
969}
970
971/**
972 * qla2x00_reset_chip() - Reset ISP chip.
973 * @ha: HA context
974 *
975 * Returns 0 on success.
976 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700977void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800978qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979{
980 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800981 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700982 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 uint16_t cmd;
985
Andrew Vasquez85880802009-12-15 21:29:46 -0800986 if (unlikely(pci_channel_offline(ha->pdev)))
987 return;
988
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700989 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
991 spin_lock_irqsave(&ha->hardware_lock, flags);
992
993 /* Turn off master enable */
994 cmd = 0;
995 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
996 cmd &= ~PCI_COMMAND_MASTER;
997 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
998
999 if (!IS_QLA2100(ha)) {
1000 /* Pause RISC. */
1001 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
1002 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
1003 for (cnt = 0; cnt < 30000; cnt++) {
1004 if ((RD_REG_WORD(&reg->hccr) &
1005 HCCR_RISC_PAUSE) != 0)
1006 break;
1007 udelay(100);
1008 }
1009 } else {
1010 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1011 udelay(10);
1012 }
1013
1014 /* Select FPM registers. */
1015 WRT_REG_WORD(&reg->ctrl_status, 0x20);
1016 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1017
1018 /* FPM Soft Reset. */
1019 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
1020 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
1021
1022 /* Toggle Fpm Reset. */
1023 if (!IS_QLA2200(ha)) {
1024 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
1025 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
1026 }
1027
1028 /* Select frame buffer registers. */
1029 WRT_REG_WORD(&reg->ctrl_status, 0x10);
1030 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1031
1032 /* Reset frame buffer FIFOs. */
1033 if (IS_QLA2200(ha)) {
1034 WRT_FB_CMD_REG(ha, reg, 0xa000);
1035 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
1036 } else {
1037 WRT_FB_CMD_REG(ha, reg, 0x00fc);
1038
1039 /* Read back fb_cmd until zero or 3 seconds max */
1040 for (cnt = 0; cnt < 3000; cnt++) {
1041 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
1042 break;
1043 udelay(100);
1044 }
1045 }
1046
1047 /* Select RISC module registers. */
1048 WRT_REG_WORD(&reg->ctrl_status, 0);
1049 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1050
1051 /* Reset RISC processor. */
1052 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1053 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1054
1055 /* Release RISC processor. */
1056 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1057 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1058 }
1059
1060 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
1061 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
1062
1063 /* Reset ISP chip. */
1064 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1065
1066 /* Wait for RISC to recover from reset. */
1067 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1068 /*
1069 * It is necessary to for a delay here since the card doesn't
1070 * respond to PCI reads during a reset. On some architectures
1071 * this will result in an MCA.
1072 */
1073 udelay(20);
1074 for (cnt = 30000; cnt; cnt--) {
1075 if ((RD_REG_WORD(&reg->ctrl_status) &
1076 CSR_ISP_SOFT_RESET) == 0)
1077 break;
1078 udelay(100);
1079 }
1080 } else
1081 udelay(10);
1082
1083 /* Reset RISC processor. */
1084 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1085
1086 WRT_REG_WORD(&reg->semaphore, 0);
1087
1088 /* Release RISC processor. */
1089 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1090 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1091
1092 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1093 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -07001094 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 udelay(100);
1098 }
1099 } else
1100 udelay(100);
1101
1102 /* Turn on master enable */
1103 cmd |= PCI_COMMAND_MASTER;
1104 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
1105
1106 /* Disable RISC pause on FPM parity error. */
1107 if (!IS_QLA2100(ha)) {
1108 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
1109 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1110 }
1111
1112 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1113}
1114
1115/**
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001116 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
1117 *
1118 * Returns 0 on success.
1119 */
Saurav Kashyapfa492632012-11-21 02:40:29 -05001120static int
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001121qla81xx_reset_mpi(scsi_qla_host_t *vha)
1122{
1123 uint16_t mb[4] = {0x1010, 0, 1, 0};
1124
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001125 if (!IS_QLA81XX(vha->hw))
1126 return QLA_SUCCESS;
1127
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001128 return qla81xx_write_mpi_register(vha, mb);
1129}
1130
1131/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001132 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001133 * @ha: HA context
1134 *
1135 * Returns 0 on success.
1136 */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001137static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001138qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001139{
1140 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001141 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001142 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Bart Van Assche52c82822015-07-09 07:23:26 -07001143 uint32_t cnt;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001144 uint16_t wd;
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001145 static int abts_cnt; /* ISP abort retry counts */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001146 int rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001147
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001148 spin_lock_irqsave(&ha->hardware_lock, flags);
1149
1150 /* Reset RISC. */
1151 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1152 for (cnt = 0; cnt < 30000; cnt++) {
1153 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
1154 break;
1155
1156 udelay(10);
1157 }
1158
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001159 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE))
1160 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
1161
1162 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
1163 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
1164 RD_REG_DWORD(&reg->hccr),
1165 RD_REG_DWORD(&reg->ctrl_status),
1166 (RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE));
1167
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001168 WRT_REG_DWORD(&reg->ctrl_status,
1169 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001170 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001171
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001172 udelay(100);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001173
Andrew Vasquez88c26662005-07-08 17:59:26 -07001174 /* Wait for firmware to complete NVRAM accesses. */
Bart Van Assche52c82822015-07-09 07:23:26 -07001175 RD_REG_WORD(&reg->mailbox0);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001176 for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
1177 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez88c26662005-07-08 17:59:26 -07001178 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001179 if (cnt)
1180 udelay(5);
1181 else
1182 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez88c26662005-07-08 17:59:26 -07001183 }
1184
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001185 if (rval == QLA_SUCCESS)
1186 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
1187
1188 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
1189 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
1190 RD_REG_DWORD(&reg->hccr),
1191 RD_REG_DWORD(&reg->mailbox0));
1192
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001193 /* Wait for soft-reset to complete. */
Bart Van Assche52c82822015-07-09 07:23:26 -07001194 RD_REG_DWORD(&reg->ctrl_status);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001195 for (cnt = 0; cnt < 6000000; cnt++) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001196 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001197 if ((RD_REG_DWORD(&reg->ctrl_status) &
1198 CSRX_ISP_SOFT_RESET) == 0)
1199 break;
1200
1201 udelay(5);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001202 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001203 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_ISP_SOFT_RESET))
1204 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
1205
1206 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
1207 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
1208 RD_REG_DWORD(&reg->hccr),
1209 RD_REG_DWORD(&reg->ctrl_status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001210
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001211 /* If required, do an MPI FW reset now */
1212 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1213 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1214 if (++abts_cnt < 5) {
1215 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1216 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1217 } else {
1218 /*
1219 * We exhausted the ISP abort retries. We have to
1220 * set the board offline.
1221 */
1222 abts_cnt = 0;
1223 vha->flags.online = 0;
1224 }
1225 }
1226 }
1227
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001228 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1229 RD_REG_DWORD(&reg->hccr);
1230
1231 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1232 RD_REG_DWORD(&reg->hccr);
1233
1234 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1235 RD_REG_DWORD(&reg->hccr);
1236
Bart Van Assche52c82822015-07-09 07:23:26 -07001237 RD_REG_WORD(&reg->mailbox0);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001238 for (cnt = 6000000; RD_REG_WORD(&reg->mailbox0) != 0 &&
1239 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001240 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001241 if (cnt)
1242 udelay(5);
1243 else
1244 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001245 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001246 if (rval == QLA_SUCCESS)
1247 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
1248
1249 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
1250 "Host Risc 0x%x, mailbox0 0x%x\n",
1251 RD_REG_DWORD(&reg->hccr),
1252 RD_REG_WORD(&reg->mailbox0));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001253
1254 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001255
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001256 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
1257 "Driver in %s mode\n",
1258 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
1259
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001260 if (IS_NOPOLLING_TYPE(ha))
1261 ha->isp_ops->enable_intrs(ha);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04001262
1263 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001264}
1265
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001266static void
1267qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
1268{
1269 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1270
1271 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1272 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
1273
1274}
1275
1276static void
1277qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
1278{
1279 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1280
1281 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1282 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
1283}
1284
1285static void
1286qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
1287{
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001288 uint32_t wd32 = 0;
1289 uint delta_msec = 100;
1290 uint elapsed_msec = 0;
1291 uint timeout_msec;
1292 ulong n;
1293
Joe Carnucciocc790762015-08-04 13:37:53 -04001294 if (vha->hw->pdev->subsystem_device != 0x0175 &&
1295 vha->hw->pdev->subsystem_device != 0x0240)
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001296 return;
1297
Joe Carnuccio8dd7e3a2015-08-04 13:37:54 -04001298 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
1299 udelay(100);
1300
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001301attempt:
1302 timeout_msec = TIMEOUT_SEMAPHORE;
1303 n = timeout_msec / delta_msec;
1304 while (n--) {
1305 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
1306 qla25xx_read_risc_sema_reg(vha, &wd32);
1307 if (wd32 & RISC_SEMAPHORE)
1308 break;
1309 msleep(delta_msec);
1310 elapsed_msec += delta_msec;
1311 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1312 goto force;
1313 }
1314
1315 if (!(wd32 & RISC_SEMAPHORE))
1316 goto force;
1317
1318 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1319 goto acquired;
1320
1321 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
1322 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
1323 n = timeout_msec / delta_msec;
1324 while (n--) {
1325 qla25xx_read_risc_sema_reg(vha, &wd32);
1326 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1327 break;
1328 msleep(delta_msec);
1329 elapsed_msec += delta_msec;
1330 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1331 goto force;
1332 }
1333
1334 if (wd32 & RISC_SEMAPHORE_FORCE)
1335 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
1336
1337 goto attempt;
1338
1339force:
1340 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
1341
1342acquired:
1343 return;
1344}
1345
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001346/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001347 * qla24xx_reset_chip() - Reset ISP24xx chip.
1348 * @ha: HA context
1349 *
1350 * Returns 0 on success.
1351 */
1352void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001353qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001354{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001355 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001356
1357 if (pci_channel_offline(ha->pdev) &&
1358 ha->flags.pci_channel_io_perm_failure) {
1359 return;
1360 }
1361
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001362 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001363
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001364 qla25xx_manipulate_risc_semaphore(vha);
1365
Andrew Vasquez88c26662005-07-08 17:59:26 -07001366 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001367 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001368}
1369
1370/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 * qla2x00_chip_diag() - Test chip for proper operation.
1372 * @ha: HA context
1373 *
1374 * Returns 0 on success.
1375 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001376int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001377qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378{
1379 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001380 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001381 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 unsigned long flags = 0;
1383 uint16_t data;
1384 uint32_t cnt;
1385 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001386 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
1388 /* Assume a failed state */
1389 rval = QLA_FUNCTION_FAILED;
1390
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001391 ql_dbg(ql_dbg_init, vha, 0x007b,
1392 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
1394 spin_lock_irqsave(&ha->hardware_lock, flags);
1395
1396 /* Reset ISP chip. */
1397 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1398
1399 /*
1400 * We need to have a delay here since the card will not respond while
1401 * in reset causing an MCA on some architectures.
1402 */
1403 udelay(20);
1404 data = qla2x00_debounce_register(&reg->ctrl_status);
1405 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1406 udelay(5);
1407 data = RD_REG_WORD(&reg->ctrl_status);
1408 barrier();
1409 }
1410
1411 if (!cnt)
1412 goto chip_diag_failed;
1413
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001414 ql_dbg(ql_dbg_init, vha, 0x007c,
1415 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
1417 /* Reset RISC processor. */
1418 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1419 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1420
1421 /* Workaround for QLA2312 PCI parity error */
1422 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1423 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1424 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1425 udelay(5);
1426 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001427 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 }
1429 } else
1430 udelay(10);
1431
1432 if (!cnt)
1433 goto chip_diag_failed;
1434
1435 /* Check product ID of chip */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001436 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
1438 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1439 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1440 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1441 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1442 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1443 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001444 ql_log(ql_log_warn, vha, 0x0062,
1445 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1446 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
1448 goto chip_diag_failed;
1449 }
1450 ha->product_id[0] = mb[1];
1451 ha->product_id[1] = mb[2];
1452 ha->product_id[2] = mb[3];
1453 ha->product_id[3] = mb[4];
1454
1455 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001456 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1458 else
1459 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001460 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
1462 if (IS_QLA2200(ha) &&
1463 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1464 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001465 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001467 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 ha->fw_transfer_size = 128;
1469 }
1470
1471 /* Wrap Incoming Mailboxes Test. */
1472 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1473
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001474 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001475 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001476 if (rval)
1477 ql_log(ql_log_warn, vha, 0x0080,
1478 "Failed mailbox send register test.\n");
1479 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 /* Flag a successful rval */
1481 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 spin_lock_irqsave(&ha->hardware_lock, flags);
1483
1484chip_diag_failed:
1485 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001486 ql_log(ql_log_info, vha, 0x0081,
1487 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
1489 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1490
1491 return (rval);
1492}
1493
1494/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001495 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1496 * @ha: HA context
1497 *
1498 * Returns 0 on success.
1499 */
1500int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001501qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001502{
1503 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001504 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001505 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001506
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001507 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07001508 return QLA_SUCCESS;
1509
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001510 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001511
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001512 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001513 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001514 ql_log(ql_log_warn, vha, 0x0082,
1515 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001516 } else {
1517 /* Flag a successful rval */
1518 rval = QLA_SUCCESS;
1519 }
1520
1521 return rval;
1522}
1523
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001524void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001525qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001526{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001527 int rval;
1528 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001529 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001530 dma_addr_t tc_dma;
1531 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001532 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001533 struct req_que *req = ha->req_q_map[0];
1534 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001535
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001536 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001537 ql_dbg(ql_dbg_init, vha, 0x00bd,
1538 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001539 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001540 }
1541
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001542 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04001543 ha->fw_dump_cap_flags = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001544 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
1545 req_q_size = rsp_q_size = 0;
1546
1547 if (IS_QLA27XX(ha))
1548 goto try_fce;
1549
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001550 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1551 fixed_size = sizeof(struct qla2100_fw_dump);
1552 } else if (IS_QLA23XX(ha)) {
1553 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1554 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1555 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001556 } else if (IS_FWI2_CAPABLE(ha)) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04001557 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001558 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
1559 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001560 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1561 else if (IS_QLA25XX(ha))
1562 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1563 else
1564 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Chad Dupuisf73cb692014-02-26 04:15:06 -05001565
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001566 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1567 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001568 if (ha->mqenable) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04001569 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001570 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001571 /*
1572 * Allocate maximum buffer size for all queues.
1573 * Resizing must be done at end-of-dump processing.
1574 */
1575 mq_size += ha->max_req_queues *
1576 (req->length * sizeof(request_t));
1577 mq_size += ha->max_rsp_queues *
1578 (rsp->length * sizeof(response_t));
1579 }
Arun Easi00876ae2013-03-25 02:21:37 -04001580 if (ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001581 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001582 /* Allocate memory for Fibre Channel Event Buffer. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05001583 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
1584 !IS_QLA27XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001585 goto try_eft;
1586
Chad Dupuisf73cb692014-02-26 04:15:06 -05001587try_fce:
1588 if (ha->fce)
1589 dma_free_coherent(&ha->pdev->dev,
1590 FCE_SIZE, ha->fce, ha->fce_dma);
1591
1592 /* Allocate memory for Fibre Channel Event Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07001593 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1594 GFP_KERNEL);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001595 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001596 ql_log(ql_log_warn, vha, 0x00be,
1597 "Unable to allocate (%d KB) for FCE.\n",
1598 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001599 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001600 }
1601
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001602 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001603 ha->fce_mb, &ha->fce_bufs);
1604 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001605 ql_log(ql_log_warn, vha, 0x00bf,
1606 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001607 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1608 tc_dma);
1609 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001610 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001611 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001612 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001613 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001614
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001615 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001616 ha->flags.fce_enabled = 1;
1617 ha->fce_dma = tc_dma;
1618 ha->fce = tc;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001619
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001620try_eft:
Chad Dupuisf73cb692014-02-26 04:15:06 -05001621 if (ha->eft)
1622 dma_free_coherent(&ha->pdev->dev,
1623 EFT_SIZE, ha->eft, ha->eft_dma);
1624
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001625 /* Allocate memory for Extended Trace Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07001626 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
1627 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001628 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001629 ql_log(ql_log_warn, vha, 0x00c1,
1630 "Unable to allocate (%d KB) for EFT.\n",
1631 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001632 goto cont_alloc;
1633 }
1634
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001635 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001636 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001637 ql_log(ql_log_warn, vha, 0x00c2,
1638 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001639 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1640 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001641 goto cont_alloc;
1642 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001643 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001644 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001645
1646 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001647 ha->eft_dma = tc_dma;
1648 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001649 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05001650
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001651cont_alloc:
Chad Dupuisf73cb692014-02-26 04:15:06 -05001652 if (IS_QLA27XX(ha)) {
1653 if (!ha->fw_dump_template) {
1654 ql_log(ql_log_warn, vha, 0x00ba,
1655 "Failed missing fwdump template\n");
1656 return;
1657 }
1658 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
1659 ql_dbg(ql_dbg_init, vha, 0x00fa,
1660 "-> allocating fwdump (%x bytes)...\n", dump_size);
1661 goto allocate;
1662 }
1663
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001664 req_q_size = req->length * sizeof(request_t);
1665 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001666 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001667 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001668 ha->chain_offset = dump_size;
1669 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001670
Chad Dupuisf73cb692014-02-26 04:15:06 -05001671allocate:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001672 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001673 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001674 ql_log(ql_log_warn, vha, 0x00c4,
1675 "Unable to allocate (%d KB) for firmware dump.\n",
1676 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001677
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001678 if (ha->fce) {
1679 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1680 ha->fce_dma);
1681 ha->fce = NULL;
1682 ha->fce_dma = 0;
1683 }
1684
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001685 if (ha->eft) {
1686 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1687 ha->eft_dma);
1688 ha->eft = NULL;
1689 ha->eft_dma = 0;
1690 }
1691 return;
1692 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05001693 ha->fw_dump_len = dump_size;
Chad Dupuiscfb09192011-11-18 09:03:07 -08001694 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001695 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001696
Chad Dupuisf73cb692014-02-26 04:15:06 -05001697 if (IS_QLA27XX(ha))
1698 return;
1699
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001700 ha->fw_dump->signature[0] = 'Q';
1701 ha->fw_dump->signature[1] = 'L';
1702 ha->fw_dump->signature[2] = 'G';
1703 ha->fw_dump->signature[3] = 'C';
Bart Van Asschead950362015-07-09 07:24:08 -07001704 ha->fw_dump->version = htonl(1);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001705
1706 ha->fw_dump->fixed_size = htonl(fixed_size);
1707 ha->fw_dump->mem_size = htonl(mem_size);
1708 ha->fw_dump->req_q_size = htonl(req_q_size);
1709 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1710
1711 ha->fw_dump->eft_size = htonl(eft_size);
1712 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1713 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1714
1715 ha->fw_dump->header_size =
1716 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001717}
1718
Andrew Vasquez18e75552009-06-03 09:55:30 -07001719static int
1720qla81xx_mpi_sync(scsi_qla_host_t *vha)
1721{
1722#define MPS_MASK 0xe0
1723 int rval;
1724 uint16_t dc;
1725 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07001726
1727 if (!IS_QLA81XX(vha->hw))
1728 return QLA_SUCCESS;
1729
1730 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1731 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001732 ql_log(ql_log_warn, vha, 0x0105,
1733 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001734 goto done;
1735 }
1736
1737 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1738 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1739 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001740 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001741 goto done_release;
1742 }
1743
1744 dc &= MPS_MASK;
1745 if (dc == (dw & MPS_MASK))
1746 goto done_release;
1747
1748 dw &= ~MPS_MASK;
1749 dw |= dc;
1750 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1751 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001752 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001753 }
1754
1755done_release:
1756 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1757 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001758 ql_log(ql_log_warn, vha, 0x006d,
1759 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001760 }
1761
1762done:
1763 return rval;
1764}
1765
Chad Dupuis8d93f552013-01-30 03:34:37 -05001766int
1767qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
1768{
1769 /* Don't try to reallocate the array */
1770 if (req->outstanding_cmds)
1771 return QLA_SUCCESS;
1772
1773 if (!IS_FWI2_CAPABLE(ha) || (ha->mqiobase &&
1774 (ql2xmultique_tag || ql2xmaxqueues > 1)))
1775 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
1776 else {
Quinn Tran03e8c682015-12-17 14:56:59 -05001777 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
1778 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05001779 else
Quinn Tran03e8c682015-12-17 14:56:59 -05001780 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05001781 }
1782
1783 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1784 req->num_outstanding_cmds, GFP_KERNEL);
1785
1786 if (!req->outstanding_cmds) {
1787 /*
1788 * Try to allocate a minimal size just so we can get through
1789 * initialization.
1790 */
1791 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
1792 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1793 req->num_outstanding_cmds, GFP_KERNEL);
1794
1795 if (!req->outstanding_cmds) {
1796 ql_log(ql_log_fatal, NULL, 0x0126,
1797 "Failed to allocate memory for "
1798 "outstanding_cmds for req_que %p.\n", req);
1799 req->num_outstanding_cmds = 0;
1800 return QLA_FUNCTION_FAILED;
1801 }
1802 }
1803
1804 return QLA_SUCCESS;
1805}
1806
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001807/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 * qla2x00_setup_chip() - Load and start RISC firmware.
1809 * @ha: HA context
1810 *
1811 * Returns 0 on success.
1812 */
1813static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001814qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001816 int rval;
1817 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001818 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001819 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1820 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001821 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001822
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001823 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001824 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001825 if (rval == QLA_SUCCESS) {
1826 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001827 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001828 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001829 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001830 }
1831
Andrew Vasquez3db06522008-01-31 12:33:49 -08001832 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1833 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1834 spin_lock_irqsave(&ha->hardware_lock, flags);
1835 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1836 RD_REG_WORD(&reg->hccr);
1837 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1838 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839
Andrew Vasquez18e75552009-06-03 09:55:30 -07001840 qla81xx_mpi_sync(vha);
1841
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001843 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001844 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001845 ql_dbg(ql_dbg_init, vha, 0x00c9,
1846 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001848 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 if (rval == QLA_SUCCESS) {
1850 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001851 ql_dbg(ql_dbg_init, vha, 0x00ca,
1852 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05001854 if (ql2xexlogins)
1855 ha->flags.exlogins_enabled = 1;
1856
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001857 if (ql2xexchoffld)
1858 ha->flags.exchoffld_enabled = 1;
1859
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001860 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001862 if (rval == QLA_SUCCESS) {
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05001863 rval = qla2x00_set_exlogins_buffer(vha);
1864 if (rval != QLA_SUCCESS)
1865 goto failed;
1866
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001867 rval = qla2x00_set_exchoffld_buffer(vha);
1868 if (rval != QLA_SUCCESS)
1869 goto failed;
1870
Giridhar Malavalia9083012010-04-12 17:59:55 -07001871enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001872 fw_major_version = ha->fw_major_version;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001873 if (IS_P3P_TYPE(ha))
Giridhar Malavali31731672011-08-16 11:31:54 -07001874 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001875 else
1876 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001877 if (rval != QLA_SUCCESS)
1878 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001879 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001880 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001881 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001882 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001883 if ((!ha->max_npiv_vports) ||
1884 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001885 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001886 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001887 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001888 }
Quinn Tran03e8c682015-12-17 14:56:59 -05001889 qla2x00_get_resource_cnts(vha);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001890
Chad Dupuis8d93f552013-01-30 03:34:37 -05001891 /*
1892 * Allocate the array of outstanding commands
1893 * now that we know the firmware resources.
1894 */
1895 rval = qla2x00_alloc_outstanding_cmds(ha,
1896 vha->req);
1897 if (rval != QLA_SUCCESS)
1898 goto failed;
1899
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08001900 if (!fw_major_version && ql2xallocfwdump
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001901 && !(IS_P3P_TYPE(ha)))
Giridhar Malavali08de2842011-08-16 11:31:44 -07001902 qla2x00_alloc_fw_dump(vha);
Chad Dupuis3b6e5b92013-10-30 03:38:09 -04001903 } else {
1904 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 }
1906 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001907 ql_log(ql_log_fatal, vha, 0x00cd,
1908 "ISP Firmware failed checksum.\n");
1909 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04001911 } else
1912 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913
Andrew Vasquez3db06522008-01-31 12:33:49 -08001914 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1915 /* Enable proper parity. */
1916 spin_lock_irqsave(&ha->hardware_lock, flags);
1917 if (IS_QLA2300(ha))
1918 /* SRAM parity */
1919 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1920 else
1921 /* SRAM, Instruction RAM and GP RAM parity */
1922 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1923 RD_REG_WORD(&reg->hccr);
1924 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1925 }
1926
Chad Dupuisf3982d82014-09-25 05:16:57 -04001927 if (IS_QLA27XX(ha))
1928 ha->flags.fac_supported = 1;
1929 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001930 uint32_t size;
1931
1932 rval = qla81xx_fac_get_sector_size(vha, &size);
1933 if (rval == QLA_SUCCESS) {
1934 ha->flags.fac_supported = 1;
1935 ha->fdt_block_size = size << 2;
1936 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001937 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001938 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1939 ha->fw_major_version, ha->fw_minor_version,
1940 ha->fw_subminor_version);
Joe Carnuccio1ca60e32014-02-26 04:15:02 -05001941
Chad Dupuisf73cb692014-02-26 04:15:06 -05001942 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001943 ha->flags.fac_supported = 0;
1944 rval = QLA_SUCCESS;
1945 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001946 }
1947 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001948failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001950 ql_log(ql_log_fatal, vha, 0x00cf,
1951 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 }
1953
1954 return (rval);
1955}
1956
1957/**
1958 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1959 * @ha: HA context
1960 *
1961 * Beginning of request ring has initialization control block already built
1962 * by nvram config routine.
1963 *
1964 * Returns 0 on success.
1965 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001966void
1967qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968{
1969 uint16_t cnt;
1970 response_t *pkt;
1971
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001972 rsp->ring_ptr = rsp->ring;
1973 rsp->ring_index = 0;
1974 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001975 pkt = rsp->ring_ptr;
1976 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 pkt->signature = RESPONSE_PROCESSED;
1978 pkt++;
1979 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980}
1981
1982/**
1983 * qla2x00_update_fw_options() - Read and process firmware options.
1984 * @ha: HA context
1985 *
1986 * Returns 0 on success.
1987 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001988void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001989qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990{
1991 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001992 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
1994 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001995 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
1997 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1998 return;
1999
2000 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002001 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
2002 "Serial link options.\n");
2003 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
2004 (uint8_t *)&ha->fw_seriallink_options,
2005 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
2007 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
2008 if (ha->fw_seriallink_options[3] & BIT_2) {
2009 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
2010
2011 /* 1G settings */
2012 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
2013 emphasis = (ha->fw_seriallink_options[2] &
2014 (BIT_4 | BIT_3)) >> 3;
2015 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002016 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 rx_sens = (ha->fw_seriallink_options[0] &
2018 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
2019 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
2020 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2021 if (rx_sens == 0x0)
2022 rx_sens = 0x3;
2023 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
2024 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2025 ha->fw_options[10] |= BIT_5 |
2026 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2027 (tx_sens & (BIT_1 | BIT_0));
2028
2029 /* 2G settings */
2030 swing = (ha->fw_seriallink_options[2] &
2031 (BIT_7 | BIT_6 | BIT_5)) >> 5;
2032 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
2033 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002034 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 rx_sens = (ha->fw_seriallink_options[1] &
2036 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
2037 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
2038 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2039 if (rx_sens == 0x0)
2040 rx_sens = 0x3;
2041 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
2042 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2043 ha->fw_options[11] |= BIT_5 |
2044 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2045 (tx_sens & (BIT_1 | BIT_0));
2046 }
2047
2048 /* FCP2 options. */
2049 /* Return command IOCBs without waiting for an ABTS to complete. */
2050 ha->fw_options[3] |= BIT_13;
2051
2052 /* LED scheme. */
2053 if (ha->flags.enable_led_scheme)
2054 ha->fw_options[2] |= BIT_12;
2055
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002056 /* Detect ISP6312. */
2057 if (IS_QLA6312(ha))
2058 ha->fw_options[2] |= BIT_13;
2059
Giridhar Malavali088d09d2016-07-06 11:14:20 -04002060 /* Set Retry FLOGI in case of P2P connection */
2061 if (ha->operating_mode == P2P) {
2062 ha->fw_options[2] |= BIT_3;
2063 ql_dbg(ql_dbg_disc, vha, 0x2100,
2064 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
2065 __func__, ha->fw_options[2]);
2066 }
2067
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002069 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070}
2071
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002072void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002073qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002074{
2075 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002076 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002077
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002078 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07002079 return;
2080
Himanshu Madhanif198caf2016-01-27 12:03:30 -05002081 /* Hold status IOCBs until ABTS response received. */
2082 if (ql2xfwholdabts)
2083 ha->fw_options[3] |= BIT_12;
2084
Giridhar Malavali088d09d2016-07-06 11:14:20 -04002085 /* Set Retry FLOGI in case of P2P connection */
2086 if (ha->operating_mode == P2P) {
2087 ha->fw_options[2] |= BIT_3;
2088 ql_dbg(ql_dbg_disc, vha, 0x2101,
2089 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
2090 __func__, ha->fw_options[2]);
2091 }
2092
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002093 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08002094 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002095 return;
2096
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002097 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08002098 le16_to_cpu(ha->fw_seriallink_options24[1]),
2099 le16_to_cpu(ha->fw_seriallink_options24[2]),
2100 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002101 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002102 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002103 "Unable to update Serial Link options (%x).\n", rval);
2104 }
2105}
2106
2107void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002108qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002109{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002110 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002111 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002112 struct req_que *req = ha->req_q_map[0];
2113 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002114
2115 /* Setup ring parameters in initialization control block. */
Bart Van Asschead950362015-07-09 07:24:08 -07002116 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
2117 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002118 ha->init_cb->request_q_length = cpu_to_le16(req->length);
2119 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
2120 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2121 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2122 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2123 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002124
2125 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
2126 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
2127 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
2128 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
2129 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
2130}
2131
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002132void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002133qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002134{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002135 struct qla_hw_data *ha = vha->hw;
Bart Van Assche118e2ef2015-07-09 07:24:27 -07002136 device_reg_t *reg = ISP_QUE_REG(ha, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002137 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
2138 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002139 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002140 uint16_t rid = 0;
2141 struct req_que *req = ha->req_q_map[0];
2142 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002143
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002144 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002145 icb = (struct init_cb_24xx *)ha->init_cb;
Bart Van Asschead950362015-07-09 07:24:08 -07002146 icb->request_q_outpointer = cpu_to_le16(0);
2147 icb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002148 icb->request_q_length = cpu_to_le16(req->length);
2149 icb->response_q_length = cpu_to_le16(rsp->length);
2150 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
2151 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
2152 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
2153 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002154
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002155 /* Setup ATIO queue dma pointers for target mode */
Bart Van Asschead950362015-07-09 07:24:08 -07002156 icb->atio_q_inpointer = cpu_to_le16(0);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002157 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
2158 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
2159 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
2160
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002161 if (IS_SHADOW_REG_CAPABLE(ha))
Bart Van Asschead950362015-07-09 07:24:08 -07002162 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002163
Chad Dupuisf73cb692014-02-26 04:15:06 -05002164 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07002165 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
2166 icb->rid = cpu_to_le16(rid);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002167 if (ha->flags.msix_enabled) {
2168 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002169 ql_dbg(ql_dbg_init, vha, 0x00fd,
2170 "Registering vector 0x%x for base que.\n",
2171 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002172 icb->msix = cpu_to_le16(msix->entry);
2173 }
2174 /* Use alternate PCI bus number */
2175 if (MSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07002176 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002177 /* Use alternate PCI devfn */
2178 if (LSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07002179 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002180
Anirban Chakraborty31557542009-12-02 10:36:55 -08002181 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002182 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
2183 (ha->flags.msix_enabled)) {
Bart Van Asschead950362015-07-09 07:24:08 -07002184 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002185 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002186 ql_dbg(ql_dbg_init, vha, 0x00fe,
2187 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08002188 } else {
Bart Van Asschead950362015-07-09 07:24:08 -07002189 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08002190 }
Bart Van Asschead950362015-07-09 07:24:08 -07002191 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002192
2193 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
2194 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
2195 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
2196 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
2197 } else {
2198 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
2199 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
2200 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
2201 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
2202 }
Arun Easiaa230bc2013-01-30 03:34:39 -05002203 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002204
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002205 /* PCI posting */
2206 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002207}
2208
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209/**
2210 * qla2x00_init_rings() - Initializes firmware.
2211 * @ha: HA context
2212 *
2213 * Beginning of request ring has initialization control block already built
2214 * by nvram config routine.
2215 *
2216 * Returns 0 on success.
2217 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002218int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002219qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220{
2221 int rval;
2222 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002223 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002224 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002225 struct req_que *req;
2226 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002227 struct mid_init_cb_24xx *mid_init_cb =
2228 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229
2230 spin_lock_irqsave(&ha->hardware_lock, flags);
2231
2232 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002233 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002234 req = ha->req_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05002235 if (!req || !test_bit(que, ha->req_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002236 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002237 req->out_ptr = (void *)(req->ring + req->length);
2238 *req->out_ptr = 0;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002239 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002240 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002242 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002243
2244 /* Initialize firmware. */
2245 req->ring_ptr = req->ring;
2246 req->ring_index = 0;
2247 req->cnt = req->length;
2248 }
2249
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002250 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002251 rsp = ha->rsp_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05002252 if (!rsp || !test_bit(que, ha->rsp_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002253 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04002254 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
2255 *rsp->in_ptr = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002256 /* Initialize response queue entries */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002257 if (IS_QLAFX00(ha))
2258 qlafx00_init_response_q_entries(rsp);
2259 else
2260 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002261 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002263 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
2264 ha->tgt.atio_ring_index = 0;
2265 /* Initialize ATIO queue entries */
2266 qlt_init_atio_q_entries(vha);
2267
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002268 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269
2270 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2271
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002272 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
2273
2274 if (IS_QLAFX00(ha)) {
2275 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
2276 goto next_check;
2277 }
2278
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002280 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002282 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04002283 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002284 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08002285 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002286 }
2287
Andrew Vasquez24a08132009-03-24 09:08:16 -07002288 if (IS_FWI2_CAPABLE(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07002289 mid_init_cb->options = cpu_to_le16(BIT_1);
Andrew Vasquez24a08132009-03-24 09:08:16 -07002290 mid_init_cb->init_cb.execution_throttle =
Quinn Tran03e8c682015-12-17 14:56:59 -05002291 cpu_to_le16(ha->cur_fw_xcb_count);
Joe Carnuccio40f38622016-07-06 11:14:28 -04002292 ha->flags.dport_enabled =
2293 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
2294 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
2295 (ha->flags.dport_enabled) ? "enabled" : "disabled");
2296 /* FA-WWPN Status */
Himanshu Madhani2486c622014-09-25 05:17:00 -04002297 ha->flags.fawwpn_enabled =
Joe Carnuccio40f38622016-07-06 11:14:28 -04002298 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
Himanshu Madhani2486c622014-09-25 05:17:00 -04002299 ql_dbg(ql_dbg_init, vha, 0x0141, "FA-WWPN Support: %s.\n",
2300 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
Andrew Vasquez24a08132009-03-24 09:08:16 -07002301 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002302
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002303 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002304next_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002306 ql_log(ql_log_fatal, vha, 0x00d2,
2307 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002309 ql_dbg(ql_dbg_init, vha, 0x00d3,
2310 "Init Firmware -- success.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 }
2312
2313 return (rval);
2314}
2315
2316/**
2317 * qla2x00_fw_ready() - Waits for firmware ready.
2318 * @ha: HA context
2319 *
2320 * Returns 0 on success.
2321 */
2322static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002323qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324{
2325 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002326 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 uint16_t min_wait; /* Minimum wait time if loop is down */
2328 uint16_t wait_time; /* Wait time if loop is coming ready */
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002329 uint16_t state[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002330 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04002332 if (IS_QLAFX00(vha->hw))
2333 return qlafx00_fw_ready(vha);
2334
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 rval = QLA_SUCCESS;
2336
Chad Dupuis33461492015-04-09 14:59:57 -04002337 /* Time to wait for loop down */
2338 if (IS_P3P_TYPE(ha))
2339 min_wait = 30;
2340 else
2341 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342
2343 /*
2344 * Firmware should take at most one RATOV to login, plus 5 seconds for
2345 * our own processing.
2346 */
2347 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
2348 wait_time = min_wait;
2349 }
2350
2351 /* Min wait time if loop down */
2352 mtime = jiffies + (min_wait * HZ);
2353
2354 /* wait time before firmware ready */
2355 wtime = jiffies + (wait_time * HZ);
2356
2357 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002358 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002359 ql_log(ql_log_info, vha, 0x801e,
2360 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
2362 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05002363 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002364 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002366 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002367 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002369 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002370 ql_dbg(ql_dbg_taskm, vha, 0x801f,
2371 "fw_state=%x 84xx=%x.\n", state[0],
2372 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002373 if ((state[2] & FSTATE_LOGGED_IN) &&
2374 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002375 ql_dbg(ql_dbg_taskm, vha, 0x8028,
2376 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002377
2378 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002379 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002380 if (rval != QLA_SUCCESS) {
2381 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002382 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002383 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002384 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002385 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002386
2387 /* Add time taken to initialize. */
2388 cs84xx_time = jiffies - cs84xx_time;
2389 wtime += cs84xx_time;
2390 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002391 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002392 "Increasing wait time by %ld. "
2393 "New time %ld.\n", cs84xx_time,
2394 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002395 }
2396 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002397 ql_dbg(ql_dbg_taskm, vha, 0x8037,
2398 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002400 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 &ha->login_timeout, &ha->r_a_tov);
2402
2403 rval = QLA_SUCCESS;
2404 break;
2405 }
2406
2407 rval = QLA_FUNCTION_FAILED;
2408
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002409 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002410 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002412 * other than Wait for Login.
2413 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002415 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 "Cable is unplugged...\n");
2417
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002418 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 break;
2420 }
2421 }
2422 } else {
2423 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07002424 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08002425 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 break;
2427 }
2428
2429 if (time_after_eq(jiffies, wtime))
2430 break;
2431
2432 /* Delay for a while */
2433 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 } while (1);
2435
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002436 ql_dbg(ql_dbg_taskm, vha, 0x803a,
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002437 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
2438 state[1], state[2], state[3], state[4], state[5], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439
Chad Dupuiscfb09192011-11-18 09:03:07 -08002440 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002441 ql_log(ql_log_warn, vha, 0x803b,
2442 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 }
2444
2445 return (rval);
2446}
2447
2448/*
2449* qla2x00_configure_hba
2450* Setup adapter context.
2451*
2452* Input:
2453* ha = adapter state pointer.
2454*
2455* Returns:
2456* 0 = success
2457*
2458* Context:
2459* Kernel context.
2460*/
2461static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002462qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463{
2464 int rval;
2465 uint16_t loop_id;
2466 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002467 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 uint8_t al_pa;
2469 uint8_t area;
2470 uint8_t domain;
2471 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002472 struct qla_hw_data *ha = vha->hw;
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002473 unsigned long flags;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002474 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
2476 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002477 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002478 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002480 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002481 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002482 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002483 ql_dbg(ql_dbg_disc, vha, 0x2008,
2484 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08002485 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002486 ql_log(ql_log_warn, vha, 0x2009,
2487 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002488 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
2489 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
2490 ql_log(ql_log_warn, vha, 0x1151,
2491 "Doing link init.\n");
2492 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
2493 return rval;
2494 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002495 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 return (rval);
2498 }
2499
2500 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002501 ql_log(ql_log_info, vha, 0x200a,
2502 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 return (QLA_FUNCTION_FAILED);
2504 }
2505
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002506 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507
2508 /* initialize */
2509 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2510 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002511 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512
2513 switch (topo) {
2514 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002515 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 ha->current_topology = ISP_CFG_NL;
2517 strcpy(connect_type, "(Loop)");
2518 break;
2519
2520 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002521 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002522 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 ha->current_topology = ISP_CFG_FL;
2524 strcpy(connect_type, "(FL_Port)");
2525 break;
2526
2527 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002528 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 ha->operating_mode = P2P;
2530 ha->current_topology = ISP_CFG_N;
2531 strcpy(connect_type, "(N_Port-to-N_Port)");
2532 break;
2533
2534 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002535 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002536 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 ha->operating_mode = P2P;
2538 ha->current_topology = ISP_CFG_F;
2539 strcpy(connect_type, "(F_Port)");
2540 break;
2541
2542 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002543 ql_dbg(ql_dbg_disc, vha, 0x200f,
2544 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 ha->current_topology = ISP_CFG_NL;
2546 strcpy(connect_type, "(Loop)");
2547 break;
2548 }
2549
2550 /* Save Host port and loop ID. */
2551 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002552 vha->d_id.b.domain = domain;
2553 vha->d_id.b.area = area;
2554 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002556 spin_lock_irqsave(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002557 qlt_update_vp_map(vha, SET_AL_PA);
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002558 spin_unlock_irqrestore(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002559
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002560 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002561 ql_log(ql_log_info, vha, 0x2010,
2562 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002563 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 return(rval);
2566}
2567
Giridhar Malavalia9083012010-04-12 17:59:55 -07002568inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002569qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2570 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002571{
2572 char *st, *en;
2573 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002574 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002575 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002576 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002577
2578 if (memcmp(model, BINZERO, len) != 0) {
2579 strncpy(ha->model_number, model, len);
2580 st = en = ha->model_number;
2581 en += len - 1;
2582 while (en > st) {
2583 if (*en != 0x20 && *en != 0x00)
2584 break;
2585 *en-- = '\0';
2586 }
2587
2588 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002589 if (use_tbl &&
2590 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002591 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002592 strncpy(ha->model_desc,
2593 qla2x00_model_name[index * 2 + 1],
2594 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002595 } else {
2596 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002597 if (use_tbl &&
2598 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002599 index < QLA_MODEL_NAMES) {
2600 strcpy(ha->model_number,
2601 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002602 strncpy(ha->model_desc,
2603 qla2x00_model_name[index * 2 + 1],
2604 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002605 } else {
2606 strcpy(ha->model_number, def);
2607 }
2608 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002609 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002610 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002611 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002612}
2613
David Miller4e08df32007-04-16 12:37:43 -07002614/* On sparc systems, obtain port and node WWN from firmware
2615 * properties.
2616 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002617static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002618{
2619#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002620 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002621 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002622 struct device_node *dp = pci_device_to_OF_node(pdev);
2623 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002624 int len;
2625
2626 val = of_get_property(dp, "port-wwn", &len);
2627 if (val && len >= WWN_SIZE)
2628 memcpy(nv->port_name, val, WWN_SIZE);
2629
2630 val = of_get_property(dp, "node-wwn", &len);
2631 if (val && len >= WWN_SIZE)
2632 memcpy(nv->node_name, val, WWN_SIZE);
2633#endif
2634}
2635
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636/*
2637* NVRAM configuration for ISP 2xxx
2638*
2639* Input:
2640* ha = adapter block pointer.
2641*
2642* Output:
2643* initialization control block in response_ring
2644* host adapters parameters in host adapter block
2645*
2646* Returns:
2647* 0 = success.
2648*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002649int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002650qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651{
David Miller4e08df32007-04-16 12:37:43 -07002652 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002653 uint8_t chksum = 0;
2654 uint16_t cnt;
2655 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002656 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002657 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002658 nvram_t *nv = ha->nvram;
2659 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002660 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661
David Miller4e08df32007-04-16 12:37:43 -07002662 rval = QLA_SUCCESS;
2663
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002665 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 ha->nvram_base = 0;
2667 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2668 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2669 ha->nvram_base = 0x80;
2670
2671 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002672 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002673 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2674 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002676 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2677 "Contents of NVRAM.\n");
2678 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2679 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680
2681 /* Bad NVRAM data, set defaults parameters. */
2682 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2683 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2684 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002685 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04002686 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002687 "detected: checksum=0x%x id=%c version=0x%x.\n",
2688 chksum, nv->id[0], nv->nvram_version);
2689 ql_log(ql_log_warn, vha, 0x0065,
2690 "Falling back to "
2691 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07002692
2693 /*
2694 * Set default initialization control block.
2695 */
2696 memset(nv, 0, ha->nvram_size);
2697 nv->parameter_block_version = ICB_VERSION;
2698
2699 if (IS_QLA23XX(ha)) {
2700 nv->firmware_options[0] = BIT_2 | BIT_1;
2701 nv->firmware_options[1] = BIT_7 | BIT_5;
2702 nv->add_firmware_options[0] = BIT_5;
2703 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04002704 nv->frame_payload_size = 2048;
David Miller4e08df32007-04-16 12:37:43 -07002705 nv->special_options[1] = BIT_7;
2706 } else if (IS_QLA2200(ha)) {
2707 nv->firmware_options[0] = BIT_2 | BIT_1;
2708 nv->firmware_options[1] = BIT_7 | BIT_5;
2709 nv->add_firmware_options[0] = BIT_5;
2710 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04002711 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07002712 } else if (IS_QLA2100(ha)) {
2713 nv->firmware_options[0] = BIT_3 | BIT_1;
2714 nv->firmware_options[1] = BIT_5;
Joe Carnuccio98aee702014-09-25 05:16:38 -04002715 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07002716 }
2717
Bart Van Asschead950362015-07-09 07:24:08 -07002718 nv->max_iocb_allocation = cpu_to_le16(256);
2719 nv->execution_throttle = cpu_to_le16(16);
David Miller4e08df32007-04-16 12:37:43 -07002720 nv->retry_count = 8;
2721 nv->retry_delay = 1;
2722
2723 nv->port_name[0] = 33;
2724 nv->port_name[3] = 224;
2725 nv->port_name[4] = 139;
2726
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002727 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002728
2729 nv->login_timeout = 4;
2730
2731 /*
2732 * Set default host adapter parameters
2733 */
2734 nv->host_p[1] = BIT_2;
2735 nv->reset_delay = 5;
2736 nv->port_down_retry_count = 8;
Bart Van Asschead950362015-07-09 07:24:08 -07002737 nv->max_luns_per_target = cpu_to_le16(8);
David Miller4e08df32007-04-16 12:37:43 -07002738 nv->link_down_timeout = 60;
2739
2740 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 }
2742
2743#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2744 /*
2745 * The SN2 does not provide BIOS emulation which means you can't change
2746 * potentially bogus BIOS settings. Force the use of default settings
2747 * for link rate and frame size. Hope that the rest of the settings
2748 * are valid.
2749 */
2750 if (ia64_platform_is("sn2")) {
Joe Carnuccio98aee702014-09-25 05:16:38 -04002751 nv->frame_payload_size = 2048;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 if (IS_QLA23XX(ha))
2753 nv->special_options[1] = BIT_7;
2754 }
2755#endif
2756
2757 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002758 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759
2760 /*
2761 * Setup driver NVRAM options.
2762 */
2763 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2764 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2765 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2766 nv->firmware_options[1] &= ~BIT_4;
2767
2768 if (IS_QLA23XX(ha)) {
2769 nv->firmware_options[0] |= BIT_2;
2770 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002771 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002772 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773
2774 if (IS_QLA2300(ha)) {
2775 if (ha->fb_rev == FPM_2310) {
2776 strcpy(ha->model_number, "QLA2310");
2777 } else {
2778 strcpy(ha->model_number, "QLA2300");
2779 }
2780 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002781 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002782 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 }
2784 } else if (IS_QLA2200(ha)) {
2785 nv->firmware_options[0] |= BIT_2;
2786 /*
2787 * 'Point-to-point preferred, else loop' is not a safe
2788 * connection mode setting.
2789 */
2790 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2791 (BIT_5 | BIT_4)) {
2792 /* Force 'loop preferred, else point-to-point'. */
2793 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2794 nv->add_firmware_options[0] |= BIT_5;
2795 }
2796 strcpy(ha->model_number, "QLA22xx");
2797 } else /*if (IS_QLA2100(ha))*/ {
2798 strcpy(ha->model_number, "QLA2100");
2799 }
2800
2801 /*
2802 * Copy over NVRAM RISC parameter block to initialization control block.
2803 */
2804 dptr1 = (uint8_t *)icb;
2805 dptr2 = (uint8_t *)&nv->parameter_block_version;
2806 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2807 while (cnt--)
2808 *dptr1++ = *dptr2++;
2809
2810 /* Copy 2nd half. */
2811 dptr1 = (uint8_t *)icb->add_firmware_options;
2812 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2813 while (cnt--)
2814 *dptr1++ = *dptr2++;
2815
Andrew Vasquez5341e862006-05-17 15:09:16 -07002816 /* Use alternate WWN? */
2817 if (nv->host_p[1] & BIT_7) {
2818 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2819 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2820 }
2821
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 /* Prepare nodename */
2823 if ((icb->firmware_options[1] & BIT_6) == 0) {
2824 /*
2825 * Firmware will apply the following mask if the nodename was
2826 * not provided.
2827 */
2828 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2829 icb->node_name[0] &= 0xF0;
2830 }
2831
2832 /*
2833 * Set host adapter parameters.
2834 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002835
2836 /*
2837 * BIT_7 in the host-parameters section allows for modification to
2838 * internal driver logging.
2839 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002840 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08002841 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2843 /* Always load RISC code on non ISP2[12]00 chips. */
2844 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2845 ha->flags.disable_risc_code_load = 0;
2846 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2847 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2848 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002849 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002850 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851
2852 ha->operating_mode =
2853 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2854
2855 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2856 sizeof(ha->fw_seriallink_options));
2857
2858 /* save HBA serial number */
2859 ha->serial0 = icb->port_name[5];
2860 ha->serial1 = icb->port_name[6];
2861 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002862 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2863 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864
Bart Van Asschead950362015-07-09 07:24:08 -07002865 icb->execution_throttle = cpu_to_le16(0xFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866
2867 ha->retry_count = nv->retry_count;
2868
2869 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002870 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 nv->login_timeout = ql2xlogintimeout;
2872 if (nv->login_timeout < 4)
2873 nv->login_timeout = 4;
2874 ha->login_timeout = nv->login_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002876 /* Set minimum RATOV to 100 tenths of a second. */
2877 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 ha->loop_reset_delay = nv->reset_delay;
2880
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 /* Link Down Timeout = 0:
2882 *
2883 * When Port Down timer expires we will start returning
2884 * I/O's to OS with "DID_NO_CONNECT".
2885 *
2886 * Link Down Timeout != 0:
2887 *
2888 * The driver waits for the link to come up after link down
2889 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002890 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 if (nv->link_down_timeout == 0) {
2892 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002893 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 } else {
2895 ha->link_down_timeout = nv->link_down_timeout;
2896 ha->loop_down_abort_time =
2897 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002898 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 /*
2901 * Need enough time to try and get the port back.
2902 */
2903 ha->port_down_retry_count = nv->port_down_retry_count;
2904 if (qlport_down_retry)
2905 ha->port_down_retry_count = qlport_down_retry;
2906 /* Set login_retry_count */
2907 ha->login_retry_count = nv->retry_count;
2908 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2909 ha->port_down_retry_count > 3)
2910 ha->login_retry_count = ha->port_down_retry_count;
2911 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2912 ha->login_retry_count = ha->port_down_retry_count;
2913 if (ql2xloginretrycount)
2914 ha->login_retry_count = ql2xloginretrycount;
2915
Bart Van Asschead950362015-07-09 07:24:08 -07002916 icb->lun_enables = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 icb->command_resource_count = 0;
2918 icb->immediate_notify_resource_count = 0;
Bart Van Asschead950362015-07-09 07:24:08 -07002919 icb->timeout = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920
2921 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2922 /* Enable RIO */
2923 icb->firmware_options[0] &= ~BIT_3;
2924 icb->add_firmware_options[0] &=
2925 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2926 icb->add_firmware_options[0] |= BIT_2;
2927 icb->response_accumulation_timer = 3;
2928 icb->interrupt_delay_timer = 5;
2929
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002930 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002932 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002933 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002934 ha->zio_mode = icb->add_firmware_options[0] &
2935 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2936 ha->zio_timer = icb->interrupt_delay_timer ?
2937 icb->interrupt_delay_timer: 2;
2938 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 icb->add_firmware_options[0] &=
2940 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002941 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002942 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002943 ha->zio_mode = QLA_ZIO_MODE_6;
2944
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002945 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002946 "ZIO mode %d enabled; timer delay (%d us).\n",
2947 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002949 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2950 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002951 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 }
2953 }
2954
David Miller4e08df32007-04-16 12:37:43 -07002955 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002956 ql_log(ql_log_warn, vha, 0x0069,
2957 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07002958 }
2959 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960}
2961
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002962static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002963qla2x00_rport_del(void *data)
2964{
2965 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002966 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002967 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002968
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002969 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002970 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002971 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002972 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Alexei Potashnikdf673272015-07-14 16:00:46 -04002973 if (rport)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002974 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002975}
2976
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977/**
2978 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2979 * @ha: HA context
2980 * @flags: allocation flags
2981 *
2982 * Returns a pointer to the allocated fcport, or NULL, if none available.
2983 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002984fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002985qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986{
2987 fc_port_t *fcport;
2988
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002989 fcport = kzalloc(sizeof(fc_port_t), flags);
2990 if (!fcport)
2991 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992
2993 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002994 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 fcport->port_type = FCT_UNKNOWN;
2996 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07002997 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002998 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003000 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001}
3002
3003/*
3004 * qla2x00_configure_loop
3005 * Updates Fibre Channel Device Database with what is actually on loop.
3006 *
3007 * Input:
3008 * ha = adapter block pointer.
3009 *
3010 * Returns:
3011 * 0 = success.
3012 * 1 = error.
3013 * 2 = database was full and device was not configured.
3014 */
3015static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003016qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017{
3018 int rval;
3019 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003020 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 rval = QLA_SUCCESS;
3022
3023 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003024 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
3025 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003027 ql_dbg(ql_dbg_disc, vha, 0x2013,
3028 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 return (rval);
3030 }
3031 }
3032
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003033 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003034 ql_dbg(ql_dbg_disc, vha, 0x2014,
3035 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036
3037 /*
3038 * If we have both an RSCN and PORT UPDATE pending then handle them
3039 * both at the same time.
3040 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003041 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3042 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043
Michael Hernandez3064ff32009-12-15 21:29:44 -08003044 qla2x00_get_data_rate(vha);
3045
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 /* Determine what we need to do */
3047 if (ha->current_topology == ISP_CFG_FL &&
3048 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
3049
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 set_bit(RSCN_UPDATE, &flags);
3051
3052 } else if (ha->current_topology == ISP_CFG_F &&
3053 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
3054
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 set_bit(RSCN_UPDATE, &flags);
3056 clear_bit(LOCAL_LOOP_UPDATE, &flags);
3057
Andrew Vasquez21333b42006-05-17 15:09:56 -07003058 } else if (ha->current_topology == ISP_CFG_N) {
3059 clear_bit(RSCN_UPDATE, &flags);
3060
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003061 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
3063
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 set_bit(RSCN_UPDATE, &flags);
3065 set_bit(LOCAL_LOOP_UPDATE, &flags);
3066 }
3067
3068 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003069 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
3070 ql_dbg(ql_dbg_disc, vha, 0x2015,
3071 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08003073 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003074 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 }
3076
3077 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003078 if (LOOP_TRANSITION(vha)) {
3079 ql_dbg(ql_dbg_disc, vha, 0x201e,
3080 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003082 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003083 else
3084 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 }
3086
3087 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003088 if (atomic_read(&vha->loop_down_timer) ||
3089 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 rval = QLA_FUNCTION_FAILED;
3091 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003092 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003093 ql_dbg(ql_dbg_disc, vha, 0x2069,
3094 "LOOP READY.\n");
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05003095
3096 /*
3097 * Process any ATIO queue entries that came in
3098 * while we weren't online.
3099 */
3100 if (qla_tgt_mode_enabled(vha)) {
3101 if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) {
3102 spin_lock_irqsave(&ha->tgt.atio_lock,
3103 flags);
3104 qlt_24xx_process_atio_queue(vha, 0);
3105 spin_unlock_irqrestore(
3106 &ha->tgt.atio_lock, flags);
3107 } else {
3108 spin_lock_irqsave(&ha->hardware_lock,
3109 flags);
3110 qlt_24xx_process_atio_queue(vha, 1);
3111 spin_unlock_irqrestore(
3112 &ha->hardware_lock, flags);
3113 }
3114 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115 }
3116 }
3117
3118 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003119 ql_dbg(ql_dbg_disc, vha, 0x206a,
3120 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003122 ql_dbg(ql_dbg_disc, vha, 0x206b,
3123 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 }
3125
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07003126 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003127 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003129 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07003130 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003131 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07003132 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 }
3134
3135 return (rval);
3136}
3137
3138
3139
3140/*
3141 * qla2x00_configure_local_loop
3142 * Updates Fibre Channel Device Database with local loop devices.
3143 *
3144 * Input:
3145 * ha = adapter block pointer.
3146 *
3147 * Returns:
3148 * 0 = success.
3149 */
3150static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003151qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152{
3153 int rval, rval2;
3154 int found_devs;
3155 int found;
3156 fc_port_t *fcport, *new_fcport;
3157
3158 uint16_t index;
3159 uint16_t entries;
3160 char *id_iter;
3161 uint16_t loop_id;
3162 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003163 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164
3165 found_devs = 0;
3166 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08003167 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08003170 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003171 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 &entries);
3173 if (rval != QLA_SUCCESS)
3174 goto cleanup_allocation;
3175
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003176 ql_dbg(ql_dbg_disc, vha, 0x2017,
3177 "Entries in ID list (%d).\n", entries);
3178 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
3179 (uint8_t *)ha->gid_list,
3180 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181
3182 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003183 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003185 ql_log(ql_log_warn, vha, 0x2018,
3186 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 rval = QLA_MEMORY_ALLOC_FAILED;
3188 goto cleanup_allocation;
3189 }
3190 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3191
3192 /*
3193 * Mark local devices that were present with FCF_DEVICE_LOST for now.
3194 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003195 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 if (atomic_read(&fcport->state) == FCS_ONLINE &&
3197 fcport->port_type != FCT_BROADCAST &&
3198 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3199
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003200 ql_dbg(ql_dbg_disc, vha, 0x2019,
3201 "Marking port lost loop_id=0x%04x.\n",
3202 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203
Chad Dupuisec426e12011-03-30 11:46:32 -07003204 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 }
3206 }
3207
3208 /* Add devices to port list. */
3209 id_iter = (char *)ha->gid_list;
3210 for (index = 0; index < entries; index++) {
3211 domain = ((struct gid_list_info *)id_iter)->domain;
3212 area = ((struct gid_list_info *)id_iter)->area;
3213 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003214 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 loop_id = (uint16_t)
3216 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003217 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 loop_id = le16_to_cpu(
3219 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003220 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221
3222 /* Bypass reserved domain fields. */
3223 if ((domain & 0xf0) == 0xf0)
3224 continue;
3225
3226 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003227 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003228 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 continue;
3230
3231 /* Bypass invalid local loop ID. */
3232 if (loop_id > LAST_LOCAL_LOOP_ID)
3233 continue;
3234
Arun Easi370d5502012-08-22 14:21:10 -04003235 memset(new_fcport, 0, sizeof(fc_port_t));
3236
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 /* Fill in member data. */
3238 new_fcport->d_id.b.domain = domain;
3239 new_fcport->d_id.b.area = area;
3240 new_fcport->d_id.b.al_pa = al_pa;
3241 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003242 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003244 ql_dbg(ql_dbg_disc, vha, 0x201a,
3245 "Failed to retrieve fcport information "
3246 "-- get_port_database=%x, loop_id=0x%04x.\n",
3247 rval2, new_fcport->loop_id);
3248 ql_dbg(ql_dbg_disc, vha, 0x201b,
3249 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003250 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 continue;
3252 }
3253
3254 /* Check for matching device in port list. */
3255 found = 0;
3256 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003257 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 if (memcmp(new_fcport->port_name, fcport->port_name,
3259 WWN_SIZE))
3260 continue;
3261
Shyam Sundarddb9b122009-03-24 09:08:10 -07003262 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 fcport->loop_id = new_fcport->loop_id;
3264 fcport->port_type = new_fcport->port_type;
3265 fcport->d_id.b24 = new_fcport->d_id.b24;
3266 memcpy(fcport->node_name, new_fcport->node_name,
3267 WWN_SIZE);
3268
3269 found++;
3270 break;
3271 }
3272
3273 if (!found) {
3274 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003275 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276
3277 /* Allocate a new replacement fcport. */
3278 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003279 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003281 ql_log(ql_log_warn, vha, 0x201c,
3282 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 rval = QLA_MEMORY_ALLOC_FAILED;
3284 goto cleanup_allocation;
3285 }
3286 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3287 }
3288
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003289 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003290 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003291
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003292 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293
3294 found_devs++;
3295 }
3296
3297cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003298 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299
3300 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003301 ql_dbg(ql_dbg_disc, vha, 0x201d,
3302 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 }
3304
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 return (rval);
3306}
3307
3308static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003309qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003310{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003311 int rval;
Quinn Tran93f2bd62014-09-25 05:16:53 -04003312 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003313 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003314
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07003315 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003316 return;
3317
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07003318 if (atomic_read(&fcport->state) != FCS_ONLINE)
3319 return;
3320
Andrew Vasquez39bd9622007-09-20 14:07:34 -07003321 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
Himanshu Madhanif0c54312018-06-03 22:09:53 -07003322 fcport->fp_speed > ha->link_data_rate ||
3323 !ha->flags.gpsc_supported)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003324 return;
3325
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003326 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003327 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003328 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003329 ql_dbg(ql_dbg_disc, vha, 0x2004,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04003330 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
3331 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003332 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003333 ql_dbg(ql_dbg_disc, vha, 0x2005,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04003334 "iIDMA adjusted to %s GB/s on %8phN.\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -05003335 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04003336 fcport->port_name);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003337 }
3338}
3339
Adrian Bunk23be3312006-11-24 02:46:01 +01003340static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003341qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05003342{
3343 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05003344 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003345 unsigned long flags;
8482e1182005-04-17 15:04:54 -05003346
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07003347 rport_ids.node_name = wwn_to_u64(fcport->node_name);
3348 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05003349 rport_ids.port_id = fcport->d_id.b.domain << 16 |
3350 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
3351 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003352 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07003353 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003354 ql_log(ql_log_warn, vha, 0x2006,
3355 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07003356 return;
3357 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003358 /*
3359 * Create target mode FC NEXUS in qla_target.c if target mode is
3360 * enabled..
3361 */
Saurav Kashyapba9f6f62015-06-10 11:05:17 -04003362
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003363 qlt_fc_port_added(vha, fcport);
3364
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003365 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003366 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003367 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003368
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003369 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003370
3371 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05003372 if (fcport->port_type == FCT_INITIATOR)
3373 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3374 if (fcport->port_type == FCT_TARGET)
3375 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003376 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05003377}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378
3379/*
Adrian Bunk23be3312006-11-24 02:46:01 +01003380 * qla2x00_update_fcport
3381 * Updates device on list.
3382 *
3383 * Input:
3384 * ha = adapter block pointer.
3385 * fcport = port structure pointer.
3386 *
3387 * Return:
3388 * 0 - Success
3389 * BIT_0 - error
3390 *
3391 * Context:
3392 * Kernel context.
3393 */
3394void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003395qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01003396{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003397 fcport->vha = vha;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003398
3399 if (IS_QLAFX00(vha->hw)) {
3400 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003401 goto reg_port;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003402 }
Adrian Bunk23be3312006-11-24 02:46:01 +01003403 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003404 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01003405
Joe Carnuccio1f93da52012-11-21 02:40:38 -05003406 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003407 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08003408 qla24xx_update_fcport_fcp_prio(vha, fcport);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04003409
3410reg_port:
3411 if (qla_ini_mode_enabled(vha))
3412 qla2x00_reg_remote_port(vha, fcport);
3413 else {
3414 /*
3415 * Create target mode FC NEXUS in qla_target.c
3416 */
3417 qlt_fc_port_added(vha, fcport);
3418 }
Adrian Bunk23be3312006-11-24 02:46:01 +01003419}
3420
3421/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 * qla2x00_configure_fabric
3423 * Setup SNS devices with loop ID's.
3424 *
3425 * Input:
3426 * ha = adapter block pointer.
3427 *
3428 * Returns:
3429 * 0 = success.
3430 * BIT_0 = error
3431 */
3432static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003433qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434{
Arun Easib3b02e62012-02-09 11:15:39 -08003435 int rval;
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003436 fc_port_t *fcport, *fcptemp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 uint16_t next_loopid;
3438 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003439 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003441 struct qla_hw_data *ha = vha->hw;
3442 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003443 int discovery_gen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444
3445 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003446 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003447 loop_id = NPH_F_PORT;
3448 else
3449 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003450 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003452 ql_dbg(ql_dbg_disc, vha, 0x201f,
3453 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003455 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456 return (QLA_SUCCESS);
3457 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003458 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07003461 /* FDMI support. */
3462 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003463 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
3464 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07003465
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003467 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003468 loop_id = NPH_SNS;
3469 else
3470 loop_id = SIMPLE_NAME_SERVER;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003471 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
3472 0xfc, mb, BIT_1|BIT_0);
3473 if (rval != QLA_SUCCESS) {
3474 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003475 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003478 ql_dbg(ql_dbg_disc, vha, 0x2042,
3479 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3480 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
3481 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 return (QLA_SUCCESS);
3483 }
3484
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003485 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3486 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003488 ql_dbg(ql_dbg_disc, vha, 0x2045,
3489 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003491 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003493 ql_dbg(ql_dbg_disc, vha, 0x2049,
3494 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003496 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003498 ql_dbg(ql_dbg_disc, vha, 0x204f,
3499 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003500 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003502 ql_dbg(ql_dbg_disc, vha, 0x2053,
3503 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 }
3505 }
3506
Joe Carnuccio827210b2013-02-08 01:57:57 -05003507#define QLA_FCPORT_SCAN 1
3508#define QLA_FCPORT_FOUND 2
3509
3510 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3511 fcport->scan_state = QLA_FCPORT_SCAN;
3512 }
3513
Alexei Potashnikdf673272015-07-14 16:00:46 -04003514 /* Mark the time right before querying FW for connected ports.
3515 * This process is long, asynchronous and by the time it's done,
3516 * collected information might not be accurate anymore. E.g.
3517 * disconnected port might have re-connected and a brand new
3518 * session has been created. In this case session's generation
3519 * will be newer than discovery_gen. */
3520 qlt_do_generation_tick(vha, &discovery_gen);
3521
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003522 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 if (rval != QLA_SUCCESS)
3524 break;
3525
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003526 /*
3527 * Logout all previous fabric devices marked lost, except
3528 * FCP2 devices.
3529 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003530 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3531 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 break;
3533
3534 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3535 continue;
3536
Roland Dreierb2032fd2015-07-14 16:00:42 -04003537 if (fcport->scan_state == QLA_FCPORT_SCAN) {
3538 if (qla_ini_mode_enabled(base_vha) &&
3539 atomic_read(&fcport->state) == FCS_ONLINE) {
3540 qla2x00_mark_device_lost(vha, fcport,
3541 ql2xplogiabsentdevice, 0);
3542 if (fcport->loop_id != FC_NO_LOOP_ID &&
3543 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
3544 fcport->port_type != FCT_INITIATOR &&
3545 fcport->port_type != FCT_BROADCAST) {
3546 ha->isp_ops->fabric_logout(vha,
3547 fcport->loop_id,
3548 fcport->d_id.b.domain,
3549 fcport->d_id.b.area,
3550 fcport->d_id.b.al_pa);
3551 qla2x00_clear_loop_id(fcport);
3552 }
3553 } else if (!qla_ini_mode_enabled(base_vha)) {
3554 /*
3555 * In target mode, explicitly kill
3556 * sessions and log out of devices
3557 * that are gone, so that we don't
3558 * end up with an initiator using the
3559 * wrong ACL (if the fabric recycles
3560 * an FC address and we have a stale
3561 * session around) and so that we don't
3562 * report initiators that are no longer
3563 * on the fabric.
3564 */
3565 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf077,
3566 "port gone, logging out/killing session: "
3567 "%8phC state 0x%x flags 0x%x fc4_type 0x%x "
3568 "scan_state %d\n",
3569 fcport->port_name,
3570 atomic_read(&fcport->state),
3571 fcport->flags, fcport->fc4_type,
3572 fcport->scan_state);
Alexei Potashnikdf673272015-07-14 16:00:46 -04003573 qlt_fc_port_deleted(vha, fcport,
3574 discovery_gen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 }
3576 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003577 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003579 /* Starting free loop ID. */
3580 next_loopid = ha->min_external_loopid;
3581
3582 /*
3583 * Scan through our port list and login entries that need to be
3584 * logged in.
3585 */
3586 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3587 if (atomic_read(&vha->loop_down_timer) ||
3588 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3589 break;
3590
3591 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3592 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3593 continue;
3594
Roland Dreierb2032fd2015-07-14 16:00:42 -04003595 /*
3596 * If we're not an initiator, skip looking for devices
3597 * and logging in. There's no reason for us to do it,
3598 * and it seems to actively cause problems in target
3599 * mode if we race with the initiator logging into us
3600 * (we might get the "port ID used" status back from
3601 * our login command and log out the initiator, which
3602 * seems to cause havoc).
3603 */
3604 if (!qla_ini_mode_enabled(base_vha)) {
3605 if (fcport->scan_state == QLA_FCPORT_FOUND) {
3606 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf078,
3607 "port %8phC state 0x%x flags 0x%x fc4_type 0x%x "
3608 "scan_state %d (initiator mode disabled; skipping "
3609 "login)\n", fcport->port_name,
3610 atomic_read(&fcport->state),
3611 fcport->flags, fcport->fc4_type,
3612 fcport->scan_state);
3613 }
3614 continue;
3615 }
3616
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003617 if (fcport->loop_id == FC_NO_LOOP_ID) {
3618 fcport->loop_id = next_loopid;
3619 rval = qla2x00_find_new_loop_id(
3620 base_vha, fcport);
3621 if (rval != QLA_SUCCESS) {
3622 /* Ran out of IDs to use */
3623 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 }
3625 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003626 /* Login and update database */
3627 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
3628 }
3629
3630 /* Exit if out of loop IDs. */
3631 if (rval != QLA_SUCCESS) {
3632 break;
3633 }
3634
3635 /*
3636 * Login and add the new devices to our port list.
3637 */
3638 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3639 if (atomic_read(&vha->loop_down_timer) ||
3640 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3641 break;
3642
Roland Dreierb2032fd2015-07-14 16:00:42 -04003643 /*
3644 * If we're not an initiator, skip looking for devices
3645 * and logging in. There's no reason for us to do it,
3646 * and it seems to actively cause problems in target
3647 * mode if we race with the initiator logging into us
3648 * (we might get the "port ID used" status back from
3649 * our login command and log out the initiator, which
3650 * seems to cause havoc).
3651 */
3652 if (qla_ini_mode_enabled(base_vha)) {
3653 /* Find a new loop ID to use. */
3654 fcport->loop_id = next_loopid;
3655 rval = qla2x00_find_new_loop_id(base_vha,
3656 fcport);
3657 if (rval != QLA_SUCCESS) {
3658 /* Ran out of IDs to use */
3659 break;
3660 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661
Roland Dreierb2032fd2015-07-14 16:00:42 -04003662 /* Login and update database */
3663 qla2x00_fabric_dev_login(vha, fcport,
3664 &next_loopid);
3665 } else {
3666 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf079,
3667 "new port %8phC state 0x%x flags 0x%x fc4_type "
3668 "0x%x scan_state %d (initiator mode disabled; "
3669 "skipping login)\n",
3670 fcport->port_name,
3671 atomic_read(&fcport->state),
3672 fcport->flags, fcport->fc4_type,
3673 fcport->scan_state);
3674 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003675
3676 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677 }
3678 } while (0);
3679
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003680 /* Free all new device structures not processed. */
3681 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3682 list_del(&fcport->list);
3683 kfree(fcport);
3684 }
3685
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003687 ql_dbg(ql_dbg_disc, vha, 0x2068,
3688 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689 }
3690
3691 return (rval);
3692}
3693
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694/*
3695 * qla2x00_find_all_fabric_devs
3696 *
3697 * Input:
3698 * ha = adapter block pointer.
3699 * dev = database device entry pointer.
3700 *
3701 * Returns:
3702 * 0 = success.
3703 *
3704 * Context:
3705 * Kernel context.
3706 */
3707static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003708qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3709 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003710{
3711 int rval;
3712 uint16_t loop_id;
3713 fc_port_t *fcport, *new_fcport, *fcptemp;
3714 int found;
3715
3716 sw_info_t *swl;
3717 int swl_idx;
3718 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003719 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003720 struct qla_hw_data *ha = vha->hw;
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05003721 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722
3723 rval = QLA_SUCCESS;
3724
3725 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08003726 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08003727 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08003728 GFP_KERNEL);
3729 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003730 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003732 ql_dbg(ql_dbg_disc, vha, 0x2054,
3733 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08003735 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003736 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003738 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003740 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003742 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003743 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3744 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003746
3747 /* If other queries succeeded probe for FC-4 type */
3748 if (swl)
3749 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750 }
3751 swl_idx = 0;
3752
3753 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003754 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003756 ql_log(ql_log_warn, vha, 0x205e,
3757 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758 return (QLA_MEMORY_ALLOC_FAILED);
3759 }
3760 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761 /* Set start port ID scan at adapter ID. */
3762 first_dev = 1;
3763 last_dev = 0;
3764
3765 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003766 loop_id = ha->min_external_loopid;
3767 for (; loop_id <= ha->max_loop_id; loop_id++) {
3768 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769 continue;
3770
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003771 if (ha->current_topology == ISP_CFG_FL &&
3772 (atomic_read(&vha->loop_down_timer) ||
3773 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003774 atomic_set(&vha->loop_down_timer, 0);
3775 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3776 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779
3780 if (swl != NULL) {
3781 if (last_dev) {
3782 wrap.b24 = new_fcport->d_id.b24;
3783 } else {
3784 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3785 memcpy(new_fcport->node_name,
3786 swl[swl_idx].node_name, WWN_SIZE);
3787 memcpy(new_fcport->port_name,
3788 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003789 memcpy(new_fcport->fabric_port_name,
3790 swl[swl_idx].fabric_port_name, WWN_SIZE);
3791 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003792 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793
3794 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3795 last_dev = 1;
3796 }
3797 swl_idx++;
3798 }
3799 } else {
3800 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003801 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003803 ql_log(ql_log_warn, vha, 0x2064,
3804 "SNS scan failed -- assuming "
3805 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 list_for_each_entry_safe(fcport, fcptemp,
3807 new_fcports, list) {
3808 list_del(&fcport->list);
3809 kfree(fcport);
3810 }
3811 rval = QLA_SUCCESS;
3812 break;
3813 }
3814 }
3815
3816 /* If wrap on switch device list, exit. */
3817 if (first_dev) {
3818 wrap.b24 = new_fcport->d_id.b24;
3819 first_dev = 0;
3820 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003821 ql_dbg(ql_dbg_disc, vha, 0x2065,
3822 "Device wrap (%02x%02x%02x).\n",
3823 new_fcport->d_id.b.domain,
3824 new_fcport->d_id.b.area,
3825 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 break;
3827 }
3828
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003829 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003830 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 continue;
3832
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003833 /* Bypass virtual ports of the same host. */
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05003834 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
3835 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003836
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003837 /* Bypass if same domain and area of adapter. */
3838 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003839 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003840 ISP_CFG_FL)
3841 continue;
3842
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 /* Bypass reserved domain fields. */
3844 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3845 continue;
3846
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003847 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003848 if (ql2xgffidenable &&
3849 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3850 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003851 continue;
3852
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853 /* Locate matching device in database. */
3854 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003855 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856 if (memcmp(new_fcport->port_name, fcport->port_name,
3857 WWN_SIZE))
3858 continue;
3859
Joe Carnuccio827210b2013-02-08 01:57:57 -05003860 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08003861
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 found++;
3863
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003864 /* Update port state. */
3865 memcpy(fcport->fabric_port_name,
3866 new_fcport->fabric_port_name, WWN_SIZE);
3867 fcport->fp_speed = new_fcport->fp_speed;
3868
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 /*
Roland Dreierb2032fd2015-07-14 16:00:42 -04003870 * If address the same and state FCS_ONLINE
3871 * (or in target mode), nothing changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 */
3873 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
Roland Dreierb2032fd2015-07-14 16:00:42 -04003874 (atomic_read(&fcport->state) == FCS_ONLINE ||
3875 !qla_ini_mode_enabled(base_vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 break;
3877 }
3878
3879 /*
3880 * If device was not a fabric device before.
3881 */
3882 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3883 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04003884 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 fcport->flags |= (FCF_FABRIC_DEVICE |
3886 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 break;
3888 }
3889
3890 /*
3891 * Port ID changed or device was marked to be updated;
3892 * Log it out if still logged in and mark it for
3893 * relogin later.
3894 */
Roland Dreierb2032fd2015-07-14 16:00:42 -04003895 if (!qla_ini_mode_enabled(base_vha)) {
3896 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
3897 "port changed FC ID, %8phC"
3898 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
3899 fcport->port_name,
3900 fcport->d_id.b.domain,
3901 fcport->d_id.b.area,
3902 fcport->d_id.b.al_pa,
3903 fcport->loop_id,
3904 new_fcport->d_id.b.domain,
3905 new_fcport->d_id.b.area,
3906 new_fcport->d_id.b.al_pa);
3907 fcport->d_id.b24 = new_fcport->d_id.b24;
3908 break;
3909 }
3910
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 fcport->d_id.b24 = new_fcport->d_id.b24;
3912 fcport->flags |= FCF_LOGIN_NEEDED;
3913 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003914 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Arun Easi0eba25d2012-02-09 11:15:58 -08003915 (fcport->flags & FCF_ASYNC_SENT) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916 fcport->port_type != FCT_INITIATOR &&
3917 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003918 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003919 fcport->d_id.b.domain, fcport->d_id.b.area,
3920 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003921 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 }
3923
3924 break;
3925 }
3926
3927 if (found)
3928 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 /* If device was not in our fcports list, then add it. */
Roland Dreierb2032fd2015-07-14 16:00:42 -04003930 new_fcport->scan_state = QLA_FCPORT_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931 list_add_tail(&new_fcport->list, new_fcports);
3932
3933 /* Allocate a new replacement fcport. */
3934 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003935 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003937 ql_log(ql_log_warn, vha, 0x2066,
3938 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 return (QLA_MEMORY_ALLOC_FAILED);
3940 }
3941 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3942 new_fcport->d_id.b24 = nxt_d_id.b24;
3943 }
3944
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003945 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946
Linus Torvalds1da177e2005-04-16 15:20:36 -07003947 return (rval);
3948}
3949
3950/*
3951 * qla2x00_find_new_loop_id
3952 * Scan through our port list and find a new usable loop ID.
3953 *
3954 * Input:
3955 * ha: adapter state pointer.
3956 * dev: port structure pointer.
3957 *
3958 * Returns:
3959 * qla2x00 local function return status code.
3960 *
3961 * Context:
3962 * Kernel context.
3963 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003964int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003965qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966{
3967 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003968 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07003969 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970
3971 rval = QLA_SUCCESS;
3972
Chad Dupuis5f16b332012-08-22 14:21:00 -04003973 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974
Chad Dupuis5f16b332012-08-22 14:21:00 -04003975 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
3976 LOOPID_MAP_SIZE);
3977 if (dev->loop_id >= LOOPID_MAP_SIZE ||
3978 qla2x00_is_reserved_id(vha, dev->loop_id)) {
3979 dev->loop_id = FC_NO_LOOP_ID;
3980 rval = QLA_FUNCTION_FAILED;
3981 } else
3982 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983
Chad Dupuis5f16b332012-08-22 14:21:00 -04003984 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985
Chad Dupuis5f16b332012-08-22 14:21:00 -04003986 if (rval == QLA_SUCCESS)
3987 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
3988 "Assigning new loopid=%x, portid=%x.\n",
3989 dev->loop_id, dev->d_id.b24);
3990 else
3991 ql_log(ql_log_warn, dev->vha, 0x2087,
3992 "No loop_id's available, portid=%x.\n",
3993 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994
3995 return (rval);
3996}
3997
3998/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 * qla2x00_fabric_dev_login
4000 * Login fabric target device and update FC port database.
4001 *
4002 * Input:
4003 * ha: adapter state pointer.
4004 * fcport: port structure list pointer.
4005 * next_loopid: contains value of a new loop ID that can be used
4006 * by the next login attempt.
4007 *
4008 * Returns:
4009 * qla2x00 local function return status code.
4010 *
4011 * Context:
4012 * Kernel context.
4013 */
4014static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004015qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 uint16_t *next_loopid)
4017{
4018 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004019 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004020 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021
4022 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004023
Andrew Vasquezac280b62009-08-20 11:06:05 -07004024 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004025 if (fcport->flags & FCF_ASYNC_SENT)
4026 return rval;
4027 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07004028 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
4029 if (!rval)
4030 return rval;
4031 }
4032
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004033 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004034 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004035 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08004036 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004037 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08004038 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004039 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004040 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004042 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07004043 fcport->d_id.b.domain, fcport->d_id.b.area,
4044 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004045 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004047 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048 }
Chad Dupuis0b91d112012-02-09 11:15:42 -08004049 } else {
4050 /* Retry Login. */
4051 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 }
4053
4054 return (rval);
4055}
4056
4057/*
4058 * qla2x00_fabric_login
4059 * Issue fabric login command.
4060 *
4061 * Input:
4062 * ha = adapter block pointer.
4063 * device = pointer to FC device type structure.
4064 *
4065 * Returns:
4066 * 0 - Login successfully
4067 * 1 - Login failed
4068 * 2 - Initiator device
4069 * 3 - Fatal error
4070 */
4071int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004072qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 uint16_t *next_loopid)
4074{
4075 int rval;
4076 int retry;
4077 uint16_t tmp_loopid;
4078 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004079 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080
4081 retry = 0;
4082 tmp_loopid = 0;
4083
4084 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004085 ql_dbg(ql_dbg_disc, vha, 0x2000,
4086 "Trying Fabric Login w/loop id 0x%04x for port "
4087 "%02x%02x%02x.\n",
4088 fcport->loop_id, fcport->d_id.b.domain,
4089 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090
4091 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08004092 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093 fcport->d_id.b.domain, fcport->d_id.b.area,
4094 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08004095 if (rval != QLA_SUCCESS) {
4096 return rval;
4097 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 if (mb[0] == MBS_PORT_ID_USED) {
4099 /*
4100 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004101 * recommends the driver perform an implicit login with
4102 * the specified ID again. The ID we just used is save
4103 * here so we return with an ID that can be tried by
4104 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105 */
4106 retry++;
4107 tmp_loopid = fcport->loop_id;
4108 fcport->loop_id = mb[1];
4109
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004110 ql_dbg(ql_dbg_disc, vha, 0x2001,
4111 "Fabric Login: port in use - next loop "
4112 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004114 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115
4116 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
4117 /*
4118 * Login succeeded.
4119 */
4120 if (retry) {
4121 /* A retry occurred before. */
4122 *next_loopid = tmp_loopid;
4123 } else {
4124 /*
4125 * No retry occurred before. Just increment the
4126 * ID value for next login.
4127 */
4128 *next_loopid = (fcport->loop_id + 1);
4129 }
4130
4131 if (mb[1] & BIT_0) {
4132 fcport->port_type = FCT_INITIATOR;
4133 } else {
4134 fcport->port_type = FCT_TARGET;
4135 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07004136 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 }
4138 }
4139
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004140 if (mb[10] & BIT_0)
4141 fcport->supported_classes |= FC_COS_CLASS2;
4142 if (mb[10] & BIT_1)
4143 fcport->supported_classes |= FC_COS_CLASS3;
4144
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004145 if (IS_FWI2_CAPABLE(ha)) {
4146 if (mb[10] & BIT_7)
4147 fcport->flags |=
4148 FCF_CONF_COMP_SUPPORTED;
4149 }
4150
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 rval = QLA_SUCCESS;
4152 break;
4153 } else if (mb[0] == MBS_LOOP_ID_USED) {
4154 /*
4155 * Loop ID already used, try next loop ID.
4156 */
4157 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004158 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 if (rval != QLA_SUCCESS) {
4160 /* Ran out of loop IDs to use */
4161 break;
4162 }
4163 } else if (mb[0] == MBS_COMMAND_ERROR) {
4164 /*
4165 * Firmware possibly timed out during login. If NO
4166 * retries are left to do then the device is declared
4167 * dead.
4168 */
4169 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004170 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07004171 fcport->d_id.b.domain, fcport->d_id.b.area,
4172 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004173 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174
4175 rval = 1;
4176 break;
4177 } else {
4178 /*
4179 * unrecoverable / not handled error
4180 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004181 ql_dbg(ql_dbg_disc, vha, 0x2002,
4182 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
4183 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
4184 fcport->d_id.b.area, fcport->d_id.b.al_pa,
4185 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186
4187 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004188 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07004189 fcport->d_id.b.domain, fcport->d_id.b.area,
4190 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004191 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07004192 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193
4194 rval = 3;
4195 break;
4196 }
4197 }
4198
4199 return (rval);
4200}
4201
4202/*
4203 * qla2x00_local_device_login
4204 * Issue local device login command.
4205 *
4206 * Input:
4207 * ha = adapter block pointer.
4208 * loop_id = loop id of device to login to.
4209 *
4210 * Returns (Where's the #define!!!!):
4211 * 0 - Login successfully
4212 * 1 - Login failed
4213 * 3 - Fatal error
4214 */
4215int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004216qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217{
4218 int rval;
4219 uint16_t mb[MAILBOX_REGISTER_COUNT];
4220
4221 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004222 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004223 if (rval == QLA_SUCCESS) {
4224 /* Interrogate mailbox registers for any errors */
4225 if (mb[0] == MBS_COMMAND_ERROR)
4226 rval = 1;
4227 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
4228 /* device not in PCB table */
4229 rval = 3;
4230 }
4231
4232 return (rval);
4233}
4234
4235/*
4236 * qla2x00_loop_resync
4237 * Resync with fibre channel devices.
4238 *
4239 * Input:
4240 * ha = adapter block pointer.
4241 *
4242 * Returns:
4243 * 0 = success
4244 */
4245int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004246qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004248 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004250 struct req_que *req;
4251 struct rsp_que *rsp;
4252
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004253 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004254 req = vha->hw->req_q_map[0];
4255 else
4256 req = vha->req;
4257 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004259 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4260 if (vha->flags.online) {
4261 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4263 wait_time = 256;
4264 do {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004265 if (!IS_QLAFX00(vha->hw)) {
4266 /*
4267 * Issue a marker after FW becomes
4268 * ready.
4269 */
4270 qla2x00_marker(vha, req, rsp, 0, 0,
4271 MK_SYNC_ALL);
4272 vha->marker_needed = 0;
4273 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274
4275 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004276 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004278 if (IS_QLAFX00(vha->hw))
4279 qlafx00_configure_devices(vha);
4280 else
4281 qla2x00_configure_loop(vha);
4282
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004284 } while (!atomic_read(&vha->loop_down_timer) &&
4285 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4286 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4287 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289 }
4290
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004291 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004294 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004295 ql_dbg(ql_dbg_disc, vha, 0x206c,
4296 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297
4298 return (rval);
4299}
4300
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004301/*
4302* qla2x00_perform_loop_resync
4303* Description: This function will set the appropriate flags and call
4304* qla2x00_loop_resync. If successful loop will be resynced
4305* Arguments : scsi_qla_host_t pointer
4306* returm : Success or Failure
4307*/
4308
4309int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
4310{
4311 int32_t rval = 0;
4312
4313 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
4314 /*Configure the flags so that resync happens properly*/
4315 atomic_set(&ha->loop_down_timer, 0);
4316 if (!(ha->device_flags & DFLG_NO_CABLE)) {
4317 atomic_set(&ha->loop_state, LOOP_UP);
4318 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4319 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
4320 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4321
4322 rval = qla2x00_loop_resync(ha);
4323 } else
4324 atomic_set(&ha->loop_state, LOOP_DEAD);
4325
4326 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
4327 }
4328
4329 return rval;
4330}
4331
Linus Torvalds1da177e2005-04-16 15:20:36 -07004332void
Andrew Vasquez67becc02009-08-25 11:36:20 -07004333qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004334{
4335 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07004336 struct scsi_qla_host *vha;
4337 struct qla_hw_data *ha = base_vha->hw;
4338 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004339
Arun Easifeafb7b2010-09-03 14:57:00 -07004340 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004341 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07004342 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
4343 atomic_inc(&vha->vref_count);
4344 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08004345 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07004346 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
4347 spin_unlock_irqrestore(&ha->vport_slock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07004348 qla2x00_rport_del(fcport);
Alexei Potashnikdf673272015-07-14 16:00:46 -04004349
4350 /*
4351 * Release the target mode FC NEXUS in
4352 * qla_target.c, if target mod is enabled.
4353 */
4354 qlt_fc_port_deleted(vha, fcport,
4355 base_vha->total_fcport_update_gen);
4356
Arun Easifeafb7b2010-09-03 14:57:00 -07004357 spin_lock_irqsave(&ha->vport_slock, flags);
4358 }
4359 }
4360 atomic_dec(&vha->vref_count);
Joe Carnuccioc1716f02017-03-15 09:48:43 -07004361 wake_up(&vha->vref_waitq);
Arun Easifeafb7b2010-09-03 14:57:00 -07004362 }
4363 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004364}
4365
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004366/* Assumes idc_lock always held on entry */
4367void
4368qla83xx_reset_ownership(scsi_qla_host_t *vha)
4369{
4370 struct qla_hw_data *ha = vha->hw;
4371 uint32_t drv_presence, drv_presence_mask;
4372 uint32_t dev_part_info1, dev_part_info2, class_type;
4373 uint32_t class_type_mask = 0x3;
4374 uint16_t fcoe_other_function = 0xffff, i;
4375
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004376 if (IS_QLA8044(ha)) {
4377 drv_presence = qla8044_rd_direct(vha,
4378 QLA8044_CRB_DRV_ACTIVE_INDEX);
4379 dev_part_info1 = qla8044_rd_direct(vha,
4380 QLA8044_CRB_DEV_PART_INFO_INDEX);
4381 dev_part_info2 = qla8044_rd_direct(vha,
4382 QLA8044_CRB_DEV_PART_INFO2);
4383 } else {
4384 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4385 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
4386 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
4387 }
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004388 for (i = 0; i < 8; i++) {
4389 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
4390 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4391 (i != ha->portnum)) {
4392 fcoe_other_function = i;
4393 break;
4394 }
4395 }
4396 if (fcoe_other_function == 0xffff) {
4397 for (i = 0; i < 8; i++) {
4398 class_type = ((dev_part_info2 >> (i * 4)) &
4399 class_type_mask);
4400 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4401 ((i + 8) != ha->portnum)) {
4402 fcoe_other_function = i + 8;
4403 break;
4404 }
4405 }
4406 }
4407 /*
4408 * Prepare drv-presence mask based on fcoe functions present.
4409 * However consider only valid physical fcoe function numbers (0-15).
4410 */
4411 drv_presence_mask = ~((1 << (ha->portnum)) |
4412 ((fcoe_other_function == 0xffff) ?
4413 0 : (1 << (fcoe_other_function))));
4414
4415 /* We are the reset owner iff:
4416 * - No other protocol drivers present.
4417 * - This is the lowest among fcoe functions. */
4418 if (!(drv_presence & drv_presence_mask) &&
4419 (ha->portnum < fcoe_other_function)) {
4420 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
4421 "This host is Reset owner.\n");
4422 ha->flags.nic_core_reset_owner = 1;
4423 }
4424}
4425
Saurav Kashyapfa492632012-11-21 02:40:29 -05004426static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004427__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
4428{
4429 int rval = QLA_SUCCESS;
4430 struct qla_hw_data *ha = vha->hw;
4431 uint32_t drv_ack;
4432
4433 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4434 if (rval == QLA_SUCCESS) {
4435 drv_ack |= (1 << ha->portnum);
4436 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4437 }
4438
4439 return rval;
4440}
4441
Saurav Kashyapfa492632012-11-21 02:40:29 -05004442static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004443__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
4444{
4445 int rval = QLA_SUCCESS;
4446 struct qla_hw_data *ha = vha->hw;
4447 uint32_t drv_ack;
4448
4449 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4450 if (rval == QLA_SUCCESS) {
4451 drv_ack &= ~(1 << ha->portnum);
4452 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4453 }
4454
4455 return rval;
4456}
4457
Saurav Kashyapfa492632012-11-21 02:40:29 -05004458static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004459qla83xx_dev_state_to_string(uint32_t dev_state)
4460{
4461 switch (dev_state) {
4462 case QLA8XXX_DEV_COLD:
4463 return "COLD/RE-INIT";
4464 case QLA8XXX_DEV_INITIALIZING:
4465 return "INITIALIZING";
4466 case QLA8XXX_DEV_READY:
4467 return "READY";
4468 case QLA8XXX_DEV_NEED_RESET:
4469 return "NEED RESET";
4470 case QLA8XXX_DEV_NEED_QUIESCENT:
4471 return "NEED QUIESCENT";
4472 case QLA8XXX_DEV_FAILED:
4473 return "FAILED";
4474 case QLA8XXX_DEV_QUIESCENT:
4475 return "QUIESCENT";
4476 default:
4477 return "Unknown";
4478 }
4479}
4480
4481/* Assumes idc-lock always held on entry */
4482void
4483qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
4484{
4485 struct qla_hw_data *ha = vha->hw;
4486 uint32_t idc_audit_reg = 0, duration_secs = 0;
4487
4488 switch (audit_type) {
4489 case IDC_AUDIT_TIMESTAMP:
4490 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
4491 idc_audit_reg = (ha->portnum) |
4492 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
4493 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4494 break;
4495
4496 case IDC_AUDIT_COMPLETION:
4497 duration_secs = ((jiffies_to_msecs(jiffies) -
4498 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
4499 idc_audit_reg = (ha->portnum) |
4500 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
4501 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4502 break;
4503
4504 default:
4505 ql_log(ql_log_warn, vha, 0xb078,
4506 "Invalid audit type specified.\n");
4507 break;
4508 }
4509}
4510
4511/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05004512static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004513qla83xx_initiating_reset(scsi_qla_host_t *vha)
4514{
4515 struct qla_hw_data *ha = vha->hw;
4516 uint32_t idc_control, dev_state;
4517
4518 __qla83xx_get_idc_control(vha, &idc_control);
4519 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
4520 ql_log(ql_log_info, vha, 0xb080,
4521 "NIC Core reset has been disabled. idc-control=0x%x\n",
4522 idc_control);
4523 return QLA_FUNCTION_FAILED;
4524 }
4525
4526 /* Set NEED-RESET iff in READY state and we are the reset-owner */
4527 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4528 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
4529 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
4530 QLA8XXX_DEV_NEED_RESET);
4531 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
4532 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
4533 } else {
4534 const char *state = qla83xx_dev_state_to_string(dev_state);
4535 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
4536
4537 /* SV: XXX: Is timeout required here? */
4538 /* Wait for IDC state change READY -> NEED_RESET */
4539 while (dev_state == QLA8XXX_DEV_READY) {
4540 qla83xx_idc_unlock(vha, 0);
4541 msleep(200);
4542 qla83xx_idc_lock(vha, 0);
4543 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4544 }
4545 }
4546
4547 /* Send IDC ack by writing to drv-ack register */
4548 __qla83xx_set_drv_ack(vha);
4549
4550 return QLA_SUCCESS;
4551}
4552
4553int
4554__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
4555{
4556 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4557}
4558
4559int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004560__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
4561{
4562 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4563}
4564
Saurav Kashyapfa492632012-11-21 02:40:29 -05004565static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004566qla83xx_check_driver_presence(scsi_qla_host_t *vha)
4567{
4568 uint32_t drv_presence = 0;
4569 struct qla_hw_data *ha = vha->hw;
4570
4571 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4572 if (drv_presence & (1 << ha->portnum))
4573 return QLA_SUCCESS;
4574 else
4575 return QLA_TEST_FAILED;
4576}
4577
4578int
4579qla83xx_nic_core_reset(scsi_qla_host_t *vha)
4580{
4581 int rval = QLA_SUCCESS;
4582 struct qla_hw_data *ha = vha->hw;
4583
4584 ql_dbg(ql_dbg_p3p, vha, 0xb058,
4585 "Entered %s().\n", __func__);
4586
4587 if (vha->device_flags & DFLG_DEV_FAILED) {
4588 ql_log(ql_log_warn, vha, 0xb059,
4589 "Device in unrecoverable FAILED state.\n");
4590 return QLA_FUNCTION_FAILED;
4591 }
4592
4593 qla83xx_idc_lock(vha, 0);
4594
4595 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
4596 ql_log(ql_log_warn, vha, 0xb05a,
4597 "Function=0x%x has been removed from IDC participation.\n",
4598 ha->portnum);
4599 rval = QLA_FUNCTION_FAILED;
4600 goto exit;
4601 }
4602
4603 qla83xx_reset_ownership(vha);
4604
4605 rval = qla83xx_initiating_reset(vha);
4606
4607 /*
4608 * Perform reset if we are the reset-owner,
4609 * else wait till IDC state changes to READY/FAILED.
4610 */
4611 if (rval == QLA_SUCCESS) {
4612 rval = qla83xx_idc_state_handler(vha);
4613
4614 if (rval == QLA_SUCCESS)
4615 ha->flags.nic_core_hung = 0;
4616 __qla83xx_clear_drv_ack(vha);
4617 }
4618
4619exit:
4620 qla83xx_idc_unlock(vha, 0);
4621
4622 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
4623
4624 return rval;
4625}
4626
Saurav Kashyap81178772012-08-22 14:21:04 -04004627int
4628qla2xxx_mctp_dump(scsi_qla_host_t *vha)
4629{
4630 struct qla_hw_data *ha = vha->hw;
4631 int rval = QLA_FUNCTION_FAILED;
4632
4633 if (!IS_MCTP_CAPABLE(ha)) {
4634 /* This message can be removed from the final version */
4635 ql_log(ql_log_info, vha, 0x506d,
4636 "This board is not MCTP capable\n");
4637 return rval;
4638 }
4639
4640 if (!ha->mctp_dump) {
4641 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
4642 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
4643
4644 if (!ha->mctp_dump) {
4645 ql_log(ql_log_warn, vha, 0x506e,
4646 "Failed to allocate memory for mctp dump\n");
4647 return rval;
4648 }
4649 }
4650
4651#define MCTP_DUMP_STR_ADDR 0x00000000
4652 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
4653 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
4654 if (rval != QLA_SUCCESS) {
4655 ql_log(ql_log_warn, vha, 0x506f,
4656 "Failed to capture mctp dump\n");
4657 } else {
4658 ql_log(ql_log_info, vha, 0x5070,
4659 "Mctp dump capture for host (%ld/%p).\n",
4660 vha->host_no, ha->mctp_dump);
4661 ha->mctp_dumped = 1;
4662 }
4663
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04004664 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04004665 ha->flags.nic_core_reset_hdlr_active = 1;
4666 rval = qla83xx_restart_nic_firmware(vha);
4667 if (rval)
4668 /* NIC Core reset failed. */
4669 ql_log(ql_log_warn, vha, 0x5071,
4670 "Failed to restart nic firmware\n");
4671 else
4672 ql_dbg(ql_dbg_p3p, vha, 0xb084,
4673 "Restarted NIC firmware successfully.\n");
4674 ha->flags.nic_core_reset_hdlr_active = 0;
4675 }
4676
4677 return rval;
4678
4679}
4680
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004681/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004682* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004683* Description: This function will block the new I/Os
4684* Its not aborting any I/Os as context
4685* is not destroyed during quiescence
4686* Arguments: scsi_qla_host_t
4687* return : void
4688*/
4689void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004690qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004691{
4692 struct qla_hw_data *ha = vha->hw;
4693 struct scsi_qla_host *vp;
4694
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004695 ql_dbg(ql_dbg_dpc, vha, 0x401d,
4696 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004697
4698 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4699 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4700 atomic_set(&vha->loop_state, LOOP_DOWN);
4701 qla2x00_mark_all_devices_lost(vha, 0);
4702 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004703 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004704 } else {
4705 if (!atomic_read(&vha->loop_down_timer))
4706 atomic_set(&vha->loop_down_timer,
4707 LOOP_DOWN_TIME);
4708 }
4709 /* Wait for pending cmds to complete */
4710 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
4711}
4712
Giridhar Malavalia9083012010-04-12 17:59:55 -07004713void
4714qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
4715{
4716 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004717 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07004718 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004719 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004720
Saurav Kashyape46ef002011-02-23 15:27:16 -08004721 /* For ISP82XX, driver waits for completion of the commands.
4722 * online flag should be set.
4723 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004724 if (!(IS_P3P_TYPE(ha)))
Saurav Kashyape46ef002011-02-23 15:27:16 -08004725 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004726 ha->flags.chip_reset_done = 0;
4727 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04004728 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004729
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004730 ql_log(ql_log_info, vha, 0x00af,
4731 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004732
Saurav Kashyape46ef002011-02-23 15:27:16 -08004733 /* For ISP82XX, reset_chip is just disabling interrupts.
4734 * Driver waits for the completion of the commands.
4735 * the interrupts need to be enabled.
4736 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004737 if (!(IS_P3P_TYPE(ha)))
Giridhar Malavalia9083012010-04-12 17:59:55 -07004738 ha->isp_ops->reset_chip(vha);
4739
4740 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
4741 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4742 atomic_set(&vha->loop_state, LOOP_DOWN);
4743 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004744
4745 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004746 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07004747 atomic_inc(&vp->vref_count);
4748 spin_unlock_irqrestore(&ha->vport_slock, flags);
4749
Giridhar Malavalia9083012010-04-12 17:59:55 -07004750 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004751
4752 spin_lock_irqsave(&ha->vport_slock, flags);
4753 atomic_dec(&vp->vref_count);
4754 }
4755 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004756 } else {
4757 if (!atomic_read(&vha->loop_down_timer))
4758 atomic_set(&vha->loop_down_timer,
4759 LOOP_DOWN_TIME);
4760 }
4761
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004762 /* Clear all async request states across all VPs. */
4763 list_for_each_entry(fcport, &vha->vp_fcports, list)
4764 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4765 spin_lock_irqsave(&ha->vport_slock, flags);
4766 list_for_each_entry(vp, &ha->vp_list, list) {
4767 atomic_inc(&vp->vref_count);
4768 spin_unlock_irqrestore(&ha->vport_slock, flags);
4769
4770 list_for_each_entry(fcport, &vp->vp_fcports, list)
4771 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4772
4773 spin_lock_irqsave(&ha->vport_slock, flags);
4774 atomic_dec(&vp->vref_count);
4775 }
4776 spin_unlock_irqrestore(&ha->vport_slock, flags);
4777
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004778 if (!ha->flags.eeh_busy) {
4779 /* Make sure for ISP 82XX IO DMA is complete */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004780 if (IS_P3P_TYPE(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004781 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004782 ql_log(ql_log_info, vha, 0x00b4,
4783 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004784
Saurav Kashyape46ef002011-02-23 15:27:16 -08004785 /* Done waiting for pending commands.
4786 * Reset the online flag.
4787 */
4788 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004789 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004790
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004791 /* Requeue all commands in outstanding command list. */
4792 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4793 }
Arun Easib6a029e2014-09-25 06:14:52 -04004794
4795 ha->chip_reset++;
4796 /* memory barrier */
4797 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798}
4799
4800/*
4801* qla2x00_abort_isp
4802* Resets ISP and aborts all outstanding commands.
4803*
4804* Input:
4805* ha = adapter block pointer.
4806*
4807* Returns:
4808* 0 = success
4809*/
4810int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004811qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812{
Andrew Vasquez476e8972006-08-23 14:54:55 -07004813 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004814 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004815 struct qla_hw_data *ha = vha->hw;
4816 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004817 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07004818 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004819
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004820 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004821 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822
Santosh Vernekara61712972012-08-22 14:21:13 -04004823 if (IS_QLA8031(ha)) {
4824 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
4825 "Clearing fcoe driver presence.\n");
4826 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
4827 ql_dbg(ql_dbg_p3p, vha, 0xb073,
4828 "Error while clearing DRV-Presence.\n");
4829 }
4830
Andrew Vasquez85880802009-12-15 21:29:46 -08004831 if (unlikely(pci_channel_offline(ha->pdev) &&
4832 ha->flags.pci_channel_io_perm_failure)) {
4833 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4834 status = 0;
4835 return status;
4836 }
4837
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004838 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08004839
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004840 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004841
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004842 if (!qla2x00_restart_isp(vha)) {
4843 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004844
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004845 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004846 /*
4847 * Issue marker command only when we are going
4848 * to start the I/O .
4849 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004850 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851 }
4852
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004853 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004854
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004855 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004856
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004857 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004858 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07004859
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004860 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
4861 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004862 if (ha->fce) {
4863 ha->flags.fce_enabled = 1;
4864 memset(ha->fce, 0,
4865 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004866 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004867 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4868 &ha->fce_bufs);
4869 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004870 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004871 "Unable to reinitialize FCE "
4872 "(%d).\n", rval);
4873 ha->flags.fce_enabled = 0;
4874 }
4875 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004876
4877 if (ha->eft) {
4878 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004879 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004880 ha->eft_dma, EFT_NUM_BUFFERS);
4881 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004882 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004883 "Unable to reinitialize EFT "
4884 "(%d).\n", rval);
4885 }
4886 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004887 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004888 vha->flags.online = 1;
4889 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004891 ql_log(ql_log_fatal, vha, 0x8035,
4892 "ISP error recover failed - "
4893 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004894 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004895 * The next call disables the board
4896 * completely.
4897 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004898 ha->isp_ops->reset_adapter(vha);
4899 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004900 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004901 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004902 status = 0;
4903 } else { /* schedule another ISP abort */
4904 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004905 ql_dbg(ql_dbg_taskm, vha, 0x8020,
4906 "ISP abort - retry remaining %d.\n",
4907 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004908 status = 1;
4909 }
4910 } else {
4911 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004912 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4913 "ISP error recovery - retrying (%d) "
4914 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004915 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004916 status = 1;
4917 }
4918 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004919
Linus Torvalds1da177e2005-04-16 15:20:36 -07004920 }
4921
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004922 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004923 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07004924
4925 spin_lock_irqsave(&ha->vport_slock, flags);
4926 list_for_each_entry(vp, &ha->vp_list, list) {
4927 if (vp->vp_idx) {
4928 atomic_inc(&vp->vref_count);
4929 spin_unlock_irqrestore(&ha->vport_slock, flags);
4930
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004931 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004932
4933 spin_lock_irqsave(&ha->vport_slock, flags);
4934 atomic_dec(&vp->vref_count);
4935 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004936 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004937 spin_unlock_irqrestore(&ha->vport_slock, flags);
4938
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004939 if (IS_QLA8031(ha)) {
4940 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
4941 "Setting back fcoe driver presence.\n");
4942 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
4943 ql_dbg(ql_dbg_p3p, vha, 0xb074,
4944 "Error while setting DRV-Presence.\n");
4945 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004946 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08004947 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
4948 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004949 }
4950
4951 return(status);
4952}
4953
4954/*
4955* qla2x00_restart_isp
4956* restarts the ISP after a reset
4957*
4958* Input:
4959* ha = adapter block pointer.
4960*
4961* Returns:
4962* 0 = success
4963*/
4964static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004965qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004966{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004967 int status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004968 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004969 struct req_que *req = ha->req_q_map[0];
4970 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971
4972 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004973 if (qla2x00_isp_firmware(vha)) {
4974 vha->flags.online = 0;
4975 status = ha->isp_ops->chip_diag(vha);
4976 if (!status)
4977 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004978 }
4979
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004980 if (!status && !(status = qla2x00_init_rings(vha))) {
4981 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004982 ha->flags.chip_reset_done = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04004983
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004984 /* Initialize the queues in use */
4985 qla25xx_init_queues(ha);
4986
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004987 status = qla2x00_fw_ready(vha);
4988 if (!status) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004989 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004990 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004991
Chad Dupuis7108b762014-04-11 16:54:45 -04004992 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993 }
4994
4995 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004996 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004997 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998 }
4999 return (status);
5000}
5001
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005002static int
5003qla25xx_init_queues(struct qla_hw_data *ha)
5004{
5005 struct rsp_que *rsp = NULL;
5006 struct req_que *req = NULL;
5007 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5008 int ret = -1;
5009 int i;
5010
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07005011 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005012 rsp = ha->rsp_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05005013 if (rsp && test_bit(i, ha->rsp_qid_map)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005014 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08005015 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005016 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005017 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
5018 "%s Rsp que: %d init failed.\n",
5019 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005020 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005021 ql_dbg(ql_dbg_init, base_vha, 0x0100,
5022 "%s Rsp que: %d inited.\n",
5023 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005024 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07005025 }
5026 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005027 req = ha->req_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05005028 if (req && test_bit(i, ha->req_qid_map)) {
5029 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005030 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08005031 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005032 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005033 ql_dbg(ql_dbg_init, base_vha, 0x0101,
5034 "%s Req que: %d init failed.\n",
5035 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005036 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005037 ql_dbg(ql_dbg_init, base_vha, 0x0102,
5038 "%s Req que: %d inited.\n",
5039 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005040 }
5041 }
5042 return ret;
5043}
5044
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045/*
5046* qla2x00_reset_adapter
5047* Reset adapter.
5048*
5049* Input:
5050* ha = adapter block pointer.
5051*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07005052void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005053qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005054{
5055 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005056 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07005057 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005059 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005060 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061
Linus Torvalds1da177e2005-04-16 15:20:36 -07005062 spin_lock_irqsave(&ha->hardware_lock, flags);
5063 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
5064 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
5065 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
5066 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
5067 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5068}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005069
5070void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005071qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005072{
5073 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005074 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005075 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
5076
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005077 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005078 return;
5079
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005080 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005081 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005082
5083 spin_lock_irqsave(&ha->hardware_lock, flags);
5084 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
5085 RD_REG_DWORD(&reg->hccr);
5086 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
5087 RD_REG_DWORD(&reg->hccr);
5088 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08005089
5090 if (IS_NOPOLLING_TYPE(ha))
5091 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005092}
5093
David Miller4e08df32007-04-16 12:37:43 -07005094/* On sparc systems, obtain port and node WWN from firmware
5095 * properties.
5096 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005097static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
5098 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07005099{
5100#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005101 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07005102 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07005103 struct device_node *dp = pci_device_to_OF_node(pdev);
5104 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07005105 int len;
5106
5107 val = of_get_property(dp, "port-wwn", &len);
5108 if (val && len >= WWN_SIZE)
5109 memcpy(nv->port_name, val, WWN_SIZE);
5110
5111 val = of_get_property(dp, "node-wwn", &len);
5112 if (val && len >= WWN_SIZE)
5113 memcpy(nv->node_name, val, WWN_SIZE);
5114#endif
5115}
5116
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005117int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005118qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005119{
David Miller4e08df32007-04-16 12:37:43 -07005120 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005121 struct init_cb_24xx *icb;
5122 struct nvram_24xx *nv;
5123 uint32_t *dptr;
5124 uint8_t *dptr1, *dptr2;
5125 uint32_t chksum;
5126 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005127 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005128
David Miller4e08df32007-04-16 12:37:43 -07005129 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005130 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07005131 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005132
5133 /* Determine NVRAM starting address. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05005134 if (ha->port_no == 0) {
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005135 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
5136 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
5137 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005138 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08005139 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
5140 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05005141
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005142 ha->nvram_size = sizeof(struct nvram_24xx);
5143 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005144
Seokmann Ju281afe12007-07-26 13:43:34 -07005145 /* Get VPD data into cache */
5146 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005147 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07005148 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
5149
5150 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005151 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005152 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005153 ha->nvram_size);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05005154 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
5155 chksum += le32_to_cpu(*dptr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005156
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005157 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
5158 "Contents of NVRAM\n");
5159 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
5160 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005161
5162 /* Bad NVRAM data, set defaults parameters. */
5163 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5164 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07005165 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005166 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005167 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04005168 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005169 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
5170 ql_log(ql_log_warn, vha, 0x006c,
5171 "Falling back to functioning (yet invalid -- WWPN) "
5172 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07005173
5174 /*
5175 * Set default initialization control block.
5176 */
5177 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07005178 nv->nvram_version = cpu_to_le16(ICB_VERSION);
5179 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04005180 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07005181 nv->execution_throttle = cpu_to_le16(0xFFFF);
5182 nv->exchange_count = cpu_to_le16(0);
5183 nv->hard_address = cpu_to_le16(124);
David Miller4e08df32007-04-16 12:37:43 -07005184 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005185 nv->port_name[1] = 0x00 + ha->port_no + 1;
David Miller4e08df32007-04-16 12:37:43 -07005186 nv->port_name[2] = 0x00;
5187 nv->port_name[3] = 0xe0;
5188 nv->port_name[4] = 0x8b;
5189 nv->port_name[5] = 0x1c;
5190 nv->port_name[6] = 0x55;
5191 nv->port_name[7] = 0x86;
5192 nv->node_name[0] = 0x20;
5193 nv->node_name[1] = 0x00;
5194 nv->node_name[2] = 0x00;
5195 nv->node_name[3] = 0xe0;
5196 nv->node_name[4] = 0x8b;
5197 nv->node_name[5] = 0x1c;
5198 nv->node_name[6] = 0x55;
5199 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005200 qla24xx_nvram_wwn_from_ofw(vha, nv);
Bart Van Asschead950362015-07-09 07:24:08 -07005201 nv->login_retry_count = cpu_to_le16(8);
5202 nv->interrupt_delay_timer = cpu_to_le16(0);
5203 nv->login_timeout = cpu_to_le16(0);
David Miller4e08df32007-04-16 12:37:43 -07005204 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07005205 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5206 nv->firmware_options_2 = cpu_to_le32(2 << 4);
5207 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
5208 nv->firmware_options_3 = cpu_to_le32(2 << 13);
5209 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
5210 nv->efi_parameters = cpu_to_le32(0);
David Miller4e08df32007-04-16 12:37:43 -07005211 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07005212 nv->max_luns_per_target = cpu_to_le16(128);
5213 nv->port_down_retry_count = cpu_to_le16(30);
5214 nv->link_down_timeout = cpu_to_le16(30);
David Miller4e08df32007-04-16 12:37:43 -07005215
5216 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005217 }
5218
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005219 if (!qla_ini_mode_enabled(vha)) {
5220 /* Don't enable full login after initial LIP */
Bart Van Asschead950362015-07-09 07:24:08 -07005221 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005222 /* Don't enable LIP full login for initiator */
Bart Van Asschead950362015-07-09 07:24:08 -07005223 nv->host_p &= cpu_to_le32(~BIT_10);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005224 }
5225
5226 qlt_24xx_config_nvram_stage1(vha, nv);
5227
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005228 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005229 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005230
5231 /* Copy 1st segment. */
5232 dptr1 = (uint8_t *)icb;
5233 dptr2 = (uint8_t *)&nv->version;
5234 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5235 while (cnt--)
5236 *dptr1++ = *dptr2++;
5237
5238 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07005239 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005240
5241 /* Copy 2nd segment. */
5242 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5243 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5244 cnt = (uint8_t *)&icb->reserved_3 -
5245 (uint8_t *)&icb->interrupt_delay_timer;
5246 while (cnt--)
5247 *dptr1++ = *dptr2++;
5248
5249 /*
5250 * Setup driver NVRAM options.
5251 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005252 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08005253 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005254
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005255 qlt_24xx_config_nvram_stage2(vha, icb);
5256
Bart Van Asschead950362015-07-09 07:24:08 -07005257 if (nv->host_p & cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04005258 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07005259 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5260 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5261 }
5262
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005263 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07005264 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005265 /*
5266 * Firmware will apply the following mask if the nodename was
5267 * not provided.
5268 */
5269 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5270 icb->node_name[0] &= 0xF0;
5271 }
5272
5273 /* Set host adapter parameters. */
5274 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08005275 ha->flags.enable_lip_reset = 0;
5276 ha->flags.enable_lip_full_login =
5277 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5278 ha->flags.enable_target_reset =
5279 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005280 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07005281 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005282
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07005283 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5284 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005285
5286 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
5287 sizeof(ha->fw_seriallink_options24));
5288
5289 /* save HBA serial number */
5290 ha->serial0 = icb->port_name[5];
5291 ha->serial1 = icb->port_name[6];
5292 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005293 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5294 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005295
Bart Van Asschead950362015-07-09 07:24:08 -07005296 icb->execution_throttle = cpu_to_le16(0xFFFF);
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08005297
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005298 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5299
5300 /* Set minimum login_timeout to 4 seconds. */
5301 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5302 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5303 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07005304 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005305 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005306
Andrew Vasquez00a537b2008-02-28 14:06:11 -08005307 /* Set minimum RATOV to 100 tenths of a second. */
5308 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005309
5310 ha->loop_reset_delay = nv->reset_delay;
5311
5312 /* Link Down Timeout = 0:
5313 *
5314 * When Port Down timer expires we will start returning
5315 * I/O's to OS with "DID_NO_CONNECT".
5316 *
5317 * Link Down Timeout != 0:
5318 *
5319 * The driver waits for the link to come up after link down
5320 * before returning I/Os to OS with "DID_NO_CONNECT".
5321 */
5322 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5323 ha->loop_down_abort_time =
5324 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5325 } else {
5326 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5327 ha->loop_down_abort_time =
5328 (LOOP_DOWN_TIME - ha->link_down_timeout);
5329 }
5330
5331 /* Need enough time to try and get the port back. */
5332 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5333 if (qlport_down_retry)
5334 ha->port_down_retry_count = qlport_down_retry;
5335
5336 /* Set login_retry_count */
5337 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5338 if (ha->port_down_retry_count ==
5339 le16_to_cpu(nv->port_down_retry_count) &&
5340 ha->port_down_retry_count > 3)
5341 ha->login_retry_count = ha->port_down_retry_count;
5342 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5343 ha->login_retry_count = ha->port_down_retry_count;
5344 if (ql2xloginretrycount)
5345 ha->login_retry_count = ql2xloginretrycount;
5346
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005347 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005348 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005349 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5350 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5351 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5352 le16_to_cpu(icb->interrupt_delay_timer): 2;
5353 }
Bart Van Asschead950362015-07-09 07:24:08 -07005354 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005355 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005356 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005357 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08005358 ha->zio_mode = QLA_ZIO_MODE_6;
5359
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005360 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005361 "ZIO mode %d enabled; timer delay (%d us).\n",
5362 ha->zio_mode, ha->zio_timer * 100);
5363
5364 icb->firmware_options_2 |= cpu_to_le32(
5365 (uint32_t)ha->zio_mode);
5366 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005367 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005368 }
5369
David Miller4e08df32007-04-16 12:37:43 -07005370 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005371 ql_log(ql_log_warn, vha, 0x0070,
5372 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07005373 }
5374 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005375}
5376
Sawan Chandak4243c112016-01-27 12:03:31 -05005377uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
5378{
5379 struct qla27xx_image_status pri_image_status, sec_image_status;
5380 uint8_t valid_pri_image, valid_sec_image;
5381 uint32_t *wptr;
5382 uint32_t cnt, chksum, size;
5383 struct qla_hw_data *ha = vha->hw;
5384
5385 valid_pri_image = valid_sec_image = 1;
5386 ha->active_image = 0;
5387 size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
5388
5389 if (!ha->flt_region_img_status_pri) {
5390 valid_pri_image = 0;
5391 goto check_sec_image;
5392 }
5393
5394 qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
5395 ha->flt_region_img_status_pri, size);
5396
5397 if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
5398 ql_dbg(ql_dbg_init, vha, 0x018b,
5399 "Primary image signature (0x%x) not valid\n",
5400 pri_image_status.signature);
5401 valid_pri_image = 0;
5402 goto check_sec_image;
5403 }
5404
5405 wptr = (uint32_t *)(&pri_image_status);
5406 cnt = size;
5407
Joe Carnuccioda08ef52016-01-27 12:03:34 -05005408 for (chksum = 0; cnt--; wptr++)
5409 chksum += le32_to_cpu(*wptr);
Sawan Chandak4243c112016-01-27 12:03:31 -05005410 if (chksum) {
5411 ql_dbg(ql_dbg_init, vha, 0x018c,
5412 "Checksum validation failed for primary image (0x%x)\n",
5413 chksum);
5414 valid_pri_image = 0;
5415 }
5416
5417check_sec_image:
5418 if (!ha->flt_region_img_status_sec) {
5419 valid_sec_image = 0;
5420 goto check_valid_image;
5421 }
5422
5423 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
5424 ha->flt_region_img_status_sec, size);
5425
5426 if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
5427 ql_dbg(ql_dbg_init, vha, 0x018d,
5428 "Secondary image signature(0x%x) not valid\n",
5429 sec_image_status.signature);
5430 valid_sec_image = 0;
5431 goto check_valid_image;
5432 }
5433
5434 wptr = (uint32_t *)(&sec_image_status);
5435 cnt = size;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05005436 for (chksum = 0; cnt--; wptr++)
5437 chksum += le32_to_cpu(*wptr);
Sawan Chandak4243c112016-01-27 12:03:31 -05005438 if (chksum) {
5439 ql_dbg(ql_dbg_init, vha, 0x018e,
5440 "Checksum validation failed for secondary image (0x%x)\n",
5441 chksum);
5442 valid_sec_image = 0;
5443 }
5444
5445check_valid_image:
5446 if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
5447 ha->active_image = QLA27XX_PRIMARY_IMAGE;
5448 if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
5449 if (!ha->active_image ||
5450 pri_image_status.generation_number <
5451 sec_image_status.generation_number)
5452 ha->active_image = QLA27XX_SECONDARY_IMAGE;
5453 }
5454
5455 ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n",
5456 ha->active_image == 0 ? "default bootld and fw" :
5457 ha->active_image == 1 ? "primary" :
5458 ha->active_image == 2 ? "secondary" :
5459 "Invalid");
5460
5461 return ha->active_image;
5462}
5463
Adrian Bunk413975a2006-06-30 02:33:06 -07005464static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005465qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
5466 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005467{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005468 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005469 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005470 uint32_t *dcode, dlen;
5471 uint32_t risc_addr;
5472 uint32_t risc_size;
5473 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005474 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005475 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005476
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005477 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08005478 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005479
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005480 rval = QLA_SUCCESS;
5481
5482 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005483 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005484 *srisc_addr = 0;
5485
Sawan Chandak4243c112016-01-27 12:03:31 -05005486 if (IS_QLA27XX(ha) &&
5487 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
5488 faddr = ha->flt_region_fw_sec;
5489
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005490 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005491 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005492 for (i = 0; i < 4; i++)
5493 dcode[i] = be32_to_cpu(dcode[i]);
5494 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5495 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5496 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5497 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005498 ql_log(ql_log_fatal, vha, 0x008c,
5499 "Unable to verify the integrity of flash firmware "
5500 "image.\n");
5501 ql_log(ql_log_fatal, vha, 0x008d,
5502 "Firmware data: %08x %08x %08x %08x.\n",
5503 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005504
5505 return QLA_FUNCTION_FAILED;
5506 }
5507
5508 while (segments && rval == QLA_SUCCESS) {
5509 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005510 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005511
5512 risc_addr = be32_to_cpu(dcode[2]);
5513 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5514 risc_size = be32_to_cpu(dcode[3]);
5515
5516 fragment = 0;
5517 while (risc_size > 0 && rval == QLA_SUCCESS) {
5518 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5519 if (dlen > risc_size)
5520 dlen = risc_size;
5521
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005522 ql_dbg(ql_dbg_init, vha, 0x008e,
5523 "Loading risc segment@ risc addr %x "
5524 "number of dwords 0x%x offset 0x%x.\n",
5525 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005526
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005527 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005528 for (i = 0; i < dlen; i++)
5529 dcode[i] = swab32(dcode[i]);
5530
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005531 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005532 dlen);
5533 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005534 ql_log(ql_log_fatal, vha, 0x008f,
5535 "Failed to load segment %d of firmware.\n",
5536 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04005537 return QLA_FUNCTION_FAILED;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005538 }
5539
5540 faddr += dlen;
5541 risc_addr += dlen;
5542 risc_size -= dlen;
5543 fragment++;
5544 }
5545
5546 /* Next segment. */
5547 segments--;
5548 }
5549
Chad Dupuisf73cb692014-02-26 04:15:06 -05005550 if (!IS_QLA27XX(ha))
5551 return rval;
5552
5553 if (ha->fw_dump_template)
5554 vfree(ha->fw_dump_template);
5555 ha->fw_dump_template = NULL;
5556 ha->fw_dump_template_len = 0;
5557
5558 ql_dbg(ql_dbg_init, vha, 0x0161,
5559 "Loading fwdump template from %x\n", faddr);
5560 qla24xx_read_flash_data(vha, dcode, faddr, 7);
5561 risc_size = be32_to_cpu(dcode[2]);
5562 ql_dbg(ql_dbg_init, vha, 0x0162,
5563 "-> array size %x dwords\n", risc_size);
5564 if (risc_size == 0 || risc_size == ~0)
5565 goto default_template;
5566
5567 dlen = (risc_size - 8) * sizeof(*dcode);
5568 ql_dbg(ql_dbg_init, vha, 0x0163,
5569 "-> template allocating %x bytes...\n", dlen);
5570 ha->fw_dump_template = vmalloc(dlen);
5571 if (!ha->fw_dump_template) {
5572 ql_log(ql_log_warn, vha, 0x0164,
5573 "Failed fwdump template allocate %x bytes.\n", risc_size);
5574 goto default_template;
5575 }
5576
5577 faddr += 7;
5578 risc_size -= 8;
5579 dcode = ha->fw_dump_template;
5580 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
5581 for (i = 0; i < risc_size; i++)
5582 dcode[i] = le32_to_cpu(dcode[i]);
5583
5584 if (!qla27xx_fwdt_template_valid(dcode)) {
5585 ql_log(ql_log_warn, vha, 0x0165,
5586 "Failed fwdump template validate\n");
5587 goto default_template;
5588 }
5589
5590 dlen = qla27xx_fwdt_template_size(dcode);
5591 ql_dbg(ql_dbg_init, vha, 0x0166,
5592 "-> template size %x bytes\n", dlen);
5593 if (dlen > risc_size * sizeof(*dcode)) {
5594 ql_log(ql_log_warn, vha, 0x0167,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005595 "Failed fwdump template exceeds array by %x bytes\n",
5596 (uint32_t)(dlen - risc_size * sizeof(*dcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005597 goto default_template;
5598 }
5599 ha->fw_dump_template_len = dlen;
5600 return rval;
5601
5602default_template:
5603 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
5604 if (ha->fw_dump_template)
5605 vfree(ha->fw_dump_template);
5606 ha->fw_dump_template = NULL;
5607 ha->fw_dump_template_len = 0;
5608
5609 dlen = qla27xx_fwdt_template_default_size();
5610 ql_dbg(ql_dbg_init, vha, 0x0169,
5611 "-> template allocating %x bytes...\n", dlen);
5612 ha->fw_dump_template = vmalloc(dlen);
5613 if (!ha->fw_dump_template) {
5614 ql_log(ql_log_warn, vha, 0x016a,
5615 "Failed fwdump template allocate %x bytes.\n", risc_size);
5616 goto failed_template;
5617 }
5618
5619 dcode = ha->fw_dump_template;
5620 risc_size = dlen / sizeof(*dcode);
5621 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
5622 for (i = 0; i < risc_size; i++)
5623 dcode[i] = be32_to_cpu(dcode[i]);
5624
5625 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5626 ql_log(ql_log_warn, vha, 0x016b,
5627 "Failed fwdump template validate\n");
5628 goto failed_template;
5629 }
5630
5631 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5632 ql_dbg(ql_dbg_init, vha, 0x016c,
5633 "-> template size %x bytes\n", dlen);
5634 ha->fw_dump_template_len = dlen;
5635 return rval;
5636
5637failed_template:
5638 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
5639 if (ha->fw_dump_template)
5640 vfree(ha->fw_dump_template);
5641 ha->fw_dump_template = NULL;
5642 ha->fw_dump_template_len = 0;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005643 return rval;
5644}
5645
Giridhar Malavalie9454a82013-02-08 01:57:47 -05005646#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005647
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005648int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005649qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08005650{
5651 int rval;
5652 int i, fragment;
5653 uint16_t *wcode, *fwcode;
5654 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
5655 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005656 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005657 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08005658
5659 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005660 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005661 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005662 ql_log(ql_log_info, vha, 0x0083,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01005663 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005664 ql_log(ql_log_info, vha, 0x0084,
5665 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08005666 return QLA_FUNCTION_FAILED;
5667 }
5668
5669 rval = QLA_SUCCESS;
5670
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005671 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08005672 *srisc_addr = 0;
5673 fwcode = (uint16_t *)blob->fw->data;
5674 fwclen = 0;
5675
5676 /* Validate firmware image by checking version. */
5677 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005678 ql_log(ql_log_fatal, vha, 0x0085,
5679 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005680 blob->fw->size);
5681 goto fail_fw_integrity;
5682 }
5683 for (i = 0; i < 4; i++)
5684 wcode[i] = be16_to_cpu(fwcode[i + 4]);
5685 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
5686 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
5687 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005688 ql_log(ql_log_fatal, vha, 0x0086,
5689 "Unable to verify integrity of firmware image.\n");
5690 ql_log(ql_log_fatal, vha, 0x0087,
5691 "Firmware data: %04x %04x %04x %04x.\n",
5692 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08005693 goto fail_fw_integrity;
5694 }
5695
5696 seg = blob->segs;
5697 while (*seg && rval == QLA_SUCCESS) {
5698 risc_addr = *seg;
5699 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
5700 risc_size = be16_to_cpu(fwcode[3]);
5701
5702 /* Validate firmware image size. */
5703 fwclen += risc_size * sizeof(uint16_t);
5704 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005705 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08005706 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005707 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08005708 goto fail_fw_integrity;
5709 }
5710
5711 fragment = 0;
5712 while (risc_size > 0 && rval == QLA_SUCCESS) {
5713 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
5714 if (wlen > risc_size)
5715 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005716 ql_dbg(ql_dbg_init, vha, 0x0089,
5717 "Loading risc segment@ risc addr %x number of "
5718 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08005719
5720 for (i = 0; i < wlen; i++)
5721 wcode[i] = swab16(fwcode[i]);
5722
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005723 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08005724 wlen);
5725 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005726 ql_log(ql_log_fatal, vha, 0x008a,
5727 "Failed to load segment %d of firmware.\n",
5728 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08005729 break;
5730 }
5731
5732 fwcode += wlen;
5733 risc_addr += wlen;
5734 risc_size -= wlen;
5735 fragment++;
5736 }
5737
5738 /* Next segment. */
5739 seg++;
5740 }
5741 return rval;
5742
5743fail_fw_integrity:
5744 return QLA_FUNCTION_FAILED;
5745}
5746
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005747static int
5748qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005749{
5750 int rval;
5751 int segments, fragment;
5752 uint32_t *dcode, dlen;
5753 uint32_t risc_addr;
5754 uint32_t risc_size;
5755 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08005756 struct fw_blob *blob;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005757 const uint32_t *fwcode;
5758 uint32_t fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005759 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005760 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005761
Andrew Vasquez54333832005-11-09 15:49:04 -08005762 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005763 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005764 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005765 ql_log(ql_log_warn, vha, 0x0090,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01005766 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005767 ql_log(ql_log_warn, vha, 0x0091,
5768 "Firmware images can be retrieved from: "
5769 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005770
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005771 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005772 }
5773
Chad Dupuiscfb09192011-11-18 09:03:07 -08005774 ql_dbg(ql_dbg_init, vha, 0x0092,
5775 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005776
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005777 rval = QLA_SUCCESS;
5778
5779 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005780 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005781 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08005782 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005783 fwclen = 0;
5784
5785 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08005786 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005787 ql_log(ql_log_fatal, vha, 0x0093,
5788 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005789 blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005790 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005791 }
5792 for (i = 0; i < 4; i++)
5793 dcode[i] = be32_to_cpu(fwcode[i + 4]);
5794 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5795 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5796 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5797 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005798 ql_log(ql_log_fatal, vha, 0x0094,
5799 "Unable to verify integrity of firmware image (%Zd).\n",
5800 blob->fw->size);
5801 ql_log(ql_log_fatal, vha, 0x0095,
5802 "Firmware data: %08x %08x %08x %08x.\n",
5803 dcode[0], dcode[1], dcode[2], dcode[3]);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005804 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005805 }
5806
5807 while (segments && rval == QLA_SUCCESS) {
5808 risc_addr = be32_to_cpu(fwcode[2]);
5809 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5810 risc_size = be32_to_cpu(fwcode[3]);
5811
5812 /* Validate firmware image size. */
5813 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08005814 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005815 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08005816 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005817 "(%Zd).\n", blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05005818 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005819 }
5820
5821 fragment = 0;
5822 while (risc_size > 0 && rval == QLA_SUCCESS) {
5823 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5824 if (dlen > risc_size)
5825 dlen = risc_size;
5826
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005827 ql_dbg(ql_dbg_init, vha, 0x0097,
5828 "Loading risc segment@ risc addr %x "
5829 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005830
5831 for (i = 0; i < dlen; i++)
5832 dcode[i] = swab32(fwcode[i]);
5833
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005834 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08005835 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005836 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005837 ql_log(ql_log_fatal, vha, 0x0098,
5838 "Failed to load segment %d of firmware.\n",
5839 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04005840 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005841 }
5842
5843 fwcode += dlen;
5844 risc_addr += dlen;
5845 risc_size -= dlen;
5846 fragment++;
5847 }
5848
5849 /* Next segment. */
5850 segments--;
5851 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05005852
5853 if (!IS_QLA27XX(ha))
5854 return rval;
5855
5856 if (ha->fw_dump_template)
5857 vfree(ha->fw_dump_template);
5858 ha->fw_dump_template = NULL;
5859 ha->fw_dump_template_len = 0;
5860
5861 ql_dbg(ql_dbg_init, vha, 0x171,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005862 "Loading fwdump template from %x\n",
5863 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005864 risc_size = be32_to_cpu(fwcode[2]);
5865 ql_dbg(ql_dbg_init, vha, 0x172,
5866 "-> array size %x dwords\n", risc_size);
5867 if (risc_size == 0 || risc_size == ~0)
5868 goto default_template;
5869
5870 dlen = (risc_size - 8) * sizeof(*fwcode);
5871 ql_dbg(ql_dbg_init, vha, 0x0173,
5872 "-> template allocating %x bytes...\n", dlen);
5873 ha->fw_dump_template = vmalloc(dlen);
5874 if (!ha->fw_dump_template) {
5875 ql_log(ql_log_warn, vha, 0x0174,
5876 "Failed fwdump template allocate %x bytes.\n", risc_size);
5877 goto default_template;
5878 }
5879
5880 fwcode += 7;
5881 risc_size -= 8;
5882 dcode = ha->fw_dump_template;
5883 for (i = 0; i < risc_size; i++)
5884 dcode[i] = le32_to_cpu(fwcode[i]);
5885
5886 if (!qla27xx_fwdt_template_valid(dcode)) {
5887 ql_log(ql_log_warn, vha, 0x0175,
5888 "Failed fwdump template validate\n");
5889 goto default_template;
5890 }
5891
5892 dlen = qla27xx_fwdt_template_size(dcode);
5893 ql_dbg(ql_dbg_init, vha, 0x0176,
5894 "-> template size %x bytes\n", dlen);
5895 if (dlen > risc_size * sizeof(*fwcode)) {
5896 ql_log(ql_log_warn, vha, 0x0177,
Chad Dupuis97ea7022014-03-13 14:16:40 -04005897 "Failed fwdump template exceeds array by %x bytes\n",
5898 (uint32_t)(dlen - risc_size * sizeof(*fwcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05005899 goto default_template;
5900 }
5901 ha->fw_dump_template_len = dlen;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005902 return rval;
5903
Chad Dupuisf73cb692014-02-26 04:15:06 -05005904default_template:
5905 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
5906 if (ha->fw_dump_template)
5907 vfree(ha->fw_dump_template);
5908 ha->fw_dump_template = NULL;
5909 ha->fw_dump_template_len = 0;
5910
5911 dlen = qla27xx_fwdt_template_default_size();
5912 ql_dbg(ql_dbg_init, vha, 0x0179,
5913 "-> template allocating %x bytes...\n", dlen);
5914 ha->fw_dump_template = vmalloc(dlen);
5915 if (!ha->fw_dump_template) {
5916 ql_log(ql_log_warn, vha, 0x017a,
5917 "Failed fwdump template allocate %x bytes.\n", risc_size);
5918 goto failed_template;
5919 }
5920
5921 dcode = ha->fw_dump_template;
5922 risc_size = dlen / sizeof(*fwcode);
5923 fwcode = qla27xx_fwdt_template_default();
5924 for (i = 0; i < risc_size; i++)
5925 dcode[i] = be32_to_cpu(fwcode[i]);
5926
5927 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
5928 ql_log(ql_log_warn, vha, 0x017b,
5929 "Failed fwdump template validate\n");
5930 goto failed_template;
5931 }
5932
5933 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
5934 ql_dbg(ql_dbg_init, vha, 0x017c,
5935 "-> template size %x bytes\n", dlen);
5936 ha->fw_dump_template_len = dlen;
5937 return rval;
5938
5939failed_template:
5940 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
5941 if (ha->fw_dump_template)
5942 vfree(ha->fw_dump_template);
5943 ha->fw_dump_template = NULL;
5944 ha->fw_dump_template_len = 0;
5945 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005946}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005947
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005948int
5949qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5950{
5951 int rval;
5952
Andrew Vasqueze337d902009-04-06 22:33:49 -07005953 if (ql2xfwloadbin == 1)
5954 return qla81xx_load_risc(vha, srisc_addr);
5955
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005956 /*
5957 * FW Load priority:
5958 * 1) Firmware via request-firmware interface (.bin file).
5959 * 2) Firmware residing in flash.
5960 */
5961 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5962 if (rval == QLA_SUCCESS)
5963 return rval;
5964
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005965 return qla24xx_load_risc_flash(vha, srisc_addr,
5966 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005967}
5968
5969int
5970qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5971{
5972 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005973 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005974
Andrew Vasqueze337d902009-04-06 22:33:49 -07005975 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005976 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07005977
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005978 /*
5979 * FW Load priority:
5980 * 1) Firmware residing in flash.
5981 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005982 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005983 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005984 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005985 if (rval == QLA_SUCCESS)
5986 return rval;
5987
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005988try_blob_fw:
5989 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5990 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
5991 return rval;
5992
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005993 ql_log(ql_log_info, vha, 0x0099,
5994 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005995 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
5996 if (rval != QLA_SUCCESS)
5997 return rval;
5998
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005999 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006000 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006001 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006002}
6003
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006004void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006005qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006006{
6007 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006008 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006009
Andrew Vasquez85880802009-12-15 21:29:46 -08006010 if (ha->flags.pci_channel_io_perm_failure)
6011 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07006012 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006013 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07006014 if (!ha->fw_major_version)
6015 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006016
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006017 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08006018 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07006019 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006020 ha->isp_ops->reset_chip(vha);
6021 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006022 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006023 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006024 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006025 ql_log(ql_log_info, vha, 0x8015,
6026 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006027 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006028 }
6029}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006030
6031int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006032qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006033{
6034 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08006035 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006036 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006037 struct qla_hw_data *ha = vha->hw;
6038 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07006039 struct req_que *req;
6040 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006041
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006042 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006043 return -EINVAL;
6044
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006045 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07006046 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07006047 req = ha->req_q_map[0];
6048 else
6049 req = vha->req;
6050 rsp = req->rsp;
6051
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006052 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006053 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006054 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006055 }
6056
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006057 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006058
6059 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08006060 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
6061 BIT_1);
6062 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
6063 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
6064 ql_dbg(ql_dbg_init, vha, 0x0120,
6065 "Failed SNS login: loop_id=%x, rval2=%d\n",
6066 NPH_SNS, rval2);
6067 else
6068 ql_dbg(ql_dbg_init, vha, 0x0103,
6069 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
6070 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
6071 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006072 return (QLA_FUNCTION_FAILED);
6073 }
6074
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006075 atomic_set(&vha->loop_down_timer, 0);
6076 atomic_set(&vha->loop_state, LOOP_UP);
6077 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6078 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
6079 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006080
6081 return rval;
6082}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006083
6084/* 84XX Support **************************************************************/
6085
6086static LIST_HEAD(qla_cs84xx_list);
6087static DEFINE_MUTEX(qla_cs84xx_mutex);
6088
6089static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006090qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006091{
6092 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006093 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006094
6095 mutex_lock(&qla_cs84xx_mutex);
6096
6097 /* Find any shared 84xx chip. */
6098 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
6099 if (cs84xx->bus == ha->pdev->bus) {
6100 kref_get(&cs84xx->kref);
6101 goto done;
6102 }
6103 }
6104
6105 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
6106 if (!cs84xx)
6107 goto done;
6108
6109 kref_init(&cs84xx->kref);
6110 spin_lock_init(&cs84xx->access_lock);
6111 mutex_init(&cs84xx->fw_update_mutex);
6112 cs84xx->bus = ha->pdev->bus;
6113
6114 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
6115done:
6116 mutex_unlock(&qla_cs84xx_mutex);
6117 return cs84xx;
6118}
6119
6120static void
6121__qla84xx_chip_release(struct kref *kref)
6122{
6123 struct qla_chip_state_84xx *cs84xx =
6124 container_of(kref, struct qla_chip_state_84xx, kref);
6125
6126 mutex_lock(&qla_cs84xx_mutex);
6127 list_del(&cs84xx->list);
6128 mutex_unlock(&qla_cs84xx_mutex);
6129 kfree(cs84xx);
6130}
6131
6132void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006133qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006134{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006135 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006136 if (ha->cs84xx)
6137 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
6138}
6139
6140static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006141qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006142{
6143 int rval;
6144 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006145 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006146
6147 mutex_lock(&ha->cs84xx->fw_update_mutex);
6148
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006149 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006150
6151 mutex_unlock(&ha->cs84xx->fw_update_mutex);
6152
6153 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
6154 QLA_SUCCESS;
6155}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006156
6157/* 81XX Support **************************************************************/
6158
6159int
6160qla81xx_nvram_config(scsi_qla_host_t *vha)
6161{
6162 int rval;
6163 struct init_cb_81xx *icb;
6164 struct nvram_81xx *nv;
6165 uint32_t *dptr;
6166 uint8_t *dptr1, *dptr2;
6167 uint32_t chksum;
6168 uint16_t cnt;
6169 struct qla_hw_data *ha = vha->hw;
6170
6171 rval = QLA_SUCCESS;
6172 icb = (struct init_cb_81xx *)ha->init_cb;
6173 nv = ha->nvram;
6174
6175 /* Determine NVRAM starting address. */
6176 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006177 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006178 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
6179 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006180
6181 /* Get VPD data into cache */
6182 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006183 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
6184 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006185
6186 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006187 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006188 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006189 dptr = (uint32_t *)nv;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006190 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
6191 chksum += le32_to_cpu(*dptr);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006192
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006193 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
6194 "Contents of NVRAM:\n");
6195 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
6196 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006197
6198 /* Bad NVRAM data, set defaults parameters. */
6199 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6200 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07006201 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006202 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006203 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04006204 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006205 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006206 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006207 ql_log(ql_log_info, vha, 0x0074,
6208 "Falling back to functioning (yet invalid -- WWPN) "
6209 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006210
6211 /*
6212 * Set default initialization control block.
6213 */
6214 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07006215 nv->nvram_version = cpu_to_le16(ICB_VERSION);
6216 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04006217 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07006218 nv->execution_throttle = cpu_to_le16(0xFFFF);
6219 nv->exchange_count = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006220 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006221 nv->port_name[1] = 0x00 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006222 nv->port_name[2] = 0x00;
6223 nv->port_name[3] = 0xe0;
6224 nv->port_name[4] = 0x8b;
6225 nv->port_name[5] = 0x1c;
6226 nv->port_name[6] = 0x55;
6227 nv->port_name[7] = 0x86;
6228 nv->node_name[0] = 0x20;
6229 nv->node_name[1] = 0x00;
6230 nv->node_name[2] = 0x00;
6231 nv->node_name[3] = 0xe0;
6232 nv->node_name[4] = 0x8b;
6233 nv->node_name[5] = 0x1c;
6234 nv->node_name[6] = 0x55;
6235 nv->node_name[7] = 0x86;
Bart Van Asschead950362015-07-09 07:24:08 -07006236 nv->login_retry_count = cpu_to_le16(8);
6237 nv->interrupt_delay_timer = cpu_to_le16(0);
6238 nv->login_timeout = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006239 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07006240 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6241 nv->firmware_options_2 = cpu_to_le32(2 << 4);
6242 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6243 nv->firmware_options_3 = cpu_to_le32(2 << 13);
6244 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6245 nv->efi_parameters = cpu_to_le32(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006246 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07006247 nv->max_luns_per_target = cpu_to_le16(128);
6248 nv->port_down_retry_count = cpu_to_le16(30);
6249 nv->link_down_timeout = cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07006250 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006251 nv->enode_mac[1] = 0xC0;
6252 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006253 nv->enode_mac[3] = 0x04;
6254 nv->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006255 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006256
6257 rval = 1;
6258 }
6259
Arun Easi9e522cd2012-08-22 14:21:31 -04006260 if (IS_T10_PI_CAPABLE(ha))
6261 nv->frame_payload_size &= ~7;
6262
Arun Easiaa230bc2013-01-30 03:34:39 -05006263 qlt_81xx_config_nvram_stage1(vha, nv);
6264
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006265 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07006266 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006267
6268 /* Copy 1st segment. */
6269 dptr1 = (uint8_t *)icb;
6270 dptr2 = (uint8_t *)&nv->version;
6271 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6272 while (cnt--)
6273 *dptr1++ = *dptr2++;
6274
6275 icb->login_retry_count = nv->login_retry_count;
6276
6277 /* Copy 2nd segment. */
6278 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6279 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6280 cnt = (uint8_t *)&icb->reserved_5 -
6281 (uint8_t *)&icb->interrupt_delay_timer;
6282 while (cnt--)
6283 *dptr1++ = *dptr2++;
6284
6285 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
6286 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
6287 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08006288 icb->enode_mac[0] = 0x00;
6289 icb->enode_mac[1] = 0xC0;
6290 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006291 icb->enode_mac[3] = 0x04;
6292 icb->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006293 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006294 }
6295
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07006296 /* Use extended-initialization control block. */
6297 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
6298
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006299 /*
6300 * Setup driver NVRAM options.
6301 */
6302 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07006303 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006304
Arun Easiaa230bc2013-01-30 03:34:39 -05006305 qlt_81xx_config_nvram_stage2(vha, icb);
6306
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006307 /* Use alternate WWN? */
Bart Van Asschead950362015-07-09 07:24:08 -07006308 if (nv->host_p & cpu_to_le32(BIT_15)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006309 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6310 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6311 }
6312
6313 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07006314 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006315 /*
6316 * Firmware will apply the following mask if the nodename was
6317 * not provided.
6318 */
6319 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6320 icb->node_name[0] &= 0xF0;
6321 }
6322
6323 /* Set host adapter parameters. */
6324 ha->flags.disable_risc_code_load = 0;
6325 ha->flags.enable_lip_reset = 0;
6326 ha->flags.enable_lip_full_login =
6327 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6328 ha->flags.enable_target_reset =
6329 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
6330 ha->flags.enable_led_scheme = 0;
6331 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
6332
6333 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6334 (BIT_6 | BIT_5 | BIT_4)) >> 4;
6335
6336 /* save HBA serial number */
6337 ha->serial0 = icb->port_name[5];
6338 ha->serial1 = icb->port_name[6];
6339 ha->serial2 = icb->port_name[7];
6340 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6341 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
6342
Bart Van Asschead950362015-07-09 07:24:08 -07006343 icb->execution_throttle = cpu_to_le16(0xFFFF);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006344
6345 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6346
6347 /* Set minimum login_timeout to 4 seconds. */
6348 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6349 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6350 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07006351 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006352 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006353
6354 /* Set minimum RATOV to 100 tenths of a second. */
6355 ha->r_a_tov = 100;
6356
6357 ha->loop_reset_delay = nv->reset_delay;
6358
6359 /* Link Down Timeout = 0:
6360 *
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006361 * When Port Down timer expires we will start returning
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006362 * I/O's to OS with "DID_NO_CONNECT".
6363 *
6364 * Link Down Timeout != 0:
6365 *
6366 * The driver waits for the link to come up after link down
6367 * before returning I/Os to OS with "DID_NO_CONNECT".
6368 */
6369 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6370 ha->loop_down_abort_time =
6371 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6372 } else {
6373 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6374 ha->loop_down_abort_time =
6375 (LOOP_DOWN_TIME - ha->link_down_timeout);
6376 }
6377
6378 /* Need enough time to try and get the port back. */
6379 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6380 if (qlport_down_retry)
6381 ha->port_down_retry_count = qlport_down_retry;
6382
6383 /* Set login_retry_count */
6384 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6385 if (ha->port_down_retry_count ==
6386 le16_to_cpu(nv->port_down_retry_count) &&
6387 ha->port_down_retry_count > 3)
6388 ha->login_retry_count = ha->port_down_retry_count;
6389 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6390 ha->login_retry_count = ha->port_down_retry_count;
6391 if (ql2xloginretrycount)
6392 ha->login_retry_count = ql2xloginretrycount;
6393
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006394 /* if not running MSI-X we need handshaking on interrupts */
Chad Dupuisf73cb692014-02-26 04:15:06 -05006395 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
Bart Van Asschead950362015-07-09 07:24:08 -07006396 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08006397
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006398 /* Enable ZIO. */
6399 if (!vha->flags.init_done) {
6400 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6401 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6402 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6403 le16_to_cpu(icb->interrupt_delay_timer): 2;
6404 }
Bart Van Asschead950362015-07-09 07:24:08 -07006405 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006406 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
6407 vha->flags.process_response_queue = 0;
6408 if (ha->zio_mode != QLA_ZIO_DISABLED) {
6409 ha->zio_mode = QLA_ZIO_MODE_6;
6410
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006411 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006412 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006413 ha->zio_mode,
6414 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006415
6416 icb->firmware_options_2 |= cpu_to_le32(
6417 (uint32_t)ha->zio_mode);
6418 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
6419 vha->flags.process_response_queue = 1;
6420 }
6421
6422 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006423 ql_log(ql_log_warn, vha, 0x0076,
6424 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006425 }
6426 return (rval);
6427}
6428
Giridhar Malavalia9083012010-04-12 17:59:55 -07006429int
6430qla82xx_restart_isp(scsi_qla_host_t *vha)
6431{
6432 int status, rval;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006433 struct qla_hw_data *ha = vha->hw;
6434 struct req_que *req = ha->req_q_map[0];
6435 struct rsp_que *rsp = ha->rsp_q_map[0];
6436 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07006437 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006438
6439 status = qla2x00_init_rings(vha);
6440 if (!status) {
6441 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6442 ha->flags.chip_reset_done = 1;
6443
6444 status = qla2x00_fw_ready(vha);
6445 if (!status) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07006446 /* Issue a marker after FW becomes ready. */
6447 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006448 vha->flags.online = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04006449 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006450 }
6451
6452 /* if no cable then assume it's good */
6453 if ((vha->device_flags & DFLG_NO_CABLE))
6454 status = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07006455 }
6456
6457 if (!status) {
6458 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6459
6460 if (!atomic_read(&vha->loop_down_timer)) {
6461 /*
6462 * Issue marker command only when we are going
6463 * to start the I/O .
6464 */
6465 vha->marker_needed = 1;
6466 }
6467
Giridhar Malavalia9083012010-04-12 17:59:55 -07006468 ha->isp_ops->enable_intrs(ha);
6469
6470 ha->isp_abort_cnt = 0;
6471 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6472
Saurav Kashyap53296782011-05-10 11:30:06 -07006473 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07006474 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07006475
Giridhar Malavalia9083012010-04-12 17:59:55 -07006476 if (ha->fce) {
6477 ha->flags.fce_enabled = 1;
6478 memset(ha->fce, 0,
6479 fce_calc_size(ha->fce_bufs));
6480 rval = qla2x00_enable_fce_trace(vha,
6481 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6482 &ha->fce_bufs);
6483 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006484 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006485 "Unable to reinitialize FCE (%d).\n",
6486 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006487 ha->flags.fce_enabled = 0;
6488 }
6489 }
6490
6491 if (ha->eft) {
6492 memset(ha->eft, 0, EFT_SIZE);
6493 rval = qla2x00_enable_eft_trace(vha,
6494 ha->eft_dma, EFT_NUM_BUFFERS);
6495 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006496 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006497 "Unable to reinitialize EFT (%d).\n",
6498 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07006499 }
6500 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006501 }
6502
6503 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006504 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006505 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07006506
6507 spin_lock_irqsave(&ha->vport_slock, flags);
6508 list_for_each_entry(vp, &ha->vp_list, list) {
6509 if (vp->vp_idx) {
6510 atomic_inc(&vp->vref_count);
6511 spin_unlock_irqrestore(&ha->vport_slock, flags);
6512
Giridhar Malavalia9083012010-04-12 17:59:55 -07006513 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07006514
6515 spin_lock_irqsave(&ha->vport_slock, flags);
6516 atomic_dec(&vp->vref_count);
6517 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07006518 }
Arun Easifeafb7b2010-09-03 14:57:00 -07006519 spin_unlock_irqrestore(&ha->vport_slock, flags);
6520
Giridhar Malavalia9083012010-04-12 17:59:55 -07006521 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08006522 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006523 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07006524 }
6525
6526 return status;
6527}
6528
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006529void
Andrew Vasquezae97c912010-02-18 10:07:28 -08006530qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006531{
Andrew Vasquezae97c912010-02-18 10:07:28 -08006532 struct qla_hw_data *ha = vha->hw;
6533
Himanshu Madhanif198caf2016-01-27 12:03:30 -05006534 /* Hold status IOCBs until ABTS response received. */
6535 if (ql2xfwholdabts)
6536 ha->fw_options[3] |= BIT_12;
6537
Giridhar Malavali088d09d2016-07-06 11:14:20 -04006538 /* Set Retry FLOGI in case of P2P connection */
6539 if (ha->operating_mode == P2P) {
6540 ha->fw_options[2] |= BIT_3;
6541 ql_dbg(ql_dbg_disc, vha, 0x2103,
6542 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
6543 __func__, ha->fw_options[2]);
6544 }
6545
Andrew Vasquezae97c912010-02-18 10:07:28 -08006546 if (!ql2xetsenable)
Himanshu Madhanif198caf2016-01-27 12:03:30 -05006547 goto out;
Andrew Vasquezae97c912010-02-18 10:07:28 -08006548
6549 /* Enable ETS Burst. */
6550 memset(ha->fw_options, 0, sizeof(ha->fw_options));
6551 ha->fw_options[2] |= BIT_9;
Himanshu Madhanif198caf2016-01-27 12:03:30 -05006552out:
Andrew Vasquezae97c912010-02-18 10:07:28 -08006553 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006554}
Sarang Radke09ff7012010-03-19 17:03:59 -07006555
6556/*
6557 * qla24xx_get_fcp_prio
6558 * Gets the fcp cmd priority value for the logged in port.
6559 * Looks for a match of the port descriptors within
6560 * each of the fcp prio config entries. If a match is found,
6561 * the tag (priority) value is returned.
6562 *
6563 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006564 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07006565 * fcport = port structure pointer.
6566 *
6567 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07006568 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006569 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07006570 *
6571 * Context:
6572 * Kernel context
6573 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006574static int
Sarang Radke09ff7012010-03-19 17:03:59 -07006575qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
6576{
6577 int i, entries;
6578 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006579 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07006580 uint32_t pid1, pid2;
6581 uint64_t wwn1, wwn2;
6582 struct qla_fcp_prio_entry *pri_entry;
6583 struct qla_hw_data *ha = vha->hw;
6584
6585 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006586 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07006587
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006588 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07006589 entries = ha->fcp_prio_cfg->num_entries;
6590 pri_entry = &ha->fcp_prio_cfg->entry[0];
6591
6592 for (i = 0; i < entries; i++) {
6593 pid_match = wwn_match = 0;
6594
6595 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
6596 pri_entry++;
6597 continue;
6598 }
6599
6600 /* check source pid for a match */
6601 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
6602 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
6603 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
6604 if (pid1 == INVALID_PORT_ID)
6605 pid_match++;
6606 else if (pid1 == pid2)
6607 pid_match++;
6608 }
6609
6610 /* check destination pid for a match */
6611 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
6612 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
6613 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
6614 if (pid1 == INVALID_PORT_ID)
6615 pid_match++;
6616 else if (pid1 == pid2)
6617 pid_match++;
6618 }
6619
6620 /* check source WWN for a match */
6621 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
6622 wwn1 = wwn_to_u64(vha->port_name);
6623 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
6624 if (wwn2 == (uint64_t)-1)
6625 wwn_match++;
6626 else if (wwn1 == wwn2)
6627 wwn_match++;
6628 }
6629
6630 /* check destination WWN for a match */
6631 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
6632 wwn1 = wwn_to_u64(fcport->port_name);
6633 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
6634 if (wwn2 == (uint64_t)-1)
6635 wwn_match++;
6636 else if (wwn1 == wwn2)
6637 wwn_match++;
6638 }
6639
6640 if (pid_match == 2 || wwn_match == 2) {
6641 /* Found a matching entry */
6642 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
6643 priority = pri_entry->tag;
6644 break;
6645 }
6646
6647 pri_entry++;
6648 }
6649
6650 return priority;
6651}
6652
6653/*
6654 * qla24xx_update_fcport_fcp_prio
6655 * Activates fcp priority for the logged in fc port
6656 *
6657 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006658 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07006659 * fcp = port structure pointer.
6660 *
6661 * Return:
6662 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6663 *
6664 * Context:
6665 * Kernel context.
6666 */
6667int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006668qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07006669{
6670 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006671 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07006672 uint16_t mb[5];
6673
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006674 if (fcport->port_type != FCT_TARGET ||
6675 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07006676 return QLA_FUNCTION_FAILED;
6677
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006678 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006679 if (priority < 0)
6680 return QLA_FUNCTION_FAILED;
6681
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006682 if (IS_P3P_TYPE(vha->hw)) {
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006683 fcport->fcp_prio = priority & 0xf;
6684 return QLA_SUCCESS;
6685 }
6686
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006687 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08006688 if (ret == QLA_SUCCESS) {
6689 if (fcport->fcp_prio != priority)
6690 ql_dbg(ql_dbg_user, vha, 0x709e,
6691 "Updated FCP_CMND priority - value=%d loop_id=%d "
6692 "port_id=%02x%02x%02x.\n", priority,
6693 fcport->loop_id, fcport->d_id.b.domain,
6694 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006695 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08006696 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006697 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006698 "Unable to update FCP_CMND priority - ret=0x%x for "
6699 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
6700 fcport->d_id.b.domain, fcport->d_id.b.area,
6701 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07006702 return ret;
6703}
6704
6705/*
6706 * qla24xx_update_all_fcp_prio
6707 * Activates fcp priority for all the logged in ports
6708 *
6709 * Input:
6710 * ha = adapter block pointer.
6711 *
6712 * Return:
6713 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6714 *
6715 * Context:
6716 * Kernel context.
6717 */
6718int
6719qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
6720{
6721 int ret;
6722 fc_port_t *fcport;
6723
6724 ret = QLA_FUNCTION_FAILED;
6725 /* We need to set priority for all logged in ports */
6726 list_for_each_entry(fcport, &vha->vp_fcports, list)
6727 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
6728
6729 return ret;
6730}