blob: 891b8f1c03e905c8105c465f00b752465f409fe4 [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
Joe Carnuccio3a117112013-02-08 01:58:00 -0500622 qla2x00_set_driver_version(vha, QLA2XXX_VERSION);
623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 return (rval);
625}
626
627/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700628 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 * @ha: HA context
630 *
631 * Returns 0 on success.
632 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700633int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800634qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700636 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700637 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800638 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700639 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700642 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700645 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
647
Andrew Vasquez737faec2008-10-24 15:13:45 -0700648 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700650 /* Get PCI bus information. */
651 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700652 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700653 spin_unlock_irqrestore(&ha->hardware_lock, flags);
654
655 return QLA_SUCCESS;
656}
657
658/**
659 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
660 * @ha: HA context
661 *
662 * Returns 0 on success.
663 */
664int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800665qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700666{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700667 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700668 unsigned long flags = 0;
669 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800670 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700671 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700672
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700673 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700674 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700675
676 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700677 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700678
679 if (IS_QLA2322(ha) || IS_QLA6322(ha))
680 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700681 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700682
683 /*
684 * If this is a 2300 card and not 2312, reset the
685 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
686 * the 2310 also reports itself as a 2300 so we need to get the
687 * fb revision level -- a 6 indicates it really is a 2300 and
688 * not a 2310.
689 */
690 if (IS_QLA2300(ha)) {
691 spin_lock_irqsave(&ha->hardware_lock, flags);
692
693 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700694 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700695 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700696 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700697 break;
698
699 udelay(10);
700 }
701
702 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700703 WRT_REG_WORD(&reg->ctrl_status, 0x20);
704 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700705
706 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700707 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700708
709 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700710 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700711
712 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700713 WRT_REG_WORD(&reg->ctrl_status, 0x0);
714 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700715
716 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700717 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700718 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700719 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700720 break;
721
722 udelay(10);
723 }
724
725 spin_unlock_irqrestore(&ha->hardware_lock, flags);
726 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700727
728 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
729
Andrew Vasquez737faec2008-10-24 15:13:45 -0700730 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700731
732 /* Get PCI bus information. */
733 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700734 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700735 spin_unlock_irqrestore(&ha->hardware_lock, flags);
736
737 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738}
739
740/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700741 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
742 * @ha: HA context
743 *
744 * Returns 0 on success.
745 */
746int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800747qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700748{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700749 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700750 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800751 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700752 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700753
754 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700755 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700756
757 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700758 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700759 w &= ~PCI_COMMAND_INTX_DISABLE;
760 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
761
762 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
763
764 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700765 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
766 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700767
768 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700769 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -0400770 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700771
Andrew Vasquez737faec2008-10-24 15:13:45 -0700772 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700773
Auke Kok44c10132007-06-08 15:46:36 -0700774 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800775
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700776 /* Get PCI bus information. */
777 spin_lock_irqsave(&ha->hardware_lock, flags);
778 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
779 spin_unlock_irqrestore(&ha->hardware_lock, flags);
780
781 return QLA_SUCCESS;
782}
783
784/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700785 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
786 * @ha: HA context
787 *
788 * Returns 0 on success.
789 */
790int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800791qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700792{
793 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800794 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700795
796 pci_set_master(ha->pdev);
797 pci_try_set_mwi(ha->pdev);
798
799 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
800 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
801 w &= ~PCI_COMMAND_INTX_DISABLE;
802 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
803
804 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700805 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -0400806 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700807
Andrew Vasquez737faec2008-10-24 15:13:45 -0700808 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700809
810 ha->chip_revision = ha->pdev->revision;
811
812 return QLA_SUCCESS;
813}
814
815/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 * qla2x00_isp_firmware() - Choose firmware image.
817 * @ha: HA context
818 *
819 * Returns 0 on success.
820 */
821static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800822qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
824 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700825 uint16_t loop_id, topo, sw_cap;
826 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800827 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
829 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700830 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
832 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700833 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
835 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800836 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700837 if (rval == QLA_SUCCESS) {
838 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800839 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700840 &area, &domain, &topo, &sw_cap);
841 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 }
843
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700844 if (rval)
845 ql_dbg(ql_dbg_init, vha, 0x007a,
846 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
848 return (rval);
849}
850
851/**
852 * qla2x00_reset_chip() - Reset ISP chip.
853 * @ha: HA context
854 *
855 * Returns 0 on success.
856 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700857void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800858qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
860 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800861 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700862 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 uint16_t cmd;
865
Andrew Vasquez85880802009-12-15 21:29:46 -0800866 if (unlikely(pci_channel_offline(ha->pdev)))
867 return;
868
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700869 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
871 spin_lock_irqsave(&ha->hardware_lock, flags);
872
873 /* Turn off master enable */
874 cmd = 0;
875 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
876 cmd &= ~PCI_COMMAND_MASTER;
877 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
878
879 if (!IS_QLA2100(ha)) {
880 /* Pause RISC. */
881 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
882 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
883 for (cnt = 0; cnt < 30000; cnt++) {
884 if ((RD_REG_WORD(&reg->hccr) &
885 HCCR_RISC_PAUSE) != 0)
886 break;
887 udelay(100);
888 }
889 } else {
890 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
891 udelay(10);
892 }
893
894 /* Select FPM registers. */
895 WRT_REG_WORD(&reg->ctrl_status, 0x20);
896 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
897
898 /* FPM Soft Reset. */
899 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
900 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
901
902 /* Toggle Fpm Reset. */
903 if (!IS_QLA2200(ha)) {
904 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
905 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
906 }
907
908 /* Select frame buffer registers. */
909 WRT_REG_WORD(&reg->ctrl_status, 0x10);
910 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
911
912 /* Reset frame buffer FIFOs. */
913 if (IS_QLA2200(ha)) {
914 WRT_FB_CMD_REG(ha, reg, 0xa000);
915 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
916 } else {
917 WRT_FB_CMD_REG(ha, reg, 0x00fc);
918
919 /* Read back fb_cmd until zero or 3 seconds max */
920 for (cnt = 0; cnt < 3000; cnt++) {
921 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
922 break;
923 udelay(100);
924 }
925 }
926
927 /* Select RISC module registers. */
928 WRT_REG_WORD(&reg->ctrl_status, 0);
929 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
930
931 /* Reset RISC processor. */
932 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
933 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
934
935 /* Release RISC processor. */
936 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
937 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
938 }
939
940 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
941 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
942
943 /* Reset ISP chip. */
944 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
945
946 /* Wait for RISC to recover from reset. */
947 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
948 /*
949 * It is necessary to for a delay here since the card doesn't
950 * respond to PCI reads during a reset. On some architectures
951 * this will result in an MCA.
952 */
953 udelay(20);
954 for (cnt = 30000; cnt; cnt--) {
955 if ((RD_REG_WORD(&reg->ctrl_status) &
956 CSR_ISP_SOFT_RESET) == 0)
957 break;
958 udelay(100);
959 }
960 } else
961 udelay(10);
962
963 /* Reset RISC processor. */
964 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
965
966 WRT_REG_WORD(&reg->semaphore, 0);
967
968 /* Release RISC processor. */
969 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
970 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
971
972 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
973 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700974 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 udelay(100);
978 }
979 } else
980 udelay(100);
981
982 /* Turn on master enable */
983 cmd |= PCI_COMMAND_MASTER;
984 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
985
986 /* Disable RISC pause on FPM parity error. */
987 if (!IS_QLA2100(ha)) {
988 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
989 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
990 }
991
992 spin_unlock_irqrestore(&ha->hardware_lock, flags);
993}
994
995/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700996 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
997 *
998 * Returns 0 on success.
999 */
Saurav Kashyapfa492632012-11-21 02:40:29 -05001000static int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001001qla81xx_reset_mpi(scsi_qla_host_t *vha)
1002{
1003 uint16_t mb[4] = {0x1010, 0, 1, 0};
1004
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001005 if (!IS_QLA81XX(vha->hw))
1006 return QLA_SUCCESS;
1007
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001008 return qla81xx_write_mpi_register(vha, mb);
1009}
1010
1011/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001012 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001013 * @ha: HA context
1014 *
1015 * Returns 0 on success.
1016 */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001017static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001018qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001019{
1020 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001021 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001022 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1023 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001024 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001025 static int abts_cnt; /* ISP abort retry counts */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001026
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001027 spin_lock_irqsave(&ha->hardware_lock, flags);
1028
1029 /* Reset RISC. */
1030 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1031 for (cnt = 0; cnt < 30000; cnt++) {
1032 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
1033 break;
1034
1035 udelay(10);
1036 }
1037
1038 WRT_REG_DWORD(&reg->ctrl_status,
1039 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001040 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001041
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001042 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001043 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001044 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1045 for (cnt = 10000 ; cnt && d2; cnt--) {
1046 udelay(5);
1047 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1048 barrier();
1049 }
1050
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001051 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001052 d2 = RD_REG_DWORD(&reg->ctrl_status);
1053 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1054 udelay(5);
1055 d2 = RD_REG_DWORD(&reg->ctrl_status);
1056 barrier();
1057 }
1058
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001059 /* If required, do an MPI FW reset now */
1060 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1061 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1062 if (++abts_cnt < 5) {
1063 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1064 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1065 } else {
1066 /*
1067 * We exhausted the ISP abort retries. We have to
1068 * set the board offline.
1069 */
1070 abts_cnt = 0;
1071 vha->flags.online = 0;
1072 }
1073 }
1074 }
1075
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001076 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1077 RD_REG_DWORD(&reg->hccr);
1078
1079 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1080 RD_REG_DWORD(&reg->hccr);
1081
1082 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1083 RD_REG_DWORD(&reg->hccr);
1084
1085 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1086 for (cnt = 6000000 ; cnt && d2; cnt--) {
1087 udelay(5);
1088 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1089 barrier();
1090 }
1091
1092 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001093
1094 if (IS_NOPOLLING_TYPE(ha))
1095 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001096}
1097
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001098static void
1099qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
1100{
1101 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1102
1103 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1104 *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
1105
1106}
1107
1108static void
1109qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
1110{
1111 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
1112
1113 WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
1114 WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
1115}
1116
1117static void
1118qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
1119{
1120 struct qla_hw_data *ha = vha->hw;
1121 uint32_t wd32 = 0;
1122 uint delta_msec = 100;
1123 uint elapsed_msec = 0;
1124 uint timeout_msec;
1125 ulong n;
1126
1127 if (!IS_QLA25XX(ha) && !IS_QLA2031(ha))
1128 return;
1129
1130attempt:
1131 timeout_msec = TIMEOUT_SEMAPHORE;
1132 n = timeout_msec / delta_msec;
1133 while (n--) {
1134 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
1135 qla25xx_read_risc_sema_reg(vha, &wd32);
1136 if (wd32 & RISC_SEMAPHORE)
1137 break;
1138 msleep(delta_msec);
1139 elapsed_msec += delta_msec;
1140 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1141 goto force;
1142 }
1143
1144 if (!(wd32 & RISC_SEMAPHORE))
1145 goto force;
1146
1147 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1148 goto acquired;
1149
1150 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
1151 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
1152 n = timeout_msec / delta_msec;
1153 while (n--) {
1154 qla25xx_read_risc_sema_reg(vha, &wd32);
1155 if (!(wd32 & RISC_SEMAPHORE_FORCE))
1156 break;
1157 msleep(delta_msec);
1158 elapsed_msec += delta_msec;
1159 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
1160 goto force;
1161 }
1162
1163 if (wd32 & RISC_SEMAPHORE_FORCE)
1164 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
1165
1166 goto attempt;
1167
1168force:
1169 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
1170
1171acquired:
1172 return;
1173}
1174
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001175/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001176 * qla24xx_reset_chip() - Reset ISP24xx chip.
1177 * @ha: HA context
1178 *
1179 * Returns 0 on success.
1180 */
1181void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001182qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001183{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001184 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001185
1186 if (pci_channel_offline(ha->pdev) &&
1187 ha->flags.pci_channel_io_perm_failure) {
1188 return;
1189 }
1190
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001191 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001192
Joe Carnuccio4ea2c9c2012-11-21 02:40:37 -05001193 qla25xx_manipulate_risc_semaphore(vha);
1194
Andrew Vasquez88c26662005-07-08 17:59:26 -07001195 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001196 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001197}
1198
1199/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 * qla2x00_chip_diag() - Test chip for proper operation.
1201 * @ha: HA context
1202 *
1203 * Returns 0 on success.
1204 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001205int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001206qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207{
1208 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001209 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001210 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 unsigned long flags = 0;
1212 uint16_t data;
1213 uint32_t cnt;
1214 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001215 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
1217 /* Assume a failed state */
1218 rval = QLA_FUNCTION_FAILED;
1219
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001220 ql_dbg(ql_dbg_init, vha, 0x007b,
1221 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
1223 spin_lock_irqsave(&ha->hardware_lock, flags);
1224
1225 /* Reset ISP chip. */
1226 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1227
1228 /*
1229 * We need to have a delay here since the card will not respond while
1230 * in reset causing an MCA on some architectures.
1231 */
1232 udelay(20);
1233 data = qla2x00_debounce_register(&reg->ctrl_status);
1234 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1235 udelay(5);
1236 data = RD_REG_WORD(&reg->ctrl_status);
1237 barrier();
1238 }
1239
1240 if (!cnt)
1241 goto chip_diag_failed;
1242
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001243 ql_dbg(ql_dbg_init, vha, 0x007c,
1244 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
1246 /* Reset RISC processor. */
1247 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1248 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1249
1250 /* Workaround for QLA2312 PCI parity error */
1251 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1252 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1253 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1254 udelay(5);
1255 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001256 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 }
1258 } else
1259 udelay(10);
1260
1261 if (!cnt)
1262 goto chip_diag_failed;
1263
1264 /* Check product ID of chip */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001265 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
1267 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1268 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1269 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1270 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1271 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1272 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001273 ql_log(ql_log_warn, vha, 0x0062,
1274 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1275 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
1277 goto chip_diag_failed;
1278 }
1279 ha->product_id[0] = mb[1];
1280 ha->product_id[1] = mb[2];
1281 ha->product_id[2] = mb[3];
1282 ha->product_id[3] = mb[4];
1283
1284 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001285 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1287 else
1288 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001289 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
1291 if (IS_QLA2200(ha) &&
1292 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1293 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001294 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001296 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 ha->fw_transfer_size = 128;
1298 }
1299
1300 /* Wrap Incoming Mailboxes Test. */
1301 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1302
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001303 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001304 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001305 if (rval)
1306 ql_log(ql_log_warn, vha, 0x0080,
1307 "Failed mailbox send register test.\n");
1308 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 /* Flag a successful rval */
1310 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 spin_lock_irqsave(&ha->hardware_lock, flags);
1312
1313chip_diag_failed:
1314 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001315 ql_log(ql_log_info, vha, 0x0081,
1316 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
1318 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1319
1320 return (rval);
1321}
1322
1323/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001324 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1325 * @ha: HA context
1326 *
1327 * Returns 0 on success.
1328 */
1329int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001330qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001331{
1332 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001333 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001334 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001335
Giridhar Malavalia9083012010-04-12 17:59:55 -07001336 if (IS_QLA82XX(ha))
1337 return QLA_SUCCESS;
1338
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001339 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001340
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001341 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001342 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001343 ql_log(ql_log_warn, vha, 0x0082,
1344 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001345 } else {
1346 /* Flag a successful rval */
1347 rval = QLA_SUCCESS;
1348 }
1349
1350 return rval;
1351}
1352
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001353void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001354qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001355{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001356 int rval;
1357 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001358 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001359 dma_addr_t tc_dma;
1360 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001361 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001362 struct req_que *req = ha->req_q_map[0];
1363 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001364
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001365 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001366 ql_dbg(ql_dbg_init, vha, 0x00bd,
1367 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001368 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001369 }
1370
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001371 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001372 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001373 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1374 fixed_size = sizeof(struct qla2100_fw_dump);
1375 } else if (IS_QLA23XX(ha)) {
1376 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1377 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1378 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001379 } else if (IS_FWI2_CAPABLE(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001380 if (IS_QLA83XX(ha))
1381 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
1382 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001383 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1384 else if (IS_QLA25XX(ha))
1385 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1386 else
1387 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001388 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1389 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001390 if (ha->mqenable) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001391 if (!IS_QLA83XX(ha))
1392 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001393 /*
1394 * Allocate maximum buffer size for all queues.
1395 * Resizing must be done at end-of-dump processing.
1396 */
1397 mq_size += ha->max_req_queues *
1398 (req->length * sizeof(request_t));
1399 mq_size += ha->max_rsp_queues *
1400 (rsp->length * sizeof(response_t));
1401 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001402 if (ha->tgt.atio_q_length)
1403 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001404 /* Allocate memory for Fibre Channel Event Buffer. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001405 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001406 goto try_eft;
1407
1408 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1409 GFP_KERNEL);
1410 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001411 ql_log(ql_log_warn, vha, 0x00be,
1412 "Unable to allocate (%d KB) for FCE.\n",
1413 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001414 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001415 }
1416
1417 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001418 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001419 ha->fce_mb, &ha->fce_bufs);
1420 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001421 ql_log(ql_log_warn, vha, 0x00bf,
1422 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001423 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1424 tc_dma);
1425 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001426 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001427 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001428 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001429 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001430
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001431 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001432 ha->flags.fce_enabled = 1;
1433 ha->fce_dma = tc_dma;
1434 ha->fce = tc;
1435try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001436 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001437 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001438 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001439 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001440 ql_log(ql_log_warn, vha, 0x00c1,
1441 "Unable to allocate (%d KB) for EFT.\n",
1442 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001443 goto cont_alloc;
1444 }
1445
Andrew Vasquezfc447652008-01-17 09:02:18 -08001446 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001447 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001448 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001449 ql_log(ql_log_warn, vha, 0x00c2,
1450 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001451 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1452 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001453 goto cont_alloc;
1454 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001455 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001456 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001457
1458 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001459 ha->eft_dma = tc_dma;
1460 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001461 }
1462cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001463 req_q_size = req->length * sizeof(request_t);
1464 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001465
1466 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001467 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001468 ha->chain_offset = dump_size;
1469 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001470
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001471 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001472 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001473 ql_log(ql_log_warn, vha, 0x00c4,
1474 "Unable to allocate (%d KB) for firmware dump.\n",
1475 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001476
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001477 if (ha->fce) {
1478 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1479 ha->fce_dma);
1480 ha->fce = NULL;
1481 ha->fce_dma = 0;
1482 }
1483
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001484 if (ha->eft) {
1485 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1486 ha->eft_dma);
1487 ha->eft = NULL;
1488 ha->eft_dma = 0;
1489 }
1490 return;
1491 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001492 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001493 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001494
1495 ha->fw_dump_len = dump_size;
1496 ha->fw_dump->signature[0] = 'Q';
1497 ha->fw_dump->signature[1] = 'L';
1498 ha->fw_dump->signature[2] = 'G';
1499 ha->fw_dump->signature[3] = 'C';
1500 ha->fw_dump->version = __constant_htonl(1);
1501
1502 ha->fw_dump->fixed_size = htonl(fixed_size);
1503 ha->fw_dump->mem_size = htonl(mem_size);
1504 ha->fw_dump->req_q_size = htonl(req_q_size);
1505 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1506
1507 ha->fw_dump->eft_size = htonl(eft_size);
1508 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1509 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1510
1511 ha->fw_dump->header_size =
1512 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001513}
1514
Andrew Vasquez18e75552009-06-03 09:55:30 -07001515static int
1516qla81xx_mpi_sync(scsi_qla_host_t *vha)
1517{
1518#define MPS_MASK 0xe0
1519 int rval;
1520 uint16_t dc;
1521 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07001522
1523 if (!IS_QLA81XX(vha->hw))
1524 return QLA_SUCCESS;
1525
1526 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1527 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001528 ql_log(ql_log_warn, vha, 0x0105,
1529 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001530 goto done;
1531 }
1532
1533 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1534 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1535 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001536 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001537 goto done_release;
1538 }
1539
1540 dc &= MPS_MASK;
1541 if (dc == (dw & MPS_MASK))
1542 goto done_release;
1543
1544 dw &= ~MPS_MASK;
1545 dw |= dc;
1546 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1547 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001548 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001549 }
1550
1551done_release:
1552 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1553 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001554 ql_log(ql_log_warn, vha, 0x006d,
1555 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001556 }
1557
1558done:
1559 return rval;
1560}
1561
Chad Dupuis8d93f552013-01-30 03:34:37 -05001562int
1563qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
1564{
1565 /* Don't try to reallocate the array */
1566 if (req->outstanding_cmds)
1567 return QLA_SUCCESS;
1568
1569 if (!IS_FWI2_CAPABLE(ha) || (ha->mqiobase &&
1570 (ql2xmultique_tag || ql2xmaxqueues > 1)))
1571 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
1572 else {
1573 if (ha->fw_xcb_count <= ha->fw_iocb_count)
1574 req->num_outstanding_cmds = ha->fw_xcb_count;
1575 else
1576 req->num_outstanding_cmds = ha->fw_iocb_count;
1577 }
1578
1579 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1580 req->num_outstanding_cmds, GFP_KERNEL);
1581
1582 if (!req->outstanding_cmds) {
1583 /*
1584 * Try to allocate a minimal size just so we can get through
1585 * initialization.
1586 */
1587 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
1588 req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
1589 req->num_outstanding_cmds, GFP_KERNEL);
1590
1591 if (!req->outstanding_cmds) {
1592 ql_log(ql_log_fatal, NULL, 0x0126,
1593 "Failed to allocate memory for "
1594 "outstanding_cmds for req_que %p.\n", req);
1595 req->num_outstanding_cmds = 0;
1596 return QLA_FUNCTION_FAILED;
1597 }
1598 }
1599
1600 return QLA_SUCCESS;
1601}
1602
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001603/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 * qla2x00_setup_chip() - Load and start RISC firmware.
1605 * @ha: HA context
1606 *
1607 * Returns 0 on success.
1608 */
1609static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001610qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001612 int rval;
1613 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001614 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001615 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1616 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001617 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001618
Giridhar Malavalia9083012010-04-12 17:59:55 -07001619 if (IS_QLA82XX(ha)) {
1620 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001621 if (rval == QLA_SUCCESS) {
1622 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001623 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001624 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001625 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001626 }
1627
Andrew Vasquez3db06522008-01-31 12:33:49 -08001628 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1629 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1630 spin_lock_irqsave(&ha->hardware_lock, flags);
1631 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1632 RD_REG_WORD(&reg->hccr);
1633 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1634 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635
Andrew Vasquez18e75552009-06-03 09:55:30 -07001636 qla81xx_mpi_sync(vha);
1637
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001639 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001640 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001641 ql_dbg(ql_dbg_init, vha, 0x00c9,
1642 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001644 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 if (rval == QLA_SUCCESS) {
1646 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001647 ql_dbg(ql_dbg_init, vha, 0x00ca,
1648 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001650 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001652 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001653enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001654 fw_major_version = ha->fw_major_version;
Giridhar Malavali31731672011-08-16 11:31:54 -07001655 if (IS_QLA82XX(ha))
1656 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001657 else
1658 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001659 if (rval != QLA_SUCCESS)
1660 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001661 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001662 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001663 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001664 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001665 if ((!ha->max_npiv_vports) ||
1666 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001667 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001668 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001669 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001670 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001671 qla2x00_get_resource_cnts(vha, NULL,
Chad Dupuis8d93f552013-01-30 03:34:37 -05001672 &ha->fw_xcb_count, NULL, &ha->fw_iocb_count,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001673 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001674
Chad Dupuis8d93f552013-01-30 03:34:37 -05001675 /*
1676 * Allocate the array of outstanding commands
1677 * now that we know the firmware resources.
1678 */
1679 rval = qla2x00_alloc_outstanding_cmds(ha,
1680 vha->req);
1681 if (rval != QLA_SUCCESS)
1682 goto failed;
1683
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08001684 if (!fw_major_version && ql2xallocfwdump
1685 && !IS_QLA82XX(ha))
Giridhar Malavali08de2842011-08-16 11:31:44 -07001686 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 }
1688 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001689 ql_log(ql_log_fatal, vha, 0x00cd,
1690 "ISP Firmware failed checksum.\n");
1691 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04001693 } else
1694 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695
Andrew Vasquez3db06522008-01-31 12:33:49 -08001696 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1697 /* Enable proper parity. */
1698 spin_lock_irqsave(&ha->hardware_lock, flags);
1699 if (IS_QLA2300(ha))
1700 /* SRAM parity */
1701 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1702 else
1703 /* SRAM, Instruction RAM and GP RAM parity */
1704 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1705 RD_REG_WORD(&reg->hccr);
1706 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1707 }
1708
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001709 if (IS_QLA83XX(ha))
1710 goto skip_fac_check;
1711
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001712 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1713 uint32_t size;
1714
1715 rval = qla81xx_fac_get_sector_size(vha, &size);
1716 if (rval == QLA_SUCCESS) {
1717 ha->flags.fac_supported = 1;
1718 ha->fdt_block_size = size << 2;
1719 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001720 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001721 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1722 ha->fw_major_version, ha->fw_minor_version,
1723 ha->fw_subminor_version);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001724skip_fac_check:
1725 if (IS_QLA83XX(ha)) {
1726 ha->flags.fac_supported = 0;
1727 rval = QLA_SUCCESS;
1728 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001729 }
1730 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001731failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001733 ql_log(ql_log_fatal, vha, 0x00cf,
1734 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 }
1736
1737 return (rval);
1738}
1739
1740/**
1741 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1742 * @ha: HA context
1743 *
1744 * Beginning of request ring has initialization control block already built
1745 * by nvram config routine.
1746 *
1747 * Returns 0 on success.
1748 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001749void
1750qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751{
1752 uint16_t cnt;
1753 response_t *pkt;
1754
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001755 rsp->ring_ptr = rsp->ring;
1756 rsp->ring_index = 0;
1757 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001758 pkt = rsp->ring_ptr;
1759 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 pkt->signature = RESPONSE_PROCESSED;
1761 pkt++;
1762 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763}
1764
1765/**
1766 * qla2x00_update_fw_options() - Read and process firmware options.
1767 * @ha: HA context
1768 *
1769 * Returns 0 on success.
1770 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001771void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001772qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773{
1774 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001775 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776
1777 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001778 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
1780 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1781 return;
1782
1783 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001784 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1785 "Serial link options.\n");
1786 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1787 (uint8_t *)&ha->fw_seriallink_options,
1788 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
1790 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1791 if (ha->fw_seriallink_options[3] & BIT_2) {
1792 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1793
1794 /* 1G settings */
1795 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1796 emphasis = (ha->fw_seriallink_options[2] &
1797 (BIT_4 | BIT_3)) >> 3;
1798 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001799 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 rx_sens = (ha->fw_seriallink_options[0] &
1801 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1802 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1803 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1804 if (rx_sens == 0x0)
1805 rx_sens = 0x3;
1806 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1807 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1808 ha->fw_options[10] |= BIT_5 |
1809 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1810 (tx_sens & (BIT_1 | BIT_0));
1811
1812 /* 2G settings */
1813 swing = (ha->fw_seriallink_options[2] &
1814 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1815 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1816 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001817 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 rx_sens = (ha->fw_seriallink_options[1] &
1819 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1820 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1821 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1822 if (rx_sens == 0x0)
1823 rx_sens = 0x3;
1824 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1825 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1826 ha->fw_options[11] |= BIT_5 |
1827 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1828 (tx_sens & (BIT_1 | BIT_0));
1829 }
1830
1831 /* FCP2 options. */
1832 /* Return command IOCBs without waiting for an ABTS to complete. */
1833 ha->fw_options[3] |= BIT_13;
1834
1835 /* LED scheme. */
1836 if (ha->flags.enable_led_scheme)
1837 ha->fw_options[2] |= BIT_12;
1838
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001839 /* Detect ISP6312. */
1840 if (IS_QLA6312(ha))
1841 ha->fw_options[2] |= BIT_13;
1842
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001844 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845}
1846
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001847void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001848qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001849{
1850 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001851 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001852
Giridhar Malavalia9083012010-04-12 17:59:55 -07001853 if (IS_QLA82XX(ha))
1854 return;
1855
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001856 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001857 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001858 return;
1859
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001860 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001861 le16_to_cpu(ha->fw_seriallink_options24[1]),
1862 le16_to_cpu(ha->fw_seriallink_options24[2]),
1863 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001864 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001865 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001866 "Unable to update Serial Link options (%x).\n", rval);
1867 }
1868}
1869
1870void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001871qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001872{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001873 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001874 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001875 struct req_que *req = ha->req_q_map[0];
1876 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001877
1878 /* Setup ring parameters in initialization control block. */
1879 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1880 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001881 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1882 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1883 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1884 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1885 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1886 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001887
1888 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1889 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1890 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1891 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1892 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1893}
1894
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001895void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001896qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001897{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001898 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001899 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1900 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1901 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001902 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001903 uint16_t rid = 0;
1904 struct req_que *req = ha->req_q_map[0];
1905 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001906
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001907 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001908 icb = (struct init_cb_24xx *)ha->init_cb;
1909 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1910 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001911 icb->request_q_length = cpu_to_le16(req->length);
1912 icb->response_q_length = cpu_to_le16(rsp->length);
1913 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1914 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1915 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1916 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001917
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001918 /* Setup ATIO queue dma pointers for target mode */
1919 icb->atio_q_inpointer = __constant_cpu_to_le16(0);
1920 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
1921 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
1922 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
1923
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001924 if (ha->mqenable || IS_QLA83XX(ha)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001925 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1926 icb->rid = __constant_cpu_to_le16(rid);
1927 if (ha->flags.msix_enabled) {
1928 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001929 ql_dbg(ql_dbg_init, vha, 0x00fd,
1930 "Registering vector 0x%x for base que.\n",
1931 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001932 icb->msix = cpu_to_le16(msix->entry);
1933 }
1934 /* Use alternate PCI bus number */
1935 if (MSB(rid))
1936 icb->firmware_options_2 |=
1937 __constant_cpu_to_le32(BIT_19);
1938 /* Use alternate PCI devfn */
1939 if (LSB(rid))
1940 icb->firmware_options_2 |=
1941 __constant_cpu_to_le32(BIT_18);
1942
Anirban Chakraborty31557542009-12-02 10:36:55 -08001943 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001944 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
1945 (ha->flags.msix_enabled)) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08001946 icb->firmware_options_2 &=
1947 __constant_cpu_to_le32(~BIT_22);
1948 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001949 ql_dbg(ql_dbg_init, vha, 0x00fe,
1950 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08001951 } else {
1952 icb->firmware_options_2 |=
1953 __constant_cpu_to_le32(BIT_22);
1954 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001955 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001956
1957 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1958 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1959 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1960 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1961 } else {
1962 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1963 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1964 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1965 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1966 }
Arun Easiaa230bc2013-01-30 03:34:39 -05001967 qlt_24xx_config_rings(vha);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001968
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001969 /* PCI posting */
1970 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001971}
1972
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973/**
1974 * qla2x00_init_rings() - Initializes firmware.
1975 * @ha: HA context
1976 *
1977 * Beginning of request ring has initialization control block already built
1978 * by nvram config routine.
1979 *
1980 * Returns 0 on success.
1981 */
1982static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001983qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984{
1985 int rval;
1986 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001987 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001988 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001989 struct req_que *req;
1990 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001991 struct mid_init_cb_24xx *mid_init_cb =
1992 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
1994 spin_lock_irqsave(&ha->hardware_lock, flags);
1995
1996 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001997 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001998 req = ha->req_q_map[que];
1999 if (!req)
2000 continue;
Chad Dupuis8d93f552013-01-30 03:34:37 -05002001 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002002 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002004 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002005
2006 /* Initialize firmware. */
2007 req->ring_ptr = req->ring;
2008 req->ring_index = 0;
2009 req->cnt = req->length;
2010 }
2011
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002012 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002013 rsp = ha->rsp_q_map[que];
2014 if (!rsp)
2015 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08002016 /* Initialize response queue entries */
2017 qla2x00_init_response_q_entries(rsp);
2018 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002020 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
2021 ha->tgt.atio_ring_index = 0;
2022 /* Initialize ATIO queue entries */
2023 qlt_init_atio_q_entries(vha);
2024
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002025 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
2027 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2028
2029 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002030 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002032 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002033
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002034 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04002035 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002036 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08002037 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08002038 }
2039
Andrew Vasquez24a08132009-03-24 09:08:16 -07002040 if (IS_FWI2_CAPABLE(ha)) {
2041 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
2042 mid_init_cb->init_cb.execution_throttle =
2043 cpu_to_le16(ha->fw_xcb_count);
2044 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002045
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002046 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002048 ql_log(ql_log_fatal, vha, 0x00d2,
2049 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002051 ql_dbg(ql_dbg_init, vha, 0x00d3,
2052 "Init Firmware -- success.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 }
2054
2055 return (rval);
2056}
2057
2058/**
2059 * qla2x00_fw_ready() - Waits for firmware ready.
2060 * @ha: HA context
2061 *
2062 * Returns 0 on success.
2063 */
2064static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002065qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066{
2067 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002068 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 uint16_t min_wait; /* Minimum wait time if loop is down */
2070 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07002071 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002072 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073
2074 rval = QLA_SUCCESS;
2075
2076 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002077 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078
2079 /*
2080 * Firmware should take at most one RATOV to login, plus 5 seconds for
2081 * our own processing.
2082 */
2083 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
2084 wait_time = min_wait;
2085 }
2086
2087 /* Min wait time if loop down */
2088 mtime = jiffies + (min_wait * HZ);
2089
2090 /* wait time before firmware ready */
2091 wtime = jiffies + (wait_time * HZ);
2092
2093 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002094 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002095 ql_log(ql_log_info, vha, 0x801e,
2096 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097
2098 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05002099 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002100 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002102 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002103 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002105 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002106 ql_dbg(ql_dbg_taskm, vha, 0x801f,
2107 "fw_state=%x 84xx=%x.\n", state[0],
2108 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002109 if ((state[2] & FSTATE_LOGGED_IN) &&
2110 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002111 ql_dbg(ql_dbg_taskm, vha, 0x8028,
2112 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002113
2114 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002115 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002116 if (rval != QLA_SUCCESS) {
2117 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08002118 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002119 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002120 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002121 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002122
2123 /* Add time taken to initialize. */
2124 cs84xx_time = jiffies - cs84xx_time;
2125 wtime += cs84xx_time;
2126 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002127 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002128 "Increasing wait time by %ld. "
2129 "New time %ld.\n", cs84xx_time,
2130 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002131 }
2132 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002133 ql_dbg(ql_dbg_taskm, vha, 0x8037,
2134 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002136 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 &ha->login_timeout, &ha->r_a_tov);
2138
2139 rval = QLA_SUCCESS;
2140 break;
2141 }
2142
2143 rval = QLA_FUNCTION_FAILED;
2144
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002145 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002146 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002148 * other than Wait for Login.
2149 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002151 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 "Cable is unplugged...\n");
2153
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002154 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 break;
2156 }
2157 }
2158 } else {
2159 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07002160 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08002161 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 break;
2163 }
2164
2165 if (time_after_eq(jiffies, wtime))
2166 break;
2167
2168 /* Delay for a while */
2169 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 } while (1);
2171
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002172 ql_dbg(ql_dbg_taskm, vha, 0x803a,
2173 "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0],
2174 state[1], state[2], state[3], state[4], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
Chad Dupuiscfb09192011-11-18 09:03:07 -08002176 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002177 ql_log(ql_log_warn, vha, 0x803b,
2178 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 }
2180
2181 return (rval);
2182}
2183
2184/*
2185* qla2x00_configure_hba
2186* Setup adapter context.
2187*
2188* Input:
2189* ha = adapter state pointer.
2190*
2191* Returns:
2192* 0 = success
2193*
2194* Context:
2195* Kernel context.
2196*/
2197static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002198qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199{
2200 int rval;
2201 uint16_t loop_id;
2202 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002203 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 uint8_t al_pa;
2205 uint8_t area;
2206 uint8_t domain;
2207 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002208 struct qla_hw_data *ha = vha->hw;
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002209 unsigned long flags;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002210 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211
2212 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002213 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002214 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002216 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002217 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002218 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002219 ql_dbg(ql_dbg_disc, vha, 0x2008,
2220 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08002221 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002222 ql_log(ql_log_warn, vha, 0x2009,
2223 "Unable to get host loop ID.\n");
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002224 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
2225 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
2226 ql_log(ql_log_warn, vha, 0x1151,
2227 "Doing link init.\n");
2228 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
2229 return rval;
2230 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002231 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 return (rval);
2234 }
2235
2236 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002237 ql_log(ql_log_info, vha, 0x200a,
2238 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 return (QLA_FUNCTION_FAILED);
2240 }
2241
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002242 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243
2244 /* initialize */
2245 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2246 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002247 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
2249 switch (topo) {
2250 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002251 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 ha->current_topology = ISP_CFG_NL;
2253 strcpy(connect_type, "(Loop)");
2254 break;
2255
2256 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002257 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002258 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 ha->current_topology = ISP_CFG_FL;
2260 strcpy(connect_type, "(FL_Port)");
2261 break;
2262
2263 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002264 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 ha->operating_mode = P2P;
2266 ha->current_topology = ISP_CFG_N;
2267 strcpy(connect_type, "(N_Port-to-N_Port)");
2268 break;
2269
2270 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002271 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002272 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 ha->operating_mode = P2P;
2274 ha->current_topology = ISP_CFG_F;
2275 strcpy(connect_type, "(F_Port)");
2276 break;
2277
2278 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002279 ql_dbg(ql_dbg_disc, vha, 0x200f,
2280 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 ha->current_topology = ISP_CFG_NL;
2282 strcpy(connect_type, "(Loop)");
2283 break;
2284 }
2285
2286 /* Save Host port and loop ID. */
2287 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002288 vha->d_id.b.domain = domain;
2289 vha->d_id.b.area = area;
2290 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002292 spin_lock_irqsave(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002293 qlt_update_vp_map(vha, SET_AL_PA);
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002294 spin_unlock_irqrestore(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002295
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002296 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002297 ql_log(ql_log_info, vha, 0x2010,
2298 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002299 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300
2301 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002302 ql_log(ql_log_warn, vha, 0x2011,
2303 "%s FAILED\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002305 ql_dbg(ql_dbg_disc, vha, 0x2012,
2306 "%s success\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 }
2308
2309 return(rval);
2310}
2311
Giridhar Malavalia9083012010-04-12 17:59:55 -07002312inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002313qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2314 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002315{
2316 char *st, *en;
2317 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002318 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002319 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002320 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002321
2322 if (memcmp(model, BINZERO, len) != 0) {
2323 strncpy(ha->model_number, model, len);
2324 st = en = ha->model_number;
2325 en += len - 1;
2326 while (en > st) {
2327 if (*en != 0x20 && *en != 0x00)
2328 break;
2329 *en-- = '\0';
2330 }
2331
2332 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002333 if (use_tbl &&
2334 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002335 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002336 strncpy(ha->model_desc,
2337 qla2x00_model_name[index * 2 + 1],
2338 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002339 } else {
2340 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002341 if (use_tbl &&
2342 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002343 index < QLA_MODEL_NAMES) {
2344 strcpy(ha->model_number,
2345 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002346 strncpy(ha->model_desc,
2347 qla2x00_model_name[index * 2 + 1],
2348 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002349 } else {
2350 strcpy(ha->model_number, def);
2351 }
2352 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002353 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002354 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002355 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002356}
2357
David Miller4e08df32007-04-16 12:37:43 -07002358/* On sparc systems, obtain port and node WWN from firmware
2359 * properties.
2360 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002361static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002362{
2363#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002364 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002365 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002366 struct device_node *dp = pci_device_to_OF_node(pdev);
2367 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002368 int len;
2369
2370 val = of_get_property(dp, "port-wwn", &len);
2371 if (val && len >= WWN_SIZE)
2372 memcpy(nv->port_name, val, WWN_SIZE);
2373
2374 val = of_get_property(dp, "node-wwn", &len);
2375 if (val && len >= WWN_SIZE)
2376 memcpy(nv->node_name, val, WWN_SIZE);
2377#endif
2378}
2379
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380/*
2381* NVRAM configuration for ISP 2xxx
2382*
2383* Input:
2384* ha = adapter block pointer.
2385*
2386* Output:
2387* initialization control block in response_ring
2388* host adapters parameters in host adapter block
2389*
2390* Returns:
2391* 0 = success.
2392*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002393int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002394qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395{
David Miller4e08df32007-04-16 12:37:43 -07002396 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002397 uint8_t chksum = 0;
2398 uint16_t cnt;
2399 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002400 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002401 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002402 nvram_t *nv = ha->nvram;
2403 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002404 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405
David Miller4e08df32007-04-16 12:37:43 -07002406 rval = QLA_SUCCESS;
2407
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002409 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 ha->nvram_base = 0;
2411 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2412 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2413 ha->nvram_base = 0x80;
2414
2415 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002416 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002417 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2418 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002420 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2421 "Contents of NVRAM.\n");
2422 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2423 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424
2425 /* Bad NVRAM data, set defaults parameters. */
2426 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2427 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2428 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002429 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04002430 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002431 "detected: checksum=0x%x id=%c version=0x%x.\n",
2432 chksum, nv->id[0], nv->nvram_version);
2433 ql_log(ql_log_warn, vha, 0x0065,
2434 "Falling back to "
2435 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07002436
2437 /*
2438 * Set default initialization control block.
2439 */
2440 memset(nv, 0, ha->nvram_size);
2441 nv->parameter_block_version = ICB_VERSION;
2442
2443 if (IS_QLA23XX(ha)) {
2444 nv->firmware_options[0] = BIT_2 | BIT_1;
2445 nv->firmware_options[1] = BIT_7 | BIT_5;
2446 nv->add_firmware_options[0] = BIT_5;
2447 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2448 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2449 nv->special_options[1] = BIT_7;
2450 } else if (IS_QLA2200(ha)) {
2451 nv->firmware_options[0] = BIT_2 | BIT_1;
2452 nv->firmware_options[1] = BIT_7 | BIT_5;
2453 nv->add_firmware_options[0] = BIT_5;
2454 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2455 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2456 } else if (IS_QLA2100(ha)) {
2457 nv->firmware_options[0] = BIT_3 | BIT_1;
2458 nv->firmware_options[1] = BIT_5;
2459 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2460 }
2461
2462 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2463 nv->execution_throttle = __constant_cpu_to_le16(16);
2464 nv->retry_count = 8;
2465 nv->retry_delay = 1;
2466
2467 nv->port_name[0] = 33;
2468 nv->port_name[3] = 224;
2469 nv->port_name[4] = 139;
2470
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002471 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002472
2473 nv->login_timeout = 4;
2474
2475 /*
2476 * Set default host adapter parameters
2477 */
2478 nv->host_p[1] = BIT_2;
2479 nv->reset_delay = 5;
2480 nv->port_down_retry_count = 8;
2481 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2482 nv->link_down_timeout = 60;
2483
2484 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 }
2486
2487#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2488 /*
2489 * The SN2 does not provide BIOS emulation which means you can't change
2490 * potentially bogus BIOS settings. Force the use of default settings
2491 * for link rate and frame size. Hope that the rest of the settings
2492 * are valid.
2493 */
2494 if (ia64_platform_is("sn2")) {
2495 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2496 if (IS_QLA23XX(ha))
2497 nv->special_options[1] = BIT_7;
2498 }
2499#endif
2500
2501 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002502 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503
2504 /*
2505 * Setup driver NVRAM options.
2506 */
2507 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2508 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2509 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2510 nv->firmware_options[1] &= ~BIT_4;
2511
2512 if (IS_QLA23XX(ha)) {
2513 nv->firmware_options[0] |= BIT_2;
2514 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002515 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002516 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517
2518 if (IS_QLA2300(ha)) {
2519 if (ha->fb_rev == FPM_2310) {
2520 strcpy(ha->model_number, "QLA2310");
2521 } else {
2522 strcpy(ha->model_number, "QLA2300");
2523 }
2524 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002525 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002526 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 }
2528 } else if (IS_QLA2200(ha)) {
2529 nv->firmware_options[0] |= BIT_2;
2530 /*
2531 * 'Point-to-point preferred, else loop' is not a safe
2532 * connection mode setting.
2533 */
2534 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2535 (BIT_5 | BIT_4)) {
2536 /* Force 'loop preferred, else point-to-point'. */
2537 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2538 nv->add_firmware_options[0] |= BIT_5;
2539 }
2540 strcpy(ha->model_number, "QLA22xx");
2541 } else /*if (IS_QLA2100(ha))*/ {
2542 strcpy(ha->model_number, "QLA2100");
2543 }
2544
2545 /*
2546 * Copy over NVRAM RISC parameter block to initialization control block.
2547 */
2548 dptr1 = (uint8_t *)icb;
2549 dptr2 = (uint8_t *)&nv->parameter_block_version;
2550 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2551 while (cnt--)
2552 *dptr1++ = *dptr2++;
2553
2554 /* Copy 2nd half. */
2555 dptr1 = (uint8_t *)icb->add_firmware_options;
2556 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2557 while (cnt--)
2558 *dptr1++ = *dptr2++;
2559
Andrew Vasquez5341e862006-05-17 15:09:16 -07002560 /* Use alternate WWN? */
2561 if (nv->host_p[1] & BIT_7) {
2562 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2563 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2564 }
2565
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 /* Prepare nodename */
2567 if ((icb->firmware_options[1] & BIT_6) == 0) {
2568 /*
2569 * Firmware will apply the following mask if the nodename was
2570 * not provided.
2571 */
2572 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2573 icb->node_name[0] &= 0xF0;
2574 }
2575
2576 /*
2577 * Set host adapter parameters.
2578 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002579
2580 /*
2581 * BIT_7 in the host-parameters section allows for modification to
2582 * internal driver logging.
2583 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002584 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08002585 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2587 /* Always load RISC code on non ISP2[12]00 chips. */
2588 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2589 ha->flags.disable_risc_code_load = 0;
2590 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2591 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2592 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002593 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002594 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595
2596 ha->operating_mode =
2597 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2598
2599 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2600 sizeof(ha->fw_seriallink_options));
2601
2602 /* save HBA serial number */
2603 ha->serial0 = icb->port_name[5];
2604 ha->serial1 = icb->port_name[6];
2605 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002606 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2607 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608
2609 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2610
2611 ha->retry_count = nv->retry_count;
2612
2613 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002614 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 nv->login_timeout = ql2xlogintimeout;
2616 if (nv->login_timeout < 4)
2617 nv->login_timeout = 4;
2618 ha->login_timeout = nv->login_timeout;
2619 icb->login_timeout = nv->login_timeout;
2620
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002621 /* Set minimum RATOV to 100 tenths of a second. */
2622 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 ha->loop_reset_delay = nv->reset_delay;
2625
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 /* Link Down Timeout = 0:
2627 *
2628 * When Port Down timer expires we will start returning
2629 * I/O's to OS with "DID_NO_CONNECT".
2630 *
2631 * Link Down Timeout != 0:
2632 *
2633 * The driver waits for the link to come up after link down
2634 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002635 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 if (nv->link_down_timeout == 0) {
2637 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002638 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 } else {
2640 ha->link_down_timeout = nv->link_down_timeout;
2641 ha->loop_down_abort_time =
2642 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 /*
2646 * Need enough time to try and get the port back.
2647 */
2648 ha->port_down_retry_count = nv->port_down_retry_count;
2649 if (qlport_down_retry)
2650 ha->port_down_retry_count = qlport_down_retry;
2651 /* Set login_retry_count */
2652 ha->login_retry_count = nv->retry_count;
2653 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2654 ha->port_down_retry_count > 3)
2655 ha->login_retry_count = ha->port_down_retry_count;
2656 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2657 ha->login_retry_count = ha->port_down_retry_count;
2658 if (ql2xloginretrycount)
2659 ha->login_retry_count = ql2xloginretrycount;
2660
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 icb->lun_enables = __constant_cpu_to_le16(0);
2662 icb->command_resource_count = 0;
2663 icb->immediate_notify_resource_count = 0;
2664 icb->timeout = __constant_cpu_to_le16(0);
2665
2666 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2667 /* Enable RIO */
2668 icb->firmware_options[0] &= ~BIT_3;
2669 icb->add_firmware_options[0] &=
2670 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2671 icb->add_firmware_options[0] |= BIT_2;
2672 icb->response_accumulation_timer = 3;
2673 icb->interrupt_delay_timer = 5;
2674
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002675 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002677 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002678 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002679 ha->zio_mode = icb->add_firmware_options[0] &
2680 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2681 ha->zio_timer = icb->interrupt_delay_timer ?
2682 icb->interrupt_delay_timer: 2;
2683 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 icb->add_firmware_options[0] &=
2685 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002686 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002687 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002688 ha->zio_mode = QLA_ZIO_MODE_6;
2689
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002690 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002691 "ZIO mode %d enabled; timer delay (%d us).\n",
2692 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002694 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2695 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002696 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 }
2698 }
2699
David Miller4e08df32007-04-16 12:37:43 -07002700 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002701 ql_log(ql_log_warn, vha, 0x0069,
2702 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07002703 }
2704 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705}
2706
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002707static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002708qla2x00_rport_del(void *data)
2709{
2710 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002711 struct fc_rport *rport;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002712 scsi_qla_host_t *vha = fcport->vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002713 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002714
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002715 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002716 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002717 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002718 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002719 if (rport) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002720 fc_remote_port_delete(rport);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002721 /*
2722 * Release the target mode FC NEXUS in qla_target.c code
2723 * if target mod is enabled.
2724 */
2725 qlt_fc_port_deleted(vha, fcport);
2726 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002727}
2728
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729/**
2730 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2731 * @ha: HA context
2732 * @flags: allocation flags
2733 *
2734 * Returns a pointer to the allocated fcport, or NULL, if none available.
2735 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002736fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002737qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738{
2739 fc_port_t *fcport;
2740
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002741 fcport = kzalloc(sizeof(fc_port_t), flags);
2742 if (!fcport)
2743 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744
2745 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002746 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 fcport->port_type = FCT_UNKNOWN;
2748 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07002749 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002750 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002752 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753}
2754
2755/*
2756 * qla2x00_configure_loop
2757 * Updates Fibre Channel Device Database with what is actually on loop.
2758 *
2759 * Input:
2760 * ha = adapter block pointer.
2761 *
2762 * Returns:
2763 * 0 = success.
2764 * 1 = error.
2765 * 2 = database was full and device was not configured.
2766 */
2767static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002768qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769{
2770 int rval;
2771 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002772 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 rval = QLA_SUCCESS;
2774
2775 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002776 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2777 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002779 ql_dbg(ql_dbg_disc, vha, 0x2013,
2780 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 return (rval);
2782 }
2783 }
2784
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002785 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002786 ql_dbg(ql_dbg_disc, vha, 0x2014,
2787 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788
2789 /*
2790 * If we have both an RSCN and PORT UPDATE pending then handle them
2791 * both at the same time.
2792 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002793 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2794 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795
Michael Hernandez3064ff32009-12-15 21:29:44 -08002796 qla2x00_get_data_rate(vha);
2797
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 /* Determine what we need to do */
2799 if (ha->current_topology == ISP_CFG_FL &&
2800 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2801
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 set_bit(RSCN_UPDATE, &flags);
2803
2804 } else if (ha->current_topology == ISP_CFG_F &&
2805 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2806
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 set_bit(RSCN_UPDATE, &flags);
2808 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2809
Andrew Vasquez21333b42006-05-17 15:09:56 -07002810 } else if (ha->current_topology == ISP_CFG_N) {
2811 clear_bit(RSCN_UPDATE, &flags);
2812
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002813 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2815
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 set_bit(RSCN_UPDATE, &flags);
2817 set_bit(LOCAL_LOOP_UPDATE, &flags);
2818 }
2819
2820 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002821 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2822 ql_dbg(ql_dbg_disc, vha, 0x2015,
2823 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08002825 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002826 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 }
2828
2829 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002830 if (LOOP_TRANSITION(vha)) {
2831 ql_dbg(ql_dbg_disc, vha, 0x201e,
2832 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002834 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002835 else
2836 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 }
2838
2839 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002840 if (atomic_read(&vha->loop_down_timer) ||
2841 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 rval = QLA_FUNCTION_FAILED;
2843 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002844 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002845 ql_dbg(ql_dbg_disc, vha, 0x2069,
2846 "LOOP READY.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 }
2848 }
2849
2850 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002851 ql_dbg(ql_dbg_disc, vha, 0x206a,
2852 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002854 ql_dbg(ql_dbg_disc, vha, 0x206b,
2855 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 }
2857
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002858 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002859 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002861 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002862 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002863 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002864 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 }
2866
2867 return (rval);
2868}
2869
2870
2871
2872/*
2873 * qla2x00_configure_local_loop
2874 * Updates Fibre Channel Device Database with local loop devices.
2875 *
2876 * Input:
2877 * ha = adapter block pointer.
2878 *
2879 * Returns:
2880 * 0 = success.
2881 */
2882static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002883qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884{
2885 int rval, rval2;
2886 int found_devs;
2887 int found;
2888 fc_port_t *fcport, *new_fcport;
2889
2890 uint16_t index;
2891 uint16_t entries;
2892 char *id_iter;
2893 uint16_t loop_id;
2894 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002895 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896
2897 found_devs = 0;
2898 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08002899 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08002902 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002903 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 &entries);
2905 if (rval != QLA_SUCCESS)
2906 goto cleanup_allocation;
2907
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002908 ql_dbg(ql_dbg_disc, vha, 0x2017,
2909 "Entries in ID list (%d).\n", entries);
2910 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
2911 (uint8_t *)ha->gid_list,
2912 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913
2914 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002915 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002917 ql_log(ql_log_warn, vha, 0x2018,
2918 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 rval = QLA_MEMORY_ALLOC_FAILED;
2920 goto cleanup_allocation;
2921 }
2922 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2923
2924 /*
2925 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2926 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002927 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2929 fcport->port_type != FCT_BROADCAST &&
2930 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2931
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002932 ql_dbg(ql_dbg_disc, vha, 0x2019,
2933 "Marking port lost loop_id=0x%04x.\n",
2934 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935
Chad Dupuisec426e12011-03-30 11:46:32 -07002936 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 }
2938 }
2939
2940 /* Add devices to port list. */
2941 id_iter = (char *)ha->gid_list;
2942 for (index = 0; index < entries; index++) {
2943 domain = ((struct gid_list_info *)id_iter)->domain;
2944 area = ((struct gid_list_info *)id_iter)->area;
2945 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002946 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 loop_id = (uint16_t)
2948 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002949 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 loop_id = le16_to_cpu(
2951 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002952 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953
2954 /* Bypass reserved domain fields. */
2955 if ((domain & 0xf0) == 0xf0)
2956 continue;
2957
2958 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002959 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002960 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 continue;
2962
2963 /* Bypass invalid local loop ID. */
2964 if (loop_id > LAST_LOCAL_LOOP_ID)
2965 continue;
2966
Arun Easi370d5502012-08-22 14:21:10 -04002967 memset(new_fcport, 0, sizeof(fc_port_t));
2968
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 /* Fill in member data. */
2970 new_fcport->d_id.b.domain = domain;
2971 new_fcport->d_id.b.area = area;
2972 new_fcport->d_id.b.al_pa = al_pa;
2973 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002974 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002976 ql_dbg(ql_dbg_disc, vha, 0x201a,
2977 "Failed to retrieve fcport information "
2978 "-- get_port_database=%x, loop_id=0x%04x.\n",
2979 rval2, new_fcport->loop_id);
2980 ql_dbg(ql_dbg_disc, vha, 0x201b,
2981 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002982 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 continue;
2984 }
2985
2986 /* Check for matching device in port list. */
2987 found = 0;
2988 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002989 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 if (memcmp(new_fcport->port_name, fcport->port_name,
2991 WWN_SIZE))
2992 continue;
2993
Shyam Sundarddb9b122009-03-24 09:08:10 -07002994 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 fcport->loop_id = new_fcport->loop_id;
2996 fcport->port_type = new_fcport->port_type;
2997 fcport->d_id.b24 = new_fcport->d_id.b24;
2998 memcpy(fcport->node_name, new_fcport->node_name,
2999 WWN_SIZE);
3000
3001 found++;
3002 break;
3003 }
3004
3005 if (!found) {
3006 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003007 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008
3009 /* Allocate a new replacement fcport. */
3010 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003011 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003013 ql_log(ql_log_warn, vha, 0x201c,
3014 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 rval = QLA_MEMORY_ALLOC_FAILED;
3016 goto cleanup_allocation;
3017 }
3018 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
3019 }
3020
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003021 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003022 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003023
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003024 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025
3026 found_devs++;
3027 }
3028
3029cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003030 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031
3032 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003033 ql_dbg(ql_dbg_disc, vha, 0x201d,
3034 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 }
3036
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 return (rval);
3038}
3039
3040static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003041qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003042{
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003043 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003044 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003045 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003046
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07003047 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003048 return;
3049
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07003050 if (atomic_read(&fcport->state) != FCS_ONLINE)
3051 return;
3052
Andrew Vasquez39bd9622007-09-20 14:07:34 -07003053 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
3054 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003055 return;
3056
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003057 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07003058 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003059 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003060 ql_dbg(ql_dbg_disc, vha, 0x2004,
3061 "Unable to adjust iIDMA "
3062 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x "
3063 "%04x.\n", fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003064 fcport->port_name[2], fcport->port_name[3],
3065 fcport->port_name[4], fcport->port_name[5],
3066 fcport->port_name[6], fcport->port_name[7], rval,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003067 fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003068 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003069 ql_dbg(ql_dbg_disc, vha, 0x2005,
3070 "iIDMA adjusted to %s GB/s "
Joe Carnucciod0297c92012-11-21 02:40:40 -05003071 "on %02x%02x%02x%02x%02x%02x%02x%02x.\n",
3072 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003073 fcport->port_name[0], fcport->port_name[1],
3074 fcport->port_name[2], fcport->port_name[3],
3075 fcport->port_name[4], fcport->port_name[5],
3076 fcport->port_name[6], fcport->port_name[7]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003077 }
3078}
3079
Adrian Bunk23be3312006-11-24 02:46:01 +01003080static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003081qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05003082{
3083 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05003084 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003085 unsigned long flags;
8482e1182005-04-17 15:04:54 -05003086
Andrew Vasquezac280b62009-08-20 11:06:05 -07003087 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05003088
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07003089 rport_ids.node_name = wwn_to_u64(fcport->node_name);
3090 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05003091 rport_ids.port_id = fcport->d_id.b.domain << 16 |
3092 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
3093 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003094 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07003095 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003096 ql_log(ql_log_warn, vha, 0x2006,
3097 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07003098 return;
3099 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003100 /*
3101 * Create target mode FC NEXUS in qla_target.c if target mode is
3102 * enabled..
3103 */
3104 qlt_fc_port_added(vha, fcport);
3105
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003106 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003107 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08003108 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003109
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003110 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003111
3112 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05003113 if (fcport->port_type == FCT_INITIATOR)
3114 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3115 if (fcport->port_type == FCT_TARGET)
3116 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07003117 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05003118}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119
3120/*
Adrian Bunk23be3312006-11-24 02:46:01 +01003121 * qla2x00_update_fcport
3122 * Updates device on list.
3123 *
3124 * Input:
3125 * ha = adapter block pointer.
3126 * fcport = port structure pointer.
3127 *
3128 * Return:
3129 * 0 - Success
3130 * BIT_0 - error
3131 *
3132 * Context:
3133 * Kernel context.
3134 */
3135void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003136qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01003137{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003138 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01003139 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003140 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01003141
Joe Carnuccio1f93da522012-11-21 02:40:38 -05003142 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003143 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08003144 qla24xx_update_fcport_fcp_prio(vha, fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003145 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01003146}
3147
3148/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 * qla2x00_configure_fabric
3150 * Setup SNS devices with loop ID's.
3151 *
3152 * Input:
3153 * ha = adapter block pointer.
3154 *
3155 * Returns:
3156 * 0 = success.
3157 * BIT_0 = error
3158 */
3159static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003160qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161{
Arun Easib3b02e62012-02-09 11:15:39 -08003162 int rval;
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003163 fc_port_t *fcport, *fcptemp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164 uint16_t next_loopid;
3165 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003166 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003168 struct qla_hw_data *ha = vha->hw;
3169 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170
3171 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003172 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003173 loop_id = NPH_F_PORT;
3174 else
3175 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003176 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003178 ql_dbg(ql_dbg_disc, vha, 0x201f,
3179 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003181 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 return (QLA_SUCCESS);
3183 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003184 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07003187 /* FDMI support. */
3188 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003189 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
3190 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07003191
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003193 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003194 loop_id = NPH_SNS;
3195 else
3196 loop_id = SIMPLE_NAME_SERVER;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003197 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
3198 0xfc, mb, BIT_1|BIT_0);
3199 if (rval != QLA_SUCCESS) {
3200 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003201 return rval;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003202 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003204 ql_dbg(ql_dbg_disc, vha, 0x2042,
3205 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3206 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
3207 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 return (QLA_SUCCESS);
3209 }
3210
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003211 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3212 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003214 ql_dbg(ql_dbg_disc, vha, 0x2045,
3215 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003217 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003219 ql_dbg(ql_dbg_disc, vha, 0x2049,
3220 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003222 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003224 ql_dbg(ql_dbg_disc, vha, 0x204f,
3225 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003226 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003228 ql_dbg(ql_dbg_disc, vha, 0x2053,
3229 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 }
3231 }
3232
Joe Carnuccio827210b2013-02-08 01:57:57 -05003233#define QLA_FCPORT_SCAN 1
3234#define QLA_FCPORT_FOUND 2
3235
3236 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3237 fcport->scan_state = QLA_FCPORT_SCAN;
3238 }
3239
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003240 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 if (rval != QLA_SUCCESS)
3242 break;
3243
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003244 /*
3245 * Logout all previous fabric devices marked lost, except
3246 * FCP2 devices.
3247 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003248 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3249 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 break;
3251
3252 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3253 continue;
3254
Joe Carnuccio827210b2013-02-08 01:57:57 -05003255 if (fcport->scan_state == QLA_FCPORT_SCAN &&
Arun Easib3b02e62012-02-09 11:15:39 -08003256 atomic_read(&fcport->state) == FCS_ONLINE) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003257 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003258 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003260 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 fcport->port_type != FCT_INITIATOR &&
3262 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003263 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003264 fcport->loop_id,
3265 fcport->d_id.b.domain,
3266 fcport->d_id.b.area,
3267 fcport->d_id.b.al_pa);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003268 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 }
3270 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003271 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003273 /* Starting free loop ID. */
3274 next_loopid = ha->min_external_loopid;
3275
3276 /*
3277 * Scan through our port list and login entries that need to be
3278 * logged in.
3279 */
3280 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3281 if (atomic_read(&vha->loop_down_timer) ||
3282 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3283 break;
3284
3285 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3286 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3287 continue;
3288
3289 if (fcport->loop_id == FC_NO_LOOP_ID) {
3290 fcport->loop_id = next_loopid;
3291 rval = qla2x00_find_new_loop_id(
3292 base_vha, fcport);
3293 if (rval != QLA_SUCCESS) {
3294 /* Ran out of IDs to use */
3295 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 }
3297 }
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003298 /* Login and update database */
3299 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
3300 }
3301
3302 /* Exit if out of loop IDs. */
3303 if (rval != QLA_SUCCESS) {
3304 break;
3305 }
3306
3307 /*
3308 * Login and add the new devices to our port list.
3309 */
3310 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3311 if (atomic_read(&vha->loop_down_timer) ||
3312 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3313 break;
3314
3315 /* Find a new loop ID to use. */
3316 fcport->loop_id = next_loopid;
3317 rval = qla2x00_find_new_loop_id(base_vha, fcport);
3318 if (rval != QLA_SUCCESS) {
3319 /* Ran out of IDs to use */
3320 break;
3321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322
bdf79622005-04-17 15:06:53 -05003323 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003324 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003325
3326 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 }
3328 } while (0);
3329
Joe Carnuccioe452ceb2013-02-08 01:57:56 -05003330 /* Free all new device structures not processed. */
3331 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3332 list_del(&fcport->list);
3333 kfree(fcport);
3334 }
3335
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003337 ql_dbg(ql_dbg_disc, vha, 0x2068,
3338 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 }
3340
3341 return (rval);
3342}
3343
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344/*
3345 * qla2x00_find_all_fabric_devs
3346 *
3347 * Input:
3348 * ha = adapter block pointer.
3349 * dev = database device entry pointer.
3350 *
3351 * Returns:
3352 * 0 = success.
3353 *
3354 * Context:
3355 * Kernel context.
3356 */
3357static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003358qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3359 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360{
3361 int rval;
3362 uint16_t loop_id;
3363 fc_port_t *fcport, *new_fcport, *fcptemp;
3364 int found;
3365
3366 sw_info_t *swl;
3367 int swl_idx;
3368 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003369 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003370 struct qla_hw_data *ha = vha->hw;
3371 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003372 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373
3374 rval = QLA_SUCCESS;
3375
3376 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08003377 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08003378 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08003379 GFP_KERNEL);
3380 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003381 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003383 ql_dbg(ql_dbg_disc, vha, 0x2054,
3384 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08003386 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003387 if (qla2x00_gid_pt(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_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003391 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003393 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003394 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3395 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003397
3398 /* If other queries succeeded probe for FC-4 type */
3399 if (swl)
3400 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401 }
3402 swl_idx = 0;
3403
3404 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003405 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003407 ql_log(ql_log_warn, vha, 0x205e,
3408 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 return (QLA_MEMORY_ALLOC_FAILED);
3410 }
3411 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 /* Set start port ID scan at adapter ID. */
3413 first_dev = 1;
3414 last_dev = 0;
3415
3416 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003417 loop_id = ha->min_external_loopid;
3418 for (; loop_id <= ha->max_loop_id; loop_id++) {
3419 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 continue;
3421
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003422 if (ha->current_topology == ISP_CFG_FL &&
3423 (atomic_read(&vha->loop_down_timer) ||
3424 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003425 atomic_set(&vha->loop_down_timer, 0);
3426 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3427 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003429 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430
3431 if (swl != NULL) {
3432 if (last_dev) {
3433 wrap.b24 = new_fcport->d_id.b24;
3434 } else {
3435 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3436 memcpy(new_fcport->node_name,
3437 swl[swl_idx].node_name, WWN_SIZE);
3438 memcpy(new_fcport->port_name,
3439 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003440 memcpy(new_fcport->fabric_port_name,
3441 swl[swl_idx].fabric_port_name, WWN_SIZE);
3442 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003443 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444
3445 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3446 last_dev = 1;
3447 }
3448 swl_idx++;
3449 }
3450 } else {
3451 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003452 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003454 ql_log(ql_log_warn, vha, 0x2064,
3455 "SNS scan failed -- assuming "
3456 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 list_for_each_entry_safe(fcport, fcptemp,
3458 new_fcports, list) {
3459 list_del(&fcport->list);
3460 kfree(fcport);
3461 }
3462 rval = QLA_SUCCESS;
3463 break;
3464 }
3465 }
3466
3467 /* If wrap on switch device list, exit. */
3468 if (first_dev) {
3469 wrap.b24 = new_fcport->d_id.b24;
3470 first_dev = 0;
3471 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003472 ql_dbg(ql_dbg_disc, vha, 0x2065,
3473 "Device wrap (%02x%02x%02x).\n",
3474 new_fcport->d_id.b.domain,
3475 new_fcport->d_id.b.area,
3476 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 break;
3478 }
3479
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003480 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003481 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 continue;
3483
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003484 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003485 found = 0;
3486 if (ha->num_vhosts) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003487 unsigned long flags;
3488
3489 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003490 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003491 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3492 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003493 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003494 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003495 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003496 spin_unlock_irqrestore(&ha->vport_slock, flags);
3497
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003498 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003499 continue;
3500 }
3501
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003502 /* Bypass if same domain and area of adapter. */
3503 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003504 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003505 ISP_CFG_FL)
3506 continue;
3507
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508 /* Bypass reserved domain fields. */
3509 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3510 continue;
3511
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003512 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003513 if (ql2xgffidenable &&
3514 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3515 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003516 continue;
3517
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 /* Locate matching device in database. */
3519 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003520 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 if (memcmp(new_fcport->port_name, fcport->port_name,
3522 WWN_SIZE))
3523 continue;
3524
Joe Carnuccio827210b2013-02-08 01:57:57 -05003525 fcport->scan_state = QLA_FCPORT_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08003526
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527 found++;
3528
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003529 /* Update port state. */
3530 memcpy(fcport->fabric_port_name,
3531 new_fcport->fabric_port_name, WWN_SIZE);
3532 fcport->fp_speed = new_fcport->fp_speed;
3533
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534 /*
3535 * If address the same and state FCS_ONLINE, nothing
3536 * changed.
3537 */
3538 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3539 atomic_read(&fcport->state) == FCS_ONLINE) {
3540 break;
3541 }
3542
3543 /*
3544 * If device was not a fabric device before.
3545 */
3546 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3547 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04003548 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 fcport->flags |= (FCF_FABRIC_DEVICE |
3550 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 break;
3552 }
3553
3554 /*
3555 * Port ID changed or device was marked to be updated;
3556 * Log it out if still logged in and mark it for
3557 * relogin later.
3558 */
3559 fcport->d_id.b24 = new_fcport->d_id.b24;
3560 fcport->flags |= FCF_LOGIN_NEEDED;
3561 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003562 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Arun Easi0eba25d2012-02-09 11:15:58 -08003563 (fcport->flags & FCF_ASYNC_SENT) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564 fcport->port_type != FCT_INITIATOR &&
3565 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003566 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003567 fcport->d_id.b.domain, fcport->d_id.b.area,
3568 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003569 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570 }
3571
3572 break;
3573 }
3574
3575 if (found)
3576 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577 /* If device was not in our fcports list, then add it. */
3578 list_add_tail(&new_fcport->list, new_fcports);
3579
3580 /* Allocate a new replacement fcport. */
3581 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003582 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003584 ql_log(ql_log_warn, vha, 0x2066,
3585 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586 return (QLA_MEMORY_ALLOC_FAILED);
3587 }
3588 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3589 new_fcport->d_id.b24 = nxt_d_id.b24;
3590 }
3591
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003592 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594 return (rval);
3595}
3596
3597/*
3598 * qla2x00_find_new_loop_id
3599 * Scan through our port list and find a new usable loop ID.
3600 *
3601 * Input:
3602 * ha: adapter state pointer.
3603 * dev: port structure pointer.
3604 *
3605 * Returns:
3606 * qla2x00 local function return status code.
3607 *
3608 * Context:
3609 * Kernel context.
3610 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003611int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003612qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613{
3614 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003615 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07003616 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617
3618 rval = QLA_SUCCESS;
3619
Chad Dupuis5f16b332012-08-22 14:21:00 -04003620 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621
Chad Dupuis5f16b332012-08-22 14:21:00 -04003622 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
3623 LOOPID_MAP_SIZE);
3624 if (dev->loop_id >= LOOPID_MAP_SIZE ||
3625 qla2x00_is_reserved_id(vha, dev->loop_id)) {
3626 dev->loop_id = FC_NO_LOOP_ID;
3627 rval = QLA_FUNCTION_FAILED;
3628 } else
3629 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630
Chad Dupuis5f16b332012-08-22 14:21:00 -04003631 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632
Chad Dupuis5f16b332012-08-22 14:21:00 -04003633 if (rval == QLA_SUCCESS)
3634 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
3635 "Assigning new loopid=%x, portid=%x.\n",
3636 dev->loop_id, dev->d_id.b24);
3637 else
3638 ql_log(ql_log_warn, dev->vha, 0x2087,
3639 "No loop_id's available, portid=%x.\n",
3640 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641
3642 return (rval);
3643}
3644
3645/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 * qla2x00_fabric_dev_login
3647 * Login fabric target device and update FC port database.
3648 *
3649 * Input:
3650 * ha: adapter state pointer.
3651 * fcport: port structure list pointer.
3652 * next_loopid: contains value of a new loop ID that can be used
3653 * by the next login attempt.
3654 *
3655 * Returns:
3656 * qla2x00 local function return status code.
3657 *
3658 * Context:
3659 * Kernel context.
3660 */
3661static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003662qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663 uint16_t *next_loopid)
3664{
3665 int rval;
3666 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003667 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003668 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669
3670 rval = QLA_SUCCESS;
3671 retry = 0;
3672
Andrew Vasquezac280b62009-08-20 11:06:05 -07003673 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003674 if (fcport->flags & FCF_ASYNC_SENT)
3675 return rval;
3676 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003677 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3678 if (!rval)
3679 return rval;
3680 }
3681
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003682 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003683 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003685 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003686 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003687 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003688 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003689 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003691 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003692 fcport->d_id.b.domain, fcport->d_id.b.area,
3693 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003694 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003695 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003696 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697 }
Chad Dupuis0b91d112012-02-09 11:15:42 -08003698 } else {
3699 /* Retry Login. */
3700 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 }
3702
3703 return (rval);
3704}
3705
3706/*
3707 * qla2x00_fabric_login
3708 * Issue fabric login command.
3709 *
3710 * Input:
3711 * ha = adapter block pointer.
3712 * device = pointer to FC device type structure.
3713 *
3714 * Returns:
3715 * 0 - Login successfully
3716 * 1 - Login failed
3717 * 2 - Initiator device
3718 * 3 - Fatal error
3719 */
3720int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003721qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 uint16_t *next_loopid)
3723{
3724 int rval;
3725 int retry;
3726 uint16_t tmp_loopid;
3727 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003728 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729
3730 retry = 0;
3731 tmp_loopid = 0;
3732
3733 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003734 ql_dbg(ql_dbg_disc, vha, 0x2000,
3735 "Trying Fabric Login w/loop id 0x%04x for port "
3736 "%02x%02x%02x.\n",
3737 fcport->loop_id, fcport->d_id.b.domain,
3738 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739
3740 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08003741 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 fcport->d_id.b.domain, fcport->d_id.b.area,
3743 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08003744 if (rval != QLA_SUCCESS) {
3745 return rval;
3746 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747 if (mb[0] == MBS_PORT_ID_USED) {
3748 /*
3749 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003750 * recommends the driver perform an implicit login with
3751 * the specified ID again. The ID we just used is save
3752 * here so we return with an ID that can be tried by
3753 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 */
3755 retry++;
3756 tmp_loopid = fcport->loop_id;
3757 fcport->loop_id = mb[1];
3758
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003759 ql_dbg(ql_dbg_disc, vha, 0x2001,
3760 "Fabric Login: port in use - next loop "
3761 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003763 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764
3765 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3766 /*
3767 * Login succeeded.
3768 */
3769 if (retry) {
3770 /* A retry occurred before. */
3771 *next_loopid = tmp_loopid;
3772 } else {
3773 /*
3774 * No retry occurred before. Just increment the
3775 * ID value for next login.
3776 */
3777 *next_loopid = (fcport->loop_id + 1);
3778 }
3779
3780 if (mb[1] & BIT_0) {
3781 fcport->port_type = FCT_INITIATOR;
3782 } else {
3783 fcport->port_type = FCT_TARGET;
3784 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003785 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786 }
3787 }
3788
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003789 if (mb[10] & BIT_0)
3790 fcport->supported_classes |= FC_COS_CLASS2;
3791 if (mb[10] & BIT_1)
3792 fcport->supported_classes |= FC_COS_CLASS3;
3793
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003794 if (IS_FWI2_CAPABLE(ha)) {
3795 if (mb[10] & BIT_7)
3796 fcport->flags |=
3797 FCF_CONF_COMP_SUPPORTED;
3798 }
3799
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 rval = QLA_SUCCESS;
3801 break;
3802 } else if (mb[0] == MBS_LOOP_ID_USED) {
3803 /*
3804 * Loop ID already used, try next loop ID.
3805 */
3806 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003807 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 if (rval != QLA_SUCCESS) {
3809 /* Ran out of loop IDs to use */
3810 break;
3811 }
3812 } else if (mb[0] == MBS_COMMAND_ERROR) {
3813 /*
3814 * Firmware possibly timed out during login. If NO
3815 * retries are left to do then the device is declared
3816 * dead.
3817 */
3818 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003819 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003820 fcport->d_id.b.domain, fcport->d_id.b.area,
3821 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003822 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823
3824 rval = 1;
3825 break;
3826 } else {
3827 /*
3828 * unrecoverable / not handled error
3829 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003830 ql_dbg(ql_dbg_disc, vha, 0x2002,
3831 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
3832 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
3833 fcport->d_id.b.area, fcport->d_id.b.al_pa,
3834 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835
3836 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003837 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003838 fcport->d_id.b.domain, fcport->d_id.b.area,
3839 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003840 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003841 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842
3843 rval = 3;
3844 break;
3845 }
3846 }
3847
3848 return (rval);
3849}
3850
3851/*
3852 * qla2x00_local_device_login
3853 * Issue local device login command.
3854 *
3855 * Input:
3856 * ha = adapter block pointer.
3857 * loop_id = loop id of device to login to.
3858 *
3859 * Returns (Where's the #define!!!!):
3860 * 0 - Login successfully
3861 * 1 - Login failed
3862 * 3 - Fatal error
3863 */
3864int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003865qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866{
3867 int rval;
3868 uint16_t mb[MAILBOX_REGISTER_COUNT];
3869
3870 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003871 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 if (rval == QLA_SUCCESS) {
3873 /* Interrogate mailbox registers for any errors */
3874 if (mb[0] == MBS_COMMAND_ERROR)
3875 rval = 1;
3876 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3877 /* device not in PCB table */
3878 rval = 3;
3879 }
3880
3881 return (rval);
3882}
3883
3884/*
3885 * qla2x00_loop_resync
3886 * Resync with fibre channel devices.
3887 *
3888 * Input:
3889 * ha = adapter block pointer.
3890 *
3891 * Returns:
3892 * 0 = success
3893 */
3894int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003895qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003897 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003899 struct req_que *req;
3900 struct rsp_que *rsp;
3901
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003902 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003903 req = vha->hw->req_q_map[0];
3904 else
3905 req = vha->req;
3906 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003908 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3909 if (vha->flags.online) {
3910 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3912 wait_time = 256;
3913 do {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003914 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003915 qla2x00_marker(vha, req, rsp, 0, 0,
3916 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003917 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918
3919 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003920 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003922 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003924 } while (!atomic_read(&vha->loop_down_timer) &&
3925 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3926 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3927 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 }
3930
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003931 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003934 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003935 ql_dbg(ql_dbg_disc, vha, 0x206c,
3936 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937
3938 return (rval);
3939}
3940
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003941/*
3942* qla2x00_perform_loop_resync
3943* Description: This function will set the appropriate flags and call
3944* qla2x00_loop_resync. If successful loop will be resynced
3945* Arguments : scsi_qla_host_t pointer
3946* returm : Success or Failure
3947*/
3948
3949int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
3950{
3951 int32_t rval = 0;
3952
3953 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
3954 /*Configure the flags so that resync happens properly*/
3955 atomic_set(&ha->loop_down_timer, 0);
3956 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3957 atomic_set(&ha->loop_state, LOOP_UP);
3958 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
3959 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
3960 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3961
3962 rval = qla2x00_loop_resync(ha);
3963 } else
3964 atomic_set(&ha->loop_state, LOOP_DEAD);
3965
3966 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3967 }
3968
3969 return rval;
3970}
3971
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003973qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003974{
3975 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07003976 struct scsi_qla_host *vha;
3977 struct qla_hw_data *ha = base_vha->hw;
3978 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003979
Arun Easifeafb7b2010-09-03 14:57:00 -07003980 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003981 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07003982 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
3983 atomic_inc(&vha->vref_count);
3984 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08003985 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07003986 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
3987 spin_unlock_irqrestore(&ha->vport_slock, flags);
3988
Andrew Vasquez67becc02009-08-25 11:36:20 -07003989 qla2x00_rport_del(fcport);
Arun Easifeafb7b2010-09-03 14:57:00 -07003990
3991 spin_lock_irqsave(&ha->vport_slock, flags);
3992 }
3993 }
3994 atomic_dec(&vha->vref_count);
3995 }
3996 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003997}
3998
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003999/* Assumes idc_lock always held on entry */
4000void
4001qla83xx_reset_ownership(scsi_qla_host_t *vha)
4002{
4003 struct qla_hw_data *ha = vha->hw;
4004 uint32_t drv_presence, drv_presence_mask;
4005 uint32_t dev_part_info1, dev_part_info2, class_type;
4006 uint32_t class_type_mask = 0x3;
4007 uint16_t fcoe_other_function = 0xffff, i;
4008
4009 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4010
4011 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
4012 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
4013 for (i = 0; i < 8; i++) {
4014 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
4015 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4016 (i != ha->portnum)) {
4017 fcoe_other_function = i;
4018 break;
4019 }
4020 }
4021 if (fcoe_other_function == 0xffff) {
4022 for (i = 0; i < 8; i++) {
4023 class_type = ((dev_part_info2 >> (i * 4)) &
4024 class_type_mask);
4025 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
4026 ((i + 8) != ha->portnum)) {
4027 fcoe_other_function = i + 8;
4028 break;
4029 }
4030 }
4031 }
4032 /*
4033 * Prepare drv-presence mask based on fcoe functions present.
4034 * However consider only valid physical fcoe function numbers (0-15).
4035 */
4036 drv_presence_mask = ~((1 << (ha->portnum)) |
4037 ((fcoe_other_function == 0xffff) ?
4038 0 : (1 << (fcoe_other_function))));
4039
4040 /* We are the reset owner iff:
4041 * - No other protocol drivers present.
4042 * - This is the lowest among fcoe functions. */
4043 if (!(drv_presence & drv_presence_mask) &&
4044 (ha->portnum < fcoe_other_function)) {
4045 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
4046 "This host is Reset owner.\n");
4047 ha->flags.nic_core_reset_owner = 1;
4048 }
4049}
4050
Saurav Kashyapfa492632012-11-21 02:40:29 -05004051static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004052__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
4053{
4054 int rval = QLA_SUCCESS;
4055 struct qla_hw_data *ha = vha->hw;
4056 uint32_t drv_ack;
4057
4058 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4059 if (rval == QLA_SUCCESS) {
4060 drv_ack |= (1 << ha->portnum);
4061 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4062 }
4063
4064 return rval;
4065}
4066
Saurav Kashyapfa492632012-11-21 02:40:29 -05004067static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004068__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
4069{
4070 int rval = QLA_SUCCESS;
4071 struct qla_hw_data *ha = vha->hw;
4072 uint32_t drv_ack;
4073
4074 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
4075 if (rval == QLA_SUCCESS) {
4076 drv_ack &= ~(1 << ha->portnum);
4077 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
4078 }
4079
4080 return rval;
4081}
4082
Saurav Kashyapfa492632012-11-21 02:40:29 -05004083static const char *
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004084qla83xx_dev_state_to_string(uint32_t dev_state)
4085{
4086 switch (dev_state) {
4087 case QLA8XXX_DEV_COLD:
4088 return "COLD/RE-INIT";
4089 case QLA8XXX_DEV_INITIALIZING:
4090 return "INITIALIZING";
4091 case QLA8XXX_DEV_READY:
4092 return "READY";
4093 case QLA8XXX_DEV_NEED_RESET:
4094 return "NEED RESET";
4095 case QLA8XXX_DEV_NEED_QUIESCENT:
4096 return "NEED QUIESCENT";
4097 case QLA8XXX_DEV_FAILED:
4098 return "FAILED";
4099 case QLA8XXX_DEV_QUIESCENT:
4100 return "QUIESCENT";
4101 default:
4102 return "Unknown";
4103 }
4104}
4105
4106/* Assumes idc-lock always held on entry */
4107void
4108qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
4109{
4110 struct qla_hw_data *ha = vha->hw;
4111 uint32_t idc_audit_reg = 0, duration_secs = 0;
4112
4113 switch (audit_type) {
4114 case IDC_AUDIT_TIMESTAMP:
4115 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
4116 idc_audit_reg = (ha->portnum) |
4117 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
4118 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4119 break;
4120
4121 case IDC_AUDIT_COMPLETION:
4122 duration_secs = ((jiffies_to_msecs(jiffies) -
4123 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
4124 idc_audit_reg = (ha->portnum) |
4125 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
4126 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
4127 break;
4128
4129 default:
4130 ql_log(ql_log_warn, vha, 0xb078,
4131 "Invalid audit type specified.\n");
4132 break;
4133 }
4134}
4135
4136/* Assumes idc_lock always held on entry */
Saurav Kashyapfa492632012-11-21 02:40:29 -05004137static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004138qla83xx_initiating_reset(scsi_qla_host_t *vha)
4139{
4140 struct qla_hw_data *ha = vha->hw;
4141 uint32_t idc_control, dev_state;
4142
4143 __qla83xx_get_idc_control(vha, &idc_control);
4144 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
4145 ql_log(ql_log_info, vha, 0xb080,
4146 "NIC Core reset has been disabled. idc-control=0x%x\n",
4147 idc_control);
4148 return QLA_FUNCTION_FAILED;
4149 }
4150
4151 /* Set NEED-RESET iff in READY state and we are the reset-owner */
4152 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4153 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
4154 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
4155 QLA8XXX_DEV_NEED_RESET);
4156 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
4157 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
4158 } else {
4159 const char *state = qla83xx_dev_state_to_string(dev_state);
4160 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
4161
4162 /* SV: XXX: Is timeout required here? */
4163 /* Wait for IDC state change READY -> NEED_RESET */
4164 while (dev_state == QLA8XXX_DEV_READY) {
4165 qla83xx_idc_unlock(vha, 0);
4166 msleep(200);
4167 qla83xx_idc_lock(vha, 0);
4168 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4169 }
4170 }
4171
4172 /* Send IDC ack by writing to drv-ack register */
4173 __qla83xx_set_drv_ack(vha);
4174
4175 return QLA_SUCCESS;
4176}
4177
4178int
4179__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
4180{
4181 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4182}
4183
4184int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004185__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
4186{
4187 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4188}
4189
Saurav Kashyapfa492632012-11-21 02:40:29 -05004190static int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004191qla83xx_check_driver_presence(scsi_qla_host_t *vha)
4192{
4193 uint32_t drv_presence = 0;
4194 struct qla_hw_data *ha = vha->hw;
4195
4196 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4197 if (drv_presence & (1 << ha->portnum))
4198 return QLA_SUCCESS;
4199 else
4200 return QLA_TEST_FAILED;
4201}
4202
4203int
4204qla83xx_nic_core_reset(scsi_qla_host_t *vha)
4205{
4206 int rval = QLA_SUCCESS;
4207 struct qla_hw_data *ha = vha->hw;
4208
4209 ql_dbg(ql_dbg_p3p, vha, 0xb058,
4210 "Entered %s().\n", __func__);
4211
4212 if (vha->device_flags & DFLG_DEV_FAILED) {
4213 ql_log(ql_log_warn, vha, 0xb059,
4214 "Device in unrecoverable FAILED state.\n");
4215 return QLA_FUNCTION_FAILED;
4216 }
4217
4218 qla83xx_idc_lock(vha, 0);
4219
4220 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
4221 ql_log(ql_log_warn, vha, 0xb05a,
4222 "Function=0x%x has been removed from IDC participation.\n",
4223 ha->portnum);
4224 rval = QLA_FUNCTION_FAILED;
4225 goto exit;
4226 }
4227
4228 qla83xx_reset_ownership(vha);
4229
4230 rval = qla83xx_initiating_reset(vha);
4231
4232 /*
4233 * Perform reset if we are the reset-owner,
4234 * else wait till IDC state changes to READY/FAILED.
4235 */
4236 if (rval == QLA_SUCCESS) {
4237 rval = qla83xx_idc_state_handler(vha);
4238
4239 if (rval == QLA_SUCCESS)
4240 ha->flags.nic_core_hung = 0;
4241 __qla83xx_clear_drv_ack(vha);
4242 }
4243
4244exit:
4245 qla83xx_idc_unlock(vha, 0);
4246
4247 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
4248
4249 return rval;
4250}
4251
Saurav Kashyap81178772012-08-22 14:21:04 -04004252int
4253qla2xxx_mctp_dump(scsi_qla_host_t *vha)
4254{
4255 struct qla_hw_data *ha = vha->hw;
4256 int rval = QLA_FUNCTION_FAILED;
4257
4258 if (!IS_MCTP_CAPABLE(ha)) {
4259 /* This message can be removed from the final version */
4260 ql_log(ql_log_info, vha, 0x506d,
4261 "This board is not MCTP capable\n");
4262 return rval;
4263 }
4264
4265 if (!ha->mctp_dump) {
4266 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
4267 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
4268
4269 if (!ha->mctp_dump) {
4270 ql_log(ql_log_warn, vha, 0x506e,
4271 "Failed to allocate memory for mctp dump\n");
4272 return rval;
4273 }
4274 }
4275
4276#define MCTP_DUMP_STR_ADDR 0x00000000
4277 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
4278 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
4279 if (rval != QLA_SUCCESS) {
4280 ql_log(ql_log_warn, vha, 0x506f,
4281 "Failed to capture mctp dump\n");
4282 } else {
4283 ql_log(ql_log_info, vha, 0x5070,
4284 "Mctp dump capture for host (%ld/%p).\n",
4285 vha->host_no, ha->mctp_dump);
4286 ha->mctp_dumped = 1;
4287 }
4288
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04004289 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04004290 ha->flags.nic_core_reset_hdlr_active = 1;
4291 rval = qla83xx_restart_nic_firmware(vha);
4292 if (rval)
4293 /* NIC Core reset failed. */
4294 ql_log(ql_log_warn, vha, 0x5071,
4295 "Failed to restart nic firmware\n");
4296 else
4297 ql_dbg(ql_dbg_p3p, vha, 0xb084,
4298 "Restarted NIC firmware successfully.\n");
4299 ha->flags.nic_core_reset_hdlr_active = 0;
4300 }
4301
4302 return rval;
4303
4304}
4305
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004306/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004307* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004308* Description: This function will block the new I/Os
4309* Its not aborting any I/Os as context
4310* is not destroyed during quiescence
4311* Arguments: scsi_qla_host_t
4312* return : void
4313*/
4314void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004315qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004316{
4317 struct qla_hw_data *ha = vha->hw;
4318 struct scsi_qla_host *vp;
4319
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004320 ql_dbg(ql_dbg_dpc, vha, 0x401d,
4321 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004322
4323 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4324 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4325 atomic_set(&vha->loop_state, LOOP_DOWN);
4326 qla2x00_mark_all_devices_lost(vha, 0);
4327 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004328 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004329 } else {
4330 if (!atomic_read(&vha->loop_down_timer))
4331 atomic_set(&vha->loop_down_timer,
4332 LOOP_DOWN_TIME);
4333 }
4334 /* Wait for pending cmds to complete */
4335 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
4336}
4337
Giridhar Malavalia9083012010-04-12 17:59:55 -07004338void
4339qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
4340{
4341 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004342 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07004343 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004344 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004345
Saurav Kashyape46ef002011-02-23 15:27:16 -08004346 /* For ISP82XX, driver waits for completion of the commands.
4347 * online flag should be set.
4348 */
4349 if (!IS_QLA82XX(ha))
4350 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004351 ha->flags.chip_reset_done = 0;
4352 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04004353 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004354
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004355 ql_log(ql_log_info, vha, 0x00af,
4356 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004357
Saurav Kashyape46ef002011-02-23 15:27:16 -08004358 /* For ISP82XX, reset_chip is just disabling interrupts.
4359 * Driver waits for the completion of the commands.
4360 * the interrupts need to be enabled.
4361 */
Giridhar Malavalia9083012010-04-12 17:59:55 -07004362 if (!IS_QLA82XX(ha))
4363 ha->isp_ops->reset_chip(vha);
4364
4365 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
4366 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4367 atomic_set(&vha->loop_state, LOOP_DOWN);
4368 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004369
4370 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004371 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07004372 atomic_inc(&vp->vref_count);
4373 spin_unlock_irqrestore(&ha->vport_slock, flags);
4374
Giridhar Malavalia9083012010-04-12 17:59:55 -07004375 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004376
4377 spin_lock_irqsave(&ha->vport_slock, flags);
4378 atomic_dec(&vp->vref_count);
4379 }
4380 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004381 } else {
4382 if (!atomic_read(&vha->loop_down_timer))
4383 atomic_set(&vha->loop_down_timer,
4384 LOOP_DOWN_TIME);
4385 }
4386
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004387 /* Clear all async request states across all VPs. */
4388 list_for_each_entry(fcport, &vha->vp_fcports, list)
4389 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4390 spin_lock_irqsave(&ha->vport_slock, flags);
4391 list_for_each_entry(vp, &ha->vp_list, list) {
4392 atomic_inc(&vp->vref_count);
4393 spin_unlock_irqrestore(&ha->vport_slock, flags);
4394
4395 list_for_each_entry(fcport, &vp->vp_fcports, list)
4396 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4397
4398 spin_lock_irqsave(&ha->vport_slock, flags);
4399 atomic_dec(&vp->vref_count);
4400 }
4401 spin_unlock_irqrestore(&ha->vport_slock, flags);
4402
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004403 if (!ha->flags.eeh_busy) {
4404 /* Make sure for ISP 82XX IO DMA is complete */
4405 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004406 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004407 ql_log(ql_log_info, vha, 0x00b4,
4408 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004409
Saurav Kashyape46ef002011-02-23 15:27:16 -08004410 /* Done waiting for pending commands.
4411 * Reset the online flag.
4412 */
4413 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004414 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004416 /* Requeue all commands in outstanding command list. */
4417 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4418 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419}
4420
4421/*
4422* qla2x00_abort_isp
4423* Resets ISP and aborts all outstanding commands.
4424*
4425* Input:
4426* ha = adapter block pointer.
4427*
4428* Returns:
4429* 0 = success
4430*/
4431int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004432qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004433{
Andrew Vasquez476e8972006-08-23 14:54:55 -07004434 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004436 struct qla_hw_data *ha = vha->hw;
4437 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004438 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07004439 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004441 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004442 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004443
Santosh Vernekara61712972012-08-22 14:21:13 -04004444 if (IS_QLA8031(ha)) {
4445 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
4446 "Clearing fcoe driver presence.\n");
4447 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
4448 ql_dbg(ql_dbg_p3p, vha, 0xb073,
4449 "Error while clearing DRV-Presence.\n");
4450 }
4451
Andrew Vasquez85880802009-12-15 21:29:46 -08004452 if (unlikely(pci_channel_offline(ha->pdev) &&
4453 ha->flags.pci_channel_io_perm_failure)) {
4454 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4455 status = 0;
4456 return status;
4457 }
4458
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004459 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08004460
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004461 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004463 if (!qla2x00_restart_isp(vha)) {
4464 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004465
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004466 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004467 /*
4468 * Issue marker command only when we are going
4469 * to start the I/O .
4470 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004471 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004472 }
4473
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004474 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004475
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004476 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004477
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004478 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004479 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07004480
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004481 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
4482 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004483 if (ha->fce) {
4484 ha->flags.fce_enabled = 1;
4485 memset(ha->fce, 0,
4486 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004487 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004488 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4489 &ha->fce_bufs);
4490 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004491 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004492 "Unable to reinitialize FCE "
4493 "(%d).\n", rval);
4494 ha->flags.fce_enabled = 0;
4495 }
4496 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004497
4498 if (ha->eft) {
4499 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004500 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004501 ha->eft_dma, EFT_NUM_BUFFERS);
4502 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004503 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004504 "Unable to reinitialize EFT "
4505 "(%d).\n", rval);
4506 }
4507 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004509 vha->flags.online = 1;
4510 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004512 ql_log(ql_log_fatal, vha, 0x8035,
4513 "ISP error recover failed - "
4514 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004515 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516 * The next call disables the board
4517 * completely.
4518 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004519 ha->isp_ops->reset_adapter(vha);
4520 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004521 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004522 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004523 status = 0;
4524 } else { /* schedule another ISP abort */
4525 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004526 ql_dbg(ql_dbg_taskm, vha, 0x8020,
4527 "ISP abort - retry remaining %d.\n",
4528 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004529 status = 1;
4530 }
4531 } else {
4532 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004533 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4534 "ISP error recovery - retrying (%d) "
4535 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004536 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004537 status = 1;
4538 }
4539 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004540
Linus Torvalds1da177e2005-04-16 15:20:36 -07004541 }
4542
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004543 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004544 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07004545
4546 spin_lock_irqsave(&ha->vport_slock, flags);
4547 list_for_each_entry(vp, &ha->vp_list, list) {
4548 if (vp->vp_idx) {
4549 atomic_inc(&vp->vref_count);
4550 spin_unlock_irqrestore(&ha->vport_slock, flags);
4551
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004552 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004553
4554 spin_lock_irqsave(&ha->vport_slock, flags);
4555 atomic_dec(&vp->vref_count);
4556 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004557 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004558 spin_unlock_irqrestore(&ha->vport_slock, flags);
4559
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004560 if (IS_QLA8031(ha)) {
4561 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
4562 "Setting back fcoe driver presence.\n");
4563 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
4564 ql_dbg(ql_dbg_p3p, vha, 0xb074,
4565 "Error while setting DRV-Presence.\n");
4566 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004567 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08004568 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
4569 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 }
4571
4572 return(status);
4573}
4574
4575/*
4576* qla2x00_restart_isp
4577* restarts the ISP after a reset
4578*
4579* Input:
4580* ha = adapter block pointer.
4581*
4582* Returns:
4583* 0 = success
4584*/
4585static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004586qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004587{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004588 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004589 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004590 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004591 struct req_que *req = ha->req_q_map[0];
4592 struct rsp_que *rsp = ha->rsp_q_map[0];
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004593 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004594
4595 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004596 if (qla2x00_isp_firmware(vha)) {
4597 vha->flags.online = 0;
4598 status = ha->isp_ops->chip_diag(vha);
4599 if (!status)
4600 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004601 }
4602
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004603 if (!status && !(status = qla2x00_init_rings(vha))) {
4604 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004605 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004606 /* Initialize the queues in use */
4607 qla25xx_init_queues(ha);
4608
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004609 status = qla2x00_fw_ready(vha);
4610 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004611 ql_dbg(ql_dbg_taskm, vha, 0x8031,
4612 "Start configure loop status = %d.\n", status);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004613
4614 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004615 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004616
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004617 vha->flags.online = 1;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004618
4619 /*
4620 * Process any ATIO queue entries that came in
4621 * while we weren't online.
4622 */
4623 spin_lock_irqsave(&ha->hardware_lock, flags);
4624 if (qla_tgt_mode_enabled(vha))
4625 qlt_24xx_process_atio_queue(vha);
4626 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4627
Linus Torvalds1da177e2005-04-16 15:20:36 -07004628 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4629 wait_time = 256;
4630 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004631 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4632 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004633 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004634 } while (!atomic_read(&vha->loop_down_timer) &&
4635 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4636 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4637 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004638 }
4639
4640 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004641 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004642 status = 0;
4643
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004644 ql_dbg(ql_dbg_taskm, vha, 0x8032,
4645 "Configure loop done, status = 0x%x.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646 }
4647 return (status);
4648}
4649
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004650static int
4651qla25xx_init_queues(struct qla_hw_data *ha)
4652{
4653 struct rsp_que *rsp = NULL;
4654 struct req_que *req = NULL;
4655 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4656 int ret = -1;
4657 int i;
4658
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004659 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004660 rsp = ha->rsp_q_map[i];
4661 if (rsp) {
4662 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004663 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004664 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004665 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4666 "%s Rsp que: %d init failed.\n",
4667 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004668 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004669 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4670 "%s Rsp que: %d inited.\n",
4671 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004672 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004673 }
4674 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004675 req = ha->req_q_map[i];
4676 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004677 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004678 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004679 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004680 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004681 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4682 "%s Req que: %d init failed.\n",
4683 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004684 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004685 ql_dbg(ql_dbg_init, base_vha, 0x0102,
4686 "%s Req que: %d inited.\n",
4687 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004688 }
4689 }
4690 return ret;
4691}
4692
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693/*
4694* qla2x00_reset_adapter
4695* Reset adapter.
4696*
4697* Input:
4698* ha = adapter block pointer.
4699*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004700void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004701qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004702{
4703 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004704 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004705 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004707 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004708 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004709
Linus Torvalds1da177e2005-04-16 15:20:36 -07004710 spin_lock_irqsave(&ha->hardware_lock, flags);
4711 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4712 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4713 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4714 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4715 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4716}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004717
4718void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004719qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004720{
4721 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004722 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004723 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4724
Giridhar Malavalia9083012010-04-12 17:59:55 -07004725 if (IS_QLA82XX(ha))
4726 return;
4727
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004728 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004729 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004730
4731 spin_lock_irqsave(&ha->hardware_lock, flags);
4732 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4733 RD_REG_DWORD(&reg->hccr);
4734 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4735 RD_REG_DWORD(&reg->hccr);
4736 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004737
4738 if (IS_NOPOLLING_TYPE(ha))
4739 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004740}
4741
David Miller4e08df32007-04-16 12:37:43 -07004742/* On sparc systems, obtain port and node WWN from firmware
4743 * properties.
4744 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004745static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4746 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004747{
4748#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004749 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004750 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004751 struct device_node *dp = pci_device_to_OF_node(pdev);
4752 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004753 int len;
4754
4755 val = of_get_property(dp, "port-wwn", &len);
4756 if (val && len >= WWN_SIZE)
4757 memcpy(nv->port_name, val, WWN_SIZE);
4758
4759 val = of_get_property(dp, "node-wwn", &len);
4760 if (val && len >= WWN_SIZE)
4761 memcpy(nv->node_name, val, WWN_SIZE);
4762#endif
4763}
4764
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004765int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004766qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004767{
David Miller4e08df32007-04-16 12:37:43 -07004768 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004769 struct init_cb_24xx *icb;
4770 struct nvram_24xx *nv;
4771 uint32_t *dptr;
4772 uint8_t *dptr1, *dptr2;
4773 uint32_t chksum;
4774 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004775 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004776
David Miller4e08df32007-04-16 12:37:43 -07004777 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004778 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004779 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004780
4781 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004782 if (ha->flags.port0) {
4783 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4784 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4785 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004786 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004787 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4788 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004789 ha->nvram_size = sizeof(struct nvram_24xx);
4790 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004791 if (IS_QLA82XX(ha))
4792 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004793
Seokmann Ju281afe12007-07-26 13:43:34 -07004794 /* Get VPD data into cache */
4795 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004796 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004797 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4798
4799 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004800 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004801 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004802 ha->nvram_size);
4803 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4804 chksum += le32_to_cpu(*dptr++);
4805
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004806 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
4807 "Contents of NVRAM\n");
4808 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
4809 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004810
4811 /* Bad NVRAM data, set defaults parameters. */
4812 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4813 || nv->id[3] != ' ' ||
4814 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4815 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004816 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04004817 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004818 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
4819 ql_log(ql_log_warn, vha, 0x006c,
4820 "Falling back to functioning (yet invalid -- WWPN) "
4821 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07004822
4823 /*
4824 * Set default initialization control block.
4825 */
4826 memset(nv, 0, ha->nvram_size);
4827 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4828 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4829 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4830 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4831 nv->exchange_count = __constant_cpu_to_le16(0);
4832 nv->hard_address = __constant_cpu_to_le16(124);
4833 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004834 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004835 nv->port_name[2] = 0x00;
4836 nv->port_name[3] = 0xe0;
4837 nv->port_name[4] = 0x8b;
4838 nv->port_name[5] = 0x1c;
4839 nv->port_name[6] = 0x55;
4840 nv->port_name[7] = 0x86;
4841 nv->node_name[0] = 0x20;
4842 nv->node_name[1] = 0x00;
4843 nv->node_name[2] = 0x00;
4844 nv->node_name[3] = 0xe0;
4845 nv->node_name[4] = 0x8b;
4846 nv->node_name[5] = 0x1c;
4847 nv->node_name[6] = 0x55;
4848 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004849 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004850 nv->login_retry_count = __constant_cpu_to_le16(8);
4851 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4852 nv->login_timeout = __constant_cpu_to_le16(0);
4853 nv->firmware_options_1 =
4854 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4855 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4856 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4857 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4858 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4859 nv->efi_parameters = __constant_cpu_to_le32(0);
4860 nv->reset_delay = 5;
4861 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4862 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4863 nv->link_down_timeout = __constant_cpu_to_le16(30);
4864
4865 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004866 }
4867
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004868 if (!qla_ini_mode_enabled(vha)) {
4869 /* Don't enable full login after initial LIP */
4870 nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13);
4871 /* Don't enable LIP full login for initiator */
4872 nv->host_p &= __constant_cpu_to_le32(~BIT_10);
4873 }
4874
4875 qlt_24xx_config_nvram_stage1(vha, nv);
4876
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004877 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004878 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004879
4880 /* Copy 1st segment. */
4881 dptr1 = (uint8_t *)icb;
4882 dptr2 = (uint8_t *)&nv->version;
4883 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4884 while (cnt--)
4885 *dptr1++ = *dptr2++;
4886
4887 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004888 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004889
4890 /* Copy 2nd segment. */
4891 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4892 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4893 cnt = (uint8_t *)&icb->reserved_3 -
4894 (uint8_t *)&icb->interrupt_delay_timer;
4895 while (cnt--)
4896 *dptr1++ = *dptr2++;
4897
4898 /*
4899 * Setup driver NVRAM options.
4900 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004901 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004902 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004903
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004904 qlt_24xx_config_nvram_stage2(vha, icb);
4905
Andrew Vasquez5341e862006-05-17 15:09:16 -07004906 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004907 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07004908 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4909 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4910 }
4911
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004912 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004913 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004914 /*
4915 * Firmware will apply the following mask if the nodename was
4916 * not provided.
4917 */
4918 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4919 icb->node_name[0] &= 0xF0;
4920 }
4921
4922 /* Set host adapter parameters. */
4923 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004924 ha->flags.enable_lip_reset = 0;
4925 ha->flags.enable_lip_full_login =
4926 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4927 ha->flags.enable_target_reset =
4928 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004929 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004930 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004931
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004932 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4933 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004934
4935 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4936 sizeof(ha->fw_seriallink_options24));
4937
4938 /* save HBA serial number */
4939 ha->serial0 = icb->port_name[5];
4940 ha->serial1 = icb->port_name[6];
4941 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004942 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4943 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004944
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004945 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4946
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004947 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4948
4949 /* Set minimum login_timeout to 4 seconds. */
4950 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4951 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4952 if (le16_to_cpu(nv->login_timeout) < 4)
4953 nv->login_timeout = __constant_cpu_to_le16(4);
4954 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004955 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004956
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004957 /* Set minimum RATOV to 100 tenths of a second. */
4958 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004959
4960 ha->loop_reset_delay = nv->reset_delay;
4961
4962 /* Link Down Timeout = 0:
4963 *
4964 * When Port Down timer expires we will start returning
4965 * I/O's to OS with "DID_NO_CONNECT".
4966 *
4967 * Link Down Timeout != 0:
4968 *
4969 * The driver waits for the link to come up after link down
4970 * before returning I/Os to OS with "DID_NO_CONNECT".
4971 */
4972 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4973 ha->loop_down_abort_time =
4974 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4975 } else {
4976 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4977 ha->loop_down_abort_time =
4978 (LOOP_DOWN_TIME - ha->link_down_timeout);
4979 }
4980
4981 /* Need enough time to try and get the port back. */
4982 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4983 if (qlport_down_retry)
4984 ha->port_down_retry_count = qlport_down_retry;
4985
4986 /* Set login_retry_count */
4987 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4988 if (ha->port_down_retry_count ==
4989 le16_to_cpu(nv->port_down_retry_count) &&
4990 ha->port_down_retry_count > 3)
4991 ha->login_retry_count = ha->port_down_retry_count;
4992 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4993 ha->login_retry_count = ha->port_down_retry_count;
4994 if (ql2xloginretrycount)
4995 ha->login_retry_count = ql2xloginretrycount;
4996
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004997 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004998 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004999 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5000 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5001 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5002 le16_to_cpu(icb->interrupt_delay_timer): 2;
5003 }
5004 icb->firmware_options_2 &= __constant_cpu_to_le32(
5005 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005006 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005007 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08005008 ha->zio_mode = QLA_ZIO_MODE_6;
5009
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005010 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005011 "ZIO mode %d enabled; timer delay (%d us).\n",
5012 ha->zio_mode, ha->zio_timer * 100);
5013
5014 icb->firmware_options_2 |= cpu_to_le32(
5015 (uint32_t)ha->zio_mode);
5016 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005017 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07005018 }
5019
David Miller4e08df32007-04-16 12:37:43 -07005020 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005021 ql_log(ql_log_warn, vha, 0x0070,
5022 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07005023 }
5024 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005025}
5026
Adrian Bunk413975a2006-06-30 02:33:06 -07005027static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005028qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
5029 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005030{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005031 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005032 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005033 uint32_t *dcode, dlen;
5034 uint32_t risc_addr;
5035 uint32_t risc_size;
5036 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005037 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005038 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005039
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005040 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08005041 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005042
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005043 rval = QLA_SUCCESS;
5044
5045 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005046 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005047 *srisc_addr = 0;
5048
5049 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005050 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005051 for (i = 0; i < 4; i++)
5052 dcode[i] = be32_to_cpu(dcode[i]);
5053 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5054 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5055 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5056 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005057 ql_log(ql_log_fatal, vha, 0x008c,
5058 "Unable to verify the integrity of flash firmware "
5059 "image.\n");
5060 ql_log(ql_log_fatal, vha, 0x008d,
5061 "Firmware data: %08x %08x %08x %08x.\n",
5062 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005063
5064 return QLA_FUNCTION_FAILED;
5065 }
5066
5067 while (segments && rval == QLA_SUCCESS) {
5068 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005069 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005070
5071 risc_addr = be32_to_cpu(dcode[2]);
5072 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5073 risc_size = be32_to_cpu(dcode[3]);
5074
5075 fragment = 0;
5076 while (risc_size > 0 && rval == QLA_SUCCESS) {
5077 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5078 if (dlen > risc_size)
5079 dlen = risc_size;
5080
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005081 ql_dbg(ql_dbg_init, vha, 0x008e,
5082 "Loading risc segment@ risc addr %x "
5083 "number of dwords 0x%x offset 0x%x.\n",
5084 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005085
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005086 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005087 for (i = 0; i < dlen; i++)
5088 dcode[i] = swab32(dcode[i]);
5089
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005090 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005091 dlen);
5092 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005093 ql_log(ql_log_fatal, vha, 0x008f,
5094 "Failed to load segment %d of firmware.\n",
5095 fragment);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005096 break;
5097 }
5098
5099 faddr += dlen;
5100 risc_addr += dlen;
5101 risc_size -= dlen;
5102 fragment++;
5103 }
5104
5105 /* Next segment. */
5106 segments--;
5107 }
5108
5109 return rval;
5110}
5111
Giridhar Malavalie9454a82013-02-08 01:57:47 -05005112#define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005113
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005114int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005115qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08005116{
5117 int rval;
5118 int i, fragment;
5119 uint16_t *wcode, *fwcode;
5120 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
5121 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005122 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005123 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08005124
5125 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005126 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005127 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005128 ql_log(ql_log_info, vha, 0x0083,
5129 "Fimware image unavailable.\n");
5130 ql_log(ql_log_info, vha, 0x0084,
5131 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08005132 return QLA_FUNCTION_FAILED;
5133 }
5134
5135 rval = QLA_SUCCESS;
5136
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005137 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08005138 *srisc_addr = 0;
5139 fwcode = (uint16_t *)blob->fw->data;
5140 fwclen = 0;
5141
5142 /* Validate firmware image by checking version. */
5143 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005144 ql_log(ql_log_fatal, vha, 0x0085,
5145 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005146 blob->fw->size);
5147 goto fail_fw_integrity;
5148 }
5149 for (i = 0; i < 4; i++)
5150 wcode[i] = be16_to_cpu(fwcode[i + 4]);
5151 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
5152 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
5153 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005154 ql_log(ql_log_fatal, vha, 0x0086,
5155 "Unable to verify integrity of firmware image.\n");
5156 ql_log(ql_log_fatal, vha, 0x0087,
5157 "Firmware data: %04x %04x %04x %04x.\n",
5158 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08005159 goto fail_fw_integrity;
5160 }
5161
5162 seg = blob->segs;
5163 while (*seg && rval == QLA_SUCCESS) {
5164 risc_addr = *seg;
5165 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
5166 risc_size = be16_to_cpu(fwcode[3]);
5167
5168 /* Validate firmware image size. */
5169 fwclen += risc_size * sizeof(uint16_t);
5170 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005171 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08005172 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005173 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08005174 goto fail_fw_integrity;
5175 }
5176
5177 fragment = 0;
5178 while (risc_size > 0 && rval == QLA_SUCCESS) {
5179 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
5180 if (wlen > risc_size)
5181 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005182 ql_dbg(ql_dbg_init, vha, 0x0089,
5183 "Loading risc segment@ risc addr %x number of "
5184 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08005185
5186 for (i = 0; i < wlen; i++)
5187 wcode[i] = swab16(fwcode[i]);
5188
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005189 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08005190 wlen);
5191 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005192 ql_log(ql_log_fatal, vha, 0x008a,
5193 "Failed to load segment %d of firmware.\n",
5194 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08005195 break;
5196 }
5197
5198 fwcode += wlen;
5199 risc_addr += wlen;
5200 risc_size -= wlen;
5201 fragment++;
5202 }
5203
5204 /* Next segment. */
5205 seg++;
5206 }
5207 return rval;
5208
5209fail_fw_integrity:
5210 return QLA_FUNCTION_FAILED;
5211}
5212
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005213static int
5214qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005215{
5216 int rval;
5217 int segments, fragment;
5218 uint32_t *dcode, dlen;
5219 uint32_t risc_addr;
5220 uint32_t risc_size;
5221 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08005222 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005223 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005224 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005225 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005226
Andrew Vasquez54333832005-11-09 15:49:04 -08005227 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005228 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005229 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005230 ql_log(ql_log_warn, vha, 0x0090,
5231 "Fimware image unavailable.\n");
5232 ql_log(ql_log_warn, vha, 0x0091,
5233 "Firmware images can be retrieved from: "
5234 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005235
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005236 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005237 }
5238
Chad Dupuiscfb09192011-11-18 09:03:07 -08005239 ql_dbg(ql_dbg_init, vha, 0x0092,
5240 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005241
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005242 rval = QLA_SUCCESS;
5243
5244 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005245 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005246 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08005247 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005248 fwclen = 0;
5249
5250 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08005251 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005252 ql_log(ql_log_fatal, vha, 0x0093,
5253 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005254 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005255 goto fail_fw_integrity;
5256 }
5257 for (i = 0; i < 4; i++)
5258 dcode[i] = be32_to_cpu(fwcode[i + 4]);
5259 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5260 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5261 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5262 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005263 ql_log(ql_log_fatal, vha, 0x0094,
5264 "Unable to verify integrity of firmware image (%Zd).\n",
5265 blob->fw->size);
5266 ql_log(ql_log_fatal, vha, 0x0095,
5267 "Firmware data: %08x %08x %08x %08x.\n",
5268 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005269 goto fail_fw_integrity;
5270 }
5271
5272 while (segments && rval == QLA_SUCCESS) {
5273 risc_addr = be32_to_cpu(fwcode[2]);
5274 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5275 risc_size = be32_to_cpu(fwcode[3]);
5276
5277 /* Validate firmware image size. */
5278 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08005279 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005280 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08005281 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005282 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08005283
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005284 goto fail_fw_integrity;
5285 }
5286
5287 fragment = 0;
5288 while (risc_size > 0 && rval == QLA_SUCCESS) {
5289 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5290 if (dlen > risc_size)
5291 dlen = risc_size;
5292
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005293 ql_dbg(ql_dbg_init, vha, 0x0097,
5294 "Loading risc segment@ risc addr %x "
5295 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005296
5297 for (i = 0; i < dlen; i++)
5298 dcode[i] = swab32(fwcode[i]);
5299
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005300 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08005301 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005302 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005303 ql_log(ql_log_fatal, vha, 0x0098,
5304 "Failed to load segment %d of firmware.\n",
5305 fragment);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005306 break;
5307 }
5308
5309 fwcode += dlen;
5310 risc_addr += dlen;
5311 risc_size -= dlen;
5312 fragment++;
5313 }
5314
5315 /* Next segment. */
5316 segments--;
5317 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005318 return rval;
5319
5320fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005321 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005322}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005323
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005324int
5325qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5326{
5327 int rval;
5328
Andrew Vasqueze337d902009-04-06 22:33:49 -07005329 if (ql2xfwloadbin == 1)
5330 return qla81xx_load_risc(vha, srisc_addr);
5331
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005332 /*
5333 * FW Load priority:
5334 * 1) Firmware via request-firmware interface (.bin file).
5335 * 2) Firmware residing in flash.
5336 */
5337 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5338 if (rval == QLA_SUCCESS)
5339 return rval;
5340
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005341 return qla24xx_load_risc_flash(vha, srisc_addr,
5342 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005343}
5344
5345int
5346qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5347{
5348 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005349 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005350
Andrew Vasqueze337d902009-04-06 22:33:49 -07005351 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005352 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07005353
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005354 /*
5355 * FW Load priority:
5356 * 1) Firmware residing in flash.
5357 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005358 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005359 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005360 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005361 if (rval == QLA_SUCCESS)
5362 return rval;
5363
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005364try_blob_fw:
5365 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5366 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
5367 return rval;
5368
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005369 ql_log(ql_log_info, vha, 0x0099,
5370 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005371 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
5372 if (rval != QLA_SUCCESS)
5373 return rval;
5374
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005375 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005376 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005377 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005378}
5379
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005380void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005381qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005382{
5383 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005384 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005385
Andrew Vasquez85880802009-12-15 21:29:46 -08005386 if (ha->flags.pci_channel_io_perm_failure)
5387 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07005388 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005389 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07005390 if (!ha->fw_major_version)
5391 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005392
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005393 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08005394 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07005395 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005396 ha->isp_ops->reset_chip(vha);
5397 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005398 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005399 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005400 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005401 ql_log(ql_log_info, vha, 0x8015,
5402 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005403 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005404 }
5405}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005406
5407int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005408qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005409{
5410 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08005411 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005412 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005413 struct qla_hw_data *ha = vha->hw;
5414 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005415 struct req_que *req;
5416 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005417
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005418 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005419 return -EINVAL;
5420
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005421 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07005422 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005423 req = ha->req_q_map[0];
5424 else
5425 req = vha->req;
5426 rsp = req->rsp;
5427
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005428 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005429 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005430 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005431 }
5432
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005433 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005434
5435 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08005436 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
5437 BIT_1);
5438 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5439 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
5440 ql_dbg(ql_dbg_init, vha, 0x0120,
5441 "Failed SNS login: loop_id=%x, rval2=%d\n",
5442 NPH_SNS, rval2);
5443 else
5444 ql_dbg(ql_dbg_init, vha, 0x0103,
5445 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5446 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
5447 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005448 return (QLA_FUNCTION_FAILED);
5449 }
5450
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005451 atomic_set(&vha->loop_down_timer, 0);
5452 atomic_set(&vha->loop_state, LOOP_UP);
5453 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5454 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5455 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005456
5457 return rval;
5458}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005459
5460/* 84XX Support **************************************************************/
5461
5462static LIST_HEAD(qla_cs84xx_list);
5463static DEFINE_MUTEX(qla_cs84xx_mutex);
5464
5465static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005466qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005467{
5468 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005469 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005470
5471 mutex_lock(&qla_cs84xx_mutex);
5472
5473 /* Find any shared 84xx chip. */
5474 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5475 if (cs84xx->bus == ha->pdev->bus) {
5476 kref_get(&cs84xx->kref);
5477 goto done;
5478 }
5479 }
5480
5481 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5482 if (!cs84xx)
5483 goto done;
5484
5485 kref_init(&cs84xx->kref);
5486 spin_lock_init(&cs84xx->access_lock);
5487 mutex_init(&cs84xx->fw_update_mutex);
5488 cs84xx->bus = ha->pdev->bus;
5489
5490 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5491done:
5492 mutex_unlock(&qla_cs84xx_mutex);
5493 return cs84xx;
5494}
5495
5496static void
5497__qla84xx_chip_release(struct kref *kref)
5498{
5499 struct qla_chip_state_84xx *cs84xx =
5500 container_of(kref, struct qla_chip_state_84xx, kref);
5501
5502 mutex_lock(&qla_cs84xx_mutex);
5503 list_del(&cs84xx->list);
5504 mutex_unlock(&qla_cs84xx_mutex);
5505 kfree(cs84xx);
5506}
5507
5508void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005509qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005510{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005511 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005512 if (ha->cs84xx)
5513 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
5514}
5515
5516static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005517qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005518{
5519 int rval;
5520 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005521 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005522
5523 mutex_lock(&ha->cs84xx->fw_update_mutex);
5524
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005525 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005526
5527 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5528
5529 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5530 QLA_SUCCESS;
5531}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005532
5533/* 81XX Support **************************************************************/
5534
5535int
5536qla81xx_nvram_config(scsi_qla_host_t *vha)
5537{
5538 int rval;
5539 struct init_cb_81xx *icb;
5540 struct nvram_81xx *nv;
5541 uint32_t *dptr;
5542 uint8_t *dptr1, *dptr2;
5543 uint32_t chksum;
5544 uint16_t cnt;
5545 struct qla_hw_data *ha = vha->hw;
5546
5547 rval = QLA_SUCCESS;
5548 icb = (struct init_cb_81xx *)ha->init_cb;
5549 nv = ha->nvram;
5550
5551 /* Determine NVRAM starting address. */
5552 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005553 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005554
5555 /* Get VPD data into cache */
5556 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005557 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5558 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005559
5560 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005561 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005562 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005563 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005564 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5565 chksum += le32_to_cpu(*dptr++);
5566
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005567 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
5568 "Contents of NVRAM:\n");
5569 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
5570 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005571
5572 /* Bad NVRAM data, set defaults parameters. */
5573 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5574 || nv->id[3] != ' ' ||
5575 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5576 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005577 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04005578 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005579 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005580 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005581 ql_log(ql_log_info, vha, 0x0074,
5582 "Falling back to functioning (yet invalid -- WWPN) "
5583 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005584
5585 /*
5586 * Set default initialization control block.
5587 */
5588 memset(nv, 0, ha->nvram_size);
5589 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5590 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5591 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5592 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5593 nv->exchange_count = __constant_cpu_to_le16(0);
5594 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005595 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005596 nv->port_name[2] = 0x00;
5597 nv->port_name[3] = 0xe0;
5598 nv->port_name[4] = 0x8b;
5599 nv->port_name[5] = 0x1c;
5600 nv->port_name[6] = 0x55;
5601 nv->port_name[7] = 0x86;
5602 nv->node_name[0] = 0x20;
5603 nv->node_name[1] = 0x00;
5604 nv->node_name[2] = 0x00;
5605 nv->node_name[3] = 0xe0;
5606 nv->node_name[4] = 0x8b;
5607 nv->node_name[5] = 0x1c;
5608 nv->node_name[6] = 0x55;
5609 nv->node_name[7] = 0x86;
5610 nv->login_retry_count = __constant_cpu_to_le16(8);
5611 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5612 nv->login_timeout = __constant_cpu_to_le16(0);
5613 nv->firmware_options_1 =
5614 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5615 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5616 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5617 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5618 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5619 nv->efi_parameters = __constant_cpu_to_le32(0);
5620 nv->reset_delay = 5;
5621 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5622 nv->port_down_retry_count = __constant_cpu_to_le16(30);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005623 nv->link_down_timeout = __constant_cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005624 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005625 nv->enode_mac[1] = 0xC0;
5626 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005627 nv->enode_mac[3] = 0x04;
5628 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005629 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005630
5631 rval = 1;
5632 }
5633
Arun Easi9e522cd2012-08-22 14:21:31 -04005634 if (IS_T10_PI_CAPABLE(ha))
5635 nv->frame_payload_size &= ~7;
5636
Arun Easiaa230bc2013-01-30 03:34:39 -05005637 qlt_81xx_config_nvram_stage1(vha, nv);
5638
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005639 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07005640 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005641
5642 /* Copy 1st segment. */
5643 dptr1 = (uint8_t *)icb;
5644 dptr2 = (uint8_t *)&nv->version;
5645 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5646 while (cnt--)
5647 *dptr1++ = *dptr2++;
5648
5649 icb->login_retry_count = nv->login_retry_count;
5650
5651 /* Copy 2nd segment. */
5652 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5653 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5654 cnt = (uint8_t *)&icb->reserved_5 -
5655 (uint8_t *)&icb->interrupt_delay_timer;
5656 while (cnt--)
5657 *dptr1++ = *dptr2++;
5658
5659 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5660 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5661 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08005662 icb->enode_mac[0] = 0x00;
5663 icb->enode_mac[1] = 0xC0;
5664 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005665 icb->enode_mac[3] = 0x04;
5666 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005667 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005668 }
5669
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005670 /* Use extended-initialization control block. */
5671 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5672
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005673 /*
5674 * Setup driver NVRAM options.
5675 */
5676 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005677 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005678
Arun Easiaa230bc2013-01-30 03:34:39 -05005679 qlt_81xx_config_nvram_stage2(vha, icb);
5680
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005681 /* Use alternate WWN? */
5682 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5683 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5684 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5685 }
5686
5687 /* Prepare nodename */
5688 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5689 /*
5690 * Firmware will apply the following mask if the nodename was
5691 * not provided.
5692 */
5693 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5694 icb->node_name[0] &= 0xF0;
5695 }
5696
5697 /* Set host adapter parameters. */
5698 ha->flags.disable_risc_code_load = 0;
5699 ha->flags.enable_lip_reset = 0;
5700 ha->flags.enable_lip_full_login =
5701 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5702 ha->flags.enable_target_reset =
5703 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5704 ha->flags.enable_led_scheme = 0;
5705 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5706
5707 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5708 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5709
5710 /* save HBA serial number */
5711 ha->serial0 = icb->port_name[5];
5712 ha->serial1 = icb->port_name[6];
5713 ha->serial2 = icb->port_name[7];
5714 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5715 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5716
5717 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5718
5719 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5720
5721 /* Set minimum login_timeout to 4 seconds. */
5722 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5723 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5724 if (le16_to_cpu(nv->login_timeout) < 4)
5725 nv->login_timeout = __constant_cpu_to_le16(4);
5726 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5727 icb->login_timeout = nv->login_timeout;
5728
5729 /* Set minimum RATOV to 100 tenths of a second. */
5730 ha->r_a_tov = 100;
5731
5732 ha->loop_reset_delay = nv->reset_delay;
5733
5734 /* Link Down Timeout = 0:
5735 *
5736 * When Port Down timer expires we will start returning
5737 * I/O's to OS with "DID_NO_CONNECT".
5738 *
5739 * Link Down Timeout != 0:
5740 *
5741 * The driver waits for the link to come up after link down
5742 * before returning I/Os to OS with "DID_NO_CONNECT".
5743 */
5744 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5745 ha->loop_down_abort_time =
5746 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5747 } else {
5748 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5749 ha->loop_down_abort_time =
5750 (LOOP_DOWN_TIME - ha->link_down_timeout);
5751 }
5752
5753 /* Need enough time to try and get the port back. */
5754 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5755 if (qlport_down_retry)
5756 ha->port_down_retry_count = qlport_down_retry;
5757
5758 /* Set login_retry_count */
5759 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5760 if (ha->port_down_retry_count ==
5761 le16_to_cpu(nv->port_down_retry_count) &&
5762 ha->port_down_retry_count > 3)
5763 ha->login_retry_count = ha->port_down_retry_count;
5764 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5765 ha->login_retry_count = ha->port_down_retry_count;
5766 if (ql2xloginretrycount)
5767 ha->login_retry_count = ql2xloginretrycount;
5768
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005769 /* if not running MSI-X we need handshaking on interrupts */
5770 if (!vha->hw->flags.msix_enabled && IS_QLA83XX(ha))
5771 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
5772
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005773 /* Enable ZIO. */
5774 if (!vha->flags.init_done) {
5775 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5776 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5777 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5778 le16_to_cpu(icb->interrupt_delay_timer): 2;
5779 }
5780 icb->firmware_options_2 &= __constant_cpu_to_le32(
5781 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5782 vha->flags.process_response_queue = 0;
5783 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5784 ha->zio_mode = QLA_ZIO_MODE_6;
5785
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005786 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005787 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005788 ha->zio_mode,
5789 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005790
5791 icb->firmware_options_2 |= cpu_to_le32(
5792 (uint32_t)ha->zio_mode);
5793 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5794 vha->flags.process_response_queue = 1;
5795 }
5796
5797 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005798 ql_log(ql_log_warn, vha, 0x0076,
5799 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005800 }
5801 return (rval);
5802}
5803
Giridhar Malavalia9083012010-04-12 17:59:55 -07005804int
5805qla82xx_restart_isp(scsi_qla_host_t *vha)
5806{
5807 int status, rval;
5808 uint32_t wait_time;
5809 struct qla_hw_data *ha = vha->hw;
5810 struct req_que *req = ha->req_q_map[0];
5811 struct rsp_que *rsp = ha->rsp_q_map[0];
5812 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005813 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005814
5815 status = qla2x00_init_rings(vha);
5816 if (!status) {
5817 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5818 ha->flags.chip_reset_done = 1;
5819
5820 status = qla2x00_fw_ready(vha);
5821 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005822 ql_log(ql_log_info, vha, 0x803c,
5823 "Start configure loop, status =%d.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005824
5825 /* Issue a marker after FW becomes ready. */
5826 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5827
5828 vha->flags.online = 1;
5829 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5830 wait_time = 256;
5831 do {
5832 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5833 qla2x00_configure_loop(vha);
5834 wait_time--;
5835 } while (!atomic_read(&vha->loop_down_timer) &&
5836 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5837 wait_time &&
5838 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5839 }
5840
5841 /* if no cable then assume it's good */
5842 if ((vha->device_flags & DFLG_NO_CABLE))
5843 status = 0;
5844
Chad Dupuiscfb09192011-11-18 09:03:07 -08005845 ql_log(ql_log_info, vha, 0x8000,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005846 "Configure loop done, status = 0x%x.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005847 }
5848
5849 if (!status) {
5850 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5851
5852 if (!atomic_read(&vha->loop_down_timer)) {
5853 /*
5854 * Issue marker command only when we are going
5855 * to start the I/O .
5856 */
5857 vha->marker_needed = 1;
5858 }
5859
5860 vha->flags.online = 1;
5861
5862 ha->isp_ops->enable_intrs(ha);
5863
5864 ha->isp_abort_cnt = 0;
5865 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5866
Saurav Kashyap53296782011-05-10 11:30:06 -07005867 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07005868 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07005869
Giridhar Malavalia9083012010-04-12 17:59:55 -07005870 if (ha->fce) {
5871 ha->flags.fce_enabled = 1;
5872 memset(ha->fce, 0,
5873 fce_calc_size(ha->fce_bufs));
5874 rval = qla2x00_enable_fce_trace(vha,
5875 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5876 &ha->fce_bufs);
5877 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005878 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005879 "Unable to reinitialize FCE (%d).\n",
5880 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005881 ha->flags.fce_enabled = 0;
5882 }
5883 }
5884
5885 if (ha->eft) {
5886 memset(ha->eft, 0, EFT_SIZE);
5887 rval = qla2x00_enable_eft_trace(vha,
5888 ha->eft_dma, EFT_NUM_BUFFERS);
5889 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005890 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005891 "Unable to reinitialize EFT (%d).\n",
5892 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005893 }
5894 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005895 }
5896
5897 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005898 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005899 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07005900
5901 spin_lock_irqsave(&ha->vport_slock, flags);
5902 list_for_each_entry(vp, &ha->vp_list, list) {
5903 if (vp->vp_idx) {
5904 atomic_inc(&vp->vref_count);
5905 spin_unlock_irqrestore(&ha->vport_slock, flags);
5906
Giridhar Malavalia9083012010-04-12 17:59:55 -07005907 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07005908
5909 spin_lock_irqsave(&ha->vport_slock, flags);
5910 atomic_dec(&vp->vref_count);
5911 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005912 }
Arun Easifeafb7b2010-09-03 14:57:00 -07005913 spin_unlock_irqrestore(&ha->vport_slock, flags);
5914
Giridhar Malavalia9083012010-04-12 17:59:55 -07005915 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005916 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005917 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005918 }
5919
5920 return status;
5921}
5922
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005923void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005924qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005925{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005926 struct qla_hw_data *ha = vha->hw;
5927
5928 if (!ql2xetsenable)
5929 return;
5930
5931 /* Enable ETS Burst. */
5932 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5933 ha->fw_options[2] |= BIT_9;
5934 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005935}
Sarang Radke09ff7012010-03-19 17:03:59 -07005936
5937/*
5938 * qla24xx_get_fcp_prio
5939 * Gets the fcp cmd priority value for the logged in port.
5940 * Looks for a match of the port descriptors within
5941 * each of the fcp prio config entries. If a match is found,
5942 * the tag (priority) value is returned.
5943 *
5944 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005945 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005946 * fcport = port structure pointer.
5947 *
5948 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005949 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005950 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005951 *
5952 * Context:
5953 * Kernel context
5954 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005955static int
Sarang Radke09ff7012010-03-19 17:03:59 -07005956qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5957{
5958 int i, entries;
5959 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005960 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005961 uint32_t pid1, pid2;
5962 uint64_t wwn1, wwn2;
5963 struct qla_fcp_prio_entry *pri_entry;
5964 struct qla_hw_data *ha = vha->hw;
5965
5966 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005967 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005968
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005969 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005970 entries = ha->fcp_prio_cfg->num_entries;
5971 pri_entry = &ha->fcp_prio_cfg->entry[0];
5972
5973 for (i = 0; i < entries; i++) {
5974 pid_match = wwn_match = 0;
5975
5976 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5977 pri_entry++;
5978 continue;
5979 }
5980
5981 /* check source pid for a match */
5982 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5983 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5984 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5985 if (pid1 == INVALID_PORT_ID)
5986 pid_match++;
5987 else if (pid1 == pid2)
5988 pid_match++;
5989 }
5990
5991 /* check destination pid for a match */
5992 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5993 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5994 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5995 if (pid1 == INVALID_PORT_ID)
5996 pid_match++;
5997 else if (pid1 == pid2)
5998 pid_match++;
5999 }
6000
6001 /* check source WWN for a match */
6002 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
6003 wwn1 = wwn_to_u64(vha->port_name);
6004 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
6005 if (wwn2 == (uint64_t)-1)
6006 wwn_match++;
6007 else if (wwn1 == wwn2)
6008 wwn_match++;
6009 }
6010
6011 /* check destination WWN for a match */
6012 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
6013 wwn1 = wwn_to_u64(fcport->port_name);
6014 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
6015 if (wwn2 == (uint64_t)-1)
6016 wwn_match++;
6017 else if (wwn1 == wwn2)
6018 wwn_match++;
6019 }
6020
6021 if (pid_match == 2 || wwn_match == 2) {
6022 /* Found a matching entry */
6023 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
6024 priority = pri_entry->tag;
6025 break;
6026 }
6027
6028 pri_entry++;
6029 }
6030
6031 return priority;
6032}
6033
6034/*
6035 * qla24xx_update_fcport_fcp_prio
6036 * Activates fcp priority for the logged in fc port
6037 *
6038 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006039 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07006040 * fcp = port structure pointer.
6041 *
6042 * Return:
6043 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6044 *
6045 * Context:
6046 * Kernel context.
6047 */
6048int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006049qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07006050{
6051 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006052 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07006053 uint16_t mb[5];
6054
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006055 if (fcport->port_type != FCT_TARGET ||
6056 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07006057 return QLA_FUNCTION_FAILED;
6058
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006059 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07006060 if (priority < 0)
6061 return QLA_FUNCTION_FAILED;
6062
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006063 if (IS_QLA82XX(vha->hw)) {
6064 fcport->fcp_prio = priority & 0xf;
6065 return QLA_SUCCESS;
6066 }
6067
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08006068 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08006069 if (ret == QLA_SUCCESS) {
6070 if (fcport->fcp_prio != priority)
6071 ql_dbg(ql_dbg_user, vha, 0x709e,
6072 "Updated FCP_CMND priority - value=%d loop_id=%d "
6073 "port_id=%02x%02x%02x.\n", priority,
6074 fcport->loop_id, fcport->d_id.b.domain,
6075 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08006076 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08006077 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07006078 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08006079 "Unable to update FCP_CMND priority - ret=0x%x for "
6080 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
6081 fcport->d_id.b.domain, fcport->d_id.b.area,
6082 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07006083 return ret;
6084}
6085
6086/*
6087 * qla24xx_update_all_fcp_prio
6088 * Activates fcp priority for all the logged in ports
6089 *
6090 * Input:
6091 * ha = adapter block pointer.
6092 *
6093 * Return:
6094 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6095 *
6096 * Context:
6097 * Kernel context.
6098 */
6099int
6100qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
6101{
6102 int ret;
6103 fc_port_t *fcport;
6104
6105 ret = QLA_FUNCTION_FAILED;
6106 /* We need to set priority for all logged in ports */
6107 list_for_each_entry(fcport, &vha->vp_fcports, list)
6108 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
6109
6110 return ret;
6111}