blob: c2d7bb8cd53fa8da93b804ed550445f71376c800 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Giridhar Malavalide7c5d02010-07-23 15:28:36 +05003 * Copyright (c) 2003-2010 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
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080038static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
Adrian Bunk413975a2006-06-30 02:33:06 -070039
Harihara Kadayam4d4df192008-04-03 13:13:26 -070040static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
41static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080042static int qla25xx_init_queues(struct qla_hw_data *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070043
Andrew Vasquezac280b62009-08-20 11:06:05 -070044/* SRB Extensions ---------------------------------------------------------- */
45
46static void
47qla2x00_ctx_sp_timeout(unsigned long __data)
48{
49 srb_t *sp = (srb_t *)__data;
50 struct srb_ctx *ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070051 struct srb_iocb *iocb;
Andrew Vasquezac280b62009-08-20 11:06:05 -070052 fc_port_t *fcport = sp->fcport;
53 struct qla_hw_data *ha = fcport->vha->hw;
54 struct req_que *req;
55 unsigned long flags;
56
57 spin_lock_irqsave(&ha->hardware_lock, flags);
58 req = ha->req_q_map[0];
59 req->outstanding_cmds[sp->handle] = NULL;
60 ctx = sp->ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070061 iocb = ctx->u.iocb_cmd;
62 iocb->timeout(sp);
Madhuranath Iyengar49163922010-05-04 15:01:28 -070063 iocb->free(sp);
Andrew Vasquez6ac52602010-05-28 15:08:19 -070064 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -070065}
66
Andrew Vasquez3dbe7562010-07-23 15:28:37 +050067static void
Andrew Vasquezac280b62009-08-20 11:06:05 -070068qla2x00_ctx_sp_free(srb_t *sp)
69{
70 struct srb_ctx *ctx = sp->ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070071 struct srb_iocb *iocb = ctx->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -070072
Madhuranath Iyengar49163922010-05-04 15:01:28 -070073 del_timer_sync(&iocb->timer);
74 kfree(iocb);
Andrew Vasquezac280b62009-08-20 11:06:05 -070075 kfree(ctx);
76 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
77}
78
79inline srb_t *
80qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
81 unsigned long tmo)
82{
83 srb_t *sp;
84 struct qla_hw_data *ha = vha->hw;
85 struct srb_ctx *ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070086 struct srb_iocb *iocb;
Andrew Vasquezac280b62009-08-20 11:06:05 -070087
88 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
89 if (!sp)
90 goto done;
91 ctx = kzalloc(size, GFP_KERNEL);
92 if (!ctx) {
93 mempool_free(sp, ha->srb_mempool);
Madhuranath Iyengar49163922010-05-04 15:01:28 -070094 sp = NULL;
95 goto done;
96 }
97 iocb = kzalloc(sizeof(struct srb_iocb), GFP_KERNEL);
98 if (!iocb) {
99 mempool_free(sp, ha->srb_mempool);
100 sp = NULL;
101 kfree(ctx);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700102 goto done;
103 }
104
105 memset(sp, 0, sizeof(*sp));
106 sp->fcport = fcport;
107 sp->ctx = ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700108 ctx->u.iocb_cmd = iocb;
109 iocb->free = qla2x00_ctx_sp_free;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700110
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700111 init_timer(&iocb->timer);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700112 if (!tmo)
113 goto done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700114 iocb->timer.expires = jiffies + tmo * HZ;
115 iocb->timer.data = (unsigned long)sp;
116 iocb->timer.function = qla2x00_ctx_sp_timeout;
117 add_timer(&iocb->timer);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700118done:
119 return sp;
120}
121
122/* Asynchronous Login/Logout Routines -------------------------------------- */
123
Andrew Vasquez5b914902010-05-28 15:08:30 -0700124static inline unsigned long
125qla2x00_get_async_timeout(struct scsi_qla_host *vha)
126{
127 unsigned long tmo;
128 struct qla_hw_data *ha = vha->hw;
129
130 /* Firmware should use switch negotiated r_a_tov for timeout. */
131 tmo = ha->r_a_tov / 10 * 2;
132 if (!IS_FWI2_CAPABLE(ha)) {
133 /*
134 * Except for earlier ISPs where the timeout is seeded from the
135 * initialization control block.
136 */
137 tmo = ha->login_timeout;
138 }
139 return tmo;
140}
Andrew Vasquezac280b62009-08-20 11:06:05 -0700141
142static void
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700143qla2x00_async_iocb_timeout(srb_t *sp)
Andrew Vasquezac280b62009-08-20 11:06:05 -0700144{
145 fc_port_t *fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700146 struct srb_ctx *ctx = sp->ctx;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700147
148 DEBUG2(printk(KERN_WARNING
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -0700149 "scsi(%ld:%x): Async-%s timeout - portid=%02x%02x%02x.\n",
150 fcport->vha->host_no, sp->handle,
151 ctx->name, fcport->d_id.b.domain,
152 fcport->d_id.b.area, fcport->d_id.b.al_pa));
Andrew Vasquezac280b62009-08-20 11:06:05 -0700153
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700154 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700155 if (ctx->type == SRB_LOGIN_CMD) {
156 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700157 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700158 /* Retry as needed. */
159 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
160 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
161 QLA_LOGIO_LOGIN_RETRIED : 0;
162 qla2x00_post_async_login_done_work(fcport->vha, fcport,
163 lio->u.logio.data);
164 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700165}
166
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700167static void
168qla2x00_async_login_ctx_done(srb_t *sp)
169{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700170 struct srb_ctx *ctx = sp->ctx;
171 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700172
173 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700174 lio->u.logio.data);
175 lio->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700176}
177
Andrew Vasquezac280b62009-08-20 11:06:05 -0700178int
179qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
180 uint16_t *data)
181{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700182 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700183 struct srb_ctx *ctx;
184 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700185 int rval;
186
187 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700188 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700189 qla2x00_get_async_timeout(vha) + 2);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700190 if (!sp)
191 goto done;
192
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700193 ctx = sp->ctx;
194 ctx->type = SRB_LOGIN_CMD;
195 ctx->name = "login";
196 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700197 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700198 lio->done = qla2x00_async_login_ctx_done;
199 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700200 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700201 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700202 rval = qla2x00_start_sp(sp);
203 if (rval != QLA_SUCCESS)
204 goto done_free_sp;
205
206 DEBUG2(printk(KERN_DEBUG
207 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
208 "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
209 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
210 fcport->login_retry));
211 return rval;
212
213done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700214 lio->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700215done:
216 return rval;
217}
218
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700219static void
220qla2x00_async_logout_ctx_done(srb_t *sp)
221{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700222 struct srb_ctx *ctx = sp->ctx;
223 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700224
225 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700226 lio->u.logio.data);
227 lio->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700228}
229
Andrew Vasquezac280b62009-08-20 11:06:05 -0700230int
231qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
232{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700233 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700234 struct srb_ctx *ctx;
235 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700236 int rval;
237
238 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700239 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700240 qla2x00_get_async_timeout(vha) + 2);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700241 if (!sp)
242 goto done;
243
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700244 ctx = sp->ctx;
245 ctx->type = SRB_LOGOUT_CMD;
246 ctx->name = "logout";
247 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700248 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700249 lio->done = qla2x00_async_logout_ctx_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700250 rval = qla2x00_start_sp(sp);
251 if (rval != QLA_SUCCESS)
252 goto done_free_sp;
253
254 DEBUG2(printk(KERN_DEBUG
255 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
256 fcport->vha->host_no, sp->handle, fcport->loop_id,
257 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
258 return rval;
259
260done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700261 lio->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700262done:
263 return rval;
264}
265
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700266static void
267qla2x00_async_adisc_ctx_done(srb_t *sp)
268{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700269 struct srb_ctx *ctx = sp->ctx;
270 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700271
272 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700273 lio->u.logio.data);
274 lio->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700275}
276
277int
278qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
279 uint16_t *data)
280{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700281 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700282 struct srb_ctx *ctx;
283 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700284 int rval;
285
286 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700287 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700288 qla2x00_get_async_timeout(vha) + 2);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700289 if (!sp)
290 goto done;
291
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700292 ctx = sp->ctx;
293 ctx->type = SRB_ADISC_CMD;
294 ctx->name = "adisc";
295 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700296 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700297 lio->done = qla2x00_async_adisc_ctx_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700298 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700299 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700300 rval = qla2x00_start_sp(sp);
301 if (rval != QLA_SUCCESS)
302 goto done_free_sp;
303
304 DEBUG2(printk(KERN_DEBUG
305 "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n",
306 fcport->vha->host_no, sp->handle, fcport->loop_id,
307 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
308
309 return rval;
310
311done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700312 lio->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700313done:
314 return rval;
315}
316
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700317static void
318qla2x00_async_tm_cmd_ctx_done(srb_t *sp)
319{
320 struct srb_ctx *ctx = sp->ctx;
321 struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd;
322
323 qla2x00_async_tm_cmd_done(sp->fcport->vha, sp->fcport, iocb);
324 iocb->free(sp);
325}
326
327int
328qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
329 uint32_t tag)
330{
331 struct scsi_qla_host *vha = fcport->vha;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700332 srb_t *sp;
333 struct srb_ctx *ctx;
334 struct srb_iocb *tcf;
335 int rval;
336
337 rval = QLA_FUNCTION_FAILED;
338 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700339 qla2x00_get_async_timeout(vha) + 2);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700340 if (!sp)
341 goto done;
342
343 ctx = sp->ctx;
344 ctx->type = SRB_TM_CMD;
345 ctx->name = "tmf";
346 tcf = ctx->u.iocb_cmd;
347 tcf->u.tmf.flags = flags;
348 tcf->u.tmf.lun = lun;
349 tcf->u.tmf.data = tag;
350 tcf->timeout = qla2x00_async_iocb_timeout;
351 tcf->done = qla2x00_async_tm_cmd_ctx_done;
352
353 rval = qla2x00_start_sp(sp);
354 if (rval != QLA_SUCCESS)
355 goto done_free_sp;
356
357 DEBUG2(printk(KERN_DEBUG
358 "scsi(%ld:%x): Async-tmf - loop-id=%x portid=%02x%02x%02x.\n",
359 fcport->vha->host_no, sp->handle, fcport->loop_id,
360 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
361
362 return rval;
363
364done_free_sp:
365 tcf->free(sp);
366done:
367 return rval;
368}
369
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700370void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700371qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
372 uint16_t *data)
373{
374 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700375
376 switch (data[0]) {
377 case MBS_COMMAND_COMPLETE:
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700378 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700379 fcport->flags |= FCF_ASYNC_SENT;
380 qla2x00_post_async_adisc_work(vha, fcport, data);
381 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700382 }
383 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700384 break;
385 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700386 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700387 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
388 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
389 else
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700390 qla2x00_mark_device_lost(vha, fcport, 1, 1);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700391 break;
392 case MBS_PORT_ID_USED:
393 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700394 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700395 qla2x00_post_async_login_work(vha, fcport, NULL);
396 break;
397 case MBS_LOOP_ID_USED:
398 fcport->loop_id++;
399 rval = qla2x00_find_new_loop_id(vha, fcport);
400 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700401 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700402 qla2x00_mark_device_lost(vha, fcport, 1, 1);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700403 break;
404 }
405 qla2x00_post_async_login_work(vha, fcport, NULL);
406 break;
407 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700408 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700409}
410
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700411void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700412qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
413 uint16_t *data)
414{
415 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700416 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700417}
418
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700419void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700420qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
421 uint16_t *data)
422{
423 if (data[0] == MBS_COMMAND_COMPLETE) {
424 qla2x00_update_fcport(vha, fcport);
425
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700426 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700427 }
428
429 /* Retry login. */
430 fcport->flags &= ~FCF_ASYNC_SENT;
431 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
432 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
433 else
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700434 qla2x00_mark_device_lost(vha, fcport, 1, 1);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700435
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700436 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700437}
438
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700439void
440qla2x00_async_tm_cmd_done(struct scsi_qla_host *vha, fc_port_t *fcport,
441 struct srb_iocb *iocb)
442{
443 int rval;
444 uint32_t flags;
445 uint16_t lun;
446
447 flags = iocb->u.tmf.flags;
448 lun = (uint16_t)iocb->u.tmf.lun;
449
450 /* Issue Marker IOCB */
Giridhar Malavalid94d10e2010-07-23 15:28:23 +0500451 rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
452 vha->hw->rsp_q_map[0], fcport->loop_id, lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700453 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
454
455 if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
456 DEBUG2_3_11(printk(KERN_WARNING
457 "%s(%ld): TM IOCB failed (%x).\n",
458 __func__, vha->host_no, rval));
459 }
460
461 return;
462}
463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464/****************************************************************************/
465/* QLogic ISP2x00 Hardware Support Functions. */
466/****************************************************************************/
467
468/*
469* qla2x00_initialize_adapter
470* Initialize board.
471*
472* Input:
473* ha = adapter block pointer.
474*
475* Returns:
476* 0 = success
477*/
478int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800479qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
481 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800482 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800483 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800486 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700487 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800488 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800489 ha->flags.pci_channel_io_perm_failure = 0;
490 ha->flags.eeh_busy = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800491 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
492 atomic_set(&vha->loop_state, LOOP_DOWN);
493 vha->device_flags = DFLG_NO_CABLE;
494 vha->dpc_flags = 0;
495 vha->flags.management_server_logged_in = 0;
496 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 ha->isp_abort_cnt = 0;
498 ha->beacon_blink_led = 0;
499
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800500 set_bit(0, ha->req_qid_map);
501 set_bit(0, ha->rsp_qid_map);
502
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700503 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800504 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -0800506 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800507 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 return (rval);
509 }
510
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800511 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800513 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700514 if (rval) {
515 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800516 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700517 return (rval);
518 }
519
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800520 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -0800521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700523
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800524 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700526 if (ha->flags.disable_serdes) {
527 /* Mask HBA via NVRAM settings? */
528 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
529 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800530 vha->port_name[0], vha->port_name[1],
531 vha->port_name[2], vha->port_name[3],
532 vha->port_name[4], vha->port_name[5],
533 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700534 return QLA_FUNCTION_FAILED;
535 }
536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
538
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800539 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
540 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800541 if (rval)
542 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800543 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800544 if (rval)
545 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700547
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700548 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800549 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700550 if (!ha->cs84xx) {
551 qla_printk(KERN_ERR, ha,
552 "Unable to configure ISP84XX.\n");
553 return QLA_FUNCTION_FAILED;
554 }
555 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800556 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700557 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800559 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700560 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800561 rval = qla84xx_init_chip(vha);
562 if (rval != QLA_SUCCESS) {
563 qla_printk(KERN_ERR, ha,
564 "Unable to initialize ISP84XX.\n");
565 qla84xx_put_chip(vha);
566 }
567 }
568
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500569 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
570 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 return (rval);
573}
574
575/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700576 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 * @ha: HA context
578 *
579 * Returns 0 on success.
580 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700581int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800582qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700584 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700585 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800586 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700587 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700590 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700593 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
595
Andrew Vasquez737faec2008-10-24 15:13:45 -0700596 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700598 /* Get PCI bus information. */
599 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700600 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700601 spin_unlock_irqrestore(&ha->hardware_lock, flags);
602
603 return QLA_SUCCESS;
604}
605
606/**
607 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
608 * @ha: HA context
609 *
610 * Returns 0 on success.
611 */
612int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800613qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700614{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700615 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700616 unsigned long flags = 0;
617 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800618 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700619 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700620
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700621 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700622 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700623
624 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700625 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700626
627 if (IS_QLA2322(ha) || IS_QLA6322(ha))
628 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700629 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700630
631 /*
632 * If this is a 2300 card and not 2312, reset the
633 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
634 * the 2310 also reports itself as a 2300 so we need to get the
635 * fb revision level -- a 6 indicates it really is a 2300 and
636 * not a 2310.
637 */
638 if (IS_QLA2300(ha)) {
639 spin_lock_irqsave(&ha->hardware_lock, flags);
640
641 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700642 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700643 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700644 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700645 break;
646
647 udelay(10);
648 }
649
650 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700651 WRT_REG_WORD(&reg->ctrl_status, 0x20);
652 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700653
654 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700655 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700656
657 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700658 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700659
660 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700661 WRT_REG_WORD(&reg->ctrl_status, 0x0);
662 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700663
664 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700665 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700666 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700667 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700668 break;
669
670 udelay(10);
671 }
672
673 spin_unlock_irqrestore(&ha->hardware_lock, flags);
674 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700675
676 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
677
Andrew Vasquez737faec2008-10-24 15:13:45 -0700678 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700679
680 /* Get PCI bus information. */
681 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700682 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700683 spin_unlock_irqrestore(&ha->hardware_lock, flags);
684
685 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686}
687
688/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700689 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
690 * @ha: HA context
691 *
692 * Returns 0 on success.
693 */
694int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800695qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700696{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700697 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700698 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800699 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700700 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700701
702 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700703 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700704
705 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700706 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700707 w &= ~PCI_COMMAND_INTX_DISABLE;
708 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
709
710 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
711
712 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700713 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
714 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700715
716 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700717 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
718 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700719
Andrew Vasquez737faec2008-10-24 15:13:45 -0700720 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700721
Auke Kok44c10132007-06-08 15:46:36 -0700722 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800723
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700724 /* Get PCI bus information. */
725 spin_lock_irqsave(&ha->hardware_lock, flags);
726 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
727 spin_unlock_irqrestore(&ha->hardware_lock, flags);
728
729 return QLA_SUCCESS;
730}
731
732/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700733 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
734 * @ha: HA context
735 *
736 * Returns 0 on success.
737 */
738int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800739qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700740{
741 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800742 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700743
744 pci_set_master(ha->pdev);
745 pci_try_set_mwi(ha->pdev);
746
747 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
748 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
749 w &= ~PCI_COMMAND_INTX_DISABLE;
750 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
751
752 /* PCIe -- adjust Maximum Read Request Size (2048). */
753 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
754 pcie_set_readrq(ha->pdev, 2048);
755
Andrew Vasquez737faec2008-10-24 15:13:45 -0700756 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700757
758 ha->chip_revision = ha->pdev->revision;
759
760 return QLA_SUCCESS;
761}
762
763/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 * qla2x00_isp_firmware() - Choose firmware image.
765 * @ha: HA context
766 *
767 * Returns 0 on success.
768 */
769static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800770qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771{
772 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700773 uint16_t loop_id, topo, sw_cap;
774 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800775 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
777 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700778 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
780 if (ha->flags.disable_risc_code_load) {
781 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800782 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
784
785 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800786 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700787 if (rval == QLA_SUCCESS) {
788 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800789 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700790 &area, &domain, &topo, &sw_cap);
791 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 }
793
794 if (rval) {
795 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800796 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 }
798
799 return (rval);
800}
801
802/**
803 * qla2x00_reset_chip() - Reset ISP chip.
804 * @ha: HA context
805 *
806 * Returns 0 on success.
807 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700808void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800809qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810{
811 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800812 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700813 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 uint16_t cmd;
816
Andrew Vasquez85880802009-12-15 21:29:46 -0800817 if (unlikely(pci_channel_offline(ha->pdev)))
818 return;
819
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700820 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822 spin_lock_irqsave(&ha->hardware_lock, flags);
823
824 /* Turn off master enable */
825 cmd = 0;
826 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
827 cmd &= ~PCI_COMMAND_MASTER;
828 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
829
830 if (!IS_QLA2100(ha)) {
831 /* Pause RISC. */
832 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
833 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
834 for (cnt = 0; cnt < 30000; cnt++) {
835 if ((RD_REG_WORD(&reg->hccr) &
836 HCCR_RISC_PAUSE) != 0)
837 break;
838 udelay(100);
839 }
840 } else {
841 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
842 udelay(10);
843 }
844
845 /* Select FPM registers. */
846 WRT_REG_WORD(&reg->ctrl_status, 0x20);
847 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
848
849 /* FPM Soft Reset. */
850 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
851 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
852
853 /* Toggle Fpm Reset. */
854 if (!IS_QLA2200(ha)) {
855 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
856 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
857 }
858
859 /* Select frame buffer registers. */
860 WRT_REG_WORD(&reg->ctrl_status, 0x10);
861 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
862
863 /* Reset frame buffer FIFOs. */
864 if (IS_QLA2200(ha)) {
865 WRT_FB_CMD_REG(ha, reg, 0xa000);
866 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
867 } else {
868 WRT_FB_CMD_REG(ha, reg, 0x00fc);
869
870 /* Read back fb_cmd until zero or 3 seconds max */
871 for (cnt = 0; cnt < 3000; cnt++) {
872 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
873 break;
874 udelay(100);
875 }
876 }
877
878 /* Select RISC module registers. */
879 WRT_REG_WORD(&reg->ctrl_status, 0);
880 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
881
882 /* Reset RISC processor. */
883 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
884 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
885
886 /* Release RISC processor. */
887 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
888 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
889 }
890
891 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
892 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
893
894 /* Reset ISP chip. */
895 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
896
897 /* Wait for RISC to recover from reset. */
898 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
899 /*
900 * It is necessary to for a delay here since the card doesn't
901 * respond to PCI reads during a reset. On some architectures
902 * this will result in an MCA.
903 */
904 udelay(20);
905 for (cnt = 30000; cnt; cnt--) {
906 if ((RD_REG_WORD(&reg->ctrl_status) &
907 CSR_ISP_SOFT_RESET) == 0)
908 break;
909 udelay(100);
910 }
911 } else
912 udelay(10);
913
914 /* Reset RISC processor. */
915 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
916
917 WRT_REG_WORD(&reg->semaphore, 0);
918
919 /* Release RISC processor. */
920 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
921 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
922
923 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
924 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700925 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928 udelay(100);
929 }
930 } else
931 udelay(100);
932
933 /* Turn on master enable */
934 cmd |= PCI_COMMAND_MASTER;
935 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
936
937 /* Disable RISC pause on FPM parity error. */
938 if (!IS_QLA2100(ha)) {
939 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
940 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
941 }
942
943 spin_unlock_irqrestore(&ha->hardware_lock, flags);
944}
945
946/**
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700947 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
948 *
949 * Returns 0 on success.
950 */
951int
952qla81xx_reset_mpi(scsi_qla_host_t *vha)
953{
954 uint16_t mb[4] = {0x1010, 0, 1, 0};
955
956 return qla81xx_write_mpi_register(vha, mb);
957}
958
959/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700960 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700961 * @ha: HA context
962 *
963 * Returns 0 on success.
964 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700965static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800966qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700967{
968 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800969 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700970 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
971 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800972 uint16_t wd;
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700973 static int abts_cnt; /* ISP abort retry counts */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700974
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700975 spin_lock_irqsave(&ha->hardware_lock, flags);
976
977 /* Reset RISC. */
978 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
979 for (cnt = 0; cnt < 30000; cnt++) {
980 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
981 break;
982
983 udelay(10);
984 }
985
986 WRT_REG_DWORD(&reg->ctrl_status,
987 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800988 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700989
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800990 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700991 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700992 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
993 for (cnt = 10000 ; cnt && d2; cnt--) {
994 udelay(5);
995 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
996 barrier();
997 }
998
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800999 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001000 d2 = RD_REG_DWORD(&reg->ctrl_status);
1001 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1002 udelay(5);
1003 d2 = RD_REG_DWORD(&reg->ctrl_status);
1004 barrier();
1005 }
1006
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001007 /* If required, do an MPI FW reset now */
1008 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1009 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1010 if (++abts_cnt < 5) {
1011 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1012 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1013 } else {
1014 /*
1015 * We exhausted the ISP abort retries. We have to
1016 * set the board offline.
1017 */
1018 abts_cnt = 0;
1019 vha->flags.online = 0;
1020 }
1021 }
1022 }
1023
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001024 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1025 RD_REG_DWORD(&reg->hccr);
1026
1027 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1028 RD_REG_DWORD(&reg->hccr);
1029
1030 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1031 RD_REG_DWORD(&reg->hccr);
1032
1033 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1034 for (cnt = 6000000 ; cnt && d2; cnt--) {
1035 udelay(5);
1036 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1037 barrier();
1038 }
1039
1040 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001041
1042 if (IS_NOPOLLING_TYPE(ha))
1043 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001044}
1045
1046/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001047 * qla24xx_reset_chip() - Reset ISP24xx chip.
1048 * @ha: HA context
1049 *
1050 * Returns 0 on success.
1051 */
1052void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001053qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001054{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001055 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001056
1057 if (pci_channel_offline(ha->pdev) &&
1058 ha->flags.pci_channel_io_perm_failure) {
1059 return;
1060 }
1061
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001062 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001063
1064 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001065 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001066}
1067
1068/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 * qla2x00_chip_diag() - Test chip for proper operation.
1070 * @ha: HA context
1071 *
1072 * Returns 0 on success.
1073 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001074int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001075qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076{
1077 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001078 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001079 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 unsigned long flags = 0;
1081 uint16_t data;
1082 uint32_t cnt;
1083 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001084 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
1086 /* Assume a failed state */
1087 rval = QLA_FUNCTION_FAILED;
1088
1089 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001090 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
1092 spin_lock_irqsave(&ha->hardware_lock, flags);
1093
1094 /* Reset ISP chip. */
1095 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1096
1097 /*
1098 * We need to have a delay here since the card will not respond while
1099 * in reset causing an MCA on some architectures.
1100 */
1101 udelay(20);
1102 data = qla2x00_debounce_register(&reg->ctrl_status);
1103 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1104 udelay(5);
1105 data = RD_REG_WORD(&reg->ctrl_status);
1106 barrier();
1107 }
1108
1109 if (!cnt)
1110 goto chip_diag_failed;
1111
1112 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07001113 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
1115 /* Reset RISC processor. */
1116 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1117 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1118
1119 /* Workaround for QLA2312 PCI parity error */
1120 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1121 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1122 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1123 udelay(5);
1124 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001125 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 }
1127 } else
1128 udelay(10);
1129
1130 if (!cnt)
1131 goto chip_diag_failed;
1132
1133 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -07001134 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
1136 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1137 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1138 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1139 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1140 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1141 mb[3] != PROD_ID_3) {
1142 qla_printk(KERN_WARNING, ha,
1143 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
1144
1145 goto chip_diag_failed;
1146 }
1147 ha->product_id[0] = mb[1];
1148 ha->product_id[1] = mb[2];
1149 ha->product_id[2] = mb[3];
1150 ha->product_id[3] = mb[4];
1151
1152 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001153 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1155 else
1156 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001157 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
1159 if (IS_QLA2200(ha) &&
1160 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1161 /* Limit firmware transfer size with a 2200A */
1162 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001163 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001165 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 ha->fw_transfer_size = 128;
1167 }
1168
1169 /* Wrap Incoming Mailboxes Test. */
1170 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1171
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001172 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
1173 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 if (rval) {
1175 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001176 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 qla_printk(KERN_WARNING, ha,
1178 "Failed mailbox send register test\n");
1179 }
1180 else {
1181 /* Flag a successful rval */
1182 rval = QLA_SUCCESS;
1183 }
1184 spin_lock_irqsave(&ha->hardware_lock, flags);
1185
1186chip_diag_failed:
1187 if (rval)
1188 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001189 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
1191 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1192
1193 return (rval);
1194}
1195
1196/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001197 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1198 * @ha: HA context
1199 *
1200 * Returns 0 on success.
1201 */
1202int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001203qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001204{
1205 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001206 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001207 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001208
Giridhar Malavalia9083012010-04-12 17:59:55 -07001209 if (IS_QLA82XX(ha))
1210 return QLA_SUCCESS;
1211
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001212 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001213
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001214 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001215 if (rval) {
1216 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001217 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001218 qla_printk(KERN_WARNING, ha,
1219 "Failed mailbox send register test\n");
1220 } else {
1221 /* Flag a successful rval */
1222 rval = QLA_SUCCESS;
1223 }
1224
1225 return rval;
1226}
1227
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001228void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001229qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001230{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001231 int rval;
1232 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001233 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001234 dma_addr_t tc_dma;
1235 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001236 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001237 struct req_que *req = ha->req_q_map[0];
1238 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001239
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001240 if (ha->fw_dump) {
1241 qla_printk(KERN_WARNING, ha,
1242 "Firmware dump previously allocated.\n");
1243 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001244 }
1245
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001246 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001247 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001248 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1249 fixed_size = sizeof(struct qla2100_fw_dump);
1250 } else if (IS_QLA23XX(ha)) {
1251 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1252 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1253 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001254 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001255 if (IS_QLA81XX(ha))
1256 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1257 else if (IS_QLA25XX(ha))
1258 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1259 else
1260 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001261 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1262 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001263 if (ha->mqenable)
1264 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001265 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001266 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001267 goto try_eft;
1268
1269 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1270 GFP_KERNEL);
1271 if (!tc) {
1272 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1273 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001274 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001275 }
1276
1277 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001278 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001279 ha->fce_mb, &ha->fce_bufs);
1280 if (rval) {
1281 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1282 "FCE (%d).\n", rval);
1283 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1284 tc_dma);
1285 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001286 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001287 }
1288
1289 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1290 FCE_SIZE / 1024);
1291
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001292 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001293 ha->flags.fce_enabled = 1;
1294 ha->fce_dma = tc_dma;
1295 ha->fce = tc;
1296try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001297 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001298 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001299 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001300 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001301 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1302 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1303 goto cont_alloc;
1304 }
1305
Andrew Vasquezfc447652008-01-17 09:02:18 -08001306 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001307 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001308 if (rval) {
1309 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1310 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001311 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1312 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001313 goto cont_alloc;
1314 }
1315
1316 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1317 EFT_SIZE / 1024);
1318
1319 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001320 ha->eft_dma = tc_dma;
1321 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001322 }
1323cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001324 req_q_size = req->length * sizeof(request_t);
1325 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001326
1327 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001328 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001329 ha->chain_offset = dump_size;
1330 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001331
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001332 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001333 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001334 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001335 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001336
1337 if (ha->eft) {
1338 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1339 ha->eft_dma);
1340 ha->eft = NULL;
1341 ha->eft_dma = 0;
1342 }
1343 return;
1344 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001345 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1346 dump_size / 1024);
1347
1348 ha->fw_dump_len = dump_size;
1349 ha->fw_dump->signature[0] = 'Q';
1350 ha->fw_dump->signature[1] = 'L';
1351 ha->fw_dump->signature[2] = 'G';
1352 ha->fw_dump->signature[3] = 'C';
1353 ha->fw_dump->version = __constant_htonl(1);
1354
1355 ha->fw_dump->fixed_size = htonl(fixed_size);
1356 ha->fw_dump->mem_size = htonl(mem_size);
1357 ha->fw_dump->req_q_size = htonl(req_q_size);
1358 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1359
1360 ha->fw_dump->eft_size = htonl(eft_size);
1361 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1362 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1363
1364 ha->fw_dump->header_size =
1365 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001366}
1367
Andrew Vasquez18e75552009-06-03 09:55:30 -07001368static int
1369qla81xx_mpi_sync(scsi_qla_host_t *vha)
1370{
1371#define MPS_MASK 0xe0
1372 int rval;
1373 uint16_t dc;
1374 uint32_t dw;
1375 struct qla_hw_data *ha = vha->hw;
1376
1377 if (!IS_QLA81XX(vha->hw))
1378 return QLA_SUCCESS;
1379
1380 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1381 if (rval != QLA_SUCCESS) {
1382 DEBUG2(qla_printk(KERN_WARNING, ha,
1383 "Sync-MPI: Unable to acquire semaphore.\n"));
1384 goto done;
1385 }
1386
1387 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1388 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1389 if (rval != QLA_SUCCESS) {
1390 DEBUG2(qla_printk(KERN_WARNING, ha,
1391 "Sync-MPI: Unable to read sync.\n"));
1392 goto done_release;
1393 }
1394
1395 dc &= MPS_MASK;
1396 if (dc == (dw & MPS_MASK))
1397 goto done_release;
1398
1399 dw &= ~MPS_MASK;
1400 dw |= dc;
1401 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1402 if (rval != QLA_SUCCESS) {
1403 DEBUG2(qla_printk(KERN_WARNING, ha,
1404 "Sync-MPI: Unable to gain sync.\n"));
1405 }
1406
1407done_release:
1408 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1409 if (rval != QLA_SUCCESS) {
1410 DEBUG2(qla_printk(KERN_WARNING, ha,
1411 "Sync-MPI: Unable to release semaphore.\n"));
1412 }
1413
1414done:
1415 return rval;
1416}
1417
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001418/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 * qla2x00_setup_chip() - Load and start RISC firmware.
1420 * @ha: HA context
1421 *
1422 * Returns 0 on success.
1423 */
1424static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001425qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001427 int rval;
1428 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001429 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001430 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1431 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001432 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001433
Giridhar Malavalia9083012010-04-12 17:59:55 -07001434 if (IS_QLA82XX(ha)) {
1435 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001436 if (rval == QLA_SUCCESS) {
1437 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001438 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001439 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001440 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001441 }
1442
Andrew Vasquez3db06522008-01-31 12:33:49 -08001443 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1444 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1445 spin_lock_irqsave(&ha->hardware_lock, flags);
1446 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1447 RD_REG_WORD(&reg->hccr);
1448 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Andrew Vasquez18e75552009-06-03 09:55:30 -07001451 qla81xx_mpi_sync(vha);
1452
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001454 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001455 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001457 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001459 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 if (rval == QLA_SUCCESS) {
1461 /* Start firmware execution. */
1462 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001463 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001465 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001467 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001468enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001469 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001470 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 &ha->fw_major_version,
1472 &ha->fw_minor_version,
1473 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001474 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001475 ha->mpi_version, &ha->mpi_capabilities,
1476 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001477 if (rval != QLA_SUCCESS)
1478 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001479 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001480 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001481 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001482 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001483 if ((!ha->max_npiv_vports) ||
1484 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001485 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001486 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001487 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001488 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001489 qla2x00_get_resource_cnts(vha, NULL,
1490 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001491 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001492
Giridhar Malavalia9083012010-04-12 17:59:55 -07001493 if (!fw_major_version && ql2xallocfwdump) {
1494 if (!IS_QLA82XX(ha))
1495 qla2x00_alloc_fw_dump(vha);
1496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 }
1498 } else {
1499 DEBUG2(printk(KERN_INFO
1500 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001501 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 }
1503 }
1504
Andrew Vasquez3db06522008-01-31 12:33:49 -08001505 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1506 /* Enable proper parity. */
1507 spin_lock_irqsave(&ha->hardware_lock, flags);
1508 if (IS_QLA2300(ha))
1509 /* SRAM parity */
1510 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1511 else
1512 /* SRAM, Instruction RAM and GP RAM parity */
1513 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1514 RD_REG_WORD(&reg->hccr);
1515 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1516 }
1517
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001518 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1519 uint32_t size;
1520
1521 rval = qla81xx_fac_get_sector_size(vha, &size);
1522 if (rval == QLA_SUCCESS) {
1523 ha->flags.fac_supported = 1;
1524 ha->fdt_block_size = size << 2;
1525 } else {
1526 qla_printk(KERN_ERR, ha,
1527 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1528 ha->fw_major_version, ha->fw_minor_version,
1529 ha->fw_subminor_version);
1530 }
1531 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001532failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 if (rval) {
1534 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001535 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 }
1537
1538 return (rval);
1539}
1540
1541/**
1542 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1543 * @ha: HA context
1544 *
1545 * Beginning of request ring has initialization control block already built
1546 * by nvram config routine.
1547 *
1548 * Returns 0 on success.
1549 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001550void
1551qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552{
1553 uint16_t cnt;
1554 response_t *pkt;
1555
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001556 rsp->ring_ptr = rsp->ring;
1557 rsp->ring_index = 0;
1558 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001559 pkt = rsp->ring_ptr;
1560 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 pkt->signature = RESPONSE_PROCESSED;
1562 pkt++;
1563 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564}
1565
1566/**
1567 * qla2x00_update_fw_options() - Read and process firmware options.
1568 * @ha: HA context
1569 *
1570 * Returns 0 on success.
1571 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001572void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001573qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574{
1575 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001576 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
1578 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001579 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
1581 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1582 return;
1583
1584 /* Serial Link options. */
1585 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001586 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1588 sizeof(ha->fw_seriallink_options)));
1589
1590 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1591 if (ha->fw_seriallink_options[3] & BIT_2) {
1592 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1593
1594 /* 1G settings */
1595 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1596 emphasis = (ha->fw_seriallink_options[2] &
1597 (BIT_4 | BIT_3)) >> 3;
1598 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001599 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 rx_sens = (ha->fw_seriallink_options[0] &
1601 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1602 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1603 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1604 if (rx_sens == 0x0)
1605 rx_sens = 0x3;
1606 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1607 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1608 ha->fw_options[10] |= BIT_5 |
1609 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1610 (tx_sens & (BIT_1 | BIT_0));
1611
1612 /* 2G settings */
1613 swing = (ha->fw_seriallink_options[2] &
1614 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1615 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1616 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001617 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 rx_sens = (ha->fw_seriallink_options[1] &
1619 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1620 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1621 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1622 if (rx_sens == 0x0)
1623 rx_sens = 0x3;
1624 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1625 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1626 ha->fw_options[11] |= BIT_5 |
1627 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1628 (tx_sens & (BIT_1 | BIT_0));
1629 }
1630
1631 /* FCP2 options. */
1632 /* Return command IOCBs without waiting for an ABTS to complete. */
1633 ha->fw_options[3] |= BIT_13;
1634
1635 /* LED scheme. */
1636 if (ha->flags.enable_led_scheme)
1637 ha->fw_options[2] |= BIT_12;
1638
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001639 /* Detect ISP6312. */
1640 if (IS_QLA6312(ha))
1641 ha->fw_options[2] |= BIT_13;
1642
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001644 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645}
1646
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001647void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001648qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001649{
1650 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001651 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001652
Giridhar Malavalia9083012010-04-12 17:59:55 -07001653 if (IS_QLA82XX(ha))
1654 return;
1655
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001656 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001657 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001658 return;
1659
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001660 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001661 le16_to_cpu(ha->fw_seriallink_options24[1]),
1662 le16_to_cpu(ha->fw_seriallink_options24[2]),
1663 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001664 if (rval != QLA_SUCCESS) {
1665 qla_printk(KERN_WARNING, ha,
1666 "Unable to update Serial Link options (%x).\n", rval);
1667 }
1668}
1669
1670void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001671qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001672{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001673 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001674 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001675 struct req_que *req = ha->req_q_map[0];
1676 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001677
1678 /* Setup ring parameters in initialization control block. */
1679 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1680 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001681 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1682 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1683 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1684 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1685 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1686 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001687
1688 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1689 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1690 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1691 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1692 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1693}
1694
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001695void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001696qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001697{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001698 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001699 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1700 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1701 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001702 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001703 uint16_t rid = 0;
1704 struct req_que *req = ha->req_q_map[0];
1705 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001706
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001707/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001708 icb = (struct init_cb_24xx *)ha->init_cb;
1709 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1710 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001711 icb->request_q_length = cpu_to_le16(req->length);
1712 icb->response_q_length = cpu_to_le16(rsp->length);
1713 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1714 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1715 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1716 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001717
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001718 if (ha->mqenable) {
1719 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1720 icb->rid = __constant_cpu_to_le16(rid);
1721 if (ha->flags.msix_enabled) {
1722 msix = &ha->msix_entries[1];
1723 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001724 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001725 icb->msix = cpu_to_le16(msix->entry);
1726 }
1727 /* Use alternate PCI bus number */
1728 if (MSB(rid))
1729 icb->firmware_options_2 |=
1730 __constant_cpu_to_le32(BIT_19);
1731 /* Use alternate PCI devfn */
1732 if (LSB(rid))
1733 icb->firmware_options_2 |=
1734 __constant_cpu_to_le32(BIT_18);
1735
Anirban Chakraborty31557542009-12-02 10:36:55 -08001736 /* Use Disable MSIX Handshake mode for capable adapters */
1737 if (IS_MSIX_NACK_CAPABLE(ha)) {
1738 icb->firmware_options_2 &=
1739 __constant_cpu_to_le32(~BIT_22);
1740 ha->flags.disable_msix_handshake = 1;
1741 qla_printk(KERN_INFO, ha,
1742 "MSIX Handshake Disable Mode turned on\n");
1743 } else {
1744 icb->firmware_options_2 |=
1745 __constant_cpu_to_le32(BIT_22);
1746 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001747 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001748
1749 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1750 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1751 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1752 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1753 } else {
1754 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1755 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1756 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1757 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1758 }
1759 /* PCI posting */
1760 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001761}
1762
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763/**
1764 * qla2x00_init_rings() - Initializes firmware.
1765 * @ha: HA context
1766 *
1767 * Beginning of request ring has initialization control block already built
1768 * by nvram config routine.
1769 *
1770 * Returns 0 on success.
1771 */
1772static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001773qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774{
1775 int rval;
1776 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001777 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001778 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001779 struct req_que *req;
1780 struct rsp_que *rsp;
1781 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001782 struct mid_init_cb_24xx *mid_init_cb =
1783 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
1785 spin_lock_irqsave(&ha->hardware_lock, flags);
1786
1787 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001788 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001789 req = ha->req_q_map[que];
1790 if (!req)
1791 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001792 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001793 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001795 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001796
1797 /* Initialize firmware. */
1798 req->ring_ptr = req->ring;
1799 req->ring_index = 0;
1800 req->cnt = req->length;
1801 }
1802
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001803 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001804 rsp = ha->rsp_q_map[que];
1805 if (!rsp)
1806 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001807 /* Initialize response queue entries */
1808 qla2x00_init_response_q_entries(rsp);
1809 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
1811 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001812 list_for_each_entry(vp, &ha->vp_list, list) {
1813 vp->rscn_in_ptr = 0;
1814 vp->rscn_out_ptr = 0;
1815 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001816 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817
1818 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1819
1820 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001821 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001823 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001824
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001825 if (ha->flags.npiv_supported) {
1826 if (ha->operating_mode == LOOP)
1827 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001828 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001829 }
1830
Andrew Vasquez24a08132009-03-24 09:08:16 -07001831 if (IS_FWI2_CAPABLE(ha)) {
1832 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1833 mid_init_cb->init_cb.execution_throttle =
1834 cpu_to_le16(ha->fw_xcb_count);
1835 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001836
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001837 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 if (rval) {
1839 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001840 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 } else {
1842 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001843 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 }
1845
1846 return (rval);
1847}
1848
1849/**
1850 * qla2x00_fw_ready() - Waits for firmware ready.
1851 * @ha: HA context
1852 *
1853 * Returns 0 on success.
1854 */
1855static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001856qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857{
1858 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001859 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 uint16_t min_wait; /* Minimum wait time if loop is down */
1861 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001862 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001863 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864
1865 rval = QLA_SUCCESS;
1866
1867 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001868 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
1870 /*
1871 * Firmware should take at most one RATOV to login, plus 5 seconds for
1872 * our own processing.
1873 */
1874 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1875 wait_time = min_wait;
1876 }
1877
1878 /* Min wait time if loop down */
1879 mtime = jiffies + (min_wait * HZ);
1880
1881 /* wait time before firmware ready */
1882 wtime = jiffies + (wait_time * HZ);
1883
1884 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001885 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1887
1888 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001889 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890
1891 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001892 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001894 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001895 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001897 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1898 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001899 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001900 state[2]));
1901 if ((state[2] & FSTATE_LOGGED_IN) &&
1902 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1903 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001904 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001905
1906 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001907 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001908 if (rval != QLA_SUCCESS)
1909 break;
1910
1911 /* Add time taken to initialize. */
1912 cs84xx_time = jiffies - cs84xx_time;
1913 wtime += cs84xx_time;
1914 mtime += cs84xx_time;
1915 DEBUG16(printk("scsi(%ld): Increasing "
1916 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001917 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001918 }
1919 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001921 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001923 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 &ha->login_timeout, &ha->r_a_tov);
1925
1926 rval = QLA_SUCCESS;
1927 break;
1928 }
1929
1930 rval = QLA_FUNCTION_FAILED;
1931
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001932 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001933 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001935 * other than Wait for Login.
1936 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 if (time_after_eq(jiffies, mtime)) {
1938 qla_printk(KERN_INFO, ha,
1939 "Cable is unplugged...\n");
1940
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001941 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 break;
1943 }
1944 }
1945 } else {
1946 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07001947 if (time_after_eq(jiffies, mtime) ||
1948 (IS_QLA82XX(ha) && ha->flags.fw_hung))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 break;
1950 }
1951
1952 if (time_after_eq(jiffies, wtime))
1953 break;
1954
1955 /* Delay for a while */
1956 msleep(500);
1957
1958 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001959 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 } while (1);
1961
Andrew Vasquez656e8912009-06-03 09:55:29 -07001962 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1963 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1964 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965
1966 if (rval) {
1967 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001968 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 }
1970
1971 return (rval);
1972}
1973
1974/*
1975* qla2x00_configure_hba
1976* Setup adapter context.
1977*
1978* Input:
1979* ha = adapter state pointer.
1980*
1981* Returns:
1982* 0 = success
1983*
1984* Context:
1985* Kernel context.
1986*/
1987static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001988qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989{
1990 int rval;
1991 uint16_t loop_id;
1992 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001993 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 uint8_t al_pa;
1995 uint8_t area;
1996 uint8_t domain;
1997 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001998 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
2000 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002001 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002002 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002004 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002005 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
2006 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002007 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08002008 } else {
2009 qla_printk(KERN_WARNING, ha,
2010 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002011 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002012 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 return (rval);
2014 }
2015
2016 if (topo == 4) {
2017 qla_printk(KERN_INFO, ha,
2018 "Cannot get topology - retrying.\n");
2019 return (QLA_FUNCTION_FAILED);
2020 }
2021
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002022 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023
2024 /* initialize */
2025 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2026 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002027 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028
2029 switch (topo) {
2030 case 0:
2031 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002032 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 ha->current_topology = ISP_CFG_NL;
2034 strcpy(connect_type, "(Loop)");
2035 break;
2036
2037 case 1:
2038 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002039 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002040 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 ha->current_topology = ISP_CFG_FL;
2042 strcpy(connect_type, "(FL_Port)");
2043 break;
2044
2045 case 2:
2046 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002047 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 ha->operating_mode = P2P;
2049 ha->current_topology = ISP_CFG_N;
2050 strcpy(connect_type, "(N_Port-to-N_Port)");
2051 break;
2052
2053 case 3:
2054 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002055 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002056 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 ha->operating_mode = P2P;
2058 ha->current_topology = ISP_CFG_F;
2059 strcpy(connect_type, "(F_Port)");
2060 break;
2061
2062 default:
2063 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
2064 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002065 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 ha->current_topology = ISP_CFG_NL;
2067 strcpy(connect_type, "(Loop)");
2068 break;
2069 }
2070
2071 /* Save Host port and loop ID. */
2072 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002073 vha->d_id.b.domain = domain;
2074 vha->d_id.b.area = area;
2075 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002077 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 qla_printk(KERN_INFO, ha,
2079 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002080 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
2082 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002083 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002085 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 }
2087
2088 return(rval);
2089}
2090
Giridhar Malavalia9083012010-04-12 17:59:55 -07002091inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002092qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2093 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002094{
2095 char *st, *en;
2096 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002097 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002098 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavalia9083012010-04-12 17:59:55 -07002099 !IS_QLA8XXX_TYPE(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002100
2101 if (memcmp(model, BINZERO, len) != 0) {
2102 strncpy(ha->model_number, model, len);
2103 st = en = ha->model_number;
2104 en += len - 1;
2105 while (en > st) {
2106 if (*en != 0x20 && *en != 0x00)
2107 break;
2108 *en-- = '\0';
2109 }
2110
2111 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002112 if (use_tbl &&
2113 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002114 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002115 strncpy(ha->model_desc,
2116 qla2x00_model_name[index * 2 + 1],
2117 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002118 } else {
2119 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002120 if (use_tbl &&
2121 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002122 index < QLA_MODEL_NAMES) {
2123 strcpy(ha->model_number,
2124 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002125 strncpy(ha->model_desc,
2126 qla2x00_model_name[index * 2 + 1],
2127 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002128 } else {
2129 strcpy(ha->model_number, def);
2130 }
2131 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002132 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002133 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002134 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002135}
2136
David Miller4e08df32007-04-16 12:37:43 -07002137/* On sparc systems, obtain port and node WWN from firmware
2138 * properties.
2139 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002140static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002141{
2142#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002143 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002144 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002145 struct device_node *dp = pci_device_to_OF_node(pdev);
2146 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002147 int len;
2148
2149 val = of_get_property(dp, "port-wwn", &len);
2150 if (val && len >= WWN_SIZE)
2151 memcpy(nv->port_name, val, WWN_SIZE);
2152
2153 val = of_get_property(dp, "node-wwn", &len);
2154 if (val && len >= WWN_SIZE)
2155 memcpy(nv->node_name, val, WWN_SIZE);
2156#endif
2157}
2158
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159/*
2160* NVRAM configuration for ISP 2xxx
2161*
2162* Input:
2163* ha = adapter block pointer.
2164*
2165* Output:
2166* initialization control block in response_ring
2167* host adapters parameters in host adapter block
2168*
2169* Returns:
2170* 0 = success.
2171*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002172int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002173qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174{
David Miller4e08df32007-04-16 12:37:43 -07002175 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002176 uint8_t chksum = 0;
2177 uint16_t cnt;
2178 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002179 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002180 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002181 nvram_t *nv = ha->nvram;
2182 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002183 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184
David Miller4e08df32007-04-16 12:37:43 -07002185 rval = QLA_SUCCESS;
2186
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002188 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 ha->nvram_base = 0;
2190 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2191 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2192 ha->nvram_base = 0x80;
2193
2194 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002195 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002196 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2197 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002199 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07002200 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
2202 /* Bad NVRAM data, set defaults parameters. */
2203 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2204 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2205 /* Reset NVRAM data. */
2206 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
2207 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
2208 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07002209 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
2210 "invalid -- WWPN) defaults.\n");
2211
2212 /*
2213 * Set default initialization control block.
2214 */
2215 memset(nv, 0, ha->nvram_size);
2216 nv->parameter_block_version = ICB_VERSION;
2217
2218 if (IS_QLA23XX(ha)) {
2219 nv->firmware_options[0] = BIT_2 | BIT_1;
2220 nv->firmware_options[1] = BIT_7 | BIT_5;
2221 nv->add_firmware_options[0] = BIT_5;
2222 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2223 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2224 nv->special_options[1] = BIT_7;
2225 } else if (IS_QLA2200(ha)) {
2226 nv->firmware_options[0] = BIT_2 | BIT_1;
2227 nv->firmware_options[1] = BIT_7 | BIT_5;
2228 nv->add_firmware_options[0] = BIT_5;
2229 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2230 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2231 } else if (IS_QLA2100(ha)) {
2232 nv->firmware_options[0] = BIT_3 | BIT_1;
2233 nv->firmware_options[1] = BIT_5;
2234 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2235 }
2236
2237 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2238 nv->execution_throttle = __constant_cpu_to_le16(16);
2239 nv->retry_count = 8;
2240 nv->retry_delay = 1;
2241
2242 nv->port_name[0] = 33;
2243 nv->port_name[3] = 224;
2244 nv->port_name[4] = 139;
2245
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002246 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002247
2248 nv->login_timeout = 4;
2249
2250 /*
2251 * Set default host adapter parameters
2252 */
2253 nv->host_p[1] = BIT_2;
2254 nv->reset_delay = 5;
2255 nv->port_down_retry_count = 8;
2256 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2257 nv->link_down_timeout = 60;
2258
2259 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 }
2261
2262#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2263 /*
2264 * The SN2 does not provide BIOS emulation which means you can't change
2265 * potentially bogus BIOS settings. Force the use of default settings
2266 * for link rate and frame size. Hope that the rest of the settings
2267 * are valid.
2268 */
2269 if (ia64_platform_is("sn2")) {
2270 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2271 if (IS_QLA23XX(ha))
2272 nv->special_options[1] = BIT_7;
2273 }
2274#endif
2275
2276 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002277 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278
2279 /*
2280 * Setup driver NVRAM options.
2281 */
2282 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2283 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2284 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2285 nv->firmware_options[1] &= ~BIT_4;
2286
2287 if (IS_QLA23XX(ha)) {
2288 nv->firmware_options[0] |= BIT_2;
2289 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002290 nv->firmware_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002291 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
2293 if (IS_QLA2300(ha)) {
2294 if (ha->fb_rev == FPM_2310) {
2295 strcpy(ha->model_number, "QLA2310");
2296 } else {
2297 strcpy(ha->model_number, "QLA2300");
2298 }
2299 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002300 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002301 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 }
2303 } else if (IS_QLA2200(ha)) {
2304 nv->firmware_options[0] |= BIT_2;
2305 /*
2306 * 'Point-to-point preferred, else loop' is not a safe
2307 * connection mode setting.
2308 */
2309 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2310 (BIT_5 | BIT_4)) {
2311 /* Force 'loop preferred, else point-to-point'. */
2312 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2313 nv->add_firmware_options[0] |= BIT_5;
2314 }
2315 strcpy(ha->model_number, "QLA22xx");
2316 } else /*if (IS_QLA2100(ha))*/ {
2317 strcpy(ha->model_number, "QLA2100");
2318 }
2319
2320 /*
2321 * Copy over NVRAM RISC parameter block to initialization control block.
2322 */
2323 dptr1 = (uint8_t *)icb;
2324 dptr2 = (uint8_t *)&nv->parameter_block_version;
2325 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2326 while (cnt--)
2327 *dptr1++ = *dptr2++;
2328
2329 /* Copy 2nd half. */
2330 dptr1 = (uint8_t *)icb->add_firmware_options;
2331 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2332 while (cnt--)
2333 *dptr1++ = *dptr2++;
2334
Andrew Vasquez5341e862006-05-17 15:09:16 -07002335 /* Use alternate WWN? */
2336 if (nv->host_p[1] & BIT_7) {
2337 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2338 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2339 }
2340
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 /* Prepare nodename */
2342 if ((icb->firmware_options[1] & BIT_6) == 0) {
2343 /*
2344 * Firmware will apply the following mask if the nodename was
2345 * not provided.
2346 */
2347 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2348 icb->node_name[0] &= 0xF0;
2349 }
2350
2351 /*
2352 * Set host adapter parameters.
2353 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002354 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002355 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2357 /* Always load RISC code on non ISP2[12]00 chips. */
2358 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2359 ha->flags.disable_risc_code_load = 0;
2360 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2361 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2362 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002363 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002364 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365
2366 ha->operating_mode =
2367 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2368
2369 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2370 sizeof(ha->fw_seriallink_options));
2371
2372 /* save HBA serial number */
2373 ha->serial0 = icb->port_name[5];
2374 ha->serial1 = icb->port_name[6];
2375 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002376 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2377 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378
2379 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2380
2381 ha->retry_count = nv->retry_count;
2382
2383 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002384 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 nv->login_timeout = ql2xlogintimeout;
2386 if (nv->login_timeout < 4)
2387 nv->login_timeout = 4;
2388 ha->login_timeout = nv->login_timeout;
2389 icb->login_timeout = nv->login_timeout;
2390
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002391 /* Set minimum RATOV to 100 tenths of a second. */
2392 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 ha->loop_reset_delay = nv->reset_delay;
2395
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 /* Link Down Timeout = 0:
2397 *
2398 * When Port Down timer expires we will start returning
2399 * I/O's to OS with "DID_NO_CONNECT".
2400 *
2401 * Link Down Timeout != 0:
2402 *
2403 * The driver waits for the link to come up after link down
2404 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002405 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 if (nv->link_down_timeout == 0) {
2407 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002408 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 } else {
2410 ha->link_down_timeout = nv->link_down_timeout;
2411 ha->loop_down_abort_time =
2412 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 /*
2416 * Need enough time to try and get the port back.
2417 */
2418 ha->port_down_retry_count = nv->port_down_retry_count;
2419 if (qlport_down_retry)
2420 ha->port_down_retry_count = qlport_down_retry;
2421 /* Set login_retry_count */
2422 ha->login_retry_count = nv->retry_count;
2423 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2424 ha->port_down_retry_count > 3)
2425 ha->login_retry_count = ha->port_down_retry_count;
2426 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2427 ha->login_retry_count = ha->port_down_retry_count;
2428 if (ql2xloginretrycount)
2429 ha->login_retry_count = ql2xloginretrycount;
2430
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 icb->lun_enables = __constant_cpu_to_le16(0);
2432 icb->command_resource_count = 0;
2433 icb->immediate_notify_resource_count = 0;
2434 icb->timeout = __constant_cpu_to_le16(0);
2435
2436 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2437 /* Enable RIO */
2438 icb->firmware_options[0] &= ~BIT_3;
2439 icb->add_firmware_options[0] &=
2440 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2441 icb->add_firmware_options[0] |= BIT_2;
2442 icb->response_accumulation_timer = 3;
2443 icb->interrupt_delay_timer = 5;
2444
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002445 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002447 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002448 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002449 ha->zio_mode = icb->add_firmware_options[0] &
2450 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2451 ha->zio_timer = icb->interrupt_delay_timer ?
2452 icb->interrupt_delay_timer: 2;
2453 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 icb->add_firmware_options[0] &=
2455 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002456 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002457 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002458 ha->zio_mode = QLA_ZIO_MODE_6;
2459
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002460 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002461 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002462 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002464 "ZIO mode %d enabled; timer delay (%d us).\n",
2465 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002467 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2468 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002469 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 }
2471 }
2472
David Miller4e08df32007-04-16 12:37:43 -07002473 if (rval) {
2474 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002475 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07002476 }
2477 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478}
2479
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002480static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002481qla2x00_rport_del(void *data)
2482{
2483 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002484 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002485
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002486 spin_lock_irq(fcport->vha->host->host_lock);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002487 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002488 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002489 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002490 if (rport)
2491 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002492}
2493
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494/**
2495 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2496 * @ha: HA context
2497 * @flags: allocation flags
2498 *
2499 * Returns a pointer to the allocated fcport, or NULL, if none available.
2500 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002501fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002502qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503{
2504 fc_port_t *fcport;
2505
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002506 fcport = kzalloc(sizeof(fc_port_t), flags);
2507 if (!fcport)
2508 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509
2510 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002511 fcport->vha = vha;
2512 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 fcport->port_type = FCT_UNKNOWN;
2514 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002516 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002518 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519}
2520
2521/*
2522 * qla2x00_configure_loop
2523 * Updates Fibre Channel Device Database with what is actually on loop.
2524 *
2525 * Input:
2526 * ha = adapter block pointer.
2527 *
2528 * Returns:
2529 * 0 = success.
2530 * 1 = error.
2531 * 2 = database was full and device was not configured.
2532 */
2533static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002534qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535{
2536 int rval;
2537 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002538 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 rval = QLA_SUCCESS;
2540
2541 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002542 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2543 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 if (rval != QLA_SUCCESS) {
2545 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002546 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 return (rval);
2548 }
2549 }
2550
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002551 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002553 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554
2555 /*
2556 * If we have both an RSCN and PORT UPDATE pending then handle them
2557 * both at the same time.
2558 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002559 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2560 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561
Michael Hernandez3064ff32009-12-15 21:29:44 -08002562 qla2x00_get_data_rate(vha);
2563
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 /* Determine what we need to do */
2565 if (ha->current_topology == ISP_CFG_FL &&
2566 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2567
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002568 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 set_bit(RSCN_UPDATE, &flags);
2570
2571 } else if (ha->current_topology == ISP_CFG_F &&
2572 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2573
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002574 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 set_bit(RSCN_UPDATE, &flags);
2576 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2577
Andrew Vasquez21333b42006-05-17 15:09:56 -07002578 } else if (ha->current_topology == ISP_CFG_N) {
2579 clear_bit(RSCN_UPDATE, &flags);
2580
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002581 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2583
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002584 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 set_bit(RSCN_UPDATE, &flags);
2586 set_bit(LOCAL_LOOP_UPDATE, &flags);
2587 }
2588
2589 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002590 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002592 else
2593 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 }
2595
2596 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002597 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002599 else
2600 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 }
2602
2603 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002604 if (atomic_read(&vha->loop_down_timer) ||
2605 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 rval = QLA_FUNCTION_FAILED;
2607 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002608 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002610 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 }
2612 }
2613
2614 if (rval) {
2615 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002616 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 } else {
2618 DEBUG3(printk("%s: exiting normally\n", __func__));
2619 }
2620
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002621 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002622 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002624 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002625 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002626 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07002627 if (!IS_ALOGIO_CAPABLE(ha))
2628 vha->flags.rscn_queue_overflow = 1;
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002629 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 }
2631
2632 return (rval);
2633}
2634
2635
2636
2637/*
2638 * qla2x00_configure_local_loop
2639 * Updates Fibre Channel Device Database with local loop devices.
2640 *
2641 * Input:
2642 * ha = adapter block pointer.
2643 *
2644 * Returns:
2645 * 0 = success.
2646 */
2647static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002648qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649{
2650 int rval, rval2;
2651 int found_devs;
2652 int found;
2653 fc_port_t *fcport, *new_fcport;
2654
2655 uint16_t index;
2656 uint16_t entries;
2657 char *id_iter;
2658 uint16_t loop_id;
2659 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002660 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661
2662 found_devs = 0;
2663 new_fcport = NULL;
2664 entries = MAX_FIBRE_DEVICES;
2665
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002666 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2667 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668
2669 /* Get list of logged in devices. */
2670 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002671 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 &entries);
2673 if (rval != QLA_SUCCESS)
2674 goto cleanup_allocation;
2675
2676 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002677 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2679 entries * sizeof(struct gid_list_info)));
2680
2681 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002682 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 if (new_fcport == NULL) {
2684 rval = QLA_MEMORY_ALLOC_FAILED;
2685 goto cleanup_allocation;
2686 }
2687 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2688
2689 /*
2690 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2691 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002692 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2694 fcport->port_type != FCT_BROADCAST &&
2695 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2696
2697 DEBUG(printk("scsi(%ld): Marking port lost, "
2698 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002699 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700
2701 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 }
2703 }
2704
2705 /* Add devices to port list. */
2706 id_iter = (char *)ha->gid_list;
2707 for (index = 0; index < entries; index++) {
2708 domain = ((struct gid_list_info *)id_iter)->domain;
2709 area = ((struct gid_list_info *)id_iter)->area;
2710 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002711 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 loop_id = (uint16_t)
2713 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002714 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 loop_id = le16_to_cpu(
2716 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002717 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718
2719 /* Bypass reserved domain fields. */
2720 if ((domain & 0xf0) == 0xf0)
2721 continue;
2722
2723 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002724 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002725 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 continue;
2727
2728 /* Bypass invalid local loop ID. */
2729 if (loop_id > LAST_LOCAL_LOOP_ID)
2730 continue;
2731
2732 /* Fill in member data. */
2733 new_fcport->d_id.b.domain = domain;
2734 new_fcport->d_id.b.area = area;
2735 new_fcport->d_id.b.al_pa = al_pa;
2736 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002737 new_fcport->vp_idx = vha->vp_idx;
2738 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 if (rval2 != QLA_SUCCESS) {
2740 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2741 "information -- get_port_database=%x, "
2742 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002743 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002744 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002745 vha->host_no));
2746 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 continue;
2748 }
2749
2750 /* Check for matching device in port list. */
2751 found = 0;
2752 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002753 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 if (memcmp(new_fcport->port_name, fcport->port_name,
2755 WWN_SIZE))
2756 continue;
2757
Shyam Sundarddb9b122009-03-24 09:08:10 -07002758 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 fcport->loop_id = new_fcport->loop_id;
2760 fcport->port_type = new_fcport->port_type;
2761 fcport->d_id.b24 = new_fcport->d_id.b24;
2762 memcpy(fcport->node_name, new_fcport->node_name,
2763 WWN_SIZE);
2764
2765 found++;
2766 break;
2767 }
2768
2769 if (!found) {
2770 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002771 if (vha->vp_idx) {
2772 new_fcport->vha = vha;
2773 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002774 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002775 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776
2777 /* Allocate a new replacement fcport. */
2778 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002779 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 if (new_fcport == NULL) {
2781 rval = QLA_MEMORY_ALLOC_FAILED;
2782 goto cleanup_allocation;
2783 }
2784 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2785 }
2786
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002787 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002788 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002789
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002790 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791
2792 found_devs++;
2793 }
2794
2795cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002796 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797
2798 if (rval != QLA_SUCCESS) {
2799 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002800 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 }
2802
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 return (rval);
2804}
2805
2806static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002807qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002808{
2809#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002810 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2811 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002812 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002813 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002814 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002815
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002816 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002817 return;
2818
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07002819 if (atomic_read(&fcport->state) != FCS_ONLINE)
2820 return;
2821
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002822 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2823 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002824 return;
2825
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002826 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002827 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002828 if (rval != QLA_SUCCESS) {
2829 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2830 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002831 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002832 fcport->port_name[2], fcport->port_name[3],
2833 fcport->port_name[4], fcport->port_name[5],
2834 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002835 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002836 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002837 link_speed = link_speeds[LS_UNKNOWN];
2838 if (fcport->fp_speed < 5)
2839 link_speed = link_speeds[fcport->fp_speed];
2840 else if (fcport->fp_speed == 0x13)
2841 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002842 DEBUG2(qla_printk(KERN_INFO, ha,
2843 "iIDMA adjusted to %s GB/s on "
2844 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002845 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002846 fcport->port_name[1], fcport->port_name[2],
2847 fcport->port_name[3], fcport->port_name[4],
2848 fcport->port_name[5], fcport->port_name[6],
2849 fcport->port_name[7]));
2850 }
2851}
2852
Adrian Bunk23be3312006-11-24 02:46:01 +01002853static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002854qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002855{
2856 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002857 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002858 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002859
Andrew Vasquezac280b62009-08-20 11:06:05 -07002860 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002861
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002862 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2863 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002864 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2865 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2866 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002867 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002868 if (!rport) {
2869 qla_printk(KERN_WARNING, ha,
2870 "Unable to allocate fc remote port!\n");
2871 return;
2872 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002873 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002874 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002875 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002876
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002877 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002878
2879 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002880 if (fcport->port_type == FCT_INITIATOR)
2881 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2882 if (fcport->port_type == FCT_TARGET)
2883 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002884 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002885}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886
2887/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002888 * qla2x00_update_fcport
2889 * Updates device on list.
2890 *
2891 * Input:
2892 * ha = adapter block pointer.
2893 * fcport = port structure pointer.
2894 *
2895 * Return:
2896 * 0 - Success
2897 * BIT_0 - error
2898 *
2899 * Context:
2900 * Kernel context.
2901 */
2902void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002903qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002904{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002905 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002906
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002907 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002908 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002909 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002910 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002911 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002912 PORT_RETRY_TIME);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002913 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01002914
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002915 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002916
2917 atomic_set(&fcport->state, FCS_ONLINE);
2918
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002919 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002920}
2921
2922/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 * qla2x00_configure_fabric
2924 * Setup SNS devices with loop ID's.
2925 *
2926 * Input:
2927 * ha = adapter block pointer.
2928 *
2929 * Returns:
2930 * 0 = success.
2931 * BIT_0 = error
2932 */
2933static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002934qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935{
2936 int rval, rval2;
2937 fc_port_t *fcport, *fcptemp;
2938 uint16_t next_loopid;
2939 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002940 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002942 struct qla_hw_data *ha = vha->hw;
2943 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944
2945 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002946 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002947 loop_id = NPH_F_PORT;
2948 else
2949 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002950 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 if (rval != QLA_SUCCESS) {
2952 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002953 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002955 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 return (QLA_SUCCESS);
2957 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002958 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959
2960 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002961 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 if (rval2 == QLA_RSCNS_HANDLED) {
2963 /* No point doing the scan, just continue. */
2964 return (QLA_SUCCESS);
2965 }
2966 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002967 /* FDMI support. */
2968 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002969 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2970 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002971
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002973 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002974 loop_id = NPH_SNS;
2975 else
2976 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002977 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002978 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 if (mb[0] != MBS_COMMAND_COMPLETE) {
2980 DEBUG2(qla_printk(KERN_INFO, ha,
2981 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002982 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 mb[0], mb[1], mb[2], mb[6], mb[7]));
2984 return (QLA_SUCCESS);
2985 }
2986
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002987 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2988 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 /* EMPTY */
2990 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002991 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002993 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 /* EMPTY */
2995 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002996 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002998 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 /* EMPTY */
3000 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003001 "failed.\n", vha->host_no));
3002 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 /* EMPTY */
3004 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003005 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 }
3007 }
3008
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003009 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 if (rval != QLA_SUCCESS)
3011 break;
3012
3013 /*
3014 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003015 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003017 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3018 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 break;
3020
3021 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3022 continue;
3023
3024 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003025 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003026 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003028 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 fcport->port_type != FCT_INITIATOR &&
3030 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003031 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003032 fcport->loop_id,
3033 fcport->d_id.b.domain,
3034 fcport->d_id.b.area,
3035 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 fcport->loop_id = FC_NO_LOOP_ID;
3037 }
3038 }
3039 }
3040
3041 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003042 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043
3044 /*
3045 * Scan through our port list and login entries that need to be
3046 * logged in.
3047 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003048 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3049 if (atomic_read(&vha->loop_down_timer) ||
3050 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 break;
3052
3053 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3054 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3055 continue;
3056
3057 if (fcport->loop_id == FC_NO_LOOP_ID) {
3058 fcport->loop_id = next_loopid;
Seokmann Jud4486fd2008-04-03 13:13:28 -07003059 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003060 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 if (rval != QLA_SUCCESS) {
3062 /* Ran out of IDs to use */
3063 break;
3064 }
3065 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003067 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 }
3069
3070 /* Exit if out of loop IDs. */
3071 if (rval != QLA_SUCCESS) {
3072 break;
3073 }
3074
3075 /*
3076 * Login and add the new devices to our port list.
3077 */
3078 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003079 if (atomic_read(&vha->loop_down_timer) ||
3080 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 break;
3082
3083 /* Find a new loop ID to use. */
3084 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003085 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 if (rval != QLA_SUCCESS) {
3087 /* Ran out of IDs to use */
3088 break;
3089 }
3090
bdf79622005-04-17 15:06:53 -05003091 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003092 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003093
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003094 if (vha->vp_idx) {
3095 fcport->vha = vha;
3096 fcport->vp_idx = vha->vp_idx;
3097 }
3098 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 }
3100 } while (0);
3101
3102 /* Free all new device structures not processed. */
3103 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3104 list_del(&fcport->list);
3105 kfree(fcport);
3106 }
3107
3108 if (rval) {
3109 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003110 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 }
3112
3113 return (rval);
3114}
3115
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116/*
3117 * qla2x00_find_all_fabric_devs
3118 *
3119 * Input:
3120 * ha = adapter block pointer.
3121 * dev = database device entry pointer.
3122 *
3123 * Returns:
3124 * 0 = success.
3125 *
3126 * Context:
3127 * Kernel context.
3128 */
3129static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003130qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3131 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132{
3133 int rval;
3134 uint16_t loop_id;
3135 fc_port_t *fcport, *new_fcport, *fcptemp;
3136 int found;
3137
3138 sw_info_t *swl;
3139 int swl_idx;
3140 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003141 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003142 struct qla_hw_data *ha = vha->hw;
3143 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003144 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145
3146 rval = QLA_SUCCESS;
3147
3148 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07003149 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003150 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 /*EMPTY*/
3152 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003153 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003155 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 kfree(swl);
3157 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003158 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 kfree(swl);
3160 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003161 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 kfree(swl);
3163 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003164 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003165 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3166 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003168
3169 /* If other queries succeeded probe for FC-4 type */
3170 if (swl)
3171 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 }
3173 swl_idx = 0;
3174
3175 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003176 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003178 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 return (QLA_MEMORY_ALLOC_FAILED);
3180 }
3181 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 /* Set start port ID scan at adapter ID. */
3183 first_dev = 1;
3184 last_dev = 0;
3185
3186 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003187 loop_id = ha->min_external_loopid;
3188 for (; loop_id <= ha->max_loop_id; loop_id++) {
3189 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 continue;
3191
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003192 if (ha->current_topology == ISP_CFG_FL &&
3193 (atomic_read(&vha->loop_down_timer) ||
3194 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003195 atomic_set(&vha->loop_down_timer, 0);
3196 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3197 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200
3201 if (swl != NULL) {
3202 if (last_dev) {
3203 wrap.b24 = new_fcport->d_id.b24;
3204 } else {
3205 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3206 memcpy(new_fcport->node_name,
3207 swl[swl_idx].node_name, WWN_SIZE);
3208 memcpy(new_fcport->port_name,
3209 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003210 memcpy(new_fcport->fabric_port_name,
3211 swl[swl_idx].fabric_port_name, WWN_SIZE);
3212 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003213 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214
3215 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3216 last_dev = 1;
3217 }
3218 swl_idx++;
3219 }
3220 } else {
3221 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003222 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 if (rval != QLA_SUCCESS) {
3224 qla_printk(KERN_WARNING, ha,
3225 "SNS scan failed -- assuming zero-entry "
3226 "result...\n");
3227 list_for_each_entry_safe(fcport, fcptemp,
3228 new_fcports, list) {
3229 list_del(&fcport->list);
3230 kfree(fcport);
3231 }
3232 rval = QLA_SUCCESS;
3233 break;
3234 }
3235 }
3236
3237 /* If wrap on switch device list, exit. */
3238 if (first_dev) {
3239 wrap.b24 = new_fcport->d_id.b24;
3240 first_dev = 0;
3241 } else if (new_fcport->d_id.b24 == wrap.b24) {
3242 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003243 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
3245 break;
3246 }
3247
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003248 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003249 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 continue;
3251
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003252 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003253 found = 0;
3254 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003255 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003256 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3257 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003258 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003259 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003260 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003261 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003262 continue;
3263 }
3264
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003265 /* Bypass if same domain and area of adapter. */
3266 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003267 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003268 ISP_CFG_FL)
3269 continue;
3270
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 /* Bypass reserved domain fields. */
3272 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3273 continue;
3274
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003275 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
3276 if (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3277 new_fcport->fc4_type != FC4_TYPE_UNKNOWN)
3278 continue;
3279
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 /* Locate matching device in database. */
3281 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003282 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 if (memcmp(new_fcport->port_name, fcport->port_name,
3284 WWN_SIZE))
3285 continue;
3286
3287 found++;
3288
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003289 /* Update port state. */
3290 memcpy(fcport->fabric_port_name,
3291 new_fcport->fabric_port_name, WWN_SIZE);
3292 fcport->fp_speed = new_fcport->fp_speed;
3293
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 /*
3295 * If address the same and state FCS_ONLINE, nothing
3296 * changed.
3297 */
3298 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3299 atomic_read(&fcport->state) == FCS_ONLINE) {
3300 break;
3301 }
3302
3303 /*
3304 * If device was not a fabric device before.
3305 */
3306 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3307 fcport->d_id.b24 = new_fcport->d_id.b24;
3308 fcport->loop_id = FC_NO_LOOP_ID;
3309 fcport->flags |= (FCF_FABRIC_DEVICE |
3310 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 break;
3312 }
3313
3314 /*
3315 * Port ID changed or device was marked to be updated;
3316 * Log it out if still logged in and mark it for
3317 * relogin later.
3318 */
3319 fcport->d_id.b24 = new_fcport->d_id.b24;
3320 fcport->flags |= FCF_LOGIN_NEEDED;
3321 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003322 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 fcport->port_type != FCT_INITIATOR &&
3324 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003325 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003326 fcport->d_id.b.domain, fcport->d_id.b.area,
3327 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 fcport->loop_id = FC_NO_LOOP_ID;
3329 }
3330
3331 break;
3332 }
3333
3334 if (found)
3335 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336 /* If device was not in our fcports list, then add it. */
3337 list_add_tail(&new_fcport->list, new_fcports);
3338
3339 /* Allocate a new replacement fcport. */
3340 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003341 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003343 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 return (QLA_MEMORY_ALLOC_FAILED);
3345 }
3346 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3347 new_fcport->d_id.b24 = nxt_d_id.b24;
3348 }
3349
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003350 kfree(swl);
3351 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 return (rval);
3354}
3355
3356/*
3357 * qla2x00_find_new_loop_id
3358 * Scan through our port list and find a new usable loop ID.
3359 *
3360 * Input:
3361 * ha: adapter state pointer.
3362 * dev: port structure pointer.
3363 *
3364 * Returns:
3365 * qla2x00 local function return status code.
3366 *
3367 * Context:
3368 * Kernel context.
3369 */
Adrian Bunk413975a2006-06-30 02:33:06 -07003370static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003371qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372{
3373 int rval;
3374 int found;
3375 fc_port_t *fcport;
3376 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003377 struct qla_hw_data *ha = vha->hw;
3378 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003379 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380
3381 rval = QLA_SUCCESS;
3382
3383 /* Save starting loop ID. */
3384 first_loop_id = dev->loop_id;
3385
3386 for (;;) {
3387 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003388 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390
3391 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003392 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394
3395 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003396 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397 /* first loop ID. */
3398 dev->loop_id = ha->min_external_loopid;
3399 }
3400
3401 /* Check for loop ID being already in use. */
3402 found = 0;
3403 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003404 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003405 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3406 if (fcport->loop_id == dev->loop_id &&
3407 fcport != dev) {
3408 /* ID possibly in use */
3409 found++;
3410 break;
3411 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003413 if (found)
3414 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 }
3416
3417 /* If not in use then it is free to use. */
3418 if (!found) {
3419 break;
3420 }
3421
3422 /* ID in use. Try next value. */
3423 dev->loop_id++;
3424
3425 /* If wrap around. No free ID to use. */
3426 if (dev->loop_id == first_loop_id) {
3427 dev->loop_id = FC_NO_LOOP_ID;
3428 rval = QLA_FUNCTION_FAILED;
3429 break;
3430 }
3431 }
3432
3433 return (rval);
3434}
3435
3436/*
3437 * qla2x00_device_resync
3438 * Marks devices in the database that needs resynchronization.
3439 *
3440 * Input:
3441 * ha = adapter block pointer.
3442 *
3443 * Context:
3444 * Kernel context.
3445 */
3446static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003447qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448{
3449 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 uint32_t mask;
3451 fc_port_t *fcport;
3452 uint32_t rscn_entry;
3453 uint8_t rscn_out_iter;
3454 uint8_t format;
Mike Waychison1516ef42010-05-04 15:01:31 -07003455 port_id_t d_id = {};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456
3457 rval = QLA_RSCNS_HANDLED;
3458
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003459 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3460 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003462 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463 format = MSB(MSW(rscn_entry));
3464 d_id.b.domain = LSB(MSW(rscn_entry));
3465 d_id.b.area = MSB(LSW(rscn_entry));
3466 d_id.b.al_pa = LSB(LSW(rscn_entry));
3467
3468 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3469 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003470 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471 d_id.b.area, d_id.b.al_pa));
3472
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003473 vha->rscn_out_ptr++;
3474 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3475 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476
3477 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003478 for (rscn_out_iter = vha->rscn_out_ptr;
3479 !vha->flags.rscn_queue_overflow &&
3480 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481 rscn_out_iter = (rscn_out_iter ==
3482 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3483
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003484 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 break;
3486
3487 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003488 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 rscn_out_iter));
3490
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003491 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 }
3493
3494 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003495 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003497 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498
3499 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003500 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 }
3502
3503 switch (format) {
3504 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 mask = 0xffffff;
3506 break;
3507 case 1:
3508 mask = 0xffff00;
3509 break;
3510 case 2:
3511 mask = 0xff0000;
3512 break;
3513 default:
3514 mask = 0x0;
3515 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003516 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517 break;
3518 }
3519
3520 rval = QLA_SUCCESS;
3521
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003522 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3524 (fcport->d_id.b24 & mask) != d_id.b24 ||
3525 fcport->port_type == FCT_BROADCAST)
3526 continue;
3527
3528 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3529 if (format != 3 ||
3530 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003531 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003532 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 }
3534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 }
3536 }
3537 return (rval);
3538}
3539
3540/*
3541 * qla2x00_fabric_dev_login
3542 * Login fabric target device and update FC port database.
3543 *
3544 * Input:
3545 * ha: adapter state pointer.
3546 * fcport: port structure list pointer.
3547 * next_loopid: contains value of a new loop ID that can be used
3548 * by the next login attempt.
3549 *
3550 * Returns:
3551 * qla2x00 local function return status code.
3552 *
3553 * Context:
3554 * Kernel context.
3555 */
3556static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003557qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558 uint16_t *next_loopid)
3559{
3560 int rval;
3561 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003562 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003563 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564
3565 rval = QLA_SUCCESS;
3566 retry = 0;
3567
Andrew Vasquezac280b62009-08-20 11:06:05 -07003568 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003569 if (fcport->flags & FCF_ASYNC_SENT)
3570 return rval;
3571 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003572 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3573 if (!rval)
3574 return rval;
3575 }
3576
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003577 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003578 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003580 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003581 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003582 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003583 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003584 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003586 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003587 fcport->d_id.b.domain, fcport->d_id.b.area,
3588 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003589 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003591 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592 }
3593 }
3594
3595 return (rval);
3596}
3597
3598/*
3599 * qla2x00_fabric_login
3600 * Issue fabric login command.
3601 *
3602 * Input:
3603 * ha = adapter block pointer.
3604 * device = pointer to FC device type structure.
3605 *
3606 * Returns:
3607 * 0 - Login successfully
3608 * 1 - Login failed
3609 * 2 - Initiator device
3610 * 3 - Fatal error
3611 */
3612int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003613qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614 uint16_t *next_loopid)
3615{
3616 int rval;
3617 int retry;
3618 uint16_t tmp_loopid;
3619 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003620 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621
3622 retry = 0;
3623 tmp_loopid = 0;
3624
3625 for (;;) {
3626 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3627 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003628 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3630
3631 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003632 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 fcport->d_id.b.domain, fcport->d_id.b.area,
3634 fcport->d_id.b.al_pa, mb, BIT_0);
3635 if (mb[0] == MBS_PORT_ID_USED) {
3636 /*
3637 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003638 * recommends the driver perform an implicit login with
3639 * the specified ID again. The ID we just used is save
3640 * here so we return with an ID that can be tried by
3641 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642 */
3643 retry++;
3644 tmp_loopid = fcport->loop_id;
3645 fcport->loop_id = mb[1];
3646
3647 DEBUG(printk("Fabric Login: port in use - next "
3648 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3649 fcport->loop_id, fcport->d_id.b.domain,
3650 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3651
3652 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3653 /*
3654 * Login succeeded.
3655 */
3656 if (retry) {
3657 /* A retry occurred before. */
3658 *next_loopid = tmp_loopid;
3659 } else {
3660 /*
3661 * No retry occurred before. Just increment the
3662 * ID value for next login.
3663 */
3664 *next_loopid = (fcport->loop_id + 1);
3665 }
3666
3667 if (mb[1] & BIT_0) {
3668 fcport->port_type = FCT_INITIATOR;
3669 } else {
3670 fcport->port_type = FCT_TARGET;
3671 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003672 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673 }
3674 }
3675
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003676 if (mb[10] & BIT_0)
3677 fcport->supported_classes |= FC_COS_CLASS2;
3678 if (mb[10] & BIT_1)
3679 fcport->supported_classes |= FC_COS_CLASS3;
3680
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681 rval = QLA_SUCCESS;
3682 break;
3683 } else if (mb[0] == MBS_LOOP_ID_USED) {
3684 /*
3685 * Loop ID already used, try next loop ID.
3686 */
3687 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003688 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689 if (rval != QLA_SUCCESS) {
3690 /* Ran out of loop IDs to use */
3691 break;
3692 }
3693 } else if (mb[0] == MBS_COMMAND_ERROR) {
3694 /*
3695 * Firmware possibly timed out during login. If NO
3696 * retries are left to do then the device is declared
3697 * dead.
3698 */
3699 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003700 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003701 fcport->d_id.b.domain, fcport->d_id.b.area,
3702 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003703 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704
3705 rval = 1;
3706 break;
3707 } else {
3708 /*
3709 * unrecoverable / not handled error
3710 */
3711 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003712 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003713 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 fcport->d_id.b.domain, fcport->d_id.b.area,
3715 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3716
3717 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003718 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003719 fcport->d_id.b.domain, fcport->d_id.b.area,
3720 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003722 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723
3724 rval = 3;
3725 break;
3726 }
3727 }
3728
3729 return (rval);
3730}
3731
3732/*
3733 * qla2x00_local_device_login
3734 * Issue local device login command.
3735 *
3736 * Input:
3737 * ha = adapter block pointer.
3738 * loop_id = loop id of device to login to.
3739 *
3740 * Returns (Where's the #define!!!!):
3741 * 0 - Login successfully
3742 * 1 - Login failed
3743 * 3 - Fatal error
3744 */
3745int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003746qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747{
3748 int rval;
3749 uint16_t mb[MAILBOX_REGISTER_COUNT];
3750
3751 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003752 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003753 if (rval == QLA_SUCCESS) {
3754 /* Interrogate mailbox registers for any errors */
3755 if (mb[0] == MBS_COMMAND_ERROR)
3756 rval = 1;
3757 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3758 /* device not in PCB table */
3759 rval = 3;
3760 }
3761
3762 return (rval);
3763}
3764
3765/*
3766 * qla2x00_loop_resync
3767 * Resync with fibre channel devices.
3768 *
3769 * Input:
3770 * ha = adapter block pointer.
3771 *
3772 * Returns:
3773 * 0 = success
3774 */
3775int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003776qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003777{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003778 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003780 struct req_que *req;
3781 struct rsp_que *rsp;
3782
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003783 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003784 req = vha->hw->req_q_map[0];
3785 else
3786 req = vha->req;
3787 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003789 atomic_set(&vha->loop_state, LOOP_UPDATE);
3790 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3791 if (vha->flags.online) {
3792 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3794 wait_time = 256;
3795 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003796 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003797
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003798 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003799 qla2x00_marker(vha, req, rsp, 0, 0,
3800 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003801 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802
3803 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003804 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003806 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003807 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003808 } while (!atomic_read(&vha->loop_down_timer) &&
3809 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3810 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3811 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 }
3814
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003815 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003818 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820
3821 return (rval);
3822}
3823
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003825qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003826{
3827 fc_port_t *fcport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003828 struct scsi_qla_host *tvp, *vha;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003829
3830 /* Go with deferred removal of rport references. */
Andrew Vasquez67becc02009-08-25 11:36:20 -07003831 list_for_each_entry_safe(vha, tvp, &base_vha->hw->vp_list, list)
3832 list_for_each_entry(fcport, &vha->vp_fcports, list)
3833 if (fcport && fcport->drport &&
3834 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3835 qla2x00_rport_del(fcport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003836}
3837
Giridhar Malavalia9083012010-04-12 17:59:55 -07003838void
3839qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3840{
3841 struct qla_hw_data *ha = vha->hw;
3842 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
3843 struct scsi_qla_host *tvp;
3844
3845 vha->flags.online = 0;
3846 ha->flags.chip_reset_done = 0;
3847 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3848 ha->qla_stats.total_isp_aborts++;
3849
3850 qla_printk(KERN_INFO, ha,
3851 "Performing ISP error recovery - ha= %p.\n", ha);
3852
3853 /* Chip reset does not apply to 82XX */
3854 if (!IS_QLA82XX(ha))
3855 ha->isp_ops->reset_chip(vha);
3856
3857 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3858 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3859 atomic_set(&vha->loop_state, LOOP_DOWN);
3860 qla2x00_mark_all_devices_lost(vha, 0);
3861 list_for_each_entry_safe(vp, tvp, &base_vha->hw->vp_list, list)
3862 qla2x00_mark_all_devices_lost(vp, 0);
3863 } else {
3864 if (!atomic_read(&vha->loop_down_timer))
3865 atomic_set(&vha->loop_down_timer,
3866 LOOP_DOWN_TIME);
3867 }
3868
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07003869 if (!ha->flags.eeh_busy) {
3870 /* Make sure for ISP 82XX IO DMA is complete */
3871 if (IS_QLA82XX(ha)) {
3872 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
3873 WAIT_HOST) == QLA_SUCCESS) {
3874 DEBUG2(qla_printk(KERN_INFO, ha,
3875 "Done wait for pending commands\n"));
3876 }
Giridhar Malavali4d78c972010-07-23 15:28:35 +05003877 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07003878
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07003879 /* Requeue all commands in outstanding command list. */
3880 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3881 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07003882}
3883
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884/*
3885* qla2x00_abort_isp
3886* Resets ISP and aborts all outstanding commands.
3887*
3888* Input:
3889* ha = adapter block pointer.
3890*
3891* Returns:
3892* 0 = success
3893*/
3894int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003895qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003897 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003899 struct qla_hw_data *ha = vha->hw;
3900 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003901 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003902 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003904 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003905 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906
Andrew Vasquez85880802009-12-15 21:29:46 -08003907 if (unlikely(pci_channel_offline(ha->pdev) &&
3908 ha->flags.pci_channel_io_perm_failure)) {
3909 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3910 status = 0;
3911 return status;
3912 }
3913
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003914 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003915
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003916 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003918 if (!qla2x00_restart_isp(vha)) {
3919 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003921 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 /*
3923 * Issue marker command only when we are going
3924 * to start the I/O .
3925 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003926 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927 }
3928
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003929 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003931 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003933 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003934 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003935
Lalit Chandivade29c53972009-10-13 15:16:47 -07003936 if (IS_QLA81XX(ha))
3937 qla2x00_get_fw_version(vha,
3938 &ha->fw_major_version,
3939 &ha->fw_minor_version,
3940 &ha->fw_subminor_version,
3941 &ha->fw_attributes, &ha->fw_memory_size,
3942 ha->mpi_version, &ha->mpi_capabilities,
3943 ha->phy_version);
3944
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003945 if (ha->fce) {
3946 ha->flags.fce_enabled = 1;
3947 memset(ha->fce, 0,
3948 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003949 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003950 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3951 &ha->fce_bufs);
3952 if (rval) {
3953 qla_printk(KERN_WARNING, ha,
3954 "Unable to reinitialize FCE "
3955 "(%d).\n", rval);
3956 ha->flags.fce_enabled = 0;
3957 }
3958 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003959
3960 if (ha->eft) {
3961 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003962 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003963 ha->eft_dma, EFT_NUM_BUFFERS);
3964 if (rval) {
3965 qla_printk(KERN_WARNING, ha,
3966 "Unable to reinitialize EFT "
3967 "(%d).\n", rval);
3968 }
3969 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003971 vha->flags.online = 1;
3972 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 if (ha->isp_abort_cnt == 0) {
3974 qla_printk(KERN_WARNING, ha,
3975 "ISP error recovery failed - "
3976 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003977 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 * The next call disables the board
3979 * completely.
3980 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003981 ha->isp_ops->reset_adapter(vha);
3982 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003984 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985 status = 0;
3986 } else { /* schedule another ISP abort */
3987 ha->isp_abort_cnt--;
3988 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003989 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003990 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991 status = 1;
3992 }
3993 } else {
3994 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3995 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3996 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003997 vha->host_no, ha->isp_abort_cnt));
3998 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 status = 1;
4000 }
4001 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004002
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 }
4004
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004005 if (!status) {
4006 DEBUG(printk(KERN_INFO
4007 "qla2x00_abort_isp(%ld): succeeded.\n",
4008 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08004009 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004010 if (vp->vp_idx)
4011 qla2x00_vp_abort_isp(vp);
4012 }
4013 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014 qla_printk(KERN_INFO, ha,
4015 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016 }
4017
4018 return(status);
4019}
4020
4021/*
4022* qla2x00_restart_isp
4023* restarts the ISP after a reset
4024*
4025* Input:
4026* ha = adapter block pointer.
4027*
4028* Returns:
4029* 0 = success
4030*/
4031static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004032qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004034 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004035 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004036 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004037 struct req_que *req = ha->req_q_map[0];
4038 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039
4040 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004041 if (qla2x00_isp_firmware(vha)) {
4042 vha->flags.online = 0;
4043 status = ha->isp_ops->chip_diag(vha);
4044 if (!status)
4045 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 }
4047
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004048 if (!status && !(status = qla2x00_init_rings(vha))) {
4049 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004050 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004051 /* Initialize the queues in use */
4052 qla25xx_init_queues(ha);
4053
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004054 status = qla2x00_fw_ready(vha);
4055 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004057 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004058
4059 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004060 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004061
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004062 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4064 wait_time = 256;
4065 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004066 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4067 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004069 } while (!atomic_read(&vha->loop_down_timer) &&
4070 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4071 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4072 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 }
4074
4075 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004076 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077 status = 0;
4078
4079 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4080 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004081 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 }
4083 return (status);
4084}
4085
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004086static int
4087qla25xx_init_queues(struct qla_hw_data *ha)
4088{
4089 struct rsp_que *rsp = NULL;
4090 struct req_que *req = NULL;
4091 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4092 int ret = -1;
4093 int i;
4094
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004095 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004096 rsp = ha->rsp_q_map[i];
4097 if (rsp) {
4098 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004099 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004100 if (ret != QLA_SUCCESS)
4101 DEBUG2_17(printk(KERN_WARNING
4102 "%s Rsp que:%d init failed\n", __func__,
4103 rsp->id));
4104 else
4105 DEBUG2_17(printk(KERN_INFO
4106 "%s Rsp que:%d inited\n", __func__,
4107 rsp->id));
4108 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004109 }
4110 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004111 req = ha->req_q_map[i];
4112 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004113 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004114 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004115 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004116 if (ret != QLA_SUCCESS)
4117 DEBUG2_17(printk(KERN_WARNING
4118 "%s Req que:%d init failed\n", __func__,
4119 req->id));
4120 else
4121 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004122 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004123 req->id));
4124 }
4125 }
4126 return ret;
4127}
4128
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129/*
4130* qla2x00_reset_adapter
4131* Reset adapter.
4132*
4133* Input:
4134* ha = adapter block pointer.
4135*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004136void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004137qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138{
4139 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004140 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004141 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004143 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004144 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 spin_lock_irqsave(&ha->hardware_lock, flags);
4147 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4148 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4149 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4150 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4151 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4152}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004153
4154void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004155qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004156{
4157 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004158 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004159 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4160
Giridhar Malavalia9083012010-04-12 17:59:55 -07004161 if (IS_QLA82XX(ha))
4162 return;
4163
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004164 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004165 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004166
4167 spin_lock_irqsave(&ha->hardware_lock, flags);
4168 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4169 RD_REG_DWORD(&reg->hccr);
4170 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4171 RD_REG_DWORD(&reg->hccr);
4172 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004173
4174 if (IS_NOPOLLING_TYPE(ha))
4175 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004176}
4177
David Miller4e08df32007-04-16 12:37:43 -07004178/* On sparc systems, obtain port and node WWN from firmware
4179 * properties.
4180 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004181static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4182 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004183{
4184#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004185 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004186 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004187 struct device_node *dp = pci_device_to_OF_node(pdev);
4188 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004189 int len;
4190
4191 val = of_get_property(dp, "port-wwn", &len);
4192 if (val && len >= WWN_SIZE)
4193 memcpy(nv->port_name, val, WWN_SIZE);
4194
4195 val = of_get_property(dp, "node-wwn", &len);
4196 if (val && len >= WWN_SIZE)
4197 memcpy(nv->node_name, val, WWN_SIZE);
4198#endif
4199}
4200
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004201int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004202qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004203{
David Miller4e08df32007-04-16 12:37:43 -07004204 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004205 struct init_cb_24xx *icb;
4206 struct nvram_24xx *nv;
4207 uint32_t *dptr;
4208 uint8_t *dptr1, *dptr2;
4209 uint32_t chksum;
4210 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004211 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004212
David Miller4e08df32007-04-16 12:37:43 -07004213 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004214 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004215 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004216
4217 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004218 if (ha->flags.port0) {
4219 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4220 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4221 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004222 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004223 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4224 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004225 ha->nvram_size = sizeof(struct nvram_24xx);
4226 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004227 if (IS_QLA82XX(ha))
4228 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004229
Seokmann Ju281afe12007-07-26 13:43:34 -07004230 /* Get VPD data into cache */
4231 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004232 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004233 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4234
4235 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004236 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004237 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004238 ha->nvram_size);
4239 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4240 chksum += le32_to_cpu(*dptr++);
4241
Andrew Vasquez76403352009-04-06 22:33:39 -07004242 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07004243 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004244
4245 /* Bad NVRAM data, set defaults parameters. */
4246 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4247 || nv->id[3] != ' ' ||
4248 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4249 /* Reset NVRAM data. */
4250 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4251 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4252 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07004253 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4254 "invalid -- WWPN) defaults.\n");
4255
4256 /*
4257 * Set default initialization control block.
4258 */
4259 memset(nv, 0, ha->nvram_size);
4260 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4261 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4262 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4263 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4264 nv->exchange_count = __constant_cpu_to_le16(0);
4265 nv->hard_address = __constant_cpu_to_le16(124);
4266 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004267 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004268 nv->port_name[2] = 0x00;
4269 nv->port_name[3] = 0xe0;
4270 nv->port_name[4] = 0x8b;
4271 nv->port_name[5] = 0x1c;
4272 nv->port_name[6] = 0x55;
4273 nv->port_name[7] = 0x86;
4274 nv->node_name[0] = 0x20;
4275 nv->node_name[1] = 0x00;
4276 nv->node_name[2] = 0x00;
4277 nv->node_name[3] = 0xe0;
4278 nv->node_name[4] = 0x8b;
4279 nv->node_name[5] = 0x1c;
4280 nv->node_name[6] = 0x55;
4281 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004282 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004283 nv->login_retry_count = __constant_cpu_to_le16(8);
4284 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4285 nv->login_timeout = __constant_cpu_to_le16(0);
4286 nv->firmware_options_1 =
4287 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4288 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4289 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4290 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4291 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4292 nv->efi_parameters = __constant_cpu_to_le32(0);
4293 nv->reset_delay = 5;
4294 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4295 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4296 nv->link_down_timeout = __constant_cpu_to_le16(30);
4297
4298 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004299 }
4300
4301 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004302 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004303
4304 /* Copy 1st segment. */
4305 dptr1 = (uint8_t *)icb;
4306 dptr2 = (uint8_t *)&nv->version;
4307 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4308 while (cnt--)
4309 *dptr1++ = *dptr2++;
4310
4311 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004312 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004313
4314 /* Copy 2nd segment. */
4315 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4316 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4317 cnt = (uint8_t *)&icb->reserved_3 -
4318 (uint8_t *)&icb->interrupt_delay_timer;
4319 while (cnt--)
4320 *dptr1++ = *dptr2++;
4321
4322 /*
4323 * Setup driver NVRAM options.
4324 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004325 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004326 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004327
Andrew Vasquez5341e862006-05-17 15:09:16 -07004328 /* Use alternate WWN? */
4329 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4330 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4331 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4332 }
4333
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004334 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004335 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004336 /*
4337 * Firmware will apply the following mask if the nodename was
4338 * not provided.
4339 */
4340 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4341 icb->node_name[0] &= 0xF0;
4342 }
4343
4344 /* Set host adapter parameters. */
4345 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004346 ha->flags.enable_lip_reset = 0;
4347 ha->flags.enable_lip_full_login =
4348 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4349 ha->flags.enable_target_reset =
4350 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004351 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004352 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004353
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004354 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4355 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004356
4357 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4358 sizeof(ha->fw_seriallink_options24));
4359
4360 /* save HBA serial number */
4361 ha->serial0 = icb->port_name[5];
4362 ha->serial1 = icb->port_name[6];
4363 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004364 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4365 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004366
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004367 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4368
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004369 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4370
4371 /* Set minimum login_timeout to 4 seconds. */
4372 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4373 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4374 if (le16_to_cpu(nv->login_timeout) < 4)
4375 nv->login_timeout = __constant_cpu_to_le16(4);
4376 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004377 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004378
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004379 /* Set minimum RATOV to 100 tenths of a second. */
4380 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004381
4382 ha->loop_reset_delay = nv->reset_delay;
4383
4384 /* Link Down Timeout = 0:
4385 *
4386 * When Port Down timer expires we will start returning
4387 * I/O's to OS with "DID_NO_CONNECT".
4388 *
4389 * Link Down Timeout != 0:
4390 *
4391 * The driver waits for the link to come up after link down
4392 * before returning I/Os to OS with "DID_NO_CONNECT".
4393 */
4394 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4395 ha->loop_down_abort_time =
4396 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4397 } else {
4398 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4399 ha->loop_down_abort_time =
4400 (LOOP_DOWN_TIME - ha->link_down_timeout);
4401 }
4402
4403 /* Need enough time to try and get the port back. */
4404 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4405 if (qlport_down_retry)
4406 ha->port_down_retry_count = qlport_down_retry;
4407
4408 /* Set login_retry_count */
4409 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4410 if (ha->port_down_retry_count ==
4411 le16_to_cpu(nv->port_down_retry_count) &&
4412 ha->port_down_retry_count > 3)
4413 ha->login_retry_count = ha->port_down_retry_count;
4414 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4415 ha->login_retry_count = ha->port_down_retry_count;
4416 if (ql2xloginretrycount)
4417 ha->login_retry_count = ql2xloginretrycount;
4418
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004419 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004420 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004421 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4422 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4423 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4424 le16_to_cpu(icb->interrupt_delay_timer): 2;
4425 }
4426 icb->firmware_options_2 &= __constant_cpu_to_le32(
4427 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004428 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004429 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004430 ha->zio_mode = QLA_ZIO_MODE_6;
4431
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004432 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004433 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004434 ha->zio_timer * 100));
4435 qla_printk(KERN_INFO, ha,
4436 "ZIO mode %d enabled; timer delay (%d us).\n",
4437 ha->zio_mode, ha->zio_timer * 100);
4438
4439 icb->firmware_options_2 |= cpu_to_le32(
4440 (uint32_t)ha->zio_mode);
4441 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004442 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004443 }
4444
David Miller4e08df32007-04-16 12:37:43 -07004445 if (rval) {
4446 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004447 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004448 }
4449 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004450}
4451
Adrian Bunk413975a2006-06-30 02:33:06 -07004452static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004453qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4454 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004455{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004456 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004457 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004458 uint32_t *dcode, dlen;
4459 uint32_t risc_addr;
4460 uint32_t risc_size;
4461 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004462 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004463 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004464
4465 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004466 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004467
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004468 rval = QLA_SUCCESS;
4469
4470 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004471 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004472 *srisc_addr = 0;
4473
4474 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004475 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004476 for (i = 0; i < 4; i++)
4477 dcode[i] = be32_to_cpu(dcode[i]);
4478 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4479 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4480 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4481 dcode[3] == 0)) {
4482 qla_printk(KERN_WARNING, ha,
4483 "Unable to verify integrity of flash firmware image!\n");
4484 qla_printk(KERN_WARNING, ha,
4485 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4486 dcode[1], dcode[2], dcode[3]);
4487
4488 return QLA_FUNCTION_FAILED;
4489 }
4490
4491 while (segments && rval == QLA_SUCCESS) {
4492 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004493 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004494
4495 risc_addr = be32_to_cpu(dcode[2]);
4496 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4497 risc_size = be32_to_cpu(dcode[3]);
4498
4499 fragment = 0;
4500 while (risc_size > 0 && rval == QLA_SUCCESS) {
4501 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4502 if (dlen > risc_size)
4503 dlen = risc_size;
4504
4505 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4506 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004507 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004508
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004509 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004510 for (i = 0; i < dlen; i++)
4511 dcode[i] = swab32(dcode[i]);
4512
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004513 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004514 dlen);
4515 if (rval) {
4516 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004517 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004518 fragment));
4519 qla_printk(KERN_WARNING, ha,
4520 "[ERROR] Failed to load segment %d of "
4521 "firmware\n", fragment);
4522 break;
4523 }
4524
4525 faddr += dlen;
4526 risc_addr += dlen;
4527 risc_size -= dlen;
4528 fragment++;
4529 }
4530
4531 /* Next segment. */
4532 segments--;
4533 }
4534
4535 return rval;
4536}
4537
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004538#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4539
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004540int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004541qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004542{
4543 int rval;
4544 int i, fragment;
4545 uint16_t *wcode, *fwcode;
4546 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4547 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004548 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004549 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004550
4551 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004552 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004553 if (!blob) {
4554 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004555 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4556 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004557 return QLA_FUNCTION_FAILED;
4558 }
4559
4560 rval = QLA_SUCCESS;
4561
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004562 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004563 *srisc_addr = 0;
4564 fwcode = (uint16_t *)blob->fw->data;
4565 fwclen = 0;
4566
4567 /* Validate firmware image by checking version. */
4568 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4569 qla_printk(KERN_WARNING, ha,
4570 "Unable to verify integrity of firmware image (%Zd)!\n",
4571 blob->fw->size);
4572 goto fail_fw_integrity;
4573 }
4574 for (i = 0; i < 4; i++)
4575 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4576 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4577 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4578 wcode[2] == 0 && wcode[3] == 0)) {
4579 qla_printk(KERN_WARNING, ha,
4580 "Unable to verify integrity of firmware image!\n");
4581 qla_printk(KERN_WARNING, ha,
4582 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4583 wcode[1], wcode[2], wcode[3]);
4584 goto fail_fw_integrity;
4585 }
4586
4587 seg = blob->segs;
4588 while (*seg && rval == QLA_SUCCESS) {
4589 risc_addr = *seg;
4590 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4591 risc_size = be16_to_cpu(fwcode[3]);
4592
4593 /* Validate firmware image size. */
4594 fwclen += risc_size * sizeof(uint16_t);
4595 if (blob->fw->size < fwclen) {
4596 qla_printk(KERN_WARNING, ha,
4597 "Unable to verify integrity of firmware image "
4598 "(%Zd)!\n", blob->fw->size);
4599 goto fail_fw_integrity;
4600 }
4601
4602 fragment = 0;
4603 while (risc_size > 0 && rval == QLA_SUCCESS) {
4604 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4605 if (wlen > risc_size)
4606 wlen = risc_size;
4607
4608 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004609 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004610 risc_addr, wlen));
4611
4612 for (i = 0; i < wlen; i++)
4613 wcode[i] = swab16(fwcode[i]);
4614
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004615 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004616 wlen);
4617 if (rval) {
4618 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004619 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004620 fragment));
4621 qla_printk(KERN_WARNING, ha,
4622 "[ERROR] Failed to load segment %d of "
4623 "firmware\n", fragment);
4624 break;
4625 }
4626
4627 fwcode += wlen;
4628 risc_addr += wlen;
4629 risc_size -= wlen;
4630 fragment++;
4631 }
4632
4633 /* Next segment. */
4634 seg++;
4635 }
4636 return rval;
4637
4638fail_fw_integrity:
4639 return QLA_FUNCTION_FAILED;
4640}
4641
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004642static int
4643qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004644{
4645 int rval;
4646 int segments, fragment;
4647 uint32_t *dcode, dlen;
4648 uint32_t risc_addr;
4649 uint32_t risc_size;
4650 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004651 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004652 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004653 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004654 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004655
Andrew Vasquez54333832005-11-09 15:49:04 -08004656 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004657 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004658 if (!blob) {
4659 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004660 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4661 "from: " QLA_FW_URL ".\n");
4662
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004663 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004664 }
4665
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004666 qla_printk(KERN_INFO, ha,
4667 "FW: Loading via request-firmware...\n");
4668
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004669 rval = QLA_SUCCESS;
4670
4671 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004672 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004673 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004674 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004675 fwclen = 0;
4676
4677 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004678 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004679 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004680 "Unable to verify integrity of firmware image (%Zd)!\n",
4681 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004682 goto fail_fw_integrity;
4683 }
4684 for (i = 0; i < 4; i++)
4685 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4686 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4687 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4688 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4689 dcode[3] == 0)) {
4690 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004691 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004692 qla_printk(KERN_WARNING, ha,
4693 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4694 dcode[1], dcode[2], dcode[3]);
4695 goto fail_fw_integrity;
4696 }
4697
4698 while (segments && rval == QLA_SUCCESS) {
4699 risc_addr = be32_to_cpu(fwcode[2]);
4700 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4701 risc_size = be32_to_cpu(fwcode[3]);
4702
4703 /* Validate firmware image size. */
4704 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004705 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004706 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004707 "Unable to verify integrity of firmware image "
4708 "(%Zd)!\n", blob->fw->size);
4709
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004710 goto fail_fw_integrity;
4711 }
4712
4713 fragment = 0;
4714 while (risc_size > 0 && rval == QLA_SUCCESS) {
4715 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4716 if (dlen > risc_size)
4717 dlen = risc_size;
4718
4719 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004720 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004721 risc_addr, dlen));
4722
4723 for (i = 0; i < dlen; i++)
4724 dcode[i] = swab32(fwcode[i]);
4725
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004726 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004727 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004728 if (rval) {
4729 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004730 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004731 fragment));
4732 qla_printk(KERN_WARNING, ha,
4733 "[ERROR] Failed to load segment %d of "
4734 "firmware\n", fragment);
4735 break;
4736 }
4737
4738 fwcode += dlen;
4739 risc_addr += dlen;
4740 risc_size -= dlen;
4741 fragment++;
4742 }
4743
4744 /* Next segment. */
4745 segments--;
4746 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004747 return rval;
4748
4749fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004750 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004751}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004752
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004753int
4754qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4755{
4756 int rval;
4757
Andrew Vasqueze337d902009-04-06 22:33:49 -07004758 if (ql2xfwloadbin == 1)
4759 return qla81xx_load_risc(vha, srisc_addr);
4760
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004761 /*
4762 * FW Load priority:
4763 * 1) Firmware via request-firmware interface (.bin file).
4764 * 2) Firmware residing in flash.
4765 */
4766 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4767 if (rval == QLA_SUCCESS)
4768 return rval;
4769
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004770 return qla24xx_load_risc_flash(vha, srisc_addr,
4771 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004772}
4773
4774int
4775qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4776{
4777 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004778 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004779
Andrew Vasqueze337d902009-04-06 22:33:49 -07004780 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004781 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004782
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004783 /*
4784 * FW Load priority:
4785 * 1) Firmware residing in flash.
4786 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004787 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004788 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004789 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004790 if (rval == QLA_SUCCESS)
4791 return rval;
4792
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004793try_blob_fw:
4794 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4795 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4796 return rval;
4797
4798 qla_printk(KERN_ERR, ha,
4799 "FW: Attempting to fallback to golden firmware...\n");
4800 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4801 if (rval != QLA_SUCCESS)
4802 return rval;
4803
4804 qla_printk(KERN_ERR, ha,
4805 "FW: Please update operational firmware...\n");
4806 ha->flags.running_gold_fw = 1;
4807
4808 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004809}
4810
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004811void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004812qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004813{
4814 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004815 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004816
Andrew Vasquez85880802009-12-15 21:29:46 -08004817 if (ha->flags.pci_channel_io_perm_failure)
4818 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004819 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004820 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004821 if (!ha->fw_major_version)
4822 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004823
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004824 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004825 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004826 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004827 ha->isp_ops->reset_chip(vha);
4828 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004829 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004830 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004831 continue;
4832 qla_printk(KERN_INFO, ha,
4833 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004834 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004835 }
4836}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004837
4838int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004839qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004840{
4841 int rval = QLA_SUCCESS;
4842 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004843 struct qla_hw_data *ha = vha->hw;
4844 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004845 struct req_que *req;
4846 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004847
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004848 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004849 return -EINVAL;
4850
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004851 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004852 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004853 req = ha->req_q_map[0];
4854 else
4855 req = vha->req;
4856 rsp = req->rsp;
4857
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004858 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004859 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004860 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004861 }
4862
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004863 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004864
4865 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004866 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004867 if (mb[0] != MBS_COMMAND_COMPLETE) {
4868 DEBUG15(qla_printk(KERN_INFO, ha,
4869 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4870 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4871 mb[0], mb[1], mb[2], mb[6], mb[7]));
4872 return (QLA_FUNCTION_FAILED);
4873 }
4874
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004875 atomic_set(&vha->loop_down_timer, 0);
4876 atomic_set(&vha->loop_state, LOOP_UP);
4877 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4878 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4879 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004880
4881 return rval;
4882}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004883
4884/* 84XX Support **************************************************************/
4885
4886static LIST_HEAD(qla_cs84xx_list);
4887static DEFINE_MUTEX(qla_cs84xx_mutex);
4888
4889static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004890qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004891{
4892 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004893 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004894
4895 mutex_lock(&qla_cs84xx_mutex);
4896
4897 /* Find any shared 84xx chip. */
4898 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4899 if (cs84xx->bus == ha->pdev->bus) {
4900 kref_get(&cs84xx->kref);
4901 goto done;
4902 }
4903 }
4904
4905 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4906 if (!cs84xx)
4907 goto done;
4908
4909 kref_init(&cs84xx->kref);
4910 spin_lock_init(&cs84xx->access_lock);
4911 mutex_init(&cs84xx->fw_update_mutex);
4912 cs84xx->bus = ha->pdev->bus;
4913
4914 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4915done:
4916 mutex_unlock(&qla_cs84xx_mutex);
4917 return cs84xx;
4918}
4919
4920static void
4921__qla84xx_chip_release(struct kref *kref)
4922{
4923 struct qla_chip_state_84xx *cs84xx =
4924 container_of(kref, struct qla_chip_state_84xx, kref);
4925
4926 mutex_lock(&qla_cs84xx_mutex);
4927 list_del(&cs84xx->list);
4928 mutex_unlock(&qla_cs84xx_mutex);
4929 kfree(cs84xx);
4930}
4931
4932void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004933qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004934{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004935 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004936 if (ha->cs84xx)
4937 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4938}
4939
4940static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004941qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004942{
4943 int rval;
4944 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004945 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004946
4947 mutex_lock(&ha->cs84xx->fw_update_mutex);
4948
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004949 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004950
4951 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4952
4953 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4954 QLA_SUCCESS;
4955}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004956
4957/* 81XX Support **************************************************************/
4958
4959int
4960qla81xx_nvram_config(scsi_qla_host_t *vha)
4961{
4962 int rval;
4963 struct init_cb_81xx *icb;
4964 struct nvram_81xx *nv;
4965 uint32_t *dptr;
4966 uint8_t *dptr1, *dptr2;
4967 uint32_t chksum;
4968 uint16_t cnt;
4969 struct qla_hw_data *ha = vha->hw;
4970
4971 rval = QLA_SUCCESS;
4972 icb = (struct init_cb_81xx *)ha->init_cb;
4973 nv = ha->nvram;
4974
4975 /* Determine NVRAM starting address. */
4976 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004977 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004978
4979 /* Get VPD data into cache */
4980 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004981 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4982 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004983
4984 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004985 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004986 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004987 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004988 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4989 chksum += le32_to_cpu(*dptr++);
4990
Andrew Vasquez76403352009-04-06 22:33:39 -07004991 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004992 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4993
4994 /* Bad NVRAM data, set defaults parameters. */
4995 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4996 || nv->id[3] != ' ' ||
4997 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4998 /* Reset NVRAM data. */
4999 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
5000 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
5001 le16_to_cpu(nv->nvram_version));
5002 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
5003 "invalid -- WWPN) defaults.\n");
5004
5005 /*
5006 * Set default initialization control block.
5007 */
5008 memset(nv, 0, ha->nvram_size);
5009 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5010 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5011 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5012 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5013 nv->exchange_count = __constant_cpu_to_le16(0);
5014 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005015 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005016 nv->port_name[2] = 0x00;
5017 nv->port_name[3] = 0xe0;
5018 nv->port_name[4] = 0x8b;
5019 nv->port_name[5] = 0x1c;
5020 nv->port_name[6] = 0x55;
5021 nv->port_name[7] = 0x86;
5022 nv->node_name[0] = 0x20;
5023 nv->node_name[1] = 0x00;
5024 nv->node_name[2] = 0x00;
5025 nv->node_name[3] = 0xe0;
5026 nv->node_name[4] = 0x8b;
5027 nv->node_name[5] = 0x1c;
5028 nv->node_name[6] = 0x55;
5029 nv->node_name[7] = 0x86;
5030 nv->login_retry_count = __constant_cpu_to_le16(8);
5031 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5032 nv->login_timeout = __constant_cpu_to_le16(0);
5033 nv->firmware_options_1 =
5034 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5035 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5036 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5037 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5038 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5039 nv->efi_parameters = __constant_cpu_to_le32(0);
5040 nv->reset_delay = 5;
5041 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5042 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5043 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005044 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005045 nv->enode_mac[1] = 0x02;
5046 nv->enode_mac[2] = 0x03;
5047 nv->enode_mac[3] = 0x04;
5048 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005049 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005050
5051 rval = 1;
5052 }
5053
5054 /* Reset Initialization control block */
5055 memset(icb, 0, sizeof(struct init_cb_81xx));
5056
5057 /* Copy 1st segment. */
5058 dptr1 = (uint8_t *)icb;
5059 dptr2 = (uint8_t *)&nv->version;
5060 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5061 while (cnt--)
5062 *dptr1++ = *dptr2++;
5063
5064 icb->login_retry_count = nv->login_retry_count;
5065
5066 /* Copy 2nd segment. */
5067 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5068 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5069 cnt = (uint8_t *)&icb->reserved_5 -
5070 (uint8_t *)&icb->interrupt_delay_timer;
5071 while (cnt--)
5072 *dptr1++ = *dptr2++;
5073
5074 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5075 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5076 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
5077 icb->enode_mac[0] = 0x01;
5078 icb->enode_mac[1] = 0x02;
5079 icb->enode_mac[2] = 0x03;
5080 icb->enode_mac[3] = 0x04;
5081 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005082 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005083 }
5084
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005085 /* Use extended-initialization control block. */
5086 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5087
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005088 /*
5089 * Setup driver NVRAM options.
5090 */
5091 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005092 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005093
5094 /* Use alternate WWN? */
5095 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5096 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5097 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5098 }
5099
5100 /* Prepare nodename */
5101 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5102 /*
5103 * Firmware will apply the following mask if the nodename was
5104 * not provided.
5105 */
5106 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5107 icb->node_name[0] &= 0xF0;
5108 }
5109
5110 /* Set host adapter parameters. */
5111 ha->flags.disable_risc_code_load = 0;
5112 ha->flags.enable_lip_reset = 0;
5113 ha->flags.enable_lip_full_login =
5114 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5115 ha->flags.enable_target_reset =
5116 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5117 ha->flags.enable_led_scheme = 0;
5118 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5119
5120 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5121 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5122
5123 /* save HBA serial number */
5124 ha->serial0 = icb->port_name[5];
5125 ha->serial1 = icb->port_name[6];
5126 ha->serial2 = icb->port_name[7];
5127 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5128 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5129
5130 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5131
5132 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5133
5134 /* Set minimum login_timeout to 4 seconds. */
5135 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5136 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5137 if (le16_to_cpu(nv->login_timeout) < 4)
5138 nv->login_timeout = __constant_cpu_to_le16(4);
5139 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5140 icb->login_timeout = nv->login_timeout;
5141
5142 /* Set minimum RATOV to 100 tenths of a second. */
5143 ha->r_a_tov = 100;
5144
5145 ha->loop_reset_delay = nv->reset_delay;
5146
5147 /* Link Down Timeout = 0:
5148 *
5149 * When Port Down timer expires we will start returning
5150 * I/O's to OS with "DID_NO_CONNECT".
5151 *
5152 * Link Down Timeout != 0:
5153 *
5154 * The driver waits for the link to come up after link down
5155 * before returning I/Os to OS with "DID_NO_CONNECT".
5156 */
5157 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5158 ha->loop_down_abort_time =
5159 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5160 } else {
5161 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5162 ha->loop_down_abort_time =
5163 (LOOP_DOWN_TIME - ha->link_down_timeout);
5164 }
5165
5166 /* Need enough time to try and get the port back. */
5167 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5168 if (qlport_down_retry)
5169 ha->port_down_retry_count = qlport_down_retry;
5170
5171 /* Set login_retry_count */
5172 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5173 if (ha->port_down_retry_count ==
5174 le16_to_cpu(nv->port_down_retry_count) &&
5175 ha->port_down_retry_count > 3)
5176 ha->login_retry_count = ha->port_down_retry_count;
5177 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5178 ha->login_retry_count = ha->port_down_retry_count;
5179 if (ql2xloginretrycount)
5180 ha->login_retry_count = ql2xloginretrycount;
5181
5182 /* Enable ZIO. */
5183 if (!vha->flags.init_done) {
5184 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5185 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5186 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5187 le16_to_cpu(icb->interrupt_delay_timer): 2;
5188 }
5189 icb->firmware_options_2 &= __constant_cpu_to_le32(
5190 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5191 vha->flags.process_response_queue = 0;
5192 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5193 ha->zio_mode = QLA_ZIO_MODE_6;
5194
5195 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5196 "(%d us).\n", vha->host_no, ha->zio_mode,
5197 ha->zio_timer * 100));
5198 qla_printk(KERN_INFO, ha,
5199 "ZIO mode %d enabled; timer delay (%d us).\n",
5200 ha->zio_mode, ha->zio_timer * 100);
5201
5202 icb->firmware_options_2 |= cpu_to_le32(
5203 (uint32_t)ha->zio_mode);
5204 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5205 vha->flags.process_response_queue = 1;
5206 }
5207
5208 if (rval) {
5209 DEBUG2_3(printk(KERN_WARNING
5210 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
5211 }
5212 return (rval);
5213}
5214
Giridhar Malavalia9083012010-04-12 17:59:55 -07005215int
5216qla82xx_restart_isp(scsi_qla_host_t *vha)
5217{
5218 int status, rval;
5219 uint32_t wait_time;
5220 struct qla_hw_data *ha = vha->hw;
5221 struct req_que *req = ha->req_q_map[0];
5222 struct rsp_que *rsp = ha->rsp_q_map[0];
5223 struct scsi_qla_host *vp;
5224 struct scsi_qla_host *tvp;
5225
5226 status = qla2x00_init_rings(vha);
5227 if (!status) {
5228 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5229 ha->flags.chip_reset_done = 1;
5230
5231 status = qla2x00_fw_ready(vha);
5232 if (!status) {
5233 qla_printk(KERN_INFO, ha,
5234 "%s(): Start configure loop, "
5235 "status = %d\n", __func__, status);
5236
5237 /* Issue a marker after FW becomes ready. */
5238 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5239
5240 vha->flags.online = 1;
5241 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5242 wait_time = 256;
5243 do {
5244 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5245 qla2x00_configure_loop(vha);
5246 wait_time--;
5247 } while (!atomic_read(&vha->loop_down_timer) &&
5248 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5249 wait_time &&
5250 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5251 }
5252
5253 /* if no cable then assume it's good */
5254 if ((vha->device_flags & DFLG_NO_CABLE))
5255 status = 0;
5256
5257 qla_printk(KERN_INFO, ha,
5258 "%s(): Configure loop done, status = 0x%x\n",
5259 __func__, status);
5260 }
5261
5262 if (!status) {
5263 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5264
5265 if (!atomic_read(&vha->loop_down_timer)) {
5266 /*
5267 * Issue marker command only when we are going
5268 * to start the I/O .
5269 */
5270 vha->marker_needed = 1;
5271 }
5272
5273 vha->flags.online = 1;
5274
5275 ha->isp_ops->enable_intrs(ha);
5276
5277 ha->isp_abort_cnt = 0;
5278 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5279
5280 if (ha->fce) {
5281 ha->flags.fce_enabled = 1;
5282 memset(ha->fce, 0,
5283 fce_calc_size(ha->fce_bufs));
5284 rval = qla2x00_enable_fce_trace(vha,
5285 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5286 &ha->fce_bufs);
5287 if (rval) {
5288 qla_printk(KERN_WARNING, ha,
5289 "Unable to reinitialize FCE "
5290 "(%d).\n", rval);
5291 ha->flags.fce_enabled = 0;
5292 }
5293 }
5294
5295 if (ha->eft) {
5296 memset(ha->eft, 0, EFT_SIZE);
5297 rval = qla2x00_enable_eft_trace(vha,
5298 ha->eft_dma, EFT_NUM_BUFFERS);
5299 if (rval) {
5300 qla_printk(KERN_WARNING, ha,
5301 "Unable to reinitialize EFT "
5302 "(%d).\n", rval);
5303 }
5304 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005305 }
5306
5307 if (!status) {
5308 DEBUG(printk(KERN_INFO
5309 "qla82xx_restart_isp(%ld): succeeded.\n",
5310 vha->host_no));
5311 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
5312 if (vp->vp_idx)
5313 qla2x00_vp_abort_isp(vp);
5314 }
5315 } else {
5316 qla_printk(KERN_INFO, ha,
5317 "qla82xx_restart_isp: **** FAILED ****\n");
5318 }
5319
5320 return status;
5321}
5322
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005323void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005324qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005325{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005326 struct qla_hw_data *ha = vha->hw;
5327
5328 if (!ql2xetsenable)
5329 return;
5330
5331 /* Enable ETS Burst. */
5332 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5333 ha->fw_options[2] |= BIT_9;
5334 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005335}
Sarang Radke09ff7012010-03-19 17:03:59 -07005336
5337/*
5338 * qla24xx_get_fcp_prio
5339 * Gets the fcp cmd priority value for the logged in port.
5340 * Looks for a match of the port descriptors within
5341 * each of the fcp prio config entries. If a match is found,
5342 * the tag (priority) value is returned.
5343 *
5344 * Input:
5345 * ha = adapter block po
5346 * fcport = port structure pointer.
5347 *
5348 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005349 * non-zero (if found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005350 * 0 (if not found)
5351 *
5352 * Context:
5353 * Kernel context
5354 */
5355uint8_t
5356qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5357{
5358 int i, entries;
5359 uint8_t pid_match, wwn_match;
5360 uint8_t priority;
5361 uint32_t pid1, pid2;
5362 uint64_t wwn1, wwn2;
5363 struct qla_fcp_prio_entry *pri_entry;
5364 struct qla_hw_data *ha = vha->hw;
5365
5366 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
5367 return 0;
5368
5369 priority = 0;
5370 entries = ha->fcp_prio_cfg->num_entries;
5371 pri_entry = &ha->fcp_prio_cfg->entry[0];
5372
5373 for (i = 0; i < entries; i++) {
5374 pid_match = wwn_match = 0;
5375
5376 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5377 pri_entry++;
5378 continue;
5379 }
5380
5381 /* check source pid for a match */
5382 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5383 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5384 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5385 if (pid1 == INVALID_PORT_ID)
5386 pid_match++;
5387 else if (pid1 == pid2)
5388 pid_match++;
5389 }
5390
5391 /* check destination pid for a match */
5392 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5393 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5394 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5395 if (pid1 == INVALID_PORT_ID)
5396 pid_match++;
5397 else if (pid1 == pid2)
5398 pid_match++;
5399 }
5400
5401 /* check source WWN for a match */
5402 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5403 wwn1 = wwn_to_u64(vha->port_name);
5404 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5405 if (wwn2 == (uint64_t)-1)
5406 wwn_match++;
5407 else if (wwn1 == wwn2)
5408 wwn_match++;
5409 }
5410
5411 /* check destination WWN for a match */
5412 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5413 wwn1 = wwn_to_u64(fcport->port_name);
5414 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5415 if (wwn2 == (uint64_t)-1)
5416 wwn_match++;
5417 else if (wwn1 == wwn2)
5418 wwn_match++;
5419 }
5420
5421 if (pid_match == 2 || wwn_match == 2) {
5422 /* Found a matching entry */
5423 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5424 priority = pri_entry->tag;
5425 break;
5426 }
5427
5428 pri_entry++;
5429 }
5430
5431 return priority;
5432}
5433
5434/*
5435 * qla24xx_update_fcport_fcp_prio
5436 * Activates fcp priority for the logged in fc port
5437 *
5438 * Input:
5439 * ha = adapter block pointer.
5440 * fcp = port structure pointer.
5441 *
5442 * Return:
5443 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5444 *
5445 * Context:
5446 * Kernel context.
5447 */
5448int
5449qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *ha, fc_port_t *fcport)
5450{
5451 int ret;
5452 uint8_t priority;
5453 uint16_t mb[5];
5454
5455 if (atomic_read(&fcport->state) == FCS_UNCONFIGURED ||
5456 fcport->port_type != FCT_TARGET ||
5457 fcport->loop_id == FC_NO_LOOP_ID)
5458 return QLA_FUNCTION_FAILED;
5459
5460 priority = qla24xx_get_fcp_prio(ha, fcport);
5461 ret = qla24xx_set_fcp_prio(ha, fcport->loop_id, priority, mb);
5462 if (ret == QLA_SUCCESS)
5463 fcport->fcp_prio = priority;
5464 else
5465 DEBUG2(printk(KERN_WARNING
5466 "scsi(%ld): Unable to activate fcp priority, "
5467 " ret=0x%x\n", ha->host_no, ret));
5468
5469 return ret;
5470}
5471
5472/*
5473 * qla24xx_update_all_fcp_prio
5474 * Activates fcp priority for all the logged in ports
5475 *
5476 * Input:
5477 * ha = adapter block pointer.
5478 *
5479 * Return:
5480 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5481 *
5482 * Context:
5483 * Kernel context.
5484 */
5485int
5486qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5487{
5488 int ret;
5489 fc_port_t *fcport;
5490
5491 ret = QLA_FUNCTION_FAILED;
5492 /* We need to set priority for all logged in ports */
5493 list_for_each_entry(fcport, &vha->vp_fcports, list)
5494 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5495
5496 return ret;
5497}