blob: edb4f8e993fca9d02bad64dbbf56a8d15fb64c72 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Saurav Kashyap1e633952013-02-08 01:57:54 -05003 * Copyright (c) 2003-2013 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
Anirban Chakraborty73208df2008-12-09 16:45:39 -08008#include "qla_gbl.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Andrew Vasquez0107109e2005-07-06 10:31:37 -070012#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#include "qla_devtbl.h"
15
David Miller4e08df32007-04-16 12:37:43 -070016#ifdef CONFIG_SPARC
17#include <asm/prom.h>
David Miller4e08df32007-04-16 12:37:43 -070018#endif
19
Nicholas Bellinger2d70c102012-05-15 14:34:28 -040020#include <target/target_core_base.h>
21#include "qla_target.h"
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023/*
24* QLogic ISP2x00 Hardware Support Function Prototypes.
25*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070026static int qla2x00_isp_firmware(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027static int qla2x00_setup_chip(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028static int qla2x00_init_rings(scsi_qla_host_t *);
29static int qla2x00_fw_ready(scsi_qla_host_t *);
30static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031static int qla2x00_configure_loop(scsi_qla_host_t *);
32static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033static int qla2x00_configure_fabric(scsi_qla_host_t *);
34static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
36 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Harihara Kadayam4d4df192008-04-03 13:13:26 -070040static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
41static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080042static int qla25xx_init_queues(struct qla_hw_data *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070043
Andrew Vasquezac280b62009-08-20 11:06:05 -070044/* SRB Extensions ---------------------------------------------------------- */
45
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080046void
47qla2x00_sp_timeout(unsigned long __data)
Andrew Vasquezac280b62009-08-20 11:06:05 -070048{
49 srb_t *sp = (srb_t *)__data;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070050 struct srb_iocb *iocb;
Andrew Vasquezac280b62009-08-20 11:06:05 -070051 fc_port_t *fcport = sp->fcport;
52 struct qla_hw_data *ha = fcport->vha->hw;
53 struct req_que *req;
54 unsigned long flags;
55
56 spin_lock_irqsave(&ha->hardware_lock, flags);
57 req = ha->req_q_map[0];
58 req->outstanding_cmds[sp->handle] = NULL;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080059 iocb = &sp->u.iocb_cmd;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070060 iocb->timeout(sp);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080061 sp->free(fcport->vha, sp);
Andrew Vasquez6ac52602010-05-28 15:08:19 -070062 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -070063}
64
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080065void
66qla2x00_sp_free(void *data, void *ptr)
Andrew Vasquezac280b62009-08-20 11:06:05 -070067{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080068 srb_t *sp = (srb_t *)ptr;
69 struct srb_iocb *iocb = &sp->u.iocb_cmd;
70 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquezac280b62009-08-20 11:06:05 -070071
Chad Dupuis4d97cc52010-10-15 11:27:41 -070072 del_timer(&iocb->timer);
Chad Dupuisb00ee7d2013-02-08 01:57:50 -050073 qla2x00_rel_sp(vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -070074}
75
Andrew Vasquezac280b62009-08-20 11:06:05 -070076/* Asynchronous Login/Logout Routines -------------------------------------- */
77
Saurav Kashyapa9b6f722012-08-22 14:21:01 -040078unsigned long
Andrew Vasquez5b914902010-05-28 15:08:30 -070079qla2x00_get_async_timeout(struct scsi_qla_host *vha)
80{
81 unsigned long tmo;
82 struct qla_hw_data *ha = vha->hw;
83
84 /* Firmware should use switch negotiated r_a_tov for timeout. */
85 tmo = ha->r_a_tov / 10 * 2;
86 if (!IS_FWI2_CAPABLE(ha)) {
87 /*
88 * Except for earlier ISPs where the timeout is seeded from the
89 * initialization control block.
90 */
91 tmo = ha->login_timeout;
92 }
93 return tmo;
94}
Andrew Vasquezac280b62009-08-20 11:06:05 -070095
96static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080097qla2x00_async_iocb_timeout(void *data)
Andrew Vasquezac280b62009-08-20 11:06:05 -070098{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080099 srb_t *sp = (srb_t *)data;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700100 fc_port_t *fcport = sp->fcport;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700101
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700102 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800103 "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800104 sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700105 fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700106
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700107 fcport->flags &= ~FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800108 if (sp->type == SRB_LOGIN_CMD) {
109 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700110 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
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;
115 qla2x00_post_async_login_done_work(fcport->vha, fcport,
116 lio->u.logio.data);
117 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700118}
119
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700120static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800121qla2x00_async_login_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700122{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800123 srb_t *sp = (srb_t *)ptr;
124 struct srb_iocb *lio = &sp->u.iocb_cmd;
125 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700126
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800127 if (!test_bit(UNLOADING, &vha->dpc_flags))
128 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
129 lio->u.logio.data);
130 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700131}
132
Andrew Vasquezac280b62009-08-20 11:06:05 -0700133int
134qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
135 uint16_t *data)
136{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700137 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700138 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700139 int rval;
140
141 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800142 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700143 if (!sp)
144 goto done;
145
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800146 sp->type = SRB_LOGIN_CMD;
147 sp->name = "login";
148 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
149
150 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700151 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800152 sp->done = qla2x00_async_login_sp_done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700153 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700154 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700155 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700156 rval = qla2x00_start_sp(sp);
157 if (rval != QLA_SUCCESS)
158 goto done_free_sp;
159
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700160 ql_dbg(ql_dbg_disc, vha, 0x2072,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800161 "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
162 "retries=%d.\n", sp->handle, fcport->loop_id,
163 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
164 fcport->login_retry);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700165 return rval;
166
167done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800168 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700169done:
170 return rval;
171}
172
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700173static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800174qla2x00_async_logout_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700175{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800176 srb_t *sp = (srb_t *)ptr;
177 struct srb_iocb *lio = &sp->u.iocb_cmd;
178 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700179
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800180 if (!test_bit(UNLOADING, &vha->dpc_flags))
181 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
182 lio->u.logio.data);
183 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700184}
185
Andrew Vasquezac280b62009-08-20 11:06:05 -0700186int
187qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
188{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700189 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700190 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700191 int rval;
192
193 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800194 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700195 if (!sp)
196 goto done;
197
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800198 sp->type = SRB_LOGOUT_CMD;
199 sp->name = "logout";
200 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
201
202 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700203 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800204 sp->done = qla2x00_async_logout_sp_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700205 rval = qla2x00_start_sp(sp);
206 if (rval != QLA_SUCCESS)
207 goto done_free_sp;
208
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700209 ql_dbg(ql_dbg_disc, vha, 0x2070,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800210 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
211 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
212 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700213 return rval;
214
215done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800216 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700217done:
218 return rval;
219}
220
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700221static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800222qla2x00_async_adisc_sp_done(void *data, void *ptr, int res)
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700223{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800224 srb_t *sp = (srb_t *)ptr;
225 struct srb_iocb *lio = &sp->u.iocb_cmd;
226 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700227
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800228 if (!test_bit(UNLOADING, &vha->dpc_flags))
229 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
230 lio->u.logio.data);
231 sp->free(sp->fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700232}
233
234int
235qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
236 uint16_t *data)
237{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700238 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700239 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700240 int rval;
241
242 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800243 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700244 if (!sp)
245 goto done;
246
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800247 sp->type = SRB_ADISC_CMD;
248 sp->name = "adisc";
249 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
250
251 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700252 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800253 sp->done = qla2x00_async_adisc_sp_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700254 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700255 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700256 rval = qla2x00_start_sp(sp);
257 if (rval != QLA_SUCCESS)
258 goto done_free_sp;
259
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700260 ql_dbg(ql_dbg_disc, vha, 0x206f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800261 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
262 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
263 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700264 return rval;
265
266done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800267 sp->free(fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700268done:
269 return rval;
270}
271
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700272static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800273qla2x00_async_tm_cmd_done(void *data, void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700274{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800275 srb_t *sp = (srb_t *)ptr;
276 struct srb_iocb *iocb = &sp->u.iocb_cmd;
277 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
278 uint32_t flags;
279 uint16_t lun;
280 int rval;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700281
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800282 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
283 flags = iocb->u.tmf.flags;
284 lun = (uint16_t)iocb->u.tmf.lun;
285
286 /* Issue Marker IOCB */
287 rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
288 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
289 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
290
291 if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
292 ql_dbg(ql_dbg_taskm, vha, 0x8030,
293 "TM IOCB failed (%x).\n", rval);
294 }
295 }
296 sp->free(sp->fcport->vha, sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700297}
298
299int
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800300qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t tm_flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700301 uint32_t tag)
302{
303 struct scsi_qla_host *vha = fcport->vha;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700304 srb_t *sp;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700305 struct srb_iocb *tcf;
306 int rval;
307
308 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800309 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700310 if (!sp)
311 goto done;
312
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800313 sp->type = SRB_TM_CMD;
314 sp->name = "tmf";
315 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
316
317 tcf = &sp->u.iocb_cmd;
318 tcf->u.tmf.flags = tm_flags;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700319 tcf->u.tmf.lun = lun;
320 tcf->u.tmf.data = tag;
321 tcf->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800322 sp->done = qla2x00_async_tm_cmd_done;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700323
324 rval = qla2x00_start_sp(sp);
325 if (rval != QLA_SUCCESS)
326 goto done_free_sp;
327
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700328 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800329 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
330 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
331 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700332 return rval;
333
334done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800335 sp->free(fcport->vha, sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700336done:
337 return rval;
338}
339
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700340void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700341qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
342 uint16_t *data)
343{
344 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700345
346 switch (data[0]) {
347 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700348 /*
349 * Driver must validate login state - If PRLI not complete,
350 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
351 * requests.
352 */
353 rval = qla2x00_get_port_database(vha, fcport, 0);
Arun Easi0eba25d2012-02-09 11:15:58 -0800354 if (rval == QLA_NOT_LOGGED_IN) {
355 fcport->flags &= ~FCF_ASYNC_SENT;
356 fcport->flags |= FCF_LOGIN_NEEDED;
357 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
358 break;
359 }
360
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700361 if (rval != QLA_SUCCESS) {
362 qla2x00_post_async_logout_work(vha, fcport, NULL);
363 qla2x00_post_async_login_work(vha, fcport, NULL);
364 break;
365 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700366 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700367 qla2x00_post_async_adisc_work(vha, fcport, data);
368 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700369 }
370 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700371 break;
372 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700373 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700374 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
375 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
376 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700377 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700378 break;
379 case MBS_PORT_ID_USED:
380 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700381 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700382 qla2x00_post_async_login_work(vha, fcport, NULL);
383 break;
384 case MBS_LOOP_ID_USED:
385 fcport->loop_id++;
386 rval = qla2x00_find_new_loop_id(vha, fcport);
387 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700388 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez80d79442011-03-30 11:46:17 -0700389 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700390 break;
391 }
392 qla2x00_post_async_login_work(vha, fcport, NULL);
393 break;
394 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700395 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700396}
397
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700398void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700399qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
400 uint16_t *data)
401{
402 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700403 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700404}
405
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700406void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700407qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
408 uint16_t *data)
409{
410 if (data[0] == MBS_COMMAND_COMPLETE) {
411 qla2x00_update_fcport(vha, fcport);
412
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700413 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700414 }
415
416 /* Retry login. */
417 fcport->flags &= ~FCF_ASYNC_SENT;
418 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
419 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
420 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700421 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700422
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700423 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700424}
425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426/****************************************************************************/
427/* QLogic ISP2x00 Hardware Support Functions. */
428/****************************************************************************/
429
Saurav Kashyapfa492632012-11-21 02:40:29 -0500430static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400431qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
432{
433 int rval = QLA_SUCCESS;
434 struct qla_hw_data *ha = vha->hw;
435 uint32_t idc_major_ver, idc_minor_ver;
Saurav Kashyap711aa7f2012-08-22 14:21:15 -0400436 uint16_t config[4];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400437
438 qla83xx_idc_lock(vha, 0);
439
440 /* SV: TODO: Assign initialization timeout from
441 * flash-info / other param
442 */
443 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
444 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
445
446 /* Set our fcoe function presence */
447 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
448 ql_dbg(ql_dbg_p3p, vha, 0xb077,
449 "Error while setting DRV-Presence.\n");
450 rval = QLA_FUNCTION_FAILED;
451 goto exit;
452 }
453
454 /* Decide the reset ownership */
455 qla83xx_reset_ownership(vha);
456
457 /*
458 * On first protocol driver load:
459 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
460 * register.
461 * Others: Check compatibility with current IDC Major version.
462 */
463 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
464 if (ha->flags.nic_core_reset_owner) {
465 /* Set IDC Major version */
466 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
467 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
468
469 /* Clearing IDC-Lock-Recovery register */
470 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
471 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
472 /*
473 * Clear further IDC participation if we are not compatible with
474 * the current IDC Major Version.
475 */
476 ql_log(ql_log_warn, vha, 0xb07d,
477 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
478 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
479 __qla83xx_clear_drv_presence(vha);
480 rval = QLA_FUNCTION_FAILED;
481 goto exit;
482 }
483 /* Each function sets its supported Minor version. */
484 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
485 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
486 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
487
Saurav Kashyap711aa7f2012-08-22 14:21:15 -0400488 if (ha->flags.nic_core_reset_owner) {
489 memset(config, 0, sizeof(config));
490 if (!qla81xx_get_port_config(vha, config))
491 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
492 QLA8XXX_DEV_READY);
493 }
494
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400495 rval = qla83xx_idc_state_handler(vha);
496
497exit:
498 qla83xx_idc_unlock(vha, 0);
499
500 return rval;
501}
502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503/*
504* qla2x00_initialize_adapter
505* Initialize board.
506*
507* Input:
508* ha = adapter block pointer.
509*
510* Returns:
511* 0 = success
512*/
513int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800514qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
516 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800517 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800518 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800521 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700522 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800523 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800524 ha->flags.pci_channel_io_perm_failure = 0;
525 ha->flags.eeh_busy = 0;
Andrew Vasquez794a5692010-12-21 16:00:21 -0800526 ha->flags.thermal_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800527 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
528 atomic_set(&vha->loop_state, LOOP_DOWN);
529 vha->device_flags = DFLG_NO_CABLE;
530 vha->dpc_flags = 0;
531 vha->flags.management_server_logged_in = 0;
532 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 ha->isp_abort_cnt = 0;
534 ha->beacon_blink_led = 0;
535
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800536 set_bit(0, ha->req_qid_map);
537 set_bit(0, ha->rsp_qid_map);
538
Chad Dupuiscfb09192011-11-18 09:03:07 -0800539 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700540 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800541 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700543 ql_log(ql_log_warn, vha, 0x0044,
544 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 return (rval);
546 }
547
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800548 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800550 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700551 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700552 ql_log(ql_log_fatal, vha, 0x004f,
553 "Unable to validate FLASH data.\n");
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700554 return (rval);
555 }
556
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800557 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -0800558 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700559 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700560
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800561 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700563 if (ha->flags.disable_serdes) {
564 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700565 ql_log(ql_log_info, vha, 0x0077,
566 "Masking HBA WWPN "
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700567 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800568 vha->port_name[0], vha->port_name[1],
569 vha->port_name[2], vha->port_name[3],
570 vha->port_name[4], vha->port_name[5],
571 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700572 return QLA_FUNCTION_FAILED;
573 }
574
Chad Dupuiscfb09192011-11-18 09:03:07 -0800575 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700576 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800578 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
579 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800580 if (rval)
581 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800582 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800583 if (rval)
584 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700586
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700587 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800588 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700589 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700590 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700591 "Unable to configure ISP84XX.\n");
592 return QLA_FUNCTION_FAILED;
593 }
594 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400595
596 if (qla_ini_mode_enabled(vha))
597 rval = qla2x00_init_rings(vha);
598
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700599 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800601 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700602 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800603 rval = qla84xx_init_chip(vha);
604 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700605 ql_log(ql_log_warn, vha, 0x00d4,
606 "Unable to initialize ISP84XX.\n");
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800607 qla84xx_put_chip(vha);
608 }
609 }
610
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400611 /* Load the NIC Core f/w if we are the first protocol driver. */
612 if (IS_QLA8031(ha)) {
613 rval = qla83xx_nic_core_fw_load(vha);
614 if (rval)
615 ql_log(ql_log_warn, vha, 0x0124,
616 "Error in initializing NIC Core f/w.\n");
617 }
618
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500619 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
620 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 return (rval);
623}
624
625/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700626 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 * @ha: HA context
628 *
629 * Returns 0 on success.
630 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700631int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800632qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700634 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700635 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800636 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700637 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700640 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700643 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
645
Andrew Vasquez737faec2008-10-24 15:13:45 -0700646 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700648 /* Get PCI bus information. */
649 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700650 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700651 spin_unlock_irqrestore(&ha->hardware_lock, flags);
652
653 return QLA_SUCCESS;
654}
655
656/**
657 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
658 * @ha: HA context
659 *
660 * Returns 0 on success.
661 */
662int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800663qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700664{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700665 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700666 unsigned long flags = 0;
667 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800668 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700669 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700670
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700671 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700672 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700673
674 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700675 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700676
677 if (IS_QLA2322(ha) || IS_QLA6322(ha))
678 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700679 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700680
681 /*
682 * If this is a 2300 card and not 2312, reset the
683 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
684 * the 2310 also reports itself as a 2300 so we need to get the
685 * fb revision level -- a 6 indicates it really is a 2300 and
686 * not a 2310.
687 */
688 if (IS_QLA2300(ha)) {
689 spin_lock_irqsave(&ha->hardware_lock, flags);
690
691 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700692 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700693 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700694 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700695 break;
696
697 udelay(10);
698 }
699
700 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700701 WRT_REG_WORD(&reg->ctrl_status, 0x20);
702 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700703
704 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700705 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700706
707 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700708 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700709
710 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700711 WRT_REG_WORD(&reg->ctrl_status, 0x0);
712 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700713
714 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700715 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700716 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700717 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700718 break;
719
720 udelay(10);
721 }
722
723 spin_unlock_irqrestore(&ha->hardware_lock, flags);
724 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700725
726 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
727
Andrew Vasquez737faec2008-10-24 15:13:45 -0700728 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700729
730 /* Get PCI bus information. */
731 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700732 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700733 spin_unlock_irqrestore(&ha->hardware_lock, flags);
734
735 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736}
737
738/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700739 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
740 * @ha: HA context
741 *
742 * Returns 0 on success.
743 */
744int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800745qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700746{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700747 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700748 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800749 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700750 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700751
752 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700753 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700754
755 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700756 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700757 w &= ~PCI_COMMAND_INTX_DISABLE;
758 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
759
760 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
761
762 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700763 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
764 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700765
766 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700767 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -0400768 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700769
Andrew Vasquez737faec2008-10-24 15:13:45 -0700770 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700771
Auke Kok44c10132007-06-08 15:46:36 -0700772 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800773
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700774 /* Get PCI bus information. */
775 spin_lock_irqsave(&ha->hardware_lock, flags);
776 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
777 spin_unlock_irqrestore(&ha->hardware_lock, flags);
778
779 return QLA_SUCCESS;
780}
781
782/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700783 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
784 * @ha: HA context
785 *
786 * Returns 0 on success.
787 */
788int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800789qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700790{
791 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800792 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700793
794 pci_set_master(ha->pdev);
795 pci_try_set_mwi(ha->pdev);
796
797 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
798 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
799 w &= ~PCI_COMMAND_INTX_DISABLE;
800 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
801
802 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700803 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -0400804 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700805
Andrew Vasquez737faec2008-10-24 15:13:45 -0700806 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700807
808 ha->chip_revision = ha->pdev->revision;
809
810 return QLA_SUCCESS;
811}
812
813/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 * qla2x00_isp_firmware() - Choose firmware image.
815 * @ha: HA context
816 *
817 * Returns 0 on success.
818 */
819static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800820qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
822 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700823 uint16_t loop_id, topo, sw_cap;
824 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800825 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
827 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700828 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700831 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
833 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800834 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700835 if (rval == QLA_SUCCESS) {
836 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800837 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700838 &area, &domain, &topo, &sw_cap);
839 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 }
841
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700842 if (rval)
843 ql_dbg(ql_dbg_init, vha, 0x007a,
844 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
846 return (rval);
847}
848
849/**
850 * qla2x00_reset_chip() - Reset ISP chip.
851 * @ha: HA context
852 *
853 * Returns 0 on success.
854 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700855void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800856qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857{
858 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800859 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700860 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 uint16_t cmd;
863
Andrew Vasquez85880802009-12-15 21:29:46 -0800864 if (unlikely(pci_channel_offline(ha->pdev)))
865 return;
866
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700867 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
869 spin_lock_irqsave(&ha->hardware_lock, flags);
870
871 /* Turn off master enable */
872 cmd = 0;
873 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
874 cmd &= ~PCI_COMMAND_MASTER;
875 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
876
877 if (!IS_QLA2100(ha)) {
878 /* Pause RISC. */
879 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
880 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
881 for (cnt = 0; cnt < 30000; cnt++) {
882 if ((RD_REG_WORD(&reg->hccr) &
883 HCCR_RISC_PAUSE) != 0)
884 break;
885 udelay(100);
886 }
887 } else {
888 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
889 udelay(10);
890 }
891
892 /* Select FPM registers. */
893 WRT_REG_WORD(&reg->ctrl_status, 0x20);
894 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
895
896 /* FPM Soft Reset. */
897 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
898 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
899
900 /* Toggle Fpm Reset. */
901 if (!IS_QLA2200(ha)) {
902 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
903 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
904 }
905
906 /* Select frame buffer registers. */
907 WRT_REG_WORD(&reg->ctrl_status, 0x10);
908 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
909
910 /* Reset frame buffer FIFOs. */
911 if (IS_QLA2200(ha)) {
912 WRT_FB_CMD_REG(ha, reg, 0xa000);
913 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
914 } else {
915 WRT_FB_CMD_REG(ha, reg, 0x00fc);
916
917 /* Read back fb_cmd until zero or 3 seconds max */
918 for (cnt = 0; cnt < 3000; cnt++) {
919 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
920 break;
921 udelay(100);
922 }
923 }
924
925 /* Select RISC module registers. */
926 WRT_REG_WORD(&reg->ctrl_status, 0);
927 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
928
929 /* Reset RISC processor. */
930 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
931 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
932
933 /* Release RISC processor. */
934 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
935 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
936 }
937
938 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
939 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
940
941 /* Reset ISP chip. */
942 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
943
944 /* Wait for RISC to recover from reset. */
945 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
946 /*
947 * It is necessary to for a delay here since the card doesn't
948 * respond to PCI reads during a reset. On some architectures
949 * this will result in an MCA.
950 */
951 udelay(20);
952 for (cnt = 30000; cnt; cnt--) {
953 if ((RD_REG_WORD(&reg->ctrl_status) &
954 CSR_ISP_SOFT_RESET) == 0)
955 break;
956 udelay(100);
957 }
958 } else
959 udelay(10);
960
961 /* Reset RISC processor. */
962 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
963
964 WRT_REG_WORD(&reg->semaphore, 0);
965
966 /* Release RISC processor. */
967 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
968 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
969
970 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
971 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700972 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
975 udelay(100);
976 }
977 } else
978 udelay(100);
979
980 /* Turn on master enable */
981 cmd |= PCI_COMMAND_MASTER;
982 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
983
984 /* Disable RISC pause on FPM parity error. */
985 if (!IS_QLA2100(ha)) {
986 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
987 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
988 }
989
990 spin_unlock_irqrestore(&ha->hardware_lock, flags);
991}
992
993/**
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700994 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
995 *
996 * Returns 0 on success.
997 */
Saurav Kashyapfa492632012-11-21 02:40:29 -0500998static int
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700999qla81xx_reset_mpi(scsi_qla_host_t *vha)
1000{
1001 uint16_t mb[4] = {0x1010, 0, 1, 0};
1002
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001003 if (!IS_QLA81XX(vha->hw))
1004 return QLA_SUCCESS;
1005
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001006 return qla81xx_write_mpi_register(vha, mb);
1007}
1008
1009/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001010 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001011 * @ha: HA context
1012 *
1013 * Returns 0 on success.
1014 */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001015static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001016qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001017{
1018 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001019 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001020 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1021 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001022 uint16_t wd;
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001023 static int abts_cnt; /* ISP abort retry counts */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001024
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001025 spin_lock_irqsave(&ha->hardware_lock, flags);
1026
1027 /* Reset RISC. */
1028 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1029 for (cnt = 0; cnt < 30000; cnt++) {
1030 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
1031 break;
1032
1033 udelay(10);
1034 }
1035
1036 WRT_REG_DWORD(&reg->ctrl_status,
1037 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001038 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001039
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001040 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001041 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001042 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1043 for (cnt = 10000 ; cnt && d2; cnt--) {
1044 udelay(5);
1045 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1046 barrier();
1047 }
1048
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001049 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001050 d2 = RD_REG_DWORD(&reg->ctrl_status);
1051 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1052 udelay(5);
1053 d2 = RD_REG_DWORD(&reg->ctrl_status);
1054 barrier();
1055 }
1056
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001057 /* If required, do an MPI FW reset now */
1058 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1059 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1060 if (++abts_cnt < 5) {
1061 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1062 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1063 } else {
1064 /*
1065 * We exhausted the ISP abort retries. We have to
1066 * set the board offline.
1067 */
1068 abts_cnt = 0;
1069 vha->flags.online = 0;
1070 }
1071 }
1072 }
1073
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001074 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1075 RD_REG_DWORD(&reg->hccr);
1076
1077 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1078 RD_REG_DWORD(&reg->hccr);
1079
1080 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1081 RD_REG_DWORD(&reg->hccr);
1082
1083 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1084 for (cnt = 6000000 ; cnt && d2; cnt--) {
1085 udelay(5);
1086 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1087 barrier();
1088 }
1089
1090 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001091
1092 if (IS_NOPOLLING_TYPE(ha))
1093 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001094}
1095
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001096static void
1097qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
1098{
1099 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1100
1101 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1102 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
1103
1104}
1105
1106static void
1107qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
1108{
1109 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1110
1111 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1112 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
1113}
1114
1115static void
1116qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
1117{
1118 struct qla_hw_data *ha = vha->hw;
1119 uint32_t wd32 = 0;
1120 uint delta_msec = 100;
1121 uint elapsed_msec = 0;
1122 uint timeout_msec;
1123 ulong n;
1124
1125 if (!IS_QLA25XX(ha) && !IS_QLA2031(ha))
1126 return;
1127
1128attempt:
1129 timeout_msec = TIMEOUT_SEMAPHORE;
1130 n = timeout_msec / delta_msec;
1131 while (n--) {
1132 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
1133 qla25xx_read_risc_sema_reg(vha, &wd32);
1134 if (wd32 & RISC_SEMAPHORE)
1135 break;
1136 msleep(delta_msec);
1137 elapsed_msec += delta_msec;
1138 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1139 goto force;
1140 }
1141
1142 if (!(wd32 & RISC_SEMAPHORE))
1143 goto force;
1144
1145 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1146 goto acquired;
1147
1148 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
1149 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
1150 n = timeout_msec / delta_msec;
1151 while (n--) {
1152 qla25xx_read_risc_sema_reg(vha, &wd32);
1153 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1154 break;
1155 msleep(delta_msec);
1156 elapsed_msec += delta_msec;
1157 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1158 goto force;
1159 }
1160
1161 if (wd32 & RISC_SEMAPHORE_FORCE)
1162 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
1163
1164 goto attempt;
1165
1166force:
1167 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
1168
1169acquired:
1170 return;
1171}
1172
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001173/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001174 * qla24xx_reset_chip() - Reset ISP24xx chip.
1175 * @ha: HA context
1176 *
1177 * Returns 0 on success.
1178 */
1179void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001180qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001181{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001182 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001183
1184 if (pci_channel_offline(ha->pdev) &&
1185 ha->flags.pci_channel_io_perm_failure) {
1186 return;
1187 }
1188
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001189 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001190
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001191 qla25xx_manipulate_risc_semaphore(vha);
1192
Andrew Vasquez88c26662005-07-08 17:59:26 -07001193 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001194 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001195}
1196
1197/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 * qla2x00_chip_diag() - Test chip for proper operation.
1199 * @ha: HA context
1200 *
1201 * Returns 0 on success.
1202 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001203int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001204qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205{
1206 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001207 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001208 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 unsigned long flags = 0;
1210 uint16_t data;
1211 uint32_t cnt;
1212 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001213 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
1215 /* Assume a failed state */
1216 rval = QLA_FUNCTION_FAILED;
1217
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001218 ql_dbg(ql_dbg_init, vha, 0x007b,
1219 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
1221 spin_lock_irqsave(&ha->hardware_lock, flags);
1222
1223 /* Reset ISP chip. */
1224 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1225
1226 /*
1227 * We need to have a delay here since the card will not respond while
1228 * in reset causing an MCA on some architectures.
1229 */
1230 udelay(20);
1231 data = qla2x00_debounce_register(&reg->ctrl_status);
1232 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1233 udelay(5);
1234 data = RD_REG_WORD(&reg->ctrl_status);
1235 barrier();
1236 }
1237
1238 if (!cnt)
1239 goto chip_diag_failed;
1240
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001241 ql_dbg(ql_dbg_init, vha, 0x007c,
1242 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
1244 /* Reset RISC processor. */
1245 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1246 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1247
1248 /* Workaround for QLA2312 PCI parity error */
1249 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1250 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1251 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1252 udelay(5);
1253 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001254 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 }
1256 } else
1257 udelay(10);
1258
1259 if (!cnt)
1260 goto chip_diag_failed;
1261
1262 /* Check product ID of chip */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001263 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
1265 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1266 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1267 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1268 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1269 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1270 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001271 ql_log(ql_log_warn, vha, 0x0062,
1272 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1273 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
1275 goto chip_diag_failed;
1276 }
1277 ha->product_id[0] = mb[1];
1278 ha->product_id[1] = mb[2];
1279 ha->product_id[2] = mb[3];
1280 ha->product_id[3] = mb[4];
1281
1282 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001283 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1285 else
1286 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001287 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
1289 if (IS_QLA2200(ha) &&
1290 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1291 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001292 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001294 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 ha->fw_transfer_size = 128;
1296 }
1297
1298 /* Wrap Incoming Mailboxes Test. */
1299 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1300
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001301 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001302 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001303 if (rval)
1304 ql_log(ql_log_warn, vha, 0x0080,
1305 "Failed mailbox send register test.\n");
1306 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 /* Flag a successful rval */
1308 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 spin_lock_irqsave(&ha->hardware_lock, flags);
1310
1311chip_diag_failed:
1312 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001313 ql_log(ql_log_info, vha, 0x0081,
1314 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
1316 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1317
1318 return (rval);
1319}
1320
1321/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001322 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1323 * @ha: HA context
1324 *
1325 * Returns 0 on success.
1326 */
1327int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001328qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001329{
1330 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001331 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001332 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001333
Giridhar Malavalia9083012010-04-12 17:59:55 -07001334 if (IS_QLA82XX(ha))
1335 return QLA_SUCCESS;
1336
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001337 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001338
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001339 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001340 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001341 ql_log(ql_log_warn, vha, 0x0082,
1342 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001343 } else {
1344 /* Flag a successful rval */
1345 rval = QLA_SUCCESS;
1346 }
1347
1348 return rval;
1349}
1350
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001351void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001352qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001353{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001354 int rval;
1355 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001356 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001357 dma_addr_t tc_dma;
1358 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001359 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001360 struct req_que *req = ha->req_q_map[0];
1361 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001362
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001363 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001364 ql_dbg(ql_dbg_init, vha, 0x00bd,
1365 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001366 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001367 }
1368
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001369 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001370 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001371 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1372 fixed_size = sizeof(struct qla2100_fw_dump);
1373 } else if (IS_QLA23XX(ha)) {
1374 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1375 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1376 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001377 } else if (IS_FWI2_CAPABLE(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001378 if (IS_QLA83XX(ha))
1379 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
1380 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001381 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1382 else if (IS_QLA25XX(ha))
1383 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1384 else
1385 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001386 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1387 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001388 if (ha->mqenable) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001389 if (!IS_QLA83XX(ha))
1390 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001391 /*
1392 * Allocate maximum buffer size for all queues.
1393 * Resizing must be done at end-of-dump processing.
1394 */
1395 mq_size += ha->max_req_queues *
1396 (req->length * sizeof(request_t));
1397 mq_size += ha->max_rsp_queues *
1398 (rsp->length * sizeof(response_t));
1399 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001400 if (ha->tgt.atio_q_length)
1401 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001402 /* Allocate memory for Fibre Channel Event Buffer. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001403 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001404 goto try_eft;
1405
1406 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1407 GFP_KERNEL);
1408 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001409 ql_log(ql_log_warn, vha, 0x00be,
1410 "Unable to allocate (%d KB) for FCE.\n",
1411 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001412 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001413 }
1414
1415 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001416 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001417 ha->fce_mb, &ha->fce_bufs);
1418 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001419 ql_log(ql_log_warn, vha, 0x00bf,
1420 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001421 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1422 tc_dma);
1423 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001424 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001425 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001426 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001427 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001428
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001429 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001430 ha->flags.fce_enabled = 1;
1431 ha->fce_dma = tc_dma;
1432 ha->fce = tc;
1433try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001434 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001435 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001436 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001437 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001438 ql_log(ql_log_warn, vha, 0x00c1,
1439 "Unable to allocate (%d KB) for EFT.\n",
1440 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001441 goto cont_alloc;
1442 }
1443
Andrew Vasquezfc447652008-01-17 09:02:18 -08001444 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001445 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001446 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001447 ql_log(ql_log_warn, vha, 0x00c2,
1448 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001449 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1450 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001451 goto cont_alloc;
1452 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001453 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001454 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001455
1456 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001457 ha->eft_dma = tc_dma;
1458 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001459 }
1460cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001461 req_q_size = req->length * sizeof(request_t);
1462 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001463
1464 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001465 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001466 ha->chain_offset = dump_size;
1467 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001468
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001469 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001470 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001471 ql_log(ql_log_warn, vha, 0x00c4,
1472 "Unable to allocate (%d KB) for firmware dump.\n",
1473 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001474
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001475 if (ha->fce) {
1476 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1477 ha->fce_dma);
1478 ha->fce = NULL;
1479 ha->fce_dma = 0;
1480 }
1481
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001482 if (ha->eft) {
1483 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1484 ha->eft_dma);
1485 ha->eft = NULL;
1486 ha->eft_dma = 0;
1487 }
1488 return;
1489 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001490 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001491 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001492
1493 ha->fw_dump_len = dump_size;
1494 ha->fw_dump->signature[0] = 'Q';
1495 ha->fw_dump->signature[1] = 'L';
1496 ha->fw_dump->signature[2] = 'G';
1497 ha->fw_dump->signature[3] = 'C';
1498 ha->fw_dump->version = __constant_htonl(1);
1499
1500 ha->fw_dump->fixed_size = htonl(fixed_size);
1501 ha->fw_dump->mem_size = htonl(mem_size);
1502 ha->fw_dump->req_q_size = htonl(req_q_size);
1503 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1504
1505 ha->fw_dump->eft_size = htonl(eft_size);
1506 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1507 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1508
1509 ha->fw_dump->header_size =
1510 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001511}
1512
Andrew Vasquez18e75552009-06-03 09:55:30 -07001513static int
1514qla81xx_mpi_sync(scsi_qla_host_t *vha)
1515{
1516#define MPS_MASK 0xe0
1517 int rval;
1518 uint16_t dc;
1519 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07001520
1521 if (!IS_QLA81XX(vha->hw))
1522 return QLA_SUCCESS;
1523
1524 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1525 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001526 ql_log(ql_log_warn, vha, 0x0105,
1527 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001528 goto done;
1529 }
1530
1531 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1532 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1533 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001534 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001535 goto done_release;
1536 }
1537
1538 dc &= MPS_MASK;
1539 if (dc == (dw & MPS_MASK))
1540 goto done_release;
1541
1542 dw &= ~MPS_MASK;
1543 dw |= dc;
1544 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1545 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001546 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001547 }
1548
1549done_release:
1550 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1551 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001552 ql_log(ql_log_warn, vha, 0x006d,
1553 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001554 }
1555
1556done:
1557 return rval;
1558}
1559
Chad Dupuis8d93f552013-01-30 03:34:37 -05001560int
1561qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
1562{
1563 /* Don't try to reallocate the array */
1564 if (req->outstanding_cmds)
1565 return QLA_SUCCESS;
1566
1567 if (!IS_FWI2_CAPABLE(ha) || (ha->mqiobase &&
1568 (ql2xmultique_tag || ql2xmaxqueues > 1)))
1569 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
1570 else {
1571 if (ha->fw_xcb_count <= ha->fw_iocb_count)
1572 req->num_outstanding_cmds = ha->fw_xcb_count;
1573 else
1574 req->num_outstanding_cmds = ha->fw_iocb_count;
1575 }
1576
1577 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1578 req->num_outstanding_cmds, GFP_KERNEL);
1579
1580 if (!req->outstanding_cmds) {
1581 /*
1582 * Try to allocate a minimal size just so we can get through
1583 * initialization.
1584 */
1585 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
1586 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1587 req->num_outstanding_cmds, GFP_KERNEL);
1588
1589 if (!req->outstanding_cmds) {
1590 ql_log(ql_log_fatal, NULL, 0x0126,
1591 "Failed to allocate memory for "
1592 "outstanding_cmds for req_que %p.\n", req);
1593 req->num_outstanding_cmds = 0;
1594 return QLA_FUNCTION_FAILED;
1595 }
1596 }
1597
1598 return QLA_SUCCESS;
1599}
1600
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001601/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 * qla2x00_setup_chip() - Load and start RISC firmware.
1603 * @ha: HA context
1604 *
1605 * Returns 0 on success.
1606 */
1607static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001608qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001610 int rval;
1611 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001612 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001613 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1614 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001615 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001616
Giridhar Malavalia9083012010-04-12 17:59:55 -07001617 if (IS_QLA82XX(ha)) {
1618 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001619 if (rval == QLA_SUCCESS) {
1620 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001621 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001622 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001623 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001624 }
1625
Andrew Vasquez3db06522008-01-31 12:33:49 -08001626 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1627 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1628 spin_lock_irqsave(&ha->hardware_lock, flags);
1629 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1630 RD_REG_WORD(&reg->hccr);
1631 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1632 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633
Andrew Vasquez18e75552009-06-03 09:55:30 -07001634 qla81xx_mpi_sync(vha);
1635
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001637 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001638 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001639 ql_dbg(ql_dbg_init, vha, 0x00c9,
1640 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001642 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 if (rval == QLA_SUCCESS) {
1644 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001645 ql_dbg(ql_dbg_init, vha, 0x00ca,
1646 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001648 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001650 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001651enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001652 fw_major_version = ha->fw_major_version;
Giridhar Malavali31731672011-08-16 11:31:54 -07001653 if (IS_QLA82XX(ha))
1654 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001655 else
1656 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001657 if (rval != QLA_SUCCESS)
1658 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001659 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001660 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001661 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001662 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001663 if ((!ha->max_npiv_vports) ||
1664 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001665 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001666 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001667 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001668 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001669 qla2x00_get_resource_cnts(vha, NULL,
Chad Dupuis8d93f552013-01-30 03:34:37 -05001670 &ha->fw_xcb_count, NULL, &ha->fw_iocb_count,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001671 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001672
Chad Dupuis8d93f552013-01-30 03:34:37 -05001673 /*
1674 * Allocate the array of outstanding commands
1675 * now that we know the firmware resources.
1676 */
1677 rval = qla2x00_alloc_outstanding_cmds(ha,
1678 vha->req);
1679 if (rval != QLA_SUCCESS)
1680 goto failed;
1681
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08001682 if (!fw_major_version && ql2xallocfwdump
1683 && !IS_QLA82XX(ha))
Giridhar Malavali08de2842011-08-16 11:31:44 -07001684 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 }
1686 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001687 ql_log(ql_log_fatal, vha, 0x00cd,
1688 "ISP Firmware failed checksum.\n");
1689 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04001691 } else
1692 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
Andrew Vasquez3db06522008-01-31 12:33:49 -08001694 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1695 /* Enable proper parity. */
1696 spin_lock_irqsave(&ha->hardware_lock, flags);
1697 if (IS_QLA2300(ha))
1698 /* SRAM parity */
1699 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1700 else
1701 /* SRAM, Instruction RAM and GP RAM parity */
1702 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1703 RD_REG_WORD(&reg->hccr);
1704 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1705 }
1706
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001707 if (IS_QLA83XX(ha))
1708 goto skip_fac_check;
1709
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001710 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1711 uint32_t size;
1712
1713 rval = qla81xx_fac_get_sector_size(vha, &size);
1714 if (rval == QLA_SUCCESS) {
1715 ha->flags.fac_supported = 1;
1716 ha->fdt_block_size = size << 2;
1717 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001718 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001719 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1720 ha->fw_major_version, ha->fw_minor_version,
1721 ha->fw_subminor_version);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001722skip_fac_check:
1723 if (IS_QLA83XX(ha)) {
1724 ha->flags.fac_supported = 0;
1725 rval = QLA_SUCCESS;
1726 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001727 }
1728 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001729failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001731 ql_log(ql_log_fatal, vha, 0x00cf,
1732 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 }
1734
1735 return (rval);
1736}
1737
1738/**
1739 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1740 * @ha: HA context
1741 *
1742 * Beginning of request ring has initialization control block already built
1743 * by nvram config routine.
1744 *
1745 * Returns 0 on success.
1746 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001747void
1748qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749{
1750 uint16_t cnt;
1751 response_t *pkt;
1752
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001753 rsp->ring_ptr = rsp->ring;
1754 rsp->ring_index = 0;
1755 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001756 pkt = rsp->ring_ptr;
1757 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 pkt->signature = RESPONSE_PROCESSED;
1759 pkt++;
1760 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761}
1762
1763/**
1764 * qla2x00_update_fw_options() - Read and process firmware options.
1765 * @ha: HA context
1766 *
1767 * Returns 0 on success.
1768 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001769void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001770qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771{
1772 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001773 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
1775 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001776 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
1778 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1779 return;
1780
1781 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001782 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1783 "Serial link options.\n");
1784 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1785 (uint8_t *)&ha->fw_seriallink_options,
1786 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
1788 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1789 if (ha->fw_seriallink_options[3] & BIT_2) {
1790 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1791
1792 /* 1G settings */
1793 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1794 emphasis = (ha->fw_seriallink_options[2] &
1795 (BIT_4 | BIT_3)) >> 3;
1796 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001797 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 rx_sens = (ha->fw_seriallink_options[0] &
1799 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1800 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1801 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1802 if (rx_sens == 0x0)
1803 rx_sens = 0x3;
1804 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1805 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1806 ha->fw_options[10] |= BIT_5 |
1807 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1808 (tx_sens & (BIT_1 | BIT_0));
1809
1810 /* 2G settings */
1811 swing = (ha->fw_seriallink_options[2] &
1812 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1813 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1814 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001815 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 rx_sens = (ha->fw_seriallink_options[1] &
1817 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1818 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1819 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1820 if (rx_sens == 0x0)
1821 rx_sens = 0x3;
1822 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1823 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1824 ha->fw_options[11] |= BIT_5 |
1825 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1826 (tx_sens & (BIT_1 | BIT_0));
1827 }
1828
1829 /* FCP2 options. */
1830 /* Return command IOCBs without waiting for an ABTS to complete. */
1831 ha->fw_options[3] |= BIT_13;
1832
1833 /* LED scheme. */
1834 if (ha->flags.enable_led_scheme)
1835 ha->fw_options[2] |= BIT_12;
1836
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001837 /* Detect ISP6312. */
1838 if (IS_QLA6312(ha))
1839 ha->fw_options[2] |= BIT_13;
1840
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001842 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843}
1844
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001845void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001846qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001847{
1848 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001849 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001850
Giridhar Malavalia9083012010-04-12 17:59:55 -07001851 if (IS_QLA82XX(ha))
1852 return;
1853
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001854 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001855 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001856 return;
1857
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001858 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001859 le16_to_cpu(ha->fw_seriallink_options24[1]),
1860 le16_to_cpu(ha->fw_seriallink_options24[2]),
1861 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001862 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001863 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001864 "Unable to update Serial Link options (%x).\n", rval);
1865 }
1866}
1867
1868void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001869qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001870{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001871 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001872 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001873 struct req_que *req = ha->req_q_map[0];
1874 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001875
1876 /* Setup ring parameters in initialization control block. */
1877 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1878 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001879 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1880 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1881 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1882 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1883 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1884 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001885
1886 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1887 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1888 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1889 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1890 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1891}
1892
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001893void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001894qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001895{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001896 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001897 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1898 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1899 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001900 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001901 uint16_t rid = 0;
1902 struct req_que *req = ha->req_q_map[0];
1903 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001904
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001905 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001906 icb = (struct init_cb_24xx *)ha->init_cb;
1907 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1908 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001909 icb->request_q_length = cpu_to_le16(req->length);
1910 icb->response_q_length = cpu_to_le16(rsp->length);
1911 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1912 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1913 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1914 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001915
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001916 /* Setup ATIO queue dma pointers for target mode */
1917 icb->atio_q_inpointer = __constant_cpu_to_le16(0);
1918 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
1919 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
1920 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
1921
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001922 if (ha->mqenable || IS_QLA83XX(ha)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001923 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1924 icb->rid = __constant_cpu_to_le16(rid);
1925 if (ha->flags.msix_enabled) {
1926 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001927 ql_dbg(ql_dbg_init, vha, 0x00fd,
1928 "Registering vector 0x%x for base que.\n",
1929 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001930 icb->msix = cpu_to_le16(msix->entry);
1931 }
1932 /* Use alternate PCI bus number */
1933 if (MSB(rid))
1934 icb->firmware_options_2 |=
1935 __constant_cpu_to_le32(BIT_19);
1936 /* Use alternate PCI devfn */
1937 if (LSB(rid))
1938 icb->firmware_options_2 |=
1939 __constant_cpu_to_le32(BIT_18);
1940
Anirban Chakraborty31557542009-12-02 10:36:55 -08001941 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001942 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
1943 (ha->flags.msix_enabled)) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08001944 icb->firmware_options_2 &=
1945 __constant_cpu_to_le32(~BIT_22);
1946 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001947 ql_dbg(ql_dbg_init, vha, 0x00fe,
1948 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08001949 } else {
1950 icb->firmware_options_2 |=
1951 __constant_cpu_to_le32(BIT_22);
1952 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001953 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001954
1955 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1956 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1957 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1958 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1959 } else {
1960 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1961 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1962 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1963 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1964 }
Arun Easiaa230bc2013-01-30 03:34:39 -05001965 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001966
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001967 /* PCI posting */
1968 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001969}
1970
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971/**
1972 * qla2x00_init_rings() - Initializes firmware.
1973 * @ha: HA context
1974 *
1975 * Beginning of request ring has initialization control block already built
1976 * by nvram config routine.
1977 *
1978 * Returns 0 on success.
1979 */
1980static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001981qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982{
1983 int rval;
1984 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001985 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001986 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001987 struct req_que *req;
1988 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001989 struct mid_init_cb_24xx *mid_init_cb =
1990 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991
1992 spin_lock_irqsave(&ha->hardware_lock, flags);
1993
1994 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001995 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001996 req = ha->req_q_map[que];
1997 if (!req)
1998 continue;
Chad Dupuis8d93f552013-01-30 03:34:37 -05001999 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002000 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002002 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002003
2004 /* Initialize firmware. */
2005 req->ring_ptr = req->ring;
2006 req->ring_index = 0;
2007 req->cnt = req->length;
2008 }
2009
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002010 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002011 rsp = ha->rsp_q_map[que];
2012 if (!rsp)
2013 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002014 /* Initialize response queue entries */
2015 qla2x00_init_response_q_entries(rsp);
2016 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002018 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
2019 ha->tgt.atio_ring_index = 0;
2020 /* Initialize ATIO queue entries */
2021 qlt_init_atio_q_entries(vha);
2022
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002023 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024
2025 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2026
2027 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002028 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002030 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002031
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002032 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04002033 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002034 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08002035 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002036 }
2037
Andrew Vasquez24a08132009-03-24 09:08:16 -07002038 if (IS_FWI2_CAPABLE(ha)) {
2039 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
2040 mid_init_cb->init_cb.execution_throttle =
2041 cpu_to_le16(ha->fw_xcb_count);
2042 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002043
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002044 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002046 ql_log(ql_log_fatal, vha, 0x00d2,
2047 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002049 ql_dbg(ql_dbg_init, vha, 0x00d3,
2050 "Init Firmware -- success.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 }
2052
2053 return (rval);
2054}
2055
2056/**
2057 * qla2x00_fw_ready() - Waits for firmware ready.
2058 * @ha: HA context
2059 *
2060 * Returns 0 on success.
2061 */
2062static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002063qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064{
2065 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002066 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 uint16_t min_wait; /* Minimum wait time if loop is down */
2068 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07002069 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002070 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
2072 rval = QLA_SUCCESS;
2073
2074 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002075 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076
2077 /*
2078 * Firmware should take at most one RATOV to login, plus 5 seconds for
2079 * our own processing.
2080 */
2081 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
2082 wait_time = min_wait;
2083 }
2084
2085 /* Min wait time if loop down */
2086 mtime = jiffies + (min_wait * HZ);
2087
2088 /* wait time before firmware ready */
2089 wtime = jiffies + (wait_time * HZ);
2090
2091 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002092 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002093 ql_log(ql_log_info, vha, 0x801e,
2094 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095
2096 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05002097 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002098 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002100 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002101 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002103 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002104 ql_dbg(ql_dbg_taskm, vha, 0x801f,
2105 "fw_state=%x 84xx=%x.\n", state[0],
2106 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002107 if ((state[2] & FSTATE_LOGGED_IN) &&
2108 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002109 ql_dbg(ql_dbg_taskm, vha, 0x8028,
2110 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002111
2112 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002113 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002114 if (rval != QLA_SUCCESS) {
2115 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002116 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002117 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002118 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002119 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002120
2121 /* Add time taken to initialize. */
2122 cs84xx_time = jiffies - cs84xx_time;
2123 wtime += cs84xx_time;
2124 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002125 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002126 "Increasing wait time by %ld. "
2127 "New time %ld.\n", cs84xx_time,
2128 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002129 }
2130 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002131 ql_dbg(ql_dbg_taskm, vha, 0x8037,
2132 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002134 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 &ha->login_timeout, &ha->r_a_tov);
2136
2137 rval = QLA_SUCCESS;
2138 break;
2139 }
2140
2141 rval = QLA_FUNCTION_FAILED;
2142
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002143 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002144 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002146 * other than Wait for Login.
2147 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002149 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 "Cable is unplugged...\n");
2151
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002152 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 break;
2154 }
2155 }
2156 } else {
2157 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07002158 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08002159 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 break;
2161 }
2162
2163 if (time_after_eq(jiffies, wtime))
2164 break;
2165
2166 /* Delay for a while */
2167 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 } while (1);
2169
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002170 ql_dbg(ql_dbg_taskm, vha, 0x803a,
2171 "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0],
2172 state[1], state[2], state[3], state[4], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173
Chad Dupuiscfb09192011-11-18 09:03:07 -08002174 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002175 ql_log(ql_log_warn, vha, 0x803b,
2176 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 }
2178
2179 return (rval);
2180}
2181
2182/*
2183* qla2x00_configure_hba
2184* Setup adapter context.
2185*
2186* Input:
2187* ha = adapter state pointer.
2188*
2189* Returns:
2190* 0 = success
2191*
2192* Context:
2193* Kernel context.
2194*/
2195static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002196qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197{
2198 int rval;
2199 uint16_t loop_id;
2200 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002201 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 uint8_t al_pa;
2203 uint8_t area;
2204 uint8_t domain;
2205 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002206 struct qla_hw_data *ha = vha->hw;
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002207 unsigned long flags;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002208 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
2210 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002211 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002212 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002214 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002215 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002216 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002217 ql_dbg(ql_dbg_disc, vha, 0x2008,
2218 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08002219 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002220 ql_log(ql_log_warn, vha, 0x2009,
2221 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002222 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
2223 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
2224 ql_log(ql_log_warn, vha, 0x1151,
2225 "Doing link init.\n");
2226 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
2227 return rval;
2228 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002229 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 return (rval);
2232 }
2233
2234 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002235 ql_log(ql_log_info, vha, 0x200a,
2236 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 return (QLA_FUNCTION_FAILED);
2238 }
2239
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002240 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
2242 /* initialize */
2243 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2244 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002245 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246
2247 switch (topo) {
2248 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002249 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 ha->current_topology = ISP_CFG_NL;
2251 strcpy(connect_type, "(Loop)");
2252 break;
2253
2254 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002255 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002256 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 ha->current_topology = ISP_CFG_FL;
2258 strcpy(connect_type, "(FL_Port)");
2259 break;
2260
2261 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002262 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 ha->operating_mode = P2P;
2264 ha->current_topology = ISP_CFG_N;
2265 strcpy(connect_type, "(N_Port-to-N_Port)");
2266 break;
2267
2268 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002269 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002270 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 ha->operating_mode = P2P;
2272 ha->current_topology = ISP_CFG_F;
2273 strcpy(connect_type, "(F_Port)");
2274 break;
2275
2276 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002277 ql_dbg(ql_dbg_disc, vha, 0x200f,
2278 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 ha->current_topology = ISP_CFG_NL;
2280 strcpy(connect_type, "(Loop)");
2281 break;
2282 }
2283
2284 /* Save Host port and loop ID. */
2285 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002286 vha->d_id.b.domain = domain;
2287 vha->d_id.b.area = area;
2288 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002290 spin_lock_irqsave(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002291 qlt_update_vp_map(vha, SET_AL_PA);
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002292 spin_unlock_irqrestore(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002293
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002294 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002295 ql_log(ql_log_info, vha, 0x2010,
2296 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002297 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
2299 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002300 ql_log(ql_log_warn, vha, 0x2011,
2301 "%s FAILED\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002303 ql_dbg(ql_dbg_disc, vha, 0x2012,
2304 "%s success\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 }
2306
2307 return(rval);
2308}
2309
Giridhar Malavalia9083012010-04-12 17:59:55 -07002310inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002311qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2312 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002313{
2314 char *st, *en;
2315 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002316 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002317 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002318 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002319
2320 if (memcmp(model, BINZERO, len) != 0) {
2321 strncpy(ha->model_number, model, len);
2322 st = en = ha->model_number;
2323 en += len - 1;
2324 while (en > st) {
2325 if (*en != 0x20 && *en != 0x00)
2326 break;
2327 *en-- = '\0';
2328 }
2329
2330 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002331 if (use_tbl &&
2332 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002333 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002334 strncpy(ha->model_desc,
2335 qla2x00_model_name[index * 2 + 1],
2336 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002337 } else {
2338 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002339 if (use_tbl &&
2340 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002341 index < QLA_MODEL_NAMES) {
2342 strcpy(ha->model_number,
2343 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002344 strncpy(ha->model_desc,
2345 qla2x00_model_name[index * 2 + 1],
2346 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002347 } else {
2348 strcpy(ha->model_number, def);
2349 }
2350 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002351 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002352 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002353 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002354}
2355
David Miller4e08df32007-04-16 12:37:43 -07002356/* On sparc systems, obtain port and node WWN from firmware
2357 * properties.
2358 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002359static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002360{
2361#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002362 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002363 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002364 struct device_node *dp = pci_device_to_OF_node(pdev);
2365 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002366 int len;
2367
2368 val = of_get_property(dp, "port-wwn", &len);
2369 if (val && len >= WWN_SIZE)
2370 memcpy(nv->port_name, val, WWN_SIZE);
2371
2372 val = of_get_property(dp, "node-wwn", &len);
2373 if (val && len >= WWN_SIZE)
2374 memcpy(nv->node_name, val, WWN_SIZE);
2375#endif
2376}
2377
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378/*
2379* NVRAM configuration for ISP 2xxx
2380*
2381* Input:
2382* ha = adapter block pointer.
2383*
2384* Output:
2385* initialization control block in response_ring
2386* host adapters parameters in host adapter block
2387*
2388* Returns:
2389* 0 = success.
2390*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002391int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002392qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393{
David Miller4e08df32007-04-16 12:37:43 -07002394 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002395 uint8_t chksum = 0;
2396 uint16_t cnt;
2397 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002398 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002399 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002400 nvram_t *nv = ha->nvram;
2401 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002402 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403
David Miller4e08df32007-04-16 12:37:43 -07002404 rval = QLA_SUCCESS;
2405
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002407 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 ha->nvram_base = 0;
2409 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2410 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2411 ha->nvram_base = 0x80;
2412
2413 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002414 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002415 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2416 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002418 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2419 "Contents of NVRAM.\n");
2420 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2421 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422
2423 /* Bad NVRAM data, set defaults parameters. */
2424 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2425 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2426 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002427 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04002428 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002429 "detected: checksum=0x%x id=%c version=0x%x.\n",
2430 chksum, nv->id[0], nv->nvram_version);
2431 ql_log(ql_log_warn, vha, 0x0065,
2432 "Falling back to "
2433 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07002434
2435 /*
2436 * Set default initialization control block.
2437 */
2438 memset(nv, 0, ha->nvram_size);
2439 nv->parameter_block_version = ICB_VERSION;
2440
2441 if (IS_QLA23XX(ha)) {
2442 nv->firmware_options[0] = BIT_2 | BIT_1;
2443 nv->firmware_options[1] = BIT_7 | BIT_5;
2444 nv->add_firmware_options[0] = BIT_5;
2445 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2446 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2447 nv->special_options[1] = BIT_7;
2448 } else if (IS_QLA2200(ha)) {
2449 nv->firmware_options[0] = BIT_2 | BIT_1;
2450 nv->firmware_options[1] = BIT_7 | BIT_5;
2451 nv->add_firmware_options[0] = BIT_5;
2452 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2453 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2454 } else if (IS_QLA2100(ha)) {
2455 nv->firmware_options[0] = BIT_3 | BIT_1;
2456 nv->firmware_options[1] = BIT_5;
2457 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2458 }
2459
2460 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2461 nv->execution_throttle = __constant_cpu_to_le16(16);
2462 nv->retry_count = 8;
2463 nv->retry_delay = 1;
2464
2465 nv->port_name[0] = 33;
2466 nv->port_name[3] = 224;
2467 nv->port_name[4] = 139;
2468
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002469 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002470
2471 nv->login_timeout = 4;
2472
2473 /*
2474 * Set default host adapter parameters
2475 */
2476 nv->host_p[1] = BIT_2;
2477 nv->reset_delay = 5;
2478 nv->port_down_retry_count = 8;
2479 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2480 nv->link_down_timeout = 60;
2481
2482 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 }
2484
2485#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2486 /*
2487 * The SN2 does not provide BIOS emulation which means you can't change
2488 * potentially bogus BIOS settings. Force the use of default settings
2489 * for link rate and frame size. Hope that the rest of the settings
2490 * are valid.
2491 */
2492 if (ia64_platform_is("sn2")) {
2493 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2494 if (IS_QLA23XX(ha))
2495 nv->special_options[1] = BIT_7;
2496 }
2497#endif
2498
2499 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002500 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501
2502 /*
2503 * Setup driver NVRAM options.
2504 */
2505 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2506 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2507 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2508 nv->firmware_options[1] &= ~BIT_4;
2509
2510 if (IS_QLA23XX(ha)) {
2511 nv->firmware_options[0] |= BIT_2;
2512 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002513 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002514 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515
2516 if (IS_QLA2300(ha)) {
2517 if (ha->fb_rev == FPM_2310) {
2518 strcpy(ha->model_number, "QLA2310");
2519 } else {
2520 strcpy(ha->model_number, "QLA2300");
2521 }
2522 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002523 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002524 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 }
2526 } else if (IS_QLA2200(ha)) {
2527 nv->firmware_options[0] |= BIT_2;
2528 /*
2529 * 'Point-to-point preferred, else loop' is not a safe
2530 * connection mode setting.
2531 */
2532 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2533 (BIT_5 | BIT_4)) {
2534 /* Force 'loop preferred, else point-to-point'. */
2535 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2536 nv->add_firmware_options[0] |= BIT_5;
2537 }
2538 strcpy(ha->model_number, "QLA22xx");
2539 } else /*if (IS_QLA2100(ha))*/ {
2540 strcpy(ha->model_number, "QLA2100");
2541 }
2542
2543 /*
2544 * Copy over NVRAM RISC parameter block to initialization control block.
2545 */
2546 dptr1 = (uint8_t *)icb;
2547 dptr2 = (uint8_t *)&nv->parameter_block_version;
2548 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2549 while (cnt--)
2550 *dptr1++ = *dptr2++;
2551
2552 /* Copy 2nd half. */
2553 dptr1 = (uint8_t *)icb->add_firmware_options;
2554 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2555 while (cnt--)
2556 *dptr1++ = *dptr2++;
2557
Andrew Vasquez5341e862006-05-17 15:09:16 -07002558 /* Use alternate WWN? */
2559 if (nv->host_p[1] & BIT_7) {
2560 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2561 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2562 }
2563
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 /* Prepare nodename */
2565 if ((icb->firmware_options[1] & BIT_6) == 0) {
2566 /*
2567 * Firmware will apply the following mask if the nodename was
2568 * not provided.
2569 */
2570 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2571 icb->node_name[0] &= 0xF0;
2572 }
2573
2574 /*
2575 * Set host adapter parameters.
2576 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002577
2578 /*
2579 * BIT_7 in the host-parameters section allows for modification to
2580 * internal driver logging.
2581 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002582 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08002583 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2585 /* Always load RISC code on non ISP2[12]00 chips. */
2586 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2587 ha->flags.disable_risc_code_load = 0;
2588 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2589 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2590 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002591 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002592 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593
2594 ha->operating_mode =
2595 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2596
2597 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2598 sizeof(ha->fw_seriallink_options));
2599
2600 /* save HBA serial number */
2601 ha->serial0 = icb->port_name[5];
2602 ha->serial1 = icb->port_name[6];
2603 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002604 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2605 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606
2607 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2608
2609 ha->retry_count = nv->retry_count;
2610
2611 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002612 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 nv->login_timeout = ql2xlogintimeout;
2614 if (nv->login_timeout < 4)
2615 nv->login_timeout = 4;
2616 ha->login_timeout = nv->login_timeout;
2617 icb->login_timeout = nv->login_timeout;
2618
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002619 /* Set minimum RATOV to 100 tenths of a second. */
2620 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 ha->loop_reset_delay = nv->reset_delay;
2623
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 /* Link Down Timeout = 0:
2625 *
2626 * When Port Down timer expires we will start returning
2627 * I/O's to OS with "DID_NO_CONNECT".
2628 *
2629 * Link Down Timeout != 0:
2630 *
2631 * The driver waits for the link to come up after link down
2632 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002633 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 if (nv->link_down_timeout == 0) {
2635 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002636 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 } else {
2638 ha->link_down_timeout = nv->link_down_timeout;
2639 ha->loop_down_abort_time =
2640 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002641 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 /*
2644 * Need enough time to try and get the port back.
2645 */
2646 ha->port_down_retry_count = nv->port_down_retry_count;
2647 if (qlport_down_retry)
2648 ha->port_down_retry_count = qlport_down_retry;
2649 /* Set login_retry_count */
2650 ha->login_retry_count = nv->retry_count;
2651 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2652 ha->port_down_retry_count > 3)
2653 ha->login_retry_count = ha->port_down_retry_count;
2654 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2655 ha->login_retry_count = ha->port_down_retry_count;
2656 if (ql2xloginretrycount)
2657 ha->login_retry_count = ql2xloginretrycount;
2658
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 icb->lun_enables = __constant_cpu_to_le16(0);
2660 icb->command_resource_count = 0;
2661 icb->immediate_notify_resource_count = 0;
2662 icb->timeout = __constant_cpu_to_le16(0);
2663
2664 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2665 /* Enable RIO */
2666 icb->firmware_options[0] &= ~BIT_3;
2667 icb->add_firmware_options[0] &=
2668 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2669 icb->add_firmware_options[0] |= BIT_2;
2670 icb->response_accumulation_timer = 3;
2671 icb->interrupt_delay_timer = 5;
2672
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002673 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002675 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002676 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002677 ha->zio_mode = icb->add_firmware_options[0] &
2678 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2679 ha->zio_timer = icb->interrupt_delay_timer ?
2680 icb->interrupt_delay_timer: 2;
2681 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 icb->add_firmware_options[0] &=
2683 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002684 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002685 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002686 ha->zio_mode = QLA_ZIO_MODE_6;
2687
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002688 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002689 "ZIO mode %d enabled; timer delay (%d us).\n",
2690 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002692 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2693 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002694 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 }
2696 }
2697
David Miller4e08df32007-04-16 12:37:43 -07002698 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002699 ql_log(ql_log_warn, vha, 0x0069,
2700 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07002701 }
2702 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703}
2704
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002705static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002706qla2x00_rport_del(void *data)
2707{
2708 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002709 struct fc_rport *rport;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002710 scsi_qla_host_t *vha = fcport->vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002711 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002712
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002713 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002714 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002715 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002716 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002717 if (rport) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002718 fc_remote_port_delete(rport);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002719 /*
2720 * Release the target mode FC NEXUS in qla_target.c code
2721 * if target mod is enabled.
2722 */
2723 qlt_fc_port_deleted(vha, fcport);
2724 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002725}
2726
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727/**
2728 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2729 * @ha: HA context
2730 * @flags: allocation flags
2731 *
2732 * Returns a pointer to the allocated fcport, or NULL, if none available.
2733 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002734fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002735qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736{
2737 fc_port_t *fcport;
2738
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002739 fcport = kzalloc(sizeof(fc_port_t), flags);
2740 if (!fcport)
2741 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742
2743 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002744 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 fcport->port_type = FCT_UNKNOWN;
2746 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07002747 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002748 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002750 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751}
2752
2753/*
2754 * qla2x00_configure_loop
2755 * Updates Fibre Channel Device Database with what is actually on loop.
2756 *
2757 * Input:
2758 * ha = adapter block pointer.
2759 *
2760 * Returns:
2761 * 0 = success.
2762 * 1 = error.
2763 * 2 = database was full and device was not configured.
2764 */
2765static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002766qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767{
2768 int rval;
2769 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002770 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 rval = QLA_SUCCESS;
2772
2773 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002774 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2775 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002777 ql_dbg(ql_dbg_disc, vha, 0x2013,
2778 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 return (rval);
2780 }
2781 }
2782
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002783 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002784 ql_dbg(ql_dbg_disc, vha, 0x2014,
2785 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786
2787 /*
2788 * If we have both an RSCN and PORT UPDATE pending then handle them
2789 * both at the same time.
2790 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002791 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2792 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793
Michael Hernandez3064ff32009-12-15 21:29:44 -08002794 qla2x00_get_data_rate(vha);
2795
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 /* Determine what we need to do */
2797 if (ha->current_topology == ISP_CFG_FL &&
2798 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2799
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 set_bit(RSCN_UPDATE, &flags);
2801
2802 } else if (ha->current_topology == ISP_CFG_F &&
2803 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2804
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 set_bit(RSCN_UPDATE, &flags);
2806 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2807
Andrew Vasquez21333b42006-05-17 15:09:56 -07002808 } else if (ha->current_topology == ISP_CFG_N) {
2809 clear_bit(RSCN_UPDATE, &flags);
2810
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002811 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2813
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 set_bit(RSCN_UPDATE, &flags);
2815 set_bit(LOCAL_LOOP_UPDATE, &flags);
2816 }
2817
2818 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002819 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2820 ql_dbg(ql_dbg_disc, vha, 0x2015,
2821 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08002823 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002824 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 }
2826
2827 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002828 if (LOOP_TRANSITION(vha)) {
2829 ql_dbg(ql_dbg_disc, vha, 0x201e,
2830 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002832 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002833 else
2834 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 }
2836
2837 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002838 if (atomic_read(&vha->loop_down_timer) ||
2839 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 rval = QLA_FUNCTION_FAILED;
2841 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002842 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002843 ql_dbg(ql_dbg_disc, vha, 0x2069,
2844 "LOOP READY.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 }
2846 }
2847
2848 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002849 ql_dbg(ql_dbg_disc, vha, 0x206a,
2850 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002852 ql_dbg(ql_dbg_disc, vha, 0x206b,
2853 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 }
2855
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002856 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002857 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002859 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002860 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002861 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 }
2864
2865 return (rval);
2866}
2867
2868
2869
2870/*
2871 * qla2x00_configure_local_loop
2872 * Updates Fibre Channel Device Database with local loop devices.
2873 *
2874 * Input:
2875 * ha = adapter block pointer.
2876 *
2877 * Returns:
2878 * 0 = success.
2879 */
2880static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002881qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882{
2883 int rval, rval2;
2884 int found_devs;
2885 int found;
2886 fc_port_t *fcport, *new_fcport;
2887
2888 uint16_t index;
2889 uint16_t entries;
2890 char *id_iter;
2891 uint16_t loop_id;
2892 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002893 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894
2895 found_devs = 0;
2896 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08002897 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08002900 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002901 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 &entries);
2903 if (rval != QLA_SUCCESS)
2904 goto cleanup_allocation;
2905
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002906 ql_dbg(ql_dbg_disc, vha, 0x2017,
2907 "Entries in ID list (%d).\n", entries);
2908 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
2909 (uint8_t *)ha->gid_list,
2910 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911
2912 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002913 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002915 ql_log(ql_log_warn, vha, 0x2018,
2916 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 rval = QLA_MEMORY_ALLOC_FAILED;
2918 goto cleanup_allocation;
2919 }
2920 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2921
2922 /*
2923 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2924 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002925 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2927 fcport->port_type != FCT_BROADCAST &&
2928 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2929
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002930 ql_dbg(ql_dbg_disc, vha, 0x2019,
2931 "Marking port lost loop_id=0x%04x.\n",
2932 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933
Chad Dupuisec426e12011-03-30 11:46:32 -07002934 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 }
2936 }
2937
2938 /* Add devices to port list. */
2939 id_iter = (char *)ha->gid_list;
2940 for (index = 0; index < entries; index++) {
2941 domain = ((struct gid_list_info *)id_iter)->domain;
2942 area = ((struct gid_list_info *)id_iter)->area;
2943 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002944 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 loop_id = (uint16_t)
2946 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002947 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 loop_id = le16_to_cpu(
2949 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002950 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951
2952 /* Bypass reserved domain fields. */
2953 if ((domain & 0xf0) == 0xf0)
2954 continue;
2955
2956 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002957 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002958 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 continue;
2960
2961 /* Bypass invalid local loop ID. */
2962 if (loop_id > LAST_LOCAL_LOOP_ID)
2963 continue;
2964
Arun Easi370d5502012-08-22 14:21:10 -04002965 memset(new_fcport, 0, sizeof(fc_port_t));
2966
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 /* Fill in member data. */
2968 new_fcport->d_id.b.domain = domain;
2969 new_fcport->d_id.b.area = area;
2970 new_fcport->d_id.b.al_pa = al_pa;
2971 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002972 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002974 ql_dbg(ql_dbg_disc, vha, 0x201a,
2975 "Failed to retrieve fcport information "
2976 "-- get_port_database=%x, loop_id=0x%04x.\n",
2977 rval2, new_fcport->loop_id);
2978 ql_dbg(ql_dbg_disc, vha, 0x201b,
2979 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002980 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 continue;
2982 }
2983
2984 /* Check for matching device in port list. */
2985 found = 0;
2986 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002987 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 if (memcmp(new_fcport->port_name, fcport->port_name,
2989 WWN_SIZE))
2990 continue;
2991
Shyam Sundarddb9b122009-03-24 09:08:10 -07002992 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 fcport->loop_id = new_fcport->loop_id;
2994 fcport->port_type = new_fcport->port_type;
2995 fcport->d_id.b24 = new_fcport->d_id.b24;
2996 memcpy(fcport->node_name, new_fcport->node_name,
2997 WWN_SIZE);
2998
2999 found++;
3000 break;
3001 }
3002
3003 if (!found) {
3004 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003005 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006
3007 /* Allocate a new replacement fcport. */
3008 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003009 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003011 ql_log(ql_log_warn, vha, 0x201c,
3012 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 rval = QLA_MEMORY_ALLOC_FAILED;
3014 goto cleanup_allocation;
3015 }
3016 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3017 }
3018
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003019 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003020 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003021
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003022 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023
3024 found_devs++;
3025 }
3026
3027cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003028 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029
3030 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003031 ql_dbg(ql_dbg_disc, vha, 0x201d,
3032 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 }
3034
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 return (rval);
3036}
3037
3038static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003039qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003040{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003041 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003042 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003043 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003044
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07003045 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003046 return;
3047
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07003048 if (atomic_read(&fcport->state) != FCS_ONLINE)
3049 return;
3050
Andrew Vasquez39bd9622007-09-20 14:07:34 -07003051 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
3052 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003053 return;
3054
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003055 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003056 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003057 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003058 ql_dbg(ql_dbg_disc, vha, 0x2004,
3059 "Unable to adjust iIDMA "
3060 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x "
3061 "%04x.\n", fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003062 fcport->port_name[2], fcport->port_name[3],
3063 fcport->port_name[4], fcport->port_name[5],
3064 fcport->port_name[6], fcport->port_name[7], rval,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003065 fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003066 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003067 ql_dbg(ql_dbg_disc, vha, 0x2005,
3068 "iIDMA adjusted to %s GB/s "
Joe Carnucciod0297c92012-11-21 02:40:40 -05003069 "on %02x%02x%02x%02x%02x%02x%02x%02x.\n",
3070 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003071 fcport->port_name[0], fcport->port_name[1],
3072 fcport->port_name[2], fcport->port_name[3],
3073 fcport->port_name[4], fcport->port_name[5],
3074 fcport->port_name[6], fcport->port_name[7]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003075 }
3076}
3077
Adrian Bunk23be3312006-11-24 02:46:01 +01003078static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003079qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05003080{
3081 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05003082 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003083 unsigned long flags;
8482e1182005-04-17 15:04:54 -05003084
Andrew Vasquezac280b62009-08-20 11:06:05 -07003085 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05003086
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07003087 rport_ids.node_name = wwn_to_u64(fcport->node_name);
3088 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05003089 rport_ids.port_id = fcport->d_id.b.domain << 16 |
3090 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
3091 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003092 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07003093 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003094 ql_log(ql_log_warn, vha, 0x2006,
3095 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07003096 return;
3097 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003098 /*
3099 * Create target mode FC NEXUS in qla_target.c if target mode is
3100 * enabled..
3101 */
3102 qlt_fc_port_added(vha, fcport);
3103
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003104 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003105 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003106 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003107
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003108 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003109
3110 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05003111 if (fcport->port_type == FCT_INITIATOR)
3112 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3113 if (fcport->port_type == FCT_TARGET)
3114 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003115 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05003116}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117
3118/*
Adrian Bunk23be3312006-11-24 02:46:01 +01003119 * qla2x00_update_fcport
3120 * Updates device on list.
3121 *
3122 * Input:
3123 * ha = adapter block pointer.
3124 * fcport = port structure pointer.
3125 *
3126 * Return:
3127 * 0 - Success
3128 * BIT_0 - error
3129 *
3130 * Context:
3131 * Kernel context.
3132 */
3133void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003134qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01003135{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003136 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01003137 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003138 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01003139
Joe Carnuccio1f93da52012-11-21 02:40:38 -05003140 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003141 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08003142 qla24xx_update_fcport_fcp_prio(vha, fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003143 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01003144}
3145
3146/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 * qla2x00_configure_fabric
3148 * Setup SNS devices with loop ID's.
3149 *
3150 * Input:
3151 * ha = adapter block pointer.
3152 *
3153 * Returns:
3154 * 0 = success.
3155 * BIT_0 = error
3156 */
3157static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003158qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159{
Arun Easib3b02e62012-02-09 11:15:39 -08003160 int rval;
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003161 fc_port_t *fcport, *fcptemp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 uint16_t next_loopid;
3163 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003164 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003166 struct qla_hw_data *ha = vha->hw;
3167 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168
3169 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003170 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003171 loop_id = NPH_F_PORT;
3172 else
3173 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003174 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003176 ql_dbg(ql_dbg_disc, vha, 0x201f,
3177 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003179 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 return (QLA_SUCCESS);
3181 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003182 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07003185 /* FDMI support. */
3186 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003187 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
3188 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07003189
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003191 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003192 loop_id = NPH_SNS;
3193 else
3194 loop_id = SIMPLE_NAME_SERVER;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003195 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
3196 0xfc, mb, BIT_1|BIT_0);
3197 if (rval != QLA_SUCCESS) {
3198 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003199 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003200 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003202 ql_dbg(ql_dbg_disc, vha, 0x2042,
3203 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3204 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
3205 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 return (QLA_SUCCESS);
3207 }
3208
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003209 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3210 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003212 ql_dbg(ql_dbg_disc, vha, 0x2045,
3213 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003215 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003217 ql_dbg(ql_dbg_disc, vha, 0x2049,
3218 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003220 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003222 ql_dbg(ql_dbg_disc, vha, 0x204f,
3223 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003224 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003226 ql_dbg(ql_dbg_disc, vha, 0x2053,
3227 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 }
3229 }
3230
Joe Carnuccio827210b2013-02-08 01:57:57 -05003231#define QLA_FCPORT_SCAN 1
3232#define QLA_FCPORT_FOUND 2
3233
3234 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3235 fcport->scan_state = QLA_FCPORT_SCAN;
3236 }
3237
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003238 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 if (rval != QLA_SUCCESS)
3240 break;
3241
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003242 /*
3243 * Logout all previous fabric devices marked lost, except
3244 * FCP2 devices.
3245 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003246 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3247 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 break;
3249
3250 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3251 continue;
3252
Joe Carnuccio827210b2013-02-08 01:57:57 -05003253 if (fcport->scan_state == QLA_FCPORT_SCAN &&
Arun Easib3b02e62012-02-09 11:15:39 -08003254 atomic_read(&fcport->state) == FCS_ONLINE) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003255 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003256 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003258 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 fcport->port_type != FCT_INITIATOR &&
3260 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003261 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003262 fcport->loop_id,
3263 fcport->d_id.b.domain,
3264 fcport->d_id.b.area,
3265 fcport->d_id.b.al_pa);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003266 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 }
3268 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003269 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003271 /* Starting free loop ID. */
3272 next_loopid = ha->min_external_loopid;
3273
3274 /*
3275 * Scan through our port list and login entries that need to be
3276 * logged in.
3277 */
3278 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3279 if (atomic_read(&vha->loop_down_timer) ||
3280 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3281 break;
3282
3283 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3284 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3285 continue;
3286
3287 if (fcport->loop_id == FC_NO_LOOP_ID) {
3288 fcport->loop_id = next_loopid;
3289 rval = qla2x00_find_new_loop_id(
3290 base_vha, fcport);
3291 if (rval != QLA_SUCCESS) {
3292 /* Ran out of IDs to use */
3293 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 }
3295 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003296 /* Login and update database */
3297 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
3298 }
3299
3300 /* Exit if out of loop IDs. */
3301 if (rval != QLA_SUCCESS) {
3302 break;
3303 }
3304
3305 /*
3306 * Login and add the new devices to our port list.
3307 */
3308 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3309 if (atomic_read(&vha->loop_down_timer) ||
3310 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3311 break;
3312
3313 /* Find a new loop ID to use. */
3314 fcport->loop_id = next_loopid;
3315 rval = qla2x00_find_new_loop_id(base_vha, fcport);
3316 if (rval != QLA_SUCCESS) {
3317 /* Ran out of IDs to use */
3318 break;
3319 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320
bdf79622005-04-17 15:06:53 -05003321 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003322 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003323
3324 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 }
3326 } while (0);
3327
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003328 /* Free all new device structures not processed. */
3329 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3330 list_del(&fcport->list);
3331 kfree(fcport);
3332 }
3333
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003335 ql_dbg(ql_dbg_disc, vha, 0x2068,
3336 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 }
3338
3339 return (rval);
3340}
3341
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342/*
3343 * qla2x00_find_all_fabric_devs
3344 *
3345 * Input:
3346 * ha = adapter block pointer.
3347 * dev = database device entry pointer.
3348 *
3349 * Returns:
3350 * 0 = success.
3351 *
3352 * Context:
3353 * Kernel context.
3354 */
3355static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003356qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3357 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358{
3359 int rval;
3360 uint16_t loop_id;
3361 fc_port_t *fcport, *new_fcport, *fcptemp;
3362 int found;
3363
3364 sw_info_t *swl;
3365 int swl_idx;
3366 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003367 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003368 struct qla_hw_data *ha = vha->hw;
3369 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003370 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371
3372 rval = QLA_SUCCESS;
3373
3374 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08003375 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08003376 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08003377 GFP_KERNEL);
3378 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003379 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003381 ql_dbg(ql_dbg_disc, vha, 0x2054,
3382 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08003384 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003385 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003387 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003389 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003391 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003392 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3393 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003395
3396 /* If other queries succeeded probe for FC-4 type */
3397 if (swl)
3398 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 }
3400 swl_idx = 0;
3401
3402 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003403 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003405 ql_log(ql_log_warn, vha, 0x205e,
3406 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 return (QLA_MEMORY_ALLOC_FAILED);
3408 }
3409 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 /* Set start port ID scan at adapter ID. */
3411 first_dev = 1;
3412 last_dev = 0;
3413
3414 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003415 loop_id = ha->min_external_loopid;
3416 for (; loop_id <= ha->max_loop_id; loop_id++) {
3417 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 continue;
3419
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003420 if (ha->current_topology == ISP_CFG_FL &&
3421 (atomic_read(&vha->loop_down_timer) ||
3422 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003423 atomic_set(&vha->loop_down_timer, 0);
3424 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3425 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003427 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428
3429 if (swl != NULL) {
3430 if (last_dev) {
3431 wrap.b24 = new_fcport->d_id.b24;
3432 } else {
3433 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3434 memcpy(new_fcport->node_name,
3435 swl[swl_idx].node_name, WWN_SIZE);
3436 memcpy(new_fcport->port_name,
3437 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003438 memcpy(new_fcport->fabric_port_name,
3439 swl[swl_idx].fabric_port_name, WWN_SIZE);
3440 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003441 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442
3443 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3444 last_dev = 1;
3445 }
3446 swl_idx++;
3447 }
3448 } else {
3449 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003450 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003452 ql_log(ql_log_warn, vha, 0x2064,
3453 "SNS scan failed -- assuming "
3454 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 list_for_each_entry_safe(fcport, fcptemp,
3456 new_fcports, list) {
3457 list_del(&fcport->list);
3458 kfree(fcport);
3459 }
3460 rval = QLA_SUCCESS;
3461 break;
3462 }
3463 }
3464
3465 /* If wrap on switch device list, exit. */
3466 if (first_dev) {
3467 wrap.b24 = new_fcport->d_id.b24;
3468 first_dev = 0;
3469 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003470 ql_dbg(ql_dbg_disc, vha, 0x2065,
3471 "Device wrap (%02x%02x%02x).\n",
3472 new_fcport->d_id.b.domain,
3473 new_fcport->d_id.b.area,
3474 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 break;
3476 }
3477
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003478 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003479 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 continue;
3481
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003482 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003483 found = 0;
3484 if (ha->num_vhosts) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003485 unsigned long flags;
3486
3487 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003488 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003489 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3490 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003491 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003492 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003493 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003494 spin_unlock_irqrestore(&ha->vport_slock, flags);
3495
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003496 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003497 continue;
3498 }
3499
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003500 /* Bypass if same domain and area of adapter. */
3501 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003502 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003503 ISP_CFG_FL)
3504 continue;
3505
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 /* Bypass reserved domain fields. */
3507 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3508 continue;
3509
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003510 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003511 if (ql2xgffidenable &&
3512 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3513 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003514 continue;
3515
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 /* Locate matching device in database. */
3517 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003518 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519 if (memcmp(new_fcport->port_name, fcport->port_name,
3520 WWN_SIZE))
3521 continue;
3522
Joe Carnuccio827210b2013-02-08 01:57:57 -05003523 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08003524
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 found++;
3526
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003527 /* Update port state. */
3528 memcpy(fcport->fabric_port_name,
3529 new_fcport->fabric_port_name, WWN_SIZE);
3530 fcport->fp_speed = new_fcport->fp_speed;
3531
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 /*
3533 * If address the same and state FCS_ONLINE, nothing
3534 * changed.
3535 */
3536 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3537 atomic_read(&fcport->state) == FCS_ONLINE) {
3538 break;
3539 }
3540
3541 /*
3542 * If device was not a fabric device before.
3543 */
3544 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3545 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04003546 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 fcport->flags |= (FCF_FABRIC_DEVICE |
3548 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 break;
3550 }
3551
3552 /*
3553 * Port ID changed or device was marked to be updated;
3554 * Log it out if still logged in and mark it for
3555 * relogin later.
3556 */
3557 fcport->d_id.b24 = new_fcport->d_id.b24;
3558 fcport->flags |= FCF_LOGIN_NEEDED;
3559 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003560 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Arun Easi0eba25d2012-02-09 11:15:58 -08003561 (fcport->flags & FCF_ASYNC_SENT) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 fcport->port_type != FCT_INITIATOR &&
3563 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003564 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003565 fcport->d_id.b.domain, fcport->d_id.b.area,
3566 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003567 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568 }
3569
3570 break;
3571 }
3572
3573 if (found)
3574 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 /* If device was not in our fcports list, then add it. */
3576 list_add_tail(&new_fcport->list, new_fcports);
3577
3578 /* Allocate a new replacement fcport. */
3579 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003580 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003582 ql_log(ql_log_warn, vha, 0x2066,
3583 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584 return (QLA_MEMORY_ALLOC_FAILED);
3585 }
3586 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3587 new_fcport->d_id.b24 = nxt_d_id.b24;
3588 }
3589
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003590 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592 return (rval);
3593}
3594
3595/*
3596 * qla2x00_find_new_loop_id
3597 * Scan through our port list and find a new usable loop ID.
3598 *
3599 * Input:
3600 * ha: adapter state pointer.
3601 * dev: port structure pointer.
3602 *
3603 * Returns:
3604 * qla2x00 local function return status code.
3605 *
3606 * Context:
3607 * Kernel context.
3608 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003609int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003610qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611{
3612 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003613 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07003614 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615
3616 rval = QLA_SUCCESS;
3617
Chad Dupuis5f16b332012-08-22 14:21:00 -04003618 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619
Chad Dupuis5f16b332012-08-22 14:21:00 -04003620 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
3621 LOOPID_MAP_SIZE);
3622 if (dev->loop_id >= LOOPID_MAP_SIZE ||
3623 qla2x00_is_reserved_id(vha, dev->loop_id)) {
3624 dev->loop_id = FC_NO_LOOP_ID;
3625 rval = QLA_FUNCTION_FAILED;
3626 } else
3627 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628
Chad Dupuis5f16b332012-08-22 14:21:00 -04003629 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630
Chad Dupuis5f16b332012-08-22 14:21:00 -04003631 if (rval == QLA_SUCCESS)
3632 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
3633 "Assigning new loopid=%x, portid=%x.\n",
3634 dev->loop_id, dev->d_id.b24);
3635 else
3636 ql_log(ql_log_warn, dev->vha, 0x2087,
3637 "No loop_id's available, portid=%x.\n",
3638 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639
3640 return (rval);
3641}
3642
3643/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644 * qla2x00_fabric_dev_login
3645 * Login fabric target device and update FC port database.
3646 *
3647 * Input:
3648 * ha: adapter state pointer.
3649 * fcport: port structure list pointer.
3650 * next_loopid: contains value of a new loop ID that can be used
3651 * by the next login attempt.
3652 *
3653 * Returns:
3654 * qla2x00 local function return status code.
3655 *
3656 * Context:
3657 * Kernel context.
3658 */
3659static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003660qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661 uint16_t *next_loopid)
3662{
3663 int rval;
3664 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003665 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003666 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667
3668 rval = QLA_SUCCESS;
3669 retry = 0;
3670
Andrew Vasquezac280b62009-08-20 11:06:05 -07003671 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003672 if (fcport->flags & FCF_ASYNC_SENT)
3673 return rval;
3674 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003675 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3676 if (!rval)
3677 return rval;
3678 }
3679
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003680 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003681 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003683 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003684 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003685 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003686 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003687 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003689 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003690 fcport->d_id.b.domain, fcport->d_id.b.area,
3691 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003692 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003694 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 }
Chad Dupuis0b91d112012-02-09 11:15:42 -08003696 } else {
3697 /* Retry Login. */
3698 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 }
3700
3701 return (rval);
3702}
3703
3704/*
3705 * qla2x00_fabric_login
3706 * Issue fabric login command.
3707 *
3708 * Input:
3709 * ha = adapter block pointer.
3710 * device = pointer to FC device type structure.
3711 *
3712 * Returns:
3713 * 0 - Login successfully
3714 * 1 - Login failed
3715 * 2 - Initiator device
3716 * 3 - Fatal error
3717 */
3718int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003719qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720 uint16_t *next_loopid)
3721{
3722 int rval;
3723 int retry;
3724 uint16_t tmp_loopid;
3725 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003726 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727
3728 retry = 0;
3729 tmp_loopid = 0;
3730
3731 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003732 ql_dbg(ql_dbg_disc, vha, 0x2000,
3733 "Trying Fabric Login w/loop id 0x%04x for port "
3734 "%02x%02x%02x.\n",
3735 fcport->loop_id, fcport->d_id.b.domain,
3736 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737
3738 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08003739 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740 fcport->d_id.b.domain, fcport->d_id.b.area,
3741 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08003742 if (rval != QLA_SUCCESS) {
3743 return rval;
3744 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745 if (mb[0] == MBS_PORT_ID_USED) {
3746 /*
3747 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003748 * recommends the driver perform an implicit login with
3749 * the specified ID again. The ID we just used is save
3750 * here so we return with an ID that can be tried by
3751 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 */
3753 retry++;
3754 tmp_loopid = fcport->loop_id;
3755 fcport->loop_id = mb[1];
3756
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003757 ql_dbg(ql_dbg_disc, vha, 0x2001,
3758 "Fabric Login: port in use - next loop "
3759 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003761 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762
3763 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3764 /*
3765 * Login succeeded.
3766 */
3767 if (retry) {
3768 /* A retry occurred before. */
3769 *next_loopid = tmp_loopid;
3770 } else {
3771 /*
3772 * No retry occurred before. Just increment the
3773 * ID value for next login.
3774 */
3775 *next_loopid = (fcport->loop_id + 1);
3776 }
3777
3778 if (mb[1] & BIT_0) {
3779 fcport->port_type = FCT_INITIATOR;
3780 } else {
3781 fcport->port_type = FCT_TARGET;
3782 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003783 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 }
3785 }
3786
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003787 if (mb[10] & BIT_0)
3788 fcport->supported_classes |= FC_COS_CLASS2;
3789 if (mb[10] & BIT_1)
3790 fcport->supported_classes |= FC_COS_CLASS3;
3791
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003792 if (IS_FWI2_CAPABLE(ha)) {
3793 if (mb[10] & BIT_7)
3794 fcport->flags |=
3795 FCF_CONF_COMP_SUPPORTED;
3796 }
3797
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798 rval = QLA_SUCCESS;
3799 break;
3800 } else if (mb[0] == MBS_LOOP_ID_USED) {
3801 /*
3802 * Loop ID already used, try next loop ID.
3803 */
3804 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003805 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 if (rval != QLA_SUCCESS) {
3807 /* Ran out of loop IDs to use */
3808 break;
3809 }
3810 } else if (mb[0] == MBS_COMMAND_ERROR) {
3811 /*
3812 * Firmware possibly timed out during login. If NO
3813 * retries are left to do then the device is declared
3814 * dead.
3815 */
3816 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003817 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003818 fcport->d_id.b.domain, fcport->d_id.b.area,
3819 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003820 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821
3822 rval = 1;
3823 break;
3824 } else {
3825 /*
3826 * unrecoverable / not handled error
3827 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003828 ql_dbg(ql_dbg_disc, vha, 0x2002,
3829 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
3830 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
3831 fcport->d_id.b.area, fcport->d_id.b.al_pa,
3832 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833
3834 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003835 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003836 fcport->d_id.b.domain, fcport->d_id.b.area,
3837 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003838 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003839 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840
3841 rval = 3;
3842 break;
3843 }
3844 }
3845
3846 return (rval);
3847}
3848
3849/*
3850 * qla2x00_local_device_login
3851 * Issue local device login command.
3852 *
3853 * Input:
3854 * ha = adapter block pointer.
3855 * loop_id = loop id of device to login to.
3856 *
3857 * Returns (Where's the #define!!!!):
3858 * 0 - Login successfully
3859 * 1 - Login failed
3860 * 3 - Fatal error
3861 */
3862int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003863qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864{
3865 int rval;
3866 uint16_t mb[MAILBOX_REGISTER_COUNT];
3867
3868 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003869 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 if (rval == QLA_SUCCESS) {
3871 /* Interrogate mailbox registers for any errors */
3872 if (mb[0] == MBS_COMMAND_ERROR)
3873 rval = 1;
3874 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3875 /* device not in PCB table */
3876 rval = 3;
3877 }
3878
3879 return (rval);
3880}
3881
3882/*
3883 * qla2x00_loop_resync
3884 * Resync with fibre channel devices.
3885 *
3886 * Input:
3887 * ha = adapter block pointer.
3888 *
3889 * Returns:
3890 * 0 = success
3891 */
3892int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003893qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003895 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003897 struct req_que *req;
3898 struct rsp_que *rsp;
3899
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003900 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003901 req = vha->hw->req_q_map[0];
3902 else
3903 req = vha->req;
3904 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003906 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3907 if (vha->flags.online) {
3908 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3910 wait_time = 256;
3911 do {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003912 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003913 qla2x00_marker(vha, req, rsp, 0, 0,
3914 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003915 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916
3917 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003918 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003920 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003922 } while (!atomic_read(&vha->loop_down_timer) &&
3923 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3924 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3925 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927 }
3928
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003929 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003932 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003933 ql_dbg(ql_dbg_disc, vha, 0x206c,
3934 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935
3936 return (rval);
3937}
3938
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003939/*
3940* qla2x00_perform_loop_resync
3941* Description: This function will set the appropriate flags and call
3942* qla2x00_loop_resync. If successful loop will be resynced
3943* Arguments : scsi_qla_host_t pointer
3944* returm : Success or Failure
3945*/
3946
3947int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
3948{
3949 int32_t rval = 0;
3950
3951 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
3952 /*Configure the flags so that resync happens properly*/
3953 atomic_set(&ha->loop_down_timer, 0);
3954 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3955 atomic_set(&ha->loop_state, LOOP_UP);
3956 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
3957 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
3958 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3959
3960 rval = qla2x00_loop_resync(ha);
3961 } else
3962 atomic_set(&ha->loop_state, LOOP_DEAD);
3963
3964 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3965 }
3966
3967 return rval;
3968}
3969
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003971qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003972{
3973 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07003974 struct scsi_qla_host *vha;
3975 struct qla_hw_data *ha = base_vha->hw;
3976 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003977
Arun Easifeafb7b2010-09-03 14:57:00 -07003978 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003979 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07003980 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
3981 atomic_inc(&vha->vref_count);
3982 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08003983 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07003984 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
3985 spin_unlock_irqrestore(&ha->vport_slock, flags);
3986
Andrew Vasquez67becc02009-08-25 11:36:20 -07003987 qla2x00_rport_del(fcport);
Arun Easifeafb7b2010-09-03 14:57:00 -07003988
3989 spin_lock_irqsave(&ha->vport_slock, flags);
3990 }
3991 }
3992 atomic_dec(&vha->vref_count);
3993 }
3994 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003995}
3996
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003997/* Assumes idc_lock always held on entry */
3998void
3999qla83xx_reset_ownership(scsi_qla_host_t *vha)
4000{
4001 struct qla_hw_data *ha = vha->hw;
4002 uint32_t drv_presence, drv_presence_mask;
4003 uint32_t dev_part_info1, dev_part_info2, class_type;
4004 uint32_t class_type_mask = 0x3;
4005 uint16_t fcoe_other_function = 0xffff, i;
4006
4007 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4008
4009 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
4010 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
4011 for (i = 0; i < 8; i++) {
4012 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
4013 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4014 (i != ha->portnum)) {
4015 fcoe_other_function = i;
4016 break;
4017 }
4018 }
4019 if (fcoe_other_function == 0xffff) {
4020 for (i = 0; i < 8; i++) {
4021 class_type = ((dev_part_info2 >> (i * 4)) &
4022 class_type_mask);
4023 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4024 ((i + 8) != ha->portnum)) {
4025 fcoe_other_function = i + 8;
4026 break;
4027 }
4028 }
4029 }
4030 /*
4031 * Prepare drv-presence mask based on fcoe functions present.
4032 * However consider only valid physical fcoe function numbers (0-15).
4033 */
4034 drv_presence_mask = ~((1 << (ha->portnum)) |
4035 ((fcoe_other_function == 0xffff) ?
4036 0 : (1 << (fcoe_other_function))));
4037
4038 /* We are the reset owner iff:
4039 * - No other protocol drivers present.
4040 * - This is the lowest among fcoe functions. */
4041 if (!(drv_presence & drv_presence_mask) &&
4042 (ha->portnum < fcoe_other_function)) {
4043 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
4044 "This host is Reset owner.\n");
4045 ha->flags.nic_core_reset_owner = 1;
4046 }
4047}
4048
Saurav Kashyapfa492632012-11-21 02:40:29 -05004049static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004050__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
4051{
4052 int rval = QLA_SUCCESS;
4053 struct qla_hw_data *ha = vha->hw;
4054 uint32_t drv_ack;
4055
4056 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4057 if (rval == QLA_SUCCESS) {
4058 drv_ack |= (1 << ha->portnum);
4059 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4060 }
4061
4062 return rval;
4063}
4064
Saurav Kashyapfa492632012-11-21 02:40:29 -05004065static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004066__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
4067{
4068 int rval = QLA_SUCCESS;
4069 struct qla_hw_data *ha = vha->hw;
4070 uint32_t drv_ack;
4071
4072 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4073 if (rval == QLA_SUCCESS) {
4074 drv_ack &= ~(1 << ha->portnum);
4075 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4076 }
4077
4078 return rval;
4079}
4080
Saurav Kashyapfa492632012-11-21 02:40:29 -05004081static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004082qla83xx_dev_state_to_string(uint32_t dev_state)
4083{
4084 switch (dev_state) {
4085 case QLA8XXX_DEV_COLD:
4086 return "COLD/RE-INIT";
4087 case QLA8XXX_DEV_INITIALIZING:
4088 return "INITIALIZING";
4089 case QLA8XXX_DEV_READY:
4090 return "READY";
4091 case QLA8XXX_DEV_NEED_RESET:
4092 return "NEED RESET";
4093 case QLA8XXX_DEV_NEED_QUIESCENT:
4094 return "NEED QUIESCENT";
4095 case QLA8XXX_DEV_FAILED:
4096 return "FAILED";
4097 case QLA8XXX_DEV_QUIESCENT:
4098 return "QUIESCENT";
4099 default:
4100 return "Unknown";
4101 }
4102}
4103
4104/* Assumes idc-lock always held on entry */
4105void
4106qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
4107{
4108 struct qla_hw_data *ha = vha->hw;
4109 uint32_t idc_audit_reg = 0, duration_secs = 0;
4110
4111 switch (audit_type) {
4112 case IDC_AUDIT_TIMESTAMP:
4113 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
4114 idc_audit_reg = (ha->portnum) |
4115 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
4116 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4117 break;
4118
4119 case IDC_AUDIT_COMPLETION:
4120 duration_secs = ((jiffies_to_msecs(jiffies) -
4121 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
4122 idc_audit_reg = (ha->portnum) |
4123 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
4124 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4125 break;
4126
4127 default:
4128 ql_log(ql_log_warn, vha, 0xb078,
4129 "Invalid audit type specified.\n");
4130 break;
4131 }
4132}
4133
4134/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05004135static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004136qla83xx_initiating_reset(scsi_qla_host_t *vha)
4137{
4138 struct qla_hw_data *ha = vha->hw;
4139 uint32_t idc_control, dev_state;
4140
4141 __qla83xx_get_idc_control(vha, &idc_control);
4142 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
4143 ql_log(ql_log_info, vha, 0xb080,
4144 "NIC Core reset has been disabled. idc-control=0x%x\n",
4145 idc_control);
4146 return QLA_FUNCTION_FAILED;
4147 }
4148
4149 /* Set NEED-RESET iff in READY state and we are the reset-owner */
4150 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4151 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
4152 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
4153 QLA8XXX_DEV_NEED_RESET);
4154 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
4155 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
4156 } else {
4157 const char *state = qla83xx_dev_state_to_string(dev_state);
4158 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
4159
4160 /* SV: XXX: Is timeout required here? */
4161 /* Wait for IDC state change READY -> NEED_RESET */
4162 while (dev_state == QLA8XXX_DEV_READY) {
4163 qla83xx_idc_unlock(vha, 0);
4164 msleep(200);
4165 qla83xx_idc_lock(vha, 0);
4166 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4167 }
4168 }
4169
4170 /* Send IDC ack by writing to drv-ack register */
4171 __qla83xx_set_drv_ack(vha);
4172
4173 return QLA_SUCCESS;
4174}
4175
4176int
4177__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
4178{
4179 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4180}
4181
4182int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004183__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
4184{
4185 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4186}
4187
Saurav Kashyapfa492632012-11-21 02:40:29 -05004188static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004189qla83xx_check_driver_presence(scsi_qla_host_t *vha)
4190{
4191 uint32_t drv_presence = 0;
4192 struct qla_hw_data *ha = vha->hw;
4193
4194 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4195 if (drv_presence & (1 << ha->portnum))
4196 return QLA_SUCCESS;
4197 else
4198 return QLA_TEST_FAILED;
4199}
4200
4201int
4202qla83xx_nic_core_reset(scsi_qla_host_t *vha)
4203{
4204 int rval = QLA_SUCCESS;
4205 struct qla_hw_data *ha = vha->hw;
4206
4207 ql_dbg(ql_dbg_p3p, vha, 0xb058,
4208 "Entered %s().\n", __func__);
4209
4210 if (vha->device_flags & DFLG_DEV_FAILED) {
4211 ql_log(ql_log_warn, vha, 0xb059,
4212 "Device in unrecoverable FAILED state.\n");
4213 return QLA_FUNCTION_FAILED;
4214 }
4215
4216 qla83xx_idc_lock(vha, 0);
4217
4218 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
4219 ql_log(ql_log_warn, vha, 0xb05a,
4220 "Function=0x%x has been removed from IDC participation.\n",
4221 ha->portnum);
4222 rval = QLA_FUNCTION_FAILED;
4223 goto exit;
4224 }
4225
4226 qla83xx_reset_ownership(vha);
4227
4228 rval = qla83xx_initiating_reset(vha);
4229
4230 /*
4231 * Perform reset if we are the reset-owner,
4232 * else wait till IDC state changes to READY/FAILED.
4233 */
4234 if (rval == QLA_SUCCESS) {
4235 rval = qla83xx_idc_state_handler(vha);
4236
4237 if (rval == QLA_SUCCESS)
4238 ha->flags.nic_core_hung = 0;
4239 __qla83xx_clear_drv_ack(vha);
4240 }
4241
4242exit:
4243 qla83xx_idc_unlock(vha, 0);
4244
4245 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
4246
4247 return rval;
4248}
4249
Saurav Kashyap81178772012-08-22 14:21:04 -04004250int
4251qla2xxx_mctp_dump(scsi_qla_host_t *vha)
4252{
4253 struct qla_hw_data *ha = vha->hw;
4254 int rval = QLA_FUNCTION_FAILED;
4255
4256 if (!IS_MCTP_CAPABLE(ha)) {
4257 /* This message can be removed from the final version */
4258 ql_log(ql_log_info, vha, 0x506d,
4259 "This board is not MCTP capable\n");
4260 return rval;
4261 }
4262
4263 if (!ha->mctp_dump) {
4264 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
4265 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
4266
4267 if (!ha->mctp_dump) {
4268 ql_log(ql_log_warn, vha, 0x506e,
4269 "Failed to allocate memory for mctp dump\n");
4270 return rval;
4271 }
4272 }
4273
4274#define MCTP_DUMP_STR_ADDR 0x00000000
4275 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
4276 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
4277 if (rval != QLA_SUCCESS) {
4278 ql_log(ql_log_warn, vha, 0x506f,
4279 "Failed to capture mctp dump\n");
4280 } else {
4281 ql_log(ql_log_info, vha, 0x5070,
4282 "Mctp dump capture for host (%ld/%p).\n",
4283 vha->host_no, ha->mctp_dump);
4284 ha->mctp_dumped = 1;
4285 }
4286
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04004287 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04004288 ha->flags.nic_core_reset_hdlr_active = 1;
4289 rval = qla83xx_restart_nic_firmware(vha);
4290 if (rval)
4291 /* NIC Core reset failed. */
4292 ql_log(ql_log_warn, vha, 0x5071,
4293 "Failed to restart nic firmware\n");
4294 else
4295 ql_dbg(ql_dbg_p3p, vha, 0xb084,
4296 "Restarted NIC firmware successfully.\n");
4297 ha->flags.nic_core_reset_hdlr_active = 0;
4298 }
4299
4300 return rval;
4301
4302}
4303
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004304/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004305* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004306* Description: This function will block the new I/Os
4307* Its not aborting any I/Os as context
4308* is not destroyed during quiescence
4309* Arguments: scsi_qla_host_t
4310* return : void
4311*/
4312void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004313qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004314{
4315 struct qla_hw_data *ha = vha->hw;
4316 struct scsi_qla_host *vp;
4317
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004318 ql_dbg(ql_dbg_dpc, vha, 0x401d,
4319 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004320
4321 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4322 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4323 atomic_set(&vha->loop_state, LOOP_DOWN);
4324 qla2x00_mark_all_devices_lost(vha, 0);
4325 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004326 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004327 } else {
4328 if (!atomic_read(&vha->loop_down_timer))
4329 atomic_set(&vha->loop_down_timer,
4330 LOOP_DOWN_TIME);
4331 }
4332 /* Wait for pending cmds to complete */
4333 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
4334}
4335
Giridhar Malavalia9083012010-04-12 17:59:55 -07004336void
4337qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
4338{
4339 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004340 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07004341 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004342 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004343
Saurav Kashyape46ef002011-02-23 15:27:16 -08004344 /* For ISP82XX, driver waits for completion of the commands.
4345 * online flag should be set.
4346 */
4347 if (!IS_QLA82XX(ha))
4348 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004349 ha->flags.chip_reset_done = 0;
4350 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04004351 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004352
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004353 ql_log(ql_log_info, vha, 0x00af,
4354 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004355
Saurav Kashyape46ef002011-02-23 15:27:16 -08004356 /* For ISP82XX, reset_chip is just disabling interrupts.
4357 * Driver waits for the completion of the commands.
4358 * the interrupts need to be enabled.
4359 */
Giridhar Malavalia9083012010-04-12 17:59:55 -07004360 if (!IS_QLA82XX(ha))
4361 ha->isp_ops->reset_chip(vha);
4362
4363 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
4364 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4365 atomic_set(&vha->loop_state, LOOP_DOWN);
4366 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004367
4368 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004369 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07004370 atomic_inc(&vp->vref_count);
4371 spin_unlock_irqrestore(&ha->vport_slock, flags);
4372
Giridhar Malavalia9083012010-04-12 17:59:55 -07004373 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004374
4375 spin_lock_irqsave(&ha->vport_slock, flags);
4376 atomic_dec(&vp->vref_count);
4377 }
4378 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004379 } else {
4380 if (!atomic_read(&vha->loop_down_timer))
4381 atomic_set(&vha->loop_down_timer,
4382 LOOP_DOWN_TIME);
4383 }
4384
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004385 /* Clear all async request states across all VPs. */
4386 list_for_each_entry(fcport, &vha->vp_fcports, list)
4387 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4388 spin_lock_irqsave(&ha->vport_slock, flags);
4389 list_for_each_entry(vp, &ha->vp_list, list) {
4390 atomic_inc(&vp->vref_count);
4391 spin_unlock_irqrestore(&ha->vport_slock, flags);
4392
4393 list_for_each_entry(fcport, &vp->vp_fcports, list)
4394 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4395
4396 spin_lock_irqsave(&ha->vport_slock, flags);
4397 atomic_dec(&vp->vref_count);
4398 }
4399 spin_unlock_irqrestore(&ha->vport_slock, flags);
4400
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004401 if (!ha->flags.eeh_busy) {
4402 /* Make sure for ISP 82XX IO DMA is complete */
4403 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004404 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004405 ql_log(ql_log_info, vha, 0x00b4,
4406 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004407
Saurav Kashyape46ef002011-02-23 15:27:16 -08004408 /* Done waiting for pending commands.
4409 * Reset the online flag.
4410 */
4411 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004414 /* Requeue all commands in outstanding command list. */
4415 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417}
4418
4419/*
4420* qla2x00_abort_isp
4421* Resets ISP and aborts all outstanding commands.
4422*
4423* Input:
4424* ha = adapter block pointer.
4425*
4426* Returns:
4427* 0 = success
4428*/
4429int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004430qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431{
Andrew Vasquez476e8972006-08-23 14:54:55 -07004432 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004433 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004434 struct qla_hw_data *ha = vha->hw;
4435 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004436 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07004437 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004439 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004440 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004441
Santosh Vernekara6171292012-08-22 14:21:13 -04004442 if (IS_QLA8031(ha)) {
4443 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
4444 "Clearing fcoe driver presence.\n");
4445 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
4446 ql_dbg(ql_dbg_p3p, vha, 0xb073,
4447 "Error while clearing DRV-Presence.\n");
4448 }
4449
Andrew Vasquez85880802009-12-15 21:29:46 -08004450 if (unlikely(pci_channel_offline(ha->pdev) &&
4451 ha->flags.pci_channel_io_perm_failure)) {
4452 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4453 status = 0;
4454 return status;
4455 }
4456
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004457 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08004458
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004459 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004461 if (!qla2x00_restart_isp(vha)) {
4462 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004464 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465 /*
4466 * Issue marker command only when we are going
4467 * to start the I/O .
4468 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004469 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470 }
4471
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004472 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004474 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004475
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004476 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004477 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07004478
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004479 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
4480 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004481 if (ha->fce) {
4482 ha->flags.fce_enabled = 1;
4483 memset(ha->fce, 0,
4484 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004485 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004486 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4487 &ha->fce_bufs);
4488 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004489 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004490 "Unable to reinitialize FCE "
4491 "(%d).\n", rval);
4492 ha->flags.fce_enabled = 0;
4493 }
4494 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004495
4496 if (ha->eft) {
4497 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004498 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004499 ha->eft_dma, EFT_NUM_BUFFERS);
4500 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004501 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004502 "Unable to reinitialize EFT "
4503 "(%d).\n", rval);
4504 }
4505 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004507 vha->flags.online = 1;
4508 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004509 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004510 ql_log(ql_log_fatal, vha, 0x8035,
4511 "ISP error recover failed - "
4512 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004513 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004514 * The next call disables the board
4515 * completely.
4516 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004517 ha->isp_ops->reset_adapter(vha);
4518 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004520 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521 status = 0;
4522 } else { /* schedule another ISP abort */
4523 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004524 ql_dbg(ql_dbg_taskm, vha, 0x8020,
4525 "ISP abort - retry remaining %d.\n",
4526 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527 status = 1;
4528 }
4529 } else {
4530 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004531 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4532 "ISP error recovery - retrying (%d) "
4533 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004534 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004535 status = 1;
4536 }
4537 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004538
Linus Torvalds1da177e2005-04-16 15:20:36 -07004539 }
4540
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004541 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004542 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07004543
4544 spin_lock_irqsave(&ha->vport_slock, flags);
4545 list_for_each_entry(vp, &ha->vp_list, list) {
4546 if (vp->vp_idx) {
4547 atomic_inc(&vp->vref_count);
4548 spin_unlock_irqrestore(&ha->vport_slock, flags);
4549
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004550 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004551
4552 spin_lock_irqsave(&ha->vport_slock, flags);
4553 atomic_dec(&vp->vref_count);
4554 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004555 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004556 spin_unlock_irqrestore(&ha->vport_slock, flags);
4557
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004558 if (IS_QLA8031(ha)) {
4559 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
4560 "Setting back fcoe driver presence.\n");
4561 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
4562 ql_dbg(ql_dbg_p3p, vha, 0xb074,
4563 "Error while setting DRV-Presence.\n");
4564 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004565 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08004566 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
4567 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568 }
4569
4570 return(status);
4571}
4572
4573/*
4574* qla2x00_restart_isp
4575* restarts the ISP after a reset
4576*
4577* Input:
4578* ha = adapter block pointer.
4579*
4580* Returns:
4581* 0 = success
4582*/
4583static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004584qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004586 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004588 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004589 struct req_que *req = ha->req_q_map[0];
4590 struct rsp_que *rsp = ha->rsp_q_map[0];
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004591 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004592
4593 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004594 if (qla2x00_isp_firmware(vha)) {
4595 vha->flags.online = 0;
4596 status = ha->isp_ops->chip_diag(vha);
4597 if (!status)
4598 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004599 }
4600
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004601 if (!status && !(status = qla2x00_init_rings(vha))) {
4602 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004603 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004604 /* Initialize the queues in use */
4605 qla25xx_init_queues(ha);
4606
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004607 status = qla2x00_fw_ready(vha);
4608 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004609 ql_dbg(ql_dbg_taskm, vha, 0x8031,
4610 "Start configure loop status = %d.\n", status);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004611
4612 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004613 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004614
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004615 vha->flags.online = 1;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004616
4617 /*
4618 * Process any ATIO queue entries that came in
4619 * while we weren't online.
4620 */
4621 spin_lock_irqsave(&ha->hardware_lock, flags);
4622 if (qla_tgt_mode_enabled(vha))
4623 qlt_24xx_process_atio_queue(vha);
4624 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4625
Linus Torvalds1da177e2005-04-16 15:20:36 -07004626 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4627 wait_time = 256;
4628 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004629 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4630 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004631 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004632 } while (!atomic_read(&vha->loop_down_timer) &&
4633 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4634 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4635 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004636 }
4637
4638 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004639 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640 status = 0;
4641
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004642 ql_dbg(ql_dbg_taskm, vha, 0x8032,
4643 "Configure loop done, status = 0x%x.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644 }
4645 return (status);
4646}
4647
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004648static int
4649qla25xx_init_queues(struct qla_hw_data *ha)
4650{
4651 struct rsp_que *rsp = NULL;
4652 struct req_que *req = NULL;
4653 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4654 int ret = -1;
4655 int i;
4656
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004657 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004658 rsp = ha->rsp_q_map[i];
4659 if (rsp) {
4660 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004661 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004662 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004663 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4664 "%s Rsp que: %d init failed.\n",
4665 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004666 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004667 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4668 "%s Rsp que: %d inited.\n",
4669 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004670 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004671 }
4672 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004673 req = ha->req_q_map[i];
4674 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004675 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004676 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004677 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004678 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004679 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4680 "%s Req que: %d init failed.\n",
4681 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004682 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004683 ql_dbg(ql_dbg_init, base_vha, 0x0102,
4684 "%s Req que: %d inited.\n",
4685 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004686 }
4687 }
4688 return ret;
4689}
4690
Linus Torvalds1da177e2005-04-16 15:20:36 -07004691/*
4692* qla2x00_reset_adapter
4693* Reset adapter.
4694*
4695* Input:
4696* ha = adapter block pointer.
4697*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004698void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004699qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004700{
4701 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004702 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004703 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004704
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004705 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004706 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004707
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708 spin_lock_irqsave(&ha->hardware_lock, flags);
4709 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4710 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4711 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4712 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4713 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4714}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004715
4716void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004717qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004718{
4719 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004720 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004721 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4722
Giridhar Malavalia9083012010-04-12 17:59:55 -07004723 if (IS_QLA82XX(ha))
4724 return;
4725
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004726 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004727 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004728
4729 spin_lock_irqsave(&ha->hardware_lock, flags);
4730 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4731 RD_REG_DWORD(&reg->hccr);
4732 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4733 RD_REG_DWORD(&reg->hccr);
4734 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004735
4736 if (IS_NOPOLLING_TYPE(ha))
4737 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004738}
4739
David Miller4e08df32007-04-16 12:37:43 -07004740/* On sparc systems, obtain port and node WWN from firmware
4741 * properties.
4742 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004743static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4744 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004745{
4746#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004747 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004748 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004749 struct device_node *dp = pci_device_to_OF_node(pdev);
4750 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004751 int len;
4752
4753 val = of_get_property(dp, "port-wwn", &len);
4754 if (val && len >= WWN_SIZE)
4755 memcpy(nv->port_name, val, WWN_SIZE);
4756
4757 val = of_get_property(dp, "node-wwn", &len);
4758 if (val && len >= WWN_SIZE)
4759 memcpy(nv->node_name, val, WWN_SIZE);
4760#endif
4761}
4762
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004763int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004764qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004765{
David Miller4e08df32007-04-16 12:37:43 -07004766 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004767 struct init_cb_24xx *icb;
4768 struct nvram_24xx *nv;
4769 uint32_t *dptr;
4770 uint8_t *dptr1, *dptr2;
4771 uint32_t chksum;
4772 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004773 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004774
David Miller4e08df32007-04-16 12:37:43 -07004775 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004776 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004777 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004778
4779 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004780 if (ha->flags.port0) {
4781 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4782 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4783 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004784 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004785 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4786 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004787 ha->nvram_size = sizeof(struct nvram_24xx);
4788 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004789 if (IS_QLA82XX(ha))
4790 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004791
Seokmann Ju281afe12007-07-26 13:43:34 -07004792 /* Get VPD data into cache */
4793 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004794 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004795 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4796
4797 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004798 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004799 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004800 ha->nvram_size);
4801 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4802 chksum += le32_to_cpu(*dptr++);
4803
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004804 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
4805 "Contents of NVRAM\n");
4806 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
4807 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004808
4809 /* Bad NVRAM data, set defaults parameters. */
4810 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4811 || nv->id[3] != ' ' ||
4812 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4813 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004814 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04004815 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004816 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
4817 ql_log(ql_log_warn, vha, 0x006c,
4818 "Falling back to functioning (yet invalid -- WWPN) "
4819 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07004820
4821 /*
4822 * Set default initialization control block.
4823 */
4824 memset(nv, 0, ha->nvram_size);
4825 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4826 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4827 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4828 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4829 nv->exchange_count = __constant_cpu_to_le16(0);
4830 nv->hard_address = __constant_cpu_to_le16(124);
4831 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004832 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004833 nv->port_name[2] = 0x00;
4834 nv->port_name[3] = 0xe0;
4835 nv->port_name[4] = 0x8b;
4836 nv->port_name[5] = 0x1c;
4837 nv->port_name[6] = 0x55;
4838 nv->port_name[7] = 0x86;
4839 nv->node_name[0] = 0x20;
4840 nv->node_name[1] = 0x00;
4841 nv->node_name[2] = 0x00;
4842 nv->node_name[3] = 0xe0;
4843 nv->node_name[4] = 0x8b;
4844 nv->node_name[5] = 0x1c;
4845 nv->node_name[6] = 0x55;
4846 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004847 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004848 nv->login_retry_count = __constant_cpu_to_le16(8);
4849 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4850 nv->login_timeout = __constant_cpu_to_le16(0);
4851 nv->firmware_options_1 =
4852 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4853 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4854 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4855 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4856 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4857 nv->efi_parameters = __constant_cpu_to_le32(0);
4858 nv->reset_delay = 5;
4859 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4860 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4861 nv->link_down_timeout = __constant_cpu_to_le16(30);
4862
4863 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004864 }
4865
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004866 if (!qla_ini_mode_enabled(vha)) {
4867 /* Don't enable full login after initial LIP */
4868 nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13);
4869 /* Don't enable LIP full login for initiator */
4870 nv->host_p &= __constant_cpu_to_le32(~BIT_10);
4871 }
4872
4873 qlt_24xx_config_nvram_stage1(vha, nv);
4874
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004875 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004876 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004877
4878 /* Copy 1st segment. */
4879 dptr1 = (uint8_t *)icb;
4880 dptr2 = (uint8_t *)&nv->version;
4881 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4882 while (cnt--)
4883 *dptr1++ = *dptr2++;
4884
4885 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004886 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004887
4888 /* Copy 2nd segment. */
4889 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4890 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4891 cnt = (uint8_t *)&icb->reserved_3 -
4892 (uint8_t *)&icb->interrupt_delay_timer;
4893 while (cnt--)
4894 *dptr1++ = *dptr2++;
4895
4896 /*
4897 * Setup driver NVRAM options.
4898 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004899 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004900 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004901
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004902 qlt_24xx_config_nvram_stage2(vha, icb);
4903
Andrew Vasquez5341e862006-05-17 15:09:16 -07004904 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004905 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07004906 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4907 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4908 }
4909
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004910 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004911 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004912 /*
4913 * Firmware will apply the following mask if the nodename was
4914 * not provided.
4915 */
4916 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4917 icb->node_name[0] &= 0xF0;
4918 }
4919
4920 /* Set host adapter parameters. */
4921 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004922 ha->flags.enable_lip_reset = 0;
4923 ha->flags.enable_lip_full_login =
4924 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4925 ha->flags.enable_target_reset =
4926 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004927 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004928 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004929
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004930 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4931 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004932
4933 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4934 sizeof(ha->fw_seriallink_options24));
4935
4936 /* save HBA serial number */
4937 ha->serial0 = icb->port_name[5];
4938 ha->serial1 = icb->port_name[6];
4939 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004940 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4941 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004942
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004943 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4944
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004945 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4946
4947 /* Set minimum login_timeout to 4 seconds. */
4948 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4949 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4950 if (le16_to_cpu(nv->login_timeout) < 4)
4951 nv->login_timeout = __constant_cpu_to_le16(4);
4952 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004953 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004954
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004955 /* Set minimum RATOV to 100 tenths of a second. */
4956 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004957
4958 ha->loop_reset_delay = nv->reset_delay;
4959
4960 /* Link Down Timeout = 0:
4961 *
4962 * When Port Down timer expires we will start returning
4963 * I/O's to OS with "DID_NO_CONNECT".
4964 *
4965 * Link Down Timeout != 0:
4966 *
4967 * The driver waits for the link to come up after link down
4968 * before returning I/Os to OS with "DID_NO_CONNECT".
4969 */
4970 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4971 ha->loop_down_abort_time =
4972 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4973 } else {
4974 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4975 ha->loop_down_abort_time =
4976 (LOOP_DOWN_TIME - ha->link_down_timeout);
4977 }
4978
4979 /* Need enough time to try and get the port back. */
4980 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4981 if (qlport_down_retry)
4982 ha->port_down_retry_count = qlport_down_retry;
4983
4984 /* Set login_retry_count */
4985 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4986 if (ha->port_down_retry_count ==
4987 le16_to_cpu(nv->port_down_retry_count) &&
4988 ha->port_down_retry_count > 3)
4989 ha->login_retry_count = ha->port_down_retry_count;
4990 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4991 ha->login_retry_count = ha->port_down_retry_count;
4992 if (ql2xloginretrycount)
4993 ha->login_retry_count = ql2xloginretrycount;
4994
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004995 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004996 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004997 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4998 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4999 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5000 le16_to_cpu(icb->interrupt_delay_timer): 2;
5001 }
5002 icb->firmware_options_2 &= __constant_cpu_to_le32(
5003 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005004 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005005 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08005006 ha->zio_mode = QLA_ZIO_MODE_6;
5007
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005008 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005009 "ZIO mode %d enabled; timer delay (%d us).\n",
5010 ha->zio_mode, ha->zio_timer * 100);
5011
5012 icb->firmware_options_2 |= cpu_to_le32(
5013 (uint32_t)ha->zio_mode);
5014 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005015 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005016 }
5017
David Miller4e08df32007-04-16 12:37:43 -07005018 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005019 ql_log(ql_log_warn, vha, 0x0070,
5020 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07005021 }
5022 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005023}
5024
Adrian Bunk413975a2006-06-30 02:33:06 -07005025static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005026qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
5027 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005028{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005029 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005030 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005031 uint32_t *dcode, dlen;
5032 uint32_t risc_addr;
5033 uint32_t risc_size;
5034 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005035 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005036 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005037
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005038 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08005039 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005040
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005041 rval = QLA_SUCCESS;
5042
5043 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005044 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005045 *srisc_addr = 0;
5046
5047 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005048 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005049 for (i = 0; i < 4; i++)
5050 dcode[i] = be32_to_cpu(dcode[i]);
5051 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5052 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5053 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5054 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005055 ql_log(ql_log_fatal, vha, 0x008c,
5056 "Unable to verify the integrity of flash firmware "
5057 "image.\n");
5058 ql_log(ql_log_fatal, vha, 0x008d,
5059 "Firmware data: %08x %08x %08x %08x.\n",
5060 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005061
5062 return QLA_FUNCTION_FAILED;
5063 }
5064
5065 while (segments && rval == QLA_SUCCESS) {
5066 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005067 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005068
5069 risc_addr = be32_to_cpu(dcode[2]);
5070 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5071 risc_size = be32_to_cpu(dcode[3]);
5072
5073 fragment = 0;
5074 while (risc_size > 0 && rval == QLA_SUCCESS) {
5075 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5076 if (dlen > risc_size)
5077 dlen = risc_size;
5078
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005079 ql_dbg(ql_dbg_init, vha, 0x008e,
5080 "Loading risc segment@ risc addr %x "
5081 "number of dwords 0x%x offset 0x%x.\n",
5082 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005083
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005084 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005085 for (i = 0; i < dlen; i++)
5086 dcode[i] = swab32(dcode[i]);
5087
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005088 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005089 dlen);
5090 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005091 ql_log(ql_log_fatal, vha, 0x008f,
5092 "Failed to load segment %d of firmware.\n",
5093 fragment);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005094 break;
5095 }
5096
5097 faddr += dlen;
5098 risc_addr += dlen;
5099 risc_size -= dlen;
5100 fragment++;
5101 }
5102
5103 /* Next segment. */
5104 segments--;
5105 }
5106
5107 return rval;
5108}
5109
Giridhar Malavalie9454a82013-02-08 01:57:47 -05005110#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005111
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005112int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005113qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08005114{
5115 int rval;
5116 int i, fragment;
5117 uint16_t *wcode, *fwcode;
5118 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
5119 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005120 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005121 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08005122
5123 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005124 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005125 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005126 ql_log(ql_log_info, vha, 0x0083,
5127 "Fimware image unavailable.\n");
5128 ql_log(ql_log_info, vha, 0x0084,
5129 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08005130 return QLA_FUNCTION_FAILED;
5131 }
5132
5133 rval = QLA_SUCCESS;
5134
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005135 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08005136 *srisc_addr = 0;
5137 fwcode = (uint16_t *)blob->fw->data;
5138 fwclen = 0;
5139
5140 /* Validate firmware image by checking version. */
5141 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005142 ql_log(ql_log_fatal, vha, 0x0085,
5143 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005144 blob->fw->size);
5145 goto fail_fw_integrity;
5146 }
5147 for (i = 0; i < 4; i++)
5148 wcode[i] = be16_to_cpu(fwcode[i + 4]);
5149 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
5150 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
5151 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005152 ql_log(ql_log_fatal, vha, 0x0086,
5153 "Unable to verify integrity of firmware image.\n");
5154 ql_log(ql_log_fatal, vha, 0x0087,
5155 "Firmware data: %04x %04x %04x %04x.\n",
5156 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08005157 goto fail_fw_integrity;
5158 }
5159
5160 seg = blob->segs;
5161 while (*seg && rval == QLA_SUCCESS) {
5162 risc_addr = *seg;
5163 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
5164 risc_size = be16_to_cpu(fwcode[3]);
5165
5166 /* Validate firmware image size. */
5167 fwclen += risc_size * sizeof(uint16_t);
5168 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005169 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08005170 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005171 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08005172 goto fail_fw_integrity;
5173 }
5174
5175 fragment = 0;
5176 while (risc_size > 0 && rval == QLA_SUCCESS) {
5177 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
5178 if (wlen > risc_size)
5179 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005180 ql_dbg(ql_dbg_init, vha, 0x0089,
5181 "Loading risc segment@ risc addr %x number of "
5182 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08005183
5184 for (i = 0; i < wlen; i++)
5185 wcode[i] = swab16(fwcode[i]);
5186
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005187 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08005188 wlen);
5189 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005190 ql_log(ql_log_fatal, vha, 0x008a,
5191 "Failed to load segment %d of firmware.\n",
5192 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08005193 break;
5194 }
5195
5196 fwcode += wlen;
5197 risc_addr += wlen;
5198 risc_size -= wlen;
5199 fragment++;
5200 }
5201
5202 /* Next segment. */
5203 seg++;
5204 }
5205 return rval;
5206
5207fail_fw_integrity:
5208 return QLA_FUNCTION_FAILED;
5209}
5210
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005211static int
5212qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005213{
5214 int rval;
5215 int segments, fragment;
5216 uint32_t *dcode, dlen;
5217 uint32_t risc_addr;
5218 uint32_t risc_size;
5219 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08005220 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005221 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005222 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005223 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005224
Andrew Vasquez54333832005-11-09 15:49:04 -08005225 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005226 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005227 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005228 ql_log(ql_log_warn, vha, 0x0090,
5229 "Fimware image unavailable.\n");
5230 ql_log(ql_log_warn, vha, 0x0091,
5231 "Firmware images can be retrieved from: "
5232 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005233
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005234 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005235 }
5236
Chad Dupuiscfb09192011-11-18 09:03:07 -08005237 ql_dbg(ql_dbg_init, vha, 0x0092,
5238 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005239
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005240 rval = QLA_SUCCESS;
5241
5242 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005243 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005244 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08005245 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005246 fwclen = 0;
5247
5248 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08005249 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005250 ql_log(ql_log_fatal, vha, 0x0093,
5251 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005252 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005253 goto fail_fw_integrity;
5254 }
5255 for (i = 0; i < 4; i++)
5256 dcode[i] = be32_to_cpu(fwcode[i + 4]);
5257 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5258 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5259 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5260 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005261 ql_log(ql_log_fatal, vha, 0x0094,
5262 "Unable to verify integrity of firmware image (%Zd).\n",
5263 blob->fw->size);
5264 ql_log(ql_log_fatal, vha, 0x0095,
5265 "Firmware data: %08x %08x %08x %08x.\n",
5266 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005267 goto fail_fw_integrity;
5268 }
5269
5270 while (segments && rval == QLA_SUCCESS) {
5271 risc_addr = be32_to_cpu(fwcode[2]);
5272 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5273 risc_size = be32_to_cpu(fwcode[3]);
5274
5275 /* Validate firmware image size. */
5276 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08005277 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005278 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08005279 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005280 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08005281
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005282 goto fail_fw_integrity;
5283 }
5284
5285 fragment = 0;
5286 while (risc_size > 0 && rval == QLA_SUCCESS) {
5287 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5288 if (dlen > risc_size)
5289 dlen = risc_size;
5290
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005291 ql_dbg(ql_dbg_init, vha, 0x0097,
5292 "Loading risc segment@ risc addr %x "
5293 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005294
5295 for (i = 0; i < dlen; i++)
5296 dcode[i] = swab32(fwcode[i]);
5297
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005298 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08005299 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005300 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005301 ql_log(ql_log_fatal, vha, 0x0098,
5302 "Failed to load segment %d of firmware.\n",
5303 fragment);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005304 break;
5305 }
5306
5307 fwcode += dlen;
5308 risc_addr += dlen;
5309 risc_size -= dlen;
5310 fragment++;
5311 }
5312
5313 /* Next segment. */
5314 segments--;
5315 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005316 return rval;
5317
5318fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005319 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005320}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005321
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005322int
5323qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5324{
5325 int rval;
5326
Andrew Vasqueze337d902009-04-06 22:33:49 -07005327 if (ql2xfwloadbin == 1)
5328 return qla81xx_load_risc(vha, srisc_addr);
5329
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005330 /*
5331 * FW Load priority:
5332 * 1) Firmware via request-firmware interface (.bin file).
5333 * 2) Firmware residing in flash.
5334 */
5335 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5336 if (rval == QLA_SUCCESS)
5337 return rval;
5338
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005339 return qla24xx_load_risc_flash(vha, srisc_addr,
5340 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005341}
5342
5343int
5344qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5345{
5346 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005347 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005348
Andrew Vasqueze337d902009-04-06 22:33:49 -07005349 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005350 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07005351
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005352 /*
5353 * FW Load priority:
5354 * 1) Firmware residing in flash.
5355 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005356 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005357 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005358 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005359 if (rval == QLA_SUCCESS)
5360 return rval;
5361
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005362try_blob_fw:
5363 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5364 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
5365 return rval;
5366
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005367 ql_log(ql_log_info, vha, 0x0099,
5368 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005369 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
5370 if (rval != QLA_SUCCESS)
5371 return rval;
5372
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005373 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005374 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005375 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005376}
5377
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005378void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005379qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005380{
5381 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005382 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005383
Andrew Vasquez85880802009-12-15 21:29:46 -08005384 if (ha->flags.pci_channel_io_perm_failure)
5385 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07005386 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005387 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07005388 if (!ha->fw_major_version)
5389 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005390
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005391 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08005392 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07005393 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005394 ha->isp_ops->reset_chip(vha);
5395 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005396 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005397 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005398 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005399 ql_log(ql_log_info, vha, 0x8015,
5400 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005401 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005402 }
5403}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005404
5405int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005406qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005407{
5408 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08005409 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005410 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005411 struct qla_hw_data *ha = vha->hw;
5412 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005413 struct req_que *req;
5414 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005415
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005416 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005417 return -EINVAL;
5418
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005419 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07005420 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005421 req = ha->req_q_map[0];
5422 else
5423 req = vha->req;
5424 rsp = req->rsp;
5425
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005426 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005427 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005428 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005429 }
5430
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005431 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005432
5433 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08005434 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
5435 BIT_1);
5436 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5437 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
5438 ql_dbg(ql_dbg_init, vha, 0x0120,
5439 "Failed SNS login: loop_id=%x, rval2=%d\n",
5440 NPH_SNS, rval2);
5441 else
5442 ql_dbg(ql_dbg_init, vha, 0x0103,
5443 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5444 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
5445 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005446 return (QLA_FUNCTION_FAILED);
5447 }
5448
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005449 atomic_set(&vha->loop_down_timer, 0);
5450 atomic_set(&vha->loop_state, LOOP_UP);
5451 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5452 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5453 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005454
5455 return rval;
5456}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005457
5458/* 84XX Support **************************************************************/
5459
5460static LIST_HEAD(qla_cs84xx_list);
5461static DEFINE_MUTEX(qla_cs84xx_mutex);
5462
5463static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005464qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005465{
5466 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005467 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005468
5469 mutex_lock(&qla_cs84xx_mutex);
5470
5471 /* Find any shared 84xx chip. */
5472 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5473 if (cs84xx->bus == ha->pdev->bus) {
5474 kref_get(&cs84xx->kref);
5475 goto done;
5476 }
5477 }
5478
5479 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5480 if (!cs84xx)
5481 goto done;
5482
5483 kref_init(&cs84xx->kref);
5484 spin_lock_init(&cs84xx->access_lock);
5485 mutex_init(&cs84xx->fw_update_mutex);
5486 cs84xx->bus = ha->pdev->bus;
5487
5488 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5489done:
5490 mutex_unlock(&qla_cs84xx_mutex);
5491 return cs84xx;
5492}
5493
5494static void
5495__qla84xx_chip_release(struct kref *kref)
5496{
5497 struct qla_chip_state_84xx *cs84xx =
5498 container_of(kref, struct qla_chip_state_84xx, kref);
5499
5500 mutex_lock(&qla_cs84xx_mutex);
5501 list_del(&cs84xx->list);
5502 mutex_unlock(&qla_cs84xx_mutex);
5503 kfree(cs84xx);
5504}
5505
5506void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005507qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005508{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005509 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005510 if (ha->cs84xx)
5511 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
5512}
5513
5514static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005515qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005516{
5517 int rval;
5518 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005519 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005520
5521 mutex_lock(&ha->cs84xx->fw_update_mutex);
5522
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005523 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005524
5525 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5526
5527 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5528 QLA_SUCCESS;
5529}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005530
5531/* 81XX Support **************************************************************/
5532
5533int
5534qla81xx_nvram_config(scsi_qla_host_t *vha)
5535{
5536 int rval;
5537 struct init_cb_81xx *icb;
5538 struct nvram_81xx *nv;
5539 uint32_t *dptr;
5540 uint8_t *dptr1, *dptr2;
5541 uint32_t chksum;
5542 uint16_t cnt;
5543 struct qla_hw_data *ha = vha->hw;
5544
5545 rval = QLA_SUCCESS;
5546 icb = (struct init_cb_81xx *)ha->init_cb;
5547 nv = ha->nvram;
5548
5549 /* Determine NVRAM starting address. */
5550 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005551 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005552
5553 /* Get VPD data into cache */
5554 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005555 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5556 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005557
5558 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005559 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005560 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005561 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005562 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5563 chksum += le32_to_cpu(*dptr++);
5564
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005565 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
5566 "Contents of NVRAM:\n");
5567 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
5568 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005569
5570 /* Bad NVRAM data, set defaults parameters. */
5571 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5572 || nv->id[3] != ' ' ||
5573 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5574 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005575 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04005576 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005577 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005578 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005579 ql_log(ql_log_info, vha, 0x0074,
5580 "Falling back to functioning (yet invalid -- WWPN) "
5581 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005582
5583 /*
5584 * Set default initialization control block.
5585 */
5586 memset(nv, 0, ha->nvram_size);
5587 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5588 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5589 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5590 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5591 nv->exchange_count = __constant_cpu_to_le16(0);
5592 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005593 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005594 nv->port_name[2] = 0x00;
5595 nv->port_name[3] = 0xe0;
5596 nv->port_name[4] = 0x8b;
5597 nv->port_name[5] = 0x1c;
5598 nv->port_name[6] = 0x55;
5599 nv->port_name[7] = 0x86;
5600 nv->node_name[0] = 0x20;
5601 nv->node_name[1] = 0x00;
5602 nv->node_name[2] = 0x00;
5603 nv->node_name[3] = 0xe0;
5604 nv->node_name[4] = 0x8b;
5605 nv->node_name[5] = 0x1c;
5606 nv->node_name[6] = 0x55;
5607 nv->node_name[7] = 0x86;
5608 nv->login_retry_count = __constant_cpu_to_le16(8);
5609 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5610 nv->login_timeout = __constant_cpu_to_le16(0);
5611 nv->firmware_options_1 =
5612 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5613 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5614 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5615 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5616 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5617 nv->efi_parameters = __constant_cpu_to_le32(0);
5618 nv->reset_delay = 5;
5619 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5620 nv->port_down_retry_count = __constant_cpu_to_le16(30);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005621 nv->link_down_timeout = __constant_cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005622 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005623 nv->enode_mac[1] = 0xC0;
5624 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005625 nv->enode_mac[3] = 0x04;
5626 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005627 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005628
5629 rval = 1;
5630 }
5631
Arun Easi9e522cd2012-08-22 14:21:31 -04005632 if (IS_T10_PI_CAPABLE(ha))
5633 nv->frame_payload_size &= ~7;
5634
Arun Easiaa230bc2013-01-30 03:34:39 -05005635 qlt_81xx_config_nvram_stage1(vha, nv);
5636
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005637 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07005638 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005639
5640 /* Copy 1st segment. */
5641 dptr1 = (uint8_t *)icb;
5642 dptr2 = (uint8_t *)&nv->version;
5643 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5644 while (cnt--)
5645 *dptr1++ = *dptr2++;
5646
5647 icb->login_retry_count = nv->login_retry_count;
5648
5649 /* Copy 2nd segment. */
5650 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5651 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5652 cnt = (uint8_t *)&icb->reserved_5 -
5653 (uint8_t *)&icb->interrupt_delay_timer;
5654 while (cnt--)
5655 *dptr1++ = *dptr2++;
5656
5657 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5658 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5659 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08005660 icb->enode_mac[0] = 0x00;
5661 icb->enode_mac[1] = 0xC0;
5662 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005663 icb->enode_mac[3] = 0x04;
5664 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005665 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005666 }
5667
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005668 /* Use extended-initialization control block. */
5669 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5670
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005671 /*
5672 * Setup driver NVRAM options.
5673 */
5674 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005675 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005676
Arun Easiaa230bc2013-01-30 03:34:39 -05005677 qlt_81xx_config_nvram_stage2(vha, icb);
5678
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005679 /* Use alternate WWN? */
5680 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5681 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5682 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5683 }
5684
5685 /* Prepare nodename */
5686 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5687 /*
5688 * Firmware will apply the following mask if the nodename was
5689 * not provided.
5690 */
5691 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5692 icb->node_name[0] &= 0xF0;
5693 }
5694
5695 /* Set host adapter parameters. */
5696 ha->flags.disable_risc_code_load = 0;
5697 ha->flags.enable_lip_reset = 0;
5698 ha->flags.enable_lip_full_login =
5699 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5700 ha->flags.enable_target_reset =
5701 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5702 ha->flags.enable_led_scheme = 0;
5703 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5704
5705 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5706 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5707
5708 /* save HBA serial number */
5709 ha->serial0 = icb->port_name[5];
5710 ha->serial1 = icb->port_name[6];
5711 ha->serial2 = icb->port_name[7];
5712 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5713 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5714
5715 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5716
5717 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5718
5719 /* Set minimum login_timeout to 4 seconds. */
5720 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5721 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5722 if (le16_to_cpu(nv->login_timeout) < 4)
5723 nv->login_timeout = __constant_cpu_to_le16(4);
5724 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5725 icb->login_timeout = nv->login_timeout;
5726
5727 /* Set minimum RATOV to 100 tenths of a second. */
5728 ha->r_a_tov = 100;
5729
5730 ha->loop_reset_delay = nv->reset_delay;
5731
5732 /* Link Down Timeout = 0:
5733 *
5734 * When Port Down timer expires we will start returning
5735 * I/O's to OS with "DID_NO_CONNECT".
5736 *
5737 * Link Down Timeout != 0:
5738 *
5739 * The driver waits for the link to come up after link down
5740 * before returning I/Os to OS with "DID_NO_CONNECT".
5741 */
5742 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5743 ha->loop_down_abort_time =
5744 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5745 } else {
5746 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5747 ha->loop_down_abort_time =
5748 (LOOP_DOWN_TIME - ha->link_down_timeout);
5749 }
5750
5751 /* Need enough time to try and get the port back. */
5752 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5753 if (qlport_down_retry)
5754 ha->port_down_retry_count = qlport_down_retry;
5755
5756 /* Set login_retry_count */
5757 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5758 if (ha->port_down_retry_count ==
5759 le16_to_cpu(nv->port_down_retry_count) &&
5760 ha->port_down_retry_count > 3)
5761 ha->login_retry_count = ha->port_down_retry_count;
5762 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5763 ha->login_retry_count = ha->port_down_retry_count;
5764 if (ql2xloginretrycount)
5765 ha->login_retry_count = ql2xloginretrycount;
5766
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005767 /* if not running MSI-X we need handshaking on interrupts */
5768 if (!vha->hw->flags.msix_enabled && IS_QLA83XX(ha))
5769 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
5770
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005771 /* Enable ZIO. */
5772 if (!vha->flags.init_done) {
5773 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5774 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5775 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5776 le16_to_cpu(icb->interrupt_delay_timer): 2;
5777 }
5778 icb->firmware_options_2 &= __constant_cpu_to_le32(
5779 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5780 vha->flags.process_response_queue = 0;
5781 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5782 ha->zio_mode = QLA_ZIO_MODE_6;
5783
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005784 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005785 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005786 ha->zio_mode,
5787 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005788
5789 icb->firmware_options_2 |= cpu_to_le32(
5790 (uint32_t)ha->zio_mode);
5791 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5792 vha->flags.process_response_queue = 1;
5793 }
5794
5795 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005796 ql_log(ql_log_warn, vha, 0x0076,
5797 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005798 }
5799 return (rval);
5800}
5801
Giridhar Malavalia9083012010-04-12 17:59:55 -07005802int
5803qla82xx_restart_isp(scsi_qla_host_t *vha)
5804{
5805 int status, rval;
5806 uint32_t wait_time;
5807 struct qla_hw_data *ha = vha->hw;
5808 struct req_que *req = ha->req_q_map[0];
5809 struct rsp_que *rsp = ha->rsp_q_map[0];
5810 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005811 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005812
5813 status = qla2x00_init_rings(vha);
5814 if (!status) {
5815 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5816 ha->flags.chip_reset_done = 1;
5817
5818 status = qla2x00_fw_ready(vha);
5819 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005820 ql_log(ql_log_info, vha, 0x803c,
5821 "Start configure loop, status =%d.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005822
5823 /* Issue a marker after FW becomes ready. */
5824 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5825
5826 vha->flags.online = 1;
5827 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5828 wait_time = 256;
5829 do {
5830 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5831 qla2x00_configure_loop(vha);
5832 wait_time--;
5833 } while (!atomic_read(&vha->loop_down_timer) &&
5834 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5835 wait_time &&
5836 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5837 }
5838
5839 /* if no cable then assume it's good */
5840 if ((vha->device_flags & DFLG_NO_CABLE))
5841 status = 0;
5842
Chad Dupuiscfb09192011-11-18 09:03:07 -08005843 ql_log(ql_log_info, vha, 0x8000,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005844 "Configure loop done, status = 0x%x.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005845 }
5846
5847 if (!status) {
5848 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5849
5850 if (!atomic_read(&vha->loop_down_timer)) {
5851 /*
5852 * Issue marker command only when we are going
5853 * to start the I/O .
5854 */
5855 vha->marker_needed = 1;
5856 }
5857
5858 vha->flags.online = 1;
5859
5860 ha->isp_ops->enable_intrs(ha);
5861
5862 ha->isp_abort_cnt = 0;
5863 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5864
Saurav Kashyap53296782011-05-10 11:30:06 -07005865 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07005866 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07005867
Giridhar Malavalia9083012010-04-12 17:59:55 -07005868 if (ha->fce) {
5869 ha->flags.fce_enabled = 1;
5870 memset(ha->fce, 0,
5871 fce_calc_size(ha->fce_bufs));
5872 rval = qla2x00_enable_fce_trace(vha,
5873 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5874 &ha->fce_bufs);
5875 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005876 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005877 "Unable to reinitialize FCE (%d).\n",
5878 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005879 ha->flags.fce_enabled = 0;
5880 }
5881 }
5882
5883 if (ha->eft) {
5884 memset(ha->eft, 0, EFT_SIZE);
5885 rval = qla2x00_enable_eft_trace(vha,
5886 ha->eft_dma, EFT_NUM_BUFFERS);
5887 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005888 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005889 "Unable to reinitialize EFT (%d).\n",
5890 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005891 }
5892 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005893 }
5894
5895 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005896 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005897 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07005898
5899 spin_lock_irqsave(&ha->vport_slock, flags);
5900 list_for_each_entry(vp, &ha->vp_list, list) {
5901 if (vp->vp_idx) {
5902 atomic_inc(&vp->vref_count);
5903 spin_unlock_irqrestore(&ha->vport_slock, flags);
5904
Giridhar Malavalia9083012010-04-12 17:59:55 -07005905 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07005906
5907 spin_lock_irqsave(&ha->vport_slock, flags);
5908 atomic_dec(&vp->vref_count);
5909 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005910 }
Arun Easifeafb7b2010-09-03 14:57:00 -07005911 spin_unlock_irqrestore(&ha->vport_slock, flags);
5912
Giridhar Malavalia9083012010-04-12 17:59:55 -07005913 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005914 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005915 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005916 }
5917
5918 return status;
5919}
5920
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005921void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005922qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005923{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005924 struct qla_hw_data *ha = vha->hw;
5925
5926 if (!ql2xetsenable)
5927 return;
5928
5929 /* Enable ETS Burst. */
5930 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5931 ha->fw_options[2] |= BIT_9;
5932 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005933}
Sarang Radke09ff7012010-03-19 17:03:59 -07005934
5935/*
5936 * qla24xx_get_fcp_prio
5937 * Gets the fcp cmd priority value for the logged in port.
5938 * Looks for a match of the port descriptors within
5939 * each of the fcp prio config entries. If a match is found,
5940 * the tag (priority) value is returned.
5941 *
5942 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005943 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005944 * fcport = port structure pointer.
5945 *
5946 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005947 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005948 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005949 *
5950 * Context:
5951 * Kernel context
5952 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005953static int
Sarang Radke09ff7012010-03-19 17:03:59 -07005954qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5955{
5956 int i, entries;
5957 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005958 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005959 uint32_t pid1, pid2;
5960 uint64_t wwn1, wwn2;
5961 struct qla_fcp_prio_entry *pri_entry;
5962 struct qla_hw_data *ha = vha->hw;
5963
5964 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005965 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005966
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005967 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005968 entries = ha->fcp_prio_cfg->num_entries;
5969 pri_entry = &ha->fcp_prio_cfg->entry[0];
5970
5971 for (i = 0; i < entries; i++) {
5972 pid_match = wwn_match = 0;
5973
5974 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5975 pri_entry++;
5976 continue;
5977 }
5978
5979 /* check source pid for a match */
5980 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5981 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5982 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5983 if (pid1 == INVALID_PORT_ID)
5984 pid_match++;
5985 else if (pid1 == pid2)
5986 pid_match++;
5987 }
5988
5989 /* check destination pid for a match */
5990 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5991 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5992 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5993 if (pid1 == INVALID_PORT_ID)
5994 pid_match++;
5995 else if (pid1 == pid2)
5996 pid_match++;
5997 }
5998
5999 /* check source WWN for a match */
6000 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
6001 wwn1 = wwn_to_u64(vha->port_name);
6002 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
6003 if (wwn2 == (uint64_t)-1)
6004 wwn_match++;
6005 else if (wwn1 == wwn2)
6006 wwn_match++;
6007 }
6008
6009 /* check destination WWN for a match */
6010 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
6011 wwn1 = wwn_to_u64(fcport->port_name);
6012 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
6013 if (wwn2 == (uint64_t)-1)
6014 wwn_match++;
6015 else if (wwn1 == wwn2)
6016 wwn_match++;
6017 }
6018
6019 if (pid_match == 2 || wwn_match == 2) {
6020 /* Found a matching entry */
6021 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
6022 priority = pri_entry->tag;
6023 break;
6024 }
6025
6026 pri_entry++;
6027 }
6028
6029 return priority;
6030}
6031
6032/*
6033 * qla24xx_update_fcport_fcp_prio
6034 * Activates fcp priority for the logged in fc port
6035 *
6036 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006037 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07006038 * fcp = port structure pointer.
6039 *
6040 * Return:
6041 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6042 *
6043 * Context:
6044 * Kernel context.
6045 */
6046int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006047qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07006048{
6049 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006050 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07006051 uint16_t mb[5];
6052
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006053 if (fcport->port_type != FCT_TARGET ||
6054 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07006055 return QLA_FUNCTION_FAILED;
6056
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006057 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006058 if (priority < 0)
6059 return QLA_FUNCTION_FAILED;
6060
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006061 if (IS_QLA82XX(vha->hw)) {
6062 fcport->fcp_prio = priority & 0xf;
6063 return QLA_SUCCESS;
6064 }
6065
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006066 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08006067 if (ret == QLA_SUCCESS) {
6068 if (fcport->fcp_prio != priority)
6069 ql_dbg(ql_dbg_user, vha, 0x709e,
6070 "Updated FCP_CMND priority - value=%d loop_id=%d "
6071 "port_id=%02x%02x%02x.\n", priority,
6072 fcport->loop_id, fcport->d_id.b.domain,
6073 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006074 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08006075 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006076 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006077 "Unable to update FCP_CMND priority - ret=0x%x for "
6078 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
6079 fcport->d_id.b.domain, fcport->d_id.b.area,
6080 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07006081 return ret;
6082}
6083
6084/*
6085 * qla24xx_update_all_fcp_prio
6086 * Activates fcp priority for all the logged in ports
6087 *
6088 * Input:
6089 * ha = adapter block pointer.
6090 *
6091 * Return:
6092 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6093 *
6094 * Context:
6095 * Kernel context.
6096 */
6097int
6098qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
6099{
6100 int ret;
6101 fc_port_t *fcport;
6102
6103 ret = QLA_FUNCTION_FAILED;
6104 /* We need to set priority for all logged in ports */
6105 list_for_each_entry(fcport, &vha->vp_fcports, list)
6106 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
6107
6108 return ret;
6109}