blob: 54ea68cec4c58c3cd0ee80c48bfaeb3f96e637d4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez07e264b2011-03-30 11:46:23 -07003 * Copyright (c) 2003-2011 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
Anirban Chakraborty73208df2008-12-09 16:45:39 -08008#include "qla_gbl.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Andrew Vasquez0107109e2005-07-06 10:31:37 -070012#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#include "qla_devtbl.h"
15
David Miller4e08df32007-04-16 12:37:43 -070016#ifdef CONFIG_SPARC
17#include <asm/prom.h>
David Miller4e08df32007-04-16 12:37:43 -070018#endif
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020/*
21* QLogic ISP2x00 Hardware Support Function Prototypes.
22*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070023static int qla2x00_isp_firmware(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static int qla2x00_setup_chip(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static int qla2x00_init_rings(scsi_qla_host_t *);
26static int qla2x00_fw_ready(scsi_qla_host_t *);
27static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028static int qla2x00_configure_loop(scsi_qla_host_t *);
29static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static int qla2x00_configure_fabric(scsi_qla_host_t *);
31static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
32static int qla2x00_device_resync(scsi_qla_host_t *);
33static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
34 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Harihara Kadayam4d4df192008-04-03 13:13:26 -070038static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
39static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080040static int qla25xx_init_queues(struct qla_hw_data *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070041
Andrew Vasquezac280b62009-08-20 11:06:05 -070042/* SRB Extensions ---------------------------------------------------------- */
43
44static void
45qla2x00_ctx_sp_timeout(unsigned long __data)
46{
47 srb_t *sp = (srb_t *)__data;
48 struct srb_ctx *ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070049 struct srb_iocb *iocb;
Andrew Vasquezac280b62009-08-20 11:06:05 -070050 fc_port_t *fcport = sp->fcport;
51 struct qla_hw_data *ha = fcport->vha->hw;
52 struct req_que *req;
53 unsigned long flags;
54
55 spin_lock_irqsave(&ha->hardware_lock, flags);
56 req = ha->req_q_map[0];
57 req->outstanding_cmds[sp->handle] = NULL;
58 ctx = sp->ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070059 iocb = ctx->u.iocb_cmd;
60 iocb->timeout(sp);
Madhuranath Iyengar49163922010-05-04 15:01:28 -070061 iocb->free(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
Andrew Vasquez3dbe7562010-07-23 15:28:37 +050065static void
Andrew Vasquezac280b62009-08-20 11:06:05 -070066qla2x00_ctx_sp_free(srb_t *sp)
67{
68 struct srb_ctx *ctx = sp->ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070069 struct srb_iocb *iocb = ctx->u.iocb_cmd;
Arun Easifeafb7b2010-09-03 14:57:00 -070070 struct scsi_qla_host *vha = sp->fcport->vha;
Andrew Vasquezac280b62009-08-20 11:06:05 -070071
Chad Dupuis4d97cc52010-10-15 11:27:41 -070072 del_timer(&iocb->timer);
Madhuranath Iyengar49163922010-05-04 15:01:28 -070073 kfree(iocb);
Andrew Vasquezac280b62009-08-20 11:06:05 -070074 kfree(ctx);
75 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
Arun Easifeafb7b2010-09-03 14:57:00 -070076
77 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquezac280b62009-08-20 11:06:05 -070078}
79
80inline srb_t *
81qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
82 unsigned long tmo)
83{
Arun Easifeafb7b2010-09-03 14:57:00 -070084 srb_t *sp = NULL;
Andrew Vasquezac280b62009-08-20 11:06:05 -070085 struct qla_hw_data *ha = vha->hw;
86 struct srb_ctx *ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070087 struct srb_iocb *iocb;
Arun Easifeafb7b2010-09-03 14:57:00 -070088 uint8_t bail;
89
90 QLA_VHA_MARK_BUSY(vha, bail);
91 if (bail)
92 return NULL;
Andrew Vasquezac280b62009-08-20 11:06:05 -070093
94 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
95 if (!sp)
96 goto done;
97 ctx = kzalloc(size, GFP_KERNEL);
98 if (!ctx) {
99 mempool_free(sp, ha->srb_mempool);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700100 sp = NULL;
101 goto done;
102 }
103 iocb = kzalloc(sizeof(struct srb_iocb), GFP_KERNEL);
104 if (!iocb) {
105 mempool_free(sp, ha->srb_mempool);
106 sp = NULL;
107 kfree(ctx);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700108 goto done;
109 }
110
111 memset(sp, 0, sizeof(*sp));
112 sp->fcport = fcport;
113 sp->ctx = ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700114 ctx->u.iocb_cmd = iocb;
115 iocb->free = qla2x00_ctx_sp_free;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700116
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700117 init_timer(&iocb->timer);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700118 if (!tmo)
119 goto done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700120 iocb->timer.expires = jiffies + tmo * HZ;
121 iocb->timer.data = (unsigned long)sp;
122 iocb->timer.function = qla2x00_ctx_sp_timeout;
123 add_timer(&iocb->timer);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700124done:
Arun Easifeafb7b2010-09-03 14:57:00 -0700125 if (!sp)
126 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700127 return sp;
128}
129
130/* Asynchronous Login/Logout Routines -------------------------------------- */
131
Andrew Vasquez5b914902010-05-28 15:08:30 -0700132static inline unsigned long
133qla2x00_get_async_timeout(struct scsi_qla_host *vha)
134{
135 unsigned long tmo;
136 struct qla_hw_data *ha = vha->hw;
137
138 /* Firmware should use switch negotiated r_a_tov for timeout. */
139 tmo = ha->r_a_tov / 10 * 2;
140 if (!IS_FWI2_CAPABLE(ha)) {
141 /*
142 * Except for earlier ISPs where the timeout is seeded from the
143 * initialization control block.
144 */
145 tmo = ha->login_timeout;
146 }
147 return tmo;
148}
Andrew Vasquezac280b62009-08-20 11:06:05 -0700149
150static void
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700151qla2x00_async_iocb_timeout(srb_t *sp)
Andrew Vasquezac280b62009-08-20 11:06:05 -0700152{
153 fc_port_t *fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700154 struct srb_ctx *ctx = sp->ctx;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700155
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700156 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
157 "Async-%s timeout - portid=%02x%02x%02x.\n",
158 ctx->name, fcport->d_id.b.domain, fcport->d_id.b.area,
159 fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700160
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700161 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700162 if (ctx->type == SRB_LOGIN_CMD) {
163 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700164 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700165 /* Retry as needed. */
166 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
167 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
168 QLA_LOGIO_LOGIN_RETRIED : 0;
169 qla2x00_post_async_login_done_work(fcport->vha, fcport,
170 lio->u.logio.data);
171 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700172}
173
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700174static void
175qla2x00_async_login_ctx_done(srb_t *sp)
176{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700177 struct srb_ctx *ctx = sp->ctx;
178 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700179
180 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700181 lio->u.logio.data);
182 lio->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700183}
184
Andrew Vasquezac280b62009-08-20 11:06:05 -0700185int
186qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
187 uint16_t *data)
188{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700189 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700190 struct srb_ctx *ctx;
191 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700192 int rval;
193
194 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700195 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700196 qla2x00_get_async_timeout(vha) + 2);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700197 if (!sp)
198 goto done;
199
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700200 ctx = sp->ctx;
201 ctx->type = SRB_LOGIN_CMD;
202 ctx->name = "login";
203 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700204 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700205 lio->done = qla2x00_async_login_ctx_done;
206 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700207 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700208 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700209 rval = qla2x00_start_sp(sp);
210 if (rval != QLA_SUCCESS)
211 goto done_free_sp;
212
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700213 ql_dbg(ql_dbg_disc, vha, 0x2072,
214 "Async-login - loopid=%x portid=%02x%02x%02x retries=%d.\n",
215 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
216 fcport->d_id.b.al_pa, fcport->login_retry);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700217 return rval;
218
219done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700220 lio->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700221done:
222 return rval;
223}
224
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700225static void
226qla2x00_async_logout_ctx_done(srb_t *sp)
227{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700228 struct srb_ctx *ctx = sp->ctx;
229 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700230
231 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700232 lio->u.logio.data);
233 lio->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700234}
235
Andrew Vasquezac280b62009-08-20 11:06:05 -0700236int
237qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
238{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700239 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700240 struct srb_ctx *ctx;
241 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700242 int rval;
243
244 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700245 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700246 qla2x00_get_async_timeout(vha) + 2);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700247 if (!sp)
248 goto done;
249
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700250 ctx = sp->ctx;
251 ctx->type = SRB_LOGOUT_CMD;
252 ctx->name = "logout";
253 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700254 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700255 lio->done = qla2x00_async_logout_ctx_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700256 rval = qla2x00_start_sp(sp);
257 if (rval != QLA_SUCCESS)
258 goto done_free_sp;
259
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700260 ql_dbg(ql_dbg_disc, vha, 0x2070,
261 "Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
262 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
263 fcport->d_id.b.al_pa);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700264 return rval;
265
266done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700267 lio->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700268done:
269 return rval;
270}
271
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700272static void
273qla2x00_async_adisc_ctx_done(srb_t *sp)
274{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700275 struct srb_ctx *ctx = sp->ctx;
276 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700277
278 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700279 lio->u.logio.data);
280 lio->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700281}
282
283int
284qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
285 uint16_t *data)
286{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700287 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700288 struct srb_ctx *ctx;
289 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700290 int rval;
291
292 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700293 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700294 qla2x00_get_async_timeout(vha) + 2);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700295 if (!sp)
296 goto done;
297
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700298 ctx = sp->ctx;
299 ctx->type = SRB_ADISC_CMD;
300 ctx->name = "adisc";
301 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700302 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700303 lio->done = qla2x00_async_adisc_ctx_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700304 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700305 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700306 rval = qla2x00_start_sp(sp);
307 if (rval != QLA_SUCCESS)
308 goto done_free_sp;
309
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700310 ql_dbg(ql_dbg_disc, vha, 0x206f,
311 "Async-adisc - loopid=%x portid=%02x%02x%02x.\n",
312 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
313 fcport->d_id.b.al_pa);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700314 return rval;
315
316done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700317 lio->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700318done:
319 return rval;
320}
321
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700322static void
323qla2x00_async_tm_cmd_ctx_done(srb_t *sp)
324{
325 struct srb_ctx *ctx = sp->ctx;
326 struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd;
327
328 qla2x00_async_tm_cmd_done(sp->fcport->vha, sp->fcport, iocb);
329 iocb->free(sp);
330}
331
332int
333qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
334 uint32_t tag)
335{
336 struct scsi_qla_host *vha = fcport->vha;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700337 srb_t *sp;
338 struct srb_ctx *ctx;
339 struct srb_iocb *tcf;
340 int rval;
341
342 rval = QLA_FUNCTION_FAILED;
343 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700344 qla2x00_get_async_timeout(vha) + 2);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700345 if (!sp)
346 goto done;
347
348 ctx = sp->ctx;
349 ctx->type = SRB_TM_CMD;
350 ctx->name = "tmf";
351 tcf = ctx->u.iocb_cmd;
352 tcf->u.tmf.flags = flags;
353 tcf->u.tmf.lun = lun;
354 tcf->u.tmf.data = tag;
355 tcf->timeout = qla2x00_async_iocb_timeout;
356 tcf->done = qla2x00_async_tm_cmd_ctx_done;
357
358 rval = qla2x00_start_sp(sp);
359 if (rval != QLA_SUCCESS)
360 goto done_free_sp;
361
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700362 ql_dbg(ql_dbg_taskm, vha, 0x802f,
363 "Async-tmf loop-id=%x portid=%02x%02x%02x.\n",
364 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
365 fcport->d_id.b.al_pa);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700366 return rval;
367
368done_free_sp:
369 tcf->free(sp);
370done:
371 return rval;
372}
373
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700374void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700375qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
376 uint16_t *data)
377{
378 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700379
380 switch (data[0]) {
381 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700382 /*
383 * Driver must validate login state - If PRLI not complete,
384 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
385 * requests.
386 */
387 rval = qla2x00_get_port_database(vha, fcport, 0);
388 if (rval != QLA_SUCCESS) {
389 qla2x00_post_async_logout_work(vha, fcport, NULL);
390 qla2x00_post_async_login_work(vha, fcport, NULL);
391 break;
392 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700393 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700394 qla2x00_post_async_adisc_work(vha, fcport, data);
395 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700396 }
397 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700398 break;
399 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700400 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700401 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
402 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
403 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700404 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700405 break;
406 case MBS_PORT_ID_USED:
407 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700408 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700409 qla2x00_post_async_login_work(vha, fcport, NULL);
410 break;
411 case MBS_LOOP_ID_USED:
412 fcport->loop_id++;
413 rval = qla2x00_find_new_loop_id(vha, fcport);
414 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700415 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez80d79442011-03-30 11:46:17 -0700416 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700417 break;
418 }
419 qla2x00_post_async_login_work(vha, fcport, NULL);
420 break;
421 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700422 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700423}
424
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700425void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700426qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
427 uint16_t *data)
428{
429 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700430 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700431}
432
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700433void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700434qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
435 uint16_t *data)
436{
437 if (data[0] == MBS_COMMAND_COMPLETE) {
438 qla2x00_update_fcport(vha, fcport);
439
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700440 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700441 }
442
443 /* Retry login. */
444 fcport->flags &= ~FCF_ASYNC_SENT;
445 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
446 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
447 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700448 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700449
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700450 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700451}
452
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700453void
454qla2x00_async_tm_cmd_done(struct scsi_qla_host *vha, fc_port_t *fcport,
455 struct srb_iocb *iocb)
456{
457 int rval;
458 uint32_t flags;
459 uint16_t lun;
460
461 flags = iocb->u.tmf.flags;
462 lun = (uint16_t)iocb->u.tmf.lun;
463
464 /* Issue Marker IOCB */
Giridhar Malavalid94d10e2010-07-23 15:28:23 +0500465 rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
466 vha->hw->rsp_q_map[0], fcport->loop_id, lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700467 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
468
469 if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700470 ql_dbg(ql_dbg_taskm, vha, 0x8030,
471 "TM IOCB failed (%x).\n", rval);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700472 }
473
474 return;
475}
476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477/****************************************************************************/
478/* QLogic ISP2x00 Hardware Support Functions. */
479/****************************************************************************/
480
481/*
482* qla2x00_initialize_adapter
483* Initialize board.
484*
485* Input:
486* ha = adapter block pointer.
487*
488* Returns:
489* 0 = success
490*/
491int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800492qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
494 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800495 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800496 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800499 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700500 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800501 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800502 ha->flags.pci_channel_io_perm_failure = 0;
503 ha->flags.eeh_busy = 0;
Andrew Vasquez794a5692010-12-21 16:00:21 -0800504 ha->flags.thermal_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800505 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
506 atomic_set(&vha->loop_state, LOOP_DOWN);
507 vha->device_flags = DFLG_NO_CABLE;
508 vha->dpc_flags = 0;
509 vha->flags.management_server_logged_in = 0;
510 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 ha->isp_abort_cnt = 0;
512 ha->beacon_blink_led = 0;
513
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800514 set_bit(0, ha->req_qid_map);
515 set_bit(0, ha->rsp_qid_map);
516
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700517 ql_log(ql_log_info, vha, 0x0040,
518 "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800519 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700521 ql_log(ql_log_warn, vha, 0x0044,
522 "Unable to configure PCI space.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 return (rval);
524 }
525
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800526 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800528 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700529 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700530 ql_log(ql_log_fatal, vha, 0x004f,
531 "Unable to validate FLASH data.\n");
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700532 return (rval);
533 }
534
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800535 ha->isp_ops->get_flash_version(vha, req->ring);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700536 ql_log(ql_log_info, vha, 0x0061,
537 "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700538
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800539 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700541 if (ha->flags.disable_serdes) {
542 /* Mask HBA via NVRAM settings? */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700543 ql_log(ql_log_info, vha, 0x0077,
544 "Masking HBA WWPN "
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700545 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800546 vha->port_name[0], vha->port_name[1],
547 vha->port_name[2], vha->port_name[3],
548 vha->port_name[4], vha->port_name[5],
549 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700550 return QLA_FUNCTION_FAILED;
551 }
552
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700553 ql_log(ql_log_info, vha, 0x0078,
554 "Verifying loaded RISC code...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800556 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
557 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800558 if (rval)
559 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800560 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800561 if (rval)
562 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700564
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700565 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800566 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700567 if (!ha->cs84xx) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700568 ql_log(ql_log_warn, vha, 0x00d0,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700569 "Unable to configure ISP84XX.\n");
570 return QLA_FUNCTION_FAILED;
571 }
572 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800573 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700574 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800576 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700577 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800578 rval = qla84xx_init_chip(vha);
579 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700580 ql_log(ql_log_warn, vha, 0x00d4,
581 "Unable to initialize ISP84XX.\n");
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800582 qla84xx_put_chip(vha);
583 }
584 }
585
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500586 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
587 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700588
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 return (rval);
590}
591
592/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700593 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 * @ha: HA context
595 *
596 * Returns 0 on success.
597 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700598int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800599qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700601 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700602 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800603 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700604 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700607 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700610 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
612
Andrew Vasquez737faec2008-10-24 15:13:45 -0700613 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700615 /* Get PCI bus information. */
616 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700617 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700618 spin_unlock_irqrestore(&ha->hardware_lock, flags);
619
620 return QLA_SUCCESS;
621}
622
623/**
624 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
625 * @ha: HA context
626 *
627 * Returns 0 on success.
628 */
629int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800630qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700631{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700632 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700633 unsigned long flags = 0;
634 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800635 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700636 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700637
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700638 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700639 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700640
641 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700642 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700643
644 if (IS_QLA2322(ha) || IS_QLA6322(ha))
645 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700646 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700647
648 /*
649 * If this is a 2300 card and not 2312, reset the
650 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
651 * the 2310 also reports itself as a 2300 so we need to get the
652 * fb revision level -- a 6 indicates it really is a 2300 and
653 * not a 2310.
654 */
655 if (IS_QLA2300(ha)) {
656 spin_lock_irqsave(&ha->hardware_lock, flags);
657
658 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700659 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700660 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700661 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700662 break;
663
664 udelay(10);
665 }
666
667 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700668 WRT_REG_WORD(&reg->ctrl_status, 0x20);
669 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700670
671 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700672 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700673
674 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700675 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700676
677 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700678 WRT_REG_WORD(&reg->ctrl_status, 0x0);
679 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700680
681 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700682 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700683 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700684 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700685 break;
686
687 udelay(10);
688 }
689
690 spin_unlock_irqrestore(&ha->hardware_lock, flags);
691 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700692
693 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
694
Andrew Vasquez737faec2008-10-24 15:13:45 -0700695 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700696
697 /* Get PCI bus information. */
698 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700699 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700700 spin_unlock_irqrestore(&ha->hardware_lock, flags);
701
702 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703}
704
705/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700706 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
707 * @ha: HA context
708 *
709 * Returns 0 on success.
710 */
711int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800712qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700713{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700714 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700715 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800716 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700717 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700718
719 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700720 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700721
722 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700723 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700724 w &= ~PCI_COMMAND_INTX_DISABLE;
725 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
726
727 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
728
729 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700730 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
731 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700732
733 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700734 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
735 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700736
Andrew Vasquez737faec2008-10-24 15:13:45 -0700737 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700738
Auke Kok44c10132007-06-08 15:46:36 -0700739 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800740
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700741 /* Get PCI bus information. */
742 spin_lock_irqsave(&ha->hardware_lock, flags);
743 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
744 spin_unlock_irqrestore(&ha->hardware_lock, flags);
745
746 return QLA_SUCCESS;
747}
748
749/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700750 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
751 * @ha: HA context
752 *
753 * Returns 0 on success.
754 */
755int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800756qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700757{
758 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800759 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700760
761 pci_set_master(ha->pdev);
762 pci_try_set_mwi(ha->pdev);
763
764 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
765 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
766 w &= ~PCI_COMMAND_INTX_DISABLE;
767 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
768
769 /* PCIe -- adjust Maximum Read Request Size (2048). */
770 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
771 pcie_set_readrq(ha->pdev, 2048);
772
Andrew Vasquez737faec2008-10-24 15:13:45 -0700773 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700774
775 ha->chip_revision = ha->pdev->revision;
776
777 return QLA_SUCCESS;
778}
779
780/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 * qla2x00_isp_firmware() - Choose firmware image.
782 * @ha: HA context
783 *
784 * Returns 0 on success.
785 */
786static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800787qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788{
789 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700790 uint16_t loop_id, topo, sw_cap;
791 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800792 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700795 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 if (ha->flags.disable_risc_code_load) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700798 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
800 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800801 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700802 if (rval == QLA_SUCCESS) {
803 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800804 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700805 &area, &domain, &topo, &sw_cap);
806 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 }
808
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700809 if (rval)
810 ql_dbg(ql_dbg_init, vha, 0x007a,
811 "**** Load RISC code ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 return (rval);
814}
815
816/**
817 * qla2x00_reset_chip() - Reset ISP chip.
818 * @ha: HA context
819 *
820 * Returns 0 on success.
821 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700822void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800823qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824{
825 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800826 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700827 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 uint16_t cmd;
830
Andrew Vasquez85880802009-12-15 21:29:46 -0800831 if (unlikely(pci_channel_offline(ha->pdev)))
832 return;
833
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700834 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836 spin_lock_irqsave(&ha->hardware_lock, flags);
837
838 /* Turn off master enable */
839 cmd = 0;
840 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
841 cmd &= ~PCI_COMMAND_MASTER;
842 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
843
844 if (!IS_QLA2100(ha)) {
845 /* Pause RISC. */
846 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
847 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
848 for (cnt = 0; cnt < 30000; cnt++) {
849 if ((RD_REG_WORD(&reg->hccr) &
850 HCCR_RISC_PAUSE) != 0)
851 break;
852 udelay(100);
853 }
854 } else {
855 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
856 udelay(10);
857 }
858
859 /* Select FPM registers. */
860 WRT_REG_WORD(&reg->ctrl_status, 0x20);
861 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
862
863 /* FPM Soft Reset. */
864 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
865 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
866
867 /* Toggle Fpm Reset. */
868 if (!IS_QLA2200(ha)) {
869 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
870 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
871 }
872
873 /* Select frame buffer registers. */
874 WRT_REG_WORD(&reg->ctrl_status, 0x10);
875 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
876
877 /* Reset frame buffer FIFOs. */
878 if (IS_QLA2200(ha)) {
879 WRT_FB_CMD_REG(ha, reg, 0xa000);
880 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
881 } else {
882 WRT_FB_CMD_REG(ha, reg, 0x00fc);
883
884 /* Read back fb_cmd until zero or 3 seconds max */
885 for (cnt = 0; cnt < 3000; cnt++) {
886 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
887 break;
888 udelay(100);
889 }
890 }
891
892 /* Select RISC module registers. */
893 WRT_REG_WORD(&reg->ctrl_status, 0);
894 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
895
896 /* Reset RISC processor. */
897 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
898 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
899
900 /* Release RISC processor. */
901 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
902 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
903 }
904
905 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
906 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
907
908 /* Reset ISP chip. */
909 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
910
911 /* Wait for RISC to recover from reset. */
912 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
913 /*
914 * It is necessary to for a delay here since the card doesn't
915 * respond to PCI reads during a reset. On some architectures
916 * this will result in an MCA.
917 */
918 udelay(20);
919 for (cnt = 30000; cnt; cnt--) {
920 if ((RD_REG_WORD(&reg->ctrl_status) &
921 CSR_ISP_SOFT_RESET) == 0)
922 break;
923 udelay(100);
924 }
925 } else
926 udelay(10);
927
928 /* Reset RISC processor. */
929 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
930
931 WRT_REG_WORD(&reg->semaphore, 0);
932
933 /* Release RISC processor. */
934 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
935 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
936
937 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
938 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700939 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
942 udelay(100);
943 }
944 } else
945 udelay(100);
946
947 /* Turn on master enable */
948 cmd |= PCI_COMMAND_MASTER;
949 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
950
951 /* Disable RISC pause on FPM parity error. */
952 if (!IS_QLA2100(ha)) {
953 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
954 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
955 }
956
957 spin_unlock_irqrestore(&ha->hardware_lock, flags);
958}
959
960/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700961 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
962 *
963 * Returns 0 on success.
964 */
965int
966qla81xx_reset_mpi(scsi_qla_host_t *vha)
967{
968 uint16_t mb[4] = {0x1010, 0, 1, 0};
969
970 return qla81xx_write_mpi_register(vha, mb);
971}
972
973/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700974 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700975 * @ha: HA context
976 *
977 * Returns 0 on success.
978 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700979static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800980qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700981{
982 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800983 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700984 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
985 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800986 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700987 static int abts_cnt; /* ISP abort retry counts */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700988
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700989 spin_lock_irqsave(&ha->hardware_lock, flags);
990
991 /* Reset RISC. */
992 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
993 for (cnt = 0; cnt < 30000; cnt++) {
994 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
995 break;
996
997 udelay(10);
998 }
999
1000 WRT_REG_DWORD(&reg->ctrl_status,
1001 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001002 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001003
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001004 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001005 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001006 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1007 for (cnt = 10000 ; cnt && d2; cnt--) {
1008 udelay(5);
1009 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1010 barrier();
1011 }
1012
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001013 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001014 d2 = RD_REG_DWORD(&reg->ctrl_status);
1015 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1016 udelay(5);
1017 d2 = RD_REG_DWORD(&reg->ctrl_status);
1018 barrier();
1019 }
1020
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001021 /* If required, do an MPI FW reset now */
1022 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1023 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1024 if (++abts_cnt < 5) {
1025 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1026 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1027 } else {
1028 /*
1029 * We exhausted the ISP abort retries. We have to
1030 * set the board offline.
1031 */
1032 abts_cnt = 0;
1033 vha->flags.online = 0;
1034 }
1035 }
1036 }
1037
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001038 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1039 RD_REG_DWORD(&reg->hccr);
1040
1041 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1042 RD_REG_DWORD(&reg->hccr);
1043
1044 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1045 RD_REG_DWORD(&reg->hccr);
1046
1047 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1048 for (cnt = 6000000 ; cnt && d2; cnt--) {
1049 udelay(5);
1050 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1051 barrier();
1052 }
1053
1054 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001055
1056 if (IS_NOPOLLING_TYPE(ha))
1057 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001058}
1059
1060/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001061 * qla24xx_reset_chip() - Reset ISP24xx chip.
1062 * @ha: HA context
1063 *
1064 * Returns 0 on success.
1065 */
1066void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001067qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001068{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001069 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001070
1071 if (pci_channel_offline(ha->pdev) &&
1072 ha->flags.pci_channel_io_perm_failure) {
1073 return;
1074 }
1075
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001076 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001077
1078 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001079 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001080}
1081
1082/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 * qla2x00_chip_diag() - Test chip for proper operation.
1084 * @ha: HA context
1085 *
1086 * Returns 0 on success.
1087 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001088int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001089qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090{
1091 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001092 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001093 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 unsigned long flags = 0;
1095 uint16_t data;
1096 uint32_t cnt;
1097 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001098 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
1100 /* Assume a failed state */
1101 rval = QLA_FUNCTION_FAILED;
1102
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001103 ql_dbg(ql_dbg_init, vha, 0x007b,
1104 "Testing device at %lx.\n", (u_long)&reg->flash_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
1106 spin_lock_irqsave(&ha->hardware_lock, flags);
1107
1108 /* Reset ISP chip. */
1109 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1110
1111 /*
1112 * We need to have a delay here since the card will not respond while
1113 * in reset causing an MCA on some architectures.
1114 */
1115 udelay(20);
1116 data = qla2x00_debounce_register(&reg->ctrl_status);
1117 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1118 udelay(5);
1119 data = RD_REG_WORD(&reg->ctrl_status);
1120 barrier();
1121 }
1122
1123 if (!cnt)
1124 goto chip_diag_failed;
1125
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001126 ql_dbg(ql_dbg_init, vha, 0x007c,
1127 "Reset register cleared by chip reset.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
1129 /* Reset RISC processor. */
1130 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1131 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1132
1133 /* Workaround for QLA2312 PCI parity error */
1134 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1135 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1136 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1137 udelay(5);
1138 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001139 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 }
1141 } else
1142 udelay(10);
1143
1144 if (!cnt)
1145 goto chip_diag_failed;
1146
1147 /* Check product ID of chip */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001148 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
1150 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1151 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1152 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1153 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1154 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1155 mb[3] != PROD_ID_3) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001156 ql_log(ql_log_warn, vha, 0x0062,
1157 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1158 mb[1], mb[2], mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
1160 goto chip_diag_failed;
1161 }
1162 ha->product_id[0] = mb[1];
1163 ha->product_id[1] = mb[2];
1164 ha->product_id[2] = mb[3];
1165 ha->product_id[3] = mb[4];
1166
1167 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001168 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1170 else
1171 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001172 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
1174 if (IS_QLA2200(ha) &&
1175 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1176 /* Limit firmware transfer size with a 2200A */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001177 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001179 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 ha->fw_transfer_size = 128;
1181 }
1182
1183 /* Wrap Incoming Mailboxes Test. */
1184 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1185
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001186 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001187 rval = qla2x00_mbx_reg_test(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001188 if (rval)
1189 ql_log(ql_log_warn, vha, 0x0080,
1190 "Failed mailbox send register test.\n");
1191 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 /* Flag a successful rval */
1193 rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 spin_lock_irqsave(&ha->hardware_lock, flags);
1195
1196chip_diag_failed:
1197 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001198 ql_log(ql_log_info, vha, 0x0081,
1199 "Chip diagnostics **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
1201 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1202
1203 return (rval);
1204}
1205
1206/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001207 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1208 * @ha: HA context
1209 *
1210 * Returns 0 on success.
1211 */
1212int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001213qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001214{
1215 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001216 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001217 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001218
Giridhar Malavalia9083012010-04-12 17:59:55 -07001219 if (IS_QLA82XX(ha))
1220 return QLA_SUCCESS;
1221
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001222 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001223
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001224 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001225 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001226 ql_log(ql_log_warn, vha, 0x0082,
1227 "Failed mailbox send register test.\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001228 } else {
1229 /* Flag a successful rval */
1230 rval = QLA_SUCCESS;
1231 }
1232
1233 return rval;
1234}
1235
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001236void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001237qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001238{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001239 int rval;
1240 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001241 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001242 dma_addr_t tc_dma;
1243 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001244 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001245 struct req_que *req = ha->req_q_map[0];
1246 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001247
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001248 if (ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001249 ql_dbg(ql_dbg_init, vha, 0x00bd,
1250 "Firmware dump already allocated.\n");
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001251 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001252 }
1253
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001254 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001255 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001256 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1257 fixed_size = sizeof(struct qla2100_fw_dump);
1258 } else if (IS_QLA23XX(ha)) {
1259 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1260 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1261 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001262 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001263 if (IS_QLA81XX(ha))
1264 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1265 else if (IS_QLA25XX(ha))
1266 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1267 else
1268 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001269 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1270 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001271 if (ha->mqenable)
1272 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001273 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001274 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001275 goto try_eft;
1276
1277 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1278 GFP_KERNEL);
1279 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001280 ql_log(ql_log_warn, vha, 0x00be,
1281 "Unable to allocate (%d KB) for FCE.\n",
1282 FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001283 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001284 }
1285
1286 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001287 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001288 ha->fce_mb, &ha->fce_bufs);
1289 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001290 ql_log(ql_log_warn, vha, 0x00bf,
1291 "Unable to initialize FCE (%d).\n", rval);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001292 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1293 tc_dma);
1294 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001295 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001296 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001297 ql_log(ql_log_info, vha, 0x00c0,
1298 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001299
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001300 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001301 ha->flags.fce_enabled = 1;
1302 ha->fce_dma = tc_dma;
1303 ha->fce = tc;
1304try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001305 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001306 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001307 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001308 if (!tc) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001309 ql_log(ql_log_warn, vha, 0x00c1,
1310 "Unable to allocate (%d KB) for EFT.\n",
1311 EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001312 goto cont_alloc;
1313 }
1314
Andrew Vasquezfc447652008-01-17 09:02:18 -08001315 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001316 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001317 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001318 ql_log(ql_log_warn, vha, 0x00c2,
1319 "Unable to initialize EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001320 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1321 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001322 goto cont_alloc;
1323 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001324 ql_log(ql_log_info, vha, 0x00c3,
1325 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001326
1327 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001328 ha->eft_dma = tc_dma;
1329 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001330 }
1331cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001332 req_q_size = req->length * sizeof(request_t);
1333 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001334
1335 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001336 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001337 ha->chain_offset = dump_size;
1338 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001339
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001340 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001341 if (!ha->fw_dump) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001342 ql_log(ql_log_warn, vha, 0x00c4,
1343 "Unable to allocate (%d KB) for firmware dump.\n",
1344 dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001345
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001346 if (ha->fce) {
1347 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1348 ha->fce_dma);
1349 ha->fce = NULL;
1350 ha->fce_dma = 0;
1351 }
1352
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001353 if (ha->eft) {
1354 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1355 ha->eft_dma);
1356 ha->eft = NULL;
1357 ha->eft_dma = 0;
1358 }
1359 return;
1360 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001361 ql_log(ql_log_info, vha, 0x00c5,
1362 "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001363
1364 ha->fw_dump_len = dump_size;
1365 ha->fw_dump->signature[0] = 'Q';
1366 ha->fw_dump->signature[1] = 'L';
1367 ha->fw_dump->signature[2] = 'G';
1368 ha->fw_dump->signature[3] = 'C';
1369 ha->fw_dump->version = __constant_htonl(1);
1370
1371 ha->fw_dump->fixed_size = htonl(fixed_size);
1372 ha->fw_dump->mem_size = htonl(mem_size);
1373 ha->fw_dump->req_q_size = htonl(req_q_size);
1374 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1375
1376 ha->fw_dump->eft_size = htonl(eft_size);
1377 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1378 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1379
1380 ha->fw_dump->header_size =
1381 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001382}
1383
Andrew Vasquez18e75552009-06-03 09:55:30 -07001384static int
1385qla81xx_mpi_sync(scsi_qla_host_t *vha)
1386{
1387#define MPS_MASK 0xe0
1388 int rval;
1389 uint16_t dc;
1390 uint32_t dw;
Andrew Vasquez18e75552009-06-03 09:55:30 -07001391
1392 if (!IS_QLA81XX(vha->hw))
1393 return QLA_SUCCESS;
1394
1395 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1396 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001397 ql_log(ql_log_warn, vha, 0x0105,
1398 "Unable to acquire semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001399 goto done;
1400 }
1401
1402 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1403 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1404 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001405 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001406 goto done_release;
1407 }
1408
1409 dc &= MPS_MASK;
1410 if (dc == (dw & MPS_MASK))
1411 goto done_release;
1412
1413 dw &= ~MPS_MASK;
1414 dw |= dc;
1415 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1416 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001417 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001418 }
1419
1420done_release:
1421 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1422 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001423 ql_log(ql_log_warn, vha, 0x006d,
1424 "Unable to release semaphore.\n");
Andrew Vasquez18e75552009-06-03 09:55:30 -07001425 }
1426
1427done:
1428 return rval;
1429}
1430
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001431/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 * qla2x00_setup_chip() - Load and start RISC firmware.
1433 * @ha: HA context
1434 *
1435 * Returns 0 on success.
1436 */
1437static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001438qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001440 int rval;
1441 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001442 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001443 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1444 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001445 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001446
Giridhar Malavalia9083012010-04-12 17:59:55 -07001447 if (IS_QLA82XX(ha)) {
1448 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001449 if (rval == QLA_SUCCESS) {
1450 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001451 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001452 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001453 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001454 }
1455
Andrew Vasquez3db06522008-01-31 12:33:49 -08001456 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1457 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1458 spin_lock_irqsave(&ha->hardware_lock, flags);
1459 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1460 RD_REG_WORD(&reg->hccr);
1461 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1462 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
Andrew Vasquez18e75552009-06-03 09:55:30 -07001464 qla81xx_mpi_sync(vha);
1465
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001467 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001468 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001469 ql_dbg(ql_dbg_init, vha, 0x00c9,
1470 "Verifying Checksum of loaded RISC code.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001472 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 if (rval == QLA_SUCCESS) {
1474 /* Start firmware execution. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001475 ql_dbg(ql_dbg_init, vha, 0x00ca,
1476 "Starting firmware.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001478 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001480 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001481enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001482 fw_major_version = ha->fw_major_version;
Giridhar Malavali31731672011-08-16 11:31:54 -07001483 if (IS_QLA82XX(ha))
1484 qla82xx_check_md_needed(vha);
1485 else {
1486 rval = qla2x00_get_fw_version(vha,
1487 &ha->fw_major_version,
1488 &ha->fw_minor_version,
1489 &ha->fw_subminor_version,
1490 &ha->fw_attributes,
1491 &ha->fw_memory_size,
1492 ha->mpi_version,
1493 &ha->mpi_capabilities,
1494 ha->phy_version);
1495 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001496 if (rval != QLA_SUCCESS)
1497 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001498 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001499 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001500 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001501 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001502 if ((!ha->max_npiv_vports) ||
1503 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001504 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001505 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001506 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001507 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001508 qla2x00_get_resource_cnts(vha, NULL,
1509 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001510 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001511
Saurav Kashyapbe5ea3c2011-11-18 09:02:11 -08001512 if (!fw_major_version && ql2xallocfwdump
1513 && !IS_QLA82XX(ha))
Giridhar Malavali08de2842011-08-16 11:31:44 -07001514 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 }
1516 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001517 ql_log(ql_log_fatal, vha, 0x00cd,
1518 "ISP Firmware failed checksum.\n");
1519 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 }
1521 }
1522
Andrew Vasquez3db06522008-01-31 12:33:49 -08001523 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1524 /* Enable proper parity. */
1525 spin_lock_irqsave(&ha->hardware_lock, flags);
1526 if (IS_QLA2300(ha))
1527 /* SRAM parity */
1528 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1529 else
1530 /* SRAM, Instruction RAM and GP RAM parity */
1531 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1532 RD_REG_WORD(&reg->hccr);
1533 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1534 }
1535
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001536 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1537 uint32_t size;
1538
1539 rval = qla81xx_fac_get_sector_size(vha, &size);
1540 if (rval == QLA_SUCCESS) {
1541 ha->flags.fac_supported = 1;
1542 ha->fdt_block_size = size << 2;
1543 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001544 ql_log(ql_log_warn, vha, 0x00ce,
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001545 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1546 ha->fw_major_version, ha->fw_minor_version,
1547 ha->fw_subminor_version);
1548 }
1549 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001550failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001552 ql_log(ql_log_fatal, vha, 0x00cf,
1553 "Setup chip ****FAILED****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 }
1555
1556 return (rval);
1557}
1558
1559/**
1560 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1561 * @ha: HA context
1562 *
1563 * Beginning of request ring has initialization control block already built
1564 * by nvram config routine.
1565 *
1566 * Returns 0 on success.
1567 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001568void
1569qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570{
1571 uint16_t cnt;
1572 response_t *pkt;
1573
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001574 rsp->ring_ptr = rsp->ring;
1575 rsp->ring_index = 0;
1576 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001577 pkt = rsp->ring_ptr;
1578 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 pkt->signature = RESPONSE_PROCESSED;
1580 pkt++;
1581 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582}
1583
1584/**
1585 * qla2x00_update_fw_options() - Read and process firmware options.
1586 * @ha: HA context
1587 *
1588 * Returns 0 on success.
1589 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001590void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001591qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592{
1593 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001594 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
1596 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001597 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598
1599 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1600 return;
1601
1602 /* Serial Link options. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001603 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
1604 "Serial link options.\n");
1605 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
1606 (uint8_t *)&ha->fw_seriallink_options,
1607 sizeof(ha->fw_seriallink_options));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
1609 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1610 if (ha->fw_seriallink_options[3] & BIT_2) {
1611 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1612
1613 /* 1G settings */
1614 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1615 emphasis = (ha->fw_seriallink_options[2] &
1616 (BIT_4 | BIT_3)) >> 3;
1617 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001618 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 rx_sens = (ha->fw_seriallink_options[0] &
1620 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1621 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1622 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1623 if (rx_sens == 0x0)
1624 rx_sens = 0x3;
1625 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1626 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1627 ha->fw_options[10] |= BIT_5 |
1628 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1629 (tx_sens & (BIT_1 | BIT_0));
1630
1631 /* 2G settings */
1632 swing = (ha->fw_seriallink_options[2] &
1633 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1634 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1635 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001636 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 rx_sens = (ha->fw_seriallink_options[1] &
1638 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1639 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1640 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1641 if (rx_sens == 0x0)
1642 rx_sens = 0x3;
1643 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1644 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1645 ha->fw_options[11] |= BIT_5 |
1646 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1647 (tx_sens & (BIT_1 | BIT_0));
1648 }
1649
1650 /* FCP2 options. */
1651 /* Return command IOCBs without waiting for an ABTS to complete. */
1652 ha->fw_options[3] |= BIT_13;
1653
1654 /* LED scheme. */
1655 if (ha->flags.enable_led_scheme)
1656 ha->fw_options[2] |= BIT_12;
1657
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001658 /* Detect ISP6312. */
1659 if (IS_QLA6312(ha))
1660 ha->fw_options[2] |= BIT_13;
1661
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001663 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664}
1665
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001666void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001667qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001668{
1669 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001670 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001671
Giridhar Malavalia9083012010-04-12 17:59:55 -07001672 if (IS_QLA82XX(ha))
1673 return;
1674
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001675 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001676 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001677 return;
1678
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001679 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001680 le16_to_cpu(ha->fw_seriallink_options24[1]),
1681 le16_to_cpu(ha->fw_seriallink_options24[2]),
1682 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001683 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001684 ql_log(ql_log_warn, vha, 0x0104,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001685 "Unable to update Serial Link options (%x).\n", rval);
1686 }
1687}
1688
1689void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001690qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001691{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001692 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001693 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001694 struct req_que *req = ha->req_q_map[0];
1695 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001696
1697 /* Setup ring parameters in initialization control block. */
1698 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1699 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001700 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1701 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1702 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1703 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1704 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1705 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001706
1707 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1708 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1709 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1710 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1711 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1712}
1713
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001714void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001715qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001716{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001717 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001718 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1719 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1720 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001721 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001722 uint16_t rid = 0;
1723 struct req_que *req = ha->req_q_map[0];
1724 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001725
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001726/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001727 icb = (struct init_cb_24xx *)ha->init_cb;
1728 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1729 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001730 icb->request_q_length = cpu_to_le16(req->length);
1731 icb->response_q_length = cpu_to_le16(rsp->length);
1732 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1733 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1734 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1735 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001736
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001737 if (ha->mqenable) {
1738 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1739 icb->rid = __constant_cpu_to_le16(rid);
1740 if (ha->flags.msix_enabled) {
1741 msix = &ha->msix_entries[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001742 ql_dbg(ql_dbg_init, vha, 0x00fd,
1743 "Registering vector 0x%x for base que.\n",
1744 msix->entry);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001745 icb->msix = cpu_to_le16(msix->entry);
1746 }
1747 /* Use alternate PCI bus number */
1748 if (MSB(rid))
1749 icb->firmware_options_2 |=
1750 __constant_cpu_to_le32(BIT_19);
1751 /* Use alternate PCI devfn */
1752 if (LSB(rid))
1753 icb->firmware_options_2 |=
1754 __constant_cpu_to_le32(BIT_18);
1755
Anirban Chakraborty31557542009-12-02 10:36:55 -08001756 /* Use Disable MSIX Handshake mode for capable adapters */
1757 if (IS_MSIX_NACK_CAPABLE(ha)) {
1758 icb->firmware_options_2 &=
1759 __constant_cpu_to_le32(~BIT_22);
1760 ha->flags.disable_msix_handshake = 1;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001761 ql_dbg(ql_dbg_init, vha, 0x00fe,
1762 "MSIX Handshake Disable Mode turned on.\n");
Anirban Chakraborty31557542009-12-02 10:36:55 -08001763 } else {
1764 icb->firmware_options_2 |=
1765 __constant_cpu_to_le32(BIT_22);
1766 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001767 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001768
1769 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1770 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1771 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1772 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1773 } else {
1774 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1775 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1776 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1777 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1778 }
1779 /* PCI posting */
1780 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001781}
1782
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783/**
1784 * qla2x00_init_rings() - Initializes firmware.
1785 * @ha: HA context
1786 *
1787 * Beginning of request ring has initialization control block already built
1788 * by nvram config routine.
1789 *
1790 * Returns 0 on success.
1791 */
1792static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001793qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794{
1795 int rval;
1796 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001797 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001798 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001799 struct req_que *req;
1800 struct rsp_que *rsp;
1801 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001802 struct mid_init_cb_24xx *mid_init_cb =
1803 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
1805 spin_lock_irqsave(&ha->hardware_lock, flags);
1806
1807 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001808 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001809 req = ha->req_q_map[que];
1810 if (!req)
1811 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001812 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001813 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001815 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001816
1817 /* Initialize firmware. */
1818 req->ring_ptr = req->ring;
1819 req->ring_index = 0;
1820 req->cnt = req->length;
1821 }
1822
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001823 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001824 rsp = ha->rsp_q_map[que];
1825 if (!rsp)
1826 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001827 /* Initialize response queue entries */
1828 qla2x00_init_response_q_entries(rsp);
1829 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830
Dan Carpenter542bce12010-10-15 11:27:38 -07001831 spin_lock(&ha->vport_slock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001833 list_for_each_entry(vp, &ha->vp_list, list) {
1834 vp->rscn_in_ptr = 0;
1835 vp->rscn_out_ptr = 0;
1836 }
Arun Easifeafb7b2010-09-03 14:57:00 -07001837
Dan Carpenter542bce12010-10-15 11:27:38 -07001838 spin_unlock(&ha->vport_slock);
Arun Easifeafb7b2010-09-03 14:57:00 -07001839
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001840 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841
1842 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1843
1844 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001845 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001847 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001848
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001849 if (ha->flags.npiv_supported) {
1850 if (ha->operating_mode == LOOP)
1851 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001852 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001853 }
1854
Andrew Vasquez24a08132009-03-24 09:08:16 -07001855 if (IS_FWI2_CAPABLE(ha)) {
1856 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1857 mid_init_cb->init_cb.execution_throttle =
1858 cpu_to_le16(ha->fw_xcb_count);
1859 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001860
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001861 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001863 ql_log(ql_log_fatal, vha, 0x00d2,
1864 "Init Firmware **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001866 ql_dbg(ql_dbg_init, vha, 0x00d3,
1867 "Init Firmware -- success.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 }
1869
1870 return (rval);
1871}
1872
1873/**
1874 * qla2x00_fw_ready() - Waits for firmware ready.
1875 * @ha: HA context
1876 *
1877 * Returns 0 on success.
1878 */
1879static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001880qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881{
1882 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001883 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 uint16_t min_wait; /* Minimum wait time if loop is down */
1885 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001886 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001887 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
1889 rval = QLA_SUCCESS;
1890
1891 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001892 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
1894 /*
1895 * Firmware should take at most one RATOV to login, plus 5 seconds for
1896 * our own processing.
1897 */
1898 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1899 wait_time = min_wait;
1900 }
1901
1902 /* Min wait time if loop down */
1903 mtime = jiffies + (min_wait * HZ);
1904
1905 /* wait time before firmware ready */
1906 wtime = jiffies + (wait_time * HZ);
1907
1908 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001909 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001910 ql_log(ql_log_info, vha, 0x801e,
1911 "Waiting for LIP to complete.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
1913 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001914 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001916 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001917 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001919 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001920 ql_dbg(ql_dbg_taskm, vha, 0x801f,
1921 "fw_state=%x 84xx=%x.\n", state[0],
1922 state[2]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001923 if ((state[2] & FSTATE_LOGGED_IN) &&
1924 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001925 ql_dbg(ql_dbg_taskm, vha, 0x8028,
1926 "Sending verify iocb.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001927
1928 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001929 rval = qla84xx_init_chip(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001930 if (rval != QLA_SUCCESS) {
1931 ql_log(ql_log_warn,
Giridhar Malavali08de2842011-08-16 11:31:44 -07001932 vha, 0x8026,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001933 "Init chip failed.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001934 break;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001935 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001936
1937 /* Add time taken to initialize. */
1938 cs84xx_time = jiffies - cs84xx_time;
1939 wtime += cs84xx_time;
1940 mtime += cs84xx_time;
Giridhar Malavali08de2842011-08-16 11:31:44 -07001941 ql_dbg(ql_dbg_taskm, vha, 0x8025,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001942 "Increasing wait time by %ld. "
1943 "New time %ld.\n", cs84xx_time,
1944 wtime);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001945 }
1946 } else if (state[0] == FSTATE_READY) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001947 ql_dbg(ql_dbg_taskm, vha, 0x8037,
1948 "F/W Ready - OK.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001950 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 &ha->login_timeout, &ha->r_a_tov);
1952
1953 rval = QLA_SUCCESS;
1954 break;
1955 }
1956
1957 rval = QLA_FUNCTION_FAILED;
1958
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001959 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001960 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001962 * other than Wait for Login.
1963 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 if (time_after_eq(jiffies, mtime)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001965 ql_log(ql_log_info, vha, 0x8038,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 "Cable is unplugged...\n");
1967
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001968 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 break;
1970 }
1971 }
1972 } else {
1973 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07001974 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08001975 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 break;
1977 }
1978
1979 if (time_after_eq(jiffies, wtime))
1980 break;
1981
1982 /* Delay for a while */
1983 msleep(500);
1984
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001985 ql_dbg(ql_dbg_taskm, vha, 0x8039,
1986 "fw_state=%x curr time=%lx.\n", state[0], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 } while (1);
1988
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001989 ql_dbg(ql_dbg_taskm, vha, 0x803a,
1990 "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0],
1991 state[1], state[2], state[3], state[4], jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992
1993 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001994 ql_log(ql_log_warn, vha, 0x803b,
1995 "Firmware ready **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 }
1997
1998 return (rval);
1999}
2000
2001/*
2002* qla2x00_configure_hba
2003* Setup adapter context.
2004*
2005* Input:
2006* ha = adapter state pointer.
2007*
2008* Returns:
2009* 0 = success
2010*
2011* Context:
2012* Kernel context.
2013*/
2014static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002015qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016{
2017 int rval;
2018 uint16_t loop_id;
2019 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002020 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 uint8_t al_pa;
2022 uint8_t area;
2023 uint8_t domain;
2024 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002025 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
2027 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002028 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002029 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002031 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Andrew Vasquez7a44b862010-12-21 16:00:23 -08002032 IS_QLA8XXX_TYPE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002033 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002034 ql_dbg(ql_dbg_disc, vha, 0x2008,
2035 "Loop is in a transition state.\n");
Ravi Anand33135aa2005-11-08 14:37:20 -08002036 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002037 ql_log(ql_log_warn, vha, 0x2009,
2038 "Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002039 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002040 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 return (rval);
2042 }
2043
2044 if (topo == 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002045 ql_log(ql_log_info, vha, 0x200a,
2046 "Cannot get topology - retrying.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 return (QLA_FUNCTION_FAILED);
2048 }
2049
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002050 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051
2052 /* initialize */
2053 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2054 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002055 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056
2057 switch (topo) {
2058 case 0:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002059 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 ha->current_topology = ISP_CFG_NL;
2061 strcpy(connect_type, "(Loop)");
2062 break;
2063
2064 case 1:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002065 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002066 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 ha->current_topology = ISP_CFG_FL;
2068 strcpy(connect_type, "(FL_Port)");
2069 break;
2070
2071 case 2:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002072 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 ha->operating_mode = P2P;
2074 ha->current_topology = ISP_CFG_N;
2075 strcpy(connect_type, "(N_Port-to-N_Port)");
2076 break;
2077
2078 case 3:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002079 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002080 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 ha->operating_mode = P2P;
2082 ha->current_topology = ISP_CFG_F;
2083 strcpy(connect_type, "(F_Port)");
2084 break;
2085
2086 default:
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002087 ql_dbg(ql_dbg_disc, vha, 0x200f,
2088 "HBA in unknown topology %x, using NL.\n", topo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 ha->current_topology = ISP_CFG_NL;
2090 strcpy(connect_type, "(Loop)");
2091 break;
2092 }
2093
2094 /* Save Host port and loop ID. */
2095 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002096 vha->d_id.b.domain = domain;
2097 vha->d_id.b.area = area;
2098 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002100 if (!vha->flags.init_done)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002101 ql_log(ql_log_info, vha, 0x2010,
2102 "Topology - %s, Host Loop address 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002103 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
2105 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002106 ql_log(ql_log_warn, vha, 0x2011,
2107 "%s FAILED\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002109 ql_dbg(ql_dbg_disc, vha, 0x2012,
2110 "%s success\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 }
2112
2113 return(rval);
2114}
2115
Giridhar Malavalia9083012010-04-12 17:59:55 -07002116inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002117qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2118 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002119{
2120 char *st, *en;
2121 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002122 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002123 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavalia9083012010-04-12 17:59:55 -07002124 !IS_QLA8XXX_TYPE(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002125
2126 if (memcmp(model, BINZERO, len) != 0) {
2127 strncpy(ha->model_number, model, len);
2128 st = en = ha->model_number;
2129 en += len - 1;
2130 while (en > st) {
2131 if (*en != 0x20 && *en != 0x00)
2132 break;
2133 *en-- = '\0';
2134 }
2135
2136 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002137 if (use_tbl &&
2138 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002139 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002140 strncpy(ha->model_desc,
2141 qla2x00_model_name[index * 2 + 1],
2142 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002143 } else {
2144 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002145 if (use_tbl &&
2146 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002147 index < QLA_MODEL_NAMES) {
2148 strcpy(ha->model_number,
2149 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002150 strncpy(ha->model_desc,
2151 qla2x00_model_name[index * 2 + 1],
2152 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002153 } else {
2154 strcpy(ha->model_number, def);
2155 }
2156 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002157 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002158 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002159 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002160}
2161
David Miller4e08df32007-04-16 12:37:43 -07002162/* On sparc systems, obtain port and node WWN from firmware
2163 * properties.
2164 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002165static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002166{
2167#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002168 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002169 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002170 struct device_node *dp = pci_device_to_OF_node(pdev);
2171 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002172 int len;
2173
2174 val = of_get_property(dp, "port-wwn", &len);
2175 if (val && len >= WWN_SIZE)
2176 memcpy(nv->port_name, val, WWN_SIZE);
2177
2178 val = of_get_property(dp, "node-wwn", &len);
2179 if (val && len >= WWN_SIZE)
2180 memcpy(nv->node_name, val, WWN_SIZE);
2181#endif
2182}
2183
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184/*
2185* NVRAM configuration for ISP 2xxx
2186*
2187* Input:
2188* ha = adapter block pointer.
2189*
2190* Output:
2191* initialization control block in response_ring
2192* host adapters parameters in host adapter block
2193*
2194* Returns:
2195* 0 = success.
2196*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002197int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002198qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199{
David Miller4e08df32007-04-16 12:37:43 -07002200 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002201 uint8_t chksum = 0;
2202 uint16_t cnt;
2203 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002204 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002205 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002206 nvram_t *nv = ha->nvram;
2207 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002208 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
David Miller4e08df32007-04-16 12:37:43 -07002210 rval = QLA_SUCCESS;
2211
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002213 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 ha->nvram_base = 0;
2215 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2216 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2217 ha->nvram_base = 0x80;
2218
2219 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002220 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002221 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2222 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002224 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
2225 "Contents of NVRAM.\n");
2226 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
2227 (uint8_t *)nv, ha->nvram_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228
2229 /* Bad NVRAM data, set defaults parameters. */
2230 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2231 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2232 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002233 ql_log(ql_log_warn, vha, 0x0064,
2234 "Inconisistent NVRAM "
2235 "detected: checksum=0x%x id=%c version=0x%x.\n",
2236 chksum, nv->id[0], nv->nvram_version);
2237 ql_log(ql_log_warn, vha, 0x0065,
2238 "Falling back to "
2239 "functioning (yet invalid -- WWPN) defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07002240
2241 /*
2242 * Set default initialization control block.
2243 */
2244 memset(nv, 0, ha->nvram_size);
2245 nv->parameter_block_version = ICB_VERSION;
2246
2247 if (IS_QLA23XX(ha)) {
2248 nv->firmware_options[0] = BIT_2 | BIT_1;
2249 nv->firmware_options[1] = BIT_7 | BIT_5;
2250 nv->add_firmware_options[0] = BIT_5;
2251 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2252 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2253 nv->special_options[1] = BIT_7;
2254 } else if (IS_QLA2200(ha)) {
2255 nv->firmware_options[0] = BIT_2 | BIT_1;
2256 nv->firmware_options[1] = BIT_7 | BIT_5;
2257 nv->add_firmware_options[0] = BIT_5;
2258 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2259 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2260 } else if (IS_QLA2100(ha)) {
2261 nv->firmware_options[0] = BIT_3 | BIT_1;
2262 nv->firmware_options[1] = BIT_5;
2263 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2264 }
2265
2266 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2267 nv->execution_throttle = __constant_cpu_to_le16(16);
2268 nv->retry_count = 8;
2269 nv->retry_delay = 1;
2270
2271 nv->port_name[0] = 33;
2272 nv->port_name[3] = 224;
2273 nv->port_name[4] = 139;
2274
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002275 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002276
2277 nv->login_timeout = 4;
2278
2279 /*
2280 * Set default host adapter parameters
2281 */
2282 nv->host_p[1] = BIT_2;
2283 nv->reset_delay = 5;
2284 nv->port_down_retry_count = 8;
2285 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2286 nv->link_down_timeout = 60;
2287
2288 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 }
2290
2291#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2292 /*
2293 * The SN2 does not provide BIOS emulation which means you can't change
2294 * potentially bogus BIOS settings. Force the use of default settings
2295 * for link rate and frame size. Hope that the rest of the settings
2296 * are valid.
2297 */
2298 if (ia64_platform_is("sn2")) {
2299 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2300 if (IS_QLA23XX(ha))
2301 nv->special_options[1] = BIT_7;
2302 }
2303#endif
2304
2305 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002306 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307
2308 /*
2309 * Setup driver NVRAM options.
2310 */
2311 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2312 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2313 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2314 nv->firmware_options[1] &= ~BIT_4;
2315
2316 if (IS_QLA23XX(ha)) {
2317 nv->firmware_options[0] |= BIT_2;
2318 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002319 nv->firmware_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002320 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321
2322 if (IS_QLA2300(ha)) {
2323 if (ha->fb_rev == FPM_2310) {
2324 strcpy(ha->model_number, "QLA2310");
2325 } else {
2326 strcpy(ha->model_number, "QLA2300");
2327 }
2328 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002329 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002330 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 }
2332 } else if (IS_QLA2200(ha)) {
2333 nv->firmware_options[0] |= BIT_2;
2334 /*
2335 * 'Point-to-point preferred, else loop' is not a safe
2336 * connection mode setting.
2337 */
2338 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2339 (BIT_5 | BIT_4)) {
2340 /* Force 'loop preferred, else point-to-point'. */
2341 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2342 nv->add_firmware_options[0] |= BIT_5;
2343 }
2344 strcpy(ha->model_number, "QLA22xx");
2345 } else /*if (IS_QLA2100(ha))*/ {
2346 strcpy(ha->model_number, "QLA2100");
2347 }
2348
2349 /*
2350 * Copy over NVRAM RISC parameter block to initialization control block.
2351 */
2352 dptr1 = (uint8_t *)icb;
2353 dptr2 = (uint8_t *)&nv->parameter_block_version;
2354 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2355 while (cnt--)
2356 *dptr1++ = *dptr2++;
2357
2358 /* Copy 2nd half. */
2359 dptr1 = (uint8_t *)icb->add_firmware_options;
2360 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2361 while (cnt--)
2362 *dptr1++ = *dptr2++;
2363
Andrew Vasquez5341e862006-05-17 15:09:16 -07002364 /* Use alternate WWN? */
2365 if (nv->host_p[1] & BIT_7) {
2366 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2367 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2368 }
2369
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 /* Prepare nodename */
2371 if ((icb->firmware_options[1] & BIT_6) == 0) {
2372 /*
2373 * Firmware will apply the following mask if the nodename was
2374 * not provided.
2375 */
2376 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2377 icb->node_name[0] &= 0xF0;
2378 }
2379
2380 /*
2381 * Set host adapter parameters.
2382 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002383
2384 /*
2385 * BIT_7 in the host-parameters section allows for modification to
2386 * internal driver logging.
2387 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002388 if (nv->host_p[0] & BIT_7)
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002389 ql2xextended_error_logging = 0x7fffffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2391 /* Always load RISC code on non ISP2[12]00 chips. */
2392 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2393 ha->flags.disable_risc_code_load = 0;
2394 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2395 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2396 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002397 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002398 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399
2400 ha->operating_mode =
2401 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2402
2403 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2404 sizeof(ha->fw_seriallink_options));
2405
2406 /* save HBA serial number */
2407 ha->serial0 = icb->port_name[5];
2408 ha->serial1 = icb->port_name[6];
2409 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002410 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2411 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412
2413 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2414
2415 ha->retry_count = nv->retry_count;
2416
2417 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002418 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 nv->login_timeout = ql2xlogintimeout;
2420 if (nv->login_timeout < 4)
2421 nv->login_timeout = 4;
2422 ha->login_timeout = nv->login_timeout;
2423 icb->login_timeout = nv->login_timeout;
2424
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002425 /* Set minimum RATOV to 100 tenths of a second. */
2426 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 ha->loop_reset_delay = nv->reset_delay;
2429
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 /* Link Down Timeout = 0:
2431 *
2432 * When Port Down timer expires we will start returning
2433 * I/O's to OS with "DID_NO_CONNECT".
2434 *
2435 * Link Down Timeout != 0:
2436 *
2437 * The driver waits for the link to come up after link down
2438 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002439 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 if (nv->link_down_timeout == 0) {
2441 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002442 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 } else {
2444 ha->link_down_timeout = nv->link_down_timeout;
2445 ha->loop_down_abort_time =
2446 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002447 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 /*
2450 * Need enough time to try and get the port back.
2451 */
2452 ha->port_down_retry_count = nv->port_down_retry_count;
2453 if (qlport_down_retry)
2454 ha->port_down_retry_count = qlport_down_retry;
2455 /* Set login_retry_count */
2456 ha->login_retry_count = nv->retry_count;
2457 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2458 ha->port_down_retry_count > 3)
2459 ha->login_retry_count = ha->port_down_retry_count;
2460 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2461 ha->login_retry_count = ha->port_down_retry_count;
2462 if (ql2xloginretrycount)
2463 ha->login_retry_count = ql2xloginretrycount;
2464
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 icb->lun_enables = __constant_cpu_to_le16(0);
2466 icb->command_resource_count = 0;
2467 icb->immediate_notify_resource_count = 0;
2468 icb->timeout = __constant_cpu_to_le16(0);
2469
2470 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2471 /* Enable RIO */
2472 icb->firmware_options[0] &= ~BIT_3;
2473 icb->add_firmware_options[0] &=
2474 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2475 icb->add_firmware_options[0] |= BIT_2;
2476 icb->response_accumulation_timer = 3;
2477 icb->interrupt_delay_timer = 5;
2478
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002479 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002481 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002482 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002483 ha->zio_mode = icb->add_firmware_options[0] &
2484 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2485 ha->zio_timer = icb->interrupt_delay_timer ?
2486 icb->interrupt_delay_timer: 2;
2487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 icb->add_firmware_options[0] &=
2489 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002490 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002491 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002492 ha->zio_mode = QLA_ZIO_MODE_6;
2493
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002494 ql_log(ql_log_info, vha, 0x0068,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002495 "ZIO mode %d enabled; timer delay (%d us).\n",
2496 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002498 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2499 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002500 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 }
2502 }
2503
David Miller4e08df32007-04-16 12:37:43 -07002504 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002505 ql_log(ql_log_warn, vha, 0x0069,
2506 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07002507 }
2508 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509}
2510
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002511static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002512qla2x00_rport_del(void *data)
2513{
2514 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002515 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002516 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002517
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002518 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002519 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002520 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002521 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002522 if (rport)
2523 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002524}
2525
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526/**
2527 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2528 * @ha: HA context
2529 * @flags: allocation flags
2530 *
2531 * Returns a pointer to the allocated fcport, or NULL, if none available.
2532 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002533fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002534qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535{
2536 fc_port_t *fcport;
2537
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002538 fcport = kzalloc(sizeof(fc_port_t), flags);
2539 if (!fcport)
2540 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541
2542 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002543 fcport->vha = vha;
2544 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 fcport->port_type = FCT_UNKNOWN;
2546 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07002547 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002548 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002550 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551}
2552
2553/*
2554 * qla2x00_configure_loop
2555 * Updates Fibre Channel Device Database with what is actually on loop.
2556 *
2557 * Input:
2558 * ha = adapter block pointer.
2559 *
2560 * Returns:
2561 * 0 = success.
2562 * 1 = error.
2563 * 2 = database was full and device was not configured.
2564 */
2565static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002566qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567{
2568 int rval;
2569 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002570 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 rval = QLA_SUCCESS;
2572
2573 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002574 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2575 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002577 ql_dbg(ql_dbg_disc, vha, 0x2013,
2578 "Unable to configure HBA.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 return (rval);
2580 }
2581 }
2582
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002583 save_flags = flags = vha->dpc_flags;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002584 ql_dbg(ql_dbg_disc, vha, 0x2014,
2585 "Configure loop -- dpc flags = 0x%lx.\n", flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586
2587 /*
2588 * If we have both an RSCN and PORT UPDATE pending then handle them
2589 * both at the same time.
2590 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002591 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2592 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593
Michael Hernandez3064ff32009-12-15 21:29:44 -08002594 qla2x00_get_data_rate(vha);
2595
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 /* Determine what we need to do */
2597 if (ha->current_topology == ISP_CFG_FL &&
2598 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2599
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002600 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 set_bit(RSCN_UPDATE, &flags);
2602
2603 } else if (ha->current_topology == ISP_CFG_F &&
2604 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2605
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002606 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 set_bit(RSCN_UPDATE, &flags);
2608 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2609
Andrew Vasquez21333b42006-05-17 15:09:56 -07002610 } else if (ha->current_topology == ISP_CFG_N) {
2611 clear_bit(RSCN_UPDATE, &flags);
2612
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002613 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2615
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002616 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 set_bit(RSCN_UPDATE, &flags);
2618 set_bit(LOCAL_LOOP_UPDATE, &flags);
2619 }
2620
2621 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002622 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
2623 ql_dbg(ql_dbg_disc, vha, 0x2015,
2624 "Loop resync needed, failing.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002626 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002627 else
2628 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 }
2630
2631 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002632 if (LOOP_TRANSITION(vha)) {
2633 ql_dbg(ql_dbg_disc, vha, 0x201e,
2634 "Needs RSCN update and loop transition.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002636 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002637 else
2638 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 }
2640
2641 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002642 if (atomic_read(&vha->loop_down_timer) ||
2643 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 rval = QLA_FUNCTION_FAILED;
2645 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002646 atomic_set(&vha->loop_state, LOOP_READY);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002647 ql_dbg(ql_dbg_disc, vha, 0x2069,
2648 "LOOP READY.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 }
2650 }
2651
2652 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002653 ql_dbg(ql_dbg_disc, vha, 0x206a,
2654 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002656 ql_dbg(ql_dbg_disc, vha, 0x206b,
2657 "%s: exiting normally.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 }
2659
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002660 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002661 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002663 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002664 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002665 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07002666 if (!IS_ALOGIO_CAPABLE(ha))
2667 vha->flags.rscn_queue_overflow = 1;
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 }
2670
2671 return (rval);
2672}
2673
2674
2675
2676/*
2677 * qla2x00_configure_local_loop
2678 * Updates Fibre Channel Device Database with local loop devices.
2679 *
2680 * Input:
2681 * ha = adapter block pointer.
2682 *
2683 * Returns:
2684 * 0 = success.
2685 */
2686static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002687qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688{
2689 int rval, rval2;
2690 int found_devs;
2691 int found;
2692 fc_port_t *fcport, *new_fcport;
2693
2694 uint16_t index;
2695 uint16_t entries;
2696 char *id_iter;
2697 uint16_t loop_id;
2698 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002699 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700
2701 found_devs = 0;
2702 new_fcport = NULL;
2703 entries = MAX_FIBRE_DEVICES;
2704
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002705 ql_dbg(ql_dbg_disc, vha, 0x2016,
2706 "Getting FCAL position map.\n");
2707 if (ql2xextended_error_logging & ql_dbg_disc)
2708 qla2x00_get_fcal_position_map(vha, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709
2710 /* Get list of logged in devices. */
2711 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002712 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 &entries);
2714 if (rval != QLA_SUCCESS)
2715 goto cleanup_allocation;
2716
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002717 ql_dbg(ql_dbg_disc, vha, 0x2017,
2718 "Entries in ID list (%d).\n", entries);
2719 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
2720 (uint8_t *)ha->gid_list,
2721 entries * sizeof(struct gid_list_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
2723 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002724 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002726 ql_log(ql_log_warn, vha, 0x2018,
2727 "Memory allocation failed for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 rval = QLA_MEMORY_ALLOC_FAILED;
2729 goto cleanup_allocation;
2730 }
2731 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2732
2733 /*
2734 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2735 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002736 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2738 fcport->port_type != FCT_BROADCAST &&
2739 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2740
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002741 ql_dbg(ql_dbg_disc, vha, 0x2019,
2742 "Marking port lost loop_id=0x%04x.\n",
2743 fcport->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744
Chad Dupuisec426e12011-03-30 11:46:32 -07002745 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 }
2747 }
2748
2749 /* Add devices to port list. */
2750 id_iter = (char *)ha->gid_list;
2751 for (index = 0; index < entries; index++) {
2752 domain = ((struct gid_list_info *)id_iter)->domain;
2753 area = ((struct gid_list_info *)id_iter)->area;
2754 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002755 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 loop_id = (uint16_t)
2757 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002758 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 loop_id = le16_to_cpu(
2760 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002761 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762
2763 /* Bypass reserved domain fields. */
2764 if ((domain & 0xf0) == 0xf0)
2765 continue;
2766
2767 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002768 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002769 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 continue;
2771
2772 /* Bypass invalid local loop ID. */
2773 if (loop_id > LAST_LOCAL_LOOP_ID)
2774 continue;
2775
2776 /* Fill in member data. */
2777 new_fcport->d_id.b.domain = domain;
2778 new_fcport->d_id.b.area = area;
2779 new_fcport->d_id.b.al_pa = al_pa;
2780 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002781 new_fcport->vp_idx = vha->vp_idx;
2782 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002784 ql_dbg(ql_dbg_disc, vha, 0x201a,
2785 "Failed to retrieve fcport information "
2786 "-- get_port_database=%x, loop_id=0x%04x.\n",
2787 rval2, new_fcport->loop_id);
2788 ql_dbg(ql_dbg_disc, vha, 0x201b,
2789 "Scheduling resync.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002790 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 continue;
2792 }
2793
2794 /* Check for matching device in port list. */
2795 found = 0;
2796 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002797 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 if (memcmp(new_fcport->port_name, fcport->port_name,
2799 WWN_SIZE))
2800 continue;
2801
Shyam Sundarddb9b122009-03-24 09:08:10 -07002802 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 fcport->loop_id = new_fcport->loop_id;
2804 fcport->port_type = new_fcport->port_type;
2805 fcport->d_id.b24 = new_fcport->d_id.b24;
2806 memcpy(fcport->node_name, new_fcport->node_name,
2807 WWN_SIZE);
2808
2809 found++;
2810 break;
2811 }
2812
2813 if (!found) {
2814 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002815 if (vha->vp_idx) {
2816 new_fcport->vha = vha;
2817 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002818 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002819 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820
2821 /* Allocate a new replacement fcport. */
2822 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002823 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002825 ql_log(ql_log_warn, vha, 0x201c,
2826 "Failed to allocate memory for fcport.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 rval = QLA_MEMORY_ALLOC_FAILED;
2828 goto cleanup_allocation;
2829 }
2830 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2831 }
2832
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002833 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002834 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002835
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002836 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837
2838 found_devs++;
2839 }
2840
2841cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002842 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843
2844 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002845 ql_dbg(ql_dbg_disc, vha, 0x201d,
2846 "Configure local loop error exit: rval=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 }
2848
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 return (rval);
2850}
2851
2852static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002853qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002854{
2855#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002856 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2857 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002858 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002859 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002860 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002861
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002862 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002863 return;
2864
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07002865 if (atomic_read(&fcport->state) != FCS_ONLINE)
2866 return;
2867
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002868 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2869 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002870 return;
2871
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002872 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002873 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002874 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002875 ql_dbg(ql_dbg_disc, vha, 0x2004,
2876 "Unable to adjust iIDMA "
2877 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x "
2878 "%04x.\n", fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002879 fcport->port_name[2], fcport->port_name[3],
2880 fcport->port_name[4], fcport->port_name[5],
2881 fcport->port_name[6], fcport->port_name[7], rval,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002882 fcport->fp_speed, mb[0], mb[1]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002883 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002884 link_speed = link_speeds[LS_UNKNOWN];
2885 if (fcport->fp_speed < 5)
2886 link_speed = link_speeds[fcport->fp_speed];
2887 else if (fcport->fp_speed == 0x13)
2888 link_speed = link_speeds[5];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002889 ql_dbg(ql_dbg_disc, vha, 0x2005,
2890 "iIDMA adjusted to %s GB/s "
2891 "on %02x%02x%02x%02x%02x%02x%02x%02x.\n", link_speed,
2892 fcport->port_name[0], fcport->port_name[1],
2893 fcport->port_name[2], fcport->port_name[3],
2894 fcport->port_name[4], fcport->port_name[5],
2895 fcport->port_name[6], fcport->port_name[7]);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002896 }
2897}
2898
Adrian Bunk23be3312006-11-24 02:46:01 +01002899static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002900qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002901{
2902 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002903 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002904 unsigned long flags;
8482e1182005-04-17 15:04:54 -05002905
Andrew Vasquezac280b62009-08-20 11:06:05 -07002906 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002907
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002908 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2909 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002910 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2911 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2912 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002913 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002914 if (!rport) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002915 ql_log(ql_log_warn, vha, 0x2006,
2916 "Unable to allocate fc remote port.\n");
Andrew Vasquez77d74142005-07-08 18:00:36 -07002917 return;
2918 }
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002919 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002920 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002921 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002922
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002923 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002924
2925 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002926 if (fcport->port_type == FCT_INITIATOR)
2927 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2928 if (fcport->port_type == FCT_TARGET)
2929 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002930 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002931}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932
2933/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002934 * qla2x00_update_fcport
2935 * Updates device on list.
2936 *
2937 * Input:
2938 * ha = adapter block pointer.
2939 * fcport = port structure pointer.
2940 *
2941 * Return:
2942 * 0 - Success
2943 * BIT_0 - error
2944 *
2945 * Context:
2946 * Kernel context.
2947 */
2948void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002949qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002950{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002951 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002952 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002953 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01002954
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002955 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08002956 qla24xx_update_fcport_fcp_prio(vha, fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002957 qla2x00_reg_remote_port(vha, fcport);
Chad Dupuisec426e12011-03-30 11:46:32 -07002958 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Adrian Bunk23be3312006-11-24 02:46:01 +01002959}
2960
2961/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 * qla2x00_configure_fabric
2963 * Setup SNS devices with loop ID's.
2964 *
2965 * Input:
2966 * ha = adapter block pointer.
2967 *
2968 * Returns:
2969 * 0 = success.
2970 * BIT_0 = error
2971 */
2972static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002973qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974{
2975 int rval, rval2;
2976 fc_port_t *fcport, *fcptemp;
2977 uint16_t next_loopid;
2978 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002979 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002981 struct qla_hw_data *ha = vha->hw;
2982 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983
2984 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002985 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002986 loop_id = NPH_F_PORT;
2987 else
2988 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002989 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002991 ql_dbg(ql_dbg_disc, vha, 0x201f,
2992 "MBX_GET_PORT_NAME failed, No FL Port.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002994 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 return (QLA_SUCCESS);
2996 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002997 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998
2999 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003000 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 if (rval2 == QLA_RSCNS_HANDLED) {
3002 /* No point doing the scan, just continue. */
3003 return (QLA_SUCCESS);
3004 }
3005 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07003006 /* FDMI support. */
3007 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003008 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
3009 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07003010
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003012 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003013 loop_id = NPH_SNS;
3014 else
3015 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003016 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003017 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003019 ql_dbg(ql_dbg_disc, vha, 0x2042,
3020 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3021 "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
3022 mb[2], mb[6], mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 return (QLA_SUCCESS);
3024 }
3025
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003026 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3027 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003029 ql_dbg(ql_dbg_disc, vha, 0x2045,
3030 "Register FC-4 TYPE failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003032 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003034 ql_dbg(ql_dbg_disc, vha, 0x2049,
3035 "Register FC-4 Features failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003037 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003039 ql_dbg(ql_dbg_disc, vha, 0x204f,
3040 "Register Node Name failed.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003041 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003043 ql_dbg(ql_dbg_disc, vha, 0x2053,
3044 "Register Symobilic Node Name failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 }
3046 }
3047
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003048 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 if (rval != QLA_SUCCESS)
3050 break;
3051
3052 /*
3053 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003054 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003056 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3057 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 break;
3059
3060 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3061 continue;
3062
3063 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003064 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003065 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003067 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 fcport->port_type != FCT_INITIATOR &&
3069 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003070 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003071 fcport->loop_id,
3072 fcport->d_id.b.domain,
3073 fcport->d_id.b.area,
3074 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 fcport->loop_id = FC_NO_LOOP_ID;
3076 }
3077 }
3078 }
3079
3080 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003081 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082
3083 /*
3084 * Scan through our port list and login entries that need to be
3085 * logged in.
3086 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003087 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3088 if (atomic_read(&vha->loop_down_timer) ||
3089 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 break;
3091
3092 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3093 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3094 continue;
3095
3096 if (fcport->loop_id == FC_NO_LOOP_ID) {
3097 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07003098 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003099 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 if (rval != QLA_SUCCESS) {
3101 /* Ran out of IDs to use */
3102 break;
3103 }
3104 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003106 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107 }
3108
3109 /* Exit if out of loop IDs. */
3110 if (rval != QLA_SUCCESS) {
3111 break;
3112 }
3113
3114 /*
3115 * Login and add the new devices to our port list.
3116 */
3117 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003118 if (atomic_read(&vha->loop_down_timer) ||
3119 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 break;
3121
3122 /* Find a new loop ID to use. */
3123 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003124 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125 if (rval != QLA_SUCCESS) {
3126 /* Ran out of IDs to use */
3127 break;
3128 }
3129
bdf79622005-04-17 15:06:53 -05003130 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003131 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003132
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003133 if (vha->vp_idx) {
3134 fcport->vha = vha;
3135 fcport->vp_idx = vha->vp_idx;
3136 }
3137 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 }
3139 } while (0);
3140
3141 /* Free all new device structures not processed. */
3142 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3143 list_del(&fcport->list);
3144 kfree(fcport);
3145 }
3146
3147 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003148 ql_dbg(ql_dbg_disc, vha, 0x2068,
3149 "Configure fabric error exit rval=%d.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 }
3151
3152 return (rval);
3153}
3154
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155/*
3156 * qla2x00_find_all_fabric_devs
3157 *
3158 * Input:
3159 * ha = adapter block pointer.
3160 * dev = database device entry pointer.
3161 *
3162 * Returns:
3163 * 0 = success.
3164 *
3165 * Context:
3166 * Kernel context.
3167 */
3168static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003169qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3170 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171{
3172 int rval;
3173 uint16_t loop_id;
3174 fc_port_t *fcport, *new_fcport, *fcptemp;
3175 int found;
3176
3177 sw_info_t *swl;
3178 int swl_idx;
3179 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003180 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003181 struct qla_hw_data *ha = vha->hw;
3182 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003183 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184
3185 rval = QLA_SUCCESS;
3186
3187 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07003188 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003189 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003191 ql_dbg(ql_dbg_disc, vha, 0x2054,
3192 "GID_PT allocations failed, fallback on GA_NXT.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003194 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 kfree(swl);
3196 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003197 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 kfree(swl);
3199 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003200 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 kfree(swl);
3202 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003203 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003204 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3205 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003207
3208 /* If other queries succeeded probe for FC-4 type */
3209 if (swl)
3210 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 }
3212 swl_idx = 0;
3213
3214 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003215 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003217 ql_log(ql_log_warn, vha, 0x205e,
3218 "Failed to allocate memory for fcport.\n");
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003219 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220 return (QLA_MEMORY_ALLOC_FAILED);
3221 }
3222 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 /* Set start port ID scan at adapter ID. */
3224 first_dev = 1;
3225 last_dev = 0;
3226
3227 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003228 loop_id = ha->min_external_loopid;
3229 for (; loop_id <= ha->max_loop_id; loop_id++) {
3230 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 continue;
3232
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003233 if (ha->current_topology == ISP_CFG_FL &&
3234 (atomic_read(&vha->loop_down_timer) ||
3235 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003236 atomic_set(&vha->loop_down_timer, 0);
3237 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3238 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003240 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241
3242 if (swl != NULL) {
3243 if (last_dev) {
3244 wrap.b24 = new_fcport->d_id.b24;
3245 } else {
3246 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3247 memcpy(new_fcport->node_name,
3248 swl[swl_idx].node_name, WWN_SIZE);
3249 memcpy(new_fcport->port_name,
3250 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003251 memcpy(new_fcport->fabric_port_name,
3252 swl[swl_idx].fabric_port_name, WWN_SIZE);
3253 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003254 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255
3256 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3257 last_dev = 1;
3258 }
3259 swl_idx++;
3260 }
3261 } else {
3262 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003263 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003265 ql_log(ql_log_warn, vha, 0x2064,
3266 "SNS scan failed -- assuming "
3267 "zero-entry result.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 list_for_each_entry_safe(fcport, fcptemp,
3269 new_fcports, list) {
3270 list_del(&fcport->list);
3271 kfree(fcport);
3272 }
3273 rval = QLA_SUCCESS;
3274 break;
3275 }
3276 }
3277
3278 /* If wrap on switch device list, exit. */
3279 if (first_dev) {
3280 wrap.b24 = new_fcport->d_id.b24;
3281 first_dev = 0;
3282 } else if (new_fcport->d_id.b24 == wrap.b24) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003283 ql_dbg(ql_dbg_disc, vha, 0x2065,
3284 "Device wrap (%02x%02x%02x).\n",
3285 new_fcport->d_id.b.domain,
3286 new_fcport->d_id.b.area,
3287 new_fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 break;
3289 }
3290
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003291 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003292 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 continue;
3294
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003295 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003296 found = 0;
3297 if (ha->num_vhosts) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003298 unsigned long flags;
3299
3300 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003301 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003302 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3303 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003304 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003305 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003306 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003307 spin_unlock_irqrestore(&ha->vport_slock, flags);
3308
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003309 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003310 continue;
3311 }
3312
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003313 /* Bypass if same domain and area of adapter. */
3314 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003315 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003316 ISP_CFG_FL)
3317 continue;
3318
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 /* Bypass reserved domain fields. */
3320 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3321 continue;
3322
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003323 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003324 if (ql2xgffidenable &&
3325 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3326 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003327 continue;
3328
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 /* Locate matching device in database. */
3330 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003331 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 if (memcmp(new_fcport->port_name, fcport->port_name,
3333 WWN_SIZE))
3334 continue;
3335
3336 found++;
3337
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003338 /* Update port state. */
3339 memcpy(fcport->fabric_port_name,
3340 new_fcport->fabric_port_name, WWN_SIZE);
3341 fcport->fp_speed = new_fcport->fp_speed;
3342
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 /*
3344 * If address the same and state FCS_ONLINE, nothing
3345 * changed.
3346 */
3347 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3348 atomic_read(&fcport->state) == FCS_ONLINE) {
3349 break;
3350 }
3351
3352 /*
3353 * If device was not a fabric device before.
3354 */
3355 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3356 fcport->d_id.b24 = new_fcport->d_id.b24;
3357 fcport->loop_id = FC_NO_LOOP_ID;
3358 fcport->flags |= (FCF_FABRIC_DEVICE |
3359 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 break;
3361 }
3362
3363 /*
3364 * Port ID changed or device was marked to be updated;
3365 * Log it out if still logged in and mark it for
3366 * relogin later.
3367 */
3368 fcport->d_id.b24 = new_fcport->d_id.b24;
3369 fcport->flags |= FCF_LOGIN_NEEDED;
3370 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003371 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 fcport->port_type != FCT_INITIATOR &&
3373 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003374 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003375 fcport->d_id.b.domain, fcport->d_id.b.area,
3376 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 fcport->loop_id = FC_NO_LOOP_ID;
3378 }
3379
3380 break;
3381 }
3382
3383 if (found)
3384 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385 /* If device was not in our fcports list, then add it. */
3386 list_add_tail(&new_fcport->list, new_fcports);
3387
3388 /* Allocate a new replacement fcport. */
3389 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003390 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 if (new_fcport == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003392 ql_log(ql_log_warn, vha, 0x2066,
3393 "Memory allocation failed for fcport.\n");
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003394 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 return (QLA_MEMORY_ALLOC_FAILED);
3396 }
3397 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3398 new_fcport->d_id.b24 = nxt_d_id.b24;
3399 }
3400
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003401 kfree(swl);
3402 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404 return (rval);
3405}
3406
3407/*
3408 * qla2x00_find_new_loop_id
3409 * Scan through our port list and find a new usable loop ID.
3410 *
3411 * Input:
3412 * ha: adapter state pointer.
3413 * dev: port structure pointer.
3414 *
3415 * Returns:
3416 * qla2x00 local function return status code.
3417 *
3418 * Context:
3419 * Kernel context.
3420 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003421int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003422qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423{
3424 int rval;
3425 int found;
3426 fc_port_t *fcport;
3427 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003428 struct qla_hw_data *ha = vha->hw;
3429 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003430 struct scsi_qla_host *tvp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003431 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432
3433 rval = QLA_SUCCESS;
3434
3435 /* Save starting loop ID. */
3436 first_loop_id = dev->loop_id;
3437
3438 for (;;) {
3439 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003440 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442
3443 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003444 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446
3447 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003448 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 /* first loop ID. */
3450 dev->loop_id = ha->min_external_loopid;
3451 }
3452
3453 /* Check for loop ID being already in use. */
3454 found = 0;
3455 fcport = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003456
3457 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003458 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003459 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3460 if (fcport->loop_id == dev->loop_id &&
3461 fcport != dev) {
3462 /* ID possibly in use */
3463 found++;
3464 break;
3465 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003467 if (found)
3468 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003470 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471
3472 /* If not in use then it is free to use. */
3473 if (!found) {
3474 break;
3475 }
3476
3477 /* ID in use. Try next value. */
3478 dev->loop_id++;
3479
3480 /* If wrap around. No free ID to use. */
3481 if (dev->loop_id == first_loop_id) {
3482 dev->loop_id = FC_NO_LOOP_ID;
3483 rval = QLA_FUNCTION_FAILED;
3484 break;
3485 }
3486 }
3487
3488 return (rval);
3489}
3490
3491/*
3492 * qla2x00_device_resync
3493 * Marks devices in the database that needs resynchronization.
3494 *
3495 * Input:
3496 * ha = adapter block pointer.
3497 *
3498 * Context:
3499 * Kernel context.
3500 */
3501static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003502qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503{
3504 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 uint32_t mask;
3506 fc_port_t *fcport;
3507 uint32_t rscn_entry;
3508 uint8_t rscn_out_iter;
3509 uint8_t format;
Mike Waychison1516ef42010-05-04 15:01:31 -07003510 port_id_t d_id = {};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511
3512 rval = QLA_RSCNS_HANDLED;
3513
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003514 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3515 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003517 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 format = MSB(MSW(rscn_entry));
3519 d_id.b.domain = LSB(MSW(rscn_entry));
3520 d_id.b.area = MSB(LSW(rscn_entry));
3521 d_id.b.al_pa = LSB(LSW(rscn_entry));
3522
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003523 ql_dbg(ql_dbg_disc, vha, 0x2020,
3524 "RSCN queue entry[%d] = [%02x/%02x%02x%02x].\n",
3525 vha->rscn_out_ptr, format, d_id.b.domain, d_id.b.area,
3526 d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003528 vha->rscn_out_ptr++;
3529 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3530 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531
3532 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003533 for (rscn_out_iter = vha->rscn_out_ptr;
3534 !vha->flags.rscn_queue_overflow &&
3535 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 rscn_out_iter = (rscn_out_iter ==
3537 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3538
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003539 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 break;
3541
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003542 ql_dbg(ql_dbg_disc, vha, 0x2021,
3543 "Skipping duplicate RSCN queue entry found at "
3544 "[%d].\n", rscn_out_iter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003546 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 }
3548
3549 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003550 if (vha->flags.rscn_queue_overflow) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003551 ql_dbg(ql_dbg_disc, vha, 0x2022,
3552 "device_resync: rscn overflow.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553
3554 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003555 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 }
3557
3558 switch (format) {
3559 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560 mask = 0xffffff;
3561 break;
3562 case 1:
3563 mask = 0xffff00;
3564 break;
3565 case 2:
3566 mask = 0xff0000;
3567 break;
3568 default:
3569 mask = 0x0;
3570 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003571 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 break;
3573 }
3574
3575 rval = QLA_SUCCESS;
3576
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003577 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003578 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3579 (fcport->d_id.b24 & mask) != d_id.b24 ||
3580 fcport->port_type == FCT_BROADCAST)
3581 continue;
3582
3583 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3584 if (format != 3 ||
3585 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003586 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003587 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 }
3589 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590 }
3591 }
3592 return (rval);
3593}
3594
3595/*
3596 * qla2x00_fabric_dev_login
3597 * Login fabric target device and update FC port database.
3598 *
3599 * Input:
3600 * ha: adapter state pointer.
3601 * fcport: port structure list pointer.
3602 * next_loopid: contains value of a new loop ID that can be used
3603 * by the next login attempt.
3604 *
3605 * Returns:
3606 * qla2x00 local function return status code.
3607 *
3608 * Context:
3609 * Kernel context.
3610 */
3611static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003612qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 uint16_t *next_loopid)
3614{
3615 int rval;
3616 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003617 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003618 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619
3620 rval = QLA_SUCCESS;
3621 retry = 0;
3622
Andrew Vasquezac280b62009-08-20 11:06:05 -07003623 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003624 if (fcport->flags & FCF_ASYNC_SENT)
3625 return rval;
3626 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003627 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3628 if (!rval)
3629 return rval;
3630 }
3631
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003632 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003633 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003635 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003636 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003637 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003638 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003639 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003641 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003642 fcport->d_id.b.domain, fcport->d_id.b.area,
3643 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003644 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003646 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647 }
3648 }
3649
3650 return (rval);
3651}
3652
3653/*
3654 * qla2x00_fabric_login
3655 * Issue fabric login command.
3656 *
3657 * Input:
3658 * ha = adapter block pointer.
3659 * device = pointer to FC device type structure.
3660 *
3661 * Returns:
3662 * 0 - Login successfully
3663 * 1 - Login failed
3664 * 2 - Initiator device
3665 * 3 - Fatal error
3666 */
3667int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003668qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 uint16_t *next_loopid)
3670{
3671 int rval;
3672 int retry;
3673 uint16_t tmp_loopid;
3674 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003675 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676
3677 retry = 0;
3678 tmp_loopid = 0;
3679
3680 for (;;) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003681 ql_dbg(ql_dbg_disc, vha, 0x2000,
3682 "Trying Fabric Login w/loop id 0x%04x for port "
3683 "%02x%02x%02x.\n",
3684 fcport->loop_id, fcport->d_id.b.domain,
3685 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686
3687 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003688 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689 fcport->d_id.b.domain, fcport->d_id.b.area,
3690 fcport->d_id.b.al_pa, mb, BIT_0);
3691 if (mb[0] == MBS_PORT_ID_USED) {
3692 /*
3693 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003694 * recommends the driver perform an implicit login with
3695 * the specified ID again. The ID we just used is save
3696 * here so we return with an ID that can be tried by
3697 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 */
3699 retry++;
3700 tmp_loopid = fcport->loop_id;
3701 fcport->loop_id = mb[1];
3702
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003703 ql_dbg(ql_dbg_disc, vha, 0x2001,
3704 "Fabric Login: port in use - next loop "
3705 "id=0x%04x, port id= %02x%02x%02x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706 fcport->loop_id, fcport->d_id.b.domain,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003707 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708
3709 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3710 /*
3711 * Login succeeded.
3712 */
3713 if (retry) {
3714 /* A retry occurred before. */
3715 *next_loopid = tmp_loopid;
3716 } else {
3717 /*
3718 * No retry occurred before. Just increment the
3719 * ID value for next login.
3720 */
3721 *next_loopid = (fcport->loop_id + 1);
3722 }
3723
3724 if (mb[1] & BIT_0) {
3725 fcport->port_type = FCT_INITIATOR;
3726 } else {
3727 fcport->port_type = FCT_TARGET;
3728 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003729 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 }
3731 }
3732
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003733 if (mb[10] & BIT_0)
3734 fcport->supported_classes |= FC_COS_CLASS2;
3735 if (mb[10] & BIT_1)
3736 fcport->supported_classes |= FC_COS_CLASS3;
3737
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 rval = QLA_SUCCESS;
3739 break;
3740 } else if (mb[0] == MBS_LOOP_ID_USED) {
3741 /*
3742 * Loop ID already used, try next loop ID.
3743 */
3744 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003745 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 if (rval != QLA_SUCCESS) {
3747 /* Ran out of loop IDs to use */
3748 break;
3749 }
3750 } else if (mb[0] == MBS_COMMAND_ERROR) {
3751 /*
3752 * Firmware possibly timed out during login. If NO
3753 * retries are left to do then the device is declared
3754 * dead.
3755 */
3756 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003757 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003758 fcport->d_id.b.domain, fcport->d_id.b.area,
3759 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003760 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761
3762 rval = 1;
3763 break;
3764 } else {
3765 /*
3766 * unrecoverable / not handled error
3767 */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003768 ql_dbg(ql_dbg_disc, vha, 0x2002,
3769 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
3770 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
3771 fcport->d_id.b.area, fcport->d_id.b.al_pa,
3772 fcport->loop_id, jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773
3774 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003775 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003776 fcport->d_id.b.domain, fcport->d_id.b.area,
3777 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003779 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780
3781 rval = 3;
3782 break;
3783 }
3784 }
3785
3786 return (rval);
3787}
3788
3789/*
3790 * qla2x00_local_device_login
3791 * Issue local device login command.
3792 *
3793 * Input:
3794 * ha = adapter block pointer.
3795 * loop_id = loop id of device to login to.
3796 *
3797 * Returns (Where's the #define!!!!):
3798 * 0 - Login successfully
3799 * 1 - Login failed
3800 * 3 - Fatal error
3801 */
3802int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003803qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804{
3805 int rval;
3806 uint16_t mb[MAILBOX_REGISTER_COUNT];
3807
3808 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003809 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 if (rval == QLA_SUCCESS) {
3811 /* Interrogate mailbox registers for any errors */
3812 if (mb[0] == MBS_COMMAND_ERROR)
3813 rval = 1;
3814 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3815 /* device not in PCB table */
3816 rval = 3;
3817 }
3818
3819 return (rval);
3820}
3821
3822/*
3823 * qla2x00_loop_resync
3824 * Resync with fibre channel devices.
3825 *
3826 * Input:
3827 * ha = adapter block pointer.
3828 *
3829 * Returns:
3830 * 0 = success
3831 */
3832int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003833qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003835 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003837 struct req_que *req;
3838 struct rsp_que *rsp;
3839
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003840 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003841 req = vha->hw->req_q_map[0];
3842 else
3843 req = vha->req;
3844 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003846 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3847 if (vha->flags.online) {
3848 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3850 wait_time = 256;
3851 do {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003852 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003853 qla2x00_marker(vha, req, rsp, 0, 0,
3854 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003855 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856
3857 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003858 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003860 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003862 } while (!atomic_read(&vha->loop_down_timer) &&
3863 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3864 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3865 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867 }
3868
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003869 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003872 if (rval)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003873 ql_dbg(ql_dbg_disc, vha, 0x206c,
3874 "%s *** FAILED ***.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875
3876 return (rval);
3877}
3878
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003879/*
3880* qla2x00_perform_loop_resync
3881* Description: This function will set the appropriate flags and call
3882* qla2x00_loop_resync. If successful loop will be resynced
3883* Arguments : scsi_qla_host_t pointer
3884* returm : Success or Failure
3885*/
3886
3887int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
3888{
3889 int32_t rval = 0;
3890
3891 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
3892 /*Configure the flags so that resync happens properly*/
3893 atomic_set(&ha->loop_down_timer, 0);
3894 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3895 atomic_set(&ha->loop_state, LOOP_UP);
3896 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
3897 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
3898 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3899
3900 rval = qla2x00_loop_resync(ha);
3901 } else
3902 atomic_set(&ha->loop_state, LOOP_DEAD);
3903
3904 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3905 }
3906
3907 return rval;
3908}
3909
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003911qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003912{
3913 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07003914 struct scsi_qla_host *vha;
3915 struct qla_hw_data *ha = base_vha->hw;
3916 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003917
Arun Easifeafb7b2010-09-03 14:57:00 -07003918 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003919 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07003920 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
3921 atomic_inc(&vha->vref_count);
3922 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08003923 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07003924 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
3925 spin_unlock_irqrestore(&ha->vport_slock, flags);
3926
Andrew Vasquez67becc02009-08-25 11:36:20 -07003927 qla2x00_rport_del(fcport);
Arun Easifeafb7b2010-09-03 14:57:00 -07003928
3929 spin_lock_irqsave(&ha->vport_slock, flags);
3930 }
3931 }
3932 atomic_dec(&vha->vref_count);
3933 }
3934 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003935}
3936
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003937/*
3938* qla82xx_quiescent_state_cleanup
3939* Description: This function will block the new I/Os
3940* Its not aborting any I/Os as context
3941* is not destroyed during quiescence
3942* Arguments: scsi_qla_host_t
3943* return : void
3944*/
3945void
3946qla82xx_quiescent_state_cleanup(scsi_qla_host_t *vha)
3947{
3948 struct qla_hw_data *ha = vha->hw;
3949 struct scsi_qla_host *vp;
3950
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003951 ql_dbg(ql_dbg_p3p, vha, 0xb002,
3952 "Performing ISP error recovery - ha=%p.\n", ha);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003953
3954 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3955 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3956 atomic_set(&vha->loop_state, LOOP_DOWN);
3957 qla2x00_mark_all_devices_lost(vha, 0);
3958 list_for_each_entry(vp, &ha->vp_list, list)
3959 qla2x00_mark_all_devices_lost(vha, 0);
3960 } else {
3961 if (!atomic_read(&vha->loop_down_timer))
3962 atomic_set(&vha->loop_down_timer,
3963 LOOP_DOWN_TIME);
3964 }
3965 /* Wait for pending cmds to complete */
3966 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
3967}
3968
Giridhar Malavalia9083012010-04-12 17:59:55 -07003969void
3970qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3971{
3972 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003973 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003974 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08003975 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003976
Saurav Kashyape46ef002011-02-23 15:27:16 -08003977 /* For ISP82XX, driver waits for completion of the commands.
3978 * online flag should be set.
3979 */
3980 if (!IS_QLA82XX(ha))
3981 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003982 ha->flags.chip_reset_done = 0;
3983 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3984 ha->qla_stats.total_isp_aborts++;
3985
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003986 ql_log(ql_log_info, vha, 0x00af,
3987 "Performing ISP error recovery - ha=%p.\n", ha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003988
Saurav Kashyape46ef002011-02-23 15:27:16 -08003989 /* For ISP82XX, reset_chip is just disabling interrupts.
3990 * Driver waits for the completion of the commands.
3991 * the interrupts need to be enabled.
3992 */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003993 if (!IS_QLA82XX(ha))
3994 ha->isp_ops->reset_chip(vha);
3995
3996 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3997 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3998 atomic_set(&vha->loop_state, LOOP_DOWN);
3999 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004000
4001 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08004002 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07004003 atomic_inc(&vp->vref_count);
4004 spin_unlock_irqrestore(&ha->vport_slock, flags);
4005
Giridhar Malavalia9083012010-04-12 17:59:55 -07004006 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07004007
4008 spin_lock_irqsave(&ha->vport_slock, flags);
4009 atomic_dec(&vp->vref_count);
4010 }
4011 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004012 } else {
4013 if (!atomic_read(&vha->loop_down_timer))
4014 atomic_set(&vha->loop_down_timer,
4015 LOOP_DOWN_TIME);
4016 }
4017
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004018 /* Clear all async request states across all VPs. */
4019 list_for_each_entry(fcport, &vha->vp_fcports, list)
4020 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4021 spin_lock_irqsave(&ha->vport_slock, flags);
4022 list_for_each_entry(vp, &ha->vp_list, list) {
4023 atomic_inc(&vp->vref_count);
4024 spin_unlock_irqrestore(&ha->vport_slock, flags);
4025
4026 list_for_each_entry(fcport, &vp->vp_fcports, list)
4027 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4028
4029 spin_lock_irqsave(&ha->vport_slock, flags);
4030 atomic_dec(&vp->vref_count);
4031 }
4032 spin_unlock_irqrestore(&ha->vport_slock, flags);
4033
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004034 if (!ha->flags.eeh_busy) {
4035 /* Make sure for ISP 82XX IO DMA is complete */
4036 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004037 qla82xx_chip_reset_cleanup(vha);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004038 ql_log(ql_log_info, vha, 0x00b4,
4039 "Done chip reset cleanup.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07004040
Saurav Kashyape46ef002011-02-23 15:27:16 -08004041 /* Done waiting for pending commands.
4042 * Reset the online flag.
4043 */
4044 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004045 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004047 /* Requeue all commands in outstanding command list. */
4048 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4049 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050}
4051
4052/*
4053* qla2x00_abort_isp
4054* Resets ISP and aborts all outstanding commands.
4055*
4056* Input:
4057* ha = adapter block pointer.
4058*
4059* Returns:
4060* 0 = success
4061*/
4062int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004063qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064{
Andrew Vasquez476e8972006-08-23 14:54:55 -07004065 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004067 struct qla_hw_data *ha = vha->hw;
4068 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004069 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07004070 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004072 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004073 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074
Andrew Vasquez85880802009-12-15 21:29:46 -08004075 if (unlikely(pci_channel_offline(ha->pdev) &&
4076 ha->flags.pci_channel_io_perm_failure)) {
4077 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4078 status = 0;
4079 return status;
4080 }
4081
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004082 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08004083
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004084 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004086 if (!qla2x00_restart_isp(vha)) {
4087 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004088
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004089 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090 /*
4091 * Issue marker command only when we are going
4092 * to start the I/O .
4093 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004094 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095 }
4096
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004097 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004099 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004100
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004101 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004102 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07004103
Lalit Chandivade29c53972009-10-13 15:16:47 -07004104 if (IS_QLA81XX(ha))
4105 qla2x00_get_fw_version(vha,
4106 &ha->fw_major_version,
4107 &ha->fw_minor_version,
4108 &ha->fw_subminor_version,
4109 &ha->fw_attributes, &ha->fw_memory_size,
4110 ha->mpi_version, &ha->mpi_capabilities,
4111 ha->phy_version);
4112
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004113 if (ha->fce) {
4114 ha->flags.fce_enabled = 1;
4115 memset(ha->fce, 0,
4116 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004117 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004118 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4119 &ha->fce_bufs);
4120 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004121 ql_log(ql_log_warn, vha, 0x8033,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004122 "Unable to reinitialize FCE "
4123 "(%d).\n", rval);
4124 ha->flags.fce_enabled = 0;
4125 }
4126 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004127
4128 if (ha->eft) {
4129 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004130 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004131 ha->eft_dma, EFT_NUM_BUFFERS);
4132 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004133 ql_log(ql_log_warn, vha, 0x8034,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004134 "Unable to reinitialize EFT "
4135 "(%d).\n", rval);
4136 }
4137 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004139 vha->flags.online = 1;
4140 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141 if (ha->isp_abort_cnt == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004142 ql_log(ql_log_fatal, vha, 0x8035,
4143 "ISP error recover failed - "
4144 "board disabled.\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004145 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 * The next call disables the board
4147 * completely.
4148 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004149 ha->isp_ops->reset_adapter(vha);
4150 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004152 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153 status = 0;
4154 } else { /* schedule another ISP abort */
4155 ha->isp_abort_cnt--;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004156 ql_dbg(ql_dbg_taskm, vha, 0x8020,
4157 "ISP abort - retry remaining %d.\n",
4158 ha->isp_abort_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 status = 1;
4160 }
4161 } else {
4162 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004163 ql_dbg(ql_dbg_taskm, vha, 0x8021,
4164 "ISP error recovery - retrying (%d) "
4165 "more times.\n", ha->isp_abort_cnt);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004166 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167 status = 1;
4168 }
4169 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004170
Linus Torvalds1da177e2005-04-16 15:20:36 -07004171 }
4172
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004173 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004174 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
Arun Easifeafb7b2010-09-03 14:57:00 -07004175
4176 spin_lock_irqsave(&ha->vport_slock, flags);
4177 list_for_each_entry(vp, &ha->vp_list, list) {
4178 if (vp->vp_idx) {
4179 atomic_inc(&vp->vref_count);
4180 spin_unlock_irqrestore(&ha->vport_slock, flags);
4181
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004182 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004183
4184 spin_lock_irqsave(&ha->vport_slock, flags);
4185 atomic_dec(&vp->vref_count);
4186 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004187 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004188 spin_unlock_irqrestore(&ha->vport_slock, flags);
4189
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004190 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004191 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192 }
4193
4194 return(status);
4195}
4196
4197/*
4198* qla2x00_restart_isp
4199* restarts the ISP after a reset
4200*
4201* Input:
4202* ha = adapter block pointer.
4203*
4204* Returns:
4205* 0 = success
4206*/
4207static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004208qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004210 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004212 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004213 struct req_que *req = ha->req_q_map[0];
4214 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215
4216 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004217 if (qla2x00_isp_firmware(vha)) {
4218 vha->flags.online = 0;
4219 status = ha->isp_ops->chip_diag(vha);
4220 if (!status)
4221 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222 }
4223
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004224 if (!status && !(status = qla2x00_init_rings(vha))) {
4225 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004226 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004227 /* Initialize the queues in use */
4228 qla25xx_init_queues(ha);
4229
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004230 status = qla2x00_fw_ready(vha);
4231 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004232 ql_dbg(ql_dbg_taskm, vha, 0x8031,
4233 "Start configure loop status = %d.\n", status);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004234
4235 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004236 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004237
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004238 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004239 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4240 wait_time = 256;
4241 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004242 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4243 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004244 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004245 } while (!atomic_read(&vha->loop_down_timer) &&
4246 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4247 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4248 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249 }
4250
4251 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004252 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004253 status = 0;
4254
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004255 ql_dbg(ql_dbg_taskm, vha, 0x8032,
4256 "Configure loop done, status = 0x%x.\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257 }
4258 return (status);
4259}
4260
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004261static int
4262qla25xx_init_queues(struct qla_hw_data *ha)
4263{
4264 struct rsp_que *rsp = NULL;
4265 struct req_que *req = NULL;
4266 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4267 int ret = -1;
4268 int i;
4269
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004270 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004271 rsp = ha->rsp_q_map[i];
4272 if (rsp) {
4273 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004274 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004275 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004276 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
4277 "%s Rsp que: %d init failed.\n",
4278 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004279 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004280 ql_dbg(ql_dbg_init, base_vha, 0x0100,
4281 "%s Rsp que: %d inited.\n",
4282 __func__, rsp->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004283 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004284 }
4285 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004286 req = ha->req_q_map[i];
4287 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004288 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004289 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004290 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004291 if (ret != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004292 ql_dbg(ql_dbg_init, base_vha, 0x0101,
4293 "%s Req que: %d init failed.\n",
4294 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004295 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004296 ql_dbg(ql_dbg_init, base_vha, 0x0102,
4297 "%s Req que: %d inited.\n",
4298 __func__, req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004299 }
4300 }
4301 return ret;
4302}
4303
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304/*
4305* qla2x00_reset_adapter
4306* Reset adapter.
4307*
4308* Input:
4309* ha = adapter block pointer.
4310*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004311void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004312qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004313{
4314 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004315 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004316 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004318 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004319 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320
Linus Torvalds1da177e2005-04-16 15:20:36 -07004321 spin_lock_irqsave(&ha->hardware_lock, flags);
4322 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4323 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4324 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4325 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4326 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4327}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004328
4329void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004330qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004331{
4332 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004333 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004334 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4335
Giridhar Malavalia9083012010-04-12 17:59:55 -07004336 if (IS_QLA82XX(ha))
4337 return;
4338
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004339 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004340 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004341
4342 spin_lock_irqsave(&ha->hardware_lock, flags);
4343 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4344 RD_REG_DWORD(&reg->hccr);
4345 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4346 RD_REG_DWORD(&reg->hccr);
4347 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004348
4349 if (IS_NOPOLLING_TYPE(ha))
4350 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004351}
4352
David Miller4e08df32007-04-16 12:37:43 -07004353/* On sparc systems, obtain port and node WWN from firmware
4354 * properties.
4355 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004356static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4357 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004358{
4359#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004360 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004361 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004362 struct device_node *dp = pci_device_to_OF_node(pdev);
4363 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004364 int len;
4365
4366 val = of_get_property(dp, "port-wwn", &len);
4367 if (val && len >= WWN_SIZE)
4368 memcpy(nv->port_name, val, WWN_SIZE);
4369
4370 val = of_get_property(dp, "node-wwn", &len);
4371 if (val && len >= WWN_SIZE)
4372 memcpy(nv->node_name, val, WWN_SIZE);
4373#endif
4374}
4375
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004376int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004377qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004378{
David Miller4e08df32007-04-16 12:37:43 -07004379 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004380 struct init_cb_24xx *icb;
4381 struct nvram_24xx *nv;
4382 uint32_t *dptr;
4383 uint8_t *dptr1, *dptr2;
4384 uint32_t chksum;
4385 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004386 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004387
David Miller4e08df32007-04-16 12:37:43 -07004388 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004389 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004390 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004391
4392 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004393 if (ha->flags.port0) {
4394 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4395 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4396 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004397 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004398 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4399 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004400 ha->nvram_size = sizeof(struct nvram_24xx);
4401 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004402 if (IS_QLA82XX(ha))
4403 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004404
Seokmann Ju281afe12007-07-26 13:43:34 -07004405 /* Get VPD data into cache */
4406 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004407 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004408 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4409
4410 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004411 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004412 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004413 ha->nvram_size);
4414 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4415 chksum += le32_to_cpu(*dptr++);
4416
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004417 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
4418 "Contents of NVRAM\n");
4419 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
4420 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004421
4422 /* Bad NVRAM data, set defaults parameters. */
4423 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4424 || nv->id[3] != ' ' ||
4425 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4426 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004427 ql_log(ql_log_warn, vha, 0x006b,
4428 "Inconisistent NVRAM detected: checksum=0x%x id=%c "
4429 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
4430 ql_log(ql_log_warn, vha, 0x006c,
4431 "Falling back to functioning (yet invalid -- WWPN) "
4432 "defaults.\n");
David Miller4e08df32007-04-16 12:37:43 -07004433
4434 /*
4435 * Set default initialization control block.
4436 */
4437 memset(nv, 0, ha->nvram_size);
4438 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4439 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4440 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4441 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4442 nv->exchange_count = __constant_cpu_to_le16(0);
4443 nv->hard_address = __constant_cpu_to_le16(124);
4444 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004445 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004446 nv->port_name[2] = 0x00;
4447 nv->port_name[3] = 0xe0;
4448 nv->port_name[4] = 0x8b;
4449 nv->port_name[5] = 0x1c;
4450 nv->port_name[6] = 0x55;
4451 nv->port_name[7] = 0x86;
4452 nv->node_name[0] = 0x20;
4453 nv->node_name[1] = 0x00;
4454 nv->node_name[2] = 0x00;
4455 nv->node_name[3] = 0xe0;
4456 nv->node_name[4] = 0x8b;
4457 nv->node_name[5] = 0x1c;
4458 nv->node_name[6] = 0x55;
4459 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004460 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004461 nv->login_retry_count = __constant_cpu_to_le16(8);
4462 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4463 nv->login_timeout = __constant_cpu_to_le16(0);
4464 nv->firmware_options_1 =
4465 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4466 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4467 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4468 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4469 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4470 nv->efi_parameters = __constant_cpu_to_le32(0);
4471 nv->reset_delay = 5;
4472 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4473 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4474 nv->link_down_timeout = __constant_cpu_to_le16(30);
4475
4476 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004477 }
4478
4479 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004480 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004481
4482 /* Copy 1st segment. */
4483 dptr1 = (uint8_t *)icb;
4484 dptr2 = (uint8_t *)&nv->version;
4485 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4486 while (cnt--)
4487 *dptr1++ = *dptr2++;
4488
4489 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004490 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004491
4492 /* Copy 2nd segment. */
4493 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4494 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4495 cnt = (uint8_t *)&icb->reserved_3 -
4496 (uint8_t *)&icb->interrupt_delay_timer;
4497 while (cnt--)
4498 *dptr1++ = *dptr2++;
4499
4500 /*
4501 * Setup driver NVRAM options.
4502 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004503 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004504 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004505
Andrew Vasquez5341e862006-05-17 15:09:16 -07004506 /* Use alternate WWN? */
4507 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4508 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4509 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4510 }
4511
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004512 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004513 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004514 /*
4515 * Firmware will apply the following mask if the nodename was
4516 * not provided.
4517 */
4518 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4519 icb->node_name[0] &= 0xF0;
4520 }
4521
4522 /* Set host adapter parameters. */
4523 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004524 ha->flags.enable_lip_reset = 0;
4525 ha->flags.enable_lip_full_login =
4526 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4527 ha->flags.enable_target_reset =
4528 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004529 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004530 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004531
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004532 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4533 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004534
4535 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4536 sizeof(ha->fw_seriallink_options24));
4537
4538 /* save HBA serial number */
4539 ha->serial0 = icb->port_name[5];
4540 ha->serial1 = icb->port_name[6];
4541 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004542 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4543 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004544
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004545 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4546
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004547 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4548
4549 /* Set minimum login_timeout to 4 seconds. */
4550 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4551 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4552 if (le16_to_cpu(nv->login_timeout) < 4)
4553 nv->login_timeout = __constant_cpu_to_le16(4);
4554 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004555 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004556
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004557 /* Set minimum RATOV to 100 tenths of a second. */
4558 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004559
4560 ha->loop_reset_delay = nv->reset_delay;
4561
4562 /* Link Down Timeout = 0:
4563 *
4564 * When Port Down timer expires we will start returning
4565 * I/O's to OS with "DID_NO_CONNECT".
4566 *
4567 * Link Down Timeout != 0:
4568 *
4569 * The driver waits for the link to come up after link down
4570 * before returning I/Os to OS with "DID_NO_CONNECT".
4571 */
4572 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4573 ha->loop_down_abort_time =
4574 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4575 } else {
4576 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4577 ha->loop_down_abort_time =
4578 (LOOP_DOWN_TIME - ha->link_down_timeout);
4579 }
4580
4581 /* Need enough time to try and get the port back. */
4582 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4583 if (qlport_down_retry)
4584 ha->port_down_retry_count = qlport_down_retry;
4585
4586 /* Set login_retry_count */
4587 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4588 if (ha->port_down_retry_count ==
4589 le16_to_cpu(nv->port_down_retry_count) &&
4590 ha->port_down_retry_count > 3)
4591 ha->login_retry_count = ha->port_down_retry_count;
4592 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4593 ha->login_retry_count = ha->port_down_retry_count;
4594 if (ql2xloginretrycount)
4595 ha->login_retry_count = ql2xloginretrycount;
4596
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004597 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004598 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004599 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4600 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4601 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4602 le16_to_cpu(icb->interrupt_delay_timer): 2;
4603 }
4604 icb->firmware_options_2 &= __constant_cpu_to_le32(
4605 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004606 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004607 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004608 ha->zio_mode = QLA_ZIO_MODE_6;
4609
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004610 ql_log(ql_log_info, vha, 0x006f,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004611 "ZIO mode %d enabled; timer delay (%d us).\n",
4612 ha->zio_mode, ha->zio_timer * 100);
4613
4614 icb->firmware_options_2 |= cpu_to_le32(
4615 (uint32_t)ha->zio_mode);
4616 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004617 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004618 }
4619
David Miller4e08df32007-04-16 12:37:43 -07004620 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004621 ql_log(ql_log_warn, vha, 0x0070,
4622 "NVRAM configuration failed.\n");
David Miller4e08df32007-04-16 12:37:43 -07004623 }
4624 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004625}
4626
Adrian Bunk413975a2006-06-30 02:33:06 -07004627static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004628qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4629 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004630{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004631 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004632 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004633 uint32_t *dcode, dlen;
4634 uint32_t risc_addr;
4635 uint32_t risc_size;
4636 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004637 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004638 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004639
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004640 ql_dbg(ql_dbg_init, vha, 0x008b,
4641 "Loading firmware from flash (%x).\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004642
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004643 rval = QLA_SUCCESS;
4644
4645 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004646 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004647 *srisc_addr = 0;
4648
4649 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004650 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004651 for (i = 0; i < 4; i++)
4652 dcode[i] = be32_to_cpu(dcode[i]);
4653 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4654 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4655 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4656 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004657 ql_log(ql_log_fatal, vha, 0x008c,
4658 "Unable to verify the integrity of flash firmware "
4659 "image.\n");
4660 ql_log(ql_log_fatal, vha, 0x008d,
4661 "Firmware data: %08x %08x %08x %08x.\n",
4662 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004663
4664 return QLA_FUNCTION_FAILED;
4665 }
4666
4667 while (segments && rval == QLA_SUCCESS) {
4668 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004669 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004670
4671 risc_addr = be32_to_cpu(dcode[2]);
4672 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4673 risc_size = be32_to_cpu(dcode[3]);
4674
4675 fragment = 0;
4676 while (risc_size > 0 && rval == QLA_SUCCESS) {
4677 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4678 if (dlen > risc_size)
4679 dlen = risc_size;
4680
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004681 ql_dbg(ql_dbg_init, vha, 0x008e,
4682 "Loading risc segment@ risc addr %x "
4683 "number of dwords 0x%x offset 0x%x.\n",
4684 risc_addr, dlen, faddr);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004685
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004686 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004687 for (i = 0; i < dlen; i++)
4688 dcode[i] = swab32(dcode[i]);
4689
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004690 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004691 dlen);
4692 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004693 ql_log(ql_log_fatal, vha, 0x008f,
4694 "Failed to load segment %d of firmware.\n",
4695 fragment);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004696 break;
4697 }
4698
4699 faddr += dlen;
4700 risc_addr += dlen;
4701 risc_size -= dlen;
4702 fragment++;
4703 }
4704
4705 /* Next segment. */
4706 segments--;
4707 }
4708
4709 return rval;
4710}
4711
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004712#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4713
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004714int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004715qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004716{
4717 int rval;
4718 int i, fragment;
4719 uint16_t *wcode, *fwcode;
4720 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4721 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004722 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004723 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004724
4725 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004726 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004727 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004728 ql_log(ql_log_info, vha, 0x0083,
4729 "Fimware image unavailable.\n");
4730 ql_log(ql_log_info, vha, 0x0084,
4731 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004732 return QLA_FUNCTION_FAILED;
4733 }
4734
4735 rval = QLA_SUCCESS;
4736
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004737 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004738 *srisc_addr = 0;
4739 fwcode = (uint16_t *)blob->fw->data;
4740 fwclen = 0;
4741
4742 /* Validate firmware image by checking version. */
4743 if (blob->fw->size < 8 * sizeof(uint16_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004744 ql_log(ql_log_fatal, vha, 0x0085,
4745 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08004746 blob->fw->size);
4747 goto fail_fw_integrity;
4748 }
4749 for (i = 0; i < 4; i++)
4750 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4751 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4752 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4753 wcode[2] == 0 && wcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004754 ql_log(ql_log_fatal, vha, 0x0086,
4755 "Unable to verify integrity of firmware image.\n");
4756 ql_log(ql_log_fatal, vha, 0x0087,
4757 "Firmware data: %04x %04x %04x %04x.\n",
4758 wcode[0], wcode[1], wcode[2], wcode[3]);
Andrew Vasquez54333832005-11-09 15:49:04 -08004759 goto fail_fw_integrity;
4760 }
4761
4762 seg = blob->segs;
4763 while (*seg && rval == QLA_SUCCESS) {
4764 risc_addr = *seg;
4765 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4766 risc_size = be16_to_cpu(fwcode[3]);
4767
4768 /* Validate firmware image size. */
4769 fwclen += risc_size * sizeof(uint16_t);
4770 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004771 ql_log(ql_log_fatal, vha, 0x0088,
Andrew Vasquez54333832005-11-09 15:49:04 -08004772 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004773 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08004774 goto fail_fw_integrity;
4775 }
4776
4777 fragment = 0;
4778 while (risc_size > 0 && rval == QLA_SUCCESS) {
4779 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4780 if (wlen > risc_size)
4781 wlen = risc_size;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004782 ql_dbg(ql_dbg_init, vha, 0x0089,
4783 "Loading risc segment@ risc addr %x number of "
4784 "words 0x%x.\n", risc_addr, wlen);
Andrew Vasquez54333832005-11-09 15:49:04 -08004785
4786 for (i = 0; i < wlen; i++)
4787 wcode[i] = swab16(fwcode[i]);
4788
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004789 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004790 wlen);
4791 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004792 ql_log(ql_log_fatal, vha, 0x008a,
4793 "Failed to load segment %d of firmware.\n",
4794 fragment);
Andrew Vasquez54333832005-11-09 15:49:04 -08004795 break;
4796 }
4797
4798 fwcode += wlen;
4799 risc_addr += wlen;
4800 risc_size -= wlen;
4801 fragment++;
4802 }
4803
4804 /* Next segment. */
4805 seg++;
4806 }
4807 return rval;
4808
4809fail_fw_integrity:
4810 return QLA_FUNCTION_FAILED;
4811}
4812
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004813static int
4814qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004815{
4816 int rval;
4817 int segments, fragment;
4818 uint32_t *dcode, dlen;
4819 uint32_t risc_addr;
4820 uint32_t risc_size;
4821 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004822 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004823 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004824 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004825 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004826
Andrew Vasquez54333832005-11-09 15:49:04 -08004827 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004828 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004829 if (!blob) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004830 ql_log(ql_log_warn, vha, 0x0090,
4831 "Fimware image unavailable.\n");
4832 ql_log(ql_log_warn, vha, 0x0091,
4833 "Firmware images can be retrieved from: "
4834 QLA_FW_URL ".\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004835
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004836 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004837 }
4838
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004839 ql_log(ql_log_info, vha, 0x0092,
4840 "Loading via request-firmware.\n");
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004841
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004842 rval = QLA_SUCCESS;
4843
4844 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004845 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004846 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004847 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004848 fwclen = 0;
4849
4850 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004851 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004852 ql_log(ql_log_fatal, vha, 0x0093,
4853 "Unable to verify integrity of firmware image (%Zd).\n",
Andrew Vasquez54333832005-11-09 15:49:04 -08004854 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004855 goto fail_fw_integrity;
4856 }
4857 for (i = 0; i < 4; i++)
4858 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4859 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4860 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4861 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4862 dcode[3] == 0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004863 ql_log(ql_log_fatal, vha, 0x0094,
4864 "Unable to verify integrity of firmware image (%Zd).\n",
4865 blob->fw->size);
4866 ql_log(ql_log_fatal, vha, 0x0095,
4867 "Firmware data: %08x %08x %08x %08x.\n",
4868 dcode[0], dcode[1], dcode[2], dcode[3]);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004869 goto fail_fw_integrity;
4870 }
4871
4872 while (segments && rval == QLA_SUCCESS) {
4873 risc_addr = be32_to_cpu(fwcode[2]);
4874 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4875 risc_size = be32_to_cpu(fwcode[3]);
4876
4877 /* Validate firmware image size. */
4878 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004879 if (blob->fw->size < fwclen) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004880 ql_log(ql_log_fatal, vha, 0x0096,
Andrew Vasquez54333832005-11-09 15:49:04 -08004881 "Unable to verify integrity of firmware image "
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004882 "(%Zd).\n", blob->fw->size);
Andrew Vasquez54333832005-11-09 15:49:04 -08004883
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004884 goto fail_fw_integrity;
4885 }
4886
4887 fragment = 0;
4888 while (risc_size > 0 && rval == QLA_SUCCESS) {
4889 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4890 if (dlen > risc_size)
4891 dlen = risc_size;
4892
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004893 ql_dbg(ql_dbg_init, vha, 0x0097,
4894 "Loading risc segment@ risc addr %x "
4895 "number of dwords 0x%x.\n", risc_addr, dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004896
4897 for (i = 0; i < dlen; i++)
4898 dcode[i] = swab32(fwcode[i]);
4899
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004900 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004901 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004902 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004903 ql_log(ql_log_fatal, vha, 0x0098,
4904 "Failed to load segment %d of firmware.\n",
4905 fragment);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004906 break;
4907 }
4908
4909 fwcode += dlen;
4910 risc_addr += dlen;
4911 risc_size -= dlen;
4912 fragment++;
4913 }
4914
4915 /* Next segment. */
4916 segments--;
4917 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004918 return rval;
4919
4920fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004921 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004922}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004923
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004924int
4925qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4926{
4927 int rval;
4928
Andrew Vasqueze337d902009-04-06 22:33:49 -07004929 if (ql2xfwloadbin == 1)
4930 return qla81xx_load_risc(vha, srisc_addr);
4931
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004932 /*
4933 * FW Load priority:
4934 * 1) Firmware via request-firmware interface (.bin file).
4935 * 2) Firmware residing in flash.
4936 */
4937 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4938 if (rval == QLA_SUCCESS)
4939 return rval;
4940
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004941 return qla24xx_load_risc_flash(vha, srisc_addr,
4942 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004943}
4944
4945int
4946qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4947{
4948 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004949 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004950
Andrew Vasqueze337d902009-04-06 22:33:49 -07004951 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004952 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004953
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004954 /*
4955 * FW Load priority:
4956 * 1) Firmware residing in flash.
4957 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004958 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004959 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004960 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004961 if (rval == QLA_SUCCESS)
4962 return rval;
4963
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004964try_blob_fw:
4965 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4966 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4967 return rval;
4968
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004969 ql_log(ql_log_info, vha, 0x0099,
4970 "Attempting to fallback to golden firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004971 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4972 if (rval != QLA_SUCCESS)
4973 return rval;
4974
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004975 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004976 ha->flags.running_gold_fw = 1;
4977
4978 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004979}
4980
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004981void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004982qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004983{
4984 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004985 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004986
Andrew Vasquez85880802009-12-15 21:29:46 -08004987 if (ha->flags.pci_channel_io_perm_failure)
4988 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004989 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004990 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004991 if (!ha->fw_major_version)
4992 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004993
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004994 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004995 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004996 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004997 ha->isp_ops->reset_chip(vha);
4998 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004999 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005000 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005001 continue;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005002 ql_log(ql_log_info, vha, 0x8015,
5003 "Attempting retry of stop-firmware command.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005004 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07005005 }
5006}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005007
5008int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005009qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005010{
5011 int rval = QLA_SUCCESS;
5012 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005013 struct qla_hw_data *ha = vha->hw;
5014 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005015 struct req_que *req;
5016 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005017
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005018 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005019 return -EINVAL;
5020
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005021 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07005022 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005023 req = ha->req_q_map[0];
5024 else
5025 req = vha->req;
5026 rsp = req->rsp;
5027
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005028 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005029 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005030 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005031 }
5032
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005033 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005034
5035 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005036 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005037 if (mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005038 ql_dbg(ql_dbg_init, vha, 0x0103,
5039 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
5040 "mb[6]=%x mb[7]=%x.\n",
5041 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005042 return (QLA_FUNCTION_FAILED);
5043 }
5044
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005045 atomic_set(&vha->loop_down_timer, 0);
5046 atomic_set(&vha->loop_state, LOOP_UP);
5047 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5048 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5049 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005050
5051 return rval;
5052}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005053
5054/* 84XX Support **************************************************************/
5055
5056static LIST_HEAD(qla_cs84xx_list);
5057static DEFINE_MUTEX(qla_cs84xx_mutex);
5058
5059static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005060qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005061{
5062 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005063 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005064
5065 mutex_lock(&qla_cs84xx_mutex);
5066
5067 /* Find any shared 84xx chip. */
5068 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5069 if (cs84xx->bus == ha->pdev->bus) {
5070 kref_get(&cs84xx->kref);
5071 goto done;
5072 }
5073 }
5074
5075 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5076 if (!cs84xx)
5077 goto done;
5078
5079 kref_init(&cs84xx->kref);
5080 spin_lock_init(&cs84xx->access_lock);
5081 mutex_init(&cs84xx->fw_update_mutex);
5082 cs84xx->bus = ha->pdev->bus;
5083
5084 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5085done:
5086 mutex_unlock(&qla_cs84xx_mutex);
5087 return cs84xx;
5088}
5089
5090static void
5091__qla84xx_chip_release(struct kref *kref)
5092{
5093 struct qla_chip_state_84xx *cs84xx =
5094 container_of(kref, struct qla_chip_state_84xx, kref);
5095
5096 mutex_lock(&qla_cs84xx_mutex);
5097 list_del(&cs84xx->list);
5098 mutex_unlock(&qla_cs84xx_mutex);
5099 kfree(cs84xx);
5100}
5101
5102void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005103qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005104{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005105 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005106 if (ha->cs84xx)
5107 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
5108}
5109
5110static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005111qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005112{
5113 int rval;
5114 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005115 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005116
5117 mutex_lock(&ha->cs84xx->fw_update_mutex);
5118
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005119 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005120
5121 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5122
5123 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5124 QLA_SUCCESS;
5125}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005126
5127/* 81XX Support **************************************************************/
5128
5129int
5130qla81xx_nvram_config(scsi_qla_host_t *vha)
5131{
5132 int rval;
5133 struct init_cb_81xx *icb;
5134 struct nvram_81xx *nv;
5135 uint32_t *dptr;
5136 uint8_t *dptr1, *dptr2;
5137 uint32_t chksum;
5138 uint16_t cnt;
5139 struct qla_hw_data *ha = vha->hw;
5140
5141 rval = QLA_SUCCESS;
5142 icb = (struct init_cb_81xx *)ha->init_cb;
5143 nv = ha->nvram;
5144
5145 /* Determine NVRAM starting address. */
5146 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005147 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005148
5149 /* Get VPD data into cache */
5150 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005151 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5152 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005153
5154 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005155 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005156 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005157 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005158 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5159 chksum += le32_to_cpu(*dptr++);
5160
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005161 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
5162 "Contents of NVRAM:\n");
5163 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
5164 (uint8_t *)nv, ha->nvram_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005165
5166 /* Bad NVRAM data, set defaults parameters. */
5167 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5168 || nv->id[3] != ' ' ||
5169 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5170 /* Reset NVRAM data. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005171 ql_log(ql_log_info, vha, 0x0073,
5172 "Inconisistent NVRAM detected: checksum=0x%x id=%c "
5173 "version=0x%x.\n", chksum, nv->id[0],
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005174 le16_to_cpu(nv->nvram_version));
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005175 ql_log(ql_log_info, vha, 0x0074,
5176 "Falling back to functioning (yet invalid -- WWPN) "
5177 "defaults.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005178
5179 /*
5180 * Set default initialization control block.
5181 */
5182 memset(nv, 0, ha->nvram_size);
5183 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5184 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5185 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5186 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5187 nv->exchange_count = __constant_cpu_to_le16(0);
5188 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005189 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005190 nv->port_name[2] = 0x00;
5191 nv->port_name[3] = 0xe0;
5192 nv->port_name[4] = 0x8b;
5193 nv->port_name[5] = 0x1c;
5194 nv->port_name[6] = 0x55;
5195 nv->port_name[7] = 0x86;
5196 nv->node_name[0] = 0x20;
5197 nv->node_name[1] = 0x00;
5198 nv->node_name[2] = 0x00;
5199 nv->node_name[3] = 0xe0;
5200 nv->node_name[4] = 0x8b;
5201 nv->node_name[5] = 0x1c;
5202 nv->node_name[6] = 0x55;
5203 nv->node_name[7] = 0x86;
5204 nv->login_retry_count = __constant_cpu_to_le16(8);
5205 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5206 nv->login_timeout = __constant_cpu_to_le16(0);
5207 nv->firmware_options_1 =
5208 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5209 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5210 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5211 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5212 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5213 nv->efi_parameters = __constant_cpu_to_le32(0);
5214 nv->reset_delay = 5;
5215 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5216 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5217 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005218 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005219 nv->enode_mac[1] = 0x02;
5220 nv->enode_mac[2] = 0x03;
5221 nv->enode_mac[3] = 0x04;
5222 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005223 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005224
5225 rval = 1;
5226 }
5227
5228 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07005229 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005230
5231 /* Copy 1st segment. */
5232 dptr1 = (uint8_t *)icb;
5233 dptr2 = (uint8_t *)&nv->version;
5234 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5235 while (cnt--)
5236 *dptr1++ = *dptr2++;
5237
5238 icb->login_retry_count = nv->login_retry_count;
5239
5240 /* Copy 2nd segment. */
5241 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5242 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5243 cnt = (uint8_t *)&icb->reserved_5 -
5244 (uint8_t *)&icb->interrupt_delay_timer;
5245 while (cnt--)
5246 *dptr1++ = *dptr2++;
5247
5248 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5249 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5250 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
5251 icb->enode_mac[0] = 0x01;
5252 icb->enode_mac[1] = 0x02;
5253 icb->enode_mac[2] = 0x03;
5254 icb->enode_mac[3] = 0x04;
5255 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005256 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005257 }
5258
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005259 /* Use extended-initialization control block. */
5260 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5261
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005262 /*
5263 * Setup driver NVRAM options.
5264 */
5265 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005266 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005267
5268 /* Use alternate WWN? */
5269 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5270 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5271 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5272 }
5273
5274 /* Prepare nodename */
5275 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5276 /*
5277 * Firmware will apply the following mask if the nodename was
5278 * not provided.
5279 */
5280 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5281 icb->node_name[0] &= 0xF0;
5282 }
5283
5284 /* Set host adapter parameters. */
5285 ha->flags.disable_risc_code_load = 0;
5286 ha->flags.enable_lip_reset = 0;
5287 ha->flags.enable_lip_full_login =
5288 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5289 ha->flags.enable_target_reset =
5290 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5291 ha->flags.enable_led_scheme = 0;
5292 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5293
5294 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5295 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5296
5297 /* save HBA serial number */
5298 ha->serial0 = icb->port_name[5];
5299 ha->serial1 = icb->port_name[6];
5300 ha->serial2 = icb->port_name[7];
5301 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5302 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5303
5304 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5305
5306 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5307
5308 /* Set minimum login_timeout to 4 seconds. */
5309 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5310 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5311 if (le16_to_cpu(nv->login_timeout) < 4)
5312 nv->login_timeout = __constant_cpu_to_le16(4);
5313 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5314 icb->login_timeout = nv->login_timeout;
5315
5316 /* Set minimum RATOV to 100 tenths of a second. */
5317 ha->r_a_tov = 100;
5318
5319 ha->loop_reset_delay = nv->reset_delay;
5320
5321 /* Link Down Timeout = 0:
5322 *
5323 * When Port Down timer expires we will start returning
5324 * I/O's to OS with "DID_NO_CONNECT".
5325 *
5326 * Link Down Timeout != 0:
5327 *
5328 * The driver waits for the link to come up after link down
5329 * before returning I/Os to OS with "DID_NO_CONNECT".
5330 */
5331 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5332 ha->loop_down_abort_time =
5333 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5334 } else {
5335 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5336 ha->loop_down_abort_time =
5337 (LOOP_DOWN_TIME - ha->link_down_timeout);
5338 }
5339
5340 /* Need enough time to try and get the port back. */
5341 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5342 if (qlport_down_retry)
5343 ha->port_down_retry_count = qlport_down_retry;
5344
5345 /* Set login_retry_count */
5346 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5347 if (ha->port_down_retry_count ==
5348 le16_to_cpu(nv->port_down_retry_count) &&
5349 ha->port_down_retry_count > 3)
5350 ha->login_retry_count = ha->port_down_retry_count;
5351 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5352 ha->login_retry_count = ha->port_down_retry_count;
5353 if (ql2xloginretrycount)
5354 ha->login_retry_count = ql2xloginretrycount;
5355
5356 /* Enable ZIO. */
5357 if (!vha->flags.init_done) {
5358 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5359 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5360 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5361 le16_to_cpu(icb->interrupt_delay_timer): 2;
5362 }
5363 icb->firmware_options_2 &= __constant_cpu_to_le32(
5364 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5365 vha->flags.process_response_queue = 0;
5366 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5367 ha->zio_mode = QLA_ZIO_MODE_6;
5368
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005369 ql_log(ql_log_info, vha, 0x0075,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005370 "ZIO mode %d enabled; timer delay (%d us).\n",
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005371 ha->zio_mode,
5372 ha->zio_timer * 100);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005373
5374 icb->firmware_options_2 |= cpu_to_le32(
5375 (uint32_t)ha->zio_mode);
5376 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5377 vha->flags.process_response_queue = 1;
5378 }
5379
5380 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005381 ql_log(ql_log_warn, vha, 0x0076,
5382 "NVRAM configuration failed.\n");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005383 }
5384 return (rval);
5385}
5386
Giridhar Malavalia9083012010-04-12 17:59:55 -07005387int
5388qla82xx_restart_isp(scsi_qla_host_t *vha)
5389{
5390 int status, rval;
5391 uint32_t wait_time;
5392 struct qla_hw_data *ha = vha->hw;
5393 struct req_que *req = ha->req_q_map[0];
5394 struct rsp_que *rsp = ha->rsp_q_map[0];
5395 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005396 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005397
5398 status = qla2x00_init_rings(vha);
5399 if (!status) {
5400 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5401 ha->flags.chip_reset_done = 1;
5402
5403 status = qla2x00_fw_ready(vha);
5404 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005405 ql_log(ql_log_info, vha, 0x803c,
5406 "Start configure loop, status =%d.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005407
5408 /* Issue a marker after FW becomes ready. */
5409 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5410
5411 vha->flags.online = 1;
5412 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5413 wait_time = 256;
5414 do {
5415 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5416 qla2x00_configure_loop(vha);
5417 wait_time--;
5418 } while (!atomic_read(&vha->loop_down_timer) &&
5419 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5420 wait_time &&
5421 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5422 }
5423
5424 /* if no cable then assume it's good */
5425 if ((vha->device_flags & DFLG_NO_CABLE))
5426 status = 0;
5427
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005428 ql_log(ql_log_info, vha, 0x803d,
5429 "Configure loop done, status = 0x%x.\n", status);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005430 }
5431
5432 if (!status) {
5433 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5434
5435 if (!atomic_read(&vha->loop_down_timer)) {
5436 /*
5437 * Issue marker command only when we are going
5438 * to start the I/O .
5439 */
5440 vha->marker_needed = 1;
5441 }
5442
5443 vha->flags.online = 1;
5444
5445 ha->isp_ops->enable_intrs(ha);
5446
5447 ha->isp_abort_cnt = 0;
5448 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5449
Saurav Kashyap53296782011-05-10 11:30:06 -07005450 /* Update the firmware version */
Giridhar Malavali31731672011-08-16 11:31:54 -07005451 status = qla82xx_check_md_needed(vha);
Saurav Kashyap53296782011-05-10 11:30:06 -07005452
Giridhar Malavalia9083012010-04-12 17:59:55 -07005453 if (ha->fce) {
5454 ha->flags.fce_enabled = 1;
5455 memset(ha->fce, 0,
5456 fce_calc_size(ha->fce_bufs));
5457 rval = qla2x00_enable_fce_trace(vha,
5458 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5459 &ha->fce_bufs);
5460 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005461 ql_log(ql_log_warn, vha, 0x803e,
5462 "Unable to reinitialize FCE (%d).\n",
5463 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005464 ha->flags.fce_enabled = 0;
5465 }
5466 }
5467
5468 if (ha->eft) {
5469 memset(ha->eft, 0, EFT_SIZE);
5470 rval = qla2x00_enable_eft_trace(vha,
5471 ha->eft_dma, EFT_NUM_BUFFERS);
5472 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005473 ql_log(ql_log_warn, vha, 0x803f,
5474 "Unable to reinitialize EFT (%d).\n",
5475 rval);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005476 }
5477 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005478 }
5479
5480 if (!status) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005481 ql_dbg(ql_dbg_taskm, vha, 0x8040,
5482 "qla82xx_restart_isp succeeded.\n");
Arun Easifeafb7b2010-09-03 14:57:00 -07005483
5484 spin_lock_irqsave(&ha->vport_slock, flags);
5485 list_for_each_entry(vp, &ha->vp_list, list) {
5486 if (vp->vp_idx) {
5487 atomic_inc(&vp->vref_count);
5488 spin_unlock_irqrestore(&ha->vport_slock, flags);
5489
Giridhar Malavalia9083012010-04-12 17:59:55 -07005490 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07005491
5492 spin_lock_irqsave(&ha->vport_slock, flags);
5493 atomic_dec(&vp->vref_count);
5494 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005495 }
Arun Easifeafb7b2010-09-03 14:57:00 -07005496 spin_unlock_irqrestore(&ha->vport_slock, flags);
5497
Giridhar Malavalia9083012010-04-12 17:59:55 -07005498 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005499 ql_log(ql_log_warn, vha, 0x8041,
5500 "qla82xx_restart_isp **** FAILED ****.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -07005501 }
5502
5503 return status;
5504}
5505
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005506void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005507qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005508{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005509 struct qla_hw_data *ha = vha->hw;
5510
5511 if (!ql2xetsenable)
5512 return;
5513
5514 /* Enable ETS Burst. */
5515 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5516 ha->fw_options[2] |= BIT_9;
5517 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005518}
Sarang Radke09ff7012010-03-19 17:03:59 -07005519
5520/*
5521 * qla24xx_get_fcp_prio
5522 * Gets the fcp cmd priority value for the logged in port.
5523 * Looks for a match of the port descriptors within
5524 * each of the fcp prio config entries. If a match is found,
5525 * the tag (priority) value is returned.
5526 *
5527 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005528 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005529 * fcport = port structure pointer.
5530 *
5531 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005532 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005533 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005534 *
5535 * Context:
5536 * Kernel context
5537 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005538static int
Sarang Radke09ff7012010-03-19 17:03:59 -07005539qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5540{
5541 int i, entries;
5542 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005543 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005544 uint32_t pid1, pid2;
5545 uint64_t wwn1, wwn2;
5546 struct qla_fcp_prio_entry *pri_entry;
5547 struct qla_hw_data *ha = vha->hw;
5548
5549 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005550 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005551
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005552 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005553 entries = ha->fcp_prio_cfg->num_entries;
5554 pri_entry = &ha->fcp_prio_cfg->entry[0];
5555
5556 for (i = 0; i < entries; i++) {
5557 pid_match = wwn_match = 0;
5558
5559 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5560 pri_entry++;
5561 continue;
5562 }
5563
5564 /* check source pid for a match */
5565 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5566 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5567 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5568 if (pid1 == INVALID_PORT_ID)
5569 pid_match++;
5570 else if (pid1 == pid2)
5571 pid_match++;
5572 }
5573
5574 /* check destination pid for a match */
5575 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5576 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5577 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5578 if (pid1 == INVALID_PORT_ID)
5579 pid_match++;
5580 else if (pid1 == pid2)
5581 pid_match++;
5582 }
5583
5584 /* check source WWN for a match */
5585 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5586 wwn1 = wwn_to_u64(vha->port_name);
5587 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5588 if (wwn2 == (uint64_t)-1)
5589 wwn_match++;
5590 else if (wwn1 == wwn2)
5591 wwn_match++;
5592 }
5593
5594 /* check destination WWN for a match */
5595 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5596 wwn1 = wwn_to_u64(fcport->port_name);
5597 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5598 if (wwn2 == (uint64_t)-1)
5599 wwn_match++;
5600 else if (wwn1 == wwn2)
5601 wwn_match++;
5602 }
5603
5604 if (pid_match == 2 || wwn_match == 2) {
5605 /* Found a matching entry */
5606 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5607 priority = pri_entry->tag;
5608 break;
5609 }
5610
5611 pri_entry++;
5612 }
5613
5614 return priority;
5615}
5616
5617/*
5618 * qla24xx_update_fcport_fcp_prio
5619 * Activates fcp priority for the logged in fc port
5620 *
5621 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005622 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005623 * fcp = port structure pointer.
5624 *
5625 * Return:
5626 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5627 *
5628 * Context:
5629 * Kernel context.
5630 */
5631int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005632qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07005633{
5634 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005635 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005636 uint16_t mb[5];
5637
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005638 if (fcport->port_type != FCT_TARGET ||
5639 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07005640 return QLA_FUNCTION_FAILED;
5641
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005642 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005643 if (priority < 0)
5644 return QLA_FUNCTION_FAILED;
5645
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005646 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Sarang Radke09ff7012010-03-19 17:03:59 -07005647 if (ret == QLA_SUCCESS)
5648 fcport->fcp_prio = priority;
5649 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005650 ql_dbg(ql_dbg_user, vha, 0x704f,
5651 "Unable to activate fcp priority, ret=0x%x.\n", ret);
Sarang Radke09ff7012010-03-19 17:03:59 -07005652
5653 return ret;
5654}
5655
5656/*
5657 * qla24xx_update_all_fcp_prio
5658 * Activates fcp priority for all the logged in ports
5659 *
5660 * Input:
5661 * ha = adapter block pointer.
5662 *
5663 * Return:
5664 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5665 *
5666 * Context:
5667 * Kernel context.
5668 */
5669int
5670qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5671{
5672 int ret;
5673 fc_port_t *fcport;
5674
5675 ret = QLA_FUNCTION_FAILED;
5676 /* We need to set priority for all logged in ports */
5677 list_for_each_entry(fcport, &vha->vp_fcports, list)
5678 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5679
5680 return ret;
5681}