blob: a7865a5d556d9dd3ae3cf4eb410dda4fa45e5339 [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 *);
Quinn Tran726b8542017-01-19 22:28:00 -080033static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Harihara Kadayam4d4df192008-04-03 13:13:26 -070036static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
37static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080038static int qla25xx_init_queues(struct qla_hw_data *);
Quinn Tran726b8542017-01-19 22:28:00 -080039static int qla24xx_post_gpdb_work(struct scsi_qla_host *, fc_port_t *, u8);
40static void qla24xx_handle_plogi_done_event(struct scsi_qla_host *,
41 struct event_arg *);
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;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080050 scsi_qla_host_t *vha = sp->vha;
Andrew Vasquezac280b62009-08-20 11:06:05 -070051 struct req_que *req;
52 unsigned long flags;
53
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080054 spin_lock_irqsave(&vha->hw->hardware_lock, flags);
55 req = vha->hw->req_q_map[0];
Andrew Vasquezac280b62009-08-20 11:06:05 -070056 req->outstanding_cmds[sp->handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080057 iocb = &sp->u.iocb_cmd;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070058 iocb->timeout(sp);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080059 sp->free(sp);
60 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -070061}
62
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080063void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080064qla2x00_sp_free(void *ptr)
Andrew Vasquezac280b62009-08-20 11:06:05 -070065{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080066 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080067 struct srb_iocb *iocb = &sp->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -070068
Chad Dupuis4d97cc52010-10-15 11:27:41 -070069 del_timer(&iocb->timer);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080070 qla2x00_rel_sp(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -070071}
72
Andrew Vasquezac280b62009-08-20 11:06:05 -070073/* Asynchronous Login/Logout Routines -------------------------------------- */
74
Saurav Kashyapa9b6f722012-08-22 14:21:01 -040075unsigned long
Andrew Vasquez5b914902010-05-28 15:08:30 -070076qla2x00_get_async_timeout(struct scsi_qla_host *vha)
77{
78 unsigned long tmo;
79 struct qla_hw_data *ha = vha->hw;
80
81 /* Firmware should use switch negotiated r_a_tov for timeout. */
82 tmo = ha->r_a_tov / 10 * 2;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -040083 if (IS_QLAFX00(ha)) {
84 tmo = FX00_DEF_RATOV * 2;
85 } else if (!IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez5b914902010-05-28 15:08:30 -070086 /*
87 * Except for earlier ISPs where the timeout is seeded from the
88 * initialization control block.
89 */
90 tmo = ha->login_timeout;
91 }
92 return tmo;
93}
Andrew Vasquezac280b62009-08-20 11:06:05 -070094
Quinn Tran726b8542017-01-19 22:28:00 -080095void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080096qla2x00_async_iocb_timeout(void *data)
Andrew Vasquezac280b62009-08-20 11:06:05 -070097{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -080098 srb_t *sp = data;
Andrew Vasquezac280b62009-08-20 11:06:05 -070099 fc_port_t *fcport = sp->fcport;
Quinn Tran726b8542017-01-19 22:28:00 -0800100 struct srb_iocb *lio = &sp->u.iocb_cmd;
101 struct event_arg ea;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700102
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700103 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
Quinn Tran726b8542017-01-19 22:28:00 -0800104 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
105 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700106
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700107 fcport->flags &= ~FCF_ASYNC_SENT;
Quinn Tran726b8542017-01-19 22:28:00 -0800108
109 switch (sp->type) {
110 case SRB_LOGIN_CMD:
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700111 /* Retry as needed. */
112 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
113 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
114 QLA_LOGIO_LOGIN_RETRIED : 0;
Quinn Tran726b8542017-01-19 22:28:00 -0800115 memset(&ea, 0, sizeof(ea));
116 ea.event = FCME_PLOGI_DONE;
117 ea.fcport = sp->fcport;
118 ea.data[0] = lio->u.logio.data[0];
119 ea.data[1] = lio->u.logio.data[1];
120 ea.sp = sp;
121 qla24xx_handle_plogi_done_event(fcport->vha, &ea);
122 break;
123 case SRB_LOGOUT_CMD:
Alexei Potashnika6ca8872015-07-14 16:00:44 -0400124 qlt_logo_completion_handler(fcport, QLA_FUNCTION_TIMEOUT);
Quinn Tran726b8542017-01-19 22:28:00 -0800125 break;
126 case SRB_CT_PTHRU_CMD:
127 case SRB_MB_IOCB:
128 case SRB_NACK_PLOGI:
129 case SRB_NACK_PRLI:
130 case SRB_NACK_LOGO:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800131 sp->done(sp, QLA_FUNCTION_TIMEOUT);
Quinn Tran726b8542017-01-19 22:28:00 -0800132 break;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700133 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700134}
135
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700136static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800137qla2x00_async_login_sp_done(void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700138{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800139 srb_t *sp = ptr;
140 struct scsi_qla_host *vha = sp->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800141 struct srb_iocb *lio = &sp->u.iocb_cmd;
Quinn Tran726b8542017-01-19 22:28:00 -0800142 struct event_arg ea;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700143
Quinn Tran726b8542017-01-19 22:28:00 -0800144 ql_dbg(ql_dbg_disc, vha, 0xffff,
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800145 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
Quinn Tran726b8542017-01-19 22:28:00 -0800146
147 sp->fcport->flags &= ~FCF_ASYNC_SENT;
148 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
149 memset(&ea, 0, sizeof(ea));
150 ea.event = FCME_PLOGI_DONE;
151 ea.fcport = sp->fcport;
152 ea.data[0] = lio->u.logio.data[0];
153 ea.data[1] = lio->u.logio.data[1];
154 ea.iop[0] = lio->u.logio.iop[0];
155 ea.iop[1] = lio->u.logio.iop[1];
156 ea.sp = sp;
157 qla2x00_fcport_event_handler(vha, &ea);
158 }
159
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800160 sp->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700161}
162
Andrew Vasquezac280b62009-08-20 11:06:05 -0700163int
164qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
165 uint16_t *data)
166{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700167 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700168 struct srb_iocb *lio;
Quinn Tran726b8542017-01-19 22:28:00 -0800169 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700170
Quinn Tran726b8542017-01-19 22:28:00 -0800171 if (!vha->flags.online)
172 goto done;
173
174 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
175 (fcport->fw_login_state == DSC_LS_PLOGI_COMP) ||
176 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
177 goto done;
178
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800179 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700180 if (!sp)
181 goto done;
182
Quinn Tran726b8542017-01-19 22:28:00 -0800183 fcport->flags |= FCF_ASYNC_SENT;
184 fcport->logout_completed = 0;
185
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800186 sp->type = SRB_LOGIN_CMD;
187 sp->name = "login";
188 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
189
190 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700191 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800192 sp->done = qla2x00_async_login_sp_done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700193 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700194 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700195 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700196 rval = qla2x00_start_sp(sp);
Chad Dupuis080c9512016-01-27 12:03:37 -0500197 if (rval != QLA_SUCCESS) {
198 fcport->flags &= ~FCF_ASYNC_SENT;
199 fcport->flags |= FCF_LOGIN_NEEDED;
200 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700201 goto done_free_sp;
Chad Dupuis080c9512016-01-27 12:03:37 -0500202 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700203
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700204 ql_dbg(ql_dbg_disc, vha, 0x2072,
Quinn Tran726b8542017-01-19 22:28:00 -0800205 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
206 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800207 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
208 fcport->login_retry);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700209 return rval;
210
211done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800212 sp->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700213done:
Quinn Tran726b8542017-01-19 22:28:00 -0800214 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700215 return rval;
216}
217
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700218static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800219qla2x00_async_logout_sp_done(void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700220{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800221 srb_t *sp = ptr;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800222 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700223
Quinn Tran726b8542017-01-19 22:28:00 -0800224 sp->fcport->flags &= ~FCF_ASYNC_SENT;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800225 if (!test_bit(UNLOADING, &sp->vha->dpc_flags))
226 qla2x00_post_async_logout_done_work(sp->vha, sp->fcport,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800227 lio->u.logio.data);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800228 sp->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700229}
230
Andrew Vasquezac280b62009-08-20 11:06:05 -0700231int
232qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
233{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700234 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700235 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700236 int rval;
237
238 rval = QLA_FUNCTION_FAILED;
Quinn Tran726b8542017-01-19 22:28:00 -0800239 fcport->flags |= FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800240 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700241 if (!sp)
242 goto done;
243
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800244 sp->type = SRB_LOGOUT_CMD;
245 sp->name = "logout";
246 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
247
248 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700249 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800250 sp->done = qla2x00_async_logout_sp_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700251 rval = qla2x00_start_sp(sp);
252 if (rval != QLA_SUCCESS)
253 goto done_free_sp;
254
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700255 ql_dbg(ql_dbg_disc, vha, 0x2070,
Quinn Tran726b8542017-01-19 22:28:00 -0800256 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
Chad Dupuiscfb09192011-11-18 09:03:07 -0800257 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
Quinn Tran726b8542017-01-19 22:28:00 -0800258 fcport->d_id.b.area, fcport->d_id.b.al_pa,
259 fcport->port_name);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700260 return rval;
261
262done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800263 sp->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700264done:
Quinn Tran726b8542017-01-19 22:28:00 -0800265 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700266 return rval;
267}
268
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700269static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800270qla2x00_async_adisc_sp_done(void *ptr, int res)
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700271{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800272 srb_t *sp = ptr;
273 struct scsi_qla_host *vha = sp->vha;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800274 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700275
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800276 if (!test_bit(UNLOADING, &vha->dpc_flags))
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800277 qla2x00_post_async_adisc_done_work(sp->vha, sp->fcport,
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800278 lio->u.logio.data);
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800279 sp->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700280}
281
282int
283qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
284 uint16_t *data)
285{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700286 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700287 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700288 int rval;
289
290 rval = QLA_FUNCTION_FAILED;
Quinn Tran726b8542017-01-19 22:28:00 -0800291 fcport->flags |= FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800292 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700293 if (!sp)
294 goto done;
295
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800296 sp->type = SRB_ADISC_CMD;
297 sp->name = "adisc";
298 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
299
300 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700301 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800302 sp->done = qla2x00_async_adisc_sp_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700303 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700304 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700305 rval = qla2x00_start_sp(sp);
306 if (rval != QLA_SUCCESS)
307 goto done_free_sp;
308
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700309 ql_dbg(ql_dbg_disc, vha, 0x206f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800310 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
311 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
312 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700313 return rval;
314
315done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800316 sp->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700317done:
Quinn Tran726b8542017-01-19 22:28:00 -0800318 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700319 return rval;
320}
321
Quinn Tran726b8542017-01-19 22:28:00 -0800322static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
323 struct event_arg *ea)
324{
325 fc_port_t *fcport, *conflict_fcport;
326 struct get_name_list_extended *e;
327 u16 i, n, found = 0, loop_id;
328 port_id_t id;
329 u64 wwn;
330 u8 opt = 0;
331
332 fcport = ea->fcport;
333
334 if (ea->rc) { /* rval */
335 if (fcport->login_retry == 0) {
336 fcport->login_retry = vha->hw->login_retry_count;
337 ql_dbg(ql_dbg_disc, vha, 0xffff,
338 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
339 fcport->port_name, fcport->login_retry);
340 }
341 return;
342 }
343
344 if (fcport->last_rscn_gen != fcport->rscn_gen) {
345 ql_dbg(ql_dbg_disc, vha, 0xffff,
346 "%s %8phC rscn gen changed rscn %d|%d \n",
347 __func__, fcport->port_name,
348 fcport->last_rscn_gen, fcport->rscn_gen);
349 qla24xx_post_gidpn_work(vha, fcport);
350 return;
351 } else if (fcport->last_login_gen != fcport->login_gen) {
352 ql_dbg(ql_dbg_disc, vha, 0xffff,
353 "%s %8phC login gen changed login %d|%d \n",
354 __func__, fcport->port_name,
355 fcport->last_login_gen, fcport->login_gen);
356 return;
357 }
358
359 n = ea->data[0] / sizeof(struct get_name_list_extended);
360
361 ql_dbg(ql_dbg_disc, vha, 0xffff,
362 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
363 __func__, __LINE__, fcport->port_name, n,
364 fcport->d_id.b.domain, fcport->d_id.b.area,
365 fcport->d_id.b.al_pa, fcport->loop_id);
366
367 for (i = 0; i < n; i++) {
368 e = &vha->gnl.l[i];
369 wwn = wwn_to_u64(e->port_name);
370
371 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
372 continue;
373
374 found = 1;
375 id.b.domain = e->port_id[2];
376 id.b.area = e->port_id[1];
377 id.b.al_pa = e->port_id[0];
378 id.b.rsvd_1 = 0;
379
380 loop_id = le16_to_cpu(e->nport_handle);
381 loop_id = (loop_id & 0x7fff);
382
383 ql_dbg(ql_dbg_disc, vha, 0xffff,
384 "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
385 __func__, fcport->port_name,
386 e->current_login_state, fcport->fw_login_state,
387 id.b.domain, id.b.area, id.b.al_pa,
388 fcport->d_id.b.domain, fcport->d_id.b.area,
389 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
390
391 if ((id.b24 != fcport->d_id.b24) ||
392 ((fcport->loop_id != FC_NO_LOOP_ID) &&
393 (fcport->loop_id != loop_id))) {
394 ql_dbg(ql_dbg_disc, vha, 0xffff,
395 "%s %d %8phC post del sess\n",
396 __func__, __LINE__, fcport->port_name);
397 qlt_schedule_sess_for_deletion(fcport, 1);
398 return;
399 }
400
401 fcport->loop_id = loop_id;
402
403 wwn = wwn_to_u64(fcport->port_name);
404 qlt_find_sess_invalidate_other(vha, wwn,
405 id, loop_id, &conflict_fcport);
406
407 if (conflict_fcport) {
408 /*
409 * Another share fcport share the same loop_id &
410 * nport id. Conflict fcport needs to finish
411 * cleanup before this fcport can proceed to login.
412 */
413 conflict_fcport->conflict = fcport;
414 fcport->login_pause = 1;
415 }
416
417 switch (e->current_login_state) {
418 case DSC_LS_PRLI_COMP:
419 ql_dbg(ql_dbg_disc, vha, 0xffff,
420 "%s %d %8phC post gpdb\n",
421 __func__, __LINE__, fcport->port_name);
422 opt = PDO_FORCE_ADISC;
423 qla24xx_post_gpdb_work(vha, fcport, opt);
424 break;
425
426 case DSC_LS_PORT_UNAVAIL:
427 default:
428 if (fcport->loop_id == FC_NO_LOOP_ID) {
429 qla2x00_find_new_loop_id(vha, fcport);
430 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
431 }
432 ql_dbg(ql_dbg_disc, vha, 0xffff,
433 "%s %d %8phC \n",
434 __func__, __LINE__, fcport->port_name);
435 qla24xx_fcport_handle_login(vha, fcport);
436 break;
437 }
438 }
439
440 if (!found) {
441 /* fw has no record of this port */
442 if (fcport->loop_id == FC_NO_LOOP_ID) {
443 qla2x00_find_new_loop_id(vha, fcport);
444 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
445 } else {
446 for (i = 0; i < n; i++) {
447 e = &vha->gnl.l[i];
448 id.b.domain = e->port_id[0];
449 id.b.area = e->port_id[1];
450 id.b.al_pa = e->port_id[2];
451 id.b.rsvd_1 = 0;
452 loop_id = le16_to_cpu(e->nport_handle);
453
454 if (fcport->d_id.b24 == id.b24) {
455 conflict_fcport =
456 qla2x00_find_fcport_by_wwpn(vha,
457 e->port_name, 0);
458
459 ql_dbg(ql_dbg_disc, vha, 0xffff,
460 "%s %d %8phC post del sess\n",
461 __func__, __LINE__,
462 conflict_fcport->port_name);
463 qlt_schedule_sess_for_deletion
464 (conflict_fcport, 1);
465 }
466
467 if (fcport->loop_id == loop_id) {
468 /* FW already picked this loop id for another fcport */
469 qla2x00_find_new_loop_id(vha, fcport);
470 }
471 }
472 }
473 qla24xx_fcport_handle_login(vha, fcport);
474 }
475} /* gnl_event */
476
477static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800478qla24xx_async_gnl_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -0800479{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800480 struct srb *sp = s;
481 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -0800482 unsigned long flags;
483 struct fc_port *fcport = NULL, *tf;
484 u16 i, n = 0, loop_id;
485 struct event_arg ea;
486 struct get_name_list_extended *e;
487 u64 wwn;
488 struct list_head h;
489
490 ql_dbg(ql_dbg_disc, vha, 0xffff,
491 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
492 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
493 sp->u.iocb_cmd.u.mbx.in_mb[2]);
494
495 memset(&ea, 0, sizeof(ea));
496 ea.sp = sp;
497 ea.rc = res;
498 ea.event = FCME_GNL_DONE;
499
500 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
501 sizeof(struct get_name_list_extended)) {
502 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
503 sizeof(struct get_name_list_extended);
504 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
505 }
506
507 for (i = 0; i < n; i++) {
508 e = &vha->gnl.l[i];
509 loop_id = le16_to_cpu(e->nport_handle);
510 /* mask out reserve bit */
511 loop_id = (loop_id & 0x7fff);
512 set_bit(loop_id, vha->hw->loop_id_map);
513 wwn = wwn_to_u64(e->port_name);
514
515 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0xffff,
516 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
517 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
518 e->port_id[0], e->current_login_state, e->last_login_state,
519 (loop_id & 0x7fff));
520 }
521
522 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
523 vha->gnl.sent = 0;
524
525 INIT_LIST_HEAD(&h);
526 fcport = tf = NULL;
527 if (!list_empty(&vha->gnl.fcports))
528 list_splice_init(&vha->gnl.fcports, &h);
529
530 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
531 list_del_init(&fcport->gnl_entry);
532 fcport->flags &= ~FCF_ASYNC_SENT;
533 ea.fcport = fcport;
534
535 qla2x00_fcport_event_handler(vha, &ea);
536 }
537
538 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
539
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800540 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800541}
542
543int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
544{
545 srb_t *sp;
546 struct srb_iocb *mbx;
547 int rval = QLA_FUNCTION_FAILED;
548 unsigned long flags;
549 u16 *mb;
550
551 if (!vha->flags.online)
552 goto done;
553
554 ql_dbg(ql_dbg_disc, vha, 0xffff,
555 "Async-gnlist WWPN %8phC \n", fcport->port_name);
556
557 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
558 fcport->flags |= FCF_ASYNC_SENT;
559 fcport->disc_state = DSC_GNL;
560 fcport->last_rscn_gen = fcport->rscn_gen;
561 fcport->last_login_gen = fcport->login_gen;
562
563 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
564 if (vha->gnl.sent) {
565 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
566 rval = QLA_SUCCESS;
567 goto done;
568 }
569 vha->gnl.sent = 1;
570 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
571
572 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
573 if (!sp)
574 goto done;
575 sp->type = SRB_MB_IOCB;
576 sp->name = "gnlist";
577 sp->gen1 = fcport->rscn_gen;
578 sp->gen2 = fcport->login_gen;
579
580 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
581
582 mb = sp->u.iocb_cmd.u.mbx.out_mb;
583 mb[0] = MBC_PORT_NODE_NAME_LIST;
584 mb[1] = BIT_2 | BIT_3;
585 mb[2] = MSW(vha->gnl.ldma);
586 mb[3] = LSW(vha->gnl.ldma);
587 mb[6] = MSW(MSD(vha->gnl.ldma));
588 mb[7] = LSW(MSD(vha->gnl.ldma));
589 mb[8] = vha->gnl.size;
590 mb[9] = vha->vp_idx;
591
592 mbx = &sp->u.iocb_cmd;
593 mbx->timeout = qla2x00_async_iocb_timeout;
594
595 sp->done = qla24xx_async_gnl_sp_done;
596
597 rval = qla2x00_start_sp(sp);
598 if (rval != QLA_SUCCESS)
599 goto done_free_sp;
600
601 ql_dbg(ql_dbg_disc, vha, 0xffff,
602 "Async-%s - OUT WWPN %8phC hndl %x\n",
603 sp->name, fcport->port_name, sp->handle);
604
605 return rval;
606
607done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800608 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800609done:
610 fcport->flags &= ~FCF_ASYNC_SENT;
611 return rval;
612}
613
614int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
615{
616 struct qla_work_evt *e;
617
618 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
619 if (!e)
620 return QLA_FUNCTION_FAILED;
621
622 e->u.fcport.fcport = fcport;
623 return qla2x00_post_work(vha, e);
624}
625
626static
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800627void qla24xx_async_gpdb_sp_done(void *s, int res)
Quinn Tran726b8542017-01-19 22:28:00 -0800628{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800629 struct srb *sp = s;
630 struct scsi_qla_host *vha = sp->vha;
Quinn Tran726b8542017-01-19 22:28:00 -0800631 struct qla_hw_data *ha = vha->hw;
632 uint64_t zero = 0;
633 struct port_database_24xx *pd;
634 fc_port_t *fcport = sp->fcport;
635 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
636 int rval = QLA_SUCCESS;
637 struct event_arg ea;
638
639 ql_dbg(ql_dbg_disc, vha, 0xffff,
640 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
641 sp->name, res, fcport->port_name, mb[1], mb[2]);
642
643 fcport->flags &= ~FCF_ASYNC_SENT;
644
645 if (res) {
646 rval = res;
647 goto gpd_error_out;
648 }
649
650 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
651
652 /* Check for logged in state. */
653 if (pd->current_login_state != PDS_PRLI_COMPLETE &&
654 pd->last_login_state != PDS_PRLI_COMPLETE) {
655 ql_dbg(ql_dbg_mbx, vha, 0xffff,
656 "Unable to verify login-state (%x/%x) for "
657 "loop_id %x.\n", pd->current_login_state,
658 pd->last_login_state, fcport->loop_id);
659 rval = QLA_FUNCTION_FAILED;
660 goto gpd_error_out;
661 }
662
663 if (fcport->loop_id == FC_NO_LOOP_ID ||
664 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
665 memcmp(fcport->port_name, pd->port_name, 8))) {
666 /* We lost the device mid way. */
667 rval = QLA_NOT_LOGGED_IN;
668 goto gpd_error_out;
669 }
670
671 /* Names are little-endian. */
672 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
673
674 /* Get port_id of device. */
675 fcport->d_id.b.domain = pd->port_id[0];
676 fcport->d_id.b.area = pd->port_id[1];
677 fcport->d_id.b.al_pa = pd->port_id[2];
678 fcport->d_id.b.rsvd_1 = 0;
679
680 /* If not target must be initiator or unknown type. */
681 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
682 fcport->port_type = FCT_INITIATOR;
683 else
684 fcport->port_type = FCT_TARGET;
685
686 /* Passback COS information. */
687 fcport->supported_classes = (pd->flags & PDF_CLASS_2) ?
688 FC_COS_CLASS2 : FC_COS_CLASS3;
689
690 if (pd->prli_svc_param_word_3[0] & BIT_7) {
691 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
692 fcport->conf_compl_supported = 1;
693 }
694
695gpd_error_out:
696 memset(&ea, 0, sizeof(ea));
697 ea.event = FCME_GPDB_DONE;
698 ea.rc = rval;
699 ea.fcport = fcport;
700 ea.sp = sp;
701
702 qla2x00_fcport_event_handler(vha, &ea);
703
704 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
705 sp->u.iocb_cmd.u.mbx.in_dma);
706
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800707 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800708}
709
710static int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport,
711 u8 opt)
712{
713 struct qla_work_evt *e;
714
715 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
716 if (!e)
717 return QLA_FUNCTION_FAILED;
718
719 e->u.fcport.fcport = fcport;
720 e->u.fcport.opt = opt;
721 return qla2x00_post_work(vha, e);
722}
723
724int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
725{
726 srb_t *sp;
727 struct srb_iocb *mbx;
728 int rval = QLA_FUNCTION_FAILED;
729 u16 *mb;
730 dma_addr_t pd_dma;
731 struct port_database_24xx *pd;
732 struct qla_hw_data *ha = vha->hw;
733
734 if (!vha->flags.online)
735 goto done;
736
737 fcport->flags |= FCF_ASYNC_SENT;
738 fcport->disc_state = DSC_GPDB;
739
740 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
741 if (!sp)
742 goto done;
743
744 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
745 if (pd == NULL) {
746 ql_log(ql_log_warn, vha, 0xffff,
747 "Failed to allocate port database structure.\n");
748 goto done_free_sp;
749 }
750 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
751
752 sp->type = SRB_MB_IOCB;
753 sp->name = "gpdb";
754 sp->gen1 = fcport->rscn_gen;
755 sp->gen2 = fcport->login_gen;
756 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
757
758 mb = sp->u.iocb_cmd.u.mbx.out_mb;
759 mb[0] = MBC_GET_PORT_DATABASE;
760 mb[1] = fcport->loop_id;
761 mb[2] = MSW(pd_dma);
762 mb[3] = LSW(pd_dma);
763 mb[6] = MSW(MSD(pd_dma));
764 mb[7] = LSW(MSD(pd_dma));
765 mb[9] = vha->vp_idx;
766 mb[10] = opt;
767
768 mbx = &sp->u.iocb_cmd;
769 mbx->timeout = qla2x00_async_iocb_timeout;
770 mbx->u.mbx.in = (void *)pd;
771 mbx->u.mbx.in_dma = pd_dma;
772
773 sp->done = qla24xx_async_gpdb_sp_done;
774
775 rval = qla2x00_start_sp(sp);
776 if (rval != QLA_SUCCESS)
777 goto done_free_sp;
778
779 ql_dbg(ql_dbg_disc, vha, 0xffff,
780 "Async-%s %8phC hndl %x opt %x\n",
781 sp->name, fcport->port_name, sp->handle, opt);
782
783 return rval;
784
785done_free_sp:
786 if (pd)
787 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
788
Joe Carnuccio25ff6af2017-01-19 22:28:04 -0800789 sp->free(sp);
Quinn Tran726b8542017-01-19 22:28:00 -0800790done:
791 fcport->flags &= ~FCF_ASYNC_SENT;
792 qla24xx_post_gpdb_work(vha, fcport, opt);
793 return rval;
794}
795
796static
797void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
798{
799 int rval = ea->rc;
800 fc_port_t *fcport = ea->fcport;
801 unsigned long flags;
802
803 fcport->flags &= ~FCF_ASYNC_SENT;
804
805 ql_dbg(ql_dbg_disc, vha, 0xffff,
806 "%s %8phC DS %d LS %d rval %d\n", __func__, fcport->port_name,
807 fcport->disc_state, fcport->fw_login_state, rval);
808
809 if (ea->sp->gen2 != fcport->login_gen) {
810 /* target side must have changed it. */
811 ql_dbg(ql_dbg_disc, vha, 0xffff,
812 "%s %8phC generation changed rscn %d|%d login %d|%d \n",
813 __func__, fcport->port_name, fcport->last_rscn_gen,
814 fcport->rscn_gen, fcport->last_login_gen,
815 fcport->login_gen);
816 return;
817 } else if (ea->sp->gen1 != fcport->rscn_gen) {
818 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC post gidpn\n",
819 __func__, __LINE__, fcport->port_name);
820 qla24xx_post_gidpn_work(vha, fcport);
821 return;
822 }
823
824 if (rval != QLA_SUCCESS) {
825 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC post del sess\n",
826 __func__, __LINE__, fcport->port_name);
827 qlt_schedule_sess_for_deletion_lock(fcport);
828 return;
829 }
830
831 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
832 ea->fcport->login_gen++;
833 ea->fcport->deleted = 0;
834 ea->fcport->logout_on_delete = 1;
835
836 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
837 vha->fcport_count++;
838 ea->fcport->login_succ = 1;
839
840 if (!IS_IIDMA_CAPABLE(vha->hw) ||
841 !vha->hw->flags.gpsc_supported) {
842 ql_dbg(ql_dbg_disc, vha, 0xffff,
843 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
844 __func__, __LINE__, fcport->port_name,
845 vha->fcport_count);
846
847 qla24xx_post_upd_fcport_work(vha, fcport);
848 } else {
849 ql_dbg(ql_dbg_disc, vha, 0xffff,
850 "%s %d %8phC post gpsc fcp_cnt %d\n",
851 __func__, __LINE__, fcport->port_name,
852 vha->fcport_count);
853
854 qla24xx_post_gpsc_work(vha, fcport);
855 }
856 }
857 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
858} /* gpdb event */
859
860int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
861{
862 if (fcport->login_retry == 0)
863 return 0;
864
865 if (fcport->scan_state != QLA_FCPORT_FOUND)
866 return 0;
867
868 ql_dbg(ql_dbg_disc, vha, 0xffff,
869 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d|%d retry %d lid %d\n",
870 __func__, fcport->port_name, fcport->disc_state,
871 fcport->fw_login_state, fcport->login_pause, fcport->flags,
872 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
873 fcport->last_login_gen, fcport->login_gen, fcport->login_retry,
874 fcport->loop_id);
875
876 fcport->login_retry--;
877
878 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
Quinn Tran726b8542017-01-19 22:28:00 -0800879 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
880 return 0;
881
Quinn Tran5b334692017-03-15 09:48:48 -0700882 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
883 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline))
884 return 0;
885 }
886
Quinn Tran726b8542017-01-19 22:28:00 -0800887 /* for pure Target Mode. Login will not be initiated */
888 if (vha->host->active_mode == MODE_TARGET)
889 return 0;
890
891 if (fcport->flags & FCF_ASYNC_SENT) {
892 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
893 return 0;
894 }
895
896 switch (fcport->disc_state) {
897 case DSC_DELETED:
898 if (fcport->loop_id == FC_NO_LOOP_ID) {
899 ql_dbg(ql_dbg_disc, vha, 0xffff,
900 "%s %d %8phC post gnl\n",
901 __func__, __LINE__, fcport->port_name);
902 qla24xx_async_gnl(vha, fcport);
903 } else {
904 ql_dbg(ql_dbg_disc, vha, 0xffff,
905 "%s %d %8phC post login\n",
906 __func__, __LINE__, fcport->port_name);
907 fcport->disc_state = DSC_LOGIN_PEND;
908 qla2x00_post_async_login_work(vha, fcport, NULL);
909 }
910 break;
911
912 case DSC_GNL:
913 if (fcport->login_pause) {
914 fcport->last_rscn_gen = fcport->rscn_gen;
915 fcport->last_login_gen = fcport->login_gen;
916 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
917 break;
918 }
919
920 if (fcport->flags & FCF_FCP2_DEVICE) {
921 u8 opt = PDO_FORCE_ADISC;
922
923 ql_dbg(ql_dbg_disc, vha, 0xffff,
924 "%s %d %8phC post gpdb\n",
925 __func__, __LINE__, fcport->port_name);
926
927 fcport->disc_state = DSC_GPDB;
928 qla24xx_post_gpdb_work(vha, fcport, opt);
929 } else {
930 ql_dbg(ql_dbg_disc, vha, 0xffff,
931 "%s %d %8phC post login \n",
932 __func__, __LINE__, fcport->port_name);
933 fcport->disc_state = DSC_LOGIN_PEND;
934 qla2x00_post_async_login_work(vha, fcport, NULL);
935 }
936
937 break;
938
939 case DSC_LOGIN_FAILED:
940 ql_dbg(ql_dbg_disc, vha, 0xffff,
941 "%s %d %8phC post gidpn \n",
942 __func__, __LINE__, fcport->port_name);
943
944 qla24xx_post_gidpn_work(vha, fcport);
945 break;
946
947 case DSC_LOGIN_COMPLETE:
948 /* recheck login state */
949 ql_dbg(ql_dbg_disc, vha, 0xffff,
950 "%s %d %8phC post gpdb \n",
951 __func__, __LINE__, fcport->port_name);
952
953 qla24xx_post_gpdb_work(vha, fcport, PDO_FORCE_ADISC);
954 break;
955
956 default:
957 break;
958 }
959
960 return 0;
961}
962
963static
964void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea)
965{
966 fcport->rscn_gen++;
967
968 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
969 "%s %8phC DS %d LS %d\n",
970 __func__, fcport->port_name, fcport->disc_state,
971 fcport->fw_login_state);
972
973 if (fcport->flags & FCF_ASYNC_SENT)
974 return;
975
976 switch (fcport->disc_state) {
977 case DSC_DELETED:
978 case DSC_LOGIN_COMPLETE:
979 qla24xx_post_gidpn_work(fcport->vha, fcport);
980 break;
981
982 default:
983 break;
984 }
985}
986
987int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
988 u8 *port_name, void *pla)
989{
990 struct qla_work_evt *e;
991 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
992 if (!e)
993 return QLA_FUNCTION_FAILED;
994
995 e->u.new_sess.id = *id;
996 e->u.new_sess.pla = pla;
997 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
998
999 return qla2x00_post_work(vha, e);
1000}
1001
1002static
1003int qla24xx_handle_delete_done_event(scsi_qla_host_t *vha,
1004 struct event_arg *ea)
1005{
1006 fc_port_t *fcport = ea->fcport;
1007
1008 if (test_bit(UNLOADING, &vha->dpc_flags))
1009 return 0;
1010
1011 switch (vha->host->active_mode) {
1012 case MODE_INITIATOR:
1013 case MODE_DUAL:
1014 if (fcport->scan_state == QLA_FCPORT_FOUND)
1015 qla24xx_fcport_handle_login(vha, fcport);
1016 break;
1017
1018 case MODE_TARGET:
1019 default:
1020 /* no-op */
1021 break;
1022 }
1023
1024 return 0;
1025}
1026
1027static
1028void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1029 struct event_arg *ea)
1030{
1031 fc_port_t *fcport = ea->fcport;
1032
1033 if (fcport->scan_state != QLA_FCPORT_FOUND) {
1034 fcport->login_retry++;
1035 return;
1036 }
1037
1038 ql_dbg(ql_dbg_disc, vha, 0xffff,
1039 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1040 __func__, fcport->port_name, fcport->disc_state,
1041 fcport->fw_login_state, fcport->login_pause,
1042 fcport->deleted, fcport->conflict,
1043 fcport->last_rscn_gen, fcport->rscn_gen,
1044 fcport->last_login_gen, fcport->login_gen,
1045 fcport->flags);
1046
1047 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
Quinn Tran726b8542017-01-19 22:28:00 -08001048 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1049 return;
1050
Quinn Tran5b334692017-03-15 09:48:48 -07001051 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1052 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline))
1053 return;
1054 }
1055
Quinn Tran726b8542017-01-19 22:28:00 -08001056 if (fcport->flags & FCF_ASYNC_SENT) {
1057 fcport->login_retry++;
1058 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1059 return;
1060 }
1061
1062 if (fcport->disc_state == DSC_DELETE_PEND) {
1063 fcport->login_retry++;
1064 return;
1065 }
1066
1067 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1068 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC post gidpn\n",
1069 __func__, __LINE__, fcport->port_name);
1070
1071 qla24xx_async_gidpn(vha, fcport);
1072 return;
1073 }
1074
1075 qla24xx_fcport_handle_login(vha, fcport);
1076}
1077
Quinn Tran41dc5292017-01-19 22:28:03 -08001078void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
Quinn Tran726b8542017-01-19 22:28:00 -08001079{
Quinn Tran41dc5292017-01-19 22:28:03 -08001080 fc_port_t *fcport, *f, *tf;
1081 uint32_t id = 0, mask, rid;
Quinn Tran726b8542017-01-19 22:28:00 -08001082 int rc;
1083
1084 switch (ea->event) {
1085 case FCME_RELOGIN:
1086 if (test_bit(UNLOADING, &vha->dpc_flags))
1087 return;
1088
1089 qla24xx_handle_relogin_event(vha, ea);
1090 break;
1091 case FCME_RSCN:
1092 if (test_bit(UNLOADING, &vha->dpc_flags))
1093 return;
Quinn Tran41dc5292017-01-19 22:28:03 -08001094 switch (ea->id.b.rsvd_1) {
1095 case RSCN_PORT_ADDR:
1096 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1097 if (!fcport) {
1098 /* cable moved */
1099 rc = qla24xx_post_gpnid_work(vha, &ea->id);
1100 if (rc) {
1101 ql_log(ql_log_warn, vha, 0xffff,
1102 "RSCN GPNID work failed %02x%02x%02x\n",
1103 ea->id.b.domain, ea->id.b.area,
1104 ea->id.b.al_pa);
1105 }
1106 } else {
1107 ea->fcport = fcport;
1108 qla24xx_handle_rscn_event(fcport, ea);
Quinn Tran726b8542017-01-19 22:28:00 -08001109 }
Quinn Tran41dc5292017-01-19 22:28:03 -08001110 break;
1111 case RSCN_AREA_ADDR:
1112 case RSCN_DOM_ADDR:
1113 if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) {
1114 mask = 0xffff00;
1115 ql_log(ql_dbg_async, vha, 0xffff,
1116 "RSCN: Area 0x%06x was affected\n",
1117 ea->id.b24);
1118 } else {
1119 mask = 0xff0000;
1120 ql_log(ql_dbg_async, vha, 0xffff,
1121 "RSCN: Domain 0x%06x was affected\n",
1122 ea->id.b24);
1123 }
1124
1125 rid = ea->id.b24 & mask;
1126 list_for_each_entry_safe(f, tf, &vha->vp_fcports,
1127 list) {
1128 id = f->d_id.b24 & mask;
1129 if (rid == id) {
1130 ea->fcport = f;
1131 qla24xx_handle_rscn_event(f, ea);
1132 }
1133 }
1134 break;
1135 case RSCN_FAB_ADDR:
1136 default:
1137 ql_log(ql_log_warn, vha, 0xffff,
1138 "RSCN: Fabric was affected. Addr format %d\n",
1139 ea->id.b.rsvd_1);
1140 qla2x00_mark_all_devices_lost(vha, 1);
1141 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1142 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Quinn Tran726b8542017-01-19 22:28:00 -08001143 }
1144 break;
1145 case FCME_GIDPN_DONE:
1146 qla24xx_handle_gidpn_event(vha, ea);
1147 break;
1148 case FCME_GNL_DONE:
1149 qla24xx_handle_gnl_done_event(vha, ea);
1150 break;
1151 case FCME_GPSC_DONE:
1152 qla24xx_post_upd_fcport_work(vha, ea->fcport);
1153 break;
1154 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1155 qla24xx_handle_plogi_done_event(vha, ea);
1156 break;
1157 case FCME_GPDB_DONE:
1158 qla24xx_handle_gpdb_event(vha, ea);
1159 break;
1160 case FCME_GPNID_DONE:
1161 qla24xx_handle_gpnid_event(vha, ea);
1162 break;
1163 case FCME_DELETE_DONE:
1164 qla24xx_handle_delete_done_event(vha, ea);
1165 break;
1166 default:
1167 BUG_ON(1);
1168 break;
1169 }
1170}
1171
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001172static void
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001173qla2x00_tmf_iocb_timeout(void *data)
1174{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001175 srb_t *sp = data;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001176 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1177
1178 tmf->u.tmf.comp_status = CS_TIMEOUT;
1179 complete(&tmf->u.tmf.comp);
1180}
1181
1182static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001183qla2x00_tmf_sp_done(void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001184{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001185 srb_t *sp = ptr;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001186 struct srb_iocb *tmf = &sp->u.iocb_cmd;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001187
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001188 complete(&tmf->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001189}
1190
1191int
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001192qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001193 uint32_t tag)
1194{
1195 struct scsi_qla_host *vha = fcport->vha;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001196 struct srb_iocb *tm_iocb;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001197 srb_t *sp;
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001198 int rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001199
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001200 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001201 if (!sp)
1202 goto done;
1203
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001204 tm_iocb = &sp->u.iocb_cmd;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001205 sp->type = SRB_TM_CMD;
1206 sp->name = "tmf";
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001207 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1208 tm_iocb->u.tmf.flags = flags;
1209 tm_iocb->u.tmf.lun = lun;
1210 tm_iocb->u.tmf.data = tag;
1211 sp->done = qla2x00_tmf_sp_done;
1212 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1213 init_completion(&tm_iocb->u.tmf.comp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001214
1215 rval = qla2x00_start_sp(sp);
1216 if (rval != QLA_SUCCESS)
1217 goto done_free_sp;
1218
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001219 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001220 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1221 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1222 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Armen Baloyanfaef62d2014-02-26 04:15:17 -05001223
1224 wait_for_completion(&tm_iocb->u.tmf.comp);
1225
1226 rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
1227 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1228
1229 if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
1230 ql_dbg(ql_dbg_taskm, vha, 0x8030,
1231 "TM IOCB failed (%x).\n", rval);
1232 }
1233
1234 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1235 flags = tm_iocb->u.tmf.flags;
1236 lun = (uint16_t)tm_iocb->u.tmf.lun;
1237
1238 /* Issue Marker IOCB */
1239 qla2x00_marker(vha, vha->hw->req_q_map[0],
1240 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
1241 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1242 }
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001243
1244done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001245 sp->free(sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -07001246done:
1247 return rval;
1248}
1249
Armen Baloyan4440e462014-02-26 04:15:18 -05001250static void
1251qla24xx_abort_iocb_timeout(void *data)
1252{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001253 srb_t *sp = data;
Armen Baloyan4440e462014-02-26 04:15:18 -05001254 struct srb_iocb *abt = &sp->u.iocb_cmd;
1255
1256 abt->u.abt.comp_status = CS_TIMEOUT;
1257 complete(&abt->u.abt.comp);
1258}
1259
1260static void
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001261qla24xx_abort_sp_done(void *ptr, int res)
Armen Baloyan4440e462014-02-26 04:15:18 -05001262{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001263 srb_t *sp = ptr;
Armen Baloyan4440e462014-02-26 04:15:18 -05001264 struct srb_iocb *abt = &sp->u.iocb_cmd;
1265
1266 complete(&abt->u.abt.comp);
1267}
1268
1269static int
1270qla24xx_async_abort_cmd(srb_t *cmd_sp)
1271{
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001272 scsi_qla_host_t *vha = cmd_sp->vha;
Armen Baloyan4440e462014-02-26 04:15:18 -05001273 fc_port_t *fcport = cmd_sp->fcport;
1274 struct srb_iocb *abt_iocb;
1275 srb_t *sp;
1276 int rval = QLA_FUNCTION_FAILED;
1277
1278 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1279 if (!sp)
1280 goto done;
1281
1282 abt_iocb = &sp->u.iocb_cmd;
1283 sp->type = SRB_ABT_CMD;
1284 sp->name = "abort";
1285 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1286 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
1287 sp->done = qla24xx_abort_sp_done;
1288 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
1289 init_completion(&abt_iocb->u.abt.comp);
1290
1291 rval = qla2x00_start_sp(sp);
1292 if (rval != QLA_SUCCESS)
1293 goto done_free_sp;
1294
1295 ql_dbg(ql_dbg_async, vha, 0x507c,
1296 "Abort command issued - hdl=%x, target_id=%x\n",
1297 cmd_sp->handle, fcport->tgt_id);
1298
1299 wait_for_completion(&abt_iocb->u.abt.comp);
1300
1301 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
1302 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1303
1304done_free_sp:
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08001305 sp->free(sp);
Armen Baloyan4440e462014-02-26 04:15:18 -05001306done:
1307 return rval;
1308}
1309
1310int
1311qla24xx_async_abort_command(srb_t *sp)
1312{
1313 unsigned long flags = 0;
1314
1315 uint32_t handle;
1316 fc_port_t *fcport = sp->fcport;
1317 struct scsi_qla_host *vha = fcport->vha;
1318 struct qla_hw_data *ha = vha->hw;
1319 struct req_que *req = vha->req;
1320
1321 spin_lock_irqsave(&ha->hardware_lock, flags);
1322 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1323 if (req->outstanding_cmds[handle] == sp)
1324 break;
1325 }
1326 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1327 if (handle == req->num_outstanding_cmds) {
1328 /* Command not found. */
1329 return QLA_FUNCTION_FAILED;
1330 }
1331 if (sp->type == SRB_FXIOCB_DCMD)
1332 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1333 FXDISC_ABORT_IOCTL);
1334
1335 return qla24xx_async_abort_cmd(sp);
1336}
1337
Quinn Tran726b8542017-01-19 22:28:00 -08001338static void
1339qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001340{
Quinn Tran726b8542017-01-19 22:28:00 -08001341 port_id_t cid; /* conflict Nport id */
Andrew Vasquezac280b62009-08-20 11:06:05 -07001342
Quinn Tran726b8542017-01-19 22:28:00 -08001343 switch (ea->data[0]) {
Andrew Vasquezac280b62009-08-20 11:06:05 -07001344 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -07001345 /*
1346 * Driver must validate login state - If PRLI not complete,
1347 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1348 * requests.
1349 */
Quinn Tran726b8542017-01-19 22:28:00 -08001350 ql_dbg(ql_dbg_disc, vha, 0xffff,
1351 "%s %d %8phC post gpdb\n",
1352 __func__, __LINE__, ea->fcport->port_name);
1353 ea->fcport->chip_reset = vha->hw->chip_reset;
1354 ea->fcport->logout_on_delete = 1;
1355 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001356 break;
1357 case MBS_COMMAND_ERROR:
Quinn Tran726b8542017-01-19 22:28:00 -08001358 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC cmd error %x\n",
1359 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
1360
1361 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1362 ea->fcport->disc_state = DSC_LOGIN_FAILED;
1363 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
Andrew Vasquezac280b62009-08-20 11:06:05 -07001364 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1365 else
Quinn Tran726b8542017-01-19 22:28:00 -08001366 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001367 break;
1368 case MBS_LOOP_ID_USED:
Quinn Tran726b8542017-01-19 22:28:00 -08001369 /* data[1] = IO PARAM 1 = nport ID */
1370 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
1371 cid.b.area = (ea->iop[1] >> 8) & 0xff;
1372 cid.b.al_pa = ea->iop[1] & 0xff;
1373 cid.b.rsvd_1 = 0;
1374
1375 ql_dbg(ql_dbg_disc, vha, 0xffff,
1376 "%s %d %8phC LoopID 0x%x in use post gnl\n",
1377 __func__, __LINE__, ea->fcport->port_name,
1378 ea->fcport->loop_id);
1379
1380 if (IS_SW_RESV_ADDR(cid)) {
1381 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1382 ea->fcport->loop_id = FC_NO_LOOP_ID;
1383 } else {
1384 qla2x00_clear_loop_id(ea->fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001385 }
Quinn Tran726b8542017-01-19 22:28:00 -08001386 qla24xx_post_gnl_work(vha, ea->fcport);
1387 break;
1388 case MBS_PORT_ID_USED:
1389 ql_dbg(ql_dbg_disc, vha, 0xffff,
1390 "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n",
1391 __func__, __LINE__, ea->fcport->port_name,
1392 ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area,
1393 ea->fcport->d_id.b.al_pa);
1394
1395 qla2x00_clear_loop_id(ea->fcport);
1396 qla24xx_post_gidpn_work(vha, ea->fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -07001397 break;
1398 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001399 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001400}
1401
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001402void
Andrew Vasquezac280b62009-08-20 11:06:05 -07001403qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1404 uint16_t *data)
1405{
Quinn Tran726b8542017-01-19 22:28:00 -08001406 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Alexei Potashnika6ca8872015-07-14 16:00:44 -04001407 qlt_logo_completion_handler(fcport, data[0]);
Quinn Tran726b8542017-01-19 22:28:00 -08001408 fcport->login_gen++;
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001409 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -07001410}
1411
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001412void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001413qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1414 uint16_t *data)
1415{
1416 if (data[0] == MBS_COMMAND_COMPLETE) {
1417 qla2x00_update_fcport(vha, fcport);
1418
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001419 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001420 }
1421
1422 /* Retry login. */
1423 fcport->flags &= ~FCF_ASYNC_SENT;
1424 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
1425 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1426 else
Andrew Vasquez80d79442011-03-30 11:46:17 -07001427 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001428
Madhuranath Iyengar49163922010-05-04 15:01:28 -07001429 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07001430}
1431
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432/****************************************************************************/
1433/* QLogic ISP2x00 Hardware Support Functions. */
1434/****************************************************************************/
1435
Saurav Kashyapfa492632012-11-21 02:40:29 -05001436static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001437qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
1438{
1439 int rval = QLA_SUCCESS;
1440 struct qla_hw_data *ha = vha->hw;
1441 uint32_t idc_major_ver, idc_minor_ver;
Saurav Kashyap711aa7f2012-08-22 14:21:15 -04001442 uint16_t config[4];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001443
1444 qla83xx_idc_lock(vha, 0);
1445
1446 /* SV: TODO: Assign initialization timeout from
1447 * flash-info / other param
1448 */
1449 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
1450 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
1451
1452 /* Set our fcoe function presence */
1453 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
1454 ql_dbg(ql_dbg_p3p, vha, 0xb077,
1455 "Error while setting DRV-Presence.\n");
1456 rval = QLA_FUNCTION_FAILED;
1457 goto exit;
1458 }
1459
1460 /* Decide the reset ownership */
1461 qla83xx_reset_ownership(vha);
1462
1463 /*
1464 * On first protocol driver load:
1465 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
1466 * register.
1467 * Others: Check compatibility with current IDC Major version.
1468 */
1469 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
1470 if (ha->flags.nic_core_reset_owner) {
1471 /* Set IDC Major version */
1472 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
1473 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
1474
1475 /* Clearing IDC-Lock-Recovery register */
1476 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
1477 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
1478 /*
1479 * Clear further IDC participation if we are not compatible with
1480 * the current IDC Major Version.
1481 */
1482 ql_log(ql_log_warn, vha, 0xb07d,
1483 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
1484 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
1485 __qla83xx_clear_drv_presence(vha);
1486 rval = QLA_FUNCTION_FAILED;
1487 goto exit;
1488 }
1489 /* Each function sets its supported Minor version. */
1490 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
1491 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
1492 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
1493
Saurav Kashyap711aa7f2012-08-22 14:21:15 -04001494 if (ha->flags.nic_core_reset_owner) {
1495 memset(config, 0, sizeof(config));
1496 if (!qla81xx_get_port_config(vha, config))
1497 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
1498 QLA8XXX_DEV_READY);
1499 }
1500
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001501 rval = qla83xx_idc_state_handler(vha);
1502
1503exit:
1504 qla83xx_idc_unlock(vha, 0);
1505
1506 return rval;
1507}
1508
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509/*
1510* qla2x00_initialize_adapter
1511* Initialize board.
1512*
1513* Input:
1514* ha = adapter block pointer.
1515*
1516* Returns:
1517* 0 = success
1518*/
1519int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001520qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521{
1522 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001523 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001524 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001525
Joe Carnucciofc90ada2016-07-06 11:14:23 -04001526 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
1527 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
1528
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001530 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001531 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001532 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -08001533 ha->flags.pci_channel_io_perm_failure = 0;
1534 ha->flags.eeh_busy = 0;
Joe Carnucciofabbb8d2013-08-27 01:37:40 -04001535 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001536 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1537 atomic_set(&vha->loop_state, LOOP_DOWN);
1538 vha->device_flags = DFLG_NO_CABLE;
1539 vha->dpc_flags = 0;
1540 vha->flags.management_server_logged_in = 0;
1541 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 ha->isp_abort_cnt = 0;
1543 ha->beacon_blink_led = 0;
1544
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001545 set_bit(0, ha->req_qid_map);
1546 set_bit(0, ha->rsp_qid_map);
1547
Chad Dupuiscfb09192011-11-18 09:03:07 -08001548 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001549 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001550 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001552 ql_log(ql_log_warn, vha, 0x0044,
1553 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 return (rval);
1555 }
1556
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001557 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001559 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001560 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001561 ql_log(ql_log_fatal, vha, 0x004f,
1562 "Unable to validate FLASH data.\n");
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001563 return rval;
1564 }
1565
1566 if (IS_QLA8044(ha)) {
1567 qla8044_read_reset_template(vha);
1568
1569 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
1570 * If DONRESET_BIT0 is set, drivers should not set dev_state
1571 * to NEED_RESET. But if NEED_RESET is set, drivers should
1572 * should honor the reset. */
1573 if (ql2xdontresethba == 1)
1574 qla8044_set_idc_dontreset(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -07001575 }
1576
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001577 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -08001578 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001579 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001580
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001581 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001583 if (ha->flags.disable_serdes) {
1584 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001585 ql_log(ql_log_info, vha, 0x0077,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04001586 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001587 return QLA_FUNCTION_FAILED;
1588 }
1589
Chad Dupuiscfb09192011-11-18 09:03:07 -08001590 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001591 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001593 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
1594 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001595 if (rval)
1596 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001597 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001598 if (rval)
1599 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07001601
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001602 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001603 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001604 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001605 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001606 "Unable to configure ISP84XX.\n");
1607 return QLA_FUNCTION_FAILED;
1608 }
1609 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001610
Quinn Tranead03852017-01-19 22:28:01 -08001611 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001612 rval = qla2x00_init_rings(vha);
1613
Lalit Chandivade2533cf62009-03-24 09:08:07 -07001614 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001616 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -07001617 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001618 rval = qla84xx_init_chip(vha);
1619 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001620 ql_log(ql_log_warn, vha, 0x00d4,
1621 "Unable to initialize ISP84XX.\n");
Bart Van Assche8d2b21d2015-06-04 15:58:09 -07001622 qla84xx_put_chip(vha);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08001623 }
1624 }
1625
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04001626 /* Load the NIC Core f/w if we are the first protocol driver. */
1627 if (IS_QLA8031(ha)) {
1628 rval = qla83xx_nic_core_fw_load(vha);
1629 if (rval)
1630 ql_log(ql_log_warn, vha, 0x0124,
1631 "Error in initializing NIC Core f/w.\n");
1632 }
1633
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +05001634 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
1635 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -07001636
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04001637 if (IS_P3P_TYPE(ha))
1638 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
1639 else
1640 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
1641
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 return (rval);
1643}
1644
1645/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001646 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 * @ha: HA context
1648 *
1649 * Returns 0 on success.
1650 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001651int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001652qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001654 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001655 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001656 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001657 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001660 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001663 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1665
Andrew Vasquez737faec2008-10-24 15:13:45 -07001666 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001668 /* Get PCI bus information. */
1669 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07001670 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001671 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1672
1673 return QLA_SUCCESS;
1674}
1675
1676/**
1677 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
1678 * @ha: HA context
1679 *
1680 * Returns 0 on success.
1681 */
1682int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001683qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001684{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001685 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001686 unsigned long flags = 0;
1687 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001688 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001689 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001690
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001691 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001692 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001693
1694 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001695 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001696
1697 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1698 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -07001699 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001700
1701 /*
1702 * If this is a 2300 card and not 2312, reset the
1703 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
1704 * the 2310 also reports itself as a 2300 so we need to get the
1705 * fb revision level -- a 6 indicates it really is a 2300 and
1706 * not a 2310.
1707 */
1708 if (IS_QLA2300(ha)) {
1709 spin_lock_irqsave(&ha->hardware_lock, flags);
1710
1711 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001712 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001713 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07001714 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001715 break;
1716
1717 udelay(10);
1718 }
1719
1720 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001721 WRT_REG_WORD(&reg->ctrl_status, 0x20);
1722 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001723
1724 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001725 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001726
1727 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -07001728 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001729
1730 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001731 WRT_REG_WORD(&reg->ctrl_status, 0x0);
1732 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001733
1734 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07001735 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001736 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07001737 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001738 break;
1739
1740 udelay(10);
1741 }
1742
1743 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1744 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001745
1746 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
1747
Andrew Vasquez737faec2008-10-24 15:13:45 -07001748 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001749
1750 /* Get PCI bus information. */
1751 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -07001752 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001753 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1754
1755 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756}
1757
1758/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001759 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
1760 * @ha: HA context
1761 *
1762 * Returns 0 on success.
1763 */
1764int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001765qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001766{
Andrew Vasqueza157b102007-05-07 07:43:01 -07001767 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001768 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001769 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001770 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001771
1772 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -07001773 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001774
1775 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -07001776 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001777 w &= ~PCI_COMMAND_INTX_DISABLE;
1778 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1779
1780 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
1781
1782 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -07001783 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
1784 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001785
1786 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07001787 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04001788 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001789
Andrew Vasquez737faec2008-10-24 15:13:45 -07001790 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001791
Auke Kok44c10132007-06-08 15:46:36 -07001792 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -08001793
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001794 /* Get PCI bus information. */
1795 spin_lock_irqsave(&ha->hardware_lock, flags);
1796 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
1797 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1798
1799 return QLA_SUCCESS;
1800}
1801
1802/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001803 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
1804 * @ha: HA context
1805 *
1806 * Returns 0 on success.
1807 */
1808int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001809qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001810{
1811 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001812 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001813
1814 pci_set_master(ha->pdev);
1815 pci_try_set_mwi(ha->pdev);
1816
1817 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
1818 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
1819 w &= ~PCI_COMMAND_INTX_DISABLE;
1820 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1821
1822 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -07001823 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -04001824 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001825
Andrew Vasquez737faec2008-10-24 15:13:45 -07001826 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001827
1828 ha->chip_revision = ha->pdev->revision;
1829
1830 return QLA_SUCCESS;
1831}
1832
1833/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 * qla2x00_isp_firmware() - Choose firmware image.
1835 * @ha: HA context
1836 *
1837 * Returns 0 on success.
1838 */
1839static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001840qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841{
1842 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001843 uint16_t loop_id, topo, sw_cap;
1844 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001845 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846
1847 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001848 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
1850 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001851 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852
1853 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001854 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001855 if (rval == QLA_SUCCESS) {
1856 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001857 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001858 &area, &domain, &topo, &sw_cap);
1859 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 }
1861
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001862 if (rval)
1863 ql_dbg(ql_dbg_init, vha, 0x007a,
1864 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865
1866 return (rval);
1867}
1868
1869/**
1870 * qla2x00_reset_chip() - Reset ISP chip.
1871 * @ha: HA context
1872 *
1873 * Returns 0 on success.
1874 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001875void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001876qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877{
1878 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001879 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001880 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 uint16_t cmd;
1883
Andrew Vasquez85880802009-12-15 21:29:46 -08001884 if (unlikely(pci_channel_offline(ha->pdev)))
1885 return;
1886
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001887 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
1889 spin_lock_irqsave(&ha->hardware_lock, flags);
1890
1891 /* Turn off master enable */
1892 cmd = 0;
1893 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
1894 cmd &= ~PCI_COMMAND_MASTER;
1895 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
1896
1897 if (!IS_QLA2100(ha)) {
1898 /* Pause RISC. */
1899 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
1900 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
1901 for (cnt = 0; cnt < 30000; cnt++) {
1902 if ((RD_REG_WORD(&reg->hccr) &
1903 HCCR_RISC_PAUSE) != 0)
1904 break;
1905 udelay(100);
1906 }
1907 } else {
1908 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1909 udelay(10);
1910 }
1911
1912 /* Select FPM registers. */
1913 WRT_REG_WORD(&reg->ctrl_status, 0x20);
1914 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1915
1916 /* FPM Soft Reset. */
1917 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
1918 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
1919
1920 /* Toggle Fpm Reset. */
1921 if (!IS_QLA2200(ha)) {
1922 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
1923 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
1924 }
1925
1926 /* Select frame buffer registers. */
1927 WRT_REG_WORD(&reg->ctrl_status, 0x10);
1928 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1929
1930 /* Reset frame buffer FIFOs. */
1931 if (IS_QLA2200(ha)) {
1932 WRT_FB_CMD_REG(ha, reg, 0xa000);
1933 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
1934 } else {
1935 WRT_FB_CMD_REG(ha, reg, 0x00fc);
1936
1937 /* Read back fb_cmd until zero or 3 seconds max */
1938 for (cnt = 0; cnt < 3000; cnt++) {
1939 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
1940 break;
1941 udelay(100);
1942 }
1943 }
1944
1945 /* Select RISC module registers. */
1946 WRT_REG_WORD(&reg->ctrl_status, 0);
1947 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
1948
1949 /* Reset RISC processor. */
1950 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1951 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1952
1953 /* Release RISC processor. */
1954 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1955 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1956 }
1957
1958 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
1959 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
1960
1961 /* Reset ISP chip. */
1962 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1963
1964 /* Wait for RISC to recover from reset. */
1965 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1966 /*
1967 * It is necessary to for a delay here since the card doesn't
1968 * respond to PCI reads during a reset. On some architectures
1969 * this will result in an MCA.
1970 */
1971 udelay(20);
1972 for (cnt = 30000; cnt; cnt--) {
1973 if ((RD_REG_WORD(&reg->ctrl_status) &
1974 CSR_ISP_SOFT_RESET) == 0)
1975 break;
1976 udelay(100);
1977 }
1978 } else
1979 udelay(10);
1980
1981 /* Reset RISC processor. */
1982 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1983
1984 WRT_REG_WORD(&reg->semaphore, 0);
1985
1986 /* Release RISC processor. */
1987 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1988 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1989
1990 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1991 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -07001992 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994
1995 udelay(100);
1996 }
1997 } else
1998 udelay(100);
1999
2000 /* Turn on master enable */
2001 cmd |= PCI_COMMAND_MASTER;
2002 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2003
2004 /* Disable RISC pause on FPM parity error. */
2005 if (!IS_QLA2100(ha)) {
2006 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
2007 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
2008 }
2009
2010 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2011}
2012
2013/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002014 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2015 *
2016 * Returns 0 on success.
2017 */
Saurav Kashyapfa492632012-11-21 02:40:29 -05002018static int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002019qla81xx_reset_mpi(scsi_qla_host_t *vha)
2020{
2021 uint16_t mb[4] = {0x1010, 0, 1, 0};
2022
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002023 if (!IS_QLA81XX(vha->hw))
2024 return QLA_SUCCESS;
2025
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002026 return qla81xx_write_mpi_register(vha, mb);
2027}
2028
2029/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002030 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002031 * @ha: HA context
2032 *
2033 * Returns 0 on success.
2034 */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002035static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002036qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002037{
2038 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002039 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002040 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Bart Van Assche52c82822015-07-09 07:23:26 -07002041 uint32_t cnt;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002042 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002043 static int abts_cnt; /* ISP abort retry counts */
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002044 int rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002045
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002046 spin_lock_irqsave(&ha->hardware_lock, flags);
2047
2048 /* Reset RISC. */
2049 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2050 for (cnt = 0; cnt < 30000; cnt++) {
2051 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2052 break;
2053
2054 udelay(10);
2055 }
2056
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002057 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE))
2058 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2059
2060 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2061 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2062 RD_REG_DWORD(&reg->hccr),
2063 RD_REG_DWORD(&reg->ctrl_status),
2064 (RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE));
2065
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002066 WRT_REG_DWORD(&reg->ctrl_status,
2067 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002068 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002069
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002070 udelay(100);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002071
Andrew Vasquez88c26662005-07-08 17:59:26 -07002072 /* Wait for firmware to complete NVRAM accesses. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002073 RD_REG_WORD(&reg->mailbox0);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002074 for (cnt = 10000; RD_REG_WORD(&reg->mailbox0) != 0 &&
2075 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez88c26662005-07-08 17:59:26 -07002076 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002077 if (cnt)
2078 udelay(5);
2079 else
2080 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez88c26662005-07-08 17:59:26 -07002081 }
2082
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002083 if (rval == QLA_SUCCESS)
2084 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2085
2086 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2087 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2088 RD_REG_DWORD(&reg->hccr),
2089 RD_REG_DWORD(&reg->mailbox0));
2090
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08002091 /* Wait for soft-reset to complete. */
Bart Van Assche52c82822015-07-09 07:23:26 -07002092 RD_REG_DWORD(&reg->ctrl_status);
Quinn Tran200ffb12016-12-23 18:06:12 -08002093 for (cnt = 0; cnt < 60; cnt++) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002094 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002095 if ((RD_REG_DWORD(&reg->ctrl_status) &
2096 CSRX_ISP_SOFT_RESET) == 0)
2097 break;
2098
2099 udelay(5);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002100 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002101 if (!(RD_REG_DWORD(&reg->ctrl_status) & CSRX_ISP_SOFT_RESET))
2102 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2103
2104 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2105 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2106 RD_REG_DWORD(&reg->hccr),
2107 RD_REG_DWORD(&reg->ctrl_status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002108
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07002109 /* If required, do an MPI FW reset now */
2110 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2111 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2112 if (++abts_cnt < 5) {
2113 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2114 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2115 } else {
2116 /*
2117 * We exhausted the ISP abort retries. We have to
2118 * set the board offline.
2119 */
2120 abts_cnt = 0;
2121 vha->flags.online = 0;
2122 }
2123 }
2124 }
2125
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002126 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
2127 RD_REG_DWORD(&reg->hccr);
2128
2129 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
2130 RD_REG_DWORD(&reg->hccr);
2131
2132 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
2133 RD_REG_DWORD(&reg->hccr);
2134
Bart Van Assche52c82822015-07-09 07:23:26 -07002135 RD_REG_WORD(&reg->mailbox0);
Quinn Tran200ffb12016-12-23 18:06:12 -08002136 for (cnt = 60; RD_REG_WORD(&reg->mailbox0) != 0 &&
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002137 rval == QLA_SUCCESS; cnt--) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002138 barrier();
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002139 if (cnt)
2140 udelay(5);
2141 else
2142 rval = QLA_FUNCTION_TIMEOUT;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002143 }
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002144 if (rval == QLA_SUCCESS)
2145 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2146
2147 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2148 "Host Risc 0x%x, mailbox0 0x%x\n",
2149 RD_REG_DWORD(&reg->hccr),
2150 RD_REG_WORD(&reg->mailbox0));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002151
2152 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002153
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002154 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2155 "Driver in %s mode\n",
2156 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2157
Andrew Vasquez124f85e2009-01-05 11:18:06 -08002158 if (IS_NOPOLLING_TYPE(ha))
2159 ha->isp_ops->enable_intrs(ha);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -04002160
2161 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002162}
2163
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002164static void
2165qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2166{
2167 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2168
2169 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2170 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2171
2172}
2173
2174static void
2175qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2176{
2177 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2178
2179 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2180 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2181}
2182
2183static void
2184qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2185{
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002186 uint32_t wd32 = 0;
2187 uint delta_msec = 100;
2188 uint elapsed_msec = 0;
2189 uint timeout_msec;
2190 ulong n;
2191
Joe Carnucciocc790762015-08-04 13:37:53 -04002192 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2193 vha->hw->pdev->subsystem_device != 0x0240)
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002194 return;
2195
Joe Carnuccio8dd7e3a2015-08-04 13:37:54 -04002196 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2197 udelay(100);
2198
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002199attempt:
2200 timeout_msec = TIMEOUT_SEMAPHORE;
2201 n = timeout_msec / delta_msec;
2202 while (n--) {
2203 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2204 qla25xx_read_risc_sema_reg(vha, &wd32);
2205 if (wd32 & RISC_SEMAPHORE)
2206 break;
2207 msleep(delta_msec);
2208 elapsed_msec += delta_msec;
2209 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2210 goto force;
2211 }
2212
2213 if (!(wd32 & RISC_SEMAPHORE))
2214 goto force;
2215
2216 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2217 goto acquired;
2218
2219 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2220 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2221 n = timeout_msec / delta_msec;
2222 while (n--) {
2223 qla25xx_read_risc_sema_reg(vha, &wd32);
2224 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2225 break;
2226 msleep(delta_msec);
2227 elapsed_msec += delta_msec;
2228 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2229 goto force;
2230 }
2231
2232 if (wd32 & RISC_SEMAPHORE_FORCE)
2233 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2234
2235 goto attempt;
2236
2237force:
2238 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2239
2240acquired:
2241 return;
2242}
2243
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002244/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07002245 * qla24xx_reset_chip() - Reset ISP24xx chip.
2246 * @ha: HA context
2247 *
2248 * Returns 0 on success.
2249 */
2250void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002251qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07002252{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002253 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08002254
2255 if (pci_channel_offline(ha->pdev) &&
2256 ha->flags.pci_channel_io_perm_failure) {
2257 return;
2258 }
2259
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002260 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002261
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05002262 qla25xx_manipulate_risc_semaphore(vha);
2263
Andrew Vasquez88c26662005-07-08 17:59:26 -07002264 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002265 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07002266}
2267
2268/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 * qla2x00_chip_diag() - Test chip for proper operation.
2270 * @ha: HA context
2271 *
2272 * Returns 0 on success.
2273 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002274int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002275qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276{
2277 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002278 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002279 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 unsigned long flags = 0;
2281 uint16_t data;
2282 uint32_t cnt;
2283 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002284 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
2286 /* Assume a failed state */
2287 rval = QLA_FUNCTION_FAILED;
2288
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002289 ql_dbg(ql_dbg_init, vha, 0x007b,
2290 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
2292 spin_lock_irqsave(&ha->hardware_lock, flags);
2293
2294 /* Reset ISP chip. */
2295 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
2296
2297 /*
2298 * We need to have a delay here since the card will not respond while
2299 * in reset causing an MCA on some architectures.
2300 */
2301 udelay(20);
2302 data = qla2x00_debounce_register(&reg->ctrl_status);
2303 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2304 udelay(5);
2305 data = RD_REG_WORD(&reg->ctrl_status);
2306 barrier();
2307 }
2308
2309 if (!cnt)
2310 goto chip_diag_failed;
2311
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002312 ql_dbg(ql_dbg_init, vha, 0x007c,
2313 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314
2315 /* Reset RISC processor. */
2316 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
2317 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
2318
2319 /* Workaround for QLA2312 PCI parity error */
2320 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2321 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2322 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2323 udelay(5);
2324 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002325 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 }
2327 } else
2328 udelay(10);
2329
2330 if (!cnt)
2331 goto chip_diag_failed;
2332
2333 /* Check product ID of chip */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002334 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335
2336 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
2337 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
2338 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
2339 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
2340 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
2341 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002342 ql_log(ql_log_warn, vha, 0x0062,
2343 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2344 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
2346 goto chip_diag_failed;
2347 }
2348 ha->product_id[0] = mb[1];
2349 ha->product_id[1] = mb[2];
2350 ha->product_id[2] = mb[3];
2351 ha->product_id[3] = mb[4];
2352
2353 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002354 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
2356 else
2357 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002358 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359
2360 if (IS_QLA2200(ha) &&
2361 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
2362 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002363 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08002365 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 ha->fw_transfer_size = 128;
2367 }
2368
2369 /* Wrap Incoming Mailboxes Test. */
2370 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2371
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002372 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002373 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002374 if (rval)
2375 ql_log(ql_log_warn, vha, 0x0080,
2376 "Failed mailbox send register test.\n");
2377 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 /* Flag a successful rval */
2379 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 spin_lock_irqsave(&ha->hardware_lock, flags);
2381
2382chip_diag_failed:
2383 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002384 ql_log(ql_log_info, vha, 0x0081,
2385 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386
2387 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2388
2389 return (rval);
2390}
2391
2392/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002393 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2394 * @ha: HA context
2395 *
2396 * Returns 0 on success.
2397 */
2398int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002399qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002400{
2401 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002402 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002403 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002404
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002405 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07002406 return QLA_SUCCESS;
2407
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002408 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002409
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002410 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002411 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002412 ql_log(ql_log_warn, vha, 0x0082,
2413 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002414 } else {
2415 /* Flag a successful rval */
2416 rval = QLA_SUCCESS;
2417 }
2418
2419 return rval;
2420}
2421
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002422void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002423qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002424{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002425 int rval;
2426 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002427 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002428 dma_addr_t tc_dma;
2429 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002430 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002431 struct req_que *req = ha->req_q_map[0];
2432 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002433
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002434 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002435 ql_dbg(ql_dbg_init, vha, 0x00bd,
2436 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002437 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002438 }
2439
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002440 ha->fw_dumped = 0;
Hiral Patel61f098d2014-04-11 16:54:21 -04002441 ha->fw_dump_cap_flags = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002442 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
2443 req_q_size = rsp_q_size = 0;
2444
2445 if (IS_QLA27XX(ha))
2446 goto try_fce;
2447
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002448 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2449 fixed_size = sizeof(struct qla2100_fw_dump);
2450 } else if (IS_QLA23XX(ha)) {
2451 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
2452 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
2453 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07002454 } else if (IS_FWI2_CAPABLE(ha)) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002455 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002456 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
2457 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002458 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
2459 else if (IS_QLA25XX(ha))
2460 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
2461 else
2462 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Chad Dupuisf73cb692014-02-26 04:15:06 -05002463
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002464 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
2465 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002466 if (ha->mqenable) {
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04002467 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002468 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08002469 /*
2470 * Allocate maximum buffer size for all queues.
2471 * Resizing must be done at end-of-dump processing.
2472 */
2473 mq_size += ha->max_req_queues *
2474 (req->length * sizeof(request_t));
2475 mq_size += ha->max_rsp_queues *
2476 (rsp->length * sizeof(response_t));
2477 }
Arun Easi00876ae2013-03-25 02:21:37 -04002478 if (ha->tgt.atio_ring)
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002479 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002480 /* Allocate memory for Fibre Channel Event Buffer. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05002481 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2482 !IS_QLA27XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002483 goto try_eft;
2484
Chad Dupuisf73cb692014-02-26 04:15:06 -05002485try_fce:
2486 if (ha->fce)
2487 dma_free_coherent(&ha->pdev->dev,
2488 FCE_SIZE, ha->fce, ha->fce_dma);
2489
2490 /* Allocate memory for Fibre Channel Event Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07002491 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
2492 GFP_KERNEL);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002493 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002494 ql_log(ql_log_warn, vha, 0x00be,
2495 "Unable to allocate (%d KB) for FCE.\n",
2496 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002497 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002498 }
2499
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002500 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002501 ha->fce_mb, &ha->fce_bufs);
2502 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002503 ql_log(ql_log_warn, vha, 0x00bf,
2504 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002505 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
2506 tc_dma);
2507 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08002508 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002509 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002510 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002511 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002512
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07002513 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002514 ha->flags.fce_enabled = 1;
2515 ha->fce_dma = tc_dma;
2516 ha->fce = tc;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002517
Andrew Vasquez436a7b12008-07-10 16:55:54 -07002518try_eft:
Chad Dupuisf73cb692014-02-26 04:15:06 -05002519 if (ha->eft)
2520 dma_free_coherent(&ha->pdev->dev,
2521 EFT_SIZE, ha->eft, ha->eft_dma);
2522
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002523 /* Allocate memory for Extended Trace Buffer. */
Joe Perches0ea85b52014-06-15 13:37:51 -07002524 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
2525 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002526 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002527 ql_log(ql_log_warn, vha, 0x00c1,
2528 "Unable to allocate (%d KB) for EFT.\n",
2529 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002530 goto cont_alloc;
2531 }
2532
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002533 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002534 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002535 ql_log(ql_log_warn, vha, 0x00c2,
2536 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002537 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
2538 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002539 goto cont_alloc;
2540 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08002541 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002542 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002543
2544 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002545 ha->eft_dma = tc_dma;
2546 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002547 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05002548
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002549cont_alloc:
Chad Dupuisf73cb692014-02-26 04:15:06 -05002550 if (IS_QLA27XX(ha)) {
2551 if (!ha->fw_dump_template) {
2552 ql_log(ql_log_warn, vha, 0x00ba,
2553 "Failed missing fwdump template\n");
2554 return;
2555 }
2556 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
2557 ql_dbg(ql_dbg_init, vha, 0x00fa,
2558 "-> allocating fwdump (%x bytes)...\n", dump_size);
2559 goto allocate;
2560 }
2561
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002562 req_q_size = req->length * sizeof(request_t);
2563 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002564 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002565 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08002566 ha->chain_offset = dump_size;
2567 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002568
Chad Dupuisf73cb692014-02-26 04:15:06 -05002569allocate:
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07002570 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002571 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002572 ql_log(ql_log_warn, vha, 0x00c4,
2573 "Unable to allocate (%d KB) for firmware dump.\n",
2574 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002575
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07002576 if (ha->fce) {
2577 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
2578 ha->fce_dma);
2579 ha->fce = NULL;
2580 ha->fce_dma = 0;
2581 }
2582
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002583 if (ha->eft) {
2584 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
2585 ha->eft_dma);
2586 ha->eft = NULL;
2587 ha->eft_dma = 0;
2588 }
2589 return;
2590 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05002591 ha->fw_dump_len = dump_size;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002592 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002593 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002594
Chad Dupuisf73cb692014-02-26 04:15:06 -05002595 if (IS_QLA27XX(ha))
2596 return;
2597
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002598 ha->fw_dump->signature[0] = 'Q';
2599 ha->fw_dump->signature[1] = 'L';
2600 ha->fw_dump->signature[2] = 'G';
2601 ha->fw_dump->signature[3] = 'C';
Bart Van Asschead950362015-07-09 07:24:08 -07002602 ha->fw_dump->version = htonl(1);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002603
2604 ha->fw_dump->fixed_size = htonl(fixed_size);
2605 ha->fw_dump->mem_size = htonl(mem_size);
2606 ha->fw_dump->req_q_size = htonl(req_q_size);
2607 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
2608
2609 ha->fw_dump->eft_size = htonl(eft_size);
2610 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
2611 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
2612
2613 ha->fw_dump->header_size =
2614 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002615}
2616
Andrew Vasquez18e75552009-06-03 09:55:30 -07002617static int
2618qla81xx_mpi_sync(scsi_qla_host_t *vha)
2619{
2620#define MPS_MASK 0xe0
2621 int rval;
2622 uint16_t dc;
2623 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07002624
2625 if (!IS_QLA81XX(vha->hw))
2626 return QLA_SUCCESS;
2627
2628 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
2629 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002630 ql_log(ql_log_warn, vha, 0x0105,
2631 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002632 goto done;
2633 }
2634
2635 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
2636 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
2637 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002638 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002639 goto done_release;
2640 }
2641
2642 dc &= MPS_MASK;
2643 if (dc == (dw & MPS_MASK))
2644 goto done_release;
2645
2646 dw &= ~MPS_MASK;
2647 dw |= dc;
2648 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
2649 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002650 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002651 }
2652
2653done_release:
2654 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
2655 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002656 ql_log(ql_log_warn, vha, 0x006d,
2657 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07002658 }
2659
2660done:
2661 return rval;
2662}
2663
Chad Dupuis8d93f552013-01-30 03:34:37 -05002664int
2665qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
2666{
2667 /* Don't try to reallocate the array */
2668 if (req->outstanding_cmds)
2669 return QLA_SUCCESS;
2670
Michael Hernandezd7459522016-12-12 14:40:07 -08002671 if (!IS_FWI2_CAPABLE(ha))
Chad Dupuis8d93f552013-01-30 03:34:37 -05002672 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
2673 else {
Quinn Tran03e8c682015-12-17 14:56:59 -05002674 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
2675 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002676 else
Quinn Tran03e8c682015-12-17 14:56:59 -05002677 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002678 }
2679
2680 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
2681 req->num_outstanding_cmds, GFP_KERNEL);
2682
2683 if (!req->outstanding_cmds) {
2684 /*
2685 * Try to allocate a minimal size just so we can get through
2686 * initialization.
2687 */
2688 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
2689 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
2690 req->num_outstanding_cmds, GFP_KERNEL);
2691
2692 if (!req->outstanding_cmds) {
2693 ql_log(ql_log_fatal, NULL, 0x0126,
2694 "Failed to allocate memory for "
2695 "outstanding_cmds for req_que %p.\n", req);
2696 req->num_outstanding_cmds = 0;
2697 return QLA_FUNCTION_FAILED;
2698 }
2699 }
2700
2701 return QLA_SUCCESS;
2702}
2703
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002704/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 * qla2x00_setup_chip() - Load and start RISC firmware.
2706 * @ha: HA context
2707 *
2708 * Returns 0 on success.
2709 */
2710static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002711qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002713 int rval;
2714 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002715 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08002716 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2717 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07002718 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08002719
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002720 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07002721 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05002722 if (rval == QLA_SUCCESS) {
2723 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07002724 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05002725 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07002726 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002727 }
2728
Andrew Vasquez3db06522008-01-31 12:33:49 -08002729 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
2730 /* Disable SRAM, Instruction RAM and GP RAM parity. */
2731 spin_lock_irqsave(&ha->hardware_lock, flags);
2732 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
2733 RD_REG_WORD(&reg->hccr);
2734 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2735 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736
Andrew Vasquez18e75552009-06-03 09:55:30 -07002737 qla81xx_mpi_sync(vha);
2738
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002740 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002741 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002742 ql_dbg(ql_dbg_init, vha, 0x00c9,
2743 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002745 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 if (rval == QLA_SUCCESS) {
2747 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002748 ql_dbg(ql_dbg_init, vha, 0x00ca,
2749 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05002751 if (ql2xexlogins)
2752 ha->flags.exlogins_enabled = 1;
2753
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05002754 if (ql2xexchoffld)
2755 ha->flags.exchoffld_enabled = 1;
2756
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002757 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07002759 if (rval == QLA_SUCCESS) {
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05002760 rval = qla2x00_set_exlogins_buffer(vha);
2761 if (rval != QLA_SUCCESS)
2762 goto failed;
2763
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05002764 rval = qla2x00_set_exchoffld_buffer(vha);
2765 if (rval != QLA_SUCCESS)
2766 goto failed;
2767
Giridhar Malavalia9083012010-04-12 17:59:55 -07002768enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07002769 fw_major_version = ha->fw_major_version;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002770 if (IS_P3P_TYPE(ha))
Giridhar Malavali31731672011-08-16 11:31:54 -07002771 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002772 else
2773 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07002774 if (rval != QLA_SUCCESS)
2775 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002776 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002777 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07002778 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002779 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002780 if ((!ha->max_npiv_vports) ||
2781 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002782 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002783 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002784 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002785 }
Quinn Tran03e8c682015-12-17 14:56:59 -05002786 qla2x00_get_resource_cnts(vha);
Andrew Vasquezd743de62009-03-24 09:08:15 -07002787
Chad Dupuis8d93f552013-01-30 03:34:37 -05002788 /*
2789 * Allocate the array of outstanding commands
2790 * now that we know the firmware resources.
2791 */
2792 rval = qla2x00_alloc_outstanding_cmds(ha,
2793 vha->req);
2794 if (rval != QLA_SUCCESS)
2795 goto failed;
2796
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08002797 if (!fw_major_version && ql2xallocfwdump
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002798 && !(IS_P3P_TYPE(ha)))
Giridhar Malavali08de2842011-08-16 11:31:44 -07002799 qla2x00_alloc_fw_dump(vha);
Chad Dupuis3b6e5b92013-10-30 03:38:09 -04002800 } else {
2801 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 }
2803 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002804 ql_log(ql_log_fatal, vha, 0x00cd,
2805 "ISP Firmware failed checksum.\n");
2806 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04002808 } else
2809 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810
Andrew Vasquez3db06522008-01-31 12:33:49 -08002811 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
2812 /* Enable proper parity. */
2813 spin_lock_irqsave(&ha->hardware_lock, flags);
2814 if (IS_QLA2300(ha))
2815 /* SRAM parity */
2816 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
2817 else
2818 /* SRAM, Instruction RAM and GP RAM parity */
2819 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
2820 RD_REG_WORD(&reg->hccr);
2821 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2822 }
2823
Chad Dupuisf3982d82014-09-25 05:16:57 -04002824 if (IS_QLA27XX(ha))
2825 ha->flags.fac_supported = 1;
2826 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07002827 uint32_t size;
2828
2829 rval = qla81xx_fac_get_sector_size(vha, &size);
2830 if (rval == QLA_SUCCESS) {
2831 ha->flags.fac_supported = 1;
2832 ha->fdt_block_size = size << 2;
2833 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002834 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07002835 "Unsupported FAC firmware (%d.%02d.%02d).\n",
2836 ha->fw_major_version, ha->fw_minor_version,
2837 ha->fw_subminor_version);
Joe Carnuccio1ca60e32014-02-26 04:15:02 -05002838
Chad Dupuisf73cb692014-02-26 04:15:06 -05002839 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002840 ha->flags.fac_supported = 0;
2841 rval = QLA_SUCCESS;
2842 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07002843 }
2844 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07002845failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002847 ql_log(ql_log_fatal, vha, 0x00cf,
2848 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 }
2850
2851 return (rval);
2852}
2853
2854/**
2855 * qla2x00_init_response_q_entries() - Initializes response queue entries.
2856 * @ha: HA context
2857 *
2858 * Beginning of request ring has initialization control block already built
2859 * by nvram config routine.
2860 *
2861 * Returns 0 on success.
2862 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002863void
2864qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865{
2866 uint16_t cnt;
2867 response_t *pkt;
2868
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002869 rsp->ring_ptr = rsp->ring;
2870 rsp->ring_index = 0;
2871 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002872 pkt = rsp->ring_ptr;
2873 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 pkt->signature = RESPONSE_PROCESSED;
2875 pkt++;
2876 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877}
2878
2879/**
2880 * qla2x00_update_fw_options() - Read and process firmware options.
2881 * @ha: HA context
2882 *
2883 * Returns 0 on success.
2884 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002885void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002886qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887{
2888 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002889 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890
2891 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002892 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893
2894 if (IS_QLA2100(ha) || IS_QLA2200(ha))
2895 return;
2896
2897 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002898 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
2899 "Serial link options.\n");
2900 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
2901 (uint8_t *)&ha->fw_seriallink_options,
2902 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903
2904 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
2905 if (ha->fw_seriallink_options[3] & BIT_2) {
2906 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
2907
2908 /* 1G settings */
2909 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
2910 emphasis = (ha->fw_seriallink_options[2] &
2911 (BIT_4 | BIT_3)) >> 3;
2912 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002913 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 rx_sens = (ha->fw_seriallink_options[0] &
2915 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
2916 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
2917 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2918 if (rx_sens == 0x0)
2919 rx_sens = 0x3;
2920 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
2921 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2922 ha->fw_options[10] |= BIT_5 |
2923 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2924 (tx_sens & (BIT_1 | BIT_0));
2925
2926 /* 2G settings */
2927 swing = (ha->fw_seriallink_options[2] &
2928 (BIT_7 | BIT_6 | BIT_5)) >> 5;
2929 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
2930 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002931 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 rx_sens = (ha->fw_seriallink_options[1] &
2933 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
2934 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
2935 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
2936 if (rx_sens == 0x0)
2937 rx_sens = 0x3;
2938 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
2939 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
2940 ha->fw_options[11] |= BIT_5 |
2941 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
2942 (tx_sens & (BIT_1 | BIT_0));
2943 }
2944
2945 /* FCP2 options. */
2946 /* Return command IOCBs without waiting for an ABTS to complete. */
2947 ha->fw_options[3] |= BIT_13;
2948
2949 /* LED scheme. */
2950 if (ha->flags.enable_led_scheme)
2951 ha->fw_options[2] |= BIT_12;
2952
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002953 /* Detect ISP6312. */
2954 if (IS_QLA6312(ha))
2955 ha->fw_options[2] |= BIT_13;
2956
Giridhar Malavali088d09d2016-07-06 11:14:20 -04002957 /* Set Retry FLOGI in case of P2P connection */
2958 if (ha->operating_mode == P2P) {
2959 ha->fw_options[2] |= BIT_3;
2960 ql_dbg(ql_dbg_disc, vha, 0x2100,
2961 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
2962 __func__, ha->fw_options[2]);
2963 }
2964
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002966 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967}
2968
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002969void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002970qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002971{
2972 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002973 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002974
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04002975 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07002976 return;
2977
Himanshu Madhanif198caf2016-01-27 12:03:30 -05002978 /* Hold status IOCBs until ABTS response received. */
2979 if (ql2xfwholdabts)
2980 ha->fw_options[3] |= BIT_12;
2981
Giridhar Malavali088d09d2016-07-06 11:14:20 -04002982 /* Set Retry FLOGI in case of P2P connection */
2983 if (ha->operating_mode == P2P) {
2984 ha->fw_options[2] |= BIT_3;
2985 ql_dbg(ql_dbg_disc, vha, 0x2101,
2986 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
2987 __func__, ha->fw_options[2]);
2988 }
2989
Quinn Tran41dc5292017-01-19 22:28:03 -08002990 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
2991 if (ql2xmvasynctoatio) {
2992 if (qla_tgt_mode_enabled(vha) ||
2993 qla_dual_mode_enabled(vha))
2994 ha->fw_options[2] |= BIT_11;
2995 else
2996 ha->fw_options[2] &= ~BIT_11;
2997 }
2998
2999 ql_dbg(ql_dbg_init, vha, 0xffff,
3000 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3001 __func__, ha->fw_options[1], ha->fw_options[2],
3002 ha->fw_options[3], vha->host->active_mode);
3003 qla2x00_set_fw_options(vha, ha->fw_options);
3004
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003005 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08003006 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003007 return;
3008
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003009 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08003010 le16_to_cpu(ha->fw_seriallink_options24[1]),
3011 le16_to_cpu(ha->fw_seriallink_options24[2]),
3012 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003013 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003014 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003015 "Unable to update Serial Link options (%x).\n", rval);
3016 }
3017}
3018
3019void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003020qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003021{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003022 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003023 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003024 struct req_que *req = ha->req_q_map[0];
3025 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003026
3027 /* Setup ring parameters in initialization control block. */
Bart Van Asschead950362015-07-09 07:24:08 -07003028 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3029 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003030 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3031 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3032 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3033 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3034 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3035 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003036
3037 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3038 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3039 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3040 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3041 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3042}
3043
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003044void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003045qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003046{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003047 struct qla_hw_data *ha = vha->hw;
Bart Van Assche118e2ef2015-07-09 07:24:27 -07003048 device_reg_t *reg = ISP_QUE_REG(ha, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003049 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3050 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003051 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003052 uint16_t rid = 0;
3053 struct req_que *req = ha->req_q_map[0];
3054 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003055
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003056 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003057 icb = (struct init_cb_24xx *)ha->init_cb;
Bart Van Asschead950362015-07-09 07:24:08 -07003058 icb->request_q_outpointer = cpu_to_le16(0);
3059 icb->response_q_inpointer = cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003060 icb->request_q_length = cpu_to_le16(req->length);
3061 icb->response_q_length = cpu_to_le16(rsp->length);
3062 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3063 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3064 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3065 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003066
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003067 /* Setup ATIO queue dma pointers for target mode */
Bart Van Asschead950362015-07-09 07:24:08 -07003068 icb->atio_q_inpointer = cpu_to_le16(0);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003069 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3070 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
3071 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
3072
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003073 if (IS_SHADOW_REG_CAPABLE(ha))
Bart Van Asschead950362015-07-09 07:24:08 -07003074 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003075
Chad Dupuisf73cb692014-02-26 04:15:06 -05003076 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003077 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3078 icb->rid = cpu_to_le16(rid);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003079 if (ha->flags.msix_enabled) {
3080 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003081 ql_dbg(ql_dbg_init, vha, 0x00fd,
3082 "Registering vector 0x%x for base que.\n",
3083 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003084 icb->msix = cpu_to_le16(msix->entry);
3085 }
3086 /* Use alternate PCI bus number */
3087 if (MSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003088 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003089 /* Use alternate PCI devfn */
3090 if (LSB(rid))
Bart Van Asschead950362015-07-09 07:24:08 -07003091 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003092
Anirban Chakraborty31557542009-12-02 10:36:55 -08003093 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003094 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
3095 (ha->flags.msix_enabled)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003096 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003097 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003098 ql_dbg(ql_dbg_init, vha, 0x00fe,
3099 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08003100 } else {
Bart Van Asschead950362015-07-09 07:24:08 -07003101 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Anirban Chakraborty31557542009-12-02 10:36:55 -08003102 }
Bart Van Asschead950362015-07-09 07:24:08 -07003103 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003104
3105 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
3106 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
3107 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
3108 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
3109 } else {
3110 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
3111 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
3112 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
3113 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
3114 }
Arun Easiaa230bc2013-01-30 03:34:39 -05003115 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003116
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003117 /* PCI posting */
3118 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003119}
3120
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121/**
3122 * qla2x00_init_rings() - Initializes firmware.
3123 * @ha: HA context
3124 *
3125 * Beginning of request ring has initialization control block already built
3126 * by nvram config routine.
3127 *
3128 * Returns 0 on success.
3129 */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003130int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003131qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132{
3133 int rval;
3134 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003135 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003136 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003137 struct req_que *req;
3138 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003139 struct mid_init_cb_24xx *mid_init_cb =
3140 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141
3142 spin_lock_irqsave(&ha->hardware_lock, flags);
3143
3144 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003145 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003146 req = ha->req_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003147 if (!req || !test_bit(que, ha->req_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003148 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003149 req->out_ptr = (void *)(req->ring + req->length);
3150 *req->out_ptr = 0;
Chad Dupuis8d93f552013-01-30 03:34:37 -05003151 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003152 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003154 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003155
3156 /* Initialize firmware. */
3157 req->ring_ptr = req->ring;
3158 req->ring_index = 0;
3159 req->cnt = req->length;
3160 }
3161
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003162 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003163 rsp = ha->rsp_q_map[que];
Quinn Trancb432852016-02-04 11:45:16 -05003164 if (!rsp || !test_bit(que, ha->rsp_qid_map))
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003165 continue;
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003166 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
3167 *rsp->in_ptr = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003168 /* Initialize response queue entries */
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003169 if (IS_QLAFX00(ha))
3170 qlafx00_init_response_q_entries(rsp);
3171 else
3172 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003175 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
3176 ha->tgt.atio_ring_index = 0;
3177 /* Initialize ATIO queue entries */
3178 qlt_init_atio_q_entries(vha);
3179
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003180 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181
3182 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3183
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003184 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
3185
3186 if (IS_QLAFX00(ha)) {
3187 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
3188 goto next_check;
3189 }
3190
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003192 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003194 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04003195 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003196 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08003197 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08003198 }
3199
Andrew Vasquez24a08132009-03-24 09:08:16 -07003200 if (IS_FWI2_CAPABLE(ha)) {
Bart Van Asschead950362015-07-09 07:24:08 -07003201 mid_init_cb->options = cpu_to_le16(BIT_1);
Andrew Vasquez24a08132009-03-24 09:08:16 -07003202 mid_init_cb->init_cb.execution_throttle =
Quinn Tran03e8c682015-12-17 14:56:59 -05003203 cpu_to_le16(ha->cur_fw_xcb_count);
Joe Carnuccio40f38622016-07-06 11:14:28 -04003204 ha->flags.dport_enabled =
3205 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
3206 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
3207 (ha->flags.dport_enabled) ? "enabled" : "disabled");
3208 /* FA-WWPN Status */
Himanshu Madhani2486c622014-09-25 05:17:00 -04003209 ha->flags.fawwpn_enabled =
Joe Carnuccio40f38622016-07-06 11:14:28 -04003210 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
Himanshu Madhani2486c622014-09-25 05:17:00 -04003211 ql_dbg(ql_dbg_init, vha, 0x0141, "FA-WWPN Support: %s.\n",
3212 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
Andrew Vasquez24a08132009-03-24 09:08:16 -07003213 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003214
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003215 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003216next_check:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003218 ql_log(ql_log_fatal, vha, 0x00d2,
3219 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003221 ql_dbg(ql_dbg_init, vha, 0x00d3,
3222 "Init Firmware -- success.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 }
3224
3225 return (rval);
3226}
3227
3228/**
3229 * qla2x00_fw_ready() - Waits for firmware ready.
3230 * @ha: HA context
3231 *
3232 * Returns 0 on success.
3233 */
3234static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003235qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236{
3237 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003238 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 uint16_t min_wait; /* Minimum wait time if loop is down */
3240 uint16_t wait_time; /* Wait time if loop is coming ready */
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003241 uint16_t state[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003242 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04003244 if (IS_QLAFX00(vha->hw))
3245 return qlafx00_fw_ready(vha);
3246
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 rval = QLA_SUCCESS;
3248
Chad Dupuis33461492015-04-09 14:59:57 -04003249 /* Time to wait for loop down */
3250 if (IS_P3P_TYPE(ha))
3251 min_wait = 30;
3252 else
3253 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254
3255 /*
3256 * Firmware should take at most one RATOV to login, plus 5 seconds for
3257 * our own processing.
3258 */
3259 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
3260 wait_time = min_wait;
3261 }
3262
3263 /* Min wait time if loop down */
3264 mtime = jiffies + (min_wait * HZ);
3265
3266 /* wait time before firmware ready */
3267 wtime = jiffies + (wait_time * HZ);
3268
3269 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003270 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003271 ql_log(ql_log_info, vha, 0x801e,
3272 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273
3274 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05003275 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003276 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003278 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003279 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003281 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003282 ql_dbg(ql_dbg_taskm, vha, 0x801f,
3283 "fw_state=%x 84xx=%x.\n", state[0],
3284 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003285 if ((state[2] & FSTATE_LOGGED_IN) &&
3286 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003287 ql_dbg(ql_dbg_taskm, vha, 0x8028,
3288 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003289
3290 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003291 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003292 if (rval != QLA_SUCCESS) {
3293 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08003294 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003295 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003296 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003297 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003298
3299 /* Add time taken to initialize. */
3300 cs84xx_time = jiffies - cs84xx_time;
3301 wtime += cs84xx_time;
3302 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08003303 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003304 "Increasing wait time by %ld. "
3305 "New time %ld.\n", cs84xx_time,
3306 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003307 }
3308 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003309 ql_dbg(ql_dbg_taskm, vha, 0x8037,
3310 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003312 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 &ha->login_timeout, &ha->r_a_tov);
3314
3315 rval = QLA_SUCCESS;
3316 break;
3317 }
3318
3319 rval = QLA_FUNCTION_FAILED;
3320
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003321 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003322 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003324 * other than Wait for Login.
3325 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003327 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 "Cable is unplugged...\n");
3329
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003330 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 break;
3332 }
3333 }
3334 } else {
3335 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07003336 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08003337 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 break;
3339 }
3340
3341 if (time_after_eq(jiffies, wtime))
3342 break;
3343
3344 /* Delay for a while */
3345 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 } while (1);
3347
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003348 ql_dbg(ql_dbg_taskm, vha, 0x803a,
Joe Carnucciob5a340d2014-09-25 05:16:48 -04003349 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
3350 state[1], state[2], state[3], state[4], state[5], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351
Chad Dupuiscfb09192011-11-18 09:03:07 -08003352 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003353 ql_log(ql_log_warn, vha, 0x803b,
3354 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 }
3356
3357 return (rval);
3358}
3359
3360/*
3361* qla2x00_configure_hba
3362* Setup adapter context.
3363*
3364* Input:
3365* ha = adapter state pointer.
3366*
3367* Returns:
3368* 0 = success
3369*
3370* Context:
3371* Kernel context.
3372*/
3373static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003374qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375{
3376 int rval;
3377 uint16_t loop_id;
3378 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003379 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 uint8_t al_pa;
3381 uint8_t area;
3382 uint8_t domain;
3383 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003384 struct qla_hw_data *ha = vha->hw;
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02003385 unsigned long flags;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003386 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387
3388 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003389 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003390 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003392 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003393 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08003394 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003395 ql_dbg(ql_dbg_disc, vha, 0x2008,
3396 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08003397 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003398 ql_log(ql_log_warn, vha, 0x2009,
3399 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05003400 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
3401 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
3402 ql_log(ql_log_warn, vha, 0x1151,
3403 "Doing link init.\n");
3404 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
3405 return rval;
3406 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003407 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08003408 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 return (rval);
3410 }
3411
3412 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003413 ql_log(ql_log_info, vha, 0x200a,
3414 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 return (QLA_FUNCTION_FAILED);
3416 }
3417
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419
3420 /* initialize */
3421 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
3422 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003423 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424
3425 switch (topo) {
3426 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003427 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 ha->current_topology = ISP_CFG_NL;
3429 strcpy(connect_type, "(Loop)");
3430 break;
3431
3432 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003433 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003434 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 ha->current_topology = ISP_CFG_FL;
3436 strcpy(connect_type, "(FL_Port)");
3437 break;
3438
3439 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003440 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 ha->operating_mode = P2P;
3442 ha->current_topology = ISP_CFG_N;
3443 strcpy(connect_type, "(N_Port-to-N_Port)");
3444 break;
3445
3446 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003447 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003448 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 ha->operating_mode = P2P;
3450 ha->current_topology = ISP_CFG_F;
3451 strcpy(connect_type, "(F_Port)");
3452 break;
3453
3454 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003455 ql_dbg(ql_dbg_disc, vha, 0x200f,
3456 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 ha->current_topology = ISP_CFG_NL;
3458 strcpy(connect_type, "(Loop)");
3459 break;
3460 }
3461
3462 /* Save Host port and loop ID. */
3463 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003464 vha->d_id.b.domain = domain;
3465 vha->d_id.b.area = area;
3466 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02003468 spin_lock_irqsave(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003469 qlt_update_vp_map(vha, SET_AL_PA);
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02003470 spin_unlock_irqrestore(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003471
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003472 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003473 ql_log(ql_log_info, vha, 0x2010,
3474 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003475 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 return(rval);
3478}
3479
Giridhar Malavalia9083012010-04-12 17:59:55 -07003480inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003481qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
3482 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003483{
3484 char *st, *en;
3485 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003486 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07003487 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003488 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003489
3490 if (memcmp(model, BINZERO, len) != 0) {
3491 strncpy(ha->model_number, model, len);
3492 st = en = ha->model_number;
3493 en += len - 1;
3494 while (en > st) {
3495 if (*en != 0x20 && *en != 0x00)
3496 break;
3497 *en-- = '\0';
3498 }
3499
3500 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07003501 if (use_tbl &&
3502 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003503 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003504 strncpy(ha->model_desc,
3505 qla2x00_model_name[index * 2 + 1],
3506 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003507 } else {
3508 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07003509 if (use_tbl &&
3510 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003511 index < QLA_MODEL_NAMES) {
3512 strcpy(ha->model_number,
3513 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003514 strncpy(ha->model_desc,
3515 qla2x00_model_name[index * 2 + 1],
3516 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003517 } else {
3518 strcpy(ha->model_number, def);
3519 }
3520 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003521 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003522 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07003523 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003524}
3525
David Miller4e08df32007-04-16 12:37:43 -07003526/* On sparc systems, obtain port and node WWN from firmware
3527 * properties.
3528 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003529static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07003530{
3531#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003532 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003533 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003534 struct device_node *dp = pci_device_to_OF_node(pdev);
3535 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003536 int len;
3537
3538 val = of_get_property(dp, "port-wwn", &len);
3539 if (val && len >= WWN_SIZE)
3540 memcpy(nv->port_name, val, WWN_SIZE);
3541
3542 val = of_get_property(dp, "node-wwn", &len);
3543 if (val && len >= WWN_SIZE)
3544 memcpy(nv->node_name, val, WWN_SIZE);
3545#endif
3546}
3547
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548/*
3549* NVRAM configuration for ISP 2xxx
3550*
3551* Input:
3552* ha = adapter block pointer.
3553*
3554* Output:
3555* initialization control block in response_ring
3556* host adapters parameters in host adapter block
3557*
3558* Returns:
3559* 0 = success.
3560*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003561int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003562qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563{
David Miller4e08df32007-04-16 12:37:43 -07003564 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003565 uint8_t chksum = 0;
3566 uint16_t cnt;
3567 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003568 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003569 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003570 nvram_t *nv = ha->nvram;
3571 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003572 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573
David Miller4e08df32007-04-16 12:37:43 -07003574 rval = QLA_SUCCESS;
3575
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003577 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 ha->nvram_base = 0;
3579 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
3580 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
3581 ha->nvram_base = 0x80;
3582
3583 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003584 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003585 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
3586 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003588 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
3589 "Contents of NVRAM.\n");
3590 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
3591 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592
3593 /* Bad NVRAM data, set defaults parameters. */
3594 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
3595 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
3596 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003597 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04003598 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003599 "detected: checksum=0x%x id=%c version=0x%x.\n",
3600 chksum, nv->id[0], nv->nvram_version);
3601 ql_log(ql_log_warn, vha, 0x0065,
3602 "Falling back to "
3603 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07003604
3605 /*
3606 * Set default initialization control block.
3607 */
3608 memset(nv, 0, ha->nvram_size);
3609 nv->parameter_block_version = ICB_VERSION;
3610
3611 if (IS_QLA23XX(ha)) {
3612 nv->firmware_options[0] = BIT_2 | BIT_1;
3613 nv->firmware_options[1] = BIT_7 | BIT_5;
3614 nv->add_firmware_options[0] = BIT_5;
3615 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04003616 nv->frame_payload_size = 2048;
David Miller4e08df32007-04-16 12:37:43 -07003617 nv->special_options[1] = BIT_7;
3618 } else if (IS_QLA2200(ha)) {
3619 nv->firmware_options[0] = BIT_2 | BIT_1;
3620 nv->firmware_options[1] = BIT_7 | BIT_5;
3621 nv->add_firmware_options[0] = BIT_5;
3622 nv->add_firmware_options[1] = BIT_5 | BIT_4;
Joe Carnuccio98aee702014-09-25 05:16:38 -04003623 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07003624 } else if (IS_QLA2100(ha)) {
3625 nv->firmware_options[0] = BIT_3 | BIT_1;
3626 nv->firmware_options[1] = BIT_5;
Joe Carnuccio98aee702014-09-25 05:16:38 -04003627 nv->frame_payload_size = 1024;
David Miller4e08df32007-04-16 12:37:43 -07003628 }
3629
Bart Van Asschead950362015-07-09 07:24:08 -07003630 nv->max_iocb_allocation = cpu_to_le16(256);
3631 nv->execution_throttle = cpu_to_le16(16);
David Miller4e08df32007-04-16 12:37:43 -07003632 nv->retry_count = 8;
3633 nv->retry_delay = 1;
3634
3635 nv->port_name[0] = 33;
3636 nv->port_name[3] = 224;
3637 nv->port_name[4] = 139;
3638
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003639 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003640
3641 nv->login_timeout = 4;
3642
3643 /*
3644 * Set default host adapter parameters
3645 */
3646 nv->host_p[1] = BIT_2;
3647 nv->reset_delay = 5;
3648 nv->port_down_retry_count = 8;
Bart Van Asschead950362015-07-09 07:24:08 -07003649 nv->max_luns_per_target = cpu_to_le16(8);
David Miller4e08df32007-04-16 12:37:43 -07003650 nv->link_down_timeout = 60;
3651
3652 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653 }
3654
3655#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
3656 /*
3657 * The SN2 does not provide BIOS emulation which means you can't change
3658 * potentially bogus BIOS settings. Force the use of default settings
3659 * for link rate and frame size. Hope that the rest of the settings
3660 * are valid.
3661 */
3662 if (ia64_platform_is("sn2")) {
Joe Carnuccio98aee702014-09-25 05:16:38 -04003663 nv->frame_payload_size = 2048;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003664 if (IS_QLA23XX(ha))
3665 nv->special_options[1] = BIT_7;
3666 }
3667#endif
3668
3669 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003670 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671
3672 /*
3673 * Setup driver NVRAM options.
3674 */
3675 nv->firmware_options[0] |= (BIT_6 | BIT_1);
3676 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
3677 nv->firmware_options[1] |= (BIT_5 | BIT_0);
3678 nv->firmware_options[1] &= ~BIT_4;
3679
3680 if (IS_QLA23XX(ha)) {
3681 nv->firmware_options[0] |= BIT_2;
3682 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003683 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003684 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003685
3686 if (IS_QLA2300(ha)) {
3687 if (ha->fb_rev == FPM_2310) {
3688 strcpy(ha->model_number, "QLA2310");
3689 } else {
3690 strcpy(ha->model_number, "QLA2300");
3691 }
3692 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003693 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003694 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 }
3696 } else if (IS_QLA2200(ha)) {
3697 nv->firmware_options[0] |= BIT_2;
3698 /*
3699 * 'Point-to-point preferred, else loop' is not a safe
3700 * connection mode setting.
3701 */
3702 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
3703 (BIT_5 | BIT_4)) {
3704 /* Force 'loop preferred, else point-to-point'. */
3705 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
3706 nv->add_firmware_options[0] |= BIT_5;
3707 }
3708 strcpy(ha->model_number, "QLA22xx");
3709 } else /*if (IS_QLA2100(ha))*/ {
3710 strcpy(ha->model_number, "QLA2100");
3711 }
3712
3713 /*
3714 * Copy over NVRAM RISC parameter block to initialization control block.
3715 */
3716 dptr1 = (uint8_t *)icb;
3717 dptr2 = (uint8_t *)&nv->parameter_block_version;
3718 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
3719 while (cnt--)
3720 *dptr1++ = *dptr2++;
3721
3722 /* Copy 2nd half. */
3723 dptr1 = (uint8_t *)icb->add_firmware_options;
3724 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
3725 while (cnt--)
3726 *dptr1++ = *dptr2++;
3727
Andrew Vasquez5341e862006-05-17 15:09:16 -07003728 /* Use alternate WWN? */
3729 if (nv->host_p[1] & BIT_7) {
3730 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3731 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3732 }
3733
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734 /* Prepare nodename */
3735 if ((icb->firmware_options[1] & BIT_6) == 0) {
3736 /*
3737 * Firmware will apply the following mask if the nodename was
3738 * not provided.
3739 */
3740 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3741 icb->node_name[0] &= 0xF0;
3742 }
3743
3744 /*
3745 * Set host adapter parameters.
3746 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07003747
3748 /*
3749 * BIT_7 in the host-parameters section allows for modification to
3750 * internal driver logging.
3751 */
Andrew Vasquez01819442006-06-23 16:11:10 -07003752 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08003753 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
3755 /* Always load RISC code on non ISP2[12]00 chips. */
3756 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
3757 ha->flags.disable_risc_code_load = 0;
3758 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
3759 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
3760 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07003761 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003762 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763
3764 ha->operating_mode =
3765 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
3766
3767 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
3768 sizeof(ha->fw_seriallink_options));
3769
3770 /* save HBA serial number */
3771 ha->serial0 = icb->port_name[5];
3772 ha->serial1 = icb->port_name[6];
3773 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003774 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3775 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776
Bart Van Asschead950362015-07-09 07:24:08 -07003777 icb->execution_throttle = cpu_to_le16(0xFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778
3779 ha->retry_count = nv->retry_count;
3780
3781 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07003782 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783 nv->login_timeout = ql2xlogintimeout;
3784 if (nv->login_timeout < 4)
3785 nv->login_timeout = 4;
3786 ha->login_timeout = nv->login_timeout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003788 /* Set minimum RATOV to 100 tenths of a second. */
3789 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791 ha->loop_reset_delay = nv->reset_delay;
3792
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 /* Link Down Timeout = 0:
3794 *
3795 * When Port Down timer expires we will start returning
3796 * I/O's to OS with "DID_NO_CONNECT".
3797 *
3798 * Link Down Timeout != 0:
3799 *
3800 * The driver waits for the link to come up after link down
3801 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003802 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 if (nv->link_down_timeout == 0) {
3804 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003805 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 } else {
3807 ha->link_down_timeout = nv->link_down_timeout;
3808 ha->loop_down_abort_time =
3809 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003810 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812 /*
3813 * Need enough time to try and get the port back.
3814 */
3815 ha->port_down_retry_count = nv->port_down_retry_count;
3816 if (qlport_down_retry)
3817 ha->port_down_retry_count = qlport_down_retry;
3818 /* Set login_retry_count */
3819 ha->login_retry_count = nv->retry_count;
3820 if (ha->port_down_retry_count == nv->port_down_retry_count &&
3821 ha->port_down_retry_count > 3)
3822 ha->login_retry_count = ha->port_down_retry_count;
3823 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3824 ha->login_retry_count = ha->port_down_retry_count;
3825 if (ql2xloginretrycount)
3826 ha->login_retry_count = ql2xloginretrycount;
3827
Bart Van Asschead950362015-07-09 07:24:08 -07003828 icb->lun_enables = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 icb->command_resource_count = 0;
3830 icb->immediate_notify_resource_count = 0;
Bart Van Asschead950362015-07-09 07:24:08 -07003831 icb->timeout = cpu_to_le16(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832
3833 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3834 /* Enable RIO */
3835 icb->firmware_options[0] &= ~BIT_3;
3836 icb->add_firmware_options[0] &=
3837 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
3838 icb->add_firmware_options[0] |= BIT_2;
3839 icb->response_accumulation_timer = 3;
3840 icb->interrupt_delay_timer = 5;
3841
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003842 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003844 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003845 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003846 ha->zio_mode = icb->add_firmware_options[0] &
3847 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3848 ha->zio_timer = icb->interrupt_delay_timer ?
3849 icb->interrupt_delay_timer: 2;
3850 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003851 icb->add_firmware_options[0] &=
3852 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003853 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003854 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003855 ha->zio_mode = QLA_ZIO_MODE_6;
3856
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003857 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003858 "ZIO mode %d enabled; timer delay (%d us).\n",
3859 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003861 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
3862 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003863 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 }
3865 }
3866
David Miller4e08df32007-04-16 12:37:43 -07003867 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003868 ql_log(ql_log_warn, vha, 0x0069,
3869 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07003870 }
3871 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872}
3873
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003874static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003875qla2x00_rport_del(void *data)
3876{
3877 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003878 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003879 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003880
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003881 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07003882 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003883 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003884 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Quinn Tran726b8542017-01-19 22:28:00 -08003885 if (rport) {
3886 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
3887 "%s %8phN. rport %p roles %x \n",
3888 __func__, fcport->port_name, rport,
3889 rport->roles);
3890
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003891 fc_remote_port_delete(rport);
Quinn Tran726b8542017-01-19 22:28:00 -08003892 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003893}
3894
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895/**
3896 * qla2x00_alloc_fcport() - Allocate a generic fcport.
3897 * @ha: HA context
3898 * @flags: allocation flags
3899 *
3900 * Returns a pointer to the allocated fcport, or NULL, if none available.
3901 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003902fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003903qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904{
3905 fc_port_t *fcport;
3906
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003907 fcport = kzalloc(sizeof(fc_port_t), flags);
3908 if (!fcport)
3909 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910
3911 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003912 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913 fcport->port_type = FCT_UNKNOWN;
3914 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07003915 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003916 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917
Quinn Tran726b8542017-01-19 22:28:00 -08003918 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
3919 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
Quinn Tran6cb32162017-02-13 12:18:29 -08003920 flags);
Quinn Tran726b8542017-01-19 22:28:00 -08003921 fcport->disc_state = DSC_DELETED;
3922 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
3923 fcport->deleted = QLA_SESS_DELETED;
3924 fcport->login_retry = vha->hw->login_retry_count;
3925 fcport->login_retry = 5;
3926 fcport->logout_on_delete = 1;
3927
3928 if (!fcport->ct_desc.ct_sns) {
3929 ql_log(ql_log_warn, vha, 0xffff,
3930 "Failed to allocate ct_sns request.\n");
3931 kfree(fcport);
3932 fcport = NULL;
3933 }
3934 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
3935 INIT_LIST_HEAD(&fcport->gnl_entry);
3936 INIT_LIST_HEAD(&fcport->list);
3937
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003938 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939}
3940
Quinn Tran726b8542017-01-19 22:28:00 -08003941void
3942qla2x00_free_fcport(fc_port_t *fcport)
3943{
3944 if (fcport->ct_desc.ct_sns) {
3945 dma_free_coherent(&fcport->vha->hw->pdev->dev,
3946 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
3947 fcport->ct_desc.ct_sns_dma);
3948
3949 fcport->ct_desc.ct_sns = NULL;
3950 }
3951 kfree(fcport);
3952}
3953
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954/*
3955 * qla2x00_configure_loop
3956 * Updates Fibre Channel Device Database with what is actually on loop.
3957 *
3958 * Input:
3959 * ha = adapter block pointer.
3960 *
3961 * Returns:
3962 * 0 = success.
3963 * 1 = error.
3964 * 2 = database was full and device was not configured.
3965 */
3966static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003967qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968{
3969 int rval;
3970 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003971 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 rval = QLA_SUCCESS;
3973
3974 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003975 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
3976 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003978 ql_dbg(ql_dbg_disc, vha, 0x2013,
3979 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 return (rval);
3981 }
3982 }
3983
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003984 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003985 ql_dbg(ql_dbg_disc, vha, 0x2014,
3986 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987
3988 /*
3989 * If we have both an RSCN and PORT UPDATE pending then handle them
3990 * both at the same time.
3991 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003992 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
3993 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003994
Michael Hernandez3064ff32009-12-15 21:29:44 -08003995 qla2x00_get_data_rate(vha);
3996
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997 /* Determine what we need to do */
3998 if (ha->current_topology == ISP_CFG_FL &&
3999 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4000
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001 set_bit(RSCN_UPDATE, &flags);
4002
4003 } else if (ha->current_topology == ISP_CFG_F &&
4004 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4005
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 set_bit(RSCN_UPDATE, &flags);
4007 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4008
Andrew Vasquez21333b42006-05-17 15:09:56 -07004009 } else if (ha->current_topology == ISP_CFG_N) {
4010 clear_bit(RSCN_UPDATE, &flags);
Quinn Tran41dc5292017-01-19 22:28:03 -08004011 } else if (ha->current_topology == ISP_CFG_NL) {
4012 clear_bit(RSCN_UPDATE, &flags);
4013 set_bit(LOCAL_LOOP_UPDATE, &flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004014 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 set_bit(RSCN_UPDATE, &flags);
4017 set_bit(LOCAL_LOOP_UPDATE, &flags);
4018 }
4019
4020 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004021 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4022 ql_dbg(ql_dbg_disc, vha, 0x2015,
4023 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08004025 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004026 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027 }
4028
4029 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004030 if (LOOP_TRANSITION(vha)) {
4031 ql_dbg(ql_dbg_disc, vha, 0x201e,
4032 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004034 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004035 else
4036 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037 }
4038
4039 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004040 if (atomic_read(&vha->loop_down_timer) ||
4041 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 rval = QLA_FUNCTION_FAILED;
4043 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004044 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004045 ql_dbg(ql_dbg_disc, vha, 0x2069,
4046 "LOOP READY.\n");
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05004047
4048 /*
4049 * Process any ATIO queue entries that came in
4050 * while we weren't online.
4051 */
Quinn Tranead03852017-01-19 22:28:01 -08004052 if (qla_tgt_mode_enabled(vha) ||
4053 qla_dual_mode_enabled(vha)) {
Dilip Kumar Uppugandla3bb67df2015-12-17 14:57:11 -05004054 if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) {
4055 spin_lock_irqsave(&ha->tgt.atio_lock,
4056 flags);
4057 qlt_24xx_process_atio_queue(vha, 0);
4058 spin_unlock_irqrestore(
4059 &ha->tgt.atio_lock, flags);
4060 } else {
4061 spin_lock_irqsave(&ha->hardware_lock,
4062 flags);
4063 qlt_24xx_process_atio_queue(vha, 1);
4064 spin_unlock_irqrestore(
4065 &ha->hardware_lock, flags);
4066 }
4067 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 }
4069 }
4070
4071 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004072 ql_dbg(ql_dbg_disc, vha, 0x206a,
4073 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004075 ql_dbg(ql_dbg_disc, vha, 0x206b,
4076 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077 }
4078
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07004079 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004080 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004082 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004083 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004084 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07004085 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 }
4087
4088 return (rval);
4089}
4090
4091
4092
4093/*
4094 * qla2x00_configure_local_loop
4095 * Updates Fibre Channel Device Database with local loop devices.
4096 *
4097 * Input:
4098 * ha = adapter block pointer.
4099 *
4100 * Returns:
4101 * 0 = success.
4102 */
4103static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004104qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004105{
4106 int rval, rval2;
4107 int found_devs;
4108 int found;
4109 fc_port_t *fcport, *new_fcport;
4110
4111 uint16_t index;
4112 uint16_t entries;
4113 char *id_iter;
4114 uint16_t loop_id;
4115 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004116 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08004117 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118
4119 found_devs = 0;
4120 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08004121 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08004124 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004125 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126 &entries);
4127 if (rval != QLA_SUCCESS)
4128 goto cleanup_allocation;
4129
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004130 ql_dbg(ql_dbg_disc, vha, 0x2017,
4131 "Entries in ID list (%d).\n", entries);
4132 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
4133 (uint8_t *)ha->gid_list,
4134 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135
4136 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004137 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004139 ql_log(ql_log_warn, vha, 0x2018,
4140 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141 rval = QLA_MEMORY_ALLOC_FAILED;
4142 goto cleanup_allocation;
4143 }
4144 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4145
4146 /*
4147 * Mark local devices that were present with FCF_DEVICE_LOST for now.
4148 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004149 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150 if (atomic_read(&fcport->state) == FCS_ONLINE &&
4151 fcport->port_type != FCT_BROADCAST &&
4152 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
4153
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004154 ql_dbg(ql_dbg_disc, vha, 0x2019,
4155 "Marking port lost loop_id=0x%04x.\n",
4156 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157
Quinn Tran41dc5292017-01-19 22:28:03 -08004158 qla2x00_mark_device_lost(vha, fcport, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 }
4160 }
4161
4162 /* Add devices to port list. */
4163 id_iter = (char *)ha->gid_list;
4164 for (index = 0; index < entries; index++) {
4165 domain = ((struct gid_list_info *)id_iter)->domain;
4166 area = ((struct gid_list_info *)id_iter)->area;
4167 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004168 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169 loop_id = (uint16_t)
4170 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004171 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 loop_id = le16_to_cpu(
4173 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004174 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004175
4176 /* Bypass reserved domain fields. */
4177 if ((domain & 0xf0) == 0xf0)
4178 continue;
4179
4180 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004181 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004182 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183 continue;
4184
4185 /* Bypass invalid local loop ID. */
4186 if (loop_id > LAST_LOCAL_LOOP_ID)
4187 continue;
4188
Quinn Tran41dc5292017-01-19 22:28:03 -08004189 memset(new_fcport->port_name, 0, WWN_SIZE);
Arun Easi370d5502012-08-22 14:21:10 -04004190
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191 /* Fill in member data. */
4192 new_fcport->d_id.b.domain = domain;
4193 new_fcport->d_id.b.area = area;
4194 new_fcport->d_id.b.al_pa = al_pa;
4195 new_fcport->loop_id = loop_id;
Quinn Tran41dc5292017-01-19 22:28:03 -08004196
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004197 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004199 ql_dbg(ql_dbg_disc, vha, 0x201a,
4200 "Failed to retrieve fcport information "
4201 "-- get_port_database=%x, loop_id=0x%04x.\n",
4202 rval2, new_fcport->loop_id);
4203 ql_dbg(ql_dbg_disc, vha, 0x201b,
4204 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004205 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206 continue;
4207 }
4208
Quinn Tran41dc5292017-01-19 22:28:03 -08004209 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210 /* Check for matching device in port list. */
4211 found = 0;
4212 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004213 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214 if (memcmp(new_fcport->port_name, fcport->port_name,
4215 WWN_SIZE))
4216 continue;
4217
Shyam Sundarddb9b122009-03-24 09:08:10 -07004218 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219 fcport->loop_id = new_fcport->loop_id;
4220 fcport->port_type = new_fcport->port_type;
4221 fcport->d_id.b24 = new_fcport->d_id.b24;
4222 memcpy(fcport->node_name, new_fcport->node_name,
4223 WWN_SIZE);
4224
Quinn Tran41dc5292017-01-19 22:28:03 -08004225 if (!fcport->login_succ) {
4226 vha->fcport_count++;
4227 fcport->login_succ = 1;
4228 fcport->disc_state = DSC_LOGIN_COMPLETE;
4229 }
4230
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231 found++;
4232 break;
4233 }
4234
4235 if (!found) {
4236 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004237 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238
4239 /* Allocate a new replacement fcport. */
4240 fcport = new_fcport;
Quinn Tran41dc5292017-01-19 22:28:03 -08004241 if (!fcport->login_succ) {
4242 vha->fcport_count++;
4243 fcport->login_succ = 1;
4244 fcport->disc_state = DSC_LOGIN_COMPLETE;
4245 }
4246
4247 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4248
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004249 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Quinn Tran41dc5292017-01-19 22:28:03 -08004250
Linus Torvalds1da177e2005-04-16 15:20:36 -07004251 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004252 ql_log(ql_log_warn, vha, 0x201c,
4253 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254 rval = QLA_MEMORY_ALLOC_FAILED;
4255 goto cleanup_allocation;
4256 }
Quinn Tran41dc5292017-01-19 22:28:03 -08004257 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004258 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4259 }
4260
Quinn Tran41dc5292017-01-19 22:28:03 -08004261 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4262
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004263 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004264 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004265
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004266 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267
4268 found_devs++;
4269 }
4270
4271cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08004272 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004273
4274 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004275 ql_dbg(ql_dbg_disc, vha, 0x201d,
4276 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277 }
4278
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279 return (rval);
4280}
4281
4282static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004283qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004284{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004285 int rval;
Quinn Tran93f2bd62014-09-25 05:16:53 -04004286 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004287 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004288
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07004289 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004290 return;
4291
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07004292 if (atomic_read(&fcport->state) != FCS_ONLINE)
4293 return;
4294
Andrew Vasquez39bd9622007-09-20 14:07:34 -07004295 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
4296 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004297 return;
4298
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004299 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07004300 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004301 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004302 ql_dbg(ql_dbg_disc, vha, 0x2004,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04004303 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
4304 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004305 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004306 ql_dbg(ql_dbg_disc, vha, 0x2005,
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04004307 "iIDMA adjusted to %s GB/s on %8phN.\n",
Joe Carnucciod0297c92012-11-21 02:40:40 -05004308 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Oleksandr Khoshaba7b833552013-08-27 01:37:27 -04004309 fcport->port_name);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004310 }
4311}
4312
Quinn Tran726b8542017-01-19 22:28:00 -08004313/* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
Adrian Bunk23be3312006-11-24 02:46:01 +01004314static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004315qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05004316{
4317 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05004318 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004319 unsigned long flags;
8482e1182005-04-17 15:04:54 -05004320
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07004321 rport_ids.node_name = wwn_to_u64(fcport->node_name);
4322 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05004323 rport_ids.port_id = fcport->d_id.b.domain << 16 |
4324 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
4325 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004326 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07004327 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004328 ql_log(ql_log_warn, vha, 0x2006,
4329 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07004330 return;
4331 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004332
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004333 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04004334 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08004335 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08004336
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004337 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07004338
4339 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05004340 if (fcport->port_type == FCT_INITIATOR)
4341 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
4342 if (fcport->port_type == FCT_TARGET)
4343 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Quinn Tran726b8542017-01-19 22:28:00 -08004344
4345 ql_dbg(ql_dbg_disc, vha, 0xffff,
4346 "%s %8phN. rport %p is %s mode \n",
4347 __func__, fcport->port_name, rport,
4348 (fcport->port_type == FCT_TARGET) ? "tgt" : "ini");
4349
Andrew Vasquez77d74142005-07-08 18:00:36 -07004350 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05004351}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352
4353/*
Adrian Bunk23be3312006-11-24 02:46:01 +01004354 * qla2x00_update_fcport
4355 * Updates device on list.
4356 *
4357 * Input:
4358 * ha = adapter block pointer.
4359 * fcport = port structure pointer.
4360 *
4361 * Return:
4362 * 0 - Success
4363 * BIT_0 - error
4364 *
4365 * Context:
4366 * Kernel context.
4367 */
4368void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004369qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01004370{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004371 fcport->vha = vha;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004372
Quinn Tran726b8542017-01-19 22:28:00 -08004373 if (IS_SW_RESV_ADDR(fcport->d_id))
4374 return;
4375
4376 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %8phC \n",
4377 __func__, fcport->port_name);
4378
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004379 if (IS_QLAFX00(vha->hw)) {
4380 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004381 goto reg_port;
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04004382 }
Adrian Bunk23be3312006-11-24 02:46:01 +01004383 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07004384 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Quinn Tran726b8542017-01-19 22:28:00 -08004385 fcport->disc_state = DSC_LOGIN_COMPLETE;
4386 fcport->deleted = 0;
4387 fcport->logout_on_delete = 1;
Adrian Bunk23be3312006-11-24 02:46:01 +01004388
Joe Carnuccio1f93da522012-11-21 02:40:38 -05004389 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004390 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08004391 qla24xx_update_fcport_fcp_prio(vha, fcport);
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004392
4393reg_port:
Quinn Tran726b8542017-01-19 22:28:00 -08004394 switch (vha->host->active_mode) {
4395 case MODE_INITIATOR:
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004396 qla2x00_reg_remote_port(vha, fcport);
Quinn Tran726b8542017-01-19 22:28:00 -08004397 break;
4398 case MODE_TARGET:
4399 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
4400 !vha->vha_tgt.qla_tgt->tgt_stopped)
4401 qlt_fc_port_added(vha, fcport);
4402 break;
4403 case MODE_DUAL:
4404 qla2x00_reg_remote_port(vha, fcport);
4405 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
4406 !vha->vha_tgt.qla_tgt->tgt_stopped)
4407 qlt_fc_port_added(vha, fcport);
4408 break;
4409 default:
4410 break;
Alexei Potashnikd20ed912015-07-14 16:00:47 -04004411 }
Adrian Bunk23be3312006-11-24 02:46:01 +01004412}
4413
4414/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415 * qla2x00_configure_fabric
4416 * Setup SNS devices with loop ID's.
4417 *
4418 * Input:
4419 * ha = adapter block pointer.
4420 *
4421 * Returns:
4422 * 0 = success.
4423 * BIT_0 = error
4424 */
4425static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004426qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427{
Arun Easib3b02e62012-02-09 11:15:39 -08004428 int rval;
Quinn Tran726b8542017-01-19 22:28:00 -08004429 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004431 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004432 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004433 struct qla_hw_data *ha = vha->hw;
Alexei Potashnikdf673272015-07-14 16:00:46 -04004434 int discovery_gen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435
4436 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07004437 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004438 loop_id = NPH_F_PORT;
4439 else
4440 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004441 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004443 ql_dbg(ql_dbg_disc, vha, 0x201f,
4444 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004446 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004447 return (QLA_SUCCESS);
4448 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004449 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450
Quinn Tran41dc5292017-01-19 22:28:03 -08004451
4452 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
4453 rval = qla2x00_send_change_request(vha, 0x3, 0);
4454 if (rval != QLA_SUCCESS)
4455 ql_log(ql_log_warn, vha, 0x121,
4456 "Failed to enable receiving of RSCN requests: 0x%x.\n",
4457 rval);
4458 }
4459
4460
Linus Torvalds1da177e2005-04-16 15:20:36 -07004461 do {
Quinn Tran726b8542017-01-19 22:28:00 -08004462 qla2x00_mgmt_svr_login(vha);
4463
Andrew Vasquezcca53352005-08-26 19:08:30 -07004464 /* FDMI support. */
4465 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004466 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
4467 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07004468
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07004470 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004471 loop_id = NPH_SNS;
4472 else
4473 loop_id = SIMPLE_NAME_SERVER;
Chad Dupuis0b91d112012-02-09 11:15:42 -08004474 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
4475 0xfc, mb, BIT_1|BIT_0);
4476 if (rval != QLA_SUCCESS) {
4477 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05004478 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08004479 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004481 ql_dbg(ql_dbg_disc, vha, 0x2042,
4482 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
4483 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
4484 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004485 return (QLA_SUCCESS);
4486 }
4487
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004488 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
4489 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004491 ql_dbg(ql_dbg_disc, vha, 0x2045,
4492 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004493 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004494 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004495 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004496 ql_dbg(ql_dbg_disc, vha, 0x2049,
4497 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004498 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004499 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004500 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004501 ql_dbg(ql_dbg_disc, vha, 0x204f,
4502 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004503 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004504 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004505 ql_dbg(ql_dbg_disc, vha, 0x2053,
4506 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507 }
4508 }
4509
Joe Carnuccio827210b2013-02-08 01:57:57 -05004510 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4511 fcport->scan_state = QLA_FCPORT_SCAN;
4512 }
4513
Alexei Potashnikdf673272015-07-14 16:00:46 -04004514 /* Mark the time right before querying FW for connected ports.
4515 * This process is long, asynchronous and by the time it's done,
4516 * collected information might not be accurate anymore. E.g.
4517 * disconnected port might have re-connected and a brand new
4518 * session has been created. In this case session's generation
4519 * will be newer than discovery_gen. */
4520 qlt_do_generation_tick(vha, &discovery_gen);
4521
Quinn Tran726b8542017-01-19 22:28:00 -08004522 rval = qla2x00_find_all_fabric_devs(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523 if (rval != QLA_SUCCESS)
4524 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004525 } while (0);
4526
Quinn Tran726b8542017-01-19 22:28:00 -08004527 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004528 ql_dbg(ql_dbg_disc, vha, 0x2068,
4529 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530
4531 return (rval);
4532}
4533
Linus Torvalds1da177e2005-04-16 15:20:36 -07004534/*
4535 * qla2x00_find_all_fabric_devs
4536 *
4537 * Input:
4538 * ha = adapter block pointer.
4539 * dev = database device entry pointer.
4540 *
4541 * Returns:
4542 * 0 = success.
4543 *
4544 * Context:
4545 * Kernel context.
4546 */
4547static int
Quinn Tran726b8542017-01-19 22:28:00 -08004548qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004549{
4550 int rval;
4551 uint16_t loop_id;
Quinn Tran726b8542017-01-19 22:28:00 -08004552 fc_port_t *fcport, *new_fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004553 int found;
4554
4555 sw_info_t *swl;
4556 int swl_idx;
4557 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07004558 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004559 struct qla_hw_data *ha = vha->hw;
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05004560 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tran726b8542017-01-19 22:28:00 -08004561 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562
4563 rval = QLA_SUCCESS;
4564
4565 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08004566 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08004567 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08004568 GFP_KERNEL);
4569 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02004570 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004571 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004572 ql_dbg(ql_dbg_disc, vha, 0x2054,
4573 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08004575 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004576 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004578 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004580 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581 swl = NULL;
Quinn Tran726b8542017-01-19 22:28:00 -08004582 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
4583 swl = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004584 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004585
4586 /* If other queries succeeded probe for FC-4 type */
4587 if (swl)
4588 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004589 }
4590 swl_idx = 0;
4591
4592 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004593 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004594 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004595 ql_log(ql_log_warn, vha, 0x205e,
4596 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004597 return (QLA_MEMORY_ALLOC_FAILED);
4598 }
4599 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004600 /* Set start port ID scan at adapter ID. */
4601 first_dev = 1;
4602 last_dev = 0;
4603
4604 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004605 loop_id = ha->min_external_loopid;
4606 for (; loop_id <= ha->max_loop_id; loop_id++) {
4607 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004608 continue;
4609
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07004610 if (ha->current_topology == ISP_CFG_FL &&
4611 (atomic_read(&vha->loop_down_timer) ||
4612 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08004613 atomic_set(&vha->loop_down_timer, 0);
4614 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4615 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08004617 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004618
4619 if (swl != NULL) {
4620 if (last_dev) {
4621 wrap.b24 = new_fcport->d_id.b24;
4622 } else {
4623 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
4624 memcpy(new_fcport->node_name,
4625 swl[swl_idx].node_name, WWN_SIZE);
4626 memcpy(new_fcport->port_name,
4627 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004628 memcpy(new_fcport->fabric_port_name,
4629 swl[swl_idx].fabric_port_name, WWN_SIZE);
4630 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004631 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004632
4633 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
4634 last_dev = 1;
4635 }
4636 swl_idx++;
4637 }
4638 } else {
4639 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004640 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004641 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004642 ql_log(ql_log_warn, vha, 0x2064,
4643 "SNS scan failed -- assuming "
4644 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645 rval = QLA_SUCCESS;
4646 break;
4647 }
4648 }
4649
4650 /* If wrap on switch device list, exit. */
4651 if (first_dev) {
4652 wrap.b24 = new_fcport->d_id.b24;
4653 first_dev = 0;
4654 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004655 ql_dbg(ql_dbg_disc, vha, 0x2065,
4656 "Device wrap (%02x%02x%02x).\n",
4657 new_fcport->d_id.b.domain,
4658 new_fcport->d_id.b.area,
4659 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 break;
4661 }
4662
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004663 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004664 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 continue;
4666
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004667 /* Bypass virtual ports of the same host. */
Chad Dupuisbb4cf5b2013-02-08 01:58:01 -05004668 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
4669 continue;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004670
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004671 /* Bypass if same domain and area of adapter. */
4672 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004673 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07004674 ISP_CFG_FL)
4675 continue;
4676
Linus Torvalds1da177e2005-04-16 15:20:36 -07004677 /* Bypass reserved domain fields. */
4678 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
4679 continue;
4680
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004681 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07004682 if (ql2xgffidenable &&
4683 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
4684 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05004685 continue;
4686
Quinn Tran726b8542017-01-19 22:28:00 -08004687 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4688
Linus Torvalds1da177e2005-04-16 15:20:36 -07004689 /* Locate matching device in database. */
4690 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004691 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004692 if (memcmp(new_fcport->port_name, fcport->port_name,
4693 WWN_SIZE))
4694 continue;
4695
Joe Carnuccio827210b2013-02-08 01:57:57 -05004696 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08004697
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698 found++;
4699
Andrew Vasquezd8b45212006-10-02 12:00:43 -07004700 /* Update port state. */
4701 memcpy(fcport->fabric_port_name,
4702 new_fcport->fabric_port_name, WWN_SIZE);
4703 fcport->fp_speed = new_fcport->fp_speed;
4704
Linus Torvalds1da177e2005-04-16 15:20:36 -07004705 /*
Roland Dreierb2032fd2015-07-14 16:00:42 -04004706 * If address the same and state FCS_ONLINE
4707 * (or in target mode), nothing changed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708 */
4709 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
Roland Dreierb2032fd2015-07-14 16:00:42 -04004710 (atomic_read(&fcport->state) == FCS_ONLINE ||
Quinn Tran726b8542017-01-19 22:28:00 -08004711 (vha->host->active_mode == MODE_TARGET))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712 break;
4713 }
4714
4715 /*
4716 * If device was not a fabric device before.
4717 */
4718 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
4719 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04004720 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721 fcport->flags |= (FCF_FABRIC_DEVICE |
4722 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723 break;
4724 }
4725
4726 /*
4727 * Port ID changed or device was marked to be updated;
4728 * Log it out if still logged in and mark it for
4729 * relogin later.
4730 */
Quinn Tran726b8542017-01-19 22:28:00 -08004731 if (qla_tgt_mode_enabled(base_vha)) {
Roland Dreierb2032fd2015-07-14 16:00:42 -04004732 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
4733 "port changed FC ID, %8phC"
4734 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
4735 fcport->port_name,
4736 fcport->d_id.b.domain,
4737 fcport->d_id.b.area,
4738 fcport->d_id.b.al_pa,
4739 fcport->loop_id,
4740 new_fcport->d_id.b.domain,
4741 new_fcport->d_id.b.area,
4742 new_fcport->d_id.b.al_pa);
4743 fcport->d_id.b24 = new_fcport->d_id.b24;
4744 break;
4745 }
4746
Linus Torvalds1da177e2005-04-16 15:20:36 -07004747 fcport->d_id.b24 = new_fcport->d_id.b24;
4748 fcport->flags |= FCF_LOGIN_NEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749 break;
4750 }
4751
Quinn Tran726b8542017-01-19 22:28:00 -08004752 if (found) {
4753 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754 continue;
Quinn Tran726b8542017-01-19 22:28:00 -08004755 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004756 /* If device was not in our fcports list, then add it. */
Roland Dreierb2032fd2015-07-14 16:00:42 -04004757 new_fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tran726b8542017-01-19 22:28:00 -08004758 list_add_tail(&new_fcport->list, &vha->vp_fcports);
4759
4760 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4761
Linus Torvalds1da177e2005-04-16 15:20:36 -07004762
4763 /* Allocate a new replacement fcport. */
4764 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004765 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004766 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004767 ql_log(ql_log_warn, vha, 0x2066,
4768 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004769 return (QLA_MEMORY_ALLOC_FAILED);
4770 }
4771 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
4772 new_fcport->d_id.b24 = nxt_d_id.b24;
4773 }
4774
Quinn Tran726b8542017-01-19 22:28:00 -08004775 qla2x00_free_fcport(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004776
Quinn Tran726b8542017-01-19 22:28:00 -08004777 /*
4778 * Logout all previous fabric dev marked lost, except FCP2 devices.
4779 */
4780 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4781 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4782 break;
4783
4784 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
4785 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
4786 continue;
4787
4788 if (fcport->scan_state == QLA_FCPORT_SCAN) {
4789 if ((qla_dual_mode_enabled(vha) ||
4790 qla_ini_mode_enabled(vha)) &&
4791 atomic_read(&fcport->state) == FCS_ONLINE) {
4792 qla2x00_mark_device_lost(vha, fcport,
4793 ql2xplogiabsentdevice, 0);
4794 if (fcport->loop_id != FC_NO_LOOP_ID &&
4795 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
4796 fcport->port_type != FCT_INITIATOR &&
4797 fcport->port_type != FCT_BROADCAST) {
4798 ql_dbg(ql_dbg_disc, vha, 0xffff,
4799 "%s %d %8phC post del sess\n",
4800 __func__, __LINE__,
4801 fcport->port_name);
4802
4803 qlt_schedule_sess_for_deletion_lock
4804 (fcport);
4805 continue;
4806 }
4807 }
4808 }
4809
4810 if (fcport->scan_state == QLA_FCPORT_FOUND)
4811 qla24xx_fcport_handle_login(vha, fcport);
4812 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004813 return (rval);
4814}
4815
4816/*
4817 * qla2x00_find_new_loop_id
4818 * Scan through our port list and find a new usable loop ID.
4819 *
4820 * Input:
4821 * ha: adapter state pointer.
4822 * dev: port structure pointer.
4823 *
4824 * Returns:
4825 * qla2x00 local function return status code.
4826 *
4827 * Context:
4828 * Kernel context.
4829 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07004830int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004831qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832{
4833 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004834 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07004835 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836
4837 rval = QLA_SUCCESS;
4838
Chad Dupuis5f16b332012-08-22 14:21:00 -04004839 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004840
Chad Dupuis5f16b332012-08-22 14:21:00 -04004841 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
4842 LOOPID_MAP_SIZE);
4843 if (dev->loop_id >= LOOPID_MAP_SIZE ||
4844 qla2x00_is_reserved_id(vha, dev->loop_id)) {
4845 dev->loop_id = FC_NO_LOOP_ID;
4846 rval = QLA_FUNCTION_FAILED;
4847 } else
4848 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004849
Chad Dupuis5f16b332012-08-22 14:21:00 -04004850 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004851
Chad Dupuis5f16b332012-08-22 14:21:00 -04004852 if (rval == QLA_SUCCESS)
4853 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
4854 "Assigning new loopid=%x, portid=%x.\n",
4855 dev->loop_id, dev->d_id.b24);
4856 else
4857 ql_log(ql_log_warn, dev->vha, 0x2087,
4858 "No loop_id's available, portid=%x.\n",
4859 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004860
4861 return (rval);
4862}
4863
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864
4865/*
4866 * qla2x00_fabric_login
4867 * Issue fabric login command.
4868 *
4869 * Input:
4870 * ha = adapter block pointer.
4871 * device = pointer to FC device type structure.
4872 *
4873 * Returns:
4874 * 0 - Login successfully
4875 * 1 - Login failed
4876 * 2 - Initiator device
4877 * 3 - Fatal error
4878 */
4879int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004880qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881 uint16_t *next_loopid)
4882{
4883 int rval;
4884 int retry;
4885 uint16_t tmp_loopid;
4886 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004887 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004888
4889 retry = 0;
4890 tmp_loopid = 0;
4891
4892 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004893 ql_dbg(ql_dbg_disc, vha, 0x2000,
4894 "Trying Fabric Login w/loop id 0x%04x for port "
4895 "%02x%02x%02x.\n",
4896 fcport->loop_id, fcport->d_id.b.domain,
4897 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898
4899 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08004900 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004901 fcport->d_id.b.domain, fcport->d_id.b.area,
4902 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08004903 if (rval != QLA_SUCCESS) {
4904 return rval;
4905 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004906 if (mb[0] == MBS_PORT_ID_USED) {
4907 /*
4908 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004909 * recommends the driver perform an implicit login with
4910 * the specified ID again. The ID we just used is save
4911 * here so we return with an ID that can be tried by
4912 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913 */
4914 retry++;
4915 tmp_loopid = fcport->loop_id;
4916 fcport->loop_id = mb[1];
4917
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004918 ql_dbg(ql_dbg_disc, vha, 0x2001,
4919 "Fabric Login: port in use - next loop "
4920 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004921 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004922 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004923
4924 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
4925 /*
4926 * Login succeeded.
4927 */
4928 if (retry) {
4929 /* A retry occurred before. */
4930 *next_loopid = tmp_loopid;
4931 } else {
4932 /*
4933 * No retry occurred before. Just increment the
4934 * ID value for next login.
4935 */
4936 *next_loopid = (fcport->loop_id + 1);
4937 }
4938
4939 if (mb[1] & BIT_0) {
4940 fcport->port_type = FCT_INITIATOR;
4941 } else {
4942 fcport->port_type = FCT_TARGET;
4943 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07004944 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004945 }
4946 }
4947
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07004948 if (mb[10] & BIT_0)
4949 fcport->supported_classes |= FC_COS_CLASS2;
4950 if (mb[10] & BIT_1)
4951 fcport->supported_classes |= FC_COS_CLASS3;
4952
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004953 if (IS_FWI2_CAPABLE(ha)) {
4954 if (mb[10] & BIT_7)
4955 fcport->flags |=
4956 FCF_CONF_COMP_SUPPORTED;
4957 }
4958
Linus Torvalds1da177e2005-04-16 15:20:36 -07004959 rval = QLA_SUCCESS;
4960 break;
4961 } else if (mb[0] == MBS_LOOP_ID_USED) {
4962 /*
4963 * Loop ID already used, try next loop ID.
4964 */
4965 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004966 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967 if (rval != QLA_SUCCESS) {
4968 /* Ran out of loop IDs to use */
4969 break;
4970 }
4971 } else if (mb[0] == MBS_COMMAND_ERROR) {
4972 /*
4973 * Firmware possibly timed out during login. If NO
4974 * retries are left to do then the device is declared
4975 * dead.
4976 */
4977 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004978 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07004979 fcport->d_id.b.domain, fcport->d_id.b.area,
4980 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004981 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004982
4983 rval = 1;
4984 break;
4985 } else {
4986 /*
4987 * unrecoverable / not handled error
4988 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004989 ql_dbg(ql_dbg_disc, vha, 0x2002,
4990 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
4991 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
4992 fcport->d_id.b.area, fcport->d_id.b.al_pa,
4993 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994
4995 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004996 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07004997 fcport->d_id.b.domain, fcport->d_id.b.area,
4998 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04004999 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07005000 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001
5002 rval = 3;
5003 break;
5004 }
5005 }
5006
5007 return (rval);
5008}
5009
5010/*
5011 * qla2x00_local_device_login
5012 * Issue local device login command.
5013 *
5014 * Input:
5015 * ha = adapter block pointer.
5016 * loop_id = loop id of device to login to.
5017 *
5018 * Returns (Where's the #define!!!!):
5019 * 0 - Login successfully
5020 * 1 - Login failed
5021 * 3 - Fatal error
5022 */
5023int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005024qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025{
5026 int rval;
5027 uint16_t mb[MAILBOX_REGISTER_COUNT];
5028
5029 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005030 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031 if (rval == QLA_SUCCESS) {
5032 /* Interrogate mailbox registers for any errors */
5033 if (mb[0] == MBS_COMMAND_ERROR)
5034 rval = 1;
5035 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
5036 /* device not in PCB table */
5037 rval = 3;
5038 }
5039
5040 return (rval);
5041}
5042
5043/*
5044 * qla2x00_loop_resync
5045 * Resync with fibre channel devices.
5046 *
5047 * Input:
5048 * ha = adapter block pointer.
5049 *
5050 * Returns:
5051 * 0 = success
5052 */
5053int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005054qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005055{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005056 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005058 struct req_que *req;
5059 struct rsp_que *rsp;
5060
Michael Hernandezd7459522016-12-12 14:40:07 -08005061 req = vha->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005062 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005063
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005064 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5065 if (vha->flags.online) {
5066 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005067 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5068 wait_time = 256;
5069 do {
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005070 if (!IS_QLAFX00(vha->hw)) {
5071 /*
5072 * Issue a marker after FW becomes
5073 * ready.
5074 */
5075 qla2x00_marker(vha, req, rsp, 0, 0,
5076 MK_SYNC_ALL);
5077 vha->marker_needed = 0;
5078 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005079
5080 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005081 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005082
Giridhar Malavali8ae6d9c2013-03-28 08:21:23 -04005083 if (IS_QLAFX00(vha->hw))
5084 qlafx00_configure_devices(vha);
5085 else
5086 qla2x00_configure_loop(vha);
5087
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005089 } while (!atomic_read(&vha->loop_down_timer) &&
5090 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5091 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
5092 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005094 }
5095
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005096 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005097 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005098
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005099 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005100 ql_dbg(ql_dbg_disc, vha, 0x206c,
5101 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102
5103 return (rval);
5104}
5105
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005106/*
5107* qla2x00_perform_loop_resync
5108* Description: This function will set the appropriate flags and call
5109* qla2x00_loop_resync. If successful loop will be resynced
5110* Arguments : scsi_qla_host_t pointer
5111* returm : Success or Failure
5112*/
5113
5114int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
5115{
5116 int32_t rval = 0;
5117
5118 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
5119 /*Configure the flags so that resync happens properly*/
5120 atomic_set(&ha->loop_down_timer, 0);
5121 if (!(ha->device_flags & DFLG_NO_CABLE)) {
5122 atomic_set(&ha->loop_state, LOOP_UP);
5123 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
5124 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
5125 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
5126
5127 rval = qla2x00_loop_resync(ha);
5128 } else
5129 atomic_set(&ha->loop_state, LOOP_DEAD);
5130
5131 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
5132 }
5133
5134 return rval;
5135}
5136
Linus Torvalds1da177e2005-04-16 15:20:36 -07005137void
Andrew Vasquez67becc02009-08-25 11:36:20 -07005138qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005139{
5140 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07005141 struct scsi_qla_host *vha;
5142 struct qla_hw_data *ha = base_vha->hw;
5143 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005144
Arun Easifeafb7b2010-09-03 14:57:00 -07005145 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005146 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07005147 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
5148 atomic_inc(&vha->vref_count);
5149 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08005150 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07005151 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
5152 spin_unlock_irqrestore(&ha->vport_slock, flags);
Andrew Vasquez67becc02009-08-25 11:36:20 -07005153 qla2x00_rport_del(fcport);
Alexei Potashnikdf673272015-07-14 16:00:46 -04005154
Arun Easifeafb7b2010-09-03 14:57:00 -07005155 spin_lock_irqsave(&ha->vport_slock, flags);
5156 }
5157 }
5158 atomic_dec(&vha->vref_count);
Joe Carnuccioc4a9b532017-03-15 09:48:43 -07005159 wake_up(&vha->vref_waitq);
Arun Easifeafb7b2010-09-03 14:57:00 -07005160 }
5161 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08005162}
5163
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005164/* Assumes idc_lock always held on entry */
5165void
5166qla83xx_reset_ownership(scsi_qla_host_t *vha)
5167{
5168 struct qla_hw_data *ha = vha->hw;
5169 uint32_t drv_presence, drv_presence_mask;
5170 uint32_t dev_part_info1, dev_part_info2, class_type;
5171 uint32_t class_type_mask = 0x3;
5172 uint16_t fcoe_other_function = 0xffff, i;
5173
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005174 if (IS_QLA8044(ha)) {
5175 drv_presence = qla8044_rd_direct(vha,
5176 QLA8044_CRB_DRV_ACTIVE_INDEX);
5177 dev_part_info1 = qla8044_rd_direct(vha,
5178 QLA8044_CRB_DEV_PART_INFO_INDEX);
5179 dev_part_info2 = qla8044_rd_direct(vha,
5180 QLA8044_CRB_DEV_PART_INFO2);
5181 } else {
5182 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5183 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
5184 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
5185 }
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005186 for (i = 0; i < 8; i++) {
5187 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
5188 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5189 (i != ha->portnum)) {
5190 fcoe_other_function = i;
5191 break;
5192 }
5193 }
5194 if (fcoe_other_function == 0xffff) {
5195 for (i = 0; i < 8; i++) {
5196 class_type = ((dev_part_info2 >> (i * 4)) &
5197 class_type_mask);
5198 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5199 ((i + 8) != ha->portnum)) {
5200 fcoe_other_function = i + 8;
5201 break;
5202 }
5203 }
5204 }
5205 /*
5206 * Prepare drv-presence mask based on fcoe functions present.
5207 * However consider only valid physical fcoe function numbers (0-15).
5208 */
5209 drv_presence_mask = ~((1 << (ha->portnum)) |
5210 ((fcoe_other_function == 0xffff) ?
5211 0 : (1 << (fcoe_other_function))));
5212
5213 /* We are the reset owner iff:
5214 * - No other protocol drivers present.
5215 * - This is the lowest among fcoe functions. */
5216 if (!(drv_presence & drv_presence_mask) &&
5217 (ha->portnum < fcoe_other_function)) {
5218 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
5219 "This host is Reset owner.\n");
5220 ha->flags.nic_core_reset_owner = 1;
5221 }
5222}
5223
Saurav Kashyapfa492632012-11-21 02:40:29 -05005224static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005225__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
5226{
5227 int rval = QLA_SUCCESS;
5228 struct qla_hw_data *ha = vha->hw;
5229 uint32_t drv_ack;
5230
5231 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5232 if (rval == QLA_SUCCESS) {
5233 drv_ack |= (1 << ha->portnum);
5234 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5235 }
5236
5237 return rval;
5238}
5239
Saurav Kashyapfa492632012-11-21 02:40:29 -05005240static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005241__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
5242{
5243 int rval = QLA_SUCCESS;
5244 struct qla_hw_data *ha = vha->hw;
5245 uint32_t drv_ack;
5246
5247 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
5248 if (rval == QLA_SUCCESS) {
5249 drv_ack &= ~(1 << ha->portnum);
5250 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
5251 }
5252
5253 return rval;
5254}
5255
Saurav Kashyapfa492632012-11-21 02:40:29 -05005256static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005257qla83xx_dev_state_to_string(uint32_t dev_state)
5258{
5259 switch (dev_state) {
5260 case QLA8XXX_DEV_COLD:
5261 return "COLD/RE-INIT";
5262 case QLA8XXX_DEV_INITIALIZING:
5263 return "INITIALIZING";
5264 case QLA8XXX_DEV_READY:
5265 return "READY";
5266 case QLA8XXX_DEV_NEED_RESET:
5267 return "NEED RESET";
5268 case QLA8XXX_DEV_NEED_QUIESCENT:
5269 return "NEED QUIESCENT";
5270 case QLA8XXX_DEV_FAILED:
5271 return "FAILED";
5272 case QLA8XXX_DEV_QUIESCENT:
5273 return "QUIESCENT";
5274 default:
5275 return "Unknown";
5276 }
5277}
5278
5279/* Assumes idc-lock always held on entry */
5280void
5281qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
5282{
5283 struct qla_hw_data *ha = vha->hw;
5284 uint32_t idc_audit_reg = 0, duration_secs = 0;
5285
5286 switch (audit_type) {
5287 case IDC_AUDIT_TIMESTAMP:
5288 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
5289 idc_audit_reg = (ha->portnum) |
5290 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
5291 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5292 break;
5293
5294 case IDC_AUDIT_COMPLETION:
5295 duration_secs = ((jiffies_to_msecs(jiffies) -
5296 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
5297 idc_audit_reg = (ha->portnum) |
5298 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
5299 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
5300 break;
5301
5302 default:
5303 ql_log(ql_log_warn, vha, 0xb078,
5304 "Invalid audit type specified.\n");
5305 break;
5306 }
5307}
5308
5309/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05005310static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005311qla83xx_initiating_reset(scsi_qla_host_t *vha)
5312{
5313 struct qla_hw_data *ha = vha->hw;
5314 uint32_t idc_control, dev_state;
5315
5316 __qla83xx_get_idc_control(vha, &idc_control);
5317 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
5318 ql_log(ql_log_info, vha, 0xb080,
5319 "NIC Core reset has been disabled. idc-control=0x%x\n",
5320 idc_control);
5321 return QLA_FUNCTION_FAILED;
5322 }
5323
5324 /* Set NEED-RESET iff in READY state and we are the reset-owner */
5325 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5326 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
5327 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
5328 QLA8XXX_DEV_NEED_RESET);
5329 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
5330 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
5331 } else {
5332 const char *state = qla83xx_dev_state_to_string(dev_state);
5333 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
5334
5335 /* SV: XXX: Is timeout required here? */
5336 /* Wait for IDC state change READY -> NEED_RESET */
5337 while (dev_state == QLA8XXX_DEV_READY) {
5338 qla83xx_idc_unlock(vha, 0);
5339 msleep(200);
5340 qla83xx_idc_lock(vha, 0);
5341 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
5342 }
5343 }
5344
5345 /* Send IDC ack by writing to drv-ack register */
5346 __qla83xx_set_drv_ack(vha);
5347
5348 return QLA_SUCCESS;
5349}
5350
5351int
5352__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
5353{
5354 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5355}
5356
5357int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005358__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
5359{
5360 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
5361}
5362
Saurav Kashyapfa492632012-11-21 02:40:29 -05005363static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005364qla83xx_check_driver_presence(scsi_qla_host_t *vha)
5365{
5366 uint32_t drv_presence = 0;
5367 struct qla_hw_data *ha = vha->hw;
5368
5369 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5370 if (drv_presence & (1 << ha->portnum))
5371 return QLA_SUCCESS;
5372 else
5373 return QLA_TEST_FAILED;
5374}
5375
5376int
5377qla83xx_nic_core_reset(scsi_qla_host_t *vha)
5378{
5379 int rval = QLA_SUCCESS;
5380 struct qla_hw_data *ha = vha->hw;
5381
5382 ql_dbg(ql_dbg_p3p, vha, 0xb058,
5383 "Entered %s().\n", __func__);
5384
5385 if (vha->device_flags & DFLG_DEV_FAILED) {
5386 ql_log(ql_log_warn, vha, 0xb059,
5387 "Device in unrecoverable FAILED state.\n");
5388 return QLA_FUNCTION_FAILED;
5389 }
5390
5391 qla83xx_idc_lock(vha, 0);
5392
5393 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
5394 ql_log(ql_log_warn, vha, 0xb05a,
5395 "Function=0x%x has been removed from IDC participation.\n",
5396 ha->portnum);
5397 rval = QLA_FUNCTION_FAILED;
5398 goto exit;
5399 }
5400
5401 qla83xx_reset_ownership(vha);
5402
5403 rval = qla83xx_initiating_reset(vha);
5404
5405 /*
5406 * Perform reset if we are the reset-owner,
5407 * else wait till IDC state changes to READY/FAILED.
5408 */
5409 if (rval == QLA_SUCCESS) {
5410 rval = qla83xx_idc_state_handler(vha);
5411
5412 if (rval == QLA_SUCCESS)
5413 ha->flags.nic_core_hung = 0;
5414 __qla83xx_clear_drv_ack(vha);
5415 }
5416
5417exit:
5418 qla83xx_idc_unlock(vha, 0);
5419
5420 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
5421
5422 return rval;
5423}
5424
Saurav Kashyap81178772012-08-22 14:21:04 -04005425int
5426qla2xxx_mctp_dump(scsi_qla_host_t *vha)
5427{
5428 struct qla_hw_data *ha = vha->hw;
5429 int rval = QLA_FUNCTION_FAILED;
5430
5431 if (!IS_MCTP_CAPABLE(ha)) {
5432 /* This message can be removed from the final version */
5433 ql_log(ql_log_info, vha, 0x506d,
5434 "This board is not MCTP capable\n");
5435 return rval;
5436 }
5437
5438 if (!ha->mctp_dump) {
5439 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
5440 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
5441
5442 if (!ha->mctp_dump) {
5443 ql_log(ql_log_warn, vha, 0x506e,
5444 "Failed to allocate memory for mctp dump\n");
5445 return rval;
5446 }
5447 }
5448
5449#define MCTP_DUMP_STR_ADDR 0x00000000
5450 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
5451 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
5452 if (rval != QLA_SUCCESS) {
5453 ql_log(ql_log_warn, vha, 0x506f,
5454 "Failed to capture mctp dump\n");
5455 } else {
5456 ql_log(ql_log_info, vha, 0x5070,
5457 "Mctp dump capture for host (%ld/%p).\n",
5458 vha->host_no, ha->mctp_dump);
5459 ha->mctp_dumped = 1;
5460 }
5461
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04005462 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04005463 ha->flags.nic_core_reset_hdlr_active = 1;
5464 rval = qla83xx_restart_nic_firmware(vha);
5465 if (rval)
5466 /* NIC Core reset failed. */
5467 ql_log(ql_log_warn, vha, 0x5071,
5468 "Failed to restart nic firmware\n");
5469 else
5470 ql_dbg(ql_dbg_p3p, vha, 0xb084,
5471 "Restarted NIC firmware successfully.\n");
5472 ha->flags.nic_core_reset_hdlr_active = 0;
5473 }
5474
5475 return rval;
5476
5477}
5478
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005479/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005480* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005481* Description: This function will block the new I/Os
5482* Its not aborting any I/Os as context
5483* is not destroyed during quiescence
5484* Arguments: scsi_qla_host_t
5485* return : void
5486*/
5487void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005488qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005489{
5490 struct qla_hw_data *ha = vha->hw;
5491 struct scsi_qla_host *vp;
5492
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005493 ql_dbg(ql_dbg_dpc, vha, 0x401d,
5494 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005495
5496 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
5497 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
5498 atomic_set(&vha->loop_state, LOOP_DOWN);
5499 qla2x00_mark_all_devices_lost(vha, 0);
5500 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04005501 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005502 } else {
5503 if (!atomic_read(&vha->loop_down_timer))
5504 atomic_set(&vha->loop_down_timer,
5505 LOOP_DOWN_TIME);
5506 }
5507 /* Wait for pending cmds to complete */
5508 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
5509}
5510
Giridhar Malavalia9083012010-04-12 17:59:55 -07005511void
5512qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
5513{
5514 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005515 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005516 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08005517 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005518
Saurav Kashyape46ef002011-02-23 15:27:16 -08005519 /* For ISP82XX, driver waits for completion of the commands.
5520 * online flag should be set.
5521 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005522 if (!(IS_P3P_TYPE(ha)))
Saurav Kashyape46ef002011-02-23 15:27:16 -08005523 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005524 ha->flags.chip_reset_done = 0;
5525 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04005526 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005527
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005528 ql_log(ql_log_info, vha, 0x00af,
5529 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005530
Saurav Kashyape46ef002011-02-23 15:27:16 -08005531 /* For ISP82XX, reset_chip is just disabling interrupts.
5532 * Driver waits for the completion of the commands.
5533 * the interrupts need to be enabled.
5534 */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005535 if (!(IS_P3P_TYPE(ha)))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005536 ha->isp_ops->reset_chip(vha);
5537
Quinn Tran726b8542017-01-19 22:28:00 -08005538 ha->chip_reset++;
5539
Giridhar Malavalia9083012010-04-12 17:59:55 -07005540 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
5541 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
5542 atomic_set(&vha->loop_state, LOOP_DOWN);
5543 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07005544
5545 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08005546 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07005547 atomic_inc(&vp->vref_count);
5548 spin_unlock_irqrestore(&ha->vport_slock, flags);
5549
Giridhar Malavalia9083012010-04-12 17:59:55 -07005550 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07005551
5552 spin_lock_irqsave(&ha->vport_slock, flags);
5553 atomic_dec(&vp->vref_count);
5554 }
5555 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005556 } else {
5557 if (!atomic_read(&vha->loop_down_timer))
5558 atomic_set(&vha->loop_down_timer,
5559 LOOP_DOWN_TIME);
5560 }
5561
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08005562 /* Clear all async request states across all VPs. */
5563 list_for_each_entry(fcport, &vha->vp_fcports, list)
5564 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5565 spin_lock_irqsave(&ha->vport_slock, flags);
5566 list_for_each_entry(vp, &ha->vp_list, list) {
5567 atomic_inc(&vp->vref_count);
5568 spin_unlock_irqrestore(&ha->vport_slock, flags);
5569
5570 list_for_each_entry(fcport, &vp->vp_fcports, list)
5571 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5572
5573 spin_lock_irqsave(&ha->vport_slock, flags);
5574 atomic_dec(&vp->vref_count);
5575 }
5576 spin_unlock_irqrestore(&ha->vport_slock, flags);
5577
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005578 if (!ha->flags.eeh_busy) {
5579 /* Make sure for ISP 82XX IO DMA is complete */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005580 if (IS_P3P_TYPE(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08005581 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005582 ql_log(ql_log_info, vha, 0x00b4,
5583 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005584
Saurav Kashyape46ef002011-02-23 15:27:16 -08005585 /* Done waiting for pending commands.
5586 * Reset the online flag.
5587 */
5588 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005589 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005590
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07005591 /* Requeue all commands in outstanding command list. */
5592 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
5593 }
Arun Easib6a029e2014-09-25 06:14:52 -04005594 /* memory barrier */
5595 wmb();
Linus Torvalds1da177e2005-04-16 15:20:36 -07005596}
5597
5598/*
5599* qla2x00_abort_isp
5600* Resets ISP and aborts all outstanding commands.
5601*
5602* Input:
5603* ha = adapter block pointer.
5604*
5605* Returns:
5606* 0 = success
5607*/
5608int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005609qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005610{
Andrew Vasquez476e8972006-08-23 14:54:55 -07005611 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005612 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005613 struct qla_hw_data *ha = vha->hw;
5614 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005615 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07005616 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005617
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005618 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07005619 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005620
Santosh Vernekara61712972012-08-22 14:21:13 -04005621 if (IS_QLA8031(ha)) {
5622 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
5623 "Clearing fcoe driver presence.\n");
5624 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
5625 ql_dbg(ql_dbg_p3p, vha, 0xb073,
5626 "Error while clearing DRV-Presence.\n");
5627 }
5628
Andrew Vasquez85880802009-12-15 21:29:46 -08005629 if (unlikely(pci_channel_offline(ha->pdev) &&
5630 ha->flags.pci_channel_io_perm_failure)) {
5631 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5632 status = 0;
5633 return status;
5634 }
5635
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005636 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08005637
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005638 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005639
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005640 if (!qla2x00_restart_isp(vha)) {
5641 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005642
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005643 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005644 /*
5645 * Issue marker command only when we are going
5646 * to start the I/O .
5647 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005648 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005649 }
5650
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005651 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005652
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005653 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005654
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07005655 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005656 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07005657
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005658 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
5659 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08005660 if (ha->fce) {
5661 ha->flags.fce_enabled = 1;
5662 memset(ha->fce, 0,
5663 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005664 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08005665 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5666 &ha->fce_bufs);
5667 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005668 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08005669 "Unable to reinitialize FCE "
5670 "(%d).\n", rval);
5671 ha->flags.fce_enabled = 0;
5672 }
5673 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07005674
5675 if (ha->eft) {
5676 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005677 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07005678 ha->eft_dma, EFT_NUM_BUFFERS);
5679 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005680 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07005681 "Unable to reinitialize EFT "
5682 "(%d).\n", rval);
5683 }
5684 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005685 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005686 vha->flags.online = 1;
5687 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005688 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005689 ql_log(ql_log_fatal, vha, 0x8035,
5690 "ISP error recover failed - "
5691 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07005692 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005693 * The next call disables the board
5694 * completely.
5695 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005696 ha->isp_ops->reset_adapter(vha);
5697 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005698 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005699 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005700 status = 0;
5701 } else { /* schedule another ISP abort */
5702 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005703 ql_dbg(ql_dbg_taskm, vha, 0x8020,
5704 "ISP abort - retry remaining %d.\n",
5705 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005706 status = 1;
5707 }
5708 } else {
5709 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005710 ql_dbg(ql_dbg_taskm, vha, 0x8021,
5711 "ISP error recovery - retrying (%d) "
5712 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005713 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005714 status = 1;
5715 }
5716 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07005717
Linus Torvalds1da177e2005-04-16 15:20:36 -07005718 }
5719
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005720 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005721 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07005722
5723 spin_lock_irqsave(&ha->vport_slock, flags);
5724 list_for_each_entry(vp, &ha->vp_list, list) {
5725 if (vp->vp_idx) {
5726 atomic_inc(&vp->vref_count);
5727 spin_unlock_irqrestore(&ha->vport_slock, flags);
5728
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005729 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07005730
5731 spin_lock_irqsave(&ha->vport_slock, flags);
5732 atomic_dec(&vp->vref_count);
5733 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005734 }
Arun Easifeafb7b2010-09-03 14:57:00 -07005735 spin_unlock_irqrestore(&ha->vport_slock, flags);
5736
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005737 if (IS_QLA8031(ha)) {
5738 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
5739 "Setting back fcoe driver presence.\n");
5740 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
5741 ql_dbg(ql_dbg_p3p, vha, 0xb074,
5742 "Error while setting DRV-Presence.\n");
5743 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005744 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08005745 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
5746 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005747 }
5748
5749 return(status);
5750}
5751
5752/*
5753* qla2x00_restart_isp
5754* restarts the ISP after a reset
5755*
5756* Input:
5757* ha = adapter block pointer.
5758*
5759* Returns:
5760* 0 = success
5761*/
5762static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005763qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005764{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08005765 int status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005766 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005767 struct req_que *req = ha->req_q_map[0];
5768 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005769
5770 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005771 if (qla2x00_isp_firmware(vha)) {
5772 vha->flags.online = 0;
5773 status = ha->isp_ops->chip_diag(vha);
5774 if (!status)
5775 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005776 }
5777
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005778 if (!status && !(status = qla2x00_init_rings(vha))) {
5779 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07005780 ha->flags.chip_reset_done = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04005781
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005782 /* Initialize the queues in use */
5783 qla25xx_init_queues(ha);
5784
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005785 status = qla2x00_fw_ready(vha);
5786 if (!status) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005787 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005788 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Chad Dupuis7108b762014-04-11 16:54:45 -04005789 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005790 }
5791
5792 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005793 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005794 status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005795 }
5796 return (status);
5797}
5798
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005799static int
5800qla25xx_init_queues(struct qla_hw_data *ha)
5801{
5802 struct rsp_que *rsp = NULL;
5803 struct req_que *req = NULL;
5804 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5805 int ret = -1;
5806 int i;
5807
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07005808 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005809 rsp = ha->rsp_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05005810 if (rsp && test_bit(i, ha->rsp_qid_map)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005811 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08005812 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005813 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005814 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
5815 "%s Rsp que: %d init failed.\n",
5816 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005817 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005818 ql_dbg(ql_dbg_init, base_vha, 0x0100,
5819 "%s Rsp que: %d inited.\n",
5820 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005821 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07005822 }
5823 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005824 req = ha->req_q_map[i];
Quinn Trancb432852016-02-04 11:45:16 -05005825 if (req && test_bit(i, ha->req_qid_map)) {
5826 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005827 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08005828 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005829 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005830 ql_dbg(ql_dbg_init, base_vha, 0x0101,
5831 "%s Req que: %d init failed.\n",
5832 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005833 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005834 ql_dbg(ql_dbg_init, base_vha, 0x0102,
5835 "%s Req que: %d inited.\n",
5836 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005837 }
5838 }
5839 return ret;
5840}
5841
Linus Torvalds1da177e2005-04-16 15:20:36 -07005842/*
5843* qla2x00_reset_adapter
5844* Reset adapter.
5845*
5846* Input:
5847* ha = adapter block pointer.
5848*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07005849void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005850qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005851{
5852 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005853 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07005854 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005855
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005856 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005857 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005858
Linus Torvalds1da177e2005-04-16 15:20:36 -07005859 spin_lock_irqsave(&ha->hardware_lock, flags);
5860 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
5861 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
5862 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
5863 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
5864 spin_unlock_irqrestore(&ha->hardware_lock, flags);
5865}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005866
5867void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005868qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005869{
5870 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005871 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005872 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
5873
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005874 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005875 return;
5876
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005877 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07005878 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005879
5880 spin_lock_irqsave(&ha->hardware_lock, flags);
5881 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
5882 RD_REG_DWORD(&reg->hccr);
5883 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
5884 RD_REG_DWORD(&reg->hccr);
5885 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08005886
5887 if (IS_NOPOLLING_TYPE(ha))
5888 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005889}
5890
David Miller4e08df32007-04-16 12:37:43 -07005891/* On sparc systems, obtain port and node WWN from firmware
5892 * properties.
5893 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005894static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
5895 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07005896{
5897#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005898 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07005899 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07005900 struct device_node *dp = pci_device_to_OF_node(pdev);
5901 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07005902 int len;
5903
5904 val = of_get_property(dp, "port-wwn", &len);
5905 if (val && len >= WWN_SIZE)
5906 memcpy(nv->port_name, val, WWN_SIZE);
5907
5908 val = of_get_property(dp, "node-wwn", &len);
5909 if (val && len >= WWN_SIZE)
5910 memcpy(nv->node_name, val, WWN_SIZE);
5911#endif
5912}
5913
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005914int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005915qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005916{
David Miller4e08df32007-04-16 12:37:43 -07005917 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005918 struct init_cb_24xx *icb;
5919 struct nvram_24xx *nv;
5920 uint32_t *dptr;
5921 uint8_t *dptr1, *dptr2;
5922 uint32_t chksum;
5923 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005924 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005925
David Miller4e08df32007-04-16 12:37:43 -07005926 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005927 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07005928 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005929
5930 /* Determine NVRAM starting address. */
Chad Dupuisf73cb692014-02-26 04:15:06 -05005931 if (ha->port_no == 0) {
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005932 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
5933 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
5934 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005935 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08005936 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
5937 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05005938
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005939 ha->nvram_size = sizeof(struct nvram_24xx);
5940 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005941
Seokmann Ju281afe12007-07-26 13:43:34 -07005942 /* Get VPD data into cache */
5943 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005944 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07005945 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
5946
5947 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005948 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005949 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005950 ha->nvram_size);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05005951 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
5952 chksum += le32_to_cpu(*dptr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005953
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005954 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
5955 "Contents of NVRAM\n");
5956 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
5957 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005958
5959 /* Bad NVRAM data, set defaults parameters. */
5960 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5961 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07005962 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005963 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005964 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04005965 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005966 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
5967 ql_log(ql_log_warn, vha, 0x006c,
5968 "Falling back to functioning (yet invalid -- WWPN) "
5969 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07005970
5971 /*
5972 * Set default initialization control block.
5973 */
5974 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07005975 nv->nvram_version = cpu_to_le16(ICB_VERSION);
5976 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04005977 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07005978 nv->execution_throttle = cpu_to_le16(0xFFFF);
5979 nv->exchange_count = cpu_to_le16(0);
5980 nv->hard_address = cpu_to_le16(124);
David Miller4e08df32007-04-16 12:37:43 -07005981 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005982 nv->port_name[1] = 0x00 + ha->port_no + 1;
David Miller4e08df32007-04-16 12:37:43 -07005983 nv->port_name[2] = 0x00;
5984 nv->port_name[3] = 0xe0;
5985 nv->port_name[4] = 0x8b;
5986 nv->port_name[5] = 0x1c;
5987 nv->port_name[6] = 0x55;
5988 nv->port_name[7] = 0x86;
5989 nv->node_name[0] = 0x20;
5990 nv->node_name[1] = 0x00;
5991 nv->node_name[2] = 0x00;
5992 nv->node_name[3] = 0xe0;
5993 nv->node_name[4] = 0x8b;
5994 nv->node_name[5] = 0x1c;
5995 nv->node_name[6] = 0x55;
5996 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005997 qla24xx_nvram_wwn_from_ofw(vha, nv);
Bart Van Asschead950362015-07-09 07:24:08 -07005998 nv->login_retry_count = cpu_to_le16(8);
5999 nv->interrupt_delay_timer = cpu_to_le16(0);
6000 nv->login_timeout = cpu_to_le16(0);
David Miller4e08df32007-04-16 12:37:43 -07006001 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07006002 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6003 nv->firmware_options_2 = cpu_to_le32(2 << 4);
6004 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6005 nv->firmware_options_3 = cpu_to_le32(2 << 13);
6006 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6007 nv->efi_parameters = cpu_to_le32(0);
David Miller4e08df32007-04-16 12:37:43 -07006008 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07006009 nv->max_luns_per_target = cpu_to_le16(128);
6010 nv->port_down_retry_count = cpu_to_le16(30);
6011 nv->link_down_timeout = cpu_to_le16(30);
David Miller4e08df32007-04-16 12:37:43 -07006012
6013 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006014 }
6015
Quinn Tran726b8542017-01-19 22:28:00 -08006016 if (qla_tgt_mode_enabled(vha)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006017 /* Don't enable full login after initial LIP */
Bart Van Asschead950362015-07-09 07:24:08 -07006018 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006019 /* Don't enable LIP full login for initiator */
Bart Van Asschead950362015-07-09 07:24:08 -07006020 nv->host_p &= cpu_to_le32(~BIT_10);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006021 }
6022
6023 qlt_24xx_config_nvram_stage1(vha, nv);
6024
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006025 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006026 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006027
6028 /* Copy 1st segment. */
6029 dptr1 = (uint8_t *)icb;
6030 dptr2 = (uint8_t *)&nv->version;
6031 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6032 while (cnt--)
6033 *dptr1++ = *dptr2++;
6034
6035 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07006036 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006037
6038 /* Copy 2nd segment. */
6039 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6040 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6041 cnt = (uint8_t *)&icb->reserved_3 -
6042 (uint8_t *)&icb->interrupt_delay_timer;
6043 while (cnt--)
6044 *dptr1++ = *dptr2++;
6045
6046 /*
6047 * Setup driver NVRAM options.
6048 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006049 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08006050 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006051
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006052 qlt_24xx_config_nvram_stage2(vha, icb);
6053
Bart Van Asschead950362015-07-09 07:24:08 -07006054 if (nv->host_p & cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04006055 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07006056 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6057 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6058 }
6059
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006060 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07006061 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006062 /*
6063 * Firmware will apply the following mask if the nodename was
6064 * not provided.
6065 */
6066 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6067 icb->node_name[0] &= 0xF0;
6068 }
6069
6070 /* Set host adapter parameters. */
6071 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08006072 ha->flags.enable_lip_reset = 0;
6073 ha->flags.enable_lip_full_login =
6074 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6075 ha->flags.enable_target_reset =
6076 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006077 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07006078 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006079
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07006080 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6081 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006082
6083 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
6084 sizeof(ha->fw_seriallink_options24));
6085
6086 /* save HBA serial number */
6087 ha->serial0 = icb->port_name[5];
6088 ha->serial1 = icb->port_name[6];
6089 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006090 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6091 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006092
Bart Van Asschead950362015-07-09 07:24:08 -07006093 icb->execution_throttle = cpu_to_le16(0xFFFF);
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08006094
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006095 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6096
6097 /* Set minimum login_timeout to 4 seconds. */
6098 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6099 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6100 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07006101 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006102 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006103
Andrew Vasquez00a537b2008-02-28 14:06:11 -08006104 /* Set minimum RATOV to 100 tenths of a second. */
6105 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006106
6107 ha->loop_reset_delay = nv->reset_delay;
6108
6109 /* Link Down Timeout = 0:
6110 *
6111 * When Port Down timer expires we will start returning
6112 * I/O's to OS with "DID_NO_CONNECT".
6113 *
6114 * Link Down Timeout != 0:
6115 *
6116 * The driver waits for the link to come up after link down
6117 * before returning I/Os to OS with "DID_NO_CONNECT".
6118 */
6119 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6120 ha->loop_down_abort_time =
6121 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6122 } else {
6123 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6124 ha->loop_down_abort_time =
6125 (LOOP_DOWN_TIME - ha->link_down_timeout);
6126 }
6127
6128 /* Need enough time to try and get the port back. */
6129 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6130 if (qlport_down_retry)
6131 ha->port_down_retry_count = qlport_down_retry;
6132
6133 /* Set login_retry_count */
6134 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6135 if (ha->port_down_retry_count ==
6136 le16_to_cpu(nv->port_down_retry_count) &&
6137 ha->port_down_retry_count > 3)
6138 ha->login_retry_count = ha->port_down_retry_count;
6139 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6140 ha->login_retry_count = ha->port_down_retry_count;
6141 if (ql2xloginretrycount)
6142 ha->login_retry_count = ql2xloginretrycount;
6143
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006144 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006145 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006146 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6147 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6148 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6149 le16_to_cpu(icb->interrupt_delay_timer): 2;
6150 }
Bart Van Asschead950362015-07-09 07:24:08 -07006151 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006152 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006153 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006154 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08006155 ha->zio_mode = QLA_ZIO_MODE_6;
6156
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006157 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006158 "ZIO mode %d enabled; timer delay (%d us).\n",
6159 ha->zio_mode, ha->zio_timer * 100);
6160
6161 icb->firmware_options_2 |= cpu_to_le32(
6162 (uint32_t)ha->zio_mode);
6163 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006164 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07006165 }
6166
David Miller4e08df32007-04-16 12:37:43 -07006167 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006168 ql_log(ql_log_warn, vha, 0x0070,
6169 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07006170 }
6171 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006172}
6173
Sawan Chandak4243c112016-01-27 12:03:31 -05006174uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
6175{
6176 struct qla27xx_image_status pri_image_status, sec_image_status;
6177 uint8_t valid_pri_image, valid_sec_image;
6178 uint32_t *wptr;
6179 uint32_t cnt, chksum, size;
6180 struct qla_hw_data *ha = vha->hw;
6181
6182 valid_pri_image = valid_sec_image = 1;
6183 ha->active_image = 0;
6184 size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
6185
6186 if (!ha->flt_region_img_status_pri) {
6187 valid_pri_image = 0;
6188 goto check_sec_image;
6189 }
6190
6191 qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
6192 ha->flt_region_img_status_pri, size);
6193
6194 if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6195 ql_dbg(ql_dbg_init, vha, 0x018b,
6196 "Primary image signature (0x%x) not valid\n",
6197 pri_image_status.signature);
6198 valid_pri_image = 0;
6199 goto check_sec_image;
6200 }
6201
6202 wptr = (uint32_t *)(&pri_image_status);
6203 cnt = size;
6204
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006205 for (chksum = 0; cnt--; wptr++)
6206 chksum += le32_to_cpu(*wptr);
Quinn Tran41dc5292017-01-19 22:28:03 -08006207
Sawan Chandak4243c112016-01-27 12:03:31 -05006208 if (chksum) {
6209 ql_dbg(ql_dbg_init, vha, 0x018c,
6210 "Checksum validation failed for primary image (0x%x)\n",
6211 chksum);
6212 valid_pri_image = 0;
6213 }
6214
6215check_sec_image:
6216 if (!ha->flt_region_img_status_sec) {
6217 valid_sec_image = 0;
6218 goto check_valid_image;
6219 }
6220
6221 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
6222 ha->flt_region_img_status_sec, size);
6223
6224 if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
6225 ql_dbg(ql_dbg_init, vha, 0x018d,
6226 "Secondary image signature(0x%x) not valid\n",
6227 sec_image_status.signature);
6228 valid_sec_image = 0;
6229 goto check_valid_image;
6230 }
6231
6232 wptr = (uint32_t *)(&sec_image_status);
6233 cnt = size;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006234 for (chksum = 0; cnt--; wptr++)
6235 chksum += le32_to_cpu(*wptr);
Sawan Chandak4243c112016-01-27 12:03:31 -05006236 if (chksum) {
6237 ql_dbg(ql_dbg_init, vha, 0x018e,
6238 "Checksum validation failed for secondary image (0x%x)\n",
6239 chksum);
6240 valid_sec_image = 0;
6241 }
6242
6243check_valid_image:
6244 if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
6245 ha->active_image = QLA27XX_PRIMARY_IMAGE;
6246 if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
6247 if (!ha->active_image ||
6248 pri_image_status.generation_number <
6249 sec_image_status.generation_number)
6250 ha->active_image = QLA27XX_SECONDARY_IMAGE;
6251 }
6252
6253 ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n",
6254 ha->active_image == 0 ? "default bootld and fw" :
6255 ha->active_image == 1 ? "primary" :
6256 ha->active_image == 2 ? "secondary" :
6257 "Invalid");
6258
6259 return ha->active_image;
6260}
6261
Adrian Bunk413975a2006-06-30 02:33:06 -07006262static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006263qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
6264 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006265{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006266 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006267 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006268 uint32_t *dcode, dlen;
6269 uint32_t risc_addr;
6270 uint32_t risc_size;
6271 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006272 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006273 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006274
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006275 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006276 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006277
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006278 rval = QLA_SUCCESS;
6279
6280 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006281 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006282 *srisc_addr = 0;
6283
Sawan Chandak4243c112016-01-27 12:03:31 -05006284 if (IS_QLA27XX(ha) &&
6285 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
6286 faddr = ha->flt_region_fw_sec;
6287
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006288 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006289 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006290 for (i = 0; i < 4; i++)
6291 dcode[i] = be32_to_cpu(dcode[i]);
6292 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
6293 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
6294 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
6295 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006296 ql_log(ql_log_fatal, vha, 0x008c,
6297 "Unable to verify the integrity of flash firmware "
6298 "image.\n");
6299 ql_log(ql_log_fatal, vha, 0x008d,
6300 "Firmware data: %08x %08x %08x %08x.\n",
6301 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006302
6303 return QLA_FUNCTION_FAILED;
6304 }
6305
6306 while (segments && rval == QLA_SUCCESS) {
6307 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006308 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006309
6310 risc_addr = be32_to_cpu(dcode[2]);
6311 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
6312 risc_size = be32_to_cpu(dcode[3]);
6313
6314 fragment = 0;
6315 while (risc_size > 0 && rval == QLA_SUCCESS) {
6316 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
6317 if (dlen > risc_size)
6318 dlen = risc_size;
6319
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006320 ql_dbg(ql_dbg_init, vha, 0x008e,
6321 "Loading risc segment@ risc addr %x "
6322 "number of dwords 0x%x offset 0x%x.\n",
6323 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006324
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006325 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006326 for (i = 0; i < dlen; i++)
6327 dcode[i] = swab32(dcode[i]);
6328
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006329 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006330 dlen);
6331 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006332 ql_log(ql_log_fatal, vha, 0x008f,
6333 "Failed to load segment %d of firmware.\n",
6334 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04006335 return QLA_FUNCTION_FAILED;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006336 }
6337
6338 faddr += dlen;
6339 risc_addr += dlen;
6340 risc_size -= dlen;
6341 fragment++;
6342 }
6343
6344 /* Next segment. */
6345 segments--;
6346 }
6347
Chad Dupuisf73cb692014-02-26 04:15:06 -05006348 if (!IS_QLA27XX(ha))
6349 return rval;
6350
6351 if (ha->fw_dump_template)
6352 vfree(ha->fw_dump_template);
6353 ha->fw_dump_template = NULL;
6354 ha->fw_dump_template_len = 0;
6355
6356 ql_dbg(ql_dbg_init, vha, 0x0161,
6357 "Loading fwdump template from %x\n", faddr);
6358 qla24xx_read_flash_data(vha, dcode, faddr, 7);
6359 risc_size = be32_to_cpu(dcode[2]);
6360 ql_dbg(ql_dbg_init, vha, 0x0162,
6361 "-> array size %x dwords\n", risc_size);
6362 if (risc_size == 0 || risc_size == ~0)
6363 goto default_template;
6364
6365 dlen = (risc_size - 8) * sizeof(*dcode);
6366 ql_dbg(ql_dbg_init, vha, 0x0163,
6367 "-> template allocating %x bytes...\n", dlen);
6368 ha->fw_dump_template = vmalloc(dlen);
6369 if (!ha->fw_dump_template) {
6370 ql_log(ql_log_warn, vha, 0x0164,
6371 "Failed fwdump template allocate %x bytes.\n", risc_size);
6372 goto default_template;
6373 }
6374
6375 faddr += 7;
6376 risc_size -= 8;
6377 dcode = ha->fw_dump_template;
6378 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
6379 for (i = 0; i < risc_size; i++)
6380 dcode[i] = le32_to_cpu(dcode[i]);
6381
6382 if (!qla27xx_fwdt_template_valid(dcode)) {
6383 ql_log(ql_log_warn, vha, 0x0165,
6384 "Failed fwdump template validate\n");
6385 goto default_template;
6386 }
6387
6388 dlen = qla27xx_fwdt_template_size(dcode);
6389 ql_dbg(ql_dbg_init, vha, 0x0166,
6390 "-> template size %x bytes\n", dlen);
6391 if (dlen > risc_size * sizeof(*dcode)) {
6392 ql_log(ql_log_warn, vha, 0x0167,
Chad Dupuis97ea7022014-03-13 14:16:40 -04006393 "Failed fwdump template exceeds array by %x bytes\n",
6394 (uint32_t)(dlen - risc_size * sizeof(*dcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05006395 goto default_template;
6396 }
6397 ha->fw_dump_template_len = dlen;
6398 return rval;
6399
6400default_template:
6401 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
6402 if (ha->fw_dump_template)
6403 vfree(ha->fw_dump_template);
6404 ha->fw_dump_template = NULL;
6405 ha->fw_dump_template_len = 0;
6406
6407 dlen = qla27xx_fwdt_template_default_size();
6408 ql_dbg(ql_dbg_init, vha, 0x0169,
6409 "-> template allocating %x bytes...\n", dlen);
6410 ha->fw_dump_template = vmalloc(dlen);
6411 if (!ha->fw_dump_template) {
6412 ql_log(ql_log_warn, vha, 0x016a,
6413 "Failed fwdump template allocate %x bytes.\n", risc_size);
6414 goto failed_template;
6415 }
6416
6417 dcode = ha->fw_dump_template;
6418 risc_size = dlen / sizeof(*dcode);
6419 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
6420 for (i = 0; i < risc_size; i++)
6421 dcode[i] = be32_to_cpu(dcode[i]);
6422
6423 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
6424 ql_log(ql_log_warn, vha, 0x016b,
6425 "Failed fwdump template validate\n");
6426 goto failed_template;
6427 }
6428
6429 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
6430 ql_dbg(ql_dbg_init, vha, 0x016c,
6431 "-> template size %x bytes\n", dlen);
6432 ha->fw_dump_template_len = dlen;
6433 return rval;
6434
6435failed_template:
6436 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
6437 if (ha->fw_dump_template)
6438 vfree(ha->fw_dump_template);
6439 ha->fw_dump_template = NULL;
6440 ha->fw_dump_template_len = 0;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006441 return rval;
6442}
6443
Giridhar Malavalie9454a82013-02-08 01:57:47 -05006444#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006445
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006446int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006447qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08006448{
6449 int rval;
6450 int i, fragment;
6451 uint16_t *wcode, *fwcode;
6452 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
6453 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006454 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006455 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08006456
6457 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006458 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08006459 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006460 ql_log(ql_log_info, vha, 0x0083,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01006461 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006462 ql_log(ql_log_info, vha, 0x0084,
6463 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08006464 return QLA_FUNCTION_FAILED;
6465 }
6466
6467 rval = QLA_SUCCESS;
6468
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006469 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08006470 *srisc_addr = 0;
6471 fwcode = (uint16_t *)blob->fw->data;
6472 fwclen = 0;
6473
6474 /* Validate firmware image by checking version. */
6475 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006476 ql_log(ql_log_fatal, vha, 0x0085,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006477 "Unable to verify integrity of firmware image (%zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08006478 blob->fw->size);
6479 goto fail_fw_integrity;
6480 }
6481 for (i = 0; i < 4; i++)
6482 wcode[i] = be16_to_cpu(fwcode[i + 4]);
6483 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
6484 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
6485 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006486 ql_log(ql_log_fatal, vha, 0x0086,
6487 "Unable to verify integrity of firmware image.\n");
6488 ql_log(ql_log_fatal, vha, 0x0087,
6489 "Firmware data: %04x %04x %04x %04x.\n",
6490 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08006491 goto fail_fw_integrity;
6492 }
6493
6494 seg = blob->segs;
6495 while (*seg && rval == QLA_SUCCESS) {
6496 risc_addr = *seg;
6497 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
6498 risc_size = be16_to_cpu(fwcode[3]);
6499
6500 /* Validate firmware image size. */
6501 fwclen += risc_size * sizeof(uint16_t);
6502 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006503 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08006504 "Unable to verify integrity of firmware image "
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006505 "(%zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08006506 goto fail_fw_integrity;
6507 }
6508
6509 fragment = 0;
6510 while (risc_size > 0 && rval == QLA_SUCCESS) {
6511 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
6512 if (wlen > risc_size)
6513 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006514 ql_dbg(ql_dbg_init, vha, 0x0089,
6515 "Loading risc segment@ risc addr %x number of "
6516 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08006517
6518 for (i = 0; i < wlen; i++)
6519 wcode[i] = swab16(fwcode[i]);
6520
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006521 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08006522 wlen);
6523 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006524 ql_log(ql_log_fatal, vha, 0x008a,
6525 "Failed to load segment %d of firmware.\n",
6526 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08006527 break;
6528 }
6529
6530 fwcode += wlen;
6531 risc_addr += wlen;
6532 risc_size -= wlen;
6533 fragment++;
6534 }
6535
6536 /* Next segment. */
6537 seg++;
6538 }
6539 return rval;
6540
6541fail_fw_integrity:
6542 return QLA_FUNCTION_FAILED;
6543}
6544
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006545static int
6546qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006547{
6548 int rval;
6549 int segments, fragment;
6550 uint32_t *dcode, dlen;
6551 uint32_t risc_addr;
6552 uint32_t risc_size;
6553 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08006554 struct fw_blob *blob;
Chad Dupuisf73cb692014-02-26 04:15:06 -05006555 const uint32_t *fwcode;
6556 uint32_t fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006557 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006558 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006559
Andrew Vasquez54333832005-11-09 15:49:04 -08006560 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006561 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08006562 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006563 ql_log(ql_log_warn, vha, 0x0090,
Yannick Guerrini94bcf832015-02-26 22:49:34 +01006564 "Firmware image unavailable.\n");
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006565 ql_log(ql_log_warn, vha, 0x0091,
6566 "Firmware images can be retrieved from: "
6567 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07006568
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006569 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006570 }
6571
Chad Dupuiscfb09192011-11-18 09:03:07 -08006572 ql_dbg(ql_dbg_init, vha, 0x0092,
6573 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006574
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006575 rval = QLA_SUCCESS;
6576
6577 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006578 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006579 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08006580 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006581 fwclen = 0;
6582
6583 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08006584 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006585 ql_log(ql_log_fatal, vha, 0x0093,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006586 "Unable to verify integrity of firmware image (%zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08006587 blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05006588 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006589 }
6590 for (i = 0; i < 4; i++)
6591 dcode[i] = be32_to_cpu(fwcode[i + 4]);
6592 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
6593 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
6594 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
6595 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006596 ql_log(ql_log_fatal, vha, 0x0094,
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006597 "Unable to verify integrity of firmware image (%zd).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006598 blob->fw->size);
6599 ql_log(ql_log_fatal, vha, 0x0095,
6600 "Firmware data: %08x %08x %08x %08x.\n",
6601 dcode[0], dcode[1], dcode[2], dcode[3]);
Chad Dupuisf73cb692014-02-26 04:15:06 -05006602 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006603 }
6604
6605 while (segments && rval == QLA_SUCCESS) {
6606 risc_addr = be32_to_cpu(fwcode[2]);
6607 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
6608 risc_size = be32_to_cpu(fwcode[3]);
6609
6610 /* Validate firmware image size. */
6611 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08006612 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006613 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08006614 "Unable to verify integrity of firmware image "
Alexey Dobriyan5b5e0922017-02-27 14:30:02 -08006615 "(%zd).\n", blob->fw->size);
Chad Dupuisf73cb692014-02-26 04:15:06 -05006616 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006617 }
6618
6619 fragment = 0;
6620 while (risc_size > 0 && rval == QLA_SUCCESS) {
6621 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
6622 if (dlen > risc_size)
6623 dlen = risc_size;
6624
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006625 ql_dbg(ql_dbg_init, vha, 0x0097,
6626 "Loading risc segment@ risc addr %x "
6627 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006628
6629 for (i = 0; i < dlen; i++)
6630 dcode[i] = swab32(fwcode[i]);
6631
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006632 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08006633 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006634 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006635 ql_log(ql_log_fatal, vha, 0x0098,
6636 "Failed to load segment %d of firmware.\n",
6637 fragment);
Chad Dupuisf261f7a2014-09-25 05:17:03 -04006638 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006639 }
6640
6641 fwcode += dlen;
6642 risc_addr += dlen;
6643 risc_size -= dlen;
6644 fragment++;
6645 }
6646
6647 /* Next segment. */
6648 segments--;
6649 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05006650
6651 if (!IS_QLA27XX(ha))
6652 return rval;
6653
6654 if (ha->fw_dump_template)
6655 vfree(ha->fw_dump_template);
6656 ha->fw_dump_template = NULL;
6657 ha->fw_dump_template_len = 0;
6658
6659 ql_dbg(ql_dbg_init, vha, 0x171,
Chad Dupuis97ea7022014-03-13 14:16:40 -04006660 "Loading fwdump template from %x\n",
6661 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
Chad Dupuisf73cb692014-02-26 04:15:06 -05006662 risc_size = be32_to_cpu(fwcode[2]);
6663 ql_dbg(ql_dbg_init, vha, 0x172,
6664 "-> array size %x dwords\n", risc_size);
6665 if (risc_size == 0 || risc_size == ~0)
6666 goto default_template;
6667
6668 dlen = (risc_size - 8) * sizeof(*fwcode);
6669 ql_dbg(ql_dbg_init, vha, 0x0173,
6670 "-> template allocating %x bytes...\n", dlen);
6671 ha->fw_dump_template = vmalloc(dlen);
6672 if (!ha->fw_dump_template) {
6673 ql_log(ql_log_warn, vha, 0x0174,
6674 "Failed fwdump template allocate %x bytes.\n", risc_size);
6675 goto default_template;
6676 }
6677
6678 fwcode += 7;
6679 risc_size -= 8;
6680 dcode = ha->fw_dump_template;
6681 for (i = 0; i < risc_size; i++)
6682 dcode[i] = le32_to_cpu(fwcode[i]);
6683
6684 if (!qla27xx_fwdt_template_valid(dcode)) {
6685 ql_log(ql_log_warn, vha, 0x0175,
6686 "Failed fwdump template validate\n");
6687 goto default_template;
6688 }
6689
6690 dlen = qla27xx_fwdt_template_size(dcode);
6691 ql_dbg(ql_dbg_init, vha, 0x0176,
6692 "-> template size %x bytes\n", dlen);
6693 if (dlen > risc_size * sizeof(*fwcode)) {
6694 ql_log(ql_log_warn, vha, 0x0177,
Chad Dupuis97ea7022014-03-13 14:16:40 -04006695 "Failed fwdump template exceeds array by %x bytes\n",
6696 (uint32_t)(dlen - risc_size * sizeof(*fwcode)));
Chad Dupuisf73cb692014-02-26 04:15:06 -05006697 goto default_template;
6698 }
6699 ha->fw_dump_template_len = dlen;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006700 return rval;
6701
Chad Dupuisf73cb692014-02-26 04:15:06 -05006702default_template:
6703 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
6704 if (ha->fw_dump_template)
6705 vfree(ha->fw_dump_template);
6706 ha->fw_dump_template = NULL;
6707 ha->fw_dump_template_len = 0;
6708
6709 dlen = qla27xx_fwdt_template_default_size();
6710 ql_dbg(ql_dbg_init, vha, 0x0179,
6711 "-> template allocating %x bytes...\n", dlen);
6712 ha->fw_dump_template = vmalloc(dlen);
6713 if (!ha->fw_dump_template) {
6714 ql_log(ql_log_warn, vha, 0x017a,
6715 "Failed fwdump template allocate %x bytes.\n", risc_size);
6716 goto failed_template;
6717 }
6718
6719 dcode = ha->fw_dump_template;
6720 risc_size = dlen / sizeof(*fwcode);
6721 fwcode = qla27xx_fwdt_template_default();
6722 for (i = 0; i < risc_size; i++)
6723 dcode[i] = be32_to_cpu(fwcode[i]);
6724
6725 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
6726 ql_log(ql_log_warn, vha, 0x017b,
6727 "Failed fwdump template validate\n");
6728 goto failed_template;
6729 }
6730
6731 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
6732 ql_dbg(ql_dbg_init, vha, 0x017c,
6733 "-> template size %x bytes\n", dlen);
6734 ha->fw_dump_template_len = dlen;
6735 return rval;
6736
6737failed_template:
6738 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
6739 if (ha->fw_dump_template)
6740 vfree(ha->fw_dump_template);
6741 ha->fw_dump_template = NULL;
6742 ha->fw_dump_template_len = 0;
6743 return rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07006744}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006745
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006746int
6747qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
6748{
6749 int rval;
6750
Andrew Vasqueze337d902009-04-06 22:33:49 -07006751 if (ql2xfwloadbin == 1)
6752 return qla81xx_load_risc(vha, srisc_addr);
6753
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006754 /*
6755 * FW Load priority:
6756 * 1) Firmware via request-firmware interface (.bin file).
6757 * 2) Firmware residing in flash.
6758 */
6759 rval = qla24xx_load_risc_blob(vha, srisc_addr);
6760 if (rval == QLA_SUCCESS)
6761 return rval;
6762
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006763 return qla24xx_load_risc_flash(vha, srisc_addr,
6764 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006765}
6766
6767int
6768qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
6769{
6770 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006771 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006772
Andrew Vasqueze337d902009-04-06 22:33:49 -07006773 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006774 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07006775
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006776 /*
6777 * FW Load priority:
6778 * 1) Firmware residing in flash.
6779 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006780 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006781 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006782 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006783 if (rval == QLA_SUCCESS)
6784 return rval;
6785
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006786try_blob_fw:
6787 rval = qla24xx_load_risc_blob(vha, srisc_addr);
6788 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
6789 return rval;
6790
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006791 ql_log(ql_log_info, vha, 0x0099,
6792 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006793 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
6794 if (rval != QLA_SUCCESS)
6795 return rval;
6796
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006797 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006798 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07006799 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08006800}
6801
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006802void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006803qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006804{
6805 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006806 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006807
Andrew Vasquez85880802009-12-15 21:29:46 -08006808 if (ha->flags.pci_channel_io_perm_failure)
6809 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07006810 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006811 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07006812 if (!ha->fw_major_version)
6813 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006814
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006815 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08006816 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07006817 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006818 ha->isp_ops->reset_chip(vha);
6819 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006820 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006821 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006822 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006823 ql_log(ql_log_info, vha, 0x8015,
6824 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006825 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07006826 }
6827}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006828
6829int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006830qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006831{
6832 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08006833 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006834 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006835 struct qla_hw_data *ha = vha->hw;
6836 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07006837 struct req_que *req;
6838 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006839
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006840 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006841 return -EINVAL;
6842
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006843 rval = qla2x00_fw_ready(base_vha);
Michael Hernandezd7459522016-12-12 14:40:07 -08006844 if (vha->qpair)
6845 req = vha->qpair->req;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07006846 else
Michael Hernandezd7459522016-12-12 14:40:07 -08006847 req = ha->req_q_map[0];
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07006848 rsp = req->rsp;
6849
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006850 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006851 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08006852 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006853 }
6854
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006855 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006856
6857 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08006858 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
6859 BIT_1);
6860 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
6861 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
6862 ql_dbg(ql_dbg_init, vha, 0x0120,
6863 "Failed SNS login: loop_id=%x, rval2=%d\n",
6864 NPH_SNS, rval2);
6865 else
6866 ql_dbg(ql_dbg_init, vha, 0x0103,
6867 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
6868 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
6869 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006870 return (QLA_FUNCTION_FAILED);
6871 }
6872
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006873 atomic_set(&vha->loop_down_timer, 0);
6874 atomic_set(&vha->loop_state, LOOP_UP);
6875 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6876 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
6877 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006878
6879 return rval;
6880}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006881
6882/* 84XX Support **************************************************************/
6883
6884static LIST_HEAD(qla_cs84xx_list);
6885static DEFINE_MUTEX(qla_cs84xx_mutex);
6886
6887static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006888qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006889{
6890 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006891 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006892
6893 mutex_lock(&qla_cs84xx_mutex);
6894
6895 /* Find any shared 84xx chip. */
6896 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
6897 if (cs84xx->bus == ha->pdev->bus) {
6898 kref_get(&cs84xx->kref);
6899 goto done;
6900 }
6901 }
6902
6903 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
6904 if (!cs84xx)
6905 goto done;
6906
6907 kref_init(&cs84xx->kref);
6908 spin_lock_init(&cs84xx->access_lock);
6909 mutex_init(&cs84xx->fw_update_mutex);
6910 cs84xx->bus = ha->pdev->bus;
6911
6912 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
6913done:
6914 mutex_unlock(&qla_cs84xx_mutex);
6915 return cs84xx;
6916}
6917
6918static void
6919__qla84xx_chip_release(struct kref *kref)
6920{
6921 struct qla_chip_state_84xx *cs84xx =
6922 container_of(kref, struct qla_chip_state_84xx, kref);
6923
6924 mutex_lock(&qla_cs84xx_mutex);
6925 list_del(&cs84xx->list);
6926 mutex_unlock(&qla_cs84xx_mutex);
6927 kfree(cs84xx);
6928}
6929
6930void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006931qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006932{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006933 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006934 if (ha->cs84xx)
6935 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
6936}
6937
6938static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006939qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006940{
6941 int rval;
6942 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006943 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006944
6945 mutex_lock(&ha->cs84xx->fw_update_mutex);
6946
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08006947 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07006948
6949 mutex_unlock(&ha->cs84xx->fw_update_mutex);
6950
6951 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
6952 QLA_SUCCESS;
6953}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006954
6955/* 81XX Support **************************************************************/
6956
6957int
6958qla81xx_nvram_config(scsi_qla_host_t *vha)
6959{
6960 int rval;
6961 struct init_cb_81xx *icb;
6962 struct nvram_81xx *nv;
6963 uint32_t *dptr;
6964 uint8_t *dptr1, *dptr2;
6965 uint32_t chksum;
6966 uint16_t cnt;
6967 struct qla_hw_data *ha = vha->hw;
6968
6969 rval = QLA_SUCCESS;
6970 icb = (struct init_cb_81xx *)ha->init_cb;
6971 nv = ha->nvram;
6972
6973 /* Determine NVRAM starting address. */
6974 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006975 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04006976 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
6977 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006978
6979 /* Get VPD data into cache */
6980 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006981 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
6982 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006983
6984 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006985 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006986 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07006987 dptr = (uint32_t *)nv;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05006988 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
6989 chksum += le32_to_cpu(*dptr);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006990
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006991 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
6992 "Contents of NVRAM:\n");
6993 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
6994 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08006995
6996 /* Bad NVRAM data, set defaults parameters. */
6997 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6998 || nv->id[3] != ' ' ||
Bart Van Asschead950362015-07-09 07:24:08 -07006999 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007000 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007001 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04007002 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007003 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007004 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007005 ql_log(ql_log_info, vha, 0x0074,
7006 "Falling back to functioning (yet invalid -- WWPN) "
7007 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007008
7009 /*
7010 * Set default initialization control block.
7011 */
7012 memset(nv, 0, ha->nvram_size);
Bart Van Asschead950362015-07-09 07:24:08 -07007013 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7014 nv->version = cpu_to_le16(ICB_VERSION);
Joe Carnuccio98aee702014-09-25 05:16:38 -04007015 nv->frame_payload_size = 2048;
Bart Van Asschead950362015-07-09 07:24:08 -07007016 nv->execution_throttle = cpu_to_le16(0xFFFF);
7017 nv->exchange_count = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007018 nv->port_name[0] = 0x21;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007019 nv->port_name[1] = 0x00 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007020 nv->port_name[2] = 0x00;
7021 nv->port_name[3] = 0xe0;
7022 nv->port_name[4] = 0x8b;
7023 nv->port_name[5] = 0x1c;
7024 nv->port_name[6] = 0x55;
7025 nv->port_name[7] = 0x86;
7026 nv->node_name[0] = 0x20;
7027 nv->node_name[1] = 0x00;
7028 nv->node_name[2] = 0x00;
7029 nv->node_name[3] = 0xe0;
7030 nv->node_name[4] = 0x8b;
7031 nv->node_name[5] = 0x1c;
7032 nv->node_name[6] = 0x55;
7033 nv->node_name[7] = 0x86;
Bart Van Asschead950362015-07-09 07:24:08 -07007034 nv->login_retry_count = cpu_to_le16(8);
7035 nv->interrupt_delay_timer = cpu_to_le16(0);
7036 nv->login_timeout = cpu_to_le16(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007037 nv->firmware_options_1 =
Bart Van Asschead950362015-07-09 07:24:08 -07007038 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7039 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7040 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7041 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7042 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7043 nv->efi_parameters = cpu_to_le32(0);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007044 nv->reset_delay = 5;
Bart Van Asschead950362015-07-09 07:24:08 -07007045 nv->max_luns_per_target = cpu_to_le16(128);
7046 nv->port_down_retry_count = cpu_to_le16(30);
7047 nv->link_down_timeout = cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07007048 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007049 nv->enode_mac[1] = 0xC0;
7050 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007051 nv->enode_mac[3] = 0x04;
7052 nv->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007053 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007054
7055 rval = 1;
7056 }
7057
Arun Easi9e522cd2012-08-22 14:21:31 -04007058 if (IS_T10_PI_CAPABLE(ha))
7059 nv->frame_payload_size &= ~7;
7060
Arun Easiaa230bc2013-01-30 03:34:39 -05007061 qlt_81xx_config_nvram_stage1(vha, nv);
7062
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007063 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07007064 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007065
7066 /* Copy 1st segment. */
7067 dptr1 = (uint8_t *)icb;
7068 dptr2 = (uint8_t *)&nv->version;
7069 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7070 while (cnt--)
7071 *dptr1++ = *dptr2++;
7072
7073 icb->login_retry_count = nv->login_retry_count;
7074
7075 /* Copy 2nd segment. */
7076 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7077 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7078 cnt = (uint8_t *)&icb->reserved_5 -
7079 (uint8_t *)&icb->interrupt_delay_timer;
7080 while (cnt--)
7081 *dptr1++ = *dptr2++;
7082
7083 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
7084 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
7085 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08007086 icb->enode_mac[0] = 0x00;
7087 icb->enode_mac[1] = 0xC0;
7088 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007089 icb->enode_mac[3] = 0x04;
7090 icb->enode_mac[4] = 0x05;
Chad Dupuisf73cb692014-02-26 04:15:06 -05007091 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007092 }
7093
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07007094 /* Use extended-initialization control block. */
7095 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
7096
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007097 /*
7098 * Setup driver NVRAM options.
7099 */
7100 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07007101 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007102
Arun Easiaa230bc2013-01-30 03:34:39 -05007103 qlt_81xx_config_nvram_stage2(vha, icb);
7104
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007105 /* Use alternate WWN? */
Bart Van Asschead950362015-07-09 07:24:08 -07007106 if (nv->host_p & cpu_to_le32(BIT_15)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007107 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7108 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7109 }
7110
7111 /* Prepare nodename */
Bart Van Asschead950362015-07-09 07:24:08 -07007112 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007113 /*
7114 * Firmware will apply the following mask if the nodename was
7115 * not provided.
7116 */
7117 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7118 icb->node_name[0] &= 0xF0;
7119 }
7120
7121 /* Set host adapter parameters. */
7122 ha->flags.disable_risc_code_load = 0;
7123 ha->flags.enable_lip_reset = 0;
7124 ha->flags.enable_lip_full_login =
7125 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
7126 ha->flags.enable_target_reset =
7127 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
7128 ha->flags.enable_led_scheme = 0;
7129 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
7130
7131 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7132 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7133
7134 /* save HBA serial number */
7135 ha->serial0 = icb->port_name[5];
7136 ha->serial1 = icb->port_name[6];
7137 ha->serial2 = icb->port_name[7];
7138 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7139 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7140
Bart Van Asschead950362015-07-09 07:24:08 -07007141 icb->execution_throttle = cpu_to_le16(0xFFFF);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007142
7143 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7144
7145 /* Set minimum login_timeout to 4 seconds. */
7146 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7147 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7148 if (le16_to_cpu(nv->login_timeout) < 4)
Bart Van Asschead950362015-07-09 07:24:08 -07007149 nv->login_timeout = cpu_to_le16(4);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007150 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007151
7152 /* Set minimum RATOV to 100 tenths of a second. */
7153 ha->r_a_tov = 100;
7154
7155 ha->loop_reset_delay = nv->reset_delay;
7156
7157 /* Link Down Timeout = 0:
7158 *
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007159 * When Port Down timer expires we will start returning
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007160 * I/O's to OS with "DID_NO_CONNECT".
7161 *
7162 * Link Down Timeout != 0:
7163 *
7164 * The driver waits for the link to come up after link down
7165 * before returning I/Os to OS with "DID_NO_CONNECT".
7166 */
7167 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7168 ha->loop_down_abort_time =
7169 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7170 } else {
7171 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7172 ha->loop_down_abort_time =
7173 (LOOP_DOWN_TIME - ha->link_down_timeout);
7174 }
7175
7176 /* Need enough time to try and get the port back. */
7177 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7178 if (qlport_down_retry)
7179 ha->port_down_retry_count = qlport_down_retry;
7180
7181 /* Set login_retry_count */
7182 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7183 if (ha->port_down_retry_count ==
7184 le16_to_cpu(nv->port_down_retry_count) &&
7185 ha->port_down_retry_count > 3)
7186 ha->login_retry_count = ha->port_down_retry_count;
7187 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7188 ha->login_retry_count = ha->port_down_retry_count;
7189 if (ql2xloginretrycount)
7190 ha->login_retry_count = ql2xloginretrycount;
7191
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007192 /* if not running MSI-X we need handshaking on interrupts */
Chad Dupuisf73cb692014-02-26 04:15:06 -05007193 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
Bart Van Asschead950362015-07-09 07:24:08 -07007194 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08007195
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007196 /* Enable ZIO. */
7197 if (!vha->flags.init_done) {
7198 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7199 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7200 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7201 le16_to_cpu(icb->interrupt_delay_timer): 2;
7202 }
Bart Van Asschead950362015-07-09 07:24:08 -07007203 icb->firmware_options_2 &= cpu_to_le32(
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007204 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7205 vha->flags.process_response_queue = 0;
7206 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7207 ha->zio_mode = QLA_ZIO_MODE_6;
7208
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007209 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007210 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007211 ha->zio_mode,
7212 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007213
7214 icb->firmware_options_2 |= cpu_to_le32(
7215 (uint32_t)ha->zio_mode);
7216 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7217 vha->flags.process_response_queue = 1;
7218 }
7219
Quinn Tran41dc5292017-01-19 22:28:03 -08007220 /* enable RIDA Format2 */
7221 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))
7222 icb->firmware_options_3 |= BIT_0;
7223
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007224 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007225 ql_log(ql_log_warn, vha, 0x0076,
7226 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007227 }
7228 return (rval);
7229}
7230
Giridhar Malavalia9083012010-04-12 17:59:55 -07007231int
7232qla82xx_restart_isp(scsi_qla_host_t *vha)
7233{
7234 int status, rval;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007235 struct qla_hw_data *ha = vha->hw;
7236 struct req_que *req = ha->req_q_map[0];
7237 struct rsp_que *rsp = ha->rsp_q_map[0];
7238 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07007239 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007240
7241 status = qla2x00_init_rings(vha);
7242 if (!status) {
7243 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7244 ha->flags.chip_reset_done = 1;
7245
7246 status = qla2x00_fw_ready(vha);
7247 if (!status) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07007248 /* Issue a marker after FW becomes ready. */
7249 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007250 vha->flags.online = 1;
Chad Dupuis7108b762014-04-11 16:54:45 -04007251 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007252 }
7253
7254 /* if no cable then assume it's good */
7255 if ((vha->device_flags & DFLG_NO_CABLE))
7256 status = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07007257 }
7258
7259 if (!status) {
7260 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7261
7262 if (!atomic_read(&vha->loop_down_timer)) {
7263 /*
7264 * Issue marker command only when we are going
7265 * to start the I/O .
7266 */
7267 vha->marker_needed = 1;
7268 }
7269
Giridhar Malavalia9083012010-04-12 17:59:55 -07007270 ha->isp_ops->enable_intrs(ha);
7271
7272 ha->isp_abort_cnt = 0;
7273 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
7274
Saurav Kashyap53296782011-05-10 11:30:06 -07007275 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07007276 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07007277
Giridhar Malavalia9083012010-04-12 17:59:55 -07007278 if (ha->fce) {
7279 ha->flags.fce_enabled = 1;
7280 memset(ha->fce, 0,
7281 fce_calc_size(ha->fce_bufs));
7282 rval = qla2x00_enable_fce_trace(vha,
7283 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
7284 &ha->fce_bufs);
7285 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007286 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007287 "Unable to reinitialize FCE (%d).\n",
7288 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007289 ha->flags.fce_enabled = 0;
7290 }
7291 }
7292
7293 if (ha->eft) {
7294 memset(ha->eft, 0, EFT_SIZE);
7295 rval = qla2x00_enable_eft_trace(vha,
7296 ha->eft_dma, EFT_NUM_BUFFERS);
7297 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007298 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007299 "Unable to reinitialize EFT (%d).\n",
7300 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07007301 }
7302 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07007303 }
7304
7305 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007306 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007307 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07007308
7309 spin_lock_irqsave(&ha->vport_slock, flags);
7310 list_for_each_entry(vp, &ha->vp_list, list) {
7311 if (vp->vp_idx) {
7312 atomic_inc(&vp->vref_count);
7313 spin_unlock_irqrestore(&ha->vport_slock, flags);
7314
Giridhar Malavalia9083012010-04-12 17:59:55 -07007315 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07007316
7317 spin_lock_irqsave(&ha->vport_slock, flags);
7318 atomic_dec(&vp->vref_count);
7319 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07007320 }
Arun Easifeafb7b2010-09-03 14:57:00 -07007321 spin_unlock_irqrestore(&ha->vport_slock, flags);
7322
Giridhar Malavalia9083012010-04-12 17:59:55 -07007323 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08007324 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007325 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07007326 }
7327
7328 return status;
7329}
7330
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007331void
Andrew Vasquezae97c912010-02-18 10:07:28 -08007332qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007333{
Andrew Vasquezae97c912010-02-18 10:07:28 -08007334 struct qla_hw_data *ha = vha->hw;
7335
Himanshu Madhanif198caf2016-01-27 12:03:30 -05007336 /* Hold status IOCBs until ABTS response received. */
7337 if (ql2xfwholdabts)
7338 ha->fw_options[3] |= BIT_12;
7339
Giridhar Malavali088d09d2016-07-06 11:14:20 -04007340 /* Set Retry FLOGI in case of P2P connection */
7341 if (ha->operating_mode == P2P) {
7342 ha->fw_options[2] |= BIT_3;
7343 ql_dbg(ql_dbg_disc, vha, 0x2103,
7344 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
7345 __func__, ha->fw_options[2]);
7346 }
7347
Quinn Tran41dc5292017-01-19 22:28:03 -08007348 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
7349 if (ql2xmvasynctoatio) {
7350 if (qla_tgt_mode_enabled(vha) ||
7351 qla_dual_mode_enabled(vha))
7352 ha->fw_options[2] |= BIT_11;
7353 else
7354 ha->fw_options[2] &= ~BIT_11;
7355 }
Andrew Vasquezae97c912010-02-18 10:07:28 -08007356
Quinn Tran41dc5292017-01-19 22:28:03 -08007357 if (ql2xetsenable) {
7358 /* Enable ETS Burst. */
7359 memset(ha->fw_options, 0, sizeof(ha->fw_options));
7360 ha->fw_options[2] |= BIT_9;
7361 }
7362
7363 ql_dbg(ql_dbg_init, vha, 0xffff,
7364 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
7365 __func__, ha->fw_options[1], ha->fw_options[2],
7366 ha->fw_options[3], vha->host->active_mode);
7367
Andrew Vasquezae97c912010-02-18 10:07:28 -08007368 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08007369}
Sarang Radke09ff7012010-03-19 17:03:59 -07007370
7371/*
7372 * qla24xx_get_fcp_prio
7373 * Gets the fcp cmd priority value for the logged in port.
7374 * Looks for a match of the port descriptors within
7375 * each of the fcp prio config entries. If a match is found,
7376 * the tag (priority) value is returned.
7377 *
7378 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007379 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07007380 * fcport = port structure pointer.
7381 *
7382 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07007383 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007384 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07007385 *
7386 * Context:
7387 * Kernel context
7388 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007389static int
Sarang Radke09ff7012010-03-19 17:03:59 -07007390qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
7391{
7392 int i, entries;
7393 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007394 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07007395 uint32_t pid1, pid2;
7396 uint64_t wwn1, wwn2;
7397 struct qla_fcp_prio_entry *pri_entry;
7398 struct qla_hw_data *ha = vha->hw;
7399
7400 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007401 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07007402
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007403 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07007404 entries = ha->fcp_prio_cfg->num_entries;
7405 pri_entry = &ha->fcp_prio_cfg->entry[0];
7406
7407 for (i = 0; i < entries; i++) {
7408 pid_match = wwn_match = 0;
7409
7410 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
7411 pri_entry++;
7412 continue;
7413 }
7414
7415 /* check source pid for a match */
7416 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
7417 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
7418 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
7419 if (pid1 == INVALID_PORT_ID)
7420 pid_match++;
7421 else if (pid1 == pid2)
7422 pid_match++;
7423 }
7424
7425 /* check destination pid for a match */
7426 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
7427 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
7428 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
7429 if (pid1 == INVALID_PORT_ID)
7430 pid_match++;
7431 else if (pid1 == pid2)
7432 pid_match++;
7433 }
7434
7435 /* check source WWN for a match */
7436 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
7437 wwn1 = wwn_to_u64(vha->port_name);
7438 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
7439 if (wwn2 == (uint64_t)-1)
7440 wwn_match++;
7441 else if (wwn1 == wwn2)
7442 wwn_match++;
7443 }
7444
7445 /* check destination WWN for a match */
7446 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
7447 wwn1 = wwn_to_u64(fcport->port_name);
7448 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
7449 if (wwn2 == (uint64_t)-1)
7450 wwn_match++;
7451 else if (wwn1 == wwn2)
7452 wwn_match++;
7453 }
7454
7455 if (pid_match == 2 || wwn_match == 2) {
7456 /* Found a matching entry */
7457 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
7458 priority = pri_entry->tag;
7459 break;
7460 }
7461
7462 pri_entry++;
7463 }
7464
7465 return priority;
7466}
7467
7468/*
7469 * qla24xx_update_fcport_fcp_prio
7470 * Activates fcp priority for the logged in fc port
7471 *
7472 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007473 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07007474 * fcp = port structure pointer.
7475 *
7476 * Return:
7477 * QLA_SUCCESS or QLA_FUNCTION_FAILED
7478 *
7479 * Context:
7480 * Kernel context.
7481 */
7482int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007483qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07007484{
7485 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007486 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07007487 uint16_t mb[5];
7488
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007489 if (fcport->port_type != FCT_TARGET ||
7490 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07007491 return QLA_FUNCTION_FAILED;
7492
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007493 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07007494 if (priority < 0)
7495 return QLA_FUNCTION_FAILED;
7496
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04007497 if (IS_P3P_TYPE(vha->hw)) {
Saurav Kashyapa00f6292011-11-18 09:03:19 -08007498 fcport->fcp_prio = priority & 0xf;
7499 return QLA_SUCCESS;
7500 }
7501
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08007502 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08007503 if (ret == QLA_SUCCESS) {
7504 if (fcport->fcp_prio != priority)
7505 ql_dbg(ql_dbg_user, vha, 0x709e,
7506 "Updated FCP_CMND priority - value=%d loop_id=%d "
7507 "port_id=%02x%02x%02x.\n", priority,
7508 fcport->loop_id, fcport->d_id.b.domain,
7509 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08007510 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08007511 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07007512 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08007513 "Unable to update FCP_CMND priority - ret=0x%x for "
7514 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
7515 fcport->d_id.b.domain, fcport->d_id.b.area,
7516 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07007517 return ret;
7518}
7519
7520/*
7521 * qla24xx_update_all_fcp_prio
7522 * Activates fcp priority for all the logged in ports
7523 *
7524 * Input:
7525 * ha = adapter block pointer.
7526 *
7527 * Return:
7528 * QLA_SUCCESS or QLA_FUNCTION_FAILED
7529 *
7530 * Context:
7531 * Kernel context.
7532 */
7533int
7534qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
7535{
7536 int ret;
7537 fc_port_t *fcport;
7538
7539 ret = QLA_FUNCTION_FAILED;
7540 /* We need to set priority for all logged in ports */
7541 list_for_each_entry(fcport, &vha->vp_fcports, list)
7542 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
7543
7544 return ret;
7545}
Michael Hernandezd7459522016-12-12 14:40:07 -08007546
7547struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos, int vp_idx)
7548{
7549 int rsp_id = 0;
7550 int req_id = 0;
7551 int i;
7552 struct qla_hw_data *ha = vha->hw;
7553 uint16_t qpair_id = 0;
7554 struct qla_qpair *qpair = NULL;
7555 struct qla_msix_entry *msix;
7556
7557 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
7558 ql_log(ql_log_warn, vha, 0x00181,
7559 "FW/Driver is not multi-queue capable.\n");
7560 return NULL;
7561 }
7562
7563 if (ql2xmqsupport) {
7564 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
7565 if (qpair == NULL) {
7566 ql_log(ql_log_warn, vha, 0x0182,
7567 "Failed to allocate memory for queue pair.\n");
7568 return NULL;
7569 }
7570 memset(qpair, 0, sizeof(struct qla_qpair));
7571
7572 qpair->hw = vha->hw;
Joe Carnuccio25ff6af2017-01-19 22:28:04 -08007573 qpair->vha = vha;
Michael Hernandezd7459522016-12-12 14:40:07 -08007574
7575 /* Assign available que pair id */
7576 mutex_lock(&ha->mq_lock);
7577 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
7578 if (qpair_id >= ha->max_qpairs) {
7579 mutex_unlock(&ha->mq_lock);
7580 ql_log(ql_log_warn, vha, 0x0183,
7581 "No resources to create additional q pair.\n");
7582 goto fail_qid_map;
7583 }
7584 set_bit(qpair_id, ha->qpair_qid_map);
7585 ha->queue_pair_map[qpair_id] = qpair;
7586 qpair->id = qpair_id;
7587 qpair->vp_idx = vp_idx;
7588
7589 for (i = 0; i < ha->msix_count; i++) {
Quinn Tran093df732016-12-12 14:40:09 -08007590 msix = &ha->msix_entries[i];
Michael Hernandezd7459522016-12-12 14:40:07 -08007591 if (msix->in_use)
7592 continue;
7593 qpair->msix = msix;
7594 ql_log(ql_dbg_multiq, vha, 0xc00f,
7595 "Vector %x selected for qpair\n", msix->vector);
7596 break;
7597 }
7598 if (!qpair->msix) {
7599 ql_log(ql_log_warn, vha, 0x0184,
7600 "Out of MSI-X vectors!.\n");
7601 goto fail_msix;
7602 }
7603
7604 qpair->msix->in_use = 1;
7605 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
7606
7607 mutex_unlock(&ha->mq_lock);
7608
7609 /* Create response queue first */
7610 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair);
7611 if (!rsp_id) {
7612 ql_log(ql_log_warn, vha, 0x0185,
7613 "Failed to create response queue.\n");
7614 goto fail_rsp;
7615 }
7616
7617 qpair->rsp = ha->rsp_q_map[rsp_id];
7618
7619 /* Create request queue */
7620 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos);
7621 if (!req_id) {
7622 ql_log(ql_log_warn, vha, 0x0186,
7623 "Failed to create request queue.\n");
7624 goto fail_req;
7625 }
7626
7627 qpair->req = ha->req_q_map[req_id];
7628 qpair->rsp->req = qpair->req;
7629
7630 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
7631 if (ha->fw_attributes & BIT_4)
7632 qpair->difdix_supported = 1;
7633 }
7634
7635 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
7636 if (!qpair->srb_mempool) {
7637 ql_log(ql_log_warn, vha, 0x0191,
7638 "Failed to create srb mempool for qpair %d\n",
7639 qpair->id);
7640 goto fail_mempool;
7641 }
7642
7643 /* Mark as online */
7644 qpair->online = 1;
7645
7646 if (!vha->flags.qpairs_available)
7647 vha->flags.qpairs_available = 1;
7648
7649 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
7650 "Request/Response queue pair created, id %d\n",
7651 qpair->id);
7652 ql_dbg(ql_dbg_init, vha, 0x0187,
7653 "Request/Response queue pair created, id %d\n",
7654 qpair->id);
7655 }
7656 return qpair;
7657
7658fail_mempool:
7659fail_req:
7660 qla25xx_delete_rsp_que(vha, qpair->rsp);
7661fail_rsp:
7662 mutex_lock(&ha->mq_lock);
7663 qpair->msix->in_use = 0;
7664 list_del(&qpair->qp_list_elem);
7665 if (list_empty(&vha->qp_list))
7666 vha->flags.qpairs_available = 0;
7667fail_msix:
7668 ha->queue_pair_map[qpair_id] = NULL;
7669 clear_bit(qpair_id, ha->qpair_qid_map);
7670 mutex_unlock(&ha->mq_lock);
7671fail_qid_map:
7672 kfree(qpair);
7673 return NULL;
7674}
7675
7676int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
7677{
7678 int ret;
7679 struct qla_hw_data *ha = qpair->hw;
7680
7681 qpair->delete_in_progress = 1;
7682 while (atomic_read(&qpair->ref_count))
7683 msleep(500);
7684
7685 ret = qla25xx_delete_req_que(vha, qpair->req);
7686 if (ret != QLA_SUCCESS)
7687 goto fail;
7688 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
7689 if (ret != QLA_SUCCESS)
7690 goto fail;
7691
7692 mutex_lock(&ha->mq_lock);
7693 ha->queue_pair_map[qpair->id] = NULL;
7694 clear_bit(qpair->id, ha->qpair_qid_map);
7695 list_del(&qpair->qp_list_elem);
7696 if (list_empty(&vha->qp_list))
7697 vha->flags.qpairs_available = 0;
7698 mempool_destroy(qpair->srb_mempool);
7699 kfree(qpair);
7700 mutex_unlock(&ha->mq_lock);
7701
7702 return QLA_SUCCESS;
7703fail:
7704 return ret;
7705}