blob: 214c0e9bdcdf2317ba457a8464530c81d56440a6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Chad Dupuis46152ce2012-08-22 14:21:08 -04003 * Copyright (c) 2003-2012 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
Saurav Kashyapa9b6f722012-08-22 14:21:01 -040080unsigned long
Andrew Vasquez5b914902010-05-28 15:08:30 -070081qla2x00_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
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400432int
433qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
434{
435 int rval = QLA_SUCCESS;
436 struct qla_hw_data *ha = vha->hw;
437 uint32_t idc_major_ver, idc_minor_ver;
Saurav Kashyap711aa7f2012-08-22 14:21:15 -0400438 uint16_t config[4];
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400439
440 qla83xx_idc_lock(vha, 0);
441
442 /* SV: TODO: Assign initialization timeout from
443 * flash-info / other param
444 */
445 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
446 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
447
448 /* Set our fcoe function presence */
449 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
450 ql_dbg(ql_dbg_p3p, vha, 0xb077,
451 "Error while setting DRV-Presence.\n");
452 rval = QLA_FUNCTION_FAILED;
453 goto exit;
454 }
455
456 /* Decide the reset ownership */
457 qla83xx_reset_ownership(vha);
458
459 /*
460 * On first protocol driver load:
461 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
462 * register.
463 * Others: Check compatibility with current IDC Major version.
464 */
465 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
466 if (ha->flags.nic_core_reset_owner) {
467 /* Set IDC Major version */
468 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
469 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
470
471 /* Clearing IDC-Lock-Recovery register */
472 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
473 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
474 /*
475 * Clear further IDC participation if we are not compatible with
476 * the current IDC Major Version.
477 */
478 ql_log(ql_log_warn, vha, 0xb07d,
479 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
480 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
481 __qla83xx_clear_drv_presence(vha);
482 rval = QLA_FUNCTION_FAILED;
483 goto exit;
484 }
485 /* Each function sets its supported Minor version. */
486 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
487 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
488 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
489
Saurav Kashyap711aa7f2012-08-22 14:21:15 -0400490 if (ha->flags.nic_core_reset_owner) {
491 memset(config, 0, sizeof(config));
492 if (!qla81xx_get_port_config(vha, config))
493 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
494 QLA8XXX_DEV_READY);
495 }
496
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400497 rval = qla83xx_idc_state_handler(vha);
498
499exit:
500 qla83xx_idc_unlock(vha, 0);
501
502 return rval;
503}
504
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505/*
506* qla2x00_initialize_adapter
507* Initialize board.
508*
509* Input:
510* ha = adapter block pointer.
511*
512* Returns:
513* 0 = success
514*/
515int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800516qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517{
518 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800519 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800520 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800523 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700524 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800525 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800526 ha->flags.pci_channel_io_perm_failure = 0;
527 ha->flags.eeh_busy = 0;
Andrew Vasquez794a5692010-12-21 16:00:21 -0800528 ha->flags.thermal_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800529 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
530 atomic_set(&vha->loop_state, LOOP_DOWN);
531 vha->device_flags = DFLG_NO_CABLE;
532 vha->dpc_flags = 0;
533 vha->flags.management_server_logged_in = 0;
534 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 ha->isp_abort_cnt = 0;
536 ha->beacon_blink_led = 0;
537
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800538 set_bit(0, ha->req_qid_map);
539 set_bit(0, ha->rsp_qid_map);
540
Chad Dupuiscfb09192011-11-18 09:03:07 -0800541 ql_dbg(ql_dbg_init, vha, 0x0040,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700542 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800543 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700545 ql_log(ql_log_warn, vha, 0x0044,
546 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 return (rval);
548 }
549
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800550 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800552 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700553 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700554 ql_log(ql_log_fatal, vha, 0x004f,
555 "Unable to validate FLASH data.\n");
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700556 return (rval);
557 }
558
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800559 ha->isp_ops->get_flash_version(vha, req->ring);
Chad Dupuiscfb09192011-11-18 09:03:07 -0800560 ql_dbg(ql_dbg_init, vha, 0x0061,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700561 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700562
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800563 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700565 if (ha->flags.disable_serdes) {
566 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700567 ql_log(ql_log_info, vha, 0x0077,
568 "Masking HBA WWPN "
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700569 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800570 vha->port_name[0], vha->port_name[1],
571 vha->port_name[2], vha->port_name[3],
572 vha->port_name[4], vha->port_name[5],
573 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700574 return QLA_FUNCTION_FAILED;
575 }
576
Chad Dupuiscfb09192011-11-18 09:03:07 -0800577 ql_dbg(ql_dbg_init, vha, 0x0078,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700578 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800580 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
581 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800582 if (rval)
583 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800584 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800585 if (rval)
586 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700588
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700589 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800590 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700591 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700592 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700593 "Unable to configure ISP84XX.\n");
594 return QLA_FUNCTION_FAILED;
595 }
596 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -0400597
598 if (qla_ini_mode_enabled(vha))
599 rval = qla2x00_init_rings(vha);
600
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700601 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800603 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700604 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800605 rval = qla84xx_init_chip(vha);
606 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700607 ql_log(ql_log_warn, vha, 0x00d4,
608 "Unable to initialize ISP84XX.\n");
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800609 qla84xx_put_chip(vha);
610 }
611 }
612
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400613 /* Load the NIC Core f/w if we are the first protocol driver. */
614 if (IS_QLA8031(ha)) {
615 rval = qla83xx_nic_core_fw_load(vha);
616 if (rval)
617 ql_log(ql_log_warn, vha, 0x0124,
618 "Error in initializing NIC Core f/w.\n");
619 }
620
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500621 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
622 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 return (rval);
625}
626
627/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700628 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 * @ha: HA context
630 *
631 * Returns 0 on success.
632 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700633int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800634qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700636 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700637 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800638 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700639 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700642 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700645 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
647
Andrew Vasquez737faec2008-10-24 15:13:45 -0700648 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700650 /* Get PCI bus information. */
651 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700652 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700653 spin_unlock_irqrestore(&ha->hardware_lock, flags);
654
655 return QLA_SUCCESS;
656}
657
658/**
659 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
660 * @ha: HA context
661 *
662 * Returns 0 on success.
663 */
664int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800665qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700666{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700667 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700668 unsigned long flags = 0;
669 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800670 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700671 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700672
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700673 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700674 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700675
676 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700677 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700678
679 if (IS_QLA2322(ha) || IS_QLA6322(ha))
680 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700681 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700682
683 /*
684 * If this is a 2300 card and not 2312, reset the
685 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
686 * the 2310 also reports itself as a 2300 so we need to get the
687 * fb revision level -- a 6 indicates it really is a 2300 and
688 * not a 2310.
689 */
690 if (IS_QLA2300(ha)) {
691 spin_lock_irqsave(&ha->hardware_lock, flags);
692
693 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700694 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700695 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700696 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700697 break;
698
699 udelay(10);
700 }
701
702 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700703 WRT_REG_WORD(&reg->ctrl_status, 0x20);
704 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700705
706 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700707 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700708
709 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700710 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700711
712 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700713 WRT_REG_WORD(&reg->ctrl_status, 0x0);
714 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700715
716 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700717 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700718 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700719 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700720 break;
721
722 udelay(10);
723 }
724
725 spin_unlock_irqrestore(&ha->hardware_lock, flags);
726 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700727
728 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
729
Andrew Vasquez737faec2008-10-24 15:13:45 -0700730 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700731
732 /* Get PCI bus information. */
733 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700734 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700735 spin_unlock_irqrestore(&ha->hardware_lock, flags);
736
737 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738}
739
740/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700741 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
742 * @ha: HA context
743 *
744 * Returns 0 on success.
745 */
746int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800747qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700748{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700749 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700750 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800751 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700752 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700753
754 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700755 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700756
757 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700758 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700759 w &= ~PCI_COMMAND_INTX_DISABLE;
760 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
761
762 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
763
764 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700765 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
766 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700767
768 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700769 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -0400770 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700771
Andrew Vasquez737faec2008-10-24 15:13:45 -0700772 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700773
Auke Kok44c10132007-06-08 15:46:36 -0700774 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800775
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700776 /* Get PCI bus information. */
777 spin_lock_irqsave(&ha->hardware_lock, flags);
778 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
779 spin_unlock_irqrestore(&ha->hardware_lock, flags);
780
781 return QLA_SUCCESS;
782}
783
784/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700785 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
786 * @ha: HA context
787 *
788 * Returns 0 on success.
789 */
790int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800791qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700792{
793 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800794 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700795
796 pci_set_master(ha->pdev);
797 pci_try_set_mwi(ha->pdev);
798
799 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
800 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
801 w &= ~PCI_COMMAND_INTX_DISABLE;
802 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
803
804 /* PCIe -- adjust Maximum Read Request Size (2048). */
Jon Masone67f1322012-07-10 14:57:56 -0700805 if (pci_is_pcie(ha->pdev))
Chad Dupuis5ffd3a52012-08-22 14:21:26 -0400806 pcie_set_readrq(ha->pdev, 4096);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700807
Andrew Vasquez737faec2008-10-24 15:13:45 -0700808 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700809
810 ha->chip_revision = ha->pdev->revision;
811
812 return QLA_SUCCESS;
813}
814
815/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 * qla2x00_isp_firmware() - Choose firmware image.
817 * @ha: HA context
818 *
819 * Returns 0 on success.
820 */
821static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800822qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
824 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700825 uint16_t loop_id, topo, sw_cap;
826 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800827 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
829 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700830 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
832 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700833 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
835 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800836 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700837 if (rval == QLA_SUCCESS) {
838 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800839 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700840 &area, &domain, &topo, &sw_cap);
841 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 }
843
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700844 if (rval)
845 ql_dbg(ql_dbg_init, vha, 0x007a,
846 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
848 return (rval);
849}
850
851/**
852 * qla2x00_reset_chip() - Reset ISP chip.
853 * @ha: HA context
854 *
855 * Returns 0 on success.
856 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700857void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800858qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
860 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800861 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700862 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 uint16_t cmd;
865
Andrew Vasquez85880802009-12-15 21:29:46 -0800866 if (unlikely(pci_channel_offline(ha->pdev)))
867 return;
868
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700869 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
871 spin_lock_irqsave(&ha->hardware_lock, flags);
872
873 /* Turn off master enable */
874 cmd = 0;
875 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
876 cmd &= ~PCI_COMMAND_MASTER;
877 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
878
879 if (!IS_QLA2100(ha)) {
880 /* Pause RISC. */
881 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
882 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
883 for (cnt = 0; cnt < 30000; cnt++) {
884 if ((RD_REG_WORD(&reg->hccr) &
885 HCCR_RISC_PAUSE) != 0)
886 break;
887 udelay(100);
888 }
889 } else {
890 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
891 udelay(10);
892 }
893
894 /* Select FPM registers. */
895 WRT_REG_WORD(&reg->ctrl_status, 0x20);
896 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
897
898 /* FPM Soft Reset. */
899 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
900 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
901
902 /* Toggle Fpm Reset. */
903 if (!IS_QLA2200(ha)) {
904 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
905 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
906 }
907
908 /* Select frame buffer registers. */
909 WRT_REG_WORD(&reg->ctrl_status, 0x10);
910 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
911
912 /* Reset frame buffer FIFOs. */
913 if (IS_QLA2200(ha)) {
914 WRT_FB_CMD_REG(ha, reg, 0xa000);
915 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
916 } else {
917 WRT_FB_CMD_REG(ha, reg, 0x00fc);
918
919 /* Read back fb_cmd until zero or 3 seconds max */
920 for (cnt = 0; cnt < 3000; cnt++) {
921 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
922 break;
923 udelay(100);
924 }
925 }
926
927 /* Select RISC module registers. */
928 WRT_REG_WORD(&reg->ctrl_status, 0);
929 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
930
931 /* Reset RISC processor. */
932 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
933 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
934
935 /* Release RISC processor. */
936 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
937 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
938 }
939
940 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
941 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
942
943 /* Reset ISP chip. */
944 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
945
946 /* Wait for RISC to recover from reset. */
947 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
948 /*
949 * It is necessary to for a delay here since the card doesn't
950 * respond to PCI reads during a reset. On some architectures
951 * this will result in an MCA.
952 */
953 udelay(20);
954 for (cnt = 30000; cnt; cnt--) {
955 if ((RD_REG_WORD(&reg->ctrl_status) &
956 CSR_ISP_SOFT_RESET) == 0)
957 break;
958 udelay(100);
959 }
960 } else
961 udelay(10);
962
963 /* Reset RISC processor. */
964 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
965
966 WRT_REG_WORD(&reg->semaphore, 0);
967
968 /* Release RISC processor. */
969 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
970 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
971
972 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
973 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700974 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 udelay(100);
978 }
979 } else
980 udelay(100);
981
982 /* Turn on master enable */
983 cmd |= PCI_COMMAND_MASTER;
984 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
985
986 /* Disable RISC pause on FPM parity error. */
987 if (!IS_QLA2100(ha)) {
988 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
989 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
990 }
991
992 spin_unlock_irqrestore(&ha->hardware_lock, flags);
993}
994
995/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700996 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
997 *
998 * Returns 0 on success.
999 */
1000int
1001qla81xx_reset_mpi(scsi_qla_host_t *vha)
1002{
1003 uint16_t mb[4] = {0x1010, 0, 1, 0};
1004
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001005 if (!IS_QLA81XX(vha->hw))
1006 return QLA_SUCCESS;
1007
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001008 return qla81xx_write_mpi_register(vha, mb);
1009}
1010
1011/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001012 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001013 * @ha: HA context
1014 *
1015 * Returns 0 on success.
1016 */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001017static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001018qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001019{
1020 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001021 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001022 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1023 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001024 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001025 static int abts_cnt; /* ISP abort retry counts */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001026
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001027 spin_lock_irqsave(&ha->hardware_lock, flags);
1028
1029 /* Reset RISC. */
1030 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1031 for (cnt = 0; cnt < 30000; cnt++) {
1032 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
1033 break;
1034
1035 udelay(10);
1036 }
1037
1038 WRT_REG_DWORD(&reg->ctrl_status,
1039 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001040 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001041
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001042 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001043 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001044 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1045 for (cnt = 10000 ; cnt && d2; cnt--) {
1046 udelay(5);
1047 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1048 barrier();
1049 }
1050
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001051 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001052 d2 = RD_REG_DWORD(&reg->ctrl_status);
1053 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1054 udelay(5);
1055 d2 = RD_REG_DWORD(&reg->ctrl_status);
1056 barrier();
1057 }
1058
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001059 /* If required, do an MPI FW reset now */
1060 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1061 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1062 if (++abts_cnt < 5) {
1063 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1064 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1065 } else {
1066 /*
1067 * We exhausted the ISP abort retries. We have to
1068 * set the board offline.
1069 */
1070 abts_cnt = 0;
1071 vha->flags.online = 0;
1072 }
1073 }
1074 }
1075
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001076 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1077 RD_REG_DWORD(&reg->hccr);
1078
1079 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1080 RD_REG_DWORD(&reg->hccr);
1081
1082 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1083 RD_REG_DWORD(&reg->hccr);
1084
1085 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1086 for (cnt = 6000000 ; cnt && d2; cnt--) {
1087 udelay(5);
1088 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1089 barrier();
1090 }
1091
1092 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001093
1094 if (IS_NOPOLLING_TYPE(ha))
1095 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001096}
1097
1098/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001099 * qla24xx_reset_chip() - Reset ISP24xx chip.
1100 * @ha: HA context
1101 *
1102 * Returns 0 on success.
1103 */
1104void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001105qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001106{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001107 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001108
1109 if (pci_channel_offline(ha->pdev) &&
1110 ha->flags.pci_channel_io_perm_failure) {
1111 return;
1112 }
1113
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001114 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001115
1116 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001117 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001118}
1119
1120/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 * qla2x00_chip_diag() - Test chip for proper operation.
1122 * @ha: HA context
1123 *
1124 * Returns 0 on success.
1125 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001126int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001127qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128{
1129 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001130 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001131 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 unsigned long flags = 0;
1133 uint16_t data;
1134 uint32_t cnt;
1135 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001136 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
1138 /* Assume a failed state */
1139 rval = QLA_FUNCTION_FAILED;
1140
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001141 ql_dbg(ql_dbg_init, vha, 0x007b,
1142 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
1144 spin_lock_irqsave(&ha->hardware_lock, flags);
1145
1146 /* Reset ISP chip. */
1147 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1148
1149 /*
1150 * We need to have a delay here since the card will not respond while
1151 * in reset causing an MCA on some architectures.
1152 */
1153 udelay(20);
1154 data = qla2x00_debounce_register(&reg->ctrl_status);
1155 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1156 udelay(5);
1157 data = RD_REG_WORD(&reg->ctrl_status);
1158 barrier();
1159 }
1160
1161 if (!cnt)
1162 goto chip_diag_failed;
1163
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001164 ql_dbg(ql_dbg_init, vha, 0x007c,
1165 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
1167 /* Reset RISC processor. */
1168 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1169 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1170
1171 /* Workaround for QLA2312 PCI parity error */
1172 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1173 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1174 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1175 udelay(5);
1176 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001177 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 }
1179 } else
1180 udelay(10);
1181
1182 if (!cnt)
1183 goto chip_diag_failed;
1184
1185 /* Check product ID of chip */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001186 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
1188 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1189 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1190 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1191 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1192 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1193 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001194 ql_log(ql_log_warn, vha, 0x0062,
1195 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1196 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
1198 goto chip_diag_failed;
1199 }
1200 ha->product_id[0] = mb[1];
1201 ha->product_id[1] = mb[2];
1202 ha->product_id[2] = mb[3];
1203 ha->product_id[3] = mb[4];
1204
1205 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001206 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1208 else
1209 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001210 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212 if (IS_QLA2200(ha) &&
1213 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1214 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001215 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001217 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 ha->fw_transfer_size = 128;
1219 }
1220
1221 /* Wrap Incoming Mailboxes Test. */
1222 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1223
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001224 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001225 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001226 if (rval)
1227 ql_log(ql_log_warn, vha, 0x0080,
1228 "Failed mailbox send register test.\n");
1229 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 /* Flag a successful rval */
1231 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 spin_lock_irqsave(&ha->hardware_lock, flags);
1233
1234chip_diag_failed:
1235 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001236 ql_log(ql_log_info, vha, 0x0081,
1237 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238
1239 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1240
1241 return (rval);
1242}
1243
1244/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001245 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1246 * @ha: HA context
1247 *
1248 * Returns 0 on success.
1249 */
1250int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001251qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001252{
1253 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001254 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001255 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001256
Giridhar Malavalia9083012010-04-12 17:59:55 -07001257 if (IS_QLA82XX(ha))
1258 return QLA_SUCCESS;
1259
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001260 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001261
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001262 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001263 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001264 ql_log(ql_log_warn, vha, 0x0082,
1265 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001266 } else {
1267 /* Flag a successful rval */
1268 rval = QLA_SUCCESS;
1269 }
1270
1271 return rval;
1272}
1273
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001274void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001275qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001276{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001277 int rval;
1278 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001279 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001280 dma_addr_t tc_dma;
1281 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001282 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001283 struct req_que *req = ha->req_q_map[0];
1284 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001285
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001286 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001287 ql_dbg(ql_dbg_init, vha, 0x00bd,
1288 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001289 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001290 }
1291
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001292 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001293 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001294 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1295 fixed_size = sizeof(struct qla2100_fw_dump);
1296 } else if (IS_QLA23XX(ha)) {
1297 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1298 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1299 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001300 } else if (IS_FWI2_CAPABLE(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001301 if (IS_QLA83XX(ha))
1302 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
1303 else if (IS_QLA81XX(ha))
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001304 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1305 else if (IS_QLA25XX(ha))
1306 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1307 else
1308 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001309 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1310 sizeof(uint32_t);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001311 if (ha->mqenable) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001312 if (!IS_QLA83XX(ha))
1313 mq_size = sizeof(struct qla2xxx_mq_chain);
Giridhar Malavali050c9bb2012-02-09 11:15:33 -08001314 /*
1315 * Allocate maximum buffer size for all queues.
1316 * Resizing must be done at end-of-dump processing.
1317 */
1318 mq_size += ha->max_req_queues *
1319 (req->length * sizeof(request_t));
1320 mq_size += ha->max_rsp_queues *
1321 (rsp->length * sizeof(response_t));
1322 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001323 if (ha->tgt.atio_q_length)
1324 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001325 /* Allocate memory for Fibre Channel Event Buffer. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001326 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001327 goto try_eft;
1328
1329 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1330 GFP_KERNEL);
1331 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001332 ql_log(ql_log_warn, vha, 0x00be,
1333 "Unable to allocate (%d KB) for FCE.\n",
1334 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001335 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001336 }
1337
1338 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001339 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001340 ha->fce_mb, &ha->fce_bufs);
1341 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001342 ql_log(ql_log_warn, vha, 0x00bf,
1343 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001344 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1345 tc_dma);
1346 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001347 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001348 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001349 ql_dbg(ql_dbg_init, vha, 0x00c0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001350 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001351
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001352 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001353 ha->flags.fce_enabled = 1;
1354 ha->fce_dma = tc_dma;
1355 ha->fce = tc;
1356try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001357 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001358 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001359 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001360 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001361 ql_log(ql_log_warn, vha, 0x00c1,
1362 "Unable to allocate (%d KB) for EFT.\n",
1363 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001364 goto cont_alloc;
1365 }
1366
Andrew Vasquezfc447652008-01-17 09:02:18 -08001367 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001368 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001369 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001370 ql_log(ql_log_warn, vha, 0x00c2,
1371 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001372 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1373 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001374 goto cont_alloc;
1375 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001376 ql_dbg(ql_dbg_init, vha, 0x00c3,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001377 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001378
1379 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001380 ha->eft_dma = tc_dma;
1381 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001382 }
1383cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001384 req_q_size = req->length * sizeof(request_t);
1385 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001386
1387 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001388 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001389 ha->chain_offset = dump_size;
1390 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001391
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001392 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001393 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001394 ql_log(ql_log_warn, vha, 0x00c4,
1395 "Unable to allocate (%d KB) for firmware dump.\n",
1396 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001397
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001398 if (ha->fce) {
1399 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1400 ha->fce_dma);
1401 ha->fce = NULL;
1402 ha->fce_dma = 0;
1403 }
1404
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001405 if (ha->eft) {
1406 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1407 ha->eft_dma);
1408 ha->eft = NULL;
1409 ha->eft_dma = 0;
1410 }
1411 return;
1412 }
Chad Dupuiscfb09192011-11-18 09:03:07 -08001413 ql_dbg(ql_dbg_init, vha, 0x00c5,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001414 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001415
1416 ha->fw_dump_len = dump_size;
1417 ha->fw_dump->signature[0] = 'Q';
1418 ha->fw_dump->signature[1] = 'L';
1419 ha->fw_dump->signature[2] = 'G';
1420 ha->fw_dump->signature[3] = 'C';
1421 ha->fw_dump->version = __constant_htonl(1);
1422
1423 ha->fw_dump->fixed_size = htonl(fixed_size);
1424 ha->fw_dump->mem_size = htonl(mem_size);
1425 ha->fw_dump->req_q_size = htonl(req_q_size);
1426 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1427
1428 ha->fw_dump->eft_size = htonl(eft_size);
1429 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1430 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1431
1432 ha->fw_dump->header_size =
1433 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001434}
1435
Andrew Vasquez18e75552009-06-03 09:55:30 -07001436static int
1437qla81xx_mpi_sync(scsi_qla_host_t *vha)
1438{
1439#define MPS_MASK 0xe0
1440 int rval;
1441 uint16_t dc;
1442 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07001443
1444 if (!IS_QLA81XX(vha->hw))
1445 return QLA_SUCCESS;
1446
1447 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1448 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001449 ql_log(ql_log_warn, vha, 0x0105,
1450 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001451 goto done;
1452 }
1453
1454 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1455 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1456 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001457 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001458 goto done_release;
1459 }
1460
1461 dc &= MPS_MASK;
1462 if (dc == (dw & MPS_MASK))
1463 goto done_release;
1464
1465 dw &= ~MPS_MASK;
1466 dw |= dc;
1467 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1468 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001469 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001470 }
1471
1472done_release:
1473 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1474 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001475 ql_log(ql_log_warn, vha, 0x006d,
1476 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001477 }
1478
1479done:
1480 return rval;
1481}
1482
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001483/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 * qla2x00_setup_chip() - Load and start RISC firmware.
1485 * @ha: HA context
1486 *
1487 * Returns 0 on success.
1488 */
1489static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001490qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001492 int rval;
1493 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001494 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001495 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1496 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001497 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001498
Giridhar Malavalia9083012010-04-12 17:59:55 -07001499 if (IS_QLA82XX(ha)) {
1500 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001501 if (rval == QLA_SUCCESS) {
1502 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001503 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001504 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001505 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001506 }
1507
Andrew Vasquez3db06522008-01-31 12:33:49 -08001508 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1509 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1510 spin_lock_irqsave(&ha->hardware_lock, flags);
1511 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1512 RD_REG_WORD(&reg->hccr);
1513 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1514 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
Andrew Vasquez18e75552009-06-03 09:55:30 -07001516 qla81xx_mpi_sync(vha);
1517
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001519 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001520 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001521 ql_dbg(ql_dbg_init, vha, 0x00c9,
1522 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001524 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 if (rval == QLA_SUCCESS) {
1526 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001527 ql_dbg(ql_dbg_init, vha, 0x00ca,
1528 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001530 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001532 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001533enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001534 fw_major_version = ha->fw_major_version;
Giridhar Malavali31731672011-08-16 11:31:54 -07001535 if (IS_QLA82XX(ha))
1536 qla82xx_check_md_needed(vha);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001537 else
1538 rval = qla2x00_get_fw_version(vha);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001539 if (rval != QLA_SUCCESS)
1540 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001541 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001542 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001543 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001544 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001545 if ((!ha->max_npiv_vports) ||
1546 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001547 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001548 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001549 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001550 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001551 qla2x00_get_resource_cnts(vha, NULL,
1552 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001553 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001554
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08001555 if (!fw_major_version && ql2xallocfwdump
1556 && !IS_QLA82XX(ha))
Giridhar Malavali08de2842011-08-16 11:31:44 -07001557 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 }
1559 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001560 ql_log(ql_log_fatal, vha, 0x00cd,
1561 "ISP Firmware failed checksum.\n");
1562 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 }
Andrew Vasquezc74d88a2012-08-22 14:21:19 -04001564 } else
1565 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Andrew Vasquez3db06522008-01-31 12:33:49 -08001567 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1568 /* Enable proper parity. */
1569 spin_lock_irqsave(&ha->hardware_lock, flags);
1570 if (IS_QLA2300(ha))
1571 /* SRAM parity */
1572 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1573 else
1574 /* SRAM, Instruction RAM and GP RAM parity */
1575 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1576 RD_REG_WORD(&reg->hccr);
1577 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1578 }
1579
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001580 if (IS_QLA83XX(ha))
1581 goto skip_fac_check;
1582
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001583 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1584 uint32_t size;
1585
1586 rval = qla81xx_fac_get_sector_size(vha, &size);
1587 if (rval == QLA_SUCCESS) {
1588 ha->flags.fac_supported = 1;
1589 ha->fdt_block_size = size << 2;
1590 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001591 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001592 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1593 ha->fw_major_version, ha->fw_minor_version,
1594 ha->fw_subminor_version);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001595skip_fac_check:
1596 if (IS_QLA83XX(ha)) {
1597 ha->flags.fac_supported = 0;
1598 rval = QLA_SUCCESS;
1599 }
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001600 }
1601 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001602failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001604 ql_log(ql_log_fatal, vha, 0x00cf,
1605 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 }
1607
1608 return (rval);
1609}
1610
1611/**
1612 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1613 * @ha: HA context
1614 *
1615 * Beginning of request ring has initialization control block already built
1616 * by nvram config routine.
1617 *
1618 * Returns 0 on success.
1619 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001620void
1621qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622{
1623 uint16_t cnt;
1624 response_t *pkt;
1625
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001626 rsp->ring_ptr = rsp->ring;
1627 rsp->ring_index = 0;
1628 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001629 pkt = rsp->ring_ptr;
1630 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 pkt->signature = RESPONSE_PROCESSED;
1632 pkt++;
1633 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634}
1635
1636/**
1637 * qla2x00_update_fw_options() - Read and process firmware options.
1638 * @ha: HA context
1639 *
1640 * Returns 0 on success.
1641 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001642void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001643qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644{
1645 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001646 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
1648 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001649 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
1651 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1652 return;
1653
1654 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001655 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1656 "Serial link options.\n");
1657 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1658 (uint8_t *)&ha->fw_seriallink_options,
1659 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
1661 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1662 if (ha->fw_seriallink_options[3] & BIT_2) {
1663 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1664
1665 /* 1G settings */
1666 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1667 emphasis = (ha->fw_seriallink_options[2] &
1668 (BIT_4 | BIT_3)) >> 3;
1669 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001670 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 rx_sens = (ha->fw_seriallink_options[0] &
1672 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1673 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1674 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1675 if (rx_sens == 0x0)
1676 rx_sens = 0x3;
1677 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1678 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1679 ha->fw_options[10] |= BIT_5 |
1680 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1681 (tx_sens & (BIT_1 | BIT_0));
1682
1683 /* 2G settings */
1684 swing = (ha->fw_seriallink_options[2] &
1685 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1686 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1687 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001688 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 rx_sens = (ha->fw_seriallink_options[1] &
1690 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1691 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1692 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1693 if (rx_sens == 0x0)
1694 rx_sens = 0x3;
1695 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1696 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1697 ha->fw_options[11] |= BIT_5 |
1698 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1699 (tx_sens & (BIT_1 | BIT_0));
1700 }
1701
1702 /* FCP2 options. */
1703 /* Return command IOCBs without waiting for an ABTS to complete. */
1704 ha->fw_options[3] |= BIT_13;
1705
1706 /* LED scheme. */
1707 if (ha->flags.enable_led_scheme)
1708 ha->fw_options[2] |= BIT_12;
1709
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001710 /* Detect ISP6312. */
1711 if (IS_QLA6312(ha))
1712 ha->fw_options[2] |= BIT_13;
1713
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001715 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716}
1717
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001718void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001719qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001720{
1721 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001722 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001723
Giridhar Malavalia9083012010-04-12 17:59:55 -07001724 if (IS_QLA82XX(ha))
1725 return;
1726
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001727 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001728 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001729 return;
1730
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001731 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001732 le16_to_cpu(ha->fw_seriallink_options24[1]),
1733 le16_to_cpu(ha->fw_seriallink_options24[2]),
1734 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001735 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001736 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001737 "Unable to update Serial Link options (%x).\n", rval);
1738 }
1739}
1740
1741void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001742qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001743{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001744 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001745 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001746 struct req_que *req = ha->req_q_map[0];
1747 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001748
1749 /* Setup ring parameters in initialization control block. */
1750 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1751 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001752 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1753 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1754 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1755 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1756 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1757 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001758
1759 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1760 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1761 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1762 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1763 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1764}
1765
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001766void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001767qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001768{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001769 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001770 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1771 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1772 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001773 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001774 uint16_t rid = 0;
1775 struct req_que *req = ha->req_q_map[0];
1776 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001777
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001778 /* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001779 icb = (struct init_cb_24xx *)ha->init_cb;
1780 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1781 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001782 icb->request_q_length = cpu_to_le16(req->length);
1783 icb->response_q_length = cpu_to_le16(rsp->length);
1784 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1785 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1786 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1787 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001788
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001789 /* Setup ATIO queue dma pointers for target mode */
1790 icb->atio_q_inpointer = __constant_cpu_to_le16(0);
1791 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
1792 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
1793 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
1794
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001795 if (ha->mqenable || IS_QLA83XX(ha)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001796 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1797 icb->rid = __constant_cpu_to_le16(rid);
1798 if (ha->flags.msix_enabled) {
1799 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001800 ql_dbg(ql_dbg_init, vha, 0x00fd,
1801 "Registering vector 0x%x for base que.\n",
1802 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001803 icb->msix = cpu_to_le16(msix->entry);
1804 }
1805 /* Use alternate PCI bus number */
1806 if (MSB(rid))
1807 icb->firmware_options_2 |=
1808 __constant_cpu_to_le32(BIT_19);
1809 /* Use alternate PCI devfn */
1810 if (LSB(rid))
1811 icb->firmware_options_2 |=
1812 __constant_cpu_to_le32(BIT_18);
1813
Anirban Chakraborty31557542009-12-02 10:36:55 -08001814 /* Use Disable MSIX Handshake mode for capable adapters */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001815 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
1816 (ha->flags.msix_enabled)) {
Anirban Chakraborty31557542009-12-02 10:36:55 -08001817 icb->firmware_options_2 &=
1818 __constant_cpu_to_le32(~BIT_22);
1819 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001820 ql_dbg(ql_dbg_init, vha, 0x00fe,
1821 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08001822 } else {
1823 icb->firmware_options_2 |=
1824 __constant_cpu_to_le32(BIT_22);
1825 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001826 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001827
1828 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1829 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1830 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1831 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1832 } else {
1833 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1834 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1835 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1836 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1837 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001838 qlt_24xx_config_rings(vha, reg);
1839
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001840 /* PCI posting */
1841 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001842}
1843
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844/**
1845 * qla2x00_init_rings() - Initializes firmware.
1846 * @ha: HA context
1847 *
1848 * Beginning of request ring has initialization control block already built
1849 * by nvram config routine.
1850 *
1851 * Returns 0 on success.
1852 */
1853static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001854qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855{
1856 int rval;
1857 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001858 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001859 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001860 struct req_que *req;
1861 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001862 struct mid_init_cb_24xx *mid_init_cb =
1863 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
1865 spin_lock_irqsave(&ha->hardware_lock, flags);
1866
1867 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001868 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001869 req = ha->req_q_map[que];
1870 if (!req)
1871 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001872 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001873 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001875 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001876
1877 /* Initialize firmware. */
1878 req->ring_ptr = req->ring;
1879 req->ring_index = 0;
1880 req->cnt = req->length;
1881 }
1882
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001883 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001884 rsp = ha->rsp_q_map[que];
1885 if (!rsp)
1886 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001887 /* Initialize response queue entries */
1888 qla2x00_init_response_q_entries(rsp);
1889 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890
Dan Carpenter542bce12010-10-15 11:27:38 -07001891 spin_lock(&ha->vport_slock);
Arun Easifeafb7b2010-09-03 14:57:00 -07001892
Dan Carpenter542bce12010-10-15 11:27:38 -07001893 spin_unlock(&ha->vport_slock);
Arun Easifeafb7b2010-09-03 14:57:00 -07001894
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001895 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
1896 ha->tgt.atio_ring_index = 0;
1897 /* Initialize ATIO queue entries */
1898 qlt_init_atio_q_entries(vha);
1899
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001900 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901
1902 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1903
1904 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001905 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001907 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001908
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001909 if (ha->flags.npiv_supported) {
Saurav Kashyap45980cc2012-08-22 14:21:21 -04001910 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001911 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001912 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001913 }
1914
Andrew Vasquez24a08132009-03-24 09:08:16 -07001915 if (IS_FWI2_CAPABLE(ha)) {
1916 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1917 mid_init_cb->init_cb.execution_throttle =
1918 cpu_to_le16(ha->fw_xcb_count);
1919 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001920
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001921 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001923 ql_log(ql_log_fatal, vha, 0x00d2,
1924 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001926 ql_dbg(ql_dbg_init, vha, 0x00d3,
1927 "Init Firmware -- success.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 }
1929
1930 return (rval);
1931}
1932
1933/**
1934 * qla2x00_fw_ready() - Waits for firmware ready.
1935 * @ha: HA context
1936 *
1937 * Returns 0 on success.
1938 */
1939static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001940qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941{
1942 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001943 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 uint16_t min_wait; /* Minimum wait time if loop is down */
1945 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001946 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001947 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
1949 rval = QLA_SUCCESS;
1950
1951 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001952 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953
1954 /*
1955 * Firmware should take at most one RATOV to login, plus 5 seconds for
1956 * our own processing.
1957 */
1958 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1959 wait_time = min_wait;
1960 }
1961
1962 /* Min wait time if loop down */
1963 mtime = jiffies + (min_wait * HZ);
1964
1965 /* wait time before firmware ready */
1966 wtime = jiffies + (wait_time * HZ);
1967
1968 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001969 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001970 ql_log(ql_log_info, vha, 0x801e,
1971 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
1973 do {
Andrew Vasquez5b939032012-11-21 02:40:26 -05001974 memset(state, -1, sizeof(state));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001975 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001977 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001978 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001980 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001981 ql_dbg(ql_dbg_taskm, vha, 0x801f,
1982 "fw_state=%x 84xx=%x.\n", state[0],
1983 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001984 if ((state[2] & FSTATE_LOGGED_IN) &&
1985 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001986 ql_dbg(ql_dbg_taskm, vha, 0x8028,
1987 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001988
1989 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001990 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001991 if (rval != QLA_SUCCESS) {
1992 ql_log(ql_log_warn,
Chad Dupuiscfb09192011-11-18 09:03:07 -08001993 vha, 0x8007,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001994 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001995 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001996 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001997
1998 /* Add time taken to initialize. */
1999 cs84xx_time = jiffies - cs84xx_time;
2000 wtime += cs84xx_time;
2001 mtime += cs84xx_time;
Chad Dupuiscfb09192011-11-18 09:03:07 -08002002 ql_dbg(ql_dbg_taskm, vha, 0x8008,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002003 "Increasing wait time by %ld. "
2004 "New time %ld.\n", cs84xx_time,
2005 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002006 }
2007 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002008 ql_dbg(ql_dbg_taskm, vha, 0x8037,
2009 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002011 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 &ha->login_timeout, &ha->r_a_tov);
2013
2014 rval = QLA_SUCCESS;
2015 break;
2016 }
2017
2018 rval = QLA_FUNCTION_FAILED;
2019
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002020 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002021 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002023 * other than Wait for Login.
2024 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002026 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 "Cable is unplugged...\n");
2028
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002029 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 break;
2031 }
2032 }
2033 } else {
2034 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07002035 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08002036 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 break;
2038 }
2039
2040 if (time_after_eq(jiffies, wtime))
2041 break;
2042
2043 /* Delay for a while */
2044 msleep(500);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 } while (1);
2046
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002047 ql_dbg(ql_dbg_taskm, vha, 0x803a,
2048 "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0],
2049 state[1], state[2], state[3], state[4], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
Chad Dupuiscfb09192011-11-18 09:03:07 -08002051 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002052 ql_log(ql_log_warn, vha, 0x803b,
2053 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 }
2055
2056 return (rval);
2057}
2058
2059/*
2060* qla2x00_configure_hba
2061* Setup adapter context.
2062*
2063* Input:
2064* ha = adapter state pointer.
2065*
2066* Returns:
2067* 0 = success
2068*
2069* Context:
2070* Kernel context.
2071*/
2072static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002073qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074{
2075 int rval;
2076 uint16_t loop_id;
2077 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002078 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 uint8_t al_pa;
2080 uint8_t area;
2081 uint8_t domain;
2082 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002083 struct qla_hw_data *ha = vha->hw;
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002084 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
2086 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002087 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002088 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002090 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002091 IS_CNA_CAPABLE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002092 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002093 ql_dbg(ql_dbg_disc, vha, 0x2008,
2094 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08002095 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002096 ql_log(ql_log_warn, vha, 0x2009,
2097 "Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002098 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002099 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 return (rval);
2101 }
2102
2103 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002104 ql_log(ql_log_info, vha, 0x200a,
2105 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 return (QLA_FUNCTION_FAILED);
2107 }
2108
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002109 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110
2111 /* initialize */
2112 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2113 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002114 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
2116 switch (topo) {
2117 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002118 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 ha->current_topology = ISP_CFG_NL;
2120 strcpy(connect_type, "(Loop)");
2121 break;
2122
2123 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002124 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002125 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 ha->current_topology = ISP_CFG_FL;
2127 strcpy(connect_type, "(FL_Port)");
2128 break;
2129
2130 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002131 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 ha->operating_mode = P2P;
2133 ha->current_topology = ISP_CFG_N;
2134 strcpy(connect_type, "(N_Port-to-N_Port)");
2135 break;
2136
2137 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002138 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002139 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 ha->operating_mode = P2P;
2141 ha->current_topology = ISP_CFG_F;
2142 strcpy(connect_type, "(F_Port)");
2143 break;
2144
2145 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002146 ql_dbg(ql_dbg_disc, vha, 0x200f,
2147 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 ha->current_topology = ISP_CFG_NL;
2149 strcpy(connect_type, "(Loop)");
2150 break;
2151 }
2152
2153 /* Save Host port and loop ID. */
2154 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002155 vha->d_id.b.domain = domain;
2156 vha->d_id.b.area = area;
2157 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002159 spin_lock_irqsave(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002160 qlt_update_vp_map(vha, SET_AL_PA);
Jiri Kosinaf24b5cb2012-10-08 09:23:54 +02002161 spin_unlock_irqrestore(&ha->vport_slock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002162
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002163 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002164 ql_log(ql_log_info, vha, 0x2010,
2165 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002166 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
2168 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002169 ql_log(ql_log_warn, vha, 0x2011,
2170 "%s FAILED\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002172 ql_dbg(ql_dbg_disc, vha, 0x2012,
2173 "%s success\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 }
2175
2176 return(rval);
2177}
2178
Giridhar Malavalia9083012010-04-12 17:59:55 -07002179inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002180qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2181 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002182{
2183 char *st, *en;
2184 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002185 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002186 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002187 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002188
2189 if (memcmp(model, BINZERO, len) != 0) {
2190 strncpy(ha->model_number, model, len);
2191 st = en = ha->model_number;
2192 en += len - 1;
2193 while (en > st) {
2194 if (*en != 0x20 && *en != 0x00)
2195 break;
2196 *en-- = '\0';
2197 }
2198
2199 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002200 if (use_tbl &&
2201 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002202 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002203 strncpy(ha->model_desc,
2204 qla2x00_model_name[index * 2 + 1],
2205 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002206 } else {
2207 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002208 if (use_tbl &&
2209 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002210 index < QLA_MODEL_NAMES) {
2211 strcpy(ha->model_number,
2212 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002213 strncpy(ha->model_desc,
2214 qla2x00_model_name[index * 2 + 1],
2215 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002216 } else {
2217 strcpy(ha->model_number, def);
2218 }
2219 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002220 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002221 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002222 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002223}
2224
David Miller4e08df32007-04-16 12:37:43 -07002225/* On sparc systems, obtain port and node WWN from firmware
2226 * properties.
2227 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002228static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002229{
2230#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002231 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002232 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002233 struct device_node *dp = pci_device_to_OF_node(pdev);
2234 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002235 int len;
2236
2237 val = of_get_property(dp, "port-wwn", &len);
2238 if (val && len >= WWN_SIZE)
2239 memcpy(nv->port_name, val, WWN_SIZE);
2240
2241 val = of_get_property(dp, "node-wwn", &len);
2242 if (val && len >= WWN_SIZE)
2243 memcpy(nv->node_name, val, WWN_SIZE);
2244#endif
2245}
2246
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247/*
2248* NVRAM configuration for ISP 2xxx
2249*
2250* Input:
2251* ha = adapter block pointer.
2252*
2253* Output:
2254* initialization control block in response_ring
2255* host adapters parameters in host adapter block
2256*
2257* Returns:
2258* 0 = success.
2259*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002260int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002261qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262{
David Miller4e08df32007-04-16 12:37:43 -07002263 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002264 uint8_t chksum = 0;
2265 uint16_t cnt;
2266 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002267 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002268 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002269 nvram_t *nv = ha->nvram;
2270 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002271 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272
David Miller4e08df32007-04-16 12:37:43 -07002273 rval = QLA_SUCCESS;
2274
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002276 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 ha->nvram_base = 0;
2278 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2279 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2280 ha->nvram_base = 0x80;
2281
2282 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002283 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002284 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2285 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002287 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2288 "Contents of NVRAM.\n");
2289 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2290 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
2292 /* Bad NVRAM data, set defaults parameters. */
2293 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2294 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2295 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002296 ql_log(ql_log_warn, vha, 0x0064,
Raul Porcel9e336522012-05-15 14:34:08 -04002297 "Inconsistent NVRAM "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002298 "detected: checksum=0x%x id=%c version=0x%x.\n",
2299 chksum, nv->id[0], nv->nvram_version);
2300 ql_log(ql_log_warn, vha, 0x0065,
2301 "Falling back to "
2302 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07002303
2304 /*
2305 * Set default initialization control block.
2306 */
2307 memset(nv, 0, ha->nvram_size);
2308 nv->parameter_block_version = ICB_VERSION;
2309
2310 if (IS_QLA23XX(ha)) {
2311 nv->firmware_options[0] = BIT_2 | BIT_1;
2312 nv->firmware_options[1] = BIT_7 | BIT_5;
2313 nv->add_firmware_options[0] = BIT_5;
2314 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2315 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2316 nv->special_options[1] = BIT_7;
2317 } else if (IS_QLA2200(ha)) {
2318 nv->firmware_options[0] = BIT_2 | BIT_1;
2319 nv->firmware_options[1] = BIT_7 | BIT_5;
2320 nv->add_firmware_options[0] = BIT_5;
2321 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2322 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2323 } else if (IS_QLA2100(ha)) {
2324 nv->firmware_options[0] = BIT_3 | BIT_1;
2325 nv->firmware_options[1] = BIT_5;
2326 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2327 }
2328
2329 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2330 nv->execution_throttle = __constant_cpu_to_le16(16);
2331 nv->retry_count = 8;
2332 nv->retry_delay = 1;
2333
2334 nv->port_name[0] = 33;
2335 nv->port_name[3] = 224;
2336 nv->port_name[4] = 139;
2337
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002338 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002339
2340 nv->login_timeout = 4;
2341
2342 /*
2343 * Set default host adapter parameters
2344 */
2345 nv->host_p[1] = BIT_2;
2346 nv->reset_delay = 5;
2347 nv->port_down_retry_count = 8;
2348 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2349 nv->link_down_timeout = 60;
2350
2351 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 }
2353
2354#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2355 /*
2356 * The SN2 does not provide BIOS emulation which means you can't change
2357 * potentially bogus BIOS settings. Force the use of default settings
2358 * for link rate and frame size. Hope that the rest of the settings
2359 * are valid.
2360 */
2361 if (ia64_platform_is("sn2")) {
2362 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2363 if (IS_QLA23XX(ha))
2364 nv->special_options[1] = BIT_7;
2365 }
2366#endif
2367
2368 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002369 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370
2371 /*
2372 * Setup driver NVRAM options.
2373 */
2374 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2375 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2376 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2377 nv->firmware_options[1] &= ~BIT_4;
2378
2379 if (IS_QLA23XX(ha)) {
2380 nv->firmware_options[0] |= BIT_2;
2381 nv->firmware_options[0] &= ~BIT_3;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002382 nv->special_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002383 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384
2385 if (IS_QLA2300(ha)) {
2386 if (ha->fb_rev == FPM_2310) {
2387 strcpy(ha->model_number, "QLA2310");
2388 } else {
2389 strcpy(ha->model_number, "QLA2300");
2390 }
2391 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002392 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002393 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 }
2395 } else if (IS_QLA2200(ha)) {
2396 nv->firmware_options[0] |= BIT_2;
2397 /*
2398 * 'Point-to-point preferred, else loop' is not a safe
2399 * connection mode setting.
2400 */
2401 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2402 (BIT_5 | BIT_4)) {
2403 /* Force 'loop preferred, else point-to-point'. */
2404 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2405 nv->add_firmware_options[0] |= BIT_5;
2406 }
2407 strcpy(ha->model_number, "QLA22xx");
2408 } else /*if (IS_QLA2100(ha))*/ {
2409 strcpy(ha->model_number, "QLA2100");
2410 }
2411
2412 /*
2413 * Copy over NVRAM RISC parameter block to initialization control block.
2414 */
2415 dptr1 = (uint8_t *)icb;
2416 dptr2 = (uint8_t *)&nv->parameter_block_version;
2417 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2418 while (cnt--)
2419 *dptr1++ = *dptr2++;
2420
2421 /* Copy 2nd half. */
2422 dptr1 = (uint8_t *)icb->add_firmware_options;
2423 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2424 while (cnt--)
2425 *dptr1++ = *dptr2++;
2426
Andrew Vasquez5341e862006-05-17 15:09:16 -07002427 /* Use alternate WWN? */
2428 if (nv->host_p[1] & BIT_7) {
2429 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2430 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2431 }
2432
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 /* Prepare nodename */
2434 if ((icb->firmware_options[1] & BIT_6) == 0) {
2435 /*
2436 * Firmware will apply the following mask if the nodename was
2437 * not provided.
2438 */
2439 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2440 icb->node_name[0] &= 0xF0;
2441 }
2442
2443 /*
2444 * Set host adapter parameters.
2445 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002446
2447 /*
2448 * BIT_7 in the host-parameters section allows for modification to
2449 * internal driver logging.
2450 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002451 if (nv->host_p[0] & BIT_7)
Chad Dupuiscfb09192011-11-18 09:03:07 -08002452 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2454 /* Always load RISC code on non ISP2[12]00 chips. */
2455 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2456 ha->flags.disable_risc_code_load = 0;
2457 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2458 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2459 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002460 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002461 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462
2463 ha->operating_mode =
2464 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2465
2466 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2467 sizeof(ha->fw_seriallink_options));
2468
2469 /* save HBA serial number */
2470 ha->serial0 = icb->port_name[5];
2471 ha->serial1 = icb->port_name[6];
2472 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002473 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2474 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
2476 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2477
2478 ha->retry_count = nv->retry_count;
2479
2480 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002481 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 nv->login_timeout = ql2xlogintimeout;
2483 if (nv->login_timeout < 4)
2484 nv->login_timeout = 4;
2485 ha->login_timeout = nv->login_timeout;
2486 icb->login_timeout = nv->login_timeout;
2487
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002488 /* Set minimum RATOV to 100 tenths of a second. */
2489 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 ha->loop_reset_delay = nv->reset_delay;
2492
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 /* Link Down Timeout = 0:
2494 *
2495 * When Port Down timer expires we will start returning
2496 * I/O's to OS with "DID_NO_CONNECT".
2497 *
2498 * Link Down Timeout != 0:
2499 *
2500 * The driver waits for the link to come up after link down
2501 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002502 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 if (nv->link_down_timeout == 0) {
2504 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002505 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 } else {
2507 ha->link_down_timeout = nv->link_down_timeout;
2508 ha->loop_down_abort_time =
2509 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002510 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 /*
2513 * Need enough time to try and get the port back.
2514 */
2515 ha->port_down_retry_count = nv->port_down_retry_count;
2516 if (qlport_down_retry)
2517 ha->port_down_retry_count = qlport_down_retry;
2518 /* Set login_retry_count */
2519 ha->login_retry_count = nv->retry_count;
2520 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2521 ha->port_down_retry_count > 3)
2522 ha->login_retry_count = ha->port_down_retry_count;
2523 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2524 ha->login_retry_count = ha->port_down_retry_count;
2525 if (ql2xloginretrycount)
2526 ha->login_retry_count = ql2xloginretrycount;
2527
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 icb->lun_enables = __constant_cpu_to_le16(0);
2529 icb->command_resource_count = 0;
2530 icb->immediate_notify_resource_count = 0;
2531 icb->timeout = __constant_cpu_to_le16(0);
2532
2533 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2534 /* Enable RIO */
2535 icb->firmware_options[0] &= ~BIT_3;
2536 icb->add_firmware_options[0] &=
2537 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2538 icb->add_firmware_options[0] |= BIT_2;
2539 icb->response_accumulation_timer = 3;
2540 icb->interrupt_delay_timer = 5;
2541
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002542 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002544 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002545 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002546 ha->zio_mode = icb->add_firmware_options[0] &
2547 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2548 ha->zio_timer = icb->interrupt_delay_timer ?
2549 icb->interrupt_delay_timer: 2;
2550 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 icb->add_firmware_options[0] &=
2552 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002553 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002554 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002555 ha->zio_mode = QLA_ZIO_MODE_6;
2556
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002557 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002558 "ZIO mode %d enabled; timer delay (%d us).\n",
2559 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002561 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2562 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002563 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 }
2565 }
2566
David Miller4e08df32007-04-16 12:37:43 -07002567 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002568 ql_log(ql_log_warn, vha, 0x0069,
2569 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07002570 }
2571 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572}
2573
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002574static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002575qla2x00_rport_del(void *data)
2576{
2577 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002578 struct fc_rport *rport;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002579 scsi_qla_host_t *vha = fcport->vha;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002580 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002581
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002582 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002583 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002584 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002585 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002586 if (rport) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002587 fc_remote_port_delete(rport);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002588 /*
2589 * Release the target mode FC NEXUS in qla_target.c code
2590 * if target mod is enabled.
2591 */
2592 qlt_fc_port_deleted(vha, fcport);
2593 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002594}
2595
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596/**
2597 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2598 * @ha: HA context
2599 * @flags: allocation flags
2600 *
2601 * Returns a pointer to the allocated fcport, or NULL, if none available.
2602 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002603fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002604qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605{
2606 fc_port_t *fcport;
2607
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002608 fcport = kzalloc(sizeof(fc_port_t), flags);
2609 if (!fcport)
2610 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611
2612 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002613 fcport->vha = vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 fcport->port_type = FCT_UNKNOWN;
2615 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07002616 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002617 fcport->supported_classes = FC_COS_UNSPECIFIED;
Joe Carnuccioc0822b62012-05-15 14:34:21 -04002618 fcport->scan_state = QLA_FCPORT_SCAN_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002620 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621}
2622
2623/*
2624 * qla2x00_configure_loop
2625 * Updates Fibre Channel Device Database with what is actually on loop.
2626 *
2627 * Input:
2628 * ha = adapter block pointer.
2629 *
2630 * Returns:
2631 * 0 = success.
2632 * 1 = error.
2633 * 2 = database was full and device was not configured.
2634 */
2635static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002636qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637{
2638 int rval;
2639 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002640 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 rval = QLA_SUCCESS;
2642
2643 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002644 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2645 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002647 ql_dbg(ql_dbg_disc, vha, 0x2013,
2648 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 return (rval);
2650 }
2651 }
2652
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002653 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002654 ql_dbg(ql_dbg_disc, vha, 0x2014,
2655 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656
2657 /*
2658 * If we have both an RSCN and PORT UPDATE pending then handle them
2659 * both at the same time.
2660 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002661 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2662 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
Michael Hernandez3064ff32009-12-15 21:29:44 -08002664 qla2x00_get_data_rate(vha);
2665
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 /* Determine what we need to do */
2667 if (ha->current_topology == ISP_CFG_FL &&
2668 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2669
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 set_bit(RSCN_UPDATE, &flags);
2671
2672 } else if (ha->current_topology == ISP_CFG_F &&
2673 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2674
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 set_bit(RSCN_UPDATE, &flags);
2676 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2677
Andrew Vasquez21333b42006-05-17 15:09:56 -07002678 } else if (ha->current_topology == ISP_CFG_N) {
2679 clear_bit(RSCN_UPDATE, &flags);
2680
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002681 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2683
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 set_bit(RSCN_UPDATE, &flags);
2685 set_bit(LOCAL_LOOP_UPDATE, &flags);
2686 }
2687
2688 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002689 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2690 ql_dbg(ql_dbg_disc, vha, 0x2015,
2691 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 rval = QLA_FUNCTION_FAILED;
Chad Dupuis642ef982012-02-09 11:15:57 -08002693 } else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002694 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 }
2696
2697 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002698 if (LOOP_TRANSITION(vha)) {
2699 ql_dbg(ql_dbg_disc, vha, 0x201e,
2700 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002702 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002703 else
2704 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 }
2706
2707 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002708 if (atomic_read(&vha->loop_down_timer) ||
2709 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 rval = QLA_FUNCTION_FAILED;
2711 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002712 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002713 ql_dbg(ql_dbg_disc, vha, 0x2069,
2714 "LOOP READY.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 }
2716 }
2717
2718 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002719 ql_dbg(ql_dbg_disc, vha, 0x206a,
2720 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002722 ql_dbg(ql_dbg_disc, vha, 0x206b,
2723 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 }
2725
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002726 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002727 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002729 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002730 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002731 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002732 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 }
2734
2735 return (rval);
2736}
2737
2738
2739
2740/*
2741 * qla2x00_configure_local_loop
2742 * Updates Fibre Channel Device Database with local loop devices.
2743 *
2744 * Input:
2745 * ha = adapter block pointer.
2746 *
2747 * Returns:
2748 * 0 = success.
2749 */
2750static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002751qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752{
2753 int rval, rval2;
2754 int found_devs;
2755 int found;
2756 fc_port_t *fcport, *new_fcport;
2757
2758 uint16_t index;
2759 uint16_t entries;
2760 char *id_iter;
2761 uint16_t loop_id;
2762 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002763 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764
2765 found_devs = 0;
2766 new_fcport = NULL;
Chad Dupuis642ef982012-02-09 11:15:57 -08002767 entries = MAX_FIBRE_DEVICES_LOOP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 /* Get list of logged in devices. */
Chad Dupuis642ef982012-02-09 11:15:57 -08002770 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002771 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 &entries);
2773 if (rval != QLA_SUCCESS)
2774 goto cleanup_allocation;
2775
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002776 ql_dbg(ql_dbg_disc, vha, 0x2017,
2777 "Entries in ID list (%d).\n", entries);
2778 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
2779 (uint8_t *)ha->gid_list,
2780 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781
2782 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002783 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002785 ql_log(ql_log_warn, vha, 0x2018,
2786 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 rval = QLA_MEMORY_ALLOC_FAILED;
2788 goto cleanup_allocation;
2789 }
2790 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2791
2792 /*
2793 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2794 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002795 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2797 fcport->port_type != FCT_BROADCAST &&
2798 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2799
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002800 ql_dbg(ql_dbg_disc, vha, 0x2019,
2801 "Marking port lost loop_id=0x%04x.\n",
2802 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803
Chad Dupuisec426e12011-03-30 11:46:32 -07002804 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 }
2806 }
2807
2808 /* Add devices to port list. */
2809 id_iter = (char *)ha->gid_list;
2810 for (index = 0; index < entries; index++) {
2811 domain = ((struct gid_list_info *)id_iter)->domain;
2812 area = ((struct gid_list_info *)id_iter)->area;
2813 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002814 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 loop_id = (uint16_t)
2816 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002817 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 loop_id = le16_to_cpu(
2819 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002820 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821
2822 /* Bypass reserved domain fields. */
2823 if ((domain & 0xf0) == 0xf0)
2824 continue;
2825
2826 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002827 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002828 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 continue;
2830
2831 /* Bypass invalid local loop ID. */
2832 if (loop_id > LAST_LOCAL_LOOP_ID)
2833 continue;
2834
Arun Easi370d5502012-08-22 14:21:10 -04002835 memset(new_fcport, 0, sizeof(fc_port_t));
2836
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 /* Fill in member data. */
2838 new_fcport->d_id.b.domain = domain;
2839 new_fcport->d_id.b.area = area;
2840 new_fcport->d_id.b.al_pa = al_pa;
2841 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002842 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002844 ql_dbg(ql_dbg_disc, vha, 0x201a,
2845 "Failed to retrieve fcport information "
2846 "-- get_port_database=%x, loop_id=0x%04x.\n",
2847 rval2, new_fcport->loop_id);
2848 ql_dbg(ql_dbg_disc, vha, 0x201b,
2849 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002850 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 continue;
2852 }
2853
2854 /* Check for matching device in port list. */
2855 found = 0;
2856 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002857 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 if (memcmp(new_fcport->port_name, fcport->port_name,
2859 WWN_SIZE))
2860 continue;
2861
Shyam Sundarddb9b122009-03-24 09:08:10 -07002862 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 fcport->loop_id = new_fcport->loop_id;
2864 fcport->port_type = new_fcport->port_type;
2865 fcport->d_id.b24 = new_fcport->d_id.b24;
2866 memcpy(fcport->node_name, new_fcport->node_name,
2867 WWN_SIZE);
2868
2869 found++;
2870 break;
2871 }
2872
2873 if (!found) {
2874 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002875 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876
2877 /* Allocate a new replacement fcport. */
2878 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002879 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002881 ql_log(ql_log_warn, vha, 0x201c,
2882 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 rval = QLA_MEMORY_ALLOC_FAILED;
2884 goto cleanup_allocation;
2885 }
2886 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2887 }
2888
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002889 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002890 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002891
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002892 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893
2894 found_devs++;
2895 }
2896
2897cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002898 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899
2900 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002901 ql_dbg(ql_dbg_disc, vha, 0x201d,
2902 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 }
2904
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 return (rval);
2906}
2907
2908static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002909qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002910{
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002911 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002912 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002913 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002914 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002915
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002916 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002917 return;
2918
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07002919 if (atomic_read(&fcport->state) != FCS_ONLINE)
2920 return;
2921
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002922 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2923 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002924 return;
2925
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002926 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002927 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002928 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002929 ql_dbg(ql_dbg_disc, vha, 0x2004,
2930 "Unable to adjust iIDMA "
2931 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x "
2932 "%04x.\n", fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002933 fcport->port_name[2], fcport->port_name[3],
2934 fcport->port_name[4], fcport->port_name[5],
2935 fcport->port_name[6], fcport->port_name[7], rval,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002936 fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002937 } else {
Chad Dupuisdaae62a2012-05-15 14:34:23 -04002938 link_speed = qla2x00_get_link_speed_str(ha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002939 ql_dbg(ql_dbg_disc, vha, 0x2005,
2940 "iIDMA adjusted to %s GB/s "
2941 "on %02x%02x%02x%02x%02x%02x%02x%02x.\n", link_speed,
2942 fcport->port_name[0], fcport->port_name[1],
2943 fcport->port_name[2], fcport->port_name[3],
2944 fcport->port_name[4], fcport->port_name[5],
2945 fcport->port_name[6], fcport->port_name[7]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002946 }
2947}
2948
Adrian Bunk23be3312006-11-24 02:46:01 +01002949static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002950qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002951{
2952 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002953 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002954 unsigned long flags;
8482e1182005-04-17 15:04:54 -05002955
Andrew Vasquezac280b62009-08-20 11:06:05 -07002956 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002957
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002958 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2959 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002960 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2961 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2962 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002963 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002964 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002965 ql_log(ql_log_warn, vha, 0x2006,
2966 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07002967 return;
2968 }
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002969 /*
2970 * Create target mode FC NEXUS in qla_target.c if target mode is
2971 * enabled..
2972 */
2973 qlt_fc_port_added(vha, fcport);
2974
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002975 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002976 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002977 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002978
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002979 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002980
2981 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002982 if (fcport->port_type == FCT_INITIATOR)
2983 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2984 if (fcport->port_type == FCT_TARGET)
2985 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002986 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002987}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988
2989/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002990 * qla2x00_update_fcport
2991 * Updates device on list.
2992 *
2993 * Input:
2994 * ha = adapter block pointer.
2995 * fcport = port structure pointer.
2996 *
2997 * Return:
2998 * 0 - Success
2999 * BIT_0 - error
3000 *
3001 * Context:
3002 * Kernel context.
3003 */
3004void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003005qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01003006{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003007 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01003008 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003009 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01003010
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003011 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08003012 qla24xx_update_fcport_fcp_prio(vha, fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003013 qla2x00_reg_remote_port(vha, fcport);
Chad Dupuisec426e12011-03-30 11:46:32 -07003014 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Adrian Bunk23be3312006-11-24 02:46:01 +01003015}
3016
3017/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 * qla2x00_configure_fabric
3019 * Setup SNS devices with loop ID's.
3020 *
3021 * Input:
3022 * ha = adapter block pointer.
3023 *
3024 * Returns:
3025 * 0 = success.
3026 * BIT_0 = error
3027 */
3028static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003029qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030{
Arun Easib3b02e62012-02-09 11:15:39 -08003031 int rval;
Joe Carnuccio4dc77c32012-05-15 14:34:24 -04003032 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 uint16_t next_loopid;
3034 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003035 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003037 struct qla_hw_data *ha = vha->hw;
3038 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039
3040 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003041 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003042 loop_id = NPH_F_PORT;
3043 else
3044 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003045 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003047 ql_dbg(ql_dbg_disc, vha, 0x201f,
3048 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003050 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 return (QLA_SUCCESS);
3052 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003053 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07003056 /* FDMI support. */
3057 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003058 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
3059 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07003060
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003062 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003063 loop_id = NPH_SNS;
3064 else
3065 loop_id = SIMPLE_NAME_SERVER;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003066 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
3067 0xfc, mb, BIT_1|BIT_0);
3068 if (rval != QLA_SUCCESS) {
3069 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Joe Carnuccio4dc77c32012-05-15 14:34:24 -04003070 break;
Chad Dupuis0b91d112012-02-09 11:15:42 -08003071 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003073 ql_dbg(ql_dbg_disc, vha, 0x2042,
3074 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3075 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
3076 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 return (QLA_SUCCESS);
3078 }
3079
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003080 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3081 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003083 ql_dbg(ql_dbg_disc, vha, 0x2045,
3084 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003086 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003088 ql_dbg(ql_dbg_disc, vha, 0x2049,
3089 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003091 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003093 ql_dbg(ql_dbg_disc, vha, 0x204f,
3094 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003095 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003097 ql_dbg(ql_dbg_disc, vha, 0x2053,
3098 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 }
3100 }
3101
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003102 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 if (rval != QLA_SUCCESS)
3104 break;
3105
Joe Carnuccio4dc77c32012-05-15 14:34:24 -04003106 /* Add new ports to existing port list */
3107 list_splice_tail_init(&new_fcports, &vha->vp_fcports);
3108
3109 /* Starting free loop ID. */
3110 next_loopid = ha->min_external_loopid;
3111
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003112 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3113 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 break;
3115
3116 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3117 continue;
3118
Joe Carnuccio4dc77c32012-05-15 14:34:24 -04003119 /* Logout lost/gone fabric devices (non-FCP2) */
Joe Carnuccioc0822b62012-05-15 14:34:21 -04003120 if (fcport->scan_state != QLA_FCPORT_SCAN_FOUND &&
Arun Easib3b02e62012-02-09 11:15:39 -08003121 atomic_read(&fcport->state) == FCS_ONLINE) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003122 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003123 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003125 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 fcport->port_type != FCT_INITIATOR &&
3127 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003128 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003129 fcport->loop_id,
3130 fcport->d_id.b.domain,
3131 fcport->d_id.b.area,
3132 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 }
Joe Carnuccioc0822b62012-05-15 14:34:21 -04003134 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 }
Joe Carnuccioc0822b62012-05-15 14:34:21 -04003136 fcport->scan_state = QLA_FCPORT_SCAN_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137
Joe Carnuccio4dc77c32012-05-15 14:34:24 -04003138 /* Login fabric devices that need a login */
3139 if ((fcport->flags & FCF_LOGIN_NEEDED) != 0 &&
3140 atomic_read(&vha->loop_down_timer) == 0) {
3141 if (fcport->loop_id == FC_NO_LOOP_ID) {
3142 fcport->loop_id = next_loopid;
3143 rval = qla2x00_find_new_loop_id(
3144 base_vha, fcport);
3145 if (rval != QLA_SUCCESS) {
3146 /* Ran out of IDs to use */
3147 continue;
3148 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 }
3150 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151
bdf79622005-04-17 15:06:53 -05003152 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003153 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 }
3155 } while (0);
3156
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003158 ql_dbg(ql_dbg_disc, vha, 0x2068,
3159 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 }
3161
3162 return (rval);
3163}
3164
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165/*
3166 * qla2x00_find_all_fabric_devs
3167 *
3168 * Input:
3169 * ha = adapter block pointer.
3170 * dev = database device entry pointer.
3171 *
3172 * Returns:
3173 * 0 = success.
3174 *
3175 * Context:
3176 * Kernel context.
3177 */
3178static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003179qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3180 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181{
3182 int rval;
3183 uint16_t loop_id;
3184 fc_port_t *fcport, *new_fcport, *fcptemp;
3185 int found;
3186
3187 sw_info_t *swl;
3188 int swl_idx;
3189 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003190 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003191 struct qla_hw_data *ha = vha->hw;
3192 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003193 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194
3195 rval = QLA_SUCCESS;
3196
3197 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez7a677352012-02-09 11:15:56 -08003198 if (!ha->swl)
Chad Dupuis642ef982012-02-09 11:15:57 -08003199 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
Andrew Vasquez7a677352012-02-09 11:15:56 -08003200 GFP_KERNEL);
3201 swl = ha->swl;
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003202 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003204 ql_dbg(ql_dbg_disc, vha, 0x2054,
3205 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 } else {
Chad Dupuis642ef982012-02-09 11:15:57 -08003207 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003208 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003210 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003212 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003214 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003215 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3216 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003218
3219 /* If other queries succeeded probe for FC-4 type */
3220 if (swl)
3221 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 }
3223 swl_idx = 0;
3224
3225 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003226 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003228 ql_log(ql_log_warn, vha, 0x205e,
3229 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 return (QLA_MEMORY_ALLOC_FAILED);
3231 }
3232 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 /* Set start port ID scan at adapter ID. */
3234 first_dev = 1;
3235 last_dev = 0;
3236
3237 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003238 loop_id = ha->min_external_loopid;
3239 for (; loop_id <= ha->max_loop_id; loop_id++) {
3240 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 continue;
3242
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003243 if (ha->current_topology == ISP_CFG_FL &&
3244 (atomic_read(&vha->loop_down_timer) ||
3245 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003246 atomic_set(&vha->loop_down_timer, 0);
3247 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3248 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251
3252 if (swl != NULL) {
3253 if (last_dev) {
3254 wrap.b24 = new_fcport->d_id.b24;
3255 } else {
3256 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3257 memcpy(new_fcport->node_name,
3258 swl[swl_idx].node_name, WWN_SIZE);
3259 memcpy(new_fcport->port_name,
3260 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003261 memcpy(new_fcport->fabric_port_name,
3262 swl[swl_idx].fabric_port_name, WWN_SIZE);
3263 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003264 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265
3266 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3267 last_dev = 1;
3268 }
3269 swl_idx++;
3270 }
3271 } else {
3272 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003273 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003275 ql_log(ql_log_warn, vha, 0x2064,
3276 "SNS scan failed -- assuming "
3277 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 list_for_each_entry_safe(fcport, fcptemp,
3279 new_fcports, list) {
3280 list_del(&fcport->list);
3281 kfree(fcport);
3282 }
3283 rval = QLA_SUCCESS;
3284 break;
3285 }
3286 }
3287
3288 /* If wrap on switch device list, exit. */
3289 if (first_dev) {
3290 wrap.b24 = new_fcport->d_id.b24;
3291 first_dev = 0;
3292 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003293 ql_dbg(ql_dbg_disc, vha, 0x2065,
3294 "Device wrap (%02x%02x%02x).\n",
3295 new_fcport->d_id.b.domain,
3296 new_fcport->d_id.b.area,
3297 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 break;
3299 }
3300
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003301 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003302 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 continue;
3304
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003305 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003306 found = 0;
3307 if (ha->num_vhosts) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003308 unsigned long flags;
3309
3310 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003311 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003312 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3313 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003314 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003315 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003316 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003317 spin_unlock_irqrestore(&ha->vport_slock, flags);
3318
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003319 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003320 continue;
3321 }
3322
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003323 /* Bypass if same domain and area of adapter. */
3324 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003325 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003326 ISP_CFG_FL)
3327 continue;
3328
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 /* Bypass reserved domain fields. */
3330 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3331 continue;
3332
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003333 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003334 if (ql2xgffidenable &&
3335 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3336 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003337 continue;
3338
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 /* Locate matching device in database. */
3340 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003341 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 if (memcmp(new_fcport->port_name, fcport->port_name,
3343 WWN_SIZE))
3344 continue;
3345
Joe Carnuccioc0822b62012-05-15 14:34:21 -04003346 fcport->scan_state = QLA_FCPORT_SCAN_FOUND;
Arun Easib3b02e62012-02-09 11:15:39 -08003347
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 found++;
3349
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003350 /* Update port state. */
3351 memcpy(fcport->fabric_port_name,
3352 new_fcport->fabric_port_name, WWN_SIZE);
3353 fcport->fp_speed = new_fcport->fp_speed;
3354
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 /*
3356 * If address the same and state FCS_ONLINE, nothing
3357 * changed.
3358 */
3359 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3360 atomic_read(&fcport->state) == FCS_ONLINE) {
3361 break;
3362 }
3363
3364 /*
3365 * If device was not a fabric device before.
3366 */
3367 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3368 fcport->d_id.b24 = new_fcport->d_id.b24;
Chad Dupuis5f16b332012-08-22 14:21:00 -04003369 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 fcport->flags |= (FCF_FABRIC_DEVICE |
3371 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 break;
3373 }
3374
3375 /*
3376 * Port ID changed or device was marked to be updated;
3377 * Log it out if still logged in and mark it for
3378 * relogin later.
3379 */
3380 fcport->d_id.b24 = new_fcport->d_id.b24;
3381 fcport->flags |= FCF_LOGIN_NEEDED;
3382 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003383 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Arun Easi0eba25d2012-02-09 11:15:58 -08003384 (fcport->flags & FCF_ASYNC_SENT) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385 fcport->port_type != FCT_INITIATOR &&
3386 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003387 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003388 fcport->d_id.b.domain, fcport->d_id.b.area,
3389 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003390 qla2x00_clear_loop_id(fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 }
3392
3393 break;
3394 }
3395
3396 if (found)
3397 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 /* If device was not in our fcports list, then add it. */
3399 list_add_tail(&new_fcport->list, new_fcports);
3400
3401 /* Allocate a new replacement fcport. */
3402 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003403 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003405 ql_log(ql_log_warn, vha, 0x2066,
3406 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 return (QLA_MEMORY_ALLOC_FAILED);
3408 }
3409 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3410 new_fcport->d_id.b24 = nxt_d_id.b24;
3411 }
3412
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003413 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 return (rval);
3416}
3417
3418/*
3419 * qla2x00_find_new_loop_id
3420 * Scan through our port list and find a new usable loop ID.
3421 *
3422 * Input:
3423 * ha: adapter state pointer.
3424 * dev: port structure pointer.
3425 *
3426 * Returns:
3427 * qla2x00 local function return status code.
3428 *
3429 * Context:
3430 * Kernel context.
3431 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003432int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003433qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434{
3435 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003436 struct qla_hw_data *ha = vha->hw;
Arun Easifeafb7b2010-09-03 14:57:00 -07003437 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438
3439 rval = QLA_SUCCESS;
3440
Chad Dupuis5f16b332012-08-22 14:21:00 -04003441 spin_lock_irqsave(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442
Chad Dupuis5f16b332012-08-22 14:21:00 -04003443 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
3444 LOOPID_MAP_SIZE);
3445 if (dev->loop_id >= LOOPID_MAP_SIZE ||
3446 qla2x00_is_reserved_id(vha, dev->loop_id)) {
3447 dev->loop_id = FC_NO_LOOP_ID;
3448 rval = QLA_FUNCTION_FAILED;
3449 } else
3450 set_bit(dev->loop_id, ha->loop_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451
Chad Dupuis5f16b332012-08-22 14:21:00 -04003452 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453
Chad Dupuis5f16b332012-08-22 14:21:00 -04003454 if (rval == QLA_SUCCESS)
3455 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
3456 "Assigning new loopid=%x, portid=%x.\n",
3457 dev->loop_id, dev->d_id.b24);
3458 else
3459 ql_log(ql_log_warn, dev->vha, 0x2087,
3460 "No loop_id's available, portid=%x.\n",
3461 dev->d_id.b24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462
3463 return (rval);
3464}
3465
3466/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 * qla2x00_fabric_dev_login
3468 * Login fabric target device and update FC port database.
3469 *
3470 * Input:
3471 * ha: adapter state pointer.
3472 * fcport: port structure list pointer.
3473 * next_loopid: contains value of a new loop ID that can be used
3474 * by the next login attempt.
3475 *
3476 * Returns:
3477 * qla2x00 local function return status code.
3478 *
3479 * Context:
3480 * Kernel context.
3481 */
3482static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003483qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 uint16_t *next_loopid)
3485{
3486 int rval;
3487 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003488 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003489 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490
3491 rval = QLA_SUCCESS;
3492 retry = 0;
3493
Andrew Vasquezac280b62009-08-20 11:06:05 -07003494 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003495 if (fcport->flags & FCF_ASYNC_SENT)
3496 return rval;
3497 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003498 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3499 if (!rval)
3500 return rval;
3501 }
3502
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003503 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003504 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003506 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003507 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003508 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003509 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003510 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003512 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003513 fcport->d_id.b.domain, fcport->d_id.b.area,
3514 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003515 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003517 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 }
Chad Dupuis0b91d112012-02-09 11:15:42 -08003519 } else {
3520 /* Retry Login. */
3521 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 }
3523
3524 return (rval);
3525}
3526
3527/*
3528 * qla2x00_fabric_login
3529 * Issue fabric login command.
3530 *
3531 * Input:
3532 * ha = adapter block pointer.
3533 * device = pointer to FC device type structure.
3534 *
3535 * Returns:
3536 * 0 - Login successfully
3537 * 1 - Login failed
3538 * 2 - Initiator device
3539 * 3 - Fatal error
3540 */
3541int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003542qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543 uint16_t *next_loopid)
3544{
3545 int rval;
3546 int retry;
3547 uint16_t tmp_loopid;
3548 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003549 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550
3551 retry = 0;
3552 tmp_loopid = 0;
3553
3554 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003555 ql_dbg(ql_dbg_disc, vha, 0x2000,
3556 "Trying Fabric Login w/loop id 0x%04x for port "
3557 "%02x%02x%02x.\n",
3558 fcport->loop_id, fcport->d_id.b.domain,
3559 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560
3561 /* Login fcport on switch. */
Chad Dupuis0b91d112012-02-09 11:15:42 -08003562 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563 fcport->d_id.b.domain, fcport->d_id.b.area,
3564 fcport->d_id.b.al_pa, mb, BIT_0);
Chad Dupuis0b91d112012-02-09 11:15:42 -08003565 if (rval != QLA_SUCCESS) {
3566 return rval;
3567 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568 if (mb[0] == MBS_PORT_ID_USED) {
3569 /*
3570 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003571 * recommends the driver perform an implicit login with
3572 * the specified ID again. The ID we just used is save
3573 * here so we return with an ID that can be tried by
3574 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 */
3576 retry++;
3577 tmp_loopid = fcport->loop_id;
3578 fcport->loop_id = mb[1];
3579
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003580 ql_dbg(ql_dbg_disc, vha, 0x2001,
3581 "Fabric Login: port in use - next loop "
3582 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003584 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585
3586 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3587 /*
3588 * Login succeeded.
3589 */
3590 if (retry) {
3591 /* A retry occurred before. */
3592 *next_loopid = tmp_loopid;
3593 } else {
3594 /*
3595 * No retry occurred before. Just increment the
3596 * ID value for next login.
3597 */
3598 *next_loopid = (fcport->loop_id + 1);
3599 }
3600
3601 if (mb[1] & BIT_0) {
3602 fcport->port_type = FCT_INITIATOR;
3603 } else {
3604 fcport->port_type = FCT_TARGET;
3605 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003606 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607 }
3608 }
3609
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003610 if (mb[10] & BIT_0)
3611 fcport->supported_classes |= FC_COS_CLASS2;
3612 if (mb[10] & BIT_1)
3613 fcport->supported_classes |= FC_COS_CLASS3;
3614
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003615 if (IS_FWI2_CAPABLE(ha)) {
3616 if (mb[10] & BIT_7)
3617 fcport->flags |=
3618 FCF_CONF_COMP_SUPPORTED;
3619 }
3620
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 rval = QLA_SUCCESS;
3622 break;
3623 } else if (mb[0] == MBS_LOOP_ID_USED) {
3624 /*
3625 * Loop ID already used, try next loop ID.
3626 */
3627 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003628 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 if (rval != QLA_SUCCESS) {
3630 /* Ran out of loop IDs to use */
3631 break;
3632 }
3633 } else if (mb[0] == MBS_COMMAND_ERROR) {
3634 /*
3635 * Firmware possibly timed out during login. If NO
3636 * retries are left to do then the device is declared
3637 * dead.
3638 */
3639 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003640 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003641 fcport->d_id.b.domain, fcport->d_id.b.area,
3642 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003643 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644
3645 rval = 1;
3646 break;
3647 } else {
3648 /*
3649 * unrecoverable / not handled error
3650 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003651 ql_dbg(ql_dbg_disc, vha, 0x2002,
3652 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
3653 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
3654 fcport->d_id.b.area, fcport->d_id.b.al_pa,
3655 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656
3657 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003658 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003659 fcport->d_id.b.domain, fcport->d_id.b.area,
3660 fcport->d_id.b.al_pa);
Chad Dupuis5f16b332012-08-22 14:21:00 -04003661 qla2x00_clear_loop_id(fcport);
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003662 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663
3664 rval = 3;
3665 break;
3666 }
3667 }
3668
3669 return (rval);
3670}
3671
3672/*
3673 * qla2x00_local_device_login
3674 * Issue local device login command.
3675 *
3676 * Input:
3677 * ha = adapter block pointer.
3678 * loop_id = loop id of device to login to.
3679 *
3680 * Returns (Where's the #define!!!!):
3681 * 0 - Login successfully
3682 * 1 - Login failed
3683 * 3 - Fatal error
3684 */
3685int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003686qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687{
3688 int rval;
3689 uint16_t mb[MAILBOX_REGISTER_COUNT];
3690
3691 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003692 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 if (rval == QLA_SUCCESS) {
3694 /* Interrogate mailbox registers for any errors */
3695 if (mb[0] == MBS_COMMAND_ERROR)
3696 rval = 1;
3697 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3698 /* device not in PCB table */
3699 rval = 3;
3700 }
3701
3702 return (rval);
3703}
3704
3705/*
3706 * qla2x00_loop_resync
3707 * Resync with fibre channel devices.
3708 *
3709 * Input:
3710 * ha = adapter block pointer.
3711 *
3712 * Returns:
3713 * 0 = success
3714 */
3715int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003716qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003718 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003720 struct req_que *req;
3721 struct rsp_que *rsp;
3722
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003723 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003724 req = vha->hw->req_q_map[0];
3725 else
3726 req = vha->req;
3727 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003729 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3730 if (vha->flags.online) {
3731 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3733 wait_time = 256;
3734 do {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003735 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003736 qla2x00_marker(vha, req, rsp, 0, 0,
3737 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003738 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739
3740 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003741 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003743 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003745 } while (!atomic_read(&vha->loop_down_timer) &&
3746 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3747 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3748 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750 }
3751
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003752 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003755 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003756 ql_dbg(ql_dbg_disc, vha, 0x206c,
3757 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758
3759 return (rval);
3760}
3761
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003762/*
3763* qla2x00_perform_loop_resync
3764* Description: This function will set the appropriate flags and call
3765* qla2x00_loop_resync. If successful loop will be resynced
3766* Arguments : scsi_qla_host_t pointer
3767* returm : Success or Failure
3768*/
3769
3770int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
3771{
3772 int32_t rval = 0;
3773
3774 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
3775 /*Configure the flags so that resync happens properly*/
3776 atomic_set(&ha->loop_down_timer, 0);
3777 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3778 atomic_set(&ha->loop_state, LOOP_UP);
3779 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
3780 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
3781 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3782
3783 rval = qla2x00_loop_resync(ha);
3784 } else
3785 atomic_set(&ha->loop_state, LOOP_DEAD);
3786
3787 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3788 }
3789
3790 return rval;
3791}
3792
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003794qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003795{
3796 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07003797 struct scsi_qla_host *vha;
3798 struct qla_hw_data *ha = base_vha->hw;
3799 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003800
Arun Easifeafb7b2010-09-03 14:57:00 -07003801 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003802 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07003803 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
3804 atomic_inc(&vha->vref_count);
3805 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08003806 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07003807 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
3808 spin_unlock_irqrestore(&ha->vport_slock, flags);
3809
Andrew Vasquez67becc02009-08-25 11:36:20 -07003810 qla2x00_rport_del(fcport);
Arun Easifeafb7b2010-09-03 14:57:00 -07003811
3812 spin_lock_irqsave(&ha->vport_slock, flags);
3813 }
3814 }
3815 atomic_dec(&vha->vref_count);
3816 }
3817 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003818}
3819
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04003820/* Assumes idc_lock always held on entry */
3821void
3822qla83xx_reset_ownership(scsi_qla_host_t *vha)
3823{
3824 struct qla_hw_data *ha = vha->hw;
3825 uint32_t drv_presence, drv_presence_mask;
3826 uint32_t dev_part_info1, dev_part_info2, class_type;
3827 uint32_t class_type_mask = 0x3;
3828 uint16_t fcoe_other_function = 0xffff, i;
3829
3830 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
3831
3832 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
3833 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
3834 for (i = 0; i < 8; i++) {
3835 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
3836 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
3837 (i != ha->portnum)) {
3838 fcoe_other_function = i;
3839 break;
3840 }
3841 }
3842 if (fcoe_other_function == 0xffff) {
3843 for (i = 0; i < 8; i++) {
3844 class_type = ((dev_part_info2 >> (i * 4)) &
3845 class_type_mask);
3846 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
3847 ((i + 8) != ha->portnum)) {
3848 fcoe_other_function = i + 8;
3849 break;
3850 }
3851 }
3852 }
3853 /*
3854 * Prepare drv-presence mask based on fcoe functions present.
3855 * However consider only valid physical fcoe function numbers (0-15).
3856 */
3857 drv_presence_mask = ~((1 << (ha->portnum)) |
3858 ((fcoe_other_function == 0xffff) ?
3859 0 : (1 << (fcoe_other_function))));
3860
3861 /* We are the reset owner iff:
3862 * - No other protocol drivers present.
3863 * - This is the lowest among fcoe functions. */
3864 if (!(drv_presence & drv_presence_mask) &&
3865 (ha->portnum < fcoe_other_function)) {
3866 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
3867 "This host is Reset owner.\n");
3868 ha->flags.nic_core_reset_owner = 1;
3869 }
3870}
3871
3872int
3873__qla83xx_set_drv_ack(scsi_qla_host_t *vha)
3874{
3875 int rval = QLA_SUCCESS;
3876 struct qla_hw_data *ha = vha->hw;
3877 uint32_t drv_ack;
3878
3879 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
3880 if (rval == QLA_SUCCESS) {
3881 drv_ack |= (1 << ha->portnum);
3882 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
3883 }
3884
3885 return rval;
3886}
3887
3888int
3889qla83xx_set_drv_ack(scsi_qla_host_t *vha)
3890{
3891 int rval = QLA_SUCCESS;
3892
3893 qla83xx_idc_lock(vha, 0);
3894 rval = __qla83xx_set_drv_ack(vha);
3895 qla83xx_idc_unlock(vha, 0);
3896
3897 return rval;
3898}
3899
3900int
3901__qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
3902{
3903 int rval = QLA_SUCCESS;
3904 struct qla_hw_data *ha = vha->hw;
3905 uint32_t drv_ack;
3906
3907 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
3908 if (rval == QLA_SUCCESS) {
3909 drv_ack &= ~(1 << ha->portnum);
3910 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
3911 }
3912
3913 return rval;
3914}
3915
3916int
3917qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
3918{
3919 int rval = QLA_SUCCESS;
3920
3921 qla83xx_idc_lock(vha, 0);
3922 rval = __qla83xx_clear_drv_ack(vha);
3923 qla83xx_idc_unlock(vha, 0);
3924
3925 return rval;
3926}
3927
3928const char *
3929qla83xx_dev_state_to_string(uint32_t dev_state)
3930{
3931 switch (dev_state) {
3932 case QLA8XXX_DEV_COLD:
3933 return "COLD/RE-INIT";
3934 case QLA8XXX_DEV_INITIALIZING:
3935 return "INITIALIZING";
3936 case QLA8XXX_DEV_READY:
3937 return "READY";
3938 case QLA8XXX_DEV_NEED_RESET:
3939 return "NEED RESET";
3940 case QLA8XXX_DEV_NEED_QUIESCENT:
3941 return "NEED QUIESCENT";
3942 case QLA8XXX_DEV_FAILED:
3943 return "FAILED";
3944 case QLA8XXX_DEV_QUIESCENT:
3945 return "QUIESCENT";
3946 default:
3947 return "Unknown";
3948 }
3949}
3950
3951/* Assumes idc-lock always held on entry */
3952void
3953qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
3954{
3955 struct qla_hw_data *ha = vha->hw;
3956 uint32_t idc_audit_reg = 0, duration_secs = 0;
3957
3958 switch (audit_type) {
3959 case IDC_AUDIT_TIMESTAMP:
3960 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
3961 idc_audit_reg = (ha->portnum) |
3962 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
3963 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
3964 break;
3965
3966 case IDC_AUDIT_COMPLETION:
3967 duration_secs = ((jiffies_to_msecs(jiffies) -
3968 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
3969 idc_audit_reg = (ha->portnum) |
3970 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
3971 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
3972 break;
3973
3974 default:
3975 ql_log(ql_log_warn, vha, 0xb078,
3976 "Invalid audit type specified.\n");
3977 break;
3978 }
3979}
3980
3981/* Assumes idc_lock always held on entry */
3982int
3983qla83xx_initiating_reset(scsi_qla_host_t *vha)
3984{
3985 struct qla_hw_data *ha = vha->hw;
3986 uint32_t idc_control, dev_state;
3987
3988 __qla83xx_get_idc_control(vha, &idc_control);
3989 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
3990 ql_log(ql_log_info, vha, 0xb080,
3991 "NIC Core reset has been disabled. idc-control=0x%x\n",
3992 idc_control);
3993 return QLA_FUNCTION_FAILED;
3994 }
3995
3996 /* Set NEED-RESET iff in READY state and we are the reset-owner */
3997 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
3998 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
3999 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
4000 QLA8XXX_DEV_NEED_RESET);
4001 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
4002 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
4003 } else {
4004 const char *state = qla83xx_dev_state_to_string(dev_state);
4005 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
4006
4007 /* SV: XXX: Is timeout required here? */
4008 /* Wait for IDC state change READY -> NEED_RESET */
4009 while (dev_state == QLA8XXX_DEV_READY) {
4010 qla83xx_idc_unlock(vha, 0);
4011 msleep(200);
4012 qla83xx_idc_lock(vha, 0);
4013 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
4014 }
4015 }
4016
4017 /* Send IDC ack by writing to drv-ack register */
4018 __qla83xx_set_drv_ack(vha);
4019
4020 return QLA_SUCCESS;
4021}
4022
4023int
4024__qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
4025{
4026 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4027}
4028
4029int
4030qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
4031{
4032 int rval = QLA_SUCCESS;
4033
4034 qla83xx_idc_lock(vha, 0);
4035 rval = __qla83xx_set_idc_control(vha, idc_control);
4036 qla83xx_idc_unlock(vha, 0);
4037
4038 return rval;
4039}
4040
4041int
4042__qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
4043{
4044 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
4045}
4046
4047int
4048qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
4049{
4050 int rval = QLA_SUCCESS;
4051
4052 qla83xx_idc_lock(vha, 0);
4053 rval = __qla83xx_get_idc_control(vha, idc_control);
4054 qla83xx_idc_unlock(vha, 0);
4055
4056 return rval;
4057}
4058
4059int
4060qla83xx_check_driver_presence(scsi_qla_host_t *vha)
4061{
4062 uint32_t drv_presence = 0;
4063 struct qla_hw_data *ha = vha->hw;
4064
4065 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
4066 if (drv_presence & (1 << ha->portnum))
4067 return QLA_SUCCESS;
4068 else
4069 return QLA_TEST_FAILED;
4070}
4071
4072int
4073qla83xx_nic_core_reset(scsi_qla_host_t *vha)
4074{
4075 int rval = QLA_SUCCESS;
4076 struct qla_hw_data *ha = vha->hw;
4077
4078 ql_dbg(ql_dbg_p3p, vha, 0xb058,
4079 "Entered %s().\n", __func__);
4080
4081 if (vha->device_flags & DFLG_DEV_FAILED) {
4082 ql_log(ql_log_warn, vha, 0xb059,
4083 "Device in unrecoverable FAILED state.\n");
4084 return QLA_FUNCTION_FAILED;
4085 }
4086
4087 qla83xx_idc_lock(vha, 0);
4088
4089 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
4090 ql_log(ql_log_warn, vha, 0xb05a,
4091 "Function=0x%x has been removed from IDC participation.\n",
4092 ha->portnum);
4093 rval = QLA_FUNCTION_FAILED;
4094 goto exit;
4095 }
4096
4097 qla83xx_reset_ownership(vha);
4098
4099 rval = qla83xx_initiating_reset(vha);
4100
4101 /*
4102 * Perform reset if we are the reset-owner,
4103 * else wait till IDC state changes to READY/FAILED.
4104 */
4105 if (rval == QLA_SUCCESS) {
4106 rval = qla83xx_idc_state_handler(vha);
4107
4108 if (rval == QLA_SUCCESS)
4109 ha->flags.nic_core_hung = 0;
4110 __qla83xx_clear_drv_ack(vha);
4111 }
4112
4113exit:
4114 qla83xx_idc_unlock(vha, 0);
4115
4116 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
4117
4118 return rval;
4119}
4120
Saurav Kashyap81178772012-08-22 14:21:04 -04004121int
4122qla2xxx_mctp_dump(scsi_qla_host_t *vha)
4123{
4124 struct qla_hw_data *ha = vha->hw;
4125 int rval = QLA_FUNCTION_FAILED;
4126
4127 if (!IS_MCTP_CAPABLE(ha)) {
4128 /* This message can be removed from the final version */
4129 ql_log(ql_log_info, vha, 0x506d,
4130 "This board is not MCTP capable\n");
4131 return rval;
4132 }
4133
4134 if (!ha->mctp_dump) {
4135 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
4136 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
4137
4138 if (!ha->mctp_dump) {
4139 ql_log(ql_log_warn, vha, 0x506e,
4140 "Failed to allocate memory for mctp dump\n");
4141 return rval;
4142 }
4143 }
4144
4145#define MCTP_DUMP_STR_ADDR 0x00000000
4146 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
4147 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
4148 if (rval != QLA_SUCCESS) {
4149 ql_log(ql_log_warn, vha, 0x506f,
4150 "Failed to capture mctp dump\n");
4151 } else {
4152 ql_log(ql_log_info, vha, 0x5070,
4153 "Mctp dump capture for host (%ld/%p).\n",
4154 vha->host_no, ha->mctp_dump);
4155 ha->mctp_dumped = 1;
4156 }
4157
Saurav Kashyap409ee0f2012-08-22 14:21:29 -04004158 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
Saurav Kashyap81178772012-08-22 14:21:04 -04004159 ha->flags.nic_core_reset_hdlr_active = 1;
4160 rval = qla83xx_restart_nic_firmware(vha);
4161 if (rval)
4162 /* NIC Core reset failed. */
4163 ql_log(ql_log_warn, vha, 0x5071,
4164 "Failed to restart nic firmware\n");
4165 else
4166 ql_dbg(ql_dbg_p3p, vha, 0xb084,
4167 "Restarted NIC firmware successfully.\n");
4168 ha->flags.nic_core_reset_hdlr_active = 0;
4169 }
4170
4171 return rval;
4172
4173}
4174
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004175/*
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004176* qla2x00_quiesce_io
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004177* Description: This function will block the new I/Os
4178* Its not aborting any I/Os as context
4179* is not destroyed during quiescence
4180* Arguments: scsi_qla_host_t
4181* return : void
4182*/
4183void
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004184qla2x00_quiesce_io(scsi_qla_host_t *vha)
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004185{
4186 struct qla_hw_data *ha = vha->hw;
4187 struct scsi_qla_host *vp;
4188
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004189 ql_dbg(ql_dbg_dpc, vha, 0x401d,
4190 "Quiescing I/O - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004191
4192 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
4193 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4194 atomic_set(&vha->loop_state, LOOP_DOWN);
4195 qla2x00_mark_all_devices_lost(vha, 0);
4196 list_for_each_entry(vp, &ha->vp_list, list)
Chad Dupuis8fcd6b82012-08-22 14:21:06 -04004197 qla2x00_mark_all_devices_lost(vp, 0);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004198 } else {
4199 if (!atomic_read(&vha->loop_down_timer))
4200 atomic_set(&vha->loop_down_timer,
4201 LOOP_DOWN_TIME);
4202 }
4203 /* Wait for pending cmds to complete */
4204 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
4205}
4206
Giridhar Malavalia9083012010-04-12 17:59:55 -07004207void
4208qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
4209{
4210 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004211 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07004212 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004213 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004214
Saurav Kashyape46ef002011-02-23 15:27:16 -08004215 /* For ISP82XX, driver waits for completion of the commands.
4216 * online flag should be set.
4217 */
4218 if (!IS_QLA82XX(ha))
4219 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004220 ha->flags.chip_reset_done = 0;
4221 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Saurav Kashyap2be21fa2012-05-15 14:34:16 -04004222 vha->qla_stats.total_isp_aborts++;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004223
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004224 ql_log(ql_log_info, vha, 0x00af,
4225 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004226
Saurav Kashyape46ef002011-02-23 15:27:16 -08004227 /* For ISP82XX, reset_chip is just disabling interrupts.
4228 * Driver waits for the completion of the commands.
4229 * the interrupts need to be enabled.
4230 */
Giridhar Malavalia9083012010-04-12 17:59:55 -07004231 if (!IS_QLA82XX(ha))
4232 ha->isp_ops->reset_chip(vha);
4233
4234 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
4235 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
4236 atomic_set(&vha->loop_state, LOOP_DOWN);
4237 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004238
4239 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004240 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07004241 atomic_inc(&vp->vref_count);
4242 spin_unlock_irqrestore(&ha->vport_slock, flags);
4243
Giridhar Malavalia9083012010-04-12 17:59:55 -07004244 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004245
4246 spin_lock_irqsave(&ha->vport_slock, flags);
4247 atomic_dec(&vp->vref_count);
4248 }
4249 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004250 } else {
4251 if (!atomic_read(&vha->loop_down_timer))
4252 atomic_set(&vha->loop_down_timer,
4253 LOOP_DOWN_TIME);
4254 }
4255
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004256 /* Clear all async request states across all VPs. */
4257 list_for_each_entry(fcport, &vha->vp_fcports, list)
4258 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4259 spin_lock_irqsave(&ha->vport_slock, flags);
4260 list_for_each_entry(vp, &ha->vp_list, list) {
4261 atomic_inc(&vp->vref_count);
4262 spin_unlock_irqrestore(&ha->vport_slock, flags);
4263
4264 list_for_each_entry(fcport, &vp->vp_fcports, list)
4265 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4266
4267 spin_lock_irqsave(&ha->vport_slock, flags);
4268 atomic_dec(&vp->vref_count);
4269 }
4270 spin_unlock_irqrestore(&ha->vport_slock, flags);
4271
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004272 if (!ha->flags.eeh_busy) {
4273 /* Make sure for ISP 82XX IO DMA is complete */
4274 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004275 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004276 ql_log(ql_log_info, vha, 0x00b4,
4277 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004278
Saurav Kashyape46ef002011-02-23 15:27:16 -08004279 /* Done waiting for pending commands.
4280 * Reset the online flag.
4281 */
4282 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004283 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004284
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004285 /* Requeue all commands in outstanding command list. */
4286 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4287 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288}
4289
4290/*
4291* qla2x00_abort_isp
4292* Resets ISP and aborts all outstanding commands.
4293*
4294* Input:
4295* ha = adapter block pointer.
4296*
4297* Returns:
4298* 0 = success
4299*/
4300int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004301qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302{
Andrew Vasquez476e8972006-08-23 14:54:55 -07004303 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004305 struct qla_hw_data *ha = vha->hw;
4306 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004307 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07004308 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004310 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004311 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004312
Santosh Vernekara61712972012-08-22 14:21:13 -04004313 if (IS_QLA8031(ha)) {
4314 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
4315 "Clearing fcoe driver presence.\n");
4316 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
4317 ql_dbg(ql_dbg_p3p, vha, 0xb073,
4318 "Error while clearing DRV-Presence.\n");
4319 }
4320
Andrew Vasquez85880802009-12-15 21:29:46 -08004321 if (unlikely(pci_channel_offline(ha->pdev) &&
4322 ha->flags.pci_channel_io_perm_failure)) {
4323 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4324 status = 0;
4325 return status;
4326 }
4327
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004328 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08004329
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004330 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004331
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004332 if (!qla2x00_restart_isp(vha)) {
4333 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004335 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336 /*
4337 * Issue marker command only when we are going
4338 * to start the I/O .
4339 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004340 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004341 }
4342
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004343 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004344
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004345 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004347 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004348 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07004349
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004350 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
4351 qla2x00_get_fw_version(vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004352 if (ha->fce) {
4353 ha->flags.fce_enabled = 1;
4354 memset(ha->fce, 0,
4355 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004356 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004357 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4358 &ha->fce_bufs);
4359 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004360 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004361 "Unable to reinitialize FCE "
4362 "(%d).\n", rval);
4363 ha->flags.fce_enabled = 0;
4364 }
4365 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004366
4367 if (ha->eft) {
4368 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004369 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004370 ha->eft_dma, EFT_NUM_BUFFERS);
4371 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004372 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004373 "Unable to reinitialize EFT "
4374 "(%d).\n", rval);
4375 }
4376 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004378 vha->flags.online = 1;
4379 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004381 ql_log(ql_log_fatal, vha, 0x8035,
4382 "ISP error recover failed - "
4383 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004384 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385 * The next call disables the board
4386 * completely.
4387 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004388 ha->isp_ops->reset_adapter(vha);
4389 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004391 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392 status = 0;
4393 } else { /* schedule another ISP abort */
4394 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004395 ql_dbg(ql_dbg_taskm, vha, 0x8020,
4396 "ISP abort - retry remaining %d.\n",
4397 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398 status = 1;
4399 }
4400 } else {
4401 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004402 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4403 "ISP error recovery - retrying (%d) "
4404 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004405 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406 status = 1;
4407 }
4408 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004409
Linus Torvalds1da177e2005-04-16 15:20:36 -07004410 }
4411
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004412 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004413 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07004414
4415 spin_lock_irqsave(&ha->vport_slock, flags);
4416 list_for_each_entry(vp, &ha->vp_list, list) {
4417 if (vp->vp_idx) {
4418 atomic_inc(&vp->vref_count);
4419 spin_unlock_irqrestore(&ha->vport_slock, flags);
4420
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004421 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004422
4423 spin_lock_irqsave(&ha->vport_slock, flags);
4424 atomic_dec(&vp->vref_count);
4425 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004426 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004427 spin_unlock_irqrestore(&ha->vport_slock, flags);
4428
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004429 if (IS_QLA8031(ha)) {
4430 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
4431 "Setting back fcoe driver presence.\n");
4432 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
4433 ql_dbg(ql_dbg_p3p, vha, 0xb074,
4434 "Error while setting DRV-Presence.\n");
4435 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004436 } else {
Joe Perchesd8424f62011-11-18 09:03:06 -08004437 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
4438 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004439 }
4440
4441 return(status);
4442}
4443
4444/*
4445* qla2x00_restart_isp
4446* restarts the ISP after a reset
4447*
4448* Input:
4449* ha = adapter block pointer.
4450*
4451* Returns:
4452* 0 = success
4453*/
4454static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004455qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004456{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004457 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004458 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004459 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004460 struct req_que *req = ha->req_q_map[0];
4461 struct rsp_que *rsp = ha->rsp_q_map[0];
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004462 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463
4464 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004465 if (qla2x00_isp_firmware(vha)) {
4466 vha->flags.online = 0;
4467 status = ha->isp_ops->chip_diag(vha);
4468 if (!status)
4469 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004470 }
4471
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004472 if (!status && !(status = qla2x00_init_rings(vha))) {
4473 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004474 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004475 /* Initialize the queues in use */
4476 qla25xx_init_queues(ha);
4477
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004478 status = qla2x00_fw_ready(vha);
4479 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004480 ql_dbg(ql_dbg_taskm, vha, 0x8031,
4481 "Start configure loop status = %d.\n", status);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004482
4483 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004484 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004485
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004486 vha->flags.online = 1;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004487
4488 /*
4489 * Process any ATIO queue entries that came in
4490 * while we weren't online.
4491 */
4492 spin_lock_irqsave(&ha->hardware_lock, flags);
4493 if (qla_tgt_mode_enabled(vha))
4494 qlt_24xx_process_atio_queue(vha);
4495 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4496
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4498 wait_time = 256;
4499 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004500 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4501 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004503 } while (!atomic_read(&vha->loop_down_timer) &&
4504 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4505 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4506 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507 }
4508
4509 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004510 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004511 status = 0;
4512
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004513 ql_dbg(ql_dbg_taskm, vha, 0x8032,
4514 "Configure loop done, status = 0x%x.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515 }
4516 return (status);
4517}
4518
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004519static int
4520qla25xx_init_queues(struct qla_hw_data *ha)
4521{
4522 struct rsp_que *rsp = NULL;
4523 struct req_que *req = NULL;
4524 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4525 int ret = -1;
4526 int i;
4527
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004528 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004529 rsp = ha->rsp_q_map[i];
4530 if (rsp) {
4531 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004532 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004533 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004534 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4535 "%s Rsp que: %d init failed.\n",
4536 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004537 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004538 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4539 "%s Rsp que: %d inited.\n",
4540 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004541 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004542 }
4543 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004544 req = ha->req_q_map[i];
4545 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004546 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004547 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004548 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004549 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004550 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4551 "%s Req que: %d init failed.\n",
4552 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004553 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004554 ql_dbg(ql_dbg_init, base_vha, 0x0102,
4555 "%s Req que: %d inited.\n",
4556 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004557 }
4558 }
4559 return ret;
4560}
4561
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562/*
4563* qla2x00_reset_adapter
4564* Reset adapter.
4565*
4566* Input:
4567* ha = adapter block pointer.
4568*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004569void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004570qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004571{
4572 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004573 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004574 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004575
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004576 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004577 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004578
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579 spin_lock_irqsave(&ha->hardware_lock, flags);
4580 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4581 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4582 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4583 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4584 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4585}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004586
4587void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004588qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004589{
4590 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004591 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004592 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4593
Giridhar Malavalia9083012010-04-12 17:59:55 -07004594 if (IS_QLA82XX(ha))
4595 return;
4596
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004597 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004598 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004599
4600 spin_lock_irqsave(&ha->hardware_lock, flags);
4601 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4602 RD_REG_DWORD(&reg->hccr);
4603 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4604 RD_REG_DWORD(&reg->hccr);
4605 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004606
4607 if (IS_NOPOLLING_TYPE(ha))
4608 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004609}
4610
David Miller4e08df32007-04-16 12:37:43 -07004611/* On sparc systems, obtain port and node WWN from firmware
4612 * properties.
4613 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004614static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4615 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004616{
4617#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004618 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004619 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004620 struct device_node *dp = pci_device_to_OF_node(pdev);
4621 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004622 int len;
4623
4624 val = of_get_property(dp, "port-wwn", &len);
4625 if (val && len >= WWN_SIZE)
4626 memcpy(nv->port_name, val, WWN_SIZE);
4627
4628 val = of_get_property(dp, "node-wwn", &len);
4629 if (val && len >= WWN_SIZE)
4630 memcpy(nv->node_name, val, WWN_SIZE);
4631#endif
4632}
4633
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004634int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004635qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004636{
David Miller4e08df32007-04-16 12:37:43 -07004637 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004638 struct init_cb_24xx *icb;
4639 struct nvram_24xx *nv;
4640 uint32_t *dptr;
4641 uint8_t *dptr1, *dptr2;
4642 uint32_t chksum;
4643 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004644 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004645
David Miller4e08df32007-04-16 12:37:43 -07004646 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004647 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004648 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004649
4650 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004651 if (ha->flags.port0) {
4652 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4653 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4654 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004655 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004656 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4657 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004658 ha->nvram_size = sizeof(struct nvram_24xx);
4659 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004660 if (IS_QLA82XX(ha))
4661 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004662
Seokmann Ju281afe12007-07-26 13:43:34 -07004663 /* Get VPD data into cache */
4664 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004665 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004666 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4667
4668 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004669 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004670 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004671 ha->nvram_size);
4672 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4673 chksum += le32_to_cpu(*dptr++);
4674
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004675 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
4676 "Contents of NVRAM\n");
4677 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
4678 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004679
4680 /* Bad NVRAM data, set defaults parameters. */
4681 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4682 || nv->id[3] != ' ' ||
4683 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4684 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004685 ql_log(ql_log_warn, vha, 0x006b,
Raul Porcel9e336522012-05-15 14:34:08 -04004686 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004687 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
4688 ql_log(ql_log_warn, vha, 0x006c,
4689 "Falling back to functioning (yet invalid -- WWPN) "
4690 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07004691
4692 /*
4693 * Set default initialization control block.
4694 */
4695 memset(nv, 0, ha->nvram_size);
4696 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4697 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4698 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4699 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4700 nv->exchange_count = __constant_cpu_to_le16(0);
4701 nv->hard_address = __constant_cpu_to_le16(124);
4702 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004703 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004704 nv->port_name[2] = 0x00;
4705 nv->port_name[3] = 0xe0;
4706 nv->port_name[4] = 0x8b;
4707 nv->port_name[5] = 0x1c;
4708 nv->port_name[6] = 0x55;
4709 nv->port_name[7] = 0x86;
4710 nv->node_name[0] = 0x20;
4711 nv->node_name[1] = 0x00;
4712 nv->node_name[2] = 0x00;
4713 nv->node_name[3] = 0xe0;
4714 nv->node_name[4] = 0x8b;
4715 nv->node_name[5] = 0x1c;
4716 nv->node_name[6] = 0x55;
4717 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004718 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004719 nv->login_retry_count = __constant_cpu_to_le16(8);
4720 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4721 nv->login_timeout = __constant_cpu_to_le16(0);
4722 nv->firmware_options_1 =
4723 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4724 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4725 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4726 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4727 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4728 nv->efi_parameters = __constant_cpu_to_le32(0);
4729 nv->reset_delay = 5;
4730 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4731 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4732 nv->link_down_timeout = __constant_cpu_to_le16(30);
4733
4734 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004735 }
4736
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004737 if (!qla_ini_mode_enabled(vha)) {
4738 /* Don't enable full login after initial LIP */
4739 nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13);
4740 /* Don't enable LIP full login for initiator */
4741 nv->host_p &= __constant_cpu_to_le32(~BIT_10);
4742 }
4743
4744 qlt_24xx_config_nvram_stage1(vha, nv);
4745
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004746 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004747 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004748
4749 /* Copy 1st segment. */
4750 dptr1 = (uint8_t *)icb;
4751 dptr2 = (uint8_t *)&nv->version;
4752 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4753 while (cnt--)
4754 *dptr1++ = *dptr2++;
4755
4756 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004757 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004758
4759 /* Copy 2nd segment. */
4760 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4761 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4762 cnt = (uint8_t *)&icb->reserved_3 -
4763 (uint8_t *)&icb->interrupt_delay_timer;
4764 while (cnt--)
4765 *dptr1++ = *dptr2++;
4766
4767 /*
4768 * Setup driver NVRAM options.
4769 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004770 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004771 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004772
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004773 qlt_24xx_config_nvram_stage2(vha, icb);
4774
Andrew Vasquez5341e862006-05-17 15:09:16 -07004775 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004776 /* Use alternate WWN? */
Andrew Vasquez5341e862006-05-17 15:09:16 -07004777 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4778 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4779 }
4780
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004781 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004782 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004783 /*
4784 * Firmware will apply the following mask if the nodename was
4785 * not provided.
4786 */
4787 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4788 icb->node_name[0] &= 0xF0;
4789 }
4790
4791 /* Set host adapter parameters. */
4792 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004793 ha->flags.enable_lip_reset = 0;
4794 ha->flags.enable_lip_full_login =
4795 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4796 ha->flags.enable_target_reset =
4797 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004798 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004799 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004800
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004801 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4802 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004803
4804 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4805 sizeof(ha->fw_seriallink_options24));
4806
4807 /* save HBA serial number */
4808 ha->serial0 = icb->port_name[5];
4809 ha->serial1 = icb->port_name[6];
4810 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004811 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4812 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004813
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004814 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4815
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004816 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4817
4818 /* Set minimum login_timeout to 4 seconds. */
4819 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4820 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4821 if (le16_to_cpu(nv->login_timeout) < 4)
4822 nv->login_timeout = __constant_cpu_to_le16(4);
4823 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004824 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004825
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004826 /* Set minimum RATOV to 100 tenths of a second. */
4827 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004828
4829 ha->loop_reset_delay = nv->reset_delay;
4830
4831 /* Link Down Timeout = 0:
4832 *
4833 * When Port Down timer expires we will start returning
4834 * I/O's to OS with "DID_NO_CONNECT".
4835 *
4836 * Link Down Timeout != 0:
4837 *
4838 * The driver waits for the link to come up after link down
4839 * before returning I/Os to OS with "DID_NO_CONNECT".
4840 */
4841 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4842 ha->loop_down_abort_time =
4843 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4844 } else {
4845 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4846 ha->loop_down_abort_time =
4847 (LOOP_DOWN_TIME - ha->link_down_timeout);
4848 }
4849
4850 /* Need enough time to try and get the port back. */
4851 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4852 if (qlport_down_retry)
4853 ha->port_down_retry_count = qlport_down_retry;
4854
4855 /* Set login_retry_count */
4856 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4857 if (ha->port_down_retry_count ==
4858 le16_to_cpu(nv->port_down_retry_count) &&
4859 ha->port_down_retry_count > 3)
4860 ha->login_retry_count = ha->port_down_retry_count;
4861 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4862 ha->login_retry_count = ha->port_down_retry_count;
4863 if (ql2xloginretrycount)
4864 ha->login_retry_count = ql2xloginretrycount;
4865
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004866 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004867 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004868 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4869 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4870 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4871 le16_to_cpu(icb->interrupt_delay_timer): 2;
4872 }
4873 icb->firmware_options_2 &= __constant_cpu_to_le32(
4874 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004875 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004876 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004877 ha->zio_mode = QLA_ZIO_MODE_6;
4878
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004879 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004880 "ZIO mode %d enabled; timer delay (%d us).\n",
4881 ha->zio_mode, ha->zio_timer * 100);
4882
4883 icb->firmware_options_2 |= cpu_to_le32(
4884 (uint32_t)ha->zio_mode);
4885 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004886 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004887 }
4888
David Miller4e08df32007-04-16 12:37:43 -07004889 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004890 ql_log(ql_log_warn, vha, 0x0070,
4891 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07004892 }
4893 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004894}
4895
Adrian Bunk413975a2006-06-30 02:33:06 -07004896static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004897qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4898 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004899{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004900 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004901 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004902 uint32_t *dcode, dlen;
4903 uint32_t risc_addr;
4904 uint32_t risc_size;
4905 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004906 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004907 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004908
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004909 ql_dbg(ql_dbg_init, vha, 0x008b,
Chad Dupuiscfb09192011-11-18 09:03:07 -08004910 "FW: Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004911
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004912 rval = QLA_SUCCESS;
4913
4914 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004915 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004916 *srisc_addr = 0;
4917
4918 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004919 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004920 for (i = 0; i < 4; i++)
4921 dcode[i] = be32_to_cpu(dcode[i]);
4922 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4923 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4924 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4925 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004926 ql_log(ql_log_fatal, vha, 0x008c,
4927 "Unable to verify the integrity of flash firmware "
4928 "image.\n");
4929 ql_log(ql_log_fatal, vha, 0x008d,
4930 "Firmware data: %08x %08x %08x %08x.\n",
4931 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004932
4933 return QLA_FUNCTION_FAILED;
4934 }
4935
4936 while (segments && rval == QLA_SUCCESS) {
4937 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004938 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004939
4940 risc_addr = be32_to_cpu(dcode[2]);
4941 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4942 risc_size = be32_to_cpu(dcode[3]);
4943
4944 fragment = 0;
4945 while (risc_size > 0 && rval == QLA_SUCCESS) {
4946 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4947 if (dlen > risc_size)
4948 dlen = risc_size;
4949
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004950 ql_dbg(ql_dbg_init, vha, 0x008e,
4951 "Loading risc segment@ risc addr %x "
4952 "number of dwords 0x%x offset 0x%x.\n",
4953 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004954
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004955 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004956 for (i = 0; i < dlen; i++)
4957 dcode[i] = swab32(dcode[i]);
4958
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004959 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004960 dlen);
4961 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004962 ql_log(ql_log_fatal, vha, 0x008f,
4963 "Failed to load segment %d of firmware.\n",
4964 fragment);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004965 break;
4966 }
4967
4968 faddr += dlen;
4969 risc_addr += dlen;
4970 risc_size -= dlen;
4971 fragment++;
4972 }
4973
4974 /* Next segment. */
4975 segments--;
4976 }
4977
4978 return rval;
4979}
4980
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004981#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4982
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004983int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004984qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004985{
4986 int rval;
4987 int i, fragment;
4988 uint16_t *wcode, *fwcode;
4989 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4990 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004991 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004992 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004993
4994 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004995 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004996 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004997 ql_log(ql_log_info, vha, 0x0083,
4998 "Fimware image unavailable.\n");
4999 ql_log(ql_log_info, vha, 0x0084,
5000 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08005001 return QLA_FUNCTION_FAILED;
5002 }
5003
5004 rval = QLA_SUCCESS;
5005
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005006 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08005007 *srisc_addr = 0;
5008 fwcode = (uint16_t *)blob->fw->data;
5009 fwclen = 0;
5010
5011 /* Validate firmware image by checking version. */
5012 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005013 ql_log(ql_log_fatal, vha, 0x0085,
5014 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005015 blob->fw->size);
5016 goto fail_fw_integrity;
5017 }
5018 for (i = 0; i < 4; i++)
5019 wcode[i] = be16_to_cpu(fwcode[i + 4]);
5020 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
5021 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
5022 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005023 ql_log(ql_log_fatal, vha, 0x0086,
5024 "Unable to verify integrity of firmware image.\n");
5025 ql_log(ql_log_fatal, vha, 0x0087,
5026 "Firmware data: %04x %04x %04x %04x.\n",
5027 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08005028 goto fail_fw_integrity;
5029 }
5030
5031 seg = blob->segs;
5032 while (*seg && rval == QLA_SUCCESS) {
5033 risc_addr = *seg;
5034 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
5035 risc_size = be16_to_cpu(fwcode[3]);
5036
5037 /* Validate firmware image size. */
5038 fwclen += risc_size * sizeof(uint16_t);
5039 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005040 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08005041 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005042 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08005043 goto fail_fw_integrity;
5044 }
5045
5046 fragment = 0;
5047 while (risc_size > 0 && rval == QLA_SUCCESS) {
5048 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
5049 if (wlen > risc_size)
5050 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005051 ql_dbg(ql_dbg_init, vha, 0x0089,
5052 "Loading risc segment@ risc addr %x number of "
5053 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08005054
5055 for (i = 0; i < wlen; i++)
5056 wcode[i] = swab16(fwcode[i]);
5057
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005058 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08005059 wlen);
5060 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005061 ql_log(ql_log_fatal, vha, 0x008a,
5062 "Failed to load segment %d of firmware.\n",
5063 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08005064 break;
5065 }
5066
5067 fwcode += wlen;
5068 risc_addr += wlen;
5069 risc_size -= wlen;
5070 fragment++;
5071 }
5072
5073 /* Next segment. */
5074 seg++;
5075 }
5076 return rval;
5077
5078fail_fw_integrity:
5079 return QLA_FUNCTION_FAILED;
5080}
5081
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005082static int
5083qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005084{
5085 int rval;
5086 int segments, fragment;
5087 uint32_t *dcode, dlen;
5088 uint32_t risc_addr;
5089 uint32_t risc_size;
5090 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08005091 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005092 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005093 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005094 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005095
Andrew Vasquez54333832005-11-09 15:49:04 -08005096 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005097 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08005098 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005099 ql_log(ql_log_warn, vha, 0x0090,
5100 "Fimware image unavailable.\n");
5101 ql_log(ql_log_warn, vha, 0x0091,
5102 "Firmware images can be retrieved from: "
5103 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07005104
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005105 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005106 }
5107
Chad Dupuiscfb09192011-11-18 09:03:07 -08005108 ql_dbg(ql_dbg_init, vha, 0x0092,
5109 "FW: Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005110
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005111 rval = QLA_SUCCESS;
5112
5113 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005114 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005115 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08005116 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005117 fwclen = 0;
5118
5119 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08005120 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005121 ql_log(ql_log_fatal, vha, 0x0093,
5122 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08005123 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005124 goto fail_fw_integrity;
5125 }
5126 for (i = 0; i < 4; i++)
5127 dcode[i] = be32_to_cpu(fwcode[i + 4]);
5128 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
5129 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
5130 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
5131 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005132 ql_log(ql_log_fatal, vha, 0x0094,
5133 "Unable to verify integrity of firmware image (%Zd).\n",
5134 blob->fw->size);
5135 ql_log(ql_log_fatal, vha, 0x0095,
5136 "Firmware data: %08x %08x %08x %08x.\n",
5137 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005138 goto fail_fw_integrity;
5139 }
5140
5141 while (segments && rval == QLA_SUCCESS) {
5142 risc_addr = be32_to_cpu(fwcode[2]);
5143 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
5144 risc_size = be32_to_cpu(fwcode[3]);
5145
5146 /* Validate firmware image size. */
5147 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08005148 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005149 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08005150 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005151 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08005152
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005153 goto fail_fw_integrity;
5154 }
5155
5156 fragment = 0;
5157 while (risc_size > 0 && rval == QLA_SUCCESS) {
5158 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
5159 if (dlen > risc_size)
5160 dlen = risc_size;
5161
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005162 ql_dbg(ql_dbg_init, vha, 0x0097,
5163 "Loading risc segment@ risc addr %x "
5164 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005165
5166 for (i = 0; i < dlen; i++)
5167 dcode[i] = swab32(fwcode[i]);
5168
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005169 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08005170 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005171 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005172 ql_log(ql_log_fatal, vha, 0x0098,
5173 "Failed to load segment %d of firmware.\n",
5174 fragment);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005175 break;
5176 }
5177
5178 fwcode += dlen;
5179 risc_addr += dlen;
5180 risc_size -= dlen;
5181 fragment++;
5182 }
5183
5184 /* Next segment. */
5185 segments--;
5186 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005187 return rval;
5188
5189fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005190 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07005191}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005192
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005193int
5194qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5195{
5196 int rval;
5197
Andrew Vasqueze337d902009-04-06 22:33:49 -07005198 if (ql2xfwloadbin == 1)
5199 return qla81xx_load_risc(vha, srisc_addr);
5200
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005201 /*
5202 * FW Load priority:
5203 * 1) Firmware via request-firmware interface (.bin file).
5204 * 2) Firmware residing in flash.
5205 */
5206 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5207 if (rval == QLA_SUCCESS)
5208 return rval;
5209
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005210 return qla24xx_load_risc_flash(vha, srisc_addr,
5211 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005212}
5213
5214int
5215qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5216{
5217 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005218 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005219
Andrew Vasqueze337d902009-04-06 22:33:49 -07005220 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005221 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07005222
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005223 /*
5224 * FW Load priority:
5225 * 1) Firmware residing in flash.
5226 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005227 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005228 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005229 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005230 if (rval == QLA_SUCCESS)
5231 return rval;
5232
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005233try_blob_fw:
5234 rval = qla24xx_load_risc_blob(vha, srisc_addr);
5235 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
5236 return rval;
5237
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005238 ql_log(ql_log_info, vha, 0x0099,
5239 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005240 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
5241 if (rval != QLA_SUCCESS)
5242 return rval;
5243
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005244 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005245 ha->flags.running_gold_fw = 1;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07005246 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08005247}
5248
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005249void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005250qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005251{
5252 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005253 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005254
Andrew Vasquez85880802009-12-15 21:29:46 -08005255 if (ha->flags.pci_channel_io_perm_failure)
5256 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07005257 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005258 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07005259 if (!ha->fw_major_version)
5260 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005261
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005262 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08005263 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07005264 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005265 ha->isp_ops->reset_chip(vha);
5266 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005267 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005268 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005269 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005270 ql_log(ql_log_info, vha, 0x8015,
5271 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005272 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005273 }
5274}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005275
5276int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005277qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005278{
5279 int rval = QLA_SUCCESS;
Chad Dupuis0b91d112012-02-09 11:15:42 -08005280 int rval2;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005281 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005282 struct qla_hw_data *ha = vha->hw;
5283 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005284 struct req_que *req;
5285 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005286
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005287 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005288 return -EINVAL;
5289
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005290 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07005291 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005292 req = ha->req_q_map[0];
5293 else
5294 req = vha->req;
5295 rsp = req->rsp;
5296
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005297 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005298 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005299 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005300 }
5301
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005302 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005303
5304 /* Login to SNS first */
Chad Dupuis0b91d112012-02-09 11:15:42 -08005305 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
5306 BIT_1);
5307 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5308 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
5309 ql_dbg(ql_dbg_init, vha, 0x0120,
5310 "Failed SNS login: loop_id=%x, rval2=%d\n",
5311 NPH_SNS, rval2);
5312 else
5313 ql_dbg(ql_dbg_init, vha, 0x0103,
5314 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5315 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
5316 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005317 return (QLA_FUNCTION_FAILED);
5318 }
5319
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005320 atomic_set(&vha->loop_down_timer, 0);
5321 atomic_set(&vha->loop_state, LOOP_UP);
5322 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5323 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5324 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005325
5326 return rval;
5327}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005328
5329/* 84XX Support **************************************************************/
5330
5331static LIST_HEAD(qla_cs84xx_list);
5332static DEFINE_MUTEX(qla_cs84xx_mutex);
5333
5334static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005335qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005336{
5337 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005338 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005339
5340 mutex_lock(&qla_cs84xx_mutex);
5341
5342 /* Find any shared 84xx chip. */
5343 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5344 if (cs84xx->bus == ha->pdev->bus) {
5345 kref_get(&cs84xx->kref);
5346 goto done;
5347 }
5348 }
5349
5350 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5351 if (!cs84xx)
5352 goto done;
5353
5354 kref_init(&cs84xx->kref);
5355 spin_lock_init(&cs84xx->access_lock);
5356 mutex_init(&cs84xx->fw_update_mutex);
5357 cs84xx->bus = ha->pdev->bus;
5358
5359 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5360done:
5361 mutex_unlock(&qla_cs84xx_mutex);
5362 return cs84xx;
5363}
5364
5365static void
5366__qla84xx_chip_release(struct kref *kref)
5367{
5368 struct qla_chip_state_84xx *cs84xx =
5369 container_of(kref, struct qla_chip_state_84xx, kref);
5370
5371 mutex_lock(&qla_cs84xx_mutex);
5372 list_del(&cs84xx->list);
5373 mutex_unlock(&qla_cs84xx_mutex);
5374 kfree(cs84xx);
5375}
5376
5377void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005378qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005379{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005380 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005381 if (ha->cs84xx)
5382 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
5383}
5384
5385static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005386qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005387{
5388 int rval;
5389 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005390 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005391
5392 mutex_lock(&ha->cs84xx->fw_update_mutex);
5393
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005394 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005395
5396 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5397
5398 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5399 QLA_SUCCESS;
5400}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005401
5402/* 81XX Support **************************************************************/
5403
5404int
5405qla81xx_nvram_config(scsi_qla_host_t *vha)
5406{
5407 int rval;
5408 struct init_cb_81xx *icb;
5409 struct nvram_81xx *nv;
5410 uint32_t *dptr;
5411 uint8_t *dptr1, *dptr2;
5412 uint32_t chksum;
5413 uint16_t cnt;
5414 struct qla_hw_data *ha = vha->hw;
5415
5416 rval = QLA_SUCCESS;
5417 icb = (struct init_cb_81xx *)ha->init_cb;
5418 nv = ha->nvram;
5419
5420 /* Determine NVRAM starting address. */
5421 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005422 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005423
5424 /* Get VPD data into cache */
5425 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005426 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5427 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005428
5429 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005430 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005431 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005432 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005433 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5434 chksum += le32_to_cpu(*dptr++);
5435
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005436 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
5437 "Contents of NVRAM:\n");
5438 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
5439 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005440
5441 /* Bad NVRAM data, set defaults parameters. */
5442 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5443 || nv->id[3] != ' ' ||
5444 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5445 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005446 ql_log(ql_log_info, vha, 0x0073,
Raul Porcel9e336522012-05-15 14:34:08 -04005447 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005448 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005449 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005450 ql_log(ql_log_info, vha, 0x0074,
5451 "Falling back to functioning (yet invalid -- WWPN) "
5452 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005453
5454 /*
5455 * Set default initialization control block.
5456 */
5457 memset(nv, 0, ha->nvram_size);
5458 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5459 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5460 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5461 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5462 nv->exchange_count = __constant_cpu_to_le16(0);
5463 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005464 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005465 nv->port_name[2] = 0x00;
5466 nv->port_name[3] = 0xe0;
5467 nv->port_name[4] = 0x8b;
5468 nv->port_name[5] = 0x1c;
5469 nv->port_name[6] = 0x55;
5470 nv->port_name[7] = 0x86;
5471 nv->node_name[0] = 0x20;
5472 nv->node_name[1] = 0x00;
5473 nv->node_name[2] = 0x00;
5474 nv->node_name[3] = 0xe0;
5475 nv->node_name[4] = 0x8b;
5476 nv->node_name[5] = 0x1c;
5477 nv->node_name[6] = 0x55;
5478 nv->node_name[7] = 0x86;
5479 nv->login_retry_count = __constant_cpu_to_le16(8);
5480 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5481 nv->login_timeout = __constant_cpu_to_le16(0);
5482 nv->firmware_options_1 =
5483 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5484 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5485 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5486 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5487 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5488 nv->efi_parameters = __constant_cpu_to_le32(0);
5489 nv->reset_delay = 5;
5490 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5491 nv->port_down_retry_count = __constant_cpu_to_le16(30);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005492 nv->link_down_timeout = __constant_cpu_to_le16(180);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005493 nv->enode_mac[0] = 0x00;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005494 nv->enode_mac[1] = 0xC0;
5495 nv->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005496 nv->enode_mac[3] = 0x04;
5497 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005498 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005499
5500 rval = 1;
5501 }
5502
Arun Easi9e522cd2012-08-22 14:21:31 -04005503 if (IS_T10_PI_CAPABLE(ha))
5504 nv->frame_payload_size &= ~7;
5505
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005506 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07005507 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005508
5509 /* Copy 1st segment. */
5510 dptr1 = (uint8_t *)icb;
5511 dptr2 = (uint8_t *)&nv->version;
5512 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5513 while (cnt--)
5514 *dptr1++ = *dptr2++;
5515
5516 icb->login_retry_count = nv->login_retry_count;
5517
5518 /* Copy 2nd segment. */
5519 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5520 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5521 cnt = (uint8_t *)&icb->reserved_5 -
5522 (uint8_t *)&icb->interrupt_delay_timer;
5523 while (cnt--)
5524 *dptr1++ = *dptr2++;
5525
5526 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5527 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5528 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
Andrew Vasquez69e5f1e2012-02-09 11:15:35 -08005529 icb->enode_mac[0] = 0x00;
5530 icb->enode_mac[1] = 0xC0;
5531 icb->enode_mac[2] = 0xDD;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005532 icb->enode_mac[3] = 0x04;
5533 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005534 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005535 }
5536
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005537 /* Use extended-initialization control block. */
5538 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5539
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005540 /*
5541 * Setup driver NVRAM options.
5542 */
5543 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005544 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005545
5546 /* Use alternate WWN? */
5547 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5548 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5549 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5550 }
5551
5552 /* Prepare nodename */
5553 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5554 /*
5555 * Firmware will apply the following mask if the nodename was
5556 * not provided.
5557 */
5558 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5559 icb->node_name[0] &= 0xF0;
5560 }
5561
5562 /* Set host adapter parameters. */
5563 ha->flags.disable_risc_code_load = 0;
5564 ha->flags.enable_lip_reset = 0;
5565 ha->flags.enable_lip_full_login =
5566 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5567 ha->flags.enable_target_reset =
5568 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5569 ha->flags.enable_led_scheme = 0;
5570 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5571
5572 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5573 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5574
5575 /* save HBA serial number */
5576 ha->serial0 = icb->port_name[5];
5577 ha->serial1 = icb->port_name[6];
5578 ha->serial2 = icb->port_name[7];
5579 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5580 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5581
5582 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5583
5584 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5585
5586 /* Set minimum login_timeout to 4 seconds. */
5587 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5588 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5589 if (le16_to_cpu(nv->login_timeout) < 4)
5590 nv->login_timeout = __constant_cpu_to_le16(4);
5591 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5592 icb->login_timeout = nv->login_timeout;
5593
5594 /* Set minimum RATOV to 100 tenths of a second. */
5595 ha->r_a_tov = 100;
5596
5597 ha->loop_reset_delay = nv->reset_delay;
5598
5599 /* Link Down Timeout = 0:
5600 *
5601 * When Port Down timer expires we will start returning
5602 * I/O's to OS with "DID_NO_CONNECT".
5603 *
5604 * Link Down Timeout != 0:
5605 *
5606 * The driver waits for the link to come up after link down
5607 * before returning I/Os to OS with "DID_NO_CONNECT".
5608 */
5609 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5610 ha->loop_down_abort_time =
5611 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5612 } else {
5613 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5614 ha->loop_down_abort_time =
5615 (LOOP_DOWN_TIME - ha->link_down_timeout);
5616 }
5617
5618 /* Need enough time to try and get the port back. */
5619 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5620 if (qlport_down_retry)
5621 ha->port_down_retry_count = qlport_down_retry;
5622
5623 /* Set login_retry_count */
5624 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5625 if (ha->port_down_retry_count ==
5626 le16_to_cpu(nv->port_down_retry_count) &&
5627 ha->port_down_retry_count > 3)
5628 ha->login_retry_count = ha->port_down_retry_count;
5629 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5630 ha->login_retry_count = ha->port_down_retry_count;
5631 if (ql2xloginretrycount)
5632 ha->login_retry_count = ql2xloginretrycount;
5633
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005634 /* if not running MSI-X we need handshaking on interrupts */
5635 if (!vha->hw->flags.msix_enabled && IS_QLA83XX(ha))
5636 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
5637
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005638 /* Enable ZIO. */
5639 if (!vha->flags.init_done) {
5640 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5641 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5642 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5643 le16_to_cpu(icb->interrupt_delay_timer): 2;
5644 }
5645 icb->firmware_options_2 &= __constant_cpu_to_le32(
5646 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5647 vha->flags.process_response_queue = 0;
5648 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5649 ha->zio_mode = QLA_ZIO_MODE_6;
5650
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005651 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005652 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005653 ha->zio_mode,
5654 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005655
5656 icb->firmware_options_2 |= cpu_to_le32(
5657 (uint32_t)ha->zio_mode);
5658 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5659 vha->flags.process_response_queue = 1;
5660 }
5661
5662 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005663 ql_log(ql_log_warn, vha, 0x0076,
5664 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005665 }
5666 return (rval);
5667}
5668
Giridhar Malavalia9083012010-04-12 17:59:55 -07005669int
5670qla82xx_restart_isp(scsi_qla_host_t *vha)
5671{
5672 int status, rval;
5673 uint32_t wait_time;
5674 struct qla_hw_data *ha = vha->hw;
5675 struct req_que *req = ha->req_q_map[0];
5676 struct rsp_que *rsp = ha->rsp_q_map[0];
5677 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005678 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005679
5680 status = qla2x00_init_rings(vha);
5681 if (!status) {
5682 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5683 ha->flags.chip_reset_done = 1;
5684
5685 status = qla2x00_fw_ready(vha);
5686 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005687 ql_log(ql_log_info, vha, 0x803c,
5688 "Start configure loop, status =%d.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005689
5690 /* Issue a marker after FW becomes ready. */
5691 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5692
5693 vha->flags.online = 1;
5694 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5695 wait_time = 256;
5696 do {
5697 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5698 qla2x00_configure_loop(vha);
5699 wait_time--;
5700 } while (!atomic_read(&vha->loop_down_timer) &&
5701 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5702 wait_time &&
5703 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5704 }
5705
5706 /* if no cable then assume it's good */
5707 if ((vha->device_flags & DFLG_NO_CABLE))
5708 status = 0;
5709
Chad Dupuiscfb09192011-11-18 09:03:07 -08005710 ql_log(ql_log_info, vha, 0x8000,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005711 "Configure loop done, status = 0x%x.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005712 }
5713
5714 if (!status) {
5715 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5716
5717 if (!atomic_read(&vha->loop_down_timer)) {
5718 /*
5719 * Issue marker command only when we are going
5720 * to start the I/O .
5721 */
5722 vha->marker_needed = 1;
5723 }
5724
5725 vha->flags.online = 1;
5726
5727 ha->isp_ops->enable_intrs(ha);
5728
5729 ha->isp_abort_cnt = 0;
5730 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5731
Saurav Kashyap53296782011-05-10 11:30:06 -07005732 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07005733 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07005734
Giridhar Malavalia9083012010-04-12 17:59:55 -07005735 if (ha->fce) {
5736 ha->flags.fce_enabled = 1;
5737 memset(ha->fce, 0,
5738 fce_calc_size(ha->fce_bufs));
5739 rval = qla2x00_enable_fce_trace(vha,
5740 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5741 &ha->fce_bufs);
5742 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005743 ql_log(ql_log_warn, vha, 0x8001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005744 "Unable to reinitialize FCE (%d).\n",
5745 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005746 ha->flags.fce_enabled = 0;
5747 }
5748 }
5749
5750 if (ha->eft) {
5751 memset(ha->eft, 0, EFT_SIZE);
5752 rval = qla2x00_enable_eft_trace(vha,
5753 ha->eft_dma, EFT_NUM_BUFFERS);
5754 if (rval) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005755 ql_log(ql_log_warn, vha, 0x8010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005756 "Unable to reinitialize EFT (%d).\n",
5757 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005758 }
5759 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005760 }
5761
5762 if (!status) {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005763 ql_dbg(ql_dbg_taskm, vha, 0x8011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005764 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07005765
5766 spin_lock_irqsave(&ha->vport_slock, flags);
5767 list_for_each_entry(vp, &ha->vp_list, list) {
5768 if (vp->vp_idx) {
5769 atomic_inc(&vp->vref_count);
5770 spin_unlock_irqrestore(&ha->vport_slock, flags);
5771
Giridhar Malavalia9083012010-04-12 17:59:55 -07005772 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07005773
5774 spin_lock_irqsave(&ha->vport_slock, flags);
5775 atomic_dec(&vp->vref_count);
5776 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005777 }
Arun Easifeafb7b2010-09-03 14:57:00 -07005778 spin_unlock_irqrestore(&ha->vport_slock, flags);
5779
Giridhar Malavalia9083012010-04-12 17:59:55 -07005780 } else {
Chad Dupuiscfb09192011-11-18 09:03:07 -08005781 ql_log(ql_log_warn, vha, 0x8016,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005782 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005783 }
5784
5785 return status;
5786}
5787
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005788void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005789qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005790{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005791 struct qla_hw_data *ha = vha->hw;
5792
5793 if (!ql2xetsenable)
5794 return;
5795
5796 /* Enable ETS Burst. */
5797 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5798 ha->fw_options[2] |= BIT_9;
5799 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005800}
Sarang Radke09ff7012010-03-19 17:03:59 -07005801
5802/*
5803 * qla24xx_get_fcp_prio
5804 * Gets the fcp cmd priority value for the logged in port.
5805 * Looks for a match of the port descriptors within
5806 * each of the fcp prio config entries. If a match is found,
5807 * the tag (priority) value is returned.
5808 *
5809 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005810 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005811 * fcport = port structure pointer.
5812 *
5813 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005814 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005815 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005816 *
5817 * Context:
5818 * Kernel context
5819 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005820static int
Sarang Radke09ff7012010-03-19 17:03:59 -07005821qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5822{
5823 int i, entries;
5824 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005825 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005826 uint32_t pid1, pid2;
5827 uint64_t wwn1, wwn2;
5828 struct qla_fcp_prio_entry *pri_entry;
5829 struct qla_hw_data *ha = vha->hw;
5830
5831 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005832 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005833
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005834 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005835 entries = ha->fcp_prio_cfg->num_entries;
5836 pri_entry = &ha->fcp_prio_cfg->entry[0];
5837
5838 for (i = 0; i < entries; i++) {
5839 pid_match = wwn_match = 0;
5840
5841 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5842 pri_entry++;
5843 continue;
5844 }
5845
5846 /* check source pid for a match */
5847 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5848 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5849 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5850 if (pid1 == INVALID_PORT_ID)
5851 pid_match++;
5852 else if (pid1 == pid2)
5853 pid_match++;
5854 }
5855
5856 /* check destination pid for a match */
5857 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5858 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5859 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5860 if (pid1 == INVALID_PORT_ID)
5861 pid_match++;
5862 else if (pid1 == pid2)
5863 pid_match++;
5864 }
5865
5866 /* check source WWN for a match */
5867 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5868 wwn1 = wwn_to_u64(vha->port_name);
5869 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5870 if (wwn2 == (uint64_t)-1)
5871 wwn_match++;
5872 else if (wwn1 == wwn2)
5873 wwn_match++;
5874 }
5875
5876 /* check destination WWN for a match */
5877 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5878 wwn1 = wwn_to_u64(fcport->port_name);
5879 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5880 if (wwn2 == (uint64_t)-1)
5881 wwn_match++;
5882 else if (wwn1 == wwn2)
5883 wwn_match++;
5884 }
5885
5886 if (pid_match == 2 || wwn_match == 2) {
5887 /* Found a matching entry */
5888 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5889 priority = pri_entry->tag;
5890 break;
5891 }
5892
5893 pri_entry++;
5894 }
5895
5896 return priority;
5897}
5898
5899/*
5900 * qla24xx_update_fcport_fcp_prio
5901 * Activates fcp priority for the logged in fc port
5902 *
5903 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005904 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005905 * fcp = port structure pointer.
5906 *
5907 * Return:
5908 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5909 *
5910 * Context:
5911 * Kernel context.
5912 */
5913int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005914qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07005915{
5916 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005917 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005918 uint16_t mb[5];
5919
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005920 if (fcport->port_type != FCT_TARGET ||
5921 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07005922 return QLA_FUNCTION_FAILED;
5923
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005924 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005925 if (priority < 0)
5926 return QLA_FUNCTION_FAILED;
5927
Saurav Kashyapa00f6292011-11-18 09:03:19 -08005928 if (IS_QLA82XX(vha->hw)) {
5929 fcport->fcp_prio = priority & 0xf;
5930 return QLA_SUCCESS;
5931 }
5932
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005933 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Chad Dupuiscfb09192011-11-18 09:03:07 -08005934 if (ret == QLA_SUCCESS) {
5935 if (fcport->fcp_prio != priority)
5936 ql_dbg(ql_dbg_user, vha, 0x709e,
5937 "Updated FCP_CMND priority - value=%d loop_id=%d "
5938 "port_id=%02x%02x%02x.\n", priority,
5939 fcport->loop_id, fcport->d_id.b.domain,
5940 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Saurav Kashyapa00f6292011-11-18 09:03:19 -08005941 fcport->fcp_prio = priority & 0xf;
Chad Dupuiscfb09192011-11-18 09:03:07 -08005942 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005943 ql_dbg(ql_dbg_user, vha, 0x704f,
Chad Dupuiscfb09192011-11-18 09:03:07 -08005944 "Unable to update FCP_CMND priority - ret=0x%x for "
5945 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
5946 fcport->d_id.b.domain, fcport->d_id.b.area,
5947 fcport->d_id.b.al_pa);
Sarang Radke09ff7012010-03-19 17:03:59 -07005948 return ret;
5949}
5950
5951/*
5952 * qla24xx_update_all_fcp_prio
5953 * Activates fcp priority for all the logged in ports
5954 *
5955 * Input:
5956 * ha = adapter block pointer.
5957 *
5958 * Return:
5959 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5960 *
5961 * Context:
5962 * Kernel context.
5963 */
5964int
5965qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5966{
5967 int ret;
5968 fc_port_t *fcport;
5969
5970 ret = QLA_FUNCTION_FAILED;
5971 /* We need to set priority for all logged in ports */
5972 list_for_each_entry(fcport, &vha->vp_fcports, list)
5973 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5974
5975 return ret;
5976}