blob: 290052352619e432cb400d115d7d2191f7959914 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez07e264b2011-03-30 11:46:23 -07003 * Copyright (c) 2003-2011 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);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080073 mempool_free(sp, vha->hw->srb_mempool);
Arun Easifeafb7b2010-09-03 14:57:00 -070074
75 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquezac280b62009-08-20 11:06:05 -070076}
77
Andrew Vasquezac280b62009-08-20 11:06:05 -070078/* Asynchronous Login/Logout Routines -------------------------------------- */
79
Andrew Vasquez5b914902010-05-28 15:08:30 -070080static inline unsigned long
81qla2x00_get_async_timeout(struct scsi_qla_host *vha)
82{
83 unsigned long tmo;
84 struct qla_hw_data *ha = vha->hw;
85
86 /* Firmware should use switch negotiated r_a_tov for timeout. */
87 tmo = ha->r_a_tov / 10 * 2;
88 if (!IS_FWI2_CAPABLE(ha)) {
89 /*
90 * Except for earlier ISPs where the timeout is seeded from the
91 * initialization control block.
92 */
93 tmo = ha->login_timeout;
94 }
95 return tmo;
96}
Andrew Vasquezac280b62009-08-20 11:06:05 -070097
98static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -080099qla2x00_async_iocb_timeout(void *data)
Andrew Vasquezac280b62009-08-20 11:06:05 -0700100{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800101 srb_t *sp = (srb_t *)data;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700102 fc_port_t *fcport = sp->fcport;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700103
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700104 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800105 "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800106 sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700107 fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700108
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700109 fcport->flags &= ~FCF_ASYNC_SENT;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800110 if (sp->type == SRB_LOGIN_CMD) {
111 struct srb_iocb *lio = &sp->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700112 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700113 /* Retry as needed. */
114 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
115 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
116 QLA_LOGIO_LOGIN_RETRIED : 0;
117 qla2x00_post_async_login_done_work(fcport->vha, fcport,
118 lio->u.logio.data);
119 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700120}
121
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700122static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800123qla2x00_async_login_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700124{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800125 srb_t *sp = (srb_t *)ptr;
126 struct srb_iocb *lio = &sp->u.iocb_cmd;
127 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700128
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800129 if (!test_bit(UNLOADING, &vha->dpc_flags))
130 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
131 lio->u.logio.data);
132 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700133}
134
Andrew Vasquezac280b62009-08-20 11:06:05 -0700135int
136qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
137 uint16_t *data)
138{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700139 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700140 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700141 int rval;
142
143 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800144 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700145 if (!sp)
146 goto done;
147
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800148 sp->type = SRB_LOGIN_CMD;
149 sp->name = "login";
150 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
151
152 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700153 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800154 sp->done = qla2x00_async_login_sp_done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700155 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700156 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700157 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700158 rval = qla2x00_start_sp(sp);
159 if (rval != QLA_SUCCESS)
160 goto done_free_sp;
161
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700162 ql_dbg(ql_dbg_disc, vha, 0x2072,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800163 "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
164 "retries=%d.\n", sp->handle, fcport->loop_id,
165 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
166 fcport->login_retry);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700167 return rval;
168
169done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800170 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700171done:
172 return rval;
173}
174
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700175static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800176qla2x00_async_logout_sp_done(void *data, void *ptr, int res)
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700177{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800178 srb_t *sp = (srb_t *)ptr;
179 struct srb_iocb *lio = &sp->u.iocb_cmd;
180 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700181
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800182 if (!test_bit(UNLOADING, &vha->dpc_flags))
183 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
184 lio->u.logio.data);
185 sp->free(sp->fcport->vha, sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700186}
187
Andrew Vasquezac280b62009-08-20 11:06:05 -0700188int
189qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
190{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700191 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700192 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700193 int rval;
194
195 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800196 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700197 if (!sp)
198 goto done;
199
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800200 sp->type = SRB_LOGOUT_CMD;
201 sp->name = "logout";
202 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
203
204 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700205 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800206 sp->done = qla2x00_async_logout_sp_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700207 rval = qla2x00_start_sp(sp);
208 if (rval != QLA_SUCCESS)
209 goto done_free_sp;
210
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700211 ql_dbg(ql_dbg_disc, vha, 0x2070,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800212 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
213 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
214 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700215 return rval;
216
217done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800218 sp->free(fcport->vha, sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700219done:
220 return rval;
221}
222
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700223static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800224qla2x00_async_adisc_sp_done(void *data, void *ptr, int res)
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700225{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800226 srb_t *sp = (srb_t *)ptr;
227 struct srb_iocb *lio = &sp->u.iocb_cmd;
228 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700229
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800230 if (!test_bit(UNLOADING, &vha->dpc_flags))
231 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
232 lio->u.logio.data);
233 sp->free(sp->fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700234}
235
236int
237qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
238 uint16_t *data)
239{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700240 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700241 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700242 int rval;
243
244 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800245 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700246 if (!sp)
247 goto done;
248
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800249 sp->type = SRB_ADISC_CMD;
250 sp->name = "adisc";
251 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
252
253 lio = &sp->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700254 lio->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800255 sp->done = qla2x00_async_adisc_sp_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700256 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700257 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700258 rval = qla2x00_start_sp(sp);
259 if (rval != QLA_SUCCESS)
260 goto done_free_sp;
261
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700262 ql_dbg(ql_dbg_disc, vha, 0x206f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800263 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
264 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
265 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700266 return rval;
267
268done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800269 sp->free(fcport->vha, sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700270done:
271 return rval;
272}
273
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700274static void
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800275qla2x00_async_tm_cmd_done(void *data, void *ptr, int res)
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700276{
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800277 srb_t *sp = (srb_t *)ptr;
278 struct srb_iocb *iocb = &sp->u.iocb_cmd;
279 struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
280 uint32_t flags;
281 uint16_t lun;
282 int rval;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700283
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800284 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
285 flags = iocb->u.tmf.flags;
286 lun = (uint16_t)iocb->u.tmf.lun;
287
288 /* Issue Marker IOCB */
289 rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
290 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
291 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
292
293 if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
294 ql_dbg(ql_dbg_taskm, vha, 0x8030,
295 "TM IOCB failed (%x).\n", rval);
296 }
297 }
298 sp->free(sp->fcport->vha, sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700299}
300
301int
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800302qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t tm_flags, uint32_t lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700303 uint32_t tag)
304{
305 struct scsi_qla_host *vha = fcport->vha;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700306 srb_t *sp;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700307 struct srb_iocb *tcf;
308 int rval;
309
310 rval = QLA_FUNCTION_FAILED;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800311 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700312 if (!sp)
313 goto done;
314
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800315 sp->type = SRB_TM_CMD;
316 sp->name = "tmf";
317 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
318
319 tcf = &sp->u.iocb_cmd;
320 tcf->u.tmf.flags = tm_flags;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700321 tcf->u.tmf.lun = lun;
322 tcf->u.tmf.data = tag;
323 tcf->timeout = qla2x00_async_iocb_timeout;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800324 sp->done = qla2x00_async_tm_cmd_done;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700325
326 rval = qla2x00_start_sp(sp);
327 if (rval != QLA_SUCCESS)
328 goto done_free_sp;
329
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700330 ql_dbg(ql_dbg_taskm, vha, 0x802f,
Chad Dupuiscfb09192011-11-18 09:03:07 -0800331 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
332 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
333 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700334 return rval;
335
336done_free_sp:
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800337 sp->free(fcport->vha, sp);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700338done:
339 return rval;
340}
341
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700342void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700343qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
344 uint16_t *data)
345{
346 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700347
348 switch (data[0]) {
349 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700350 /*
351 * Driver must validate login state - If PRLI not complete,
352 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
353 * requests.
354 */
355 rval = qla2x00_get_port_database(vha, fcport, 0);
Arun Easi0eba25d2012-02-09 11:15:58 -0800356 if (rval == QLA_NOT_LOGGED_IN) {
357 fcport->flags &= ~FCF_ASYNC_SENT;
358 fcport->flags |= FCF_LOGIN_NEEDED;
359 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
360 break;
361 }
362
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700363 if (rval != QLA_SUCCESS) {
364 qla2x00_post_async_logout_work(vha, fcport, NULL);
365 qla2x00_post_async_login_work(vha, fcport, NULL);
366 break;
367 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700368 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700369 qla2x00_post_async_adisc_work(vha, fcport, data);
370 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700371 }
372 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700373 break;
374 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700375 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700376 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
377 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
378 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700379 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700380 break;
381 case MBS_PORT_ID_USED:
382 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700383 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700384 qla2x00_post_async_login_work(vha, fcport, NULL);
385 break;
386 case MBS_LOOP_ID_USED:
387 fcport->loop_id++;
388 rval = qla2x00_find_new_loop_id(vha, fcport);
389 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700390 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez80d79442011-03-30 11:46:17 -0700391 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700392 break;
393 }
394 qla2x00_post_async_login_work(vha, fcport, NULL);
395 break;
396 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700397 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700398}
399
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700400void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700401qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
402 uint16_t *data)
403{
404 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700405 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700406}
407
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700408void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700409qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
410 uint16_t *data)
411{
412 if (data[0] == MBS_COMMAND_COMPLETE) {
413 qla2x00_update_fcport(vha, fcport);
414
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700415 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700416 }
417
418 /* Retry login. */
419 fcport->flags &= ~FCF_ASYNC_SENT;
420 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
421 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
422 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700423 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700424
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700425 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700426}
427
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428/****************************************************************************/
429/* QLogic ISP2x00 Hardware Support Functions. */
430/****************************************************************************/
431
432/*
433* qla2x00_initialize_adapter
434* Initialize board.
435*
436* Input:
437* ha = adapter block pointer.
438*
439* Returns:
440* 0 = success
441*/
442int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800443qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
445 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800446 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800447 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800450 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700451 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800452 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800453 ha->flags.pci_channel_io_perm_failure = 0;
454 ha->flags.eeh_busy = 0;
Andrew Vasquez794a5692010-12-21 16:00:21 -0800455 ha->flags.thermal_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800456 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
457 atomic_set(&vha->loop_state, LOOP_DOWN);
458 vha->device_flags = DFLG_NO_CABLE;
459 vha->dpc_flags = 0;
460 vha->flags.management_server_logged_in = 0;
461 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 ha->isp_abort_cnt = 0;
463 ha->beacon_blink_led = 0;
464
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800465 set_bit(0, ha->req_qid_map);
466 set_bit(0, ha->rsp_qid_map);
467
Chad Dupuiscfb09192011-11-18 09:03:07 -0800468 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700469 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800470 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700472 ql_log(ql_log_warn, vha, 0x0044,
473 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 return (rval);
475 }
476
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800477 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800479 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700480 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700481 ql_log(ql_log_fatal, vha, 0x004f,
482 "Unable to validate FLASH data.\n");
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700483 return (rval);
484 }
485
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800486 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -0800487 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700488 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700489
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800490 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700492 if (ha->flags.disable_serdes) {
493 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700494 ql_log(ql_log_info, vha, 0x0077,
495 "Masking HBA WWPN "
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700496 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800497 vha->port_name[0], vha->port_name[1],
498 vha->port_name[2], vha->port_name[3],
499 vha->port_name[4], vha->port_name[5],
500 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700501 return QLA_FUNCTION_FAILED;
502 }
503
Chad Dupuiscfb09192011-11-18 09:03:07 -0800504 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700505 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800507 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
508 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800509 if (rval)
510 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800511 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800512 if (rval)
513 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700515
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700516 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800517 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700518 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700519 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700520 "Unable to configure ISP84XX.\n");
521 return QLA_FUNCTION_FAILED;
522 }
523 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400524
525 if (qla_ini_mode_enabled(vha))
526 rval = qla2x00_init_rings(vha);
527
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700528 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800530 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700531 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800532 rval = qla84xx_init_chip(vha);
533 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700534 ql_log(ql_log_warn, vha, 0x00d4,
535 "Unable to initialize ISP84XX.\n");
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800536 qla84xx_put_chip(vha);
537 }
538 }
539
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500540 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
541 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 return (rval);
544}
545
546/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700547 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 * @ha: HA context
549 *
550 * Returns 0 on success.
551 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700552int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800553qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700555 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700556 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800557 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700558 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700561 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700564 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
566
Andrew Vasquez737faec2008-10-24 15:13:45 -0700567 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700569 /* Get PCI bus information. */
570 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700571 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700572 spin_unlock_irqrestore(&ha->hardware_lock, flags);
573
574 return QLA_SUCCESS;
575}
576
577/**
578 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
579 * @ha: HA context
580 *
581 * Returns 0 on success.
582 */
583int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800584qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700585{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700586 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700587 unsigned long flags = 0;
588 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800589 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700590 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700591
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700592 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700593 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700594
595 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700596 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700597
598 if (IS_QLA2322(ha) || IS_QLA6322(ha))
599 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700600 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700601
602 /*
603 * If this is a 2300 card and not 2312, reset the
604 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
605 * the 2310 also reports itself as a 2300 so we need to get the
606 * fb revision level -- a 6 indicates it really is a 2300 and
607 * not a 2310.
608 */
609 if (IS_QLA2300(ha)) {
610 spin_lock_irqsave(&ha->hardware_lock, flags);
611
612 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700613 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700614 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700615 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700616 break;
617
618 udelay(10);
619 }
620
621 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700622 WRT_REG_WORD(&reg->ctrl_status, 0x20);
623 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700624
625 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700626 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700627
628 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700629 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700630
631 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700632 WRT_REG_WORD(&reg->ctrl_status, 0x0);
633 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700634
635 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700636 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700637 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700638 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700639 break;
640
641 udelay(10);
642 }
643
644 spin_unlock_irqrestore(&ha->hardware_lock, flags);
645 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700646
647 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
648
Andrew Vasquez737faec2008-10-24 15:13:45 -0700649 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700650
651 /* Get PCI bus information. */
652 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700653 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700654 spin_unlock_irqrestore(&ha->hardware_lock, flags);
655
656 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657}
658
659/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700660 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
661 * @ha: HA context
662 *
663 * Returns 0 on success.
664 */
665int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800666qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700667{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700668 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700669 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800670 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700671 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700672
673 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700674 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -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 Vasquez0107109e2005-07-06 10:31:37 -0700678 w &= ~PCI_COMMAND_INTX_DISABLE;
679 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
680
681 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
682
683 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700684 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
685 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700686
687 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700688 if (pci_is_pcie(ha->pdev))
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700689 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700690
Andrew Vasquez737faec2008-10-24 15:13:45 -0700691 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700692
Auke Kok44c10132007-06-08 15:46:36 -0700693 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800694
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700695 /* Get PCI bus information. */
696 spin_lock_irqsave(&ha->hardware_lock, flags);
697 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
698 spin_unlock_irqrestore(&ha->hardware_lock, flags);
699
700 return QLA_SUCCESS;
701}
702
703/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700704 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
705 * @ha: HA context
706 *
707 * Returns 0 on success.
708 */
709int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800710qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700711{
712 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800713 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700714
715 pci_set_master(ha->pdev);
716 pci_try_set_mwi(ha->pdev);
717
718 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
719 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
720 w &= ~PCI_COMMAND_INTX_DISABLE;
721 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
722
723 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700724 if (pci_is_pcie(ha->pdev))
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700725 pcie_set_readrq(ha->pdev, 2048);
726
Andrew Vasquez737faec2008-10-24 15:13:45 -0700727 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700728
729 ha->chip_revision = ha->pdev->revision;
730
731 return QLA_SUCCESS;
732}
733
734/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 * qla2x00_isp_firmware() - Choose firmware image.
736 * @ha: HA context
737 *
738 * Returns 0 on success.
739 */
740static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800741qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742{
743 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700744 uint16_t loop_id, topo, sw_cap;
745 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800746 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
748 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700749 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
751 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700752 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800755 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700756 if (rval == QLA_SUCCESS) {
757 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800758 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700759 &area, &domain, &topo, &sw_cap);
760 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 }
762
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700763 if (rval)
764 ql_dbg(ql_dbg_init, vha, 0x007a,
765 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
767 return (rval);
768}
769
770/**
771 * qla2x00_reset_chip() - Reset ISP chip.
772 * @ha: HA context
773 *
774 * Returns 0 on success.
775 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700776void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800777qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778{
779 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800780 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700781 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 uint16_t cmd;
784
Andrew Vasquez85880802009-12-15 21:29:46 -0800785 if (unlikely(pci_channel_offline(ha->pdev)))
786 return;
787
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700788 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
790 spin_lock_irqsave(&ha->hardware_lock, flags);
791
792 /* Turn off master enable */
793 cmd = 0;
794 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
795 cmd &= ~PCI_COMMAND_MASTER;
796 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
797
798 if (!IS_QLA2100(ha)) {
799 /* Pause RISC. */
800 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
801 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
802 for (cnt = 0; cnt < 30000; cnt++) {
803 if ((RD_REG_WORD(&reg->hccr) &
804 HCCR_RISC_PAUSE) != 0)
805 break;
806 udelay(100);
807 }
808 } else {
809 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
810 udelay(10);
811 }
812
813 /* Select FPM registers. */
814 WRT_REG_WORD(&reg->ctrl_status, 0x20);
815 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
816
817 /* FPM Soft Reset. */
818 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
819 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
820
821 /* Toggle Fpm Reset. */
822 if (!IS_QLA2200(ha)) {
823 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
824 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
825 }
826
827 /* Select frame buffer registers. */
828 WRT_REG_WORD(&reg->ctrl_status, 0x10);
829 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
830
831 /* Reset frame buffer FIFOs. */
832 if (IS_QLA2200(ha)) {
833 WRT_FB_CMD_REG(ha, reg, 0xa000);
834 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
835 } else {
836 WRT_FB_CMD_REG(ha, reg, 0x00fc);
837
838 /* Read back fb_cmd until zero or 3 seconds max */
839 for (cnt = 0; cnt < 3000; cnt++) {
840 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
841 break;
842 udelay(100);
843 }
844 }
845
846 /* Select RISC module registers. */
847 WRT_REG_WORD(&reg->ctrl_status, 0);
848 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
849
850 /* Reset RISC processor. */
851 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
852 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
853
854 /* Release RISC processor. */
855 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
856 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
857 }
858
859 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
860 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
861
862 /* Reset ISP chip. */
863 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
864
865 /* Wait for RISC to recover from reset. */
866 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
867 /*
868 * It is necessary to for a delay here since the card doesn't
869 * respond to PCI reads during a reset. On some architectures
870 * this will result in an MCA.
871 */
872 udelay(20);
873 for (cnt = 30000; cnt; cnt--) {
874 if ((RD_REG_WORD(&reg->ctrl_status) &
875 CSR_ISP_SOFT_RESET) == 0)
876 break;
877 udelay(100);
878 }
879 } else
880 udelay(10);
881
882 /* Reset RISC processor. */
883 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
884
885 WRT_REG_WORD(&reg->semaphore, 0);
886
887 /* Release RISC processor. */
888 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
889 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
890
891 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
892 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700893 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
896 udelay(100);
897 }
898 } else
899 udelay(100);
900
901 /* Turn on master enable */
902 cmd |= PCI_COMMAND_MASTER;
903 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
904
905 /* Disable RISC pause on FPM parity error. */
906 if (!IS_QLA2100(ha)) {
907 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
908 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
909 }
910
911 spin_unlock_irqrestore(&ha->hardware_lock, flags);
912}
913
914/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700915 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
916 *
917 * Returns 0 on success.
918 */
919int
920qla81xx_reset_mpi(scsi_qla_host_t *vha)
921{
922 uint16_t mb[4] = {0x1010, 0, 1, 0};
923
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800924 if (!IS_QLA81XX(vha->hw))
925 return QLA_SUCCESS;
926
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700927 return qla81xx_write_mpi_register(vha, mb);
928}
929
930/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700931 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700932 * @ha: HA context
933 *
934 * Returns 0 on success.
935 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700936static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800937qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700938{
939 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800940 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700941 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
942 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800943 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700944 static int abts_cnt; /* ISP abort retry counts */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700945
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700946 spin_lock_irqsave(&ha->hardware_lock, flags);
947
948 /* Reset RISC. */
949 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
950 for (cnt = 0; cnt < 30000; cnt++) {
951 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
952 break;
953
954 udelay(10);
955 }
956
957 WRT_REG_DWORD(&reg->ctrl_status,
958 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800959 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700960
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800961 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700962 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700963 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
964 for (cnt = 10000 ; cnt && d2; cnt--) {
965 udelay(5);
966 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
967 barrier();
968 }
969
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800970 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700971 d2 = RD_REG_DWORD(&reg->ctrl_status);
972 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
973 udelay(5);
974 d2 = RD_REG_DWORD(&reg->ctrl_status);
975 barrier();
976 }
977
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700978 /* If required, do an MPI FW reset now */
979 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
980 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
981 if (++abts_cnt < 5) {
982 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
983 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
984 } else {
985 /*
986 * We exhausted the ISP abort retries. We have to
987 * set the board offline.
988 */
989 abts_cnt = 0;
990 vha->flags.online = 0;
991 }
992 }
993 }
994
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700995 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
996 RD_REG_DWORD(&reg->hccr);
997
998 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
999 RD_REG_DWORD(&reg->hccr);
1000
1001 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1002 RD_REG_DWORD(&reg->hccr);
1003
1004 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1005 for (cnt = 6000000 ; cnt && d2; cnt--) {
1006 udelay(5);
1007 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1008 barrier();
1009 }
1010
1011 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001012
1013 if (IS_NOPOLLING_TYPE(ha))
1014 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001015}
1016
1017/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001018 * qla24xx_reset_chip() - Reset ISP24xx chip.
1019 * @ha: HA context
1020 *
1021 * Returns 0 on success.
1022 */
1023void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001024qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001025{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001026 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001027
1028 if (pci_channel_offline(ha->pdev) &&
1029 ha->flags.pci_channel_io_perm_failure) {
1030 return;
1031 }
1032
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001033 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001034
1035 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001036 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001037}
1038
1039/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 * qla2x00_chip_diag() - Test chip for proper operation.
1041 * @ha: HA context
1042 *
1043 * Returns 0 on success.
1044 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001045int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001046qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047{
1048 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001049 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001050 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 unsigned long flags = 0;
1052 uint16_t data;
1053 uint32_t cnt;
1054 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001055 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
1057 /* Assume a failed state */
1058 rval = QLA_FUNCTION_FAILED;
1059
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001060 ql_dbg(ql_dbg_init, vha, 0x007b,
1061 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
1063 spin_lock_irqsave(&ha->hardware_lock, flags);
1064
1065 /* Reset ISP chip. */
1066 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1067
1068 /*
1069 * We need to have a delay here since the card will not respond while
1070 * in reset causing an MCA on some architectures.
1071 */
1072 udelay(20);
1073 data = qla2x00_debounce_register(&reg->ctrl_status);
1074 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1075 udelay(5);
1076 data = RD_REG_WORD(&reg->ctrl_status);
1077 barrier();
1078 }
1079
1080 if (!cnt)
1081 goto chip_diag_failed;
1082
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001083 ql_dbg(ql_dbg_init, vha, 0x007c,
1084 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
1086 /* Reset RISC processor. */
1087 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1088 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1089
1090 /* Workaround for QLA2312 PCI parity error */
1091 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1092 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1093 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1094 udelay(5);
1095 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001096 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 }
1098 } else
1099 udelay(10);
1100
1101 if (!cnt)
1102 goto chip_diag_failed;
1103
1104 /* Check product ID of chip */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001105 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
1107 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1108 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1109 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1110 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1111 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1112 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001113 ql_log(ql_log_warn, vha, 0x0062,
1114 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1115 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
1117 goto chip_diag_failed;
1118 }
1119 ha->product_id[0] = mb[1];
1120 ha->product_id[1] = mb[2];
1121 ha->product_id[2] = mb[3];
1122 ha->product_id[3] = mb[4];
1123
1124 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001125 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1127 else
1128 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001129 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
1131 if (IS_QLA2200(ha) &&
1132 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1133 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001134 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001136 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 ha->fw_transfer_size = 128;
1138 }
1139
1140 /* Wrap Incoming Mailboxes Test. */
1141 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1142
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001143 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001144 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001145 if (rval)
1146 ql_log(ql_log_warn, vha, 0x0080,
1147 "Failed mailbox send register test.\n");
1148 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 /* Flag a successful rval */
1150 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 spin_lock_irqsave(&ha->hardware_lock, flags);
1152
1153chip_diag_failed:
1154 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001155 ql_log(ql_log_info, vha, 0x0081,
1156 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
1158 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1159
1160 return (rval);
1161}
1162
1163/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001164 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1165 * @ha: HA context
1166 *
1167 * Returns 0 on success.
1168 */
1169int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001170qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001171{
1172 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001173 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001174 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001175
Giridhar Malavalia9083012010-04-12 17:59:55 -07001176 if (IS_QLA82XX(ha))
1177 return QLA_SUCCESS;
1178
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001179 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001180
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001181 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001182 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001183 ql_log(ql_log_warn, vha, 0x0082,
1184 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001185 } else {
1186 /* Flag a successful rval */
1187 rval = QLA_SUCCESS;
1188 }
1189
1190 return rval;
1191}
1192
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001193void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001194qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001195{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001196 int rval;
1197 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001198 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001199 dma_addr_t tc_dma;
1200 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001201 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001202 struct req_que *req = ha->req_q_map[0];
1203 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001204
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001205 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001206 ql_dbg(ql_dbg_init, vha, 0x00bd,
1207 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001208 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001209 }
1210
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001211 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001212 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001213 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1214 fixed_size = sizeof(struct qla2100_fw_dump);
1215 } else if (IS_QLA23XX(ha)) {
1216 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1217 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1218 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001219 } else if (IS_FWI2_CAPABLE(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001220 if (IS_QLA83XX(ha))
1221 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
1222 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001223 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1224 else if (IS_QLA25XX(ha))
1225 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1226 else
1227 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001228 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1229 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001230 if (ha->mqenable) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001231 if (!IS_QLA83XX(ha))
1232 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001233 /*
1234 * Allocate maximum buffer size for all queues.
1235 * Resizing must be done at end-of-dump processing.
1236 */
1237 mq_size += ha->max_req_queues *
1238 (req->length * sizeof(request_t));
1239 mq_size += ha->max_rsp_queues *
1240 (rsp->length * sizeof(response_t));
1241 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001242 if (ha->tgt.atio_q_length)
1243 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001244 /* Allocate memory for Fibre Channel Event Buffer. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001245 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001246 goto try_eft;
1247
1248 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1249 GFP_KERNEL);
1250 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001251 ql_log(ql_log_warn, vha, 0x00be,
1252 "Unable to allocate (%d KB) for FCE.\n",
1253 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001254 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001255 }
1256
1257 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001258 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001259 ha->fce_mb, &ha->fce_bufs);
1260 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001261 ql_log(ql_log_warn, vha, 0x00bf,
1262 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001263 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1264 tc_dma);
1265 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001266 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001267 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001268 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001269 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001270
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001271 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001272 ha->flags.fce_enabled = 1;
1273 ha->fce_dma = tc_dma;
1274 ha->fce = tc;
1275try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001276 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001277 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001278 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001279 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001280 ql_log(ql_log_warn, vha, 0x00c1,
1281 "Unable to allocate (%d KB) for EFT.\n",
1282 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001283 goto cont_alloc;
1284 }
1285
Andrew Vasquezfc447652008-01-17 09:02:18 -08001286 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001287 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001288 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001289 ql_log(ql_log_warn, vha, 0x00c2,
1290 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001291 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1292 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001293 goto cont_alloc;
1294 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001295 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001296 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001297
1298 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001299 ha->eft_dma = tc_dma;
1300 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001301 }
1302cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001303 req_q_size = req->length * sizeof(request_t);
1304 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001305
1306 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001307 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001308 ha->chain_offset = dump_size;
1309 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001310
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001311 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001312 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001313 ql_log(ql_log_warn, vha, 0x00c4,
1314 "Unable to allocate (%d KB) for firmware dump.\n",
1315 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001316
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001317 if (ha->fce) {
1318 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1319 ha->fce_dma);
1320 ha->fce = NULL;
1321 ha->fce_dma = 0;
1322 }
1323
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001324 if (ha->eft) {
1325 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1326 ha->eft_dma);
1327 ha->eft = NULL;
1328 ha->eft_dma = 0;
1329 }
1330 return;
1331 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001332 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001333 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001334
1335 ha->fw_dump_len = dump_size;
1336 ha->fw_dump->signature[0] = 'Q';
1337 ha->fw_dump->signature[1] = 'L';
1338 ha->fw_dump->signature[2] = 'G';
1339 ha->fw_dump->signature[3] = 'C';
1340 ha->fw_dump->version = __constant_htonl(1);
1341
1342 ha->fw_dump->fixed_size = htonl(fixed_size);
1343 ha->fw_dump->mem_size = htonl(mem_size);
1344 ha->fw_dump->req_q_size = htonl(req_q_size);
1345 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1346
1347 ha->fw_dump->eft_size = htonl(eft_size);
1348 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1349 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1350
1351 ha->fw_dump->header_size =
1352 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001353}
1354
Andrew Vasquez18e75552009-06-03 09:55:30 -07001355static int
1356qla81xx_mpi_sync(scsi_qla_host_t *vha)
1357{
1358#define MPS_MASK 0xe0
1359 int rval;
1360 uint16_t dc;
1361 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07001362
1363 if (!IS_QLA81XX(vha->hw))
1364 return QLA_SUCCESS;
1365
1366 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1367 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001368 ql_log(ql_log_warn, vha, 0x0105,
1369 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001370 goto done;
1371 }
1372
1373 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1374 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1375 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001376 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001377 goto done_release;
1378 }
1379
1380 dc &= MPS_MASK;
1381 if (dc == (dw & MPS_MASK))
1382 goto done_release;
1383
1384 dw &= ~MPS_MASK;
1385 dw |= dc;
1386 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1387 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001388 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001389 }
1390
1391done_release:
1392 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1393 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001394 ql_log(ql_log_warn, vha, 0x006d,
1395 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001396 }
1397
1398done:
1399 return rval;
1400}
1401
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001402/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 * qla2x00_setup_chip() - Load and start RISC firmware.
1404 * @ha: HA context
1405 *
1406 * Returns 0 on success.
1407 */
1408static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001409qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001411 int rval;
1412 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001413 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001414 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1415 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001416 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001417
Giridhar Malavalia9083012010-04-12 17:59:55 -07001418 if (IS_QLA82XX(ha)) {
1419 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001420 if (rval == QLA_SUCCESS) {
1421 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001422 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001423 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001424 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001425 }
1426
Andrew Vasquez3db06522008-01-31 12:33:49 -08001427 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1428 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1429 spin_lock_irqsave(&ha->hardware_lock, flags);
1430 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1431 RD_REG_WORD(&reg->hccr);
1432 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1433 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
Andrew Vasquez18e75552009-06-03 09:55:30 -07001435 qla81xx_mpi_sync(vha);
1436
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001438 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001439 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001440 ql_dbg(ql_dbg_init, vha, 0x00c9,
1441 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001443 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 if (rval == QLA_SUCCESS) {
1445 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001446 ql_dbg(ql_dbg_init, vha, 0x00ca,
1447 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001449 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001451 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001452enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001453 fw_major_version = ha->fw_major_version;
Giridhar Malavali31731672011-08-16 11:31:54 -07001454 if (IS_QLA82XX(ha))
1455 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001456 else
1457 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001458 if (rval != QLA_SUCCESS)
1459 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001460 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001461 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001462 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001463 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001464 if ((!ha->max_npiv_vports) ||
1465 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001466 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001467 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001468 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001469 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001470 qla2x00_get_resource_cnts(vha, NULL,
1471 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001472 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001473
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08001474 if (!fw_major_version && ql2xallocfwdump
1475 && !IS_QLA82XX(ha))
Giridhar Malavali08de2842011-08-16 11:31:44 -07001476 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 }
1478 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001479 ql_log(ql_log_fatal, vha, 0x00cd,
1480 "ISP Firmware failed checksum.\n");
1481 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 }
1483 }
1484
Andrew Vasquez3db06522008-01-31 12:33:49 -08001485 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1486 /* Enable proper parity. */
1487 spin_lock_irqsave(&ha->hardware_lock, flags);
1488 if (IS_QLA2300(ha))
1489 /* SRAM parity */
1490 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1491 else
1492 /* SRAM, Instruction RAM and GP RAM parity */
1493 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1494 RD_REG_WORD(&reg->hccr);
1495 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1496 }
1497
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001498 if (IS_QLA83XX(ha))
1499 goto skip_fac_check;
1500
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001501 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1502 uint32_t size;
1503
1504 rval = qla81xx_fac_get_sector_size(vha, &size);
1505 if (rval == QLA_SUCCESS) {
1506 ha->flags.fac_supported = 1;
1507 ha->fdt_block_size = size << 2;
1508 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001509 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001510 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1511 ha->fw_major_version, ha->fw_minor_version,
1512 ha->fw_subminor_version);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001513skip_fac_check:
1514 if (IS_QLA83XX(ha)) {
1515 ha->flags.fac_supported = 0;
1516 rval = QLA_SUCCESS;
1517 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001518 }
1519 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001520failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001522 ql_log(ql_log_fatal, vha, 0x00cf,
1523 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 }
1525
1526 return (rval);
1527}
1528
1529/**
1530 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1531 * @ha: HA context
1532 *
1533 * Beginning of request ring has initialization control block already built
1534 * by nvram config routine.
1535 *
1536 * Returns 0 on success.
1537 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001538void
1539qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540{
1541 uint16_t cnt;
1542 response_t *pkt;
1543
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001544 rsp->ring_ptr = rsp->ring;
1545 rsp->ring_index = 0;
1546 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001547 pkt = rsp->ring_ptr;
1548 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 pkt->signature = RESPONSE_PROCESSED;
1550 pkt++;
1551 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552}
1553
1554/**
1555 * qla2x00_update_fw_options() - Read and process firmware options.
1556 * @ha: HA context
1557 *
1558 * Returns 0 on success.
1559 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001560void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001561qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562{
1563 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001564 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
1566 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001567 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
1569 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1570 return;
1571
1572 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001573 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1574 "Serial link options.\n");
1575 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1576 (uint8_t *)&ha->fw_seriallink_options,
1577 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
1579 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1580 if (ha->fw_seriallink_options[3] & BIT_2) {
1581 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1582
1583 /* 1G settings */
1584 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1585 emphasis = (ha->fw_seriallink_options[2] &
1586 (BIT_4 | BIT_3)) >> 3;
1587 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001588 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 rx_sens = (ha->fw_seriallink_options[0] &
1590 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1591 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1592 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1593 if (rx_sens == 0x0)
1594 rx_sens = 0x3;
1595 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1596 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1597 ha->fw_options[10] |= BIT_5 |
1598 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1599 (tx_sens & (BIT_1 | BIT_0));
1600
1601 /* 2G settings */
1602 swing = (ha->fw_seriallink_options[2] &
1603 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1604 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1605 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001606 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 rx_sens = (ha->fw_seriallink_options[1] &
1608 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1609 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1610 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1611 if (rx_sens == 0x0)
1612 rx_sens = 0x3;
1613 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1614 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1615 ha->fw_options[11] |= BIT_5 |
1616 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1617 (tx_sens & (BIT_1 | BIT_0));
1618 }
1619
1620 /* FCP2 options. */
1621 /* Return command IOCBs without waiting for an ABTS to complete. */
1622 ha->fw_options[3] |= BIT_13;
1623
1624 /* LED scheme. */
1625 if (ha->flags.enable_led_scheme)
1626 ha->fw_options[2] |= BIT_12;
1627
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001628 /* Detect ISP6312. */
1629 if (IS_QLA6312(ha))
1630 ha->fw_options[2] |= BIT_13;
1631
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001633 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634}
1635
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001636void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001637qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001638{
1639 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001640 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001641
Giridhar Malavalia9083012010-04-12 17:59:55 -07001642 if (IS_QLA82XX(ha))
1643 return;
1644
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001645 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001646 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001647 return;
1648
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001649 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001650 le16_to_cpu(ha->fw_seriallink_options24[1]),
1651 le16_to_cpu(ha->fw_seriallink_options24[2]),
1652 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001653 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001654 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001655 "Unable to update Serial Link options (%x).\n", rval);
1656 }
1657}
1658
1659void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001660qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001661{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001662 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001663 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001664 struct req_que *req = ha->req_q_map[0];
1665 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001666
1667 /* Setup ring parameters in initialization control block. */
1668 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1669 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001670 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1671 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1672 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1673 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1674 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1675 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001676
1677 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1678 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1679 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1680 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1681 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1682}
1683
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001684void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001685qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001686{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001687 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001688 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1689 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1690 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001691 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001692 uint16_t rid = 0;
1693 struct req_que *req = ha->req_q_map[0];
1694 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001695
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001696 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001697 icb = (struct init_cb_24xx *)ha->init_cb;
1698 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1699 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001700 icb->request_q_length = cpu_to_le16(req->length);
1701 icb->response_q_length = cpu_to_le16(rsp->length);
1702 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1703 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1704 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1705 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001706
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001707 /* Setup ATIO queue dma pointers for target mode */
1708 icb->atio_q_inpointer = __constant_cpu_to_le16(0);
1709 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
1710 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
1711 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
1712
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001713 if (ha->mqenable || IS_QLA83XX(ha)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001714 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1715 icb->rid = __constant_cpu_to_le16(rid);
1716 if (ha->flags.msix_enabled) {
1717 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001718 ql_dbg(ql_dbg_init, vha, 0x00fd,
1719 "Registering vector 0x%x for base que.\n",
1720 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001721 icb->msix = cpu_to_le16(msix->entry);
1722 }
1723 /* Use alternate PCI bus number */
1724 if (MSB(rid))
1725 icb->firmware_options_2 |=
1726 __constant_cpu_to_le32(BIT_19);
1727 /* Use alternate PCI devfn */
1728 if (LSB(rid))
1729 icb->firmware_options_2 |=
1730 __constant_cpu_to_le32(BIT_18);
1731
Anirban Chakraborty31557542009-12-02 10:36:55 -08001732 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001733 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
1734 (ha->flags.msix_enabled)) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08001735 icb->firmware_options_2 &=
1736 __constant_cpu_to_le32(~BIT_22);
1737 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001738 ql_dbg(ql_dbg_init, vha, 0x00fe,
1739 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08001740 } else {
1741 icb->firmware_options_2 |=
1742 __constant_cpu_to_le32(BIT_22);
1743 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001744 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001745
1746 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1747 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1748 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1749 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1750 } else {
1751 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1752 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1753 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1754 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1755 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001756 qlt_24xx_config_rings(vha, reg);
1757
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001758 /* PCI posting */
1759 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001760}
1761
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762/**
1763 * qla2x00_init_rings() - Initializes firmware.
1764 * @ha: HA context
1765 *
1766 * Beginning of request ring has initialization control block already built
1767 * by nvram config routine.
1768 *
1769 * Returns 0 on success.
1770 */
1771static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001772qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773{
1774 int rval;
1775 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001776 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001777 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001778 struct req_que *req;
1779 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001780 struct mid_init_cb_24xx *mid_init_cb =
1781 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782
1783 spin_lock_irqsave(&ha->hardware_lock, flags);
1784
1785 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001786 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001787 req = ha->req_q_map[que];
1788 if (!req)
1789 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001790 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001791 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001793 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001794
1795 /* Initialize firmware. */
1796 req->ring_ptr = req->ring;
1797 req->ring_index = 0;
1798 req->cnt = req->length;
1799 }
1800
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001801 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001802 rsp = ha->rsp_q_map[que];
1803 if (!rsp)
1804 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001805 /* Initialize response queue entries */
1806 qla2x00_init_response_q_entries(rsp);
1807 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
Dan Carpenter542bce12010-10-15 11:27:38 -07001809 spin_lock(&ha->vport_slock);
Arun Easifeafb7b2010-09-03 14:57:00 -07001810
Dan Carpenter542bce12010-10-15 11:27:38 -07001811 spin_unlock(&ha->vport_slock);
Arun Easifeafb7b2010-09-03 14:57:00 -07001812
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001813 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
1814 ha->tgt.atio_ring_index = 0;
1815 /* Initialize ATIO queue entries */
1816 qlt_init_atio_q_entries(vha);
1817
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001818 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
1820 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1821
1822 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001823 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001825 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001826
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001827 if (ha->flags.npiv_supported) {
1828 if (ha->operating_mode == LOOP)
1829 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001830 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001831 }
1832
Andrew Vasquez24a08132009-03-24 09:08:16 -07001833 if (IS_FWI2_CAPABLE(ha)) {
1834 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1835 mid_init_cb->init_cb.execution_throttle =
1836 cpu_to_le16(ha->fw_xcb_count);
1837 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001838
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001839 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001841 ql_log(ql_log_fatal, vha, 0x00d2,
1842 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001844 ql_dbg(ql_dbg_init, vha, 0x00d3,
1845 "Init Firmware -- success.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 }
1847
1848 return (rval);
1849}
1850
1851/**
1852 * qla2x00_fw_ready() - Waits for firmware ready.
1853 * @ha: HA context
1854 *
1855 * Returns 0 on success.
1856 */
1857static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001858qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859{
1860 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001861 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 uint16_t min_wait; /* Minimum wait time if loop is down */
1863 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001864 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001865 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866
1867 rval = QLA_SUCCESS;
1868
1869 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001870 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871
1872 /*
1873 * Firmware should take at most one RATOV to login, plus 5 seconds for
1874 * our own processing.
1875 */
1876 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1877 wait_time = min_wait;
1878 }
1879
1880 /* Min wait time if loop down */
1881 mtime = jiffies + (min_wait * HZ);
1882
1883 /* wait time before firmware ready */
1884 wtime = jiffies + (wait_time * HZ);
1885
1886 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001887 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001888 ql_log(ql_log_info, vha, 0x801e,
1889 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890
1891 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001892 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001894 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001895 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001897 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001898 ql_dbg(ql_dbg_taskm, vha, 0x801f,
1899 "fw_state=%x 84xx=%x.\n", state[0],
1900 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001901 if ((state[2] & FSTATE_LOGGED_IN) &&
1902 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001903 ql_dbg(ql_dbg_taskm, vha, 0x8028,
1904 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001905
1906 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001907 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001908 if (rval != QLA_SUCCESS) {
1909 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001910 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001911 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001912 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001913 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001914
1915 /* Add time taken to initialize. */
1916 cs84xx_time = jiffies - cs84xx_time;
1917 wtime += cs84xx_time;
1918 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08001919 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001920 "Increasing wait time by %ld. "
1921 "New time %ld.\n", cs84xx_time,
1922 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001923 }
1924 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001925 ql_dbg(ql_dbg_taskm, vha, 0x8037,
1926 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001928 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 &ha->login_timeout, &ha->r_a_tov);
1930
1931 rval = QLA_SUCCESS;
1932 break;
1933 }
1934
1935 rval = QLA_FUNCTION_FAILED;
1936
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001937 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001938 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001940 * other than Wait for Login.
1941 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001943 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 "Cable is unplugged...\n");
1945
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001946 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 break;
1948 }
1949 }
1950 } else {
1951 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07001952 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08001953 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 break;
1955 }
1956
1957 if (time_after_eq(jiffies, wtime))
1958 break;
1959
1960 /* Delay for a while */
1961 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 } while (1);
1963
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001964 ql_dbg(ql_dbg_taskm, vha, 0x803a,
1965 "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0],
1966 state[1], state[2], state[3], state[4], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967
Chad Dupuiscfb09192011-11-18 09:03:07 -08001968 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001969 ql_log(ql_log_warn, vha, 0x803b,
1970 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 }
1972
1973 return (rval);
1974}
1975
1976/*
1977* qla2x00_configure_hba
1978* Setup adapter context.
1979*
1980* Input:
1981* ha = adapter state pointer.
1982*
1983* Returns:
1984* 0 = success
1985*
1986* Context:
1987* Kernel context.
1988*/
1989static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001990qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991{
1992 int rval;
1993 uint16_t loop_id;
1994 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001995 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 uint8_t al_pa;
1997 uint8_t area;
1998 uint8_t domain;
1999 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002000 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
2002 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002003 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002004 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002006 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002007 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002008 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002009 ql_dbg(ql_dbg_disc, vha, 0x2008,
2010 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08002011 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002012 ql_log(ql_log_warn, vha, 0x2009,
2013 "Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002014 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002015 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 return (rval);
2017 }
2018
2019 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002020 ql_log(ql_log_info, vha, 0x200a,
2021 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 return (QLA_FUNCTION_FAILED);
2023 }
2024
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002025 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
2027 /* initialize */
2028 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2029 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002030 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
2032 switch (topo) {
2033 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002034 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 ha->current_topology = ISP_CFG_NL;
2036 strcpy(connect_type, "(Loop)");
2037 break;
2038
2039 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002040 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002041 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 ha->current_topology = ISP_CFG_FL;
2043 strcpy(connect_type, "(FL_Port)");
2044 break;
2045
2046 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002047 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 ha->operating_mode = P2P;
2049 ha->current_topology = ISP_CFG_N;
2050 strcpy(connect_type, "(N_Port-to-N_Port)");
2051 break;
2052
2053 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002054 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002055 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 ha->operating_mode = P2P;
2057 ha->current_topology = ISP_CFG_F;
2058 strcpy(connect_type, "(F_Port)");
2059 break;
2060
2061 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002062 ql_dbg(ql_dbg_disc, vha, 0x200f,
2063 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 ha->current_topology = ISP_CFG_NL;
2065 strcpy(connect_type, "(Loop)");
2066 break;
2067 }
2068
2069 /* Save Host port and loop ID. */
2070 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002071 vha->d_id.b.domain = domain;
2072 vha->d_id.b.area = area;
2073 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002075 spin_lock(&ha->vport_slock);
2076 qlt_update_vp_map(vha, SET_AL_PA);
2077 spin_unlock(&ha->vport_slock);
2078
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002079 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002080 ql_log(ql_log_info, vha, 0x2010,
2081 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002082 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
2084 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002085 ql_log(ql_log_warn, vha, 0x2011,
2086 "%s FAILED\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002088 ql_dbg(ql_dbg_disc, vha, 0x2012,
2089 "%s success\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 }
2091
2092 return(rval);
2093}
2094
Giridhar Malavalia9083012010-04-12 17:59:55 -07002095inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002096qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2097 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002098{
2099 char *st, *en;
2100 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002101 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002102 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002103 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002104
2105 if (memcmp(model, BINZERO, len) != 0) {
2106 strncpy(ha->model_number, model, len);
2107 st = en = ha->model_number;
2108 en += len - 1;
2109 while (en > st) {
2110 if (*en != 0x20 && *en != 0x00)
2111 break;
2112 *en-- = '\0';
2113 }
2114
2115 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002116 if (use_tbl &&
2117 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002118 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002119 strncpy(ha->model_desc,
2120 qla2x00_model_name[index * 2 + 1],
2121 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002122 } else {
2123 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002124 if (use_tbl &&
2125 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002126 index < QLA_MODEL_NAMES) {
2127 strcpy(ha->model_number,
2128 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002129 strncpy(ha->model_desc,
2130 qla2x00_model_name[index * 2 + 1],
2131 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002132 } else {
2133 strcpy(ha->model_number, def);
2134 }
2135 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002136 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002137 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002138 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002139}
2140
David Miller4e08df32007-04-16 12:37:43 -07002141/* On sparc systems, obtain port and node WWN from firmware
2142 * properties.
2143 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002144static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002145{
2146#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002147 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002148 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002149 struct device_node *dp = pci_device_to_OF_node(pdev);
2150 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002151 int len;
2152
2153 val = of_get_property(dp, "port-wwn", &len);
2154 if (val && len >= WWN_SIZE)
2155 memcpy(nv->port_name, val, WWN_SIZE);
2156
2157 val = of_get_property(dp, "node-wwn", &len);
2158 if (val && len >= WWN_SIZE)
2159 memcpy(nv->node_name, val, WWN_SIZE);
2160#endif
2161}
2162
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163/*
2164* NVRAM configuration for ISP 2xxx
2165*
2166* Input:
2167* ha = adapter block pointer.
2168*
2169* Output:
2170* initialization control block in response_ring
2171* host adapters parameters in host adapter block
2172*
2173* Returns:
2174* 0 = success.
2175*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002176int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002177qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178{
David Miller4e08df32007-04-16 12:37:43 -07002179 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002180 uint8_t chksum = 0;
2181 uint16_t cnt;
2182 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002183 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002184 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002185 nvram_t *nv = ha->nvram;
2186 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002187 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
David Miller4e08df32007-04-16 12:37:43 -07002189 rval = QLA_SUCCESS;
2190
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002192 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 ha->nvram_base = 0;
2194 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2195 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2196 ha->nvram_base = 0x80;
2197
2198 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002199 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002200 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2201 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002203 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2204 "Contents of NVRAM.\n");
2205 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2206 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207
2208 /* Bad NVRAM data, set defaults parameters. */
2209 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2210 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2211 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002212 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04002213 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002214 "detected: checksum=0x%x id=%c version=0x%x.\n",
2215 chksum, nv->id[0], nv->nvram_version);
2216 ql_log(ql_log_warn, vha, 0x0065,
2217 "Falling back to "
2218 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07002219
2220 /*
2221 * Set default initialization control block.
2222 */
2223 memset(nv, 0, ha->nvram_size);
2224 nv->parameter_block_version = ICB_VERSION;
2225
2226 if (IS_QLA23XX(ha)) {
2227 nv->firmware_options[0] = BIT_2 | BIT_1;
2228 nv->firmware_options[1] = BIT_7 | BIT_5;
2229 nv->add_firmware_options[0] = BIT_5;
2230 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2231 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2232 nv->special_options[1] = BIT_7;
2233 } else if (IS_QLA2200(ha)) {
2234 nv->firmware_options[0] = BIT_2 | BIT_1;
2235 nv->firmware_options[1] = BIT_7 | BIT_5;
2236 nv->add_firmware_options[0] = BIT_5;
2237 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2238 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2239 } else if (IS_QLA2100(ha)) {
2240 nv->firmware_options[0] = BIT_3 | BIT_1;
2241 nv->firmware_options[1] = BIT_5;
2242 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2243 }
2244
2245 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2246 nv->execution_throttle = __constant_cpu_to_le16(16);
2247 nv->retry_count = 8;
2248 nv->retry_delay = 1;
2249
2250 nv->port_name[0] = 33;
2251 nv->port_name[3] = 224;
2252 nv->port_name[4] = 139;
2253
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002254 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002255
2256 nv->login_timeout = 4;
2257
2258 /*
2259 * Set default host adapter parameters
2260 */
2261 nv->host_p[1] = BIT_2;
2262 nv->reset_delay = 5;
2263 nv->port_down_retry_count = 8;
2264 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2265 nv->link_down_timeout = 60;
2266
2267 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 }
2269
2270#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2271 /*
2272 * The SN2 does not provide BIOS emulation which means you can't change
2273 * potentially bogus BIOS settings. Force the use of default settings
2274 * for link rate and frame size. Hope that the rest of the settings
2275 * are valid.
2276 */
2277 if (ia64_platform_is("sn2")) {
2278 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2279 if (IS_QLA23XX(ha))
2280 nv->special_options[1] = BIT_7;
2281 }
2282#endif
2283
2284 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002285 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286
2287 /*
2288 * Setup driver NVRAM options.
2289 */
2290 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2291 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2292 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2293 nv->firmware_options[1] &= ~BIT_4;
2294
2295 if (IS_QLA23XX(ha)) {
2296 nv->firmware_options[0] |= BIT_2;
2297 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002298 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002299 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300
2301 if (IS_QLA2300(ha)) {
2302 if (ha->fb_rev == FPM_2310) {
2303 strcpy(ha->model_number, "QLA2310");
2304 } else {
2305 strcpy(ha->model_number, "QLA2300");
2306 }
2307 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002308 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002309 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 }
2311 } else if (IS_QLA2200(ha)) {
2312 nv->firmware_options[0] |= BIT_2;
2313 /*
2314 * 'Point-to-point preferred, else loop' is not a safe
2315 * connection mode setting.
2316 */
2317 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2318 (BIT_5 | BIT_4)) {
2319 /* Force 'loop preferred, else point-to-point'. */
2320 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2321 nv->add_firmware_options[0] |= BIT_5;
2322 }
2323 strcpy(ha->model_number, "QLA22xx");
2324 } else /*if (IS_QLA2100(ha))*/ {
2325 strcpy(ha->model_number, "QLA2100");
2326 }
2327
2328 /*
2329 * Copy over NVRAM RISC parameter block to initialization control block.
2330 */
2331 dptr1 = (uint8_t *)icb;
2332 dptr2 = (uint8_t *)&nv->parameter_block_version;
2333 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2334 while (cnt--)
2335 *dptr1++ = *dptr2++;
2336
2337 /* Copy 2nd half. */
2338 dptr1 = (uint8_t *)icb->add_firmware_options;
2339 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2340 while (cnt--)
2341 *dptr1++ = *dptr2++;
2342
Andrew Vasquez5341e862006-05-17 15:09:16 -07002343 /* Use alternate WWN? */
2344 if (nv->host_p[1] & BIT_7) {
2345 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2346 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2347 }
2348
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 /* Prepare nodename */
2350 if ((icb->firmware_options[1] & BIT_6) == 0) {
2351 /*
2352 * Firmware will apply the following mask if the nodename was
2353 * not provided.
2354 */
2355 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2356 icb->node_name[0] &= 0xF0;
2357 }
2358
2359 /*
2360 * Set host adapter parameters.
2361 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002362
2363 /*
2364 * BIT_7 in the host-parameters section allows for modification to
2365 * internal driver logging.
2366 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002367 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08002368 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2370 /* Always load RISC code on non ISP2[12]00 chips. */
2371 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2372 ha->flags.disable_risc_code_load = 0;
2373 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2374 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2375 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002376 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002377 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378
2379 ha->operating_mode =
2380 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2381
2382 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2383 sizeof(ha->fw_seriallink_options));
2384
2385 /* save HBA serial number */
2386 ha->serial0 = icb->port_name[5];
2387 ha->serial1 = icb->port_name[6];
2388 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002389 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2390 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391
2392 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2393
2394 ha->retry_count = nv->retry_count;
2395
2396 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002397 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 nv->login_timeout = ql2xlogintimeout;
2399 if (nv->login_timeout < 4)
2400 nv->login_timeout = 4;
2401 ha->login_timeout = nv->login_timeout;
2402 icb->login_timeout = nv->login_timeout;
2403
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002404 /* Set minimum RATOV to 100 tenths of a second. */
2405 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 ha->loop_reset_delay = nv->reset_delay;
2408
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 /* Link Down Timeout = 0:
2410 *
2411 * When Port Down timer expires we will start returning
2412 * I/O's to OS with "DID_NO_CONNECT".
2413 *
2414 * Link Down Timeout != 0:
2415 *
2416 * The driver waits for the link to come up after link down
2417 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002418 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 if (nv->link_down_timeout == 0) {
2420 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002421 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 } else {
2423 ha->link_down_timeout = nv->link_down_timeout;
2424 ha->loop_down_abort_time =
2425 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002426 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 /*
2429 * Need enough time to try and get the port back.
2430 */
2431 ha->port_down_retry_count = nv->port_down_retry_count;
2432 if (qlport_down_retry)
2433 ha->port_down_retry_count = qlport_down_retry;
2434 /* Set login_retry_count */
2435 ha->login_retry_count = nv->retry_count;
2436 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2437 ha->port_down_retry_count > 3)
2438 ha->login_retry_count = ha->port_down_retry_count;
2439 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2440 ha->login_retry_count = ha->port_down_retry_count;
2441 if (ql2xloginretrycount)
2442 ha->login_retry_count = ql2xloginretrycount;
2443
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 icb->lun_enables = __constant_cpu_to_le16(0);
2445 icb->command_resource_count = 0;
2446 icb->immediate_notify_resource_count = 0;
2447 icb->timeout = __constant_cpu_to_le16(0);
2448
2449 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2450 /* Enable RIO */
2451 icb->firmware_options[0] &= ~BIT_3;
2452 icb->add_firmware_options[0] &=
2453 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2454 icb->add_firmware_options[0] |= BIT_2;
2455 icb->response_accumulation_timer = 3;
2456 icb->interrupt_delay_timer = 5;
2457
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002458 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002460 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002461 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002462 ha->zio_mode = icb->add_firmware_options[0] &
2463 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2464 ha->zio_timer = icb->interrupt_delay_timer ?
2465 icb->interrupt_delay_timer: 2;
2466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 icb->add_firmware_options[0] &=
2468 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002469 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002470 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002471 ha->zio_mode = QLA_ZIO_MODE_6;
2472
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002473 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002474 "ZIO mode %d enabled; timer delay (%d us).\n",
2475 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002477 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2478 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002479 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 }
2481 }
2482
David Miller4e08df32007-04-16 12:37:43 -07002483 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002484 ql_log(ql_log_warn, vha, 0x0069,
2485 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07002486 }
2487 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488}
2489
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002490static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002491qla2x00_rport_del(void *data)
2492{
2493 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002494 struct fc_rport *rport;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002495 scsi_qla_host_t *vha = fcport->vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002496 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002497
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002498 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002499 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002500 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002501 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002502 if (rport) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002503 fc_remote_port_delete(rport);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002504 /*
2505 * Release the target mode FC NEXUS in qla_target.c code
2506 * if target mod is enabled.
2507 */
2508 qlt_fc_port_deleted(vha, fcport);
2509 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002510}
2511
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512/**
2513 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2514 * @ha: HA context
2515 * @flags: allocation flags
2516 *
2517 * Returns a pointer to the allocated fcport, or NULL, if none available.
2518 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002519fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002520qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521{
2522 fc_port_t *fcport;
2523
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002524 fcport = kzalloc(sizeof(fc_port_t), flags);
2525 if (!fcport)
2526 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527
2528 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002529 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 fcport->port_type = FCT_UNKNOWN;
2531 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07002532 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002533 fcport->supported_classes = FC_COS_UNSPECIFIED;
Joe Carnuccioc0822b62012-05-15 14:34:21 -04002534 fcport->scan_state = QLA_FCPORT_SCAN_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002536 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537}
2538
2539/*
2540 * qla2x00_configure_loop
2541 * Updates Fibre Channel Device Database with what is actually on loop.
2542 *
2543 * Input:
2544 * ha = adapter block pointer.
2545 *
2546 * Returns:
2547 * 0 = success.
2548 * 1 = error.
2549 * 2 = database was full and device was not configured.
2550 */
2551static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002552qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553{
2554 int rval;
2555 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002556 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 rval = QLA_SUCCESS;
2558
2559 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002560 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2561 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002563 ql_dbg(ql_dbg_disc, vha, 0x2013,
2564 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 return (rval);
2566 }
2567 }
2568
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002569 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002570 ql_dbg(ql_dbg_disc, vha, 0x2014,
2571 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572
2573 /*
2574 * If we have both an RSCN and PORT UPDATE pending then handle them
2575 * both at the same time.
2576 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002577 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2578 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579
Michael Hernandez3064ff32009-12-15 21:29:44 -08002580 qla2x00_get_data_rate(vha);
2581
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 /* Determine what we need to do */
2583 if (ha->current_topology == ISP_CFG_FL &&
2584 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2585
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 set_bit(RSCN_UPDATE, &flags);
2587
2588 } else if (ha->current_topology == ISP_CFG_F &&
2589 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2590
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 set_bit(RSCN_UPDATE, &flags);
2592 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2593
Andrew Vasquez21333b42006-05-17 15:09:56 -07002594 } else if (ha->current_topology == ISP_CFG_N) {
2595 clear_bit(RSCN_UPDATE, &flags);
2596
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002597 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2599
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 set_bit(RSCN_UPDATE, &flags);
2601 set_bit(LOCAL_LOOP_UPDATE, &flags);
2602 }
2603
2604 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002605 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2606 ql_dbg(ql_dbg_disc, vha, 0x2015,
2607 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08002609 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002610 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 }
2612
2613 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002614 if (LOOP_TRANSITION(vha)) {
2615 ql_dbg(ql_dbg_disc, vha, 0x201e,
2616 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002618 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002619 else
2620 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 }
2622
2623 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002624 if (atomic_read(&vha->loop_down_timer) ||
2625 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 rval = QLA_FUNCTION_FAILED;
2627 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002628 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002629 ql_dbg(ql_dbg_disc, vha, 0x2069,
2630 "LOOP READY.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 }
2632 }
2633
2634 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002635 ql_dbg(ql_dbg_disc, vha, 0x206a,
2636 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002638 ql_dbg(ql_dbg_disc, vha, 0x206b,
2639 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 }
2641
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002642 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002643 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002645 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002646 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002647 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 }
2650
2651 return (rval);
2652}
2653
2654
2655
2656/*
2657 * qla2x00_configure_local_loop
2658 * Updates Fibre Channel Device Database with local loop devices.
2659 *
2660 * Input:
2661 * ha = adapter block pointer.
2662 *
2663 * Returns:
2664 * 0 = success.
2665 */
2666static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002667qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668{
2669 int rval, rval2;
2670 int found_devs;
2671 int found;
2672 fc_port_t *fcport, *new_fcport;
2673
2674 uint16_t index;
2675 uint16_t entries;
2676 char *id_iter;
2677 uint16_t loop_id;
2678 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002679 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680
2681 found_devs = 0;
2682 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08002683 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002685 ql_dbg(ql_dbg_disc, vha, 0x2016,
2686 "Getting FCAL position map.\n");
2687 if (ql2xextended_error_logging & ql_dbg_disc)
2688 qla2x00_get_fcal_position_map(vha, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689
2690 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08002691 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002692 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 &entries);
2694 if (rval != QLA_SUCCESS)
2695 goto cleanup_allocation;
2696
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002697 ql_dbg(ql_dbg_disc, vha, 0x2017,
2698 "Entries in ID list (%d).\n", entries);
2699 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
2700 (uint8_t *)ha->gid_list,
2701 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702
2703 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002704 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002706 ql_log(ql_log_warn, vha, 0x2018,
2707 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 rval = QLA_MEMORY_ALLOC_FAILED;
2709 goto cleanup_allocation;
2710 }
2711 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2712
2713 /*
2714 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2715 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002716 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2718 fcport->port_type != FCT_BROADCAST &&
2719 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2720
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002721 ql_dbg(ql_dbg_disc, vha, 0x2019,
2722 "Marking port lost loop_id=0x%04x.\n",
2723 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724
Chad Dupuisec426e12011-03-30 11:46:32 -07002725 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 }
2727 }
2728
2729 /* Add devices to port list. */
2730 id_iter = (char *)ha->gid_list;
2731 for (index = 0; index < entries; index++) {
2732 domain = ((struct gid_list_info *)id_iter)->domain;
2733 area = ((struct gid_list_info *)id_iter)->area;
2734 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002735 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 loop_id = (uint16_t)
2737 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002738 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 loop_id = le16_to_cpu(
2740 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002741 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742
2743 /* Bypass reserved domain fields. */
2744 if ((domain & 0xf0) == 0xf0)
2745 continue;
2746
2747 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002748 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002749 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 continue;
2751
2752 /* Bypass invalid local loop ID. */
2753 if (loop_id > LAST_LOCAL_LOOP_ID)
2754 continue;
2755
2756 /* Fill in member data. */
2757 new_fcport->d_id.b.domain = domain;
2758 new_fcport->d_id.b.area = area;
2759 new_fcport->d_id.b.al_pa = al_pa;
2760 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002761 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002763 ql_dbg(ql_dbg_disc, vha, 0x201a,
2764 "Failed to retrieve fcport information "
2765 "-- get_port_database=%x, loop_id=0x%04x.\n",
2766 rval2, new_fcport->loop_id);
2767 ql_dbg(ql_dbg_disc, vha, 0x201b,
2768 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002769 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 continue;
2771 }
2772
2773 /* Check for matching device in port list. */
2774 found = 0;
2775 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002776 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 if (memcmp(new_fcport->port_name, fcport->port_name,
2778 WWN_SIZE))
2779 continue;
2780
Shyam Sundarddb9b122009-03-24 09:08:10 -07002781 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 fcport->loop_id = new_fcport->loop_id;
2783 fcport->port_type = new_fcport->port_type;
2784 fcport->d_id.b24 = new_fcport->d_id.b24;
2785 memcpy(fcport->node_name, new_fcport->node_name,
2786 WWN_SIZE);
2787
2788 found++;
2789 break;
2790 }
2791
2792 if (!found) {
2793 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002794 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795
2796 /* Allocate a new replacement fcport. */
2797 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002798 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002800 ql_log(ql_log_warn, vha, 0x201c,
2801 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 rval = QLA_MEMORY_ALLOC_FAILED;
2803 goto cleanup_allocation;
2804 }
2805 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2806 }
2807
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002808 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002809 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002810
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002811 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812
2813 found_devs++;
2814 }
2815
2816cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002817 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818
2819 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002820 ql_dbg(ql_dbg_disc, vha, 0x201d,
2821 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 }
2823
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 return (rval);
2825}
2826
2827static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002828qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002829{
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002830 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002831 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002832 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002833 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002834
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002835 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002836 return;
2837
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07002838 if (atomic_read(&fcport->state) != FCS_ONLINE)
2839 return;
2840
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002841 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2842 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002843 return;
2844
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002845 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002846 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002847 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002848 ql_dbg(ql_dbg_disc, vha, 0x2004,
2849 "Unable to adjust iIDMA "
2850 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x "
2851 "%04x.\n", fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002852 fcport->port_name[2], fcport->port_name[3],
2853 fcport->port_name[4], fcport->port_name[5],
2854 fcport->port_name[6], fcport->port_name[7], rval,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002855 fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002856 } else {
Chad Dupuisdaae62a2012-05-15 14:34:23 -04002857 link_speed = qla2x00_get_link_speed_str(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002858 ql_dbg(ql_dbg_disc, vha, 0x2005,
2859 "iIDMA adjusted to %s GB/s "
2860 "on %02x%02x%02x%02x%02x%02x%02x%02x.\n", link_speed,
2861 fcport->port_name[0], fcport->port_name[1],
2862 fcport->port_name[2], fcport->port_name[3],
2863 fcport->port_name[4], fcport->port_name[5],
2864 fcport->port_name[6], fcport->port_name[7]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002865 }
2866}
2867
Adrian Bunk23be3312006-11-24 02:46:01 +01002868static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002869qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002870{
2871 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002872 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002873 unsigned long flags;
8482e1182005-04-17 15:04:54 -05002874
Andrew Vasquezac280b62009-08-20 11:06:05 -07002875 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002876
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002877 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2878 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002879 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2880 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2881 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002882 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002883 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002884 ql_log(ql_log_warn, vha, 0x2006,
2885 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07002886 return;
2887 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002888 /*
2889 * Create target mode FC NEXUS in qla_target.c if target mode is
2890 * enabled..
2891 */
2892 qlt_fc_port_added(vha, fcport);
2893
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002894 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002895 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002896 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002897
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002898 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002899
2900 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002901 if (fcport->port_type == FCT_INITIATOR)
2902 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2903 if (fcport->port_type == FCT_TARGET)
2904 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002905 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002906}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907
2908/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002909 * qla2x00_update_fcport
2910 * Updates device on list.
2911 *
2912 * Input:
2913 * ha = adapter block pointer.
2914 * fcport = port structure pointer.
2915 *
2916 * Return:
2917 * 0 - Success
2918 * BIT_0 - error
2919 *
2920 * Context:
2921 * Kernel context.
2922 */
2923void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002924qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002925{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002926 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002927 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002928 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01002929
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002930 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08002931 qla24xx_update_fcport_fcp_prio(vha, fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002932 qla2x00_reg_remote_port(vha, fcport);
Chad Dupuisec426e12011-03-30 11:46:32 -07002933 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Adrian Bunk23be3312006-11-24 02:46:01 +01002934}
2935
2936/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 * qla2x00_configure_fabric
2938 * Setup SNS devices with loop ID's.
2939 *
2940 * Input:
2941 * ha = adapter block pointer.
2942 *
2943 * Returns:
2944 * 0 = success.
2945 * BIT_0 = error
2946 */
2947static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002948qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949{
Arun Easib3b02e62012-02-09 11:15:39 -08002950 int rval;
Joe Carnuccio4dc77c32012-05-15 14:34:24 -04002951 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 uint16_t next_loopid;
2953 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002954 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002956 struct qla_hw_data *ha = vha->hw;
2957 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958
2959 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002960 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002961 loop_id = NPH_F_PORT;
2962 else
2963 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002964 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002966 ql_dbg(ql_dbg_disc, vha, 0x201f,
2967 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002969 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 return (QLA_SUCCESS);
2971 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002972 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002975 /* FDMI support. */
2976 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002977 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2978 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002979
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002981 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002982 loop_id = NPH_SNS;
2983 else
2984 loop_id = SIMPLE_NAME_SERVER;
Chad Dupuis0b91d112012-02-09 11:15:42 -08002985 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
2986 0xfc, mb, BIT_1|BIT_0);
2987 if (rval != QLA_SUCCESS) {
2988 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccio4dc77c32012-05-15 14:34:24 -04002989 break;
Chad Dupuis0b91d112012-02-09 11:15:42 -08002990 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002992 ql_dbg(ql_dbg_disc, vha, 0x2042,
2993 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
2994 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
2995 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 return (QLA_SUCCESS);
2997 }
2998
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002999 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3000 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003002 ql_dbg(ql_dbg_disc, vha, 0x2045,
3003 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003005 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003007 ql_dbg(ql_dbg_disc, vha, 0x2049,
3008 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003010 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003012 ql_dbg(ql_dbg_disc, vha, 0x204f,
3013 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003014 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003016 ql_dbg(ql_dbg_disc, vha, 0x2053,
3017 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 }
3019 }
3020
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003021 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 if (rval != QLA_SUCCESS)
3023 break;
3024
Joe Carnuccio4dc77c32012-05-15 14:34:24 -04003025 /* Add new ports to existing port list */
3026 list_splice_tail_init(&new_fcports, &vha->vp_fcports);
3027
3028 /* Starting free loop ID. */
3029 next_loopid = ha->min_external_loopid;
3030
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003031 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3032 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 break;
3034
3035 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3036 continue;
3037
Joe Carnuccio4dc77c32012-05-15 14:34:24 -04003038 /* Logout lost/gone fabric devices (non-FCP2) */
Joe Carnuccioc0822b62012-05-15 14:34:21 -04003039 if (fcport->scan_state != QLA_FCPORT_SCAN_FOUND &&
Arun Easib3b02e62012-02-09 11:15:39 -08003040 atomic_read(&fcport->state) == FCS_ONLINE) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003041 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003042 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003044 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 fcport->port_type != FCT_INITIATOR &&
3046 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003047 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003048 fcport->loop_id,
3049 fcport->d_id.b.domain,
3050 fcport->d_id.b.area,
3051 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 }
Joe Carnuccioc0822b62012-05-15 14:34:21 -04003053 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 }
Joe Carnuccioc0822b62012-05-15 14:34:21 -04003055 fcport->scan_state = QLA_FCPORT_SCAN_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056
Joe Carnuccio4dc77c32012-05-15 14:34:24 -04003057 /* Login fabric devices that need a login */
3058 if ((fcport->flags & FCF_LOGIN_NEEDED) != 0 &&
3059 atomic_read(&vha->loop_down_timer) == 0) {
3060 if (fcport->loop_id == FC_NO_LOOP_ID) {
3061 fcport->loop_id = next_loopid;
3062 rval = qla2x00_find_new_loop_id(
3063 base_vha, fcport);
3064 if (rval != QLA_SUCCESS) {
3065 /* Ran out of IDs to use */
3066 continue;
3067 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 }
3069 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070
bdf79622005-04-17 15:06:53 -05003071 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003072 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 }
3074 } while (0);
3075
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003077 ql_dbg(ql_dbg_disc, vha, 0x2068,
3078 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 }
3080
3081 return (rval);
3082}
3083
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084/*
3085 * qla2x00_find_all_fabric_devs
3086 *
3087 * Input:
3088 * ha = adapter block pointer.
3089 * dev = database device entry pointer.
3090 *
3091 * Returns:
3092 * 0 = success.
3093 *
3094 * Context:
3095 * Kernel context.
3096 */
3097static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003098qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3099 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100{
3101 int rval;
3102 uint16_t loop_id;
3103 fc_port_t *fcport, *new_fcport, *fcptemp;
3104 int found;
3105
3106 sw_info_t *swl;
3107 int swl_idx;
3108 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003109 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003110 struct qla_hw_data *ha = vha->hw;
3111 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003112 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113
3114 rval = QLA_SUCCESS;
3115
3116 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08003117 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08003118 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08003119 GFP_KERNEL);
3120 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003121 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003123 ql_dbg(ql_dbg_disc, vha, 0x2054,
3124 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08003126 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003127 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003129 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003131 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003133 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003134 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3135 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003137
3138 /* If other queries succeeded probe for FC-4 type */
3139 if (swl)
3140 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 }
3142 swl_idx = 0;
3143
3144 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003145 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003147 ql_log(ql_log_warn, vha, 0x205e,
3148 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 return (QLA_MEMORY_ALLOC_FAILED);
3150 }
3151 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 /* Set start port ID scan at adapter ID. */
3153 first_dev = 1;
3154 last_dev = 0;
3155
3156 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003157 loop_id = ha->min_external_loopid;
3158 for (; loop_id <= ha->max_loop_id; loop_id++) {
3159 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 continue;
3161
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003162 if (ha->current_topology == ISP_CFG_FL &&
3163 (atomic_read(&vha->loop_down_timer) ||
3164 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003165 atomic_set(&vha->loop_down_timer, 0);
3166 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3167 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003169 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170
3171 if (swl != NULL) {
3172 if (last_dev) {
3173 wrap.b24 = new_fcport->d_id.b24;
3174 } else {
3175 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3176 memcpy(new_fcport->node_name,
3177 swl[swl_idx].node_name, WWN_SIZE);
3178 memcpy(new_fcport->port_name,
3179 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003180 memcpy(new_fcport->fabric_port_name,
3181 swl[swl_idx].fabric_port_name, WWN_SIZE);
3182 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003183 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184
3185 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3186 last_dev = 1;
3187 }
3188 swl_idx++;
3189 }
3190 } else {
3191 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003192 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003194 ql_log(ql_log_warn, vha, 0x2064,
3195 "SNS scan failed -- assuming "
3196 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 list_for_each_entry_safe(fcport, fcptemp,
3198 new_fcports, list) {
3199 list_del(&fcport->list);
3200 kfree(fcport);
3201 }
3202 rval = QLA_SUCCESS;
3203 break;
3204 }
3205 }
3206
3207 /* If wrap on switch device list, exit. */
3208 if (first_dev) {
3209 wrap.b24 = new_fcport->d_id.b24;
3210 first_dev = 0;
3211 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003212 ql_dbg(ql_dbg_disc, vha, 0x2065,
3213 "Device wrap (%02x%02x%02x).\n",
3214 new_fcport->d_id.b.domain,
3215 new_fcport->d_id.b.area,
3216 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 break;
3218 }
3219
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003220 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003221 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 continue;
3223
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003224 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003225 found = 0;
3226 if (ha->num_vhosts) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003227 unsigned long flags;
3228
3229 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003230 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003231 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3232 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003233 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003234 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003235 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003236 spin_unlock_irqrestore(&ha->vport_slock, flags);
3237
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003238 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003239 continue;
3240 }
3241
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003242 /* Bypass if same domain and area of adapter. */
3243 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003244 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003245 ISP_CFG_FL)
3246 continue;
3247
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 /* Bypass reserved domain fields. */
3249 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3250 continue;
3251
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003252 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003253 if (ql2xgffidenable &&
3254 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3255 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003256 continue;
3257
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 /* Locate matching device in database. */
3259 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003260 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 if (memcmp(new_fcport->port_name, fcport->port_name,
3262 WWN_SIZE))
3263 continue;
3264
Joe Carnuccioc0822b62012-05-15 14:34:21 -04003265 fcport->scan_state = QLA_FCPORT_SCAN_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08003266
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 found++;
3268
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003269 /* Update port state. */
3270 memcpy(fcport->fabric_port_name,
3271 new_fcport->fabric_port_name, WWN_SIZE);
3272 fcport->fp_speed = new_fcport->fp_speed;
3273
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 /*
3275 * If address the same and state FCS_ONLINE, nothing
3276 * changed.
3277 */
3278 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3279 atomic_read(&fcport->state) == FCS_ONLINE) {
3280 break;
3281 }
3282
3283 /*
3284 * If device was not a fabric device before.
3285 */
3286 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3287 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04003288 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 fcport->flags |= (FCF_FABRIC_DEVICE |
3290 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 break;
3292 }
3293
3294 /*
3295 * Port ID changed or device was marked to be updated;
3296 * Log it out if still logged in and mark it for
3297 * relogin later.
3298 */
3299 fcport->d_id.b24 = new_fcport->d_id.b24;
3300 fcport->flags |= FCF_LOGIN_NEEDED;
3301 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003302 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Arun Easi0eba25d2012-02-09 11:15:58 -08003303 (fcport->flags & FCF_ASYNC_SENT) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 fcport->port_type != FCT_INITIATOR &&
3305 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003306 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003307 fcport->d_id.b.domain, fcport->d_id.b.area,
3308 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003309 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310 }
3311
3312 break;
3313 }
3314
3315 if (found)
3316 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 /* If device was not in our fcports list, then add it. */
3318 list_add_tail(&new_fcport->list, new_fcports);
3319
3320 /* Allocate a new replacement fcport. */
3321 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003322 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003324 ql_log(ql_log_warn, vha, 0x2066,
3325 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 return (QLA_MEMORY_ALLOC_FAILED);
3327 }
3328 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3329 new_fcport->d_id.b24 = nxt_d_id.b24;
3330 }
3331
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003332 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 return (rval);
3335}
3336
3337/*
3338 * qla2x00_find_new_loop_id
3339 * Scan through our port list and find a new usable loop ID.
3340 *
3341 * Input:
3342 * ha: adapter state pointer.
3343 * dev: port structure pointer.
3344 *
3345 * Returns:
3346 * qla2x00 local function return status code.
3347 *
3348 * Context:
3349 * Kernel context.
3350 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003351int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003352qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353{
3354 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003355 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07003356 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357
3358 rval = QLA_SUCCESS;
3359
Chad Dupuis5f16b332012-08-22 14:21:00 -04003360 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361
Chad Dupuis5f16b332012-08-22 14:21:00 -04003362 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
3363 LOOPID_MAP_SIZE);
3364 if (dev->loop_id >= LOOPID_MAP_SIZE ||
3365 qla2x00_is_reserved_id(vha, dev->loop_id)) {
3366 dev->loop_id = FC_NO_LOOP_ID;
3367 rval = QLA_FUNCTION_FAILED;
3368 } else
3369 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370
Chad Dupuis5f16b332012-08-22 14:21:00 -04003371 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372
Chad Dupuis5f16b332012-08-22 14:21:00 -04003373 if (rval == QLA_SUCCESS)
3374 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
3375 "Assigning new loopid=%x, portid=%x.\n",
3376 dev->loop_id, dev->d_id.b24);
3377 else
3378 ql_log(ql_log_warn, dev->vha, 0x2087,
3379 "No loop_id's available, portid=%x.\n",
3380 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381
3382 return (rval);
3383}
3384
3385/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 * qla2x00_fabric_dev_login
3387 * Login fabric target device and update FC port database.
3388 *
3389 * Input:
3390 * ha: adapter state pointer.
3391 * fcport: port structure list pointer.
3392 * next_loopid: contains value of a new loop ID that can be used
3393 * by the next login attempt.
3394 *
3395 * Returns:
3396 * qla2x00 local function return status code.
3397 *
3398 * Context:
3399 * Kernel context.
3400 */
3401static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003402qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403 uint16_t *next_loopid)
3404{
3405 int rval;
3406 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003407 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003408 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409
3410 rval = QLA_SUCCESS;
3411 retry = 0;
3412
Andrew Vasquezac280b62009-08-20 11:06:05 -07003413 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003414 if (fcport->flags & FCF_ASYNC_SENT)
3415 return rval;
3416 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003417 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3418 if (!rval)
3419 return rval;
3420 }
3421
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003422 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003423 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003425 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003426 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003427 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003428 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003429 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003431 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003432 fcport->d_id.b.domain, fcport->d_id.b.area,
3433 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003434 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003436 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 }
Chad Dupuis0b91d112012-02-09 11:15:42 -08003438 } else {
3439 /* Retry Login. */
3440 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 }
3442
3443 return (rval);
3444}
3445
3446/*
3447 * qla2x00_fabric_login
3448 * Issue fabric login command.
3449 *
3450 * Input:
3451 * ha = adapter block pointer.
3452 * device = pointer to FC device type structure.
3453 *
3454 * Returns:
3455 * 0 - Login successfully
3456 * 1 - Login failed
3457 * 2 - Initiator device
3458 * 3 - Fatal error
3459 */
3460int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003461qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 uint16_t *next_loopid)
3463{
3464 int rval;
3465 int retry;
3466 uint16_t tmp_loopid;
3467 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003468 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469
3470 retry = 0;
3471 tmp_loopid = 0;
3472
3473 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003474 ql_dbg(ql_dbg_disc, vha, 0x2000,
3475 "Trying Fabric Login w/loop id 0x%04x for port "
3476 "%02x%02x%02x.\n",
3477 fcport->loop_id, fcport->d_id.b.domain,
3478 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479
3480 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08003481 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 fcport->d_id.b.domain, fcport->d_id.b.area,
3483 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08003484 if (rval != QLA_SUCCESS) {
3485 return rval;
3486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487 if (mb[0] == MBS_PORT_ID_USED) {
3488 /*
3489 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003490 * recommends the driver perform an implicit login with
3491 * the specified ID again. The ID we just used is save
3492 * here so we return with an ID that can be tried by
3493 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 */
3495 retry++;
3496 tmp_loopid = fcport->loop_id;
3497 fcport->loop_id = mb[1];
3498
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003499 ql_dbg(ql_dbg_disc, vha, 0x2001,
3500 "Fabric Login: port in use - next loop "
3501 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003503 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504
3505 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3506 /*
3507 * Login succeeded.
3508 */
3509 if (retry) {
3510 /* A retry occurred before. */
3511 *next_loopid = tmp_loopid;
3512 } else {
3513 /*
3514 * No retry occurred before. Just increment the
3515 * ID value for next login.
3516 */
3517 *next_loopid = (fcport->loop_id + 1);
3518 }
3519
3520 if (mb[1] & BIT_0) {
3521 fcport->port_type = FCT_INITIATOR;
3522 } else {
3523 fcport->port_type = FCT_TARGET;
3524 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003525 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 }
3527 }
3528
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003529 if (mb[10] & BIT_0)
3530 fcport->supported_classes |= FC_COS_CLASS2;
3531 if (mb[10] & BIT_1)
3532 fcport->supported_classes |= FC_COS_CLASS3;
3533
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003534 if (IS_FWI2_CAPABLE(ha)) {
3535 if (mb[10] & BIT_7)
3536 fcport->flags |=
3537 FCF_CONF_COMP_SUPPORTED;
3538 }
3539
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 rval = QLA_SUCCESS;
3541 break;
3542 } else if (mb[0] == MBS_LOOP_ID_USED) {
3543 /*
3544 * Loop ID already used, try next loop ID.
3545 */
3546 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003547 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 if (rval != QLA_SUCCESS) {
3549 /* Ran out of loop IDs to use */
3550 break;
3551 }
3552 } else if (mb[0] == MBS_COMMAND_ERROR) {
3553 /*
3554 * Firmware possibly timed out during login. If NO
3555 * retries are left to do then the device is declared
3556 * dead.
3557 */
3558 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003559 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003560 fcport->d_id.b.domain, fcport->d_id.b.area,
3561 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003562 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563
3564 rval = 1;
3565 break;
3566 } else {
3567 /*
3568 * unrecoverable / not handled error
3569 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003570 ql_dbg(ql_dbg_disc, vha, 0x2002,
3571 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
3572 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
3573 fcport->d_id.b.area, fcport->d_id.b.al_pa,
3574 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575
3576 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003577 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003578 fcport->d_id.b.domain, fcport->d_id.b.area,
3579 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003580 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003581 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582
3583 rval = 3;
3584 break;
3585 }
3586 }
3587
3588 return (rval);
3589}
3590
3591/*
3592 * qla2x00_local_device_login
3593 * Issue local device login command.
3594 *
3595 * Input:
3596 * ha = adapter block pointer.
3597 * loop_id = loop id of device to login to.
3598 *
3599 * Returns (Where's the #define!!!!):
3600 * 0 - Login successfully
3601 * 1 - Login failed
3602 * 3 - Fatal error
3603 */
3604int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003605qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606{
3607 int rval;
3608 uint16_t mb[MAILBOX_REGISTER_COUNT];
3609
3610 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003611 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612 if (rval == QLA_SUCCESS) {
3613 /* Interrogate mailbox registers for any errors */
3614 if (mb[0] == MBS_COMMAND_ERROR)
3615 rval = 1;
3616 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3617 /* device not in PCB table */
3618 rval = 3;
3619 }
3620
3621 return (rval);
3622}
3623
3624/*
3625 * qla2x00_loop_resync
3626 * Resync with fibre channel devices.
3627 *
3628 * Input:
3629 * ha = adapter block pointer.
3630 *
3631 * Returns:
3632 * 0 = success
3633 */
3634int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003635qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003637 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003639 struct req_que *req;
3640 struct rsp_que *rsp;
3641
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003642 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003643 req = vha->hw->req_q_map[0];
3644 else
3645 req = vha->req;
3646 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003648 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3649 if (vha->flags.online) {
3650 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3652 wait_time = 256;
3653 do {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003654 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003655 qla2x00_marker(vha, req, rsp, 0, 0,
3656 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003657 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658
3659 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003660 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003662 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003664 } while (!atomic_read(&vha->loop_down_timer) &&
3665 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3666 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3667 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 }
3670
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003671 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003674 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003675 ql_dbg(ql_dbg_disc, vha, 0x206c,
3676 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677
3678 return (rval);
3679}
3680
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003681/*
3682* qla2x00_perform_loop_resync
3683* Description: This function will set the appropriate flags and call
3684* qla2x00_loop_resync. If successful loop will be resynced
3685* Arguments : scsi_qla_host_t pointer
3686* returm : Success or Failure
3687*/
3688
3689int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
3690{
3691 int32_t rval = 0;
3692
3693 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
3694 /*Configure the flags so that resync happens properly*/
3695 atomic_set(&ha->loop_down_timer, 0);
3696 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3697 atomic_set(&ha->loop_state, LOOP_UP);
3698 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
3699 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
3700 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3701
3702 rval = qla2x00_loop_resync(ha);
3703 } else
3704 atomic_set(&ha->loop_state, LOOP_DEAD);
3705
3706 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3707 }
3708
3709 return rval;
3710}
3711
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003713qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003714{
3715 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07003716 struct scsi_qla_host *vha;
3717 struct qla_hw_data *ha = base_vha->hw;
3718 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003719
Arun Easifeafb7b2010-09-03 14:57:00 -07003720 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003721 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07003722 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
3723 atomic_inc(&vha->vref_count);
3724 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08003725 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07003726 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
3727 spin_unlock_irqrestore(&ha->vport_slock, flags);
3728
Andrew Vasquez67becc02009-08-25 11:36:20 -07003729 qla2x00_rport_del(fcport);
Arun Easifeafb7b2010-09-03 14:57:00 -07003730
3731 spin_lock_irqsave(&ha->vport_slock, flags);
3732 }
3733 }
3734 atomic_dec(&vha->vref_count);
3735 }
3736 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003737}
3738
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003739/*
3740* qla82xx_quiescent_state_cleanup
3741* Description: This function will block the new I/Os
3742* Its not aborting any I/Os as context
3743* is not destroyed during quiescence
3744* Arguments: scsi_qla_host_t
3745* return : void
3746*/
3747void
3748qla82xx_quiescent_state_cleanup(scsi_qla_host_t *vha)
3749{
3750 struct qla_hw_data *ha = vha->hw;
3751 struct scsi_qla_host *vp;
3752
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003753 ql_dbg(ql_dbg_p3p, vha, 0xb002,
3754 "Performing ISP error recovery - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003755
3756 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3757 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3758 atomic_set(&vha->loop_state, LOOP_DOWN);
3759 qla2x00_mark_all_devices_lost(vha, 0);
3760 list_for_each_entry(vp, &ha->vp_list, list)
3761 qla2x00_mark_all_devices_lost(vha, 0);
3762 } else {
3763 if (!atomic_read(&vha->loop_down_timer))
3764 atomic_set(&vha->loop_down_timer,
3765 LOOP_DOWN_TIME);
3766 }
3767 /* Wait for pending cmds to complete */
3768 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
3769}
3770
Giridhar Malavalia9083012010-04-12 17:59:55 -07003771void
3772qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3773{
3774 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003775 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003776 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08003777 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003778
Saurav Kashyape46ef002011-02-23 15:27:16 -08003779 /* For ISP82XX, driver waits for completion of the commands.
3780 * online flag should be set.
3781 */
3782 if (!IS_QLA82XX(ha))
3783 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003784 ha->flags.chip_reset_done = 0;
3785 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04003786 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003787
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003788 ql_log(ql_log_info, vha, 0x00af,
3789 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003790
Saurav Kashyape46ef002011-02-23 15:27:16 -08003791 /* For ISP82XX, reset_chip is just disabling interrupts.
3792 * Driver waits for the completion of the commands.
3793 * the interrupts need to be enabled.
3794 */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003795 if (!IS_QLA82XX(ha))
3796 ha->isp_ops->reset_chip(vha);
3797
3798 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3799 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3800 atomic_set(&vha->loop_state, LOOP_DOWN);
3801 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07003802
3803 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003804 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003805 atomic_inc(&vp->vref_count);
3806 spin_unlock_irqrestore(&ha->vport_slock, flags);
3807
Giridhar Malavalia9083012010-04-12 17:59:55 -07003808 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07003809
3810 spin_lock_irqsave(&ha->vport_slock, flags);
3811 atomic_dec(&vp->vref_count);
3812 }
3813 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003814 } else {
3815 if (!atomic_read(&vha->loop_down_timer))
3816 atomic_set(&vha->loop_down_timer,
3817 LOOP_DOWN_TIME);
3818 }
3819
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08003820 /* Clear all async request states across all VPs. */
3821 list_for_each_entry(fcport, &vha->vp_fcports, list)
3822 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
3823 spin_lock_irqsave(&ha->vport_slock, flags);
3824 list_for_each_entry(vp, &ha->vp_list, list) {
3825 atomic_inc(&vp->vref_count);
3826 spin_unlock_irqrestore(&ha->vport_slock, flags);
3827
3828 list_for_each_entry(fcport, &vp->vp_fcports, list)
3829 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
3830
3831 spin_lock_irqsave(&ha->vport_slock, flags);
3832 atomic_dec(&vp->vref_count);
3833 }
3834 spin_unlock_irqrestore(&ha->vport_slock, flags);
3835
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07003836 if (!ha->flags.eeh_busy) {
3837 /* Make sure for ISP 82XX IO DMA is complete */
3838 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08003839 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003840 ql_log(ql_log_info, vha, 0x00b4,
3841 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07003842
Saurav Kashyape46ef002011-02-23 15:27:16 -08003843 /* Done waiting for pending commands.
3844 * Reset the online flag.
3845 */
3846 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003847 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07003849 /* Requeue all commands in outstanding command list. */
3850 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3851 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003852}
3853
3854/*
3855* qla2x00_abort_isp
3856* Resets ISP and aborts all outstanding commands.
3857*
3858* Input:
3859* ha = adapter block pointer.
3860*
3861* Returns:
3862* 0 = success
3863*/
3864int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003865qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003867 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003869 struct qla_hw_data *ha = vha->hw;
3870 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003871 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07003872 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003873
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003874 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003875 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876
Andrew Vasquez85880802009-12-15 21:29:46 -08003877 if (unlikely(pci_channel_offline(ha->pdev) &&
3878 ha->flags.pci_channel_io_perm_failure)) {
3879 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3880 status = 0;
3881 return status;
3882 }
3883
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003884 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003885
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003886 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003888 if (!qla2x00_restart_isp(vha)) {
3889 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003891 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892 /*
3893 * Issue marker command only when we are going
3894 * to start the I/O .
3895 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003896 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897 }
3898
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003899 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003901 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003903 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003904 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003905
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003906 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
3907 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003908 if (ha->fce) {
3909 ha->flags.fce_enabled = 1;
3910 memset(ha->fce, 0,
3911 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003912 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003913 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3914 &ha->fce_bufs);
3915 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003916 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003917 "Unable to reinitialize FCE "
3918 "(%d).\n", rval);
3919 ha->flags.fce_enabled = 0;
3920 }
3921 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003922
3923 if (ha->eft) {
3924 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003925 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003926 ha->eft_dma, EFT_NUM_BUFFERS);
3927 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003928 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003929 "Unable to reinitialize EFT "
3930 "(%d).\n", rval);
3931 }
3932 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003933 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003934 vha->flags.online = 1;
3935 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003937 ql_log(ql_log_fatal, vha, 0x8035,
3938 "ISP error recover failed - "
3939 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003940 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003941 * The next call disables the board
3942 * completely.
3943 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003944 ha->isp_ops->reset_adapter(vha);
3945 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003947 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 status = 0;
3949 } else { /* schedule another ISP abort */
3950 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003951 ql_dbg(ql_dbg_taskm, vha, 0x8020,
3952 "ISP abort - retry remaining %d.\n",
3953 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954 status = 1;
3955 }
3956 } else {
3957 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003958 ql_dbg(ql_dbg_taskm, vha, 0x8021,
3959 "ISP error recovery - retrying (%d) "
3960 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003961 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003962 status = 1;
3963 }
3964 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003965
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 }
3967
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003968 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003969 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07003970
3971 spin_lock_irqsave(&ha->vport_slock, flags);
3972 list_for_each_entry(vp, &ha->vp_list, list) {
3973 if (vp->vp_idx) {
3974 atomic_inc(&vp->vref_count);
3975 spin_unlock_irqrestore(&ha->vport_slock, flags);
3976
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003977 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07003978
3979 spin_lock_irqsave(&ha->vport_slock, flags);
3980 atomic_dec(&vp->vref_count);
3981 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003982 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003983 spin_unlock_irqrestore(&ha->vport_slock, flags);
3984
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003985 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08003986 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
3987 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 }
3989
3990 return(status);
3991}
3992
3993/*
3994* qla2x00_restart_isp
3995* restarts the ISP after a reset
3996*
3997* Input:
3998* ha = adapter block pointer.
3999*
4000* Returns:
4001* 0 = success
4002*/
4003static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004004qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004006 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004008 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004009 struct req_que *req = ha->req_q_map[0];
4010 struct rsp_que *rsp = ha->rsp_q_map[0];
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004011 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012
4013 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004014 if (qla2x00_isp_firmware(vha)) {
4015 vha->flags.online = 0;
4016 status = ha->isp_ops->chip_diag(vha);
4017 if (!status)
4018 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 }
4020
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004021 if (!status && !(status = qla2x00_init_rings(vha))) {
4022 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004023 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004024 /* Initialize the queues in use */
4025 qla25xx_init_queues(ha);
4026
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004027 status = qla2x00_fw_ready(vha);
4028 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004029 ql_dbg(ql_dbg_taskm, vha, 0x8031,
4030 "Start configure loop status = %d.\n", status);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004031
4032 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004033 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004034
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004035 vha->flags.online = 1;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004036
4037 /*
4038 * Process any ATIO queue entries that came in
4039 * while we weren't online.
4040 */
4041 spin_lock_irqsave(&ha->hardware_lock, flags);
4042 if (qla_tgt_mode_enabled(vha))
4043 qlt_24xx_process_atio_queue(vha);
4044 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4045
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4047 wait_time = 256;
4048 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004049 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4050 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004051 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004052 } while (!atomic_read(&vha->loop_down_timer) &&
4053 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4054 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4055 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 }
4057
4058 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004059 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 status = 0;
4061
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004062 ql_dbg(ql_dbg_taskm, vha, 0x8032,
4063 "Configure loop done, status = 0x%x.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 }
4065 return (status);
4066}
4067
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004068static int
4069qla25xx_init_queues(struct qla_hw_data *ha)
4070{
4071 struct rsp_que *rsp = NULL;
4072 struct req_que *req = NULL;
4073 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4074 int ret = -1;
4075 int i;
4076
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004077 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004078 rsp = ha->rsp_q_map[i];
4079 if (rsp) {
4080 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004081 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004082 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004083 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4084 "%s Rsp que: %d init failed.\n",
4085 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004086 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004087 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4088 "%s Rsp que: %d inited.\n",
4089 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004090 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004091 }
4092 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004093 req = ha->req_q_map[i];
4094 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004095 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004096 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004097 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004098 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004099 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4100 "%s Req que: %d init failed.\n",
4101 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004102 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004103 ql_dbg(ql_dbg_init, base_vha, 0x0102,
4104 "%s Req que: %d inited.\n",
4105 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004106 }
4107 }
4108 return ret;
4109}
4110
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111/*
4112* qla2x00_reset_adapter
4113* Reset adapter.
4114*
4115* Input:
4116* ha = adapter block pointer.
4117*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004118void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004119qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120{
4121 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004122 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004123 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004125 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004126 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128 spin_lock_irqsave(&ha->hardware_lock, flags);
4129 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4130 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4131 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4132 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4133 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4134}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004135
4136void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004137qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004138{
4139 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004140 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004141 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4142
Giridhar Malavalia9083012010-04-12 17:59:55 -07004143 if (IS_QLA82XX(ha))
4144 return;
4145
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004146 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004147 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004148
4149 spin_lock_irqsave(&ha->hardware_lock, flags);
4150 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4151 RD_REG_DWORD(&reg->hccr);
4152 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4153 RD_REG_DWORD(&reg->hccr);
4154 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004155
4156 if (IS_NOPOLLING_TYPE(ha))
4157 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004158}
4159
David Miller4e08df32007-04-16 12:37:43 -07004160/* On sparc systems, obtain port and node WWN from firmware
4161 * properties.
4162 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004163static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4164 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004165{
4166#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004167 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004168 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004169 struct device_node *dp = pci_device_to_OF_node(pdev);
4170 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004171 int len;
4172
4173 val = of_get_property(dp, "port-wwn", &len);
4174 if (val && len >= WWN_SIZE)
4175 memcpy(nv->port_name, val, WWN_SIZE);
4176
4177 val = of_get_property(dp, "node-wwn", &len);
4178 if (val && len >= WWN_SIZE)
4179 memcpy(nv->node_name, val, WWN_SIZE);
4180#endif
4181}
4182
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004183int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004184qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004185{
David Miller4e08df32007-04-16 12:37:43 -07004186 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004187 struct init_cb_24xx *icb;
4188 struct nvram_24xx *nv;
4189 uint32_t *dptr;
4190 uint8_t *dptr1, *dptr2;
4191 uint32_t chksum;
4192 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004193 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004194
David Miller4e08df32007-04-16 12:37:43 -07004195 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004196 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004197 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004198
4199 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004200 if (ha->flags.port0) {
4201 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4202 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4203 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004204 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004205 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4206 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004207 ha->nvram_size = sizeof(struct nvram_24xx);
4208 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004209 if (IS_QLA82XX(ha))
4210 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004211
Seokmann Ju281afe12007-07-26 13:43:34 -07004212 /* Get VPD data into cache */
4213 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004214 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004215 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4216
4217 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004218 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004219 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004220 ha->nvram_size);
4221 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4222 chksum += le32_to_cpu(*dptr++);
4223
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004224 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
4225 "Contents of NVRAM\n");
4226 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
4227 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004228
4229 /* Bad NVRAM data, set defaults parameters. */
4230 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4231 || nv->id[3] != ' ' ||
4232 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4233 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004234 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04004235 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004236 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
4237 ql_log(ql_log_warn, vha, 0x006c,
4238 "Falling back to functioning (yet invalid -- WWPN) "
4239 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07004240
4241 /*
4242 * Set default initialization control block.
4243 */
4244 memset(nv, 0, ha->nvram_size);
4245 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4246 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4247 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4248 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4249 nv->exchange_count = __constant_cpu_to_le16(0);
4250 nv->hard_address = __constant_cpu_to_le16(124);
4251 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004252 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004253 nv->port_name[2] = 0x00;
4254 nv->port_name[3] = 0xe0;
4255 nv->port_name[4] = 0x8b;
4256 nv->port_name[5] = 0x1c;
4257 nv->port_name[6] = 0x55;
4258 nv->port_name[7] = 0x86;
4259 nv->node_name[0] = 0x20;
4260 nv->node_name[1] = 0x00;
4261 nv->node_name[2] = 0x00;
4262 nv->node_name[3] = 0xe0;
4263 nv->node_name[4] = 0x8b;
4264 nv->node_name[5] = 0x1c;
4265 nv->node_name[6] = 0x55;
4266 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004267 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004268 nv->login_retry_count = __constant_cpu_to_le16(8);
4269 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4270 nv->login_timeout = __constant_cpu_to_le16(0);
4271 nv->firmware_options_1 =
4272 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4273 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4274 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4275 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4276 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4277 nv->efi_parameters = __constant_cpu_to_le32(0);
4278 nv->reset_delay = 5;
4279 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4280 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4281 nv->link_down_timeout = __constant_cpu_to_le16(30);
4282
4283 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004284 }
4285
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004286 if (!qla_ini_mode_enabled(vha)) {
4287 /* Don't enable full login after initial LIP */
4288 nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13);
4289 /* Don't enable LIP full login for initiator */
4290 nv->host_p &= __constant_cpu_to_le32(~BIT_10);
4291 }
4292
4293 qlt_24xx_config_nvram_stage1(vha, nv);
4294
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004295 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004296 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004297
4298 /* Copy 1st segment. */
4299 dptr1 = (uint8_t *)icb;
4300 dptr2 = (uint8_t *)&nv->version;
4301 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4302 while (cnt--)
4303 *dptr1++ = *dptr2++;
4304
4305 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004306 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004307
4308 /* Copy 2nd segment. */
4309 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4310 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4311 cnt = (uint8_t *)&icb->reserved_3 -
4312 (uint8_t *)&icb->interrupt_delay_timer;
4313 while (cnt--)
4314 *dptr1++ = *dptr2++;
4315
4316 /*
4317 * Setup driver NVRAM options.
4318 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004319 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004320 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004321
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004322 qlt_24xx_config_nvram_stage2(vha, icb);
4323
Andrew Vasquez5341e862006-05-17 15:09:16 -07004324 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004325 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07004326 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4327 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4328 }
4329
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004330 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004331 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004332 /*
4333 * Firmware will apply the following mask if the nodename was
4334 * not provided.
4335 */
4336 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4337 icb->node_name[0] &= 0xF0;
4338 }
4339
4340 /* Set host adapter parameters. */
4341 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004342 ha->flags.enable_lip_reset = 0;
4343 ha->flags.enable_lip_full_login =
4344 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4345 ha->flags.enable_target_reset =
4346 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004347 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004348 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004349
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004350 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4351 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004352
4353 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4354 sizeof(ha->fw_seriallink_options24));
4355
4356 /* save HBA serial number */
4357 ha->serial0 = icb->port_name[5];
4358 ha->serial1 = icb->port_name[6];
4359 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004360 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4361 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004362
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004363 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4364
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004365 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4366
4367 /* Set minimum login_timeout to 4 seconds. */
4368 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4369 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4370 if (le16_to_cpu(nv->login_timeout) < 4)
4371 nv->login_timeout = __constant_cpu_to_le16(4);
4372 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004373 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004374
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004375 /* Set minimum RATOV to 100 tenths of a second. */
4376 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004377
4378 ha->loop_reset_delay = nv->reset_delay;
4379
4380 /* Link Down Timeout = 0:
4381 *
4382 * When Port Down timer expires we will start returning
4383 * I/O's to OS with "DID_NO_CONNECT".
4384 *
4385 * Link Down Timeout != 0:
4386 *
4387 * The driver waits for the link to come up after link down
4388 * before returning I/Os to OS with "DID_NO_CONNECT".
4389 */
4390 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4391 ha->loop_down_abort_time =
4392 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4393 } else {
4394 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4395 ha->loop_down_abort_time =
4396 (LOOP_DOWN_TIME - ha->link_down_timeout);
4397 }
4398
4399 /* Need enough time to try and get the port back. */
4400 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4401 if (qlport_down_retry)
4402 ha->port_down_retry_count = qlport_down_retry;
4403
4404 /* Set login_retry_count */
4405 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4406 if (ha->port_down_retry_count ==
4407 le16_to_cpu(nv->port_down_retry_count) &&
4408 ha->port_down_retry_count > 3)
4409 ha->login_retry_count = ha->port_down_retry_count;
4410 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4411 ha->login_retry_count = ha->port_down_retry_count;
4412 if (ql2xloginretrycount)
4413 ha->login_retry_count = ql2xloginretrycount;
4414
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004415 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004416 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004417 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4418 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4419 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4420 le16_to_cpu(icb->interrupt_delay_timer): 2;
4421 }
4422 icb->firmware_options_2 &= __constant_cpu_to_le32(
4423 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004424 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004425 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004426 ha->zio_mode = QLA_ZIO_MODE_6;
4427
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004428 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004429 "ZIO mode %d enabled; timer delay (%d us).\n",
4430 ha->zio_mode, ha->zio_timer * 100);
4431
4432 icb->firmware_options_2 |= cpu_to_le32(
4433 (uint32_t)ha->zio_mode);
4434 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004435 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004436 }
4437
David Miller4e08df32007-04-16 12:37:43 -07004438 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004439 ql_log(ql_log_warn, vha, 0x0070,
4440 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07004441 }
4442 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004443}
4444
Adrian Bunk413975a2006-06-30 02:33:06 -07004445static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004446qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4447 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004448{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004449 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004450 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004451 uint32_t *dcode, dlen;
4452 uint32_t risc_addr;
4453 uint32_t risc_size;
4454 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004455 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004456 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004457
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004458 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08004459 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004460
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004461 rval = QLA_SUCCESS;
4462
4463 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004464 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004465 *srisc_addr = 0;
4466
4467 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004468 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004469 for (i = 0; i < 4; i++)
4470 dcode[i] = be32_to_cpu(dcode[i]);
4471 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4472 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4473 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4474 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004475 ql_log(ql_log_fatal, vha, 0x008c,
4476 "Unable to verify the integrity of flash firmware "
4477 "image.\n");
4478 ql_log(ql_log_fatal, vha, 0x008d,
4479 "Firmware data: %08x %08x %08x %08x.\n",
4480 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004481
4482 return QLA_FUNCTION_FAILED;
4483 }
4484
4485 while (segments && rval == QLA_SUCCESS) {
4486 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004487 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004488
4489 risc_addr = be32_to_cpu(dcode[2]);
4490 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4491 risc_size = be32_to_cpu(dcode[3]);
4492
4493 fragment = 0;
4494 while (risc_size > 0 && rval == QLA_SUCCESS) {
4495 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4496 if (dlen > risc_size)
4497 dlen = risc_size;
4498
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004499 ql_dbg(ql_dbg_init, vha, 0x008e,
4500 "Loading risc segment@ risc addr %x "
4501 "number of dwords 0x%x offset 0x%x.\n",
4502 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004503
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004504 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004505 for (i = 0; i < dlen; i++)
4506 dcode[i] = swab32(dcode[i]);
4507
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004508 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004509 dlen);
4510 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004511 ql_log(ql_log_fatal, vha, 0x008f,
4512 "Failed to load segment %d of firmware.\n",
4513 fragment);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004514 break;
4515 }
4516
4517 faddr += dlen;
4518 risc_addr += dlen;
4519 risc_size -= dlen;
4520 fragment++;
4521 }
4522
4523 /* Next segment. */
4524 segments--;
4525 }
4526
4527 return rval;
4528}
4529
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004530#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4531
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004532int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004533qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004534{
4535 int rval;
4536 int i, fragment;
4537 uint16_t *wcode, *fwcode;
4538 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4539 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004540 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004541 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004542
4543 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004544 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004545 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004546 ql_log(ql_log_info, vha, 0x0083,
4547 "Fimware image unavailable.\n");
4548 ql_log(ql_log_info, vha, 0x0084,
4549 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004550 return QLA_FUNCTION_FAILED;
4551 }
4552
4553 rval = QLA_SUCCESS;
4554
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004555 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004556 *srisc_addr = 0;
4557 fwcode = (uint16_t *)blob->fw->data;
4558 fwclen = 0;
4559
4560 /* Validate firmware image by checking version. */
4561 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004562 ql_log(ql_log_fatal, vha, 0x0085,
4563 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08004564 blob->fw->size);
4565 goto fail_fw_integrity;
4566 }
4567 for (i = 0; i < 4; i++)
4568 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4569 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4570 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4571 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004572 ql_log(ql_log_fatal, vha, 0x0086,
4573 "Unable to verify integrity of firmware image.\n");
4574 ql_log(ql_log_fatal, vha, 0x0087,
4575 "Firmware data: %04x %04x %04x %04x.\n",
4576 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08004577 goto fail_fw_integrity;
4578 }
4579
4580 seg = blob->segs;
4581 while (*seg && rval == QLA_SUCCESS) {
4582 risc_addr = *seg;
4583 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4584 risc_size = be16_to_cpu(fwcode[3]);
4585
4586 /* Validate firmware image size. */
4587 fwclen += risc_size * sizeof(uint16_t);
4588 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004589 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08004590 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004591 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08004592 goto fail_fw_integrity;
4593 }
4594
4595 fragment = 0;
4596 while (risc_size > 0 && rval == QLA_SUCCESS) {
4597 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4598 if (wlen > risc_size)
4599 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004600 ql_dbg(ql_dbg_init, vha, 0x0089,
4601 "Loading risc segment@ risc addr %x number of "
4602 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08004603
4604 for (i = 0; i < wlen; i++)
4605 wcode[i] = swab16(fwcode[i]);
4606
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004607 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004608 wlen);
4609 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004610 ql_log(ql_log_fatal, vha, 0x008a,
4611 "Failed to load segment %d of firmware.\n",
4612 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08004613 break;
4614 }
4615
4616 fwcode += wlen;
4617 risc_addr += wlen;
4618 risc_size -= wlen;
4619 fragment++;
4620 }
4621
4622 /* Next segment. */
4623 seg++;
4624 }
4625 return rval;
4626
4627fail_fw_integrity:
4628 return QLA_FUNCTION_FAILED;
4629}
4630
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004631static int
4632qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004633{
4634 int rval;
4635 int segments, fragment;
4636 uint32_t *dcode, dlen;
4637 uint32_t risc_addr;
4638 uint32_t risc_size;
4639 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004640 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004641 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004642 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004643 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004644
Andrew Vasquez54333832005-11-09 15:49:04 -08004645 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004646 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004647 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004648 ql_log(ql_log_warn, vha, 0x0090,
4649 "Fimware image unavailable.\n");
4650 ql_log(ql_log_warn, vha, 0x0091,
4651 "Firmware images can be retrieved from: "
4652 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004653
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004654 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004655 }
4656
Chad Dupuiscfb09192011-11-18 09:03:07 -08004657 ql_dbg(ql_dbg_init, vha, 0x0092,
4658 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004659
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004660 rval = QLA_SUCCESS;
4661
4662 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004663 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004664 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004665 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004666 fwclen = 0;
4667
4668 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004669 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004670 ql_log(ql_log_fatal, vha, 0x0093,
4671 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08004672 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004673 goto fail_fw_integrity;
4674 }
4675 for (i = 0; i < 4; i++)
4676 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4677 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4678 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4679 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4680 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004681 ql_log(ql_log_fatal, vha, 0x0094,
4682 "Unable to verify integrity of firmware image (%Zd).\n",
4683 blob->fw->size);
4684 ql_log(ql_log_fatal, vha, 0x0095,
4685 "Firmware data: %08x %08x %08x %08x.\n",
4686 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004687 goto fail_fw_integrity;
4688 }
4689
4690 while (segments && rval == QLA_SUCCESS) {
4691 risc_addr = be32_to_cpu(fwcode[2]);
4692 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4693 risc_size = be32_to_cpu(fwcode[3]);
4694
4695 /* Validate firmware image size. */
4696 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004697 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004698 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08004699 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004700 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08004701
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004702 goto fail_fw_integrity;
4703 }
4704
4705 fragment = 0;
4706 while (risc_size > 0 && rval == QLA_SUCCESS) {
4707 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4708 if (dlen > risc_size)
4709 dlen = risc_size;
4710
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004711 ql_dbg(ql_dbg_init, vha, 0x0097,
4712 "Loading risc segment@ risc addr %x "
4713 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004714
4715 for (i = 0; i < dlen; i++)
4716 dcode[i] = swab32(fwcode[i]);
4717
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004718 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004719 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004720 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004721 ql_log(ql_log_fatal, vha, 0x0098,
4722 "Failed to load segment %d of firmware.\n",
4723 fragment);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004724 break;
4725 }
4726
4727 fwcode += dlen;
4728 risc_addr += dlen;
4729 risc_size -= dlen;
4730 fragment++;
4731 }
4732
4733 /* Next segment. */
4734 segments--;
4735 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004736 return rval;
4737
4738fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004739 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004740}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004741
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004742int
4743qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4744{
4745 int rval;
4746
Andrew Vasqueze337d902009-04-06 22:33:49 -07004747 if (ql2xfwloadbin == 1)
4748 return qla81xx_load_risc(vha, srisc_addr);
4749
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004750 /*
4751 * FW Load priority:
4752 * 1) Firmware via request-firmware interface (.bin file).
4753 * 2) Firmware residing in flash.
4754 */
4755 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4756 if (rval == QLA_SUCCESS)
4757 return rval;
4758
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004759 return qla24xx_load_risc_flash(vha, srisc_addr,
4760 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004761}
4762
4763int
4764qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4765{
4766 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004767 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004768
Andrew Vasqueze337d902009-04-06 22:33:49 -07004769 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004770 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004771
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004772 /*
4773 * FW Load priority:
4774 * 1) Firmware residing in flash.
4775 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004776 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004777 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004778 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004779 if (rval == QLA_SUCCESS)
4780 return rval;
4781
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004782try_blob_fw:
4783 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4784 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4785 return rval;
4786
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004787 ql_log(ql_log_info, vha, 0x0099,
4788 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004789 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4790 if (rval != QLA_SUCCESS)
4791 return rval;
4792
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004793 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004794 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004795 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004796}
4797
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004798void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004799qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004800{
4801 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004802 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004803
Andrew Vasquez85880802009-12-15 21:29:46 -08004804 if (ha->flags.pci_channel_io_perm_failure)
4805 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004806 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004807 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004808 if (!ha->fw_major_version)
4809 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004810
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004811 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004812 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004813 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004814 ha->isp_ops->reset_chip(vha);
4815 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004816 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004817 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004818 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004819 ql_log(ql_log_info, vha, 0x8015,
4820 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004821 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004822 }
4823}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004824
4825int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004826qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004827{
4828 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08004829 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004830 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004831 struct qla_hw_data *ha = vha->hw;
4832 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004833 struct req_que *req;
4834 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004835
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004836 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004837 return -EINVAL;
4838
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004839 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004840 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004841 req = ha->req_q_map[0];
4842 else
4843 req = vha->req;
4844 rsp = req->rsp;
4845
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004846 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004847 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004848 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004849 }
4850
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004851 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004852
4853 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08004854 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
4855 BIT_1);
4856 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
4857 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
4858 ql_dbg(ql_dbg_init, vha, 0x0120,
4859 "Failed SNS login: loop_id=%x, rval2=%d\n",
4860 NPH_SNS, rval2);
4861 else
4862 ql_dbg(ql_dbg_init, vha, 0x0103,
4863 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4864 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
4865 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004866 return (QLA_FUNCTION_FAILED);
4867 }
4868
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004869 atomic_set(&vha->loop_down_timer, 0);
4870 atomic_set(&vha->loop_state, LOOP_UP);
4871 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4872 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4873 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004874
4875 return rval;
4876}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004877
4878/* 84XX Support **************************************************************/
4879
4880static LIST_HEAD(qla_cs84xx_list);
4881static DEFINE_MUTEX(qla_cs84xx_mutex);
4882
4883static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004884qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004885{
4886 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004887 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004888
4889 mutex_lock(&qla_cs84xx_mutex);
4890
4891 /* Find any shared 84xx chip. */
4892 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4893 if (cs84xx->bus == ha->pdev->bus) {
4894 kref_get(&cs84xx->kref);
4895 goto done;
4896 }
4897 }
4898
4899 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4900 if (!cs84xx)
4901 goto done;
4902
4903 kref_init(&cs84xx->kref);
4904 spin_lock_init(&cs84xx->access_lock);
4905 mutex_init(&cs84xx->fw_update_mutex);
4906 cs84xx->bus = ha->pdev->bus;
4907
4908 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4909done:
4910 mutex_unlock(&qla_cs84xx_mutex);
4911 return cs84xx;
4912}
4913
4914static void
4915__qla84xx_chip_release(struct kref *kref)
4916{
4917 struct qla_chip_state_84xx *cs84xx =
4918 container_of(kref, struct qla_chip_state_84xx, kref);
4919
4920 mutex_lock(&qla_cs84xx_mutex);
4921 list_del(&cs84xx->list);
4922 mutex_unlock(&qla_cs84xx_mutex);
4923 kfree(cs84xx);
4924}
4925
4926void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004927qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004928{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004929 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004930 if (ha->cs84xx)
4931 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4932}
4933
4934static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004935qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004936{
4937 int rval;
4938 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004939 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004940
4941 mutex_lock(&ha->cs84xx->fw_update_mutex);
4942
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004943 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004944
4945 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4946
4947 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4948 QLA_SUCCESS;
4949}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004950
4951/* 81XX Support **************************************************************/
4952
4953int
4954qla81xx_nvram_config(scsi_qla_host_t *vha)
4955{
4956 int rval;
4957 struct init_cb_81xx *icb;
4958 struct nvram_81xx *nv;
4959 uint32_t *dptr;
4960 uint8_t *dptr1, *dptr2;
4961 uint32_t chksum;
4962 uint16_t cnt;
4963 struct qla_hw_data *ha = vha->hw;
4964
4965 rval = QLA_SUCCESS;
4966 icb = (struct init_cb_81xx *)ha->init_cb;
4967 nv = ha->nvram;
4968
4969 /* Determine NVRAM starting address. */
4970 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004971 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004972
4973 /* Get VPD data into cache */
4974 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004975 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4976 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004977
4978 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004979 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004980 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004981 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004982 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4983 chksum += le32_to_cpu(*dptr++);
4984
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004985 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
4986 "Contents of NVRAM:\n");
4987 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
4988 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004989
4990 /* Bad NVRAM data, set defaults parameters. */
4991 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4992 || nv->id[3] != ' ' ||
4993 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4994 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004995 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04004996 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004997 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004998 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004999 ql_log(ql_log_info, vha, 0x0074,
5000 "Falling back to functioning (yet invalid -- WWPN) "
5001 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005002
5003 /*
5004 * Set default initialization control block.
5005 */
5006 memset(nv, 0, ha->nvram_size);
5007 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5008 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5009 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5010 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5011 nv->exchange_count = __constant_cpu_to_le16(0);
5012 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005013 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005014 nv->port_name[2] = 0x00;
5015 nv->port_name[3] = 0xe0;
5016 nv->port_name[4] = 0x8b;
5017 nv->port_name[5] = 0x1c;
5018 nv->port_name[6] = 0x55;
5019 nv->port_name[7] = 0x86;
5020 nv->node_name[0] = 0x20;
5021 nv->node_name[1] = 0x00;
5022 nv->node_name[2] = 0x00;
5023 nv->node_name[3] = 0xe0;
5024 nv->node_name[4] = 0x8b;
5025 nv->node_name[5] = 0x1c;
5026 nv->node_name[6] = 0x55;
5027 nv->node_name[7] = 0x86;
5028 nv->login_retry_count = __constant_cpu_to_le16(8);
5029 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5030 nv->login_timeout = __constant_cpu_to_le16(0);
5031 nv->firmware_options_1 =
5032 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5033 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5034 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5035 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5036 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5037 nv->efi_parameters = __constant_cpu_to_le32(0);
5038 nv->reset_delay = 5;
5039 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5040 nv->port_down_retry_count = __constant_cpu_to_le16(30);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005041 nv->link_down_timeout = __constant_cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005042 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005043 nv->enode_mac[1] = 0xC0;
5044 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005045 nv->enode_mac[3] = 0x04;
5046 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005047 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005048
5049 rval = 1;
5050 }
5051
5052 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07005053 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005054
5055 /* Copy 1st segment. */
5056 dptr1 = (uint8_t *)icb;
5057 dptr2 = (uint8_t *)&nv->version;
5058 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5059 while (cnt--)
5060 *dptr1++ = *dptr2++;
5061
5062 icb->login_retry_count = nv->login_retry_count;
5063
5064 /* Copy 2nd segment. */
5065 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5066 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5067 cnt = (uint8_t *)&icb->reserved_5 -
5068 (uint8_t *)&icb->interrupt_delay_timer;
5069 while (cnt--)
5070 *dptr1++ = *dptr2++;
5071
5072 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5073 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5074 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08005075 icb->enode_mac[0] = 0x00;
5076 icb->enode_mac[1] = 0xC0;
5077 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005078 icb->enode_mac[3] = 0x04;
5079 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005080 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005081 }
5082
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005083 /* Use extended-initialization control block. */
5084 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5085
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005086 /*
5087 * Setup driver NVRAM options.
5088 */
5089 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005090 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005091
5092 /* Use alternate WWN? */
5093 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5094 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5095 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5096 }
5097
5098 /* Prepare nodename */
5099 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5100 /*
5101 * Firmware will apply the following mask if the nodename was
5102 * not provided.
5103 */
5104 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5105 icb->node_name[0] &= 0xF0;
5106 }
5107
5108 /* Set host adapter parameters. */
5109 ha->flags.disable_risc_code_load = 0;
5110 ha->flags.enable_lip_reset = 0;
5111 ha->flags.enable_lip_full_login =
5112 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5113 ha->flags.enable_target_reset =
5114 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5115 ha->flags.enable_led_scheme = 0;
5116 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5117
5118 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5119 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5120
5121 /* save HBA serial number */
5122 ha->serial0 = icb->port_name[5];
5123 ha->serial1 = icb->port_name[6];
5124 ha->serial2 = icb->port_name[7];
5125 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5126 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5127
5128 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5129
5130 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5131
5132 /* Set minimum login_timeout to 4 seconds. */
5133 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5134 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5135 if (le16_to_cpu(nv->login_timeout) < 4)
5136 nv->login_timeout = __constant_cpu_to_le16(4);
5137 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5138 icb->login_timeout = nv->login_timeout;
5139
5140 /* Set minimum RATOV to 100 tenths of a second. */
5141 ha->r_a_tov = 100;
5142
5143 ha->loop_reset_delay = nv->reset_delay;
5144
5145 /* Link Down Timeout = 0:
5146 *
5147 * When Port Down timer expires we will start returning
5148 * I/O's to OS with "DID_NO_CONNECT".
5149 *
5150 * Link Down Timeout != 0:
5151 *
5152 * The driver waits for the link to come up after link down
5153 * before returning I/Os to OS with "DID_NO_CONNECT".
5154 */
5155 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5156 ha->loop_down_abort_time =
5157 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5158 } else {
5159 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5160 ha->loop_down_abort_time =
5161 (LOOP_DOWN_TIME - ha->link_down_timeout);
5162 }
5163
5164 /* Need enough time to try and get the port back. */
5165 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5166 if (qlport_down_retry)
5167 ha->port_down_retry_count = qlport_down_retry;
5168
5169 /* Set login_retry_count */
5170 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5171 if (ha->port_down_retry_count ==
5172 le16_to_cpu(nv->port_down_retry_count) &&
5173 ha->port_down_retry_count > 3)
5174 ha->login_retry_count = ha->port_down_retry_count;
5175 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5176 ha->login_retry_count = ha->port_down_retry_count;
5177 if (ql2xloginretrycount)
5178 ha->login_retry_count = ql2xloginretrycount;
5179
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005180 /* if not running MSI-X we need handshaking on interrupts */
5181 if (!vha->hw->flags.msix_enabled && IS_QLA83XX(ha))
5182 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
5183
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005184 /* Enable ZIO. */
5185 if (!vha->flags.init_done) {
5186 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5187 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5188 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5189 le16_to_cpu(icb->interrupt_delay_timer): 2;
5190 }
5191 icb->firmware_options_2 &= __constant_cpu_to_le32(
5192 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5193 vha->flags.process_response_queue = 0;
5194 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5195 ha->zio_mode = QLA_ZIO_MODE_6;
5196
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005197 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005198 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005199 ha->zio_mode,
5200 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005201
5202 icb->firmware_options_2 |= cpu_to_le32(
5203 (uint32_t)ha->zio_mode);
5204 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5205 vha->flags.process_response_queue = 1;
5206 }
5207
5208 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005209 ql_log(ql_log_warn, vha, 0x0076,
5210 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005211 }
5212 return (rval);
5213}
5214
Giridhar Malavalia9083012010-04-12 17:59:55 -07005215int
5216qla82xx_restart_isp(scsi_qla_host_t *vha)
5217{
5218 int status, rval;
5219 uint32_t wait_time;
5220 struct qla_hw_data *ha = vha->hw;
5221 struct req_que *req = ha->req_q_map[0];
5222 struct rsp_que *rsp = ha->rsp_q_map[0];
5223 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005224 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005225
5226 status = qla2x00_init_rings(vha);
5227 if (!status) {
5228 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5229 ha->flags.chip_reset_done = 1;
5230
5231 status = qla2x00_fw_ready(vha);
5232 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005233 ql_log(ql_log_info, vha, 0x803c,
5234 "Start configure loop, status =%d.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005235
5236 /* Issue a marker after FW becomes ready. */
5237 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5238
5239 vha->flags.online = 1;
5240 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5241 wait_time = 256;
5242 do {
5243 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5244 qla2x00_configure_loop(vha);
5245 wait_time--;
5246 } while (!atomic_read(&vha->loop_down_timer) &&
5247 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5248 wait_time &&
5249 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5250 }
5251
5252 /* if no cable then assume it's good */
5253 if ((vha->device_flags & DFLG_NO_CABLE))
5254 status = 0;
5255
Chad Dupuiscfb09192011-11-18 09:03:07 -08005256 ql_log(ql_log_info, vha, 0x8000,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005257 "Configure loop done, status = 0x%x.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005258 }
5259
5260 if (!status) {
5261 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5262
5263 if (!atomic_read(&vha->loop_down_timer)) {
5264 /*
5265 * Issue marker command only when we are going
5266 * to start the I/O .
5267 */
5268 vha->marker_needed = 1;
5269 }
5270
5271 vha->flags.online = 1;
5272
5273 ha->isp_ops->enable_intrs(ha);
5274
5275 ha->isp_abort_cnt = 0;
5276 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5277
Saurav Kashyap53296782011-05-10 11:30:06 -07005278 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07005279 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07005280
Giridhar Malavalia9083012010-04-12 17:59:55 -07005281 if (ha->fce) {
5282 ha->flags.fce_enabled = 1;
5283 memset(ha->fce, 0,
5284 fce_calc_size(ha->fce_bufs));
5285 rval = qla2x00_enable_fce_trace(vha,
5286 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5287 &ha->fce_bufs);
5288 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005289 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005290 "Unable to reinitialize FCE (%d).\n",
5291 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005292 ha->flags.fce_enabled = 0;
5293 }
5294 }
5295
5296 if (ha->eft) {
5297 memset(ha->eft, 0, EFT_SIZE);
5298 rval = qla2x00_enable_eft_trace(vha,
5299 ha->eft_dma, EFT_NUM_BUFFERS);
5300 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005301 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005302 "Unable to reinitialize EFT (%d).\n",
5303 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005304 }
5305 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005306 }
5307
5308 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005309 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005310 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07005311
5312 spin_lock_irqsave(&ha->vport_slock, flags);
5313 list_for_each_entry(vp, &ha->vp_list, list) {
5314 if (vp->vp_idx) {
5315 atomic_inc(&vp->vref_count);
5316 spin_unlock_irqrestore(&ha->vport_slock, flags);
5317
Giridhar Malavalia9083012010-04-12 17:59:55 -07005318 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07005319
5320 spin_lock_irqsave(&ha->vport_slock, flags);
5321 atomic_dec(&vp->vref_count);
5322 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005323 }
Arun Easifeafb7b2010-09-03 14:57:00 -07005324 spin_unlock_irqrestore(&ha->vport_slock, flags);
5325
Giridhar Malavalia9083012010-04-12 17:59:55 -07005326 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005327 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005328 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005329 }
5330
5331 return status;
5332}
5333
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005334void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005335qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005336{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005337 struct qla_hw_data *ha = vha->hw;
5338
5339 if (!ql2xetsenable)
5340 return;
5341
5342 /* Enable ETS Burst. */
5343 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5344 ha->fw_options[2] |= BIT_9;
5345 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005346}
Sarang Radke09ff7012010-03-19 17:03:59 -07005347
5348/*
5349 * qla24xx_get_fcp_prio
5350 * Gets the fcp cmd priority value for the logged in port.
5351 * Looks for a match of the port descriptors within
5352 * each of the fcp prio config entries. If a match is found,
5353 * the tag (priority) value is returned.
5354 *
5355 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005356 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005357 * fcport = port structure pointer.
5358 *
5359 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005360 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005361 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005362 *
5363 * Context:
5364 * Kernel context
5365 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005366static int
Sarang Radke09ff7012010-03-19 17:03:59 -07005367qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5368{
5369 int i, entries;
5370 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005371 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005372 uint32_t pid1, pid2;
5373 uint64_t wwn1, wwn2;
5374 struct qla_fcp_prio_entry *pri_entry;
5375 struct qla_hw_data *ha = vha->hw;
5376
5377 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005378 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005379
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005380 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005381 entries = ha->fcp_prio_cfg->num_entries;
5382 pri_entry = &ha->fcp_prio_cfg->entry[0];
5383
5384 for (i = 0; i < entries; i++) {
5385 pid_match = wwn_match = 0;
5386
5387 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5388 pri_entry++;
5389 continue;
5390 }
5391
5392 /* check source pid for a match */
5393 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5394 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5395 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5396 if (pid1 == INVALID_PORT_ID)
5397 pid_match++;
5398 else if (pid1 == pid2)
5399 pid_match++;
5400 }
5401
5402 /* check destination pid for a match */
5403 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5404 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5405 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5406 if (pid1 == INVALID_PORT_ID)
5407 pid_match++;
5408 else if (pid1 == pid2)
5409 pid_match++;
5410 }
5411
5412 /* check source WWN for a match */
5413 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5414 wwn1 = wwn_to_u64(vha->port_name);
5415 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5416 if (wwn2 == (uint64_t)-1)
5417 wwn_match++;
5418 else if (wwn1 == wwn2)
5419 wwn_match++;
5420 }
5421
5422 /* check destination WWN for a match */
5423 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5424 wwn1 = wwn_to_u64(fcport->port_name);
5425 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5426 if (wwn2 == (uint64_t)-1)
5427 wwn_match++;
5428 else if (wwn1 == wwn2)
5429 wwn_match++;
5430 }
5431
5432 if (pid_match == 2 || wwn_match == 2) {
5433 /* Found a matching entry */
5434 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5435 priority = pri_entry->tag;
5436 break;
5437 }
5438
5439 pri_entry++;
5440 }
5441
5442 return priority;
5443}
5444
5445/*
5446 * qla24xx_update_fcport_fcp_prio
5447 * Activates fcp priority for the logged in fc port
5448 *
5449 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005450 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005451 * fcp = port structure pointer.
5452 *
5453 * Return:
5454 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5455 *
5456 * Context:
5457 * Kernel context.
5458 */
5459int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005460qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07005461{
5462 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005463 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005464 uint16_t mb[5];
5465
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005466 if (fcport->port_type != FCT_TARGET ||
5467 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07005468 return QLA_FUNCTION_FAILED;
5469
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005470 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005471 if (priority < 0)
5472 return QLA_FUNCTION_FAILED;
5473
Saurav Kashyapa00f6292011-11-18 09:03:19 -08005474 if (IS_QLA82XX(vha->hw)) {
5475 fcport->fcp_prio = priority & 0xf;
5476 return QLA_SUCCESS;
5477 }
5478
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005479 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08005480 if (ret == QLA_SUCCESS) {
5481 if (fcport->fcp_prio != priority)
5482 ql_dbg(ql_dbg_user, vha, 0x709e,
5483 "Updated FCP_CMND priority - value=%d loop_id=%d "
5484 "port_id=%02x%02x%02x.\n", priority,
5485 fcport->loop_id, fcport->d_id.b.domain,
5486 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08005487 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08005488 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005489 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08005490 "Unable to update FCP_CMND priority - ret=0x%x for "
5491 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
5492 fcport->d_id.b.domain, fcport->d_id.b.area,
5493 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07005494 return ret;
5495}
5496
5497/*
5498 * qla24xx_update_all_fcp_prio
5499 * Activates fcp priority for all the logged in ports
5500 *
5501 * Input:
5502 * ha = adapter block pointer.
5503 *
5504 * Return:
5505 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5506 *
5507 * Context:
5508 * Kernel context.
5509 */
5510int
5511qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5512{
5513 int ret;
5514 fc_port_t *fcport;
5515
5516 ret = QLA_FUNCTION_FAILED;
5517 /* We need to set priority for all logged in ports */
5518 list_for_each_entry(fcport, &vha->vp_fcports, list)
5519 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5520
5521 return ret;
5522}