blob: 77c68a789681c7788b4f2ed3c637aa0fd221f7ca [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;
Arun Easifeafb7b2010-09-03 14:57:00 -070072 struct scsi_qla_host *vha = sp->fcport->vha;
Andrew Vasquezac280b62009-08-20 11:06:05 -070073
Chad Dupuis4d97cc52010-10-15 11:27:41 -070074 del_timer(&iocb->timer);
Madhuranath Iyengar49163922010-05-04 15:01:28 -070075 kfree(iocb);
Andrew Vasquezac280b62009-08-20 11:06:05 -070076 kfree(ctx);
77 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
Arun Easifeafb7b2010-09-03 14:57:00 -070078
79 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquezac280b62009-08-20 11:06:05 -070080}
81
82inline srb_t *
83qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
84 unsigned long tmo)
85{
Arun Easifeafb7b2010-09-03 14:57:00 -070086 srb_t *sp = NULL;
Andrew Vasquezac280b62009-08-20 11:06:05 -070087 struct qla_hw_data *ha = vha->hw;
88 struct srb_ctx *ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070089 struct srb_iocb *iocb;
Arun Easifeafb7b2010-09-03 14:57:00 -070090 uint8_t bail;
91
92 QLA_VHA_MARK_BUSY(vha, bail);
93 if (bail)
94 return NULL;
Andrew Vasquezac280b62009-08-20 11:06:05 -070095
96 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
97 if (!sp)
98 goto done;
99 ctx = kzalloc(size, GFP_KERNEL);
100 if (!ctx) {
101 mempool_free(sp, ha->srb_mempool);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700102 sp = NULL;
103 goto done;
104 }
105 iocb = kzalloc(sizeof(struct srb_iocb), GFP_KERNEL);
106 if (!iocb) {
107 mempool_free(sp, ha->srb_mempool);
108 sp = NULL;
109 kfree(ctx);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700110 goto done;
111 }
112
113 memset(sp, 0, sizeof(*sp));
114 sp->fcport = fcport;
115 sp->ctx = ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700116 ctx->u.iocb_cmd = iocb;
117 iocb->free = qla2x00_ctx_sp_free;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700118
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700119 init_timer(&iocb->timer);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700120 if (!tmo)
121 goto done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700122 iocb->timer.expires = jiffies + tmo * HZ;
123 iocb->timer.data = (unsigned long)sp;
124 iocb->timer.function = qla2x00_ctx_sp_timeout;
125 add_timer(&iocb->timer);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700126done:
Arun Easifeafb7b2010-09-03 14:57:00 -0700127 if (!sp)
128 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700129 return sp;
130}
131
132/* Asynchronous Login/Logout Routines -------------------------------------- */
133
Andrew Vasquez5b914902010-05-28 15:08:30 -0700134static inline unsigned long
135qla2x00_get_async_timeout(struct scsi_qla_host *vha)
136{
137 unsigned long tmo;
138 struct qla_hw_data *ha = vha->hw;
139
140 /* Firmware should use switch negotiated r_a_tov for timeout. */
141 tmo = ha->r_a_tov / 10 * 2;
142 if (!IS_FWI2_CAPABLE(ha)) {
143 /*
144 * Except for earlier ISPs where the timeout is seeded from the
145 * initialization control block.
146 */
147 tmo = ha->login_timeout;
148 }
149 return tmo;
150}
Andrew Vasquezac280b62009-08-20 11:06:05 -0700151
152static void
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700153qla2x00_async_iocb_timeout(srb_t *sp)
Andrew Vasquezac280b62009-08-20 11:06:05 -0700154{
155 fc_port_t *fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700156 struct srb_ctx *ctx = sp->ctx;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700157
158 DEBUG2(printk(KERN_WARNING
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -0700159 "scsi(%ld:%x): Async-%s timeout - portid=%02x%02x%02x.\n",
160 fcport->vha->host_no, sp->handle,
161 ctx->name, fcport->d_id.b.domain,
162 fcport->d_id.b.area, fcport->d_id.b.al_pa));
Andrew Vasquezac280b62009-08-20 11:06:05 -0700163
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700164 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700165 if (ctx->type == SRB_LOGIN_CMD) {
166 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700167 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700168 /* Retry as needed. */
169 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
170 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
171 QLA_LOGIO_LOGIN_RETRIED : 0;
172 qla2x00_post_async_login_done_work(fcport->vha, fcport,
173 lio->u.logio.data);
174 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700175}
176
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700177static void
178qla2x00_async_login_ctx_done(srb_t *sp)
179{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700180 struct srb_ctx *ctx = sp->ctx;
181 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700182
183 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700184 lio->u.logio.data);
185 lio->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700186}
187
Andrew Vasquezac280b62009-08-20 11:06:05 -0700188int
189qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
190 uint16_t *data)
191{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700192 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700193 struct srb_ctx *ctx;
194 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700195 int rval;
196
197 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700198 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700199 qla2x00_get_async_timeout(vha) + 2);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700200 if (!sp)
201 goto done;
202
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700203 ctx = sp->ctx;
204 ctx->type = SRB_LOGIN_CMD;
205 ctx->name = "login";
206 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700207 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700208 lio->done = qla2x00_async_login_ctx_done;
209 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700210 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700211 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700212 rval = qla2x00_start_sp(sp);
213 if (rval != QLA_SUCCESS)
214 goto done_free_sp;
215
216 DEBUG2(printk(KERN_DEBUG
217 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
218 "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
219 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
220 fcport->login_retry));
221 return rval;
222
223done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700224 lio->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700225done:
226 return rval;
227}
228
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700229static void
230qla2x00_async_logout_ctx_done(srb_t *sp)
231{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700232 struct srb_ctx *ctx = sp->ctx;
233 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700234
235 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700236 lio->u.logio.data);
237 lio->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700238}
239
Andrew Vasquezac280b62009-08-20 11:06:05 -0700240int
241qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
242{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700243 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700244 struct srb_ctx *ctx;
245 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700246 int rval;
247
248 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700249 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700250 qla2x00_get_async_timeout(vha) + 2);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700251 if (!sp)
252 goto done;
253
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700254 ctx = sp->ctx;
255 ctx->type = SRB_LOGOUT_CMD;
256 ctx->name = "logout";
257 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700258 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700259 lio->done = qla2x00_async_logout_ctx_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700260 rval = qla2x00_start_sp(sp);
261 if (rval != QLA_SUCCESS)
262 goto done_free_sp;
263
264 DEBUG2(printk(KERN_DEBUG
265 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
266 fcport->vha->host_no, sp->handle, fcport->loop_id,
267 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
268 return rval;
269
270done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700271 lio->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700272done:
273 return rval;
274}
275
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700276static void
277qla2x00_async_adisc_ctx_done(srb_t *sp)
278{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700279 struct srb_ctx *ctx = sp->ctx;
280 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700281
282 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700283 lio->u.logio.data);
284 lio->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700285}
286
287int
288qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
289 uint16_t *data)
290{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700291 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700292 struct srb_ctx *ctx;
293 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700294 int rval;
295
296 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700297 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700298 qla2x00_get_async_timeout(vha) + 2);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700299 if (!sp)
300 goto done;
301
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700302 ctx = sp->ctx;
303 ctx->type = SRB_ADISC_CMD;
304 ctx->name = "adisc";
305 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700306 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700307 lio->done = qla2x00_async_adisc_ctx_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700308 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700309 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700310 rval = qla2x00_start_sp(sp);
311 if (rval != QLA_SUCCESS)
312 goto done_free_sp;
313
314 DEBUG2(printk(KERN_DEBUG
315 "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n",
316 fcport->vha->host_no, sp->handle, fcport->loop_id,
317 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
318
319 return rval;
320
321done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700322 lio->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700323done:
324 return rval;
325}
326
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700327static void
328qla2x00_async_tm_cmd_ctx_done(srb_t *sp)
329{
330 struct srb_ctx *ctx = sp->ctx;
331 struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd;
332
333 qla2x00_async_tm_cmd_done(sp->fcport->vha, sp->fcport, iocb);
334 iocb->free(sp);
335}
336
337int
338qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
339 uint32_t tag)
340{
341 struct scsi_qla_host *vha = fcport->vha;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700342 srb_t *sp;
343 struct srb_ctx *ctx;
344 struct srb_iocb *tcf;
345 int rval;
346
347 rval = QLA_FUNCTION_FAILED;
348 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700349 qla2x00_get_async_timeout(vha) + 2);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700350 if (!sp)
351 goto done;
352
353 ctx = sp->ctx;
354 ctx->type = SRB_TM_CMD;
355 ctx->name = "tmf";
356 tcf = ctx->u.iocb_cmd;
357 tcf->u.tmf.flags = flags;
358 tcf->u.tmf.lun = lun;
359 tcf->u.tmf.data = tag;
360 tcf->timeout = qla2x00_async_iocb_timeout;
361 tcf->done = qla2x00_async_tm_cmd_ctx_done;
362
363 rval = qla2x00_start_sp(sp);
364 if (rval != QLA_SUCCESS)
365 goto done_free_sp;
366
367 DEBUG2(printk(KERN_DEBUG
368 "scsi(%ld:%x): Async-tmf - loop-id=%x portid=%02x%02x%02x.\n",
369 fcport->vha->host_no, sp->handle, fcport->loop_id,
370 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
371
372 return rval;
373
374done_free_sp:
375 tcf->free(sp);
376done:
377 return rval;
378}
379
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700380void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700381qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
382 uint16_t *data)
383{
384 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700385
386 switch (data[0]) {
387 case MBS_COMMAND_COMPLETE:
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700388 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700389 fcport->flags |= FCF_ASYNC_SENT;
390 qla2x00_post_async_adisc_work(vha, fcport, data);
391 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700392 }
393 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700394 break;
395 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700396 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700397 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
398 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
399 else
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700400 qla2x00_mark_device_lost(vha, fcport, 1, 1);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700401 break;
402 case MBS_PORT_ID_USED:
403 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700404 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700405 qla2x00_post_async_login_work(vha, fcport, NULL);
406 break;
407 case MBS_LOOP_ID_USED:
408 fcport->loop_id++;
409 rval = qla2x00_find_new_loop_id(vha, fcport);
410 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700411 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700412 qla2x00_mark_device_lost(vha, fcport, 1, 1);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700413 break;
414 }
415 qla2x00_post_async_login_work(vha, fcport, NULL);
416 break;
417 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700418 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700419}
420
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700421void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700422qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
423 uint16_t *data)
424{
425 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700426 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700427}
428
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700429void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700430qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
431 uint16_t *data)
432{
433 if (data[0] == MBS_COMMAND_COMPLETE) {
434 qla2x00_update_fcport(vha, fcport);
435
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700436 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700437 }
438
439 /* Retry login. */
440 fcport->flags &= ~FCF_ASYNC_SENT;
441 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
442 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
443 else
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700444 qla2x00_mark_device_lost(vha, fcport, 1, 1);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700445
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700446 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700447}
448
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700449void
450qla2x00_async_tm_cmd_done(struct scsi_qla_host *vha, fc_port_t *fcport,
451 struct srb_iocb *iocb)
452{
453 int rval;
454 uint32_t flags;
455 uint16_t lun;
456
457 flags = iocb->u.tmf.flags;
458 lun = (uint16_t)iocb->u.tmf.lun;
459
460 /* Issue Marker IOCB */
Giridhar Malavalid94d10e2010-07-23 15:28:23 +0500461 rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
462 vha->hw->rsp_q_map[0], fcport->loop_id, lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700463 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
464
465 if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
466 DEBUG2_3_11(printk(KERN_WARNING
467 "%s(%ld): TM IOCB failed (%x).\n",
468 __func__, vha->host_no, rval));
469 }
470
471 return;
472}
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474/****************************************************************************/
475/* QLogic ISP2x00 Hardware Support Functions. */
476/****************************************************************************/
477
478/*
479* qla2x00_initialize_adapter
480* Initialize board.
481*
482* Input:
483* ha = adapter block pointer.
484*
485* Returns:
486* 0 = success
487*/
488int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800489qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490{
491 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800492 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800493 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800496 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700497 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800498 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800499 ha->flags.pci_channel_io_perm_failure = 0;
500 ha->flags.eeh_busy = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800501 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
502 atomic_set(&vha->loop_state, LOOP_DOWN);
503 vha->device_flags = DFLG_NO_CABLE;
504 vha->dpc_flags = 0;
505 vha->flags.management_server_logged_in = 0;
506 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 ha->isp_abort_cnt = 0;
508 ha->beacon_blink_led = 0;
509
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800510 set_bit(0, ha->req_qid_map);
511 set_bit(0, ha->rsp_qid_map);
512
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700513 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800514 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -0800516 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800517 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 return (rval);
519 }
520
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800521 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800523 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700524 if (rval) {
525 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800526 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700527 return (rval);
528 }
529
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800530 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -0800531
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700533
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800534 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700536 if (ha->flags.disable_serdes) {
537 /* Mask HBA via NVRAM settings? */
538 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
539 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800540 vha->port_name[0], vha->port_name[1],
541 vha->port_name[2], vha->port_name[3],
542 vha->port_name[4], vha->port_name[5],
543 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700544 return QLA_FUNCTION_FAILED;
545 }
546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
548
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800549 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
550 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800551 if (rval)
552 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800553 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800554 if (rval)
555 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700557
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700558 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800559 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700560 if (!ha->cs84xx) {
561 qla_printk(KERN_ERR, ha,
562 "Unable to configure ISP84XX.\n");
563 return QLA_FUNCTION_FAILED;
564 }
565 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800566 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700567 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800569 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700570 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800571 rval = qla84xx_init_chip(vha);
572 if (rval != QLA_SUCCESS) {
573 qla_printk(KERN_ERR, ha,
574 "Unable to initialize ISP84XX.\n");
575 qla84xx_put_chip(vha);
576 }
577 }
578
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500579 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
580 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 return (rval);
583}
584
585/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700586 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 * @ha: HA context
588 *
589 * Returns 0 on success.
590 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700591int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800592qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700594 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700595 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800596 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700597 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700600 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700603 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
605
Andrew Vasquez737faec2008-10-24 15:13:45 -0700606 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700608 /* Get PCI bus information. */
609 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700610 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700611 spin_unlock_irqrestore(&ha->hardware_lock, flags);
612
613 return QLA_SUCCESS;
614}
615
616/**
617 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
618 * @ha: HA context
619 *
620 * Returns 0 on success.
621 */
622int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800623qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700624{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700625 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700626 unsigned long flags = 0;
627 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800628 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700629 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700630
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700631 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700632 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700633
634 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700635 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700636
637 if (IS_QLA2322(ha) || IS_QLA6322(ha))
638 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700639 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700640
641 /*
642 * If this is a 2300 card and not 2312, reset the
643 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
644 * the 2310 also reports itself as a 2300 so we need to get the
645 * fb revision level -- a 6 indicates it really is a 2300 and
646 * not a 2310.
647 */
648 if (IS_QLA2300(ha)) {
649 spin_lock_irqsave(&ha->hardware_lock, flags);
650
651 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700652 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700653 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700654 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700655 break;
656
657 udelay(10);
658 }
659
660 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700661 WRT_REG_WORD(&reg->ctrl_status, 0x20);
662 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700663
664 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700665 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700666
667 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700668 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700669
670 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700671 WRT_REG_WORD(&reg->ctrl_status, 0x0);
672 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700673
674 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700675 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700676 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700677 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700678 break;
679
680 udelay(10);
681 }
682
683 spin_unlock_irqrestore(&ha->hardware_lock, flags);
684 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700685
686 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
687
Andrew Vasquez737faec2008-10-24 15:13:45 -0700688 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700689
690 /* Get PCI bus information. */
691 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700692 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700693 spin_unlock_irqrestore(&ha->hardware_lock, flags);
694
695 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696}
697
698/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700699 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
700 * @ha: HA context
701 *
702 * Returns 0 on success.
703 */
704int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800705qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700706{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700707 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700708 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800709 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700710 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700711
712 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700713 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700714
715 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700716 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700717 w &= ~PCI_COMMAND_INTX_DISABLE;
718 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
719
720 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
721
722 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700723 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
724 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700725
726 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700727 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
728 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700729
Andrew Vasquez737faec2008-10-24 15:13:45 -0700730 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700731
Auke Kok44c10132007-06-08 15:46:36 -0700732 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800733
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700734 /* Get PCI bus information. */
735 spin_lock_irqsave(&ha->hardware_lock, flags);
736 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
737 spin_unlock_irqrestore(&ha->hardware_lock, flags);
738
739 return QLA_SUCCESS;
740}
741
742/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700743 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
744 * @ha: HA context
745 *
746 * Returns 0 on success.
747 */
748int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800749qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700750{
751 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800752 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700753
754 pci_set_master(ha->pdev);
755 pci_try_set_mwi(ha->pdev);
756
757 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
758 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
759 w &= ~PCI_COMMAND_INTX_DISABLE;
760 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
761
762 /* PCIe -- adjust Maximum Read Request Size (2048). */
763 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
764 pcie_set_readrq(ha->pdev, 2048);
765
Andrew Vasquez737faec2008-10-24 15:13:45 -0700766 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700767
768 ha->chip_revision = ha->pdev->revision;
769
770 return QLA_SUCCESS;
771}
772
773/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 * qla2x00_isp_firmware() - Choose firmware image.
775 * @ha: HA context
776 *
777 * Returns 0 on success.
778 */
779static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800780qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781{
782 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700783 uint16_t loop_id, topo, sw_cap;
784 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800785 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700788 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
790 if (ha->flags.disable_risc_code_load) {
791 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800792 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
794
795 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800796 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700797 if (rval == QLA_SUCCESS) {
798 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800799 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700800 &area, &domain, &topo, &sw_cap);
801 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 }
803
804 if (rval) {
805 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800806 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 }
808
809 return (rval);
810}
811
812/**
813 * qla2x00_reset_chip() - Reset ISP chip.
814 * @ha: HA context
815 *
816 * Returns 0 on success.
817 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700818void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800819qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
821 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800822 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700823 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 uint16_t cmd;
826
Andrew Vasquez85880802009-12-15 21:29:46 -0800827 if (unlikely(pci_channel_offline(ha->pdev)))
828 return;
829
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700830 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
832 spin_lock_irqsave(&ha->hardware_lock, flags);
833
834 /* Turn off master enable */
835 cmd = 0;
836 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
837 cmd &= ~PCI_COMMAND_MASTER;
838 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
839
840 if (!IS_QLA2100(ha)) {
841 /* Pause RISC. */
842 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
843 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
844 for (cnt = 0; cnt < 30000; cnt++) {
845 if ((RD_REG_WORD(&reg->hccr) &
846 HCCR_RISC_PAUSE) != 0)
847 break;
848 udelay(100);
849 }
850 } else {
851 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
852 udelay(10);
853 }
854
855 /* Select FPM registers. */
856 WRT_REG_WORD(&reg->ctrl_status, 0x20);
857 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
858
859 /* FPM Soft Reset. */
860 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
861 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
862
863 /* Toggle Fpm Reset. */
864 if (!IS_QLA2200(ha)) {
865 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
866 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
867 }
868
869 /* Select frame buffer registers. */
870 WRT_REG_WORD(&reg->ctrl_status, 0x10);
871 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
872
873 /* Reset frame buffer FIFOs. */
874 if (IS_QLA2200(ha)) {
875 WRT_FB_CMD_REG(ha, reg, 0xa000);
876 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
877 } else {
878 WRT_FB_CMD_REG(ha, reg, 0x00fc);
879
880 /* Read back fb_cmd until zero or 3 seconds max */
881 for (cnt = 0; cnt < 3000; cnt++) {
882 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
883 break;
884 udelay(100);
885 }
886 }
887
888 /* Select RISC module registers. */
889 WRT_REG_WORD(&reg->ctrl_status, 0);
890 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
891
892 /* Reset RISC processor. */
893 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
894 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
895
896 /* Release RISC processor. */
897 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
898 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
899 }
900
901 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
902 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
903
904 /* Reset ISP chip. */
905 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
906
907 /* Wait for RISC to recover from reset. */
908 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
909 /*
910 * It is necessary to for a delay here since the card doesn't
911 * respond to PCI reads during a reset. On some architectures
912 * this will result in an MCA.
913 */
914 udelay(20);
915 for (cnt = 30000; cnt; cnt--) {
916 if ((RD_REG_WORD(&reg->ctrl_status) &
917 CSR_ISP_SOFT_RESET) == 0)
918 break;
919 udelay(100);
920 }
921 } else
922 udelay(10);
923
924 /* Reset RISC processor. */
925 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
926
927 WRT_REG_WORD(&reg->semaphore, 0);
928
929 /* Release RISC processor. */
930 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
931 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
932
933 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
934 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700935 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
938 udelay(100);
939 }
940 } else
941 udelay(100);
942
943 /* Turn on master enable */
944 cmd |= PCI_COMMAND_MASTER;
945 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
946
947 /* Disable RISC pause on FPM parity error. */
948 if (!IS_QLA2100(ha)) {
949 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
950 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
951 }
952
953 spin_unlock_irqrestore(&ha->hardware_lock, flags);
954}
955
956/**
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700957 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
958 *
959 * Returns 0 on success.
960 */
961int
962qla81xx_reset_mpi(scsi_qla_host_t *vha)
963{
964 uint16_t mb[4] = {0x1010, 0, 1, 0};
965
966 return qla81xx_write_mpi_register(vha, mb);
967}
968
969/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700970 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700971 * @ha: HA context
972 *
973 * Returns 0 on success.
974 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700975static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800976qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700977{
978 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800979 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700980 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
981 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800982 uint16_t wd;
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700983 static int abts_cnt; /* ISP abort retry counts */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700984
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700985 spin_lock_irqsave(&ha->hardware_lock, flags);
986
987 /* Reset RISC. */
988 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
989 for (cnt = 0; cnt < 30000; cnt++) {
990 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
991 break;
992
993 udelay(10);
994 }
995
996 WRT_REG_DWORD(&reg->ctrl_status,
997 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800998 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700999
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001000 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001001 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001002 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1003 for (cnt = 10000 ; cnt && d2; cnt--) {
1004 udelay(5);
1005 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1006 barrier();
1007 }
1008
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001009 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001010 d2 = RD_REG_DWORD(&reg->ctrl_status);
1011 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1012 udelay(5);
1013 d2 = RD_REG_DWORD(&reg->ctrl_status);
1014 barrier();
1015 }
1016
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001017 /* If required, do an MPI FW reset now */
1018 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1019 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1020 if (++abts_cnt < 5) {
1021 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1022 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1023 } else {
1024 /*
1025 * We exhausted the ISP abort retries. We have to
1026 * set the board offline.
1027 */
1028 abts_cnt = 0;
1029 vha->flags.online = 0;
1030 }
1031 }
1032 }
1033
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001034 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1035 RD_REG_DWORD(&reg->hccr);
1036
1037 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1038 RD_REG_DWORD(&reg->hccr);
1039
1040 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1041 RD_REG_DWORD(&reg->hccr);
1042
1043 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1044 for (cnt = 6000000 ; cnt && d2; cnt--) {
1045 udelay(5);
1046 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1047 barrier();
1048 }
1049
1050 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001051
1052 if (IS_NOPOLLING_TYPE(ha))
1053 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001054}
1055
1056/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001057 * qla24xx_reset_chip() - Reset ISP24xx chip.
1058 * @ha: HA context
1059 *
1060 * Returns 0 on success.
1061 */
1062void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001063qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001064{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001065 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001066
1067 if (pci_channel_offline(ha->pdev) &&
1068 ha->flags.pci_channel_io_perm_failure) {
1069 return;
1070 }
1071
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001072 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001073
1074 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001075 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001076}
1077
1078/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 * qla2x00_chip_diag() - Test chip for proper operation.
1080 * @ha: HA context
1081 *
1082 * Returns 0 on success.
1083 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001084int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001085qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086{
1087 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001088 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001089 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 unsigned long flags = 0;
1091 uint16_t data;
1092 uint32_t cnt;
1093 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001094 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
1096 /* Assume a failed state */
1097 rval = QLA_FUNCTION_FAILED;
1098
1099 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001100 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
1102 spin_lock_irqsave(&ha->hardware_lock, flags);
1103
1104 /* Reset ISP chip. */
1105 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1106
1107 /*
1108 * We need to have a delay here since the card will not respond while
1109 * in reset causing an MCA on some architectures.
1110 */
1111 udelay(20);
1112 data = qla2x00_debounce_register(&reg->ctrl_status);
1113 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1114 udelay(5);
1115 data = RD_REG_WORD(&reg->ctrl_status);
1116 barrier();
1117 }
1118
1119 if (!cnt)
1120 goto chip_diag_failed;
1121
1122 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07001123 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
1125 /* Reset RISC processor. */
1126 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1127 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1128
1129 /* Workaround for QLA2312 PCI parity error */
1130 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1131 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1132 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1133 udelay(5);
1134 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001135 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 }
1137 } else
1138 udelay(10);
1139
1140 if (!cnt)
1141 goto chip_diag_failed;
1142
1143 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -07001144 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1147 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1148 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1149 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1150 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1151 mb[3] != PROD_ID_3) {
1152 qla_printk(KERN_WARNING, ha,
1153 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
1154
1155 goto chip_diag_failed;
1156 }
1157 ha->product_id[0] = mb[1];
1158 ha->product_id[1] = mb[2];
1159 ha->product_id[2] = mb[3];
1160 ha->product_id[3] = mb[4];
1161
1162 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001163 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1165 else
1166 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001167 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
1169 if (IS_QLA2200(ha) &&
1170 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1171 /* Limit firmware transfer size with a 2200A */
1172 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001173 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001175 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 ha->fw_transfer_size = 128;
1177 }
1178
1179 /* Wrap Incoming Mailboxes Test. */
1180 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1181
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001182 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
1183 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 if (rval) {
1185 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001186 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 qla_printk(KERN_WARNING, ha,
1188 "Failed mailbox send register test\n");
1189 }
1190 else {
1191 /* Flag a successful rval */
1192 rval = QLA_SUCCESS;
1193 }
1194 spin_lock_irqsave(&ha->hardware_lock, flags);
1195
1196chip_diag_failed:
1197 if (rval)
1198 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001199 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
1201 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1202
1203 return (rval);
1204}
1205
1206/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001207 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1208 * @ha: HA context
1209 *
1210 * Returns 0 on success.
1211 */
1212int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001213qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001214{
1215 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001216 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001217 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001218
Giridhar Malavalia9083012010-04-12 17:59:55 -07001219 if (IS_QLA82XX(ha))
1220 return QLA_SUCCESS;
1221
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001222 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001223
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001224 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001225 if (rval) {
1226 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001227 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001228 qla_printk(KERN_WARNING, ha,
1229 "Failed mailbox send register test\n");
1230 } else {
1231 /* Flag a successful rval */
1232 rval = QLA_SUCCESS;
1233 }
1234
1235 return rval;
1236}
1237
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001238void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001239qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001240{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001241 int rval;
1242 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001243 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001244 dma_addr_t tc_dma;
1245 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001246 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001247 struct req_que *req = ha->req_q_map[0];
1248 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001249
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001250 if (ha->fw_dump) {
1251 qla_printk(KERN_WARNING, ha,
1252 "Firmware dump previously allocated.\n");
1253 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001254 }
1255
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001256 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001257 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001258 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1259 fixed_size = sizeof(struct qla2100_fw_dump);
1260 } else if (IS_QLA23XX(ha)) {
1261 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1262 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1263 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001264 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001265 if (IS_QLA81XX(ha))
1266 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1267 else if (IS_QLA25XX(ha))
1268 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1269 else
1270 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001271 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1272 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001273 if (ha->mqenable)
1274 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001275 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001276 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001277 goto try_eft;
1278
1279 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1280 GFP_KERNEL);
1281 if (!tc) {
1282 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1283 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001284 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001285 }
1286
1287 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001288 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001289 ha->fce_mb, &ha->fce_bufs);
1290 if (rval) {
1291 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1292 "FCE (%d).\n", rval);
1293 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1294 tc_dma);
1295 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001296 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001297 }
1298
1299 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1300 FCE_SIZE / 1024);
1301
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001302 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001303 ha->flags.fce_enabled = 1;
1304 ha->fce_dma = tc_dma;
1305 ha->fce = tc;
1306try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001307 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001308 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001309 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001310 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001311 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1312 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1313 goto cont_alloc;
1314 }
1315
Andrew Vasquezfc447652008-01-17 09:02:18 -08001316 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001317 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001318 if (rval) {
1319 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1320 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001321 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1322 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001323 goto cont_alloc;
1324 }
1325
1326 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1327 EFT_SIZE / 1024);
1328
1329 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001330 ha->eft_dma = tc_dma;
1331 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001332 }
1333cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001334 req_q_size = req->length * sizeof(request_t);
1335 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001336
1337 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001338 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001339 ha->chain_offset = dump_size;
1340 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001341
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001342 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001343 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001344 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001345 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001346
1347 if (ha->eft) {
1348 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1349 ha->eft_dma);
1350 ha->eft = NULL;
1351 ha->eft_dma = 0;
1352 }
1353 return;
1354 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001355 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1356 dump_size / 1024);
1357
1358 ha->fw_dump_len = dump_size;
1359 ha->fw_dump->signature[0] = 'Q';
1360 ha->fw_dump->signature[1] = 'L';
1361 ha->fw_dump->signature[2] = 'G';
1362 ha->fw_dump->signature[3] = 'C';
1363 ha->fw_dump->version = __constant_htonl(1);
1364
1365 ha->fw_dump->fixed_size = htonl(fixed_size);
1366 ha->fw_dump->mem_size = htonl(mem_size);
1367 ha->fw_dump->req_q_size = htonl(req_q_size);
1368 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1369
1370 ha->fw_dump->eft_size = htonl(eft_size);
1371 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1372 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1373
1374 ha->fw_dump->header_size =
1375 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001376}
1377
Andrew Vasquez18e75552009-06-03 09:55:30 -07001378static int
1379qla81xx_mpi_sync(scsi_qla_host_t *vha)
1380{
1381#define MPS_MASK 0xe0
1382 int rval;
1383 uint16_t dc;
1384 uint32_t dw;
1385 struct qla_hw_data *ha = vha->hw;
1386
1387 if (!IS_QLA81XX(vha->hw))
1388 return QLA_SUCCESS;
1389
1390 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1391 if (rval != QLA_SUCCESS) {
1392 DEBUG2(qla_printk(KERN_WARNING, ha,
1393 "Sync-MPI: Unable to acquire semaphore.\n"));
1394 goto done;
1395 }
1396
1397 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1398 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1399 if (rval != QLA_SUCCESS) {
1400 DEBUG2(qla_printk(KERN_WARNING, ha,
1401 "Sync-MPI: Unable to read sync.\n"));
1402 goto done_release;
1403 }
1404
1405 dc &= MPS_MASK;
1406 if (dc == (dw & MPS_MASK))
1407 goto done_release;
1408
1409 dw &= ~MPS_MASK;
1410 dw |= dc;
1411 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1412 if (rval != QLA_SUCCESS) {
1413 DEBUG2(qla_printk(KERN_WARNING, ha,
1414 "Sync-MPI: Unable to gain sync.\n"));
1415 }
1416
1417done_release:
1418 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1419 if (rval != QLA_SUCCESS) {
1420 DEBUG2(qla_printk(KERN_WARNING, ha,
1421 "Sync-MPI: Unable to release semaphore.\n"));
1422 }
1423
1424done:
1425 return rval;
1426}
1427
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001428/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 * qla2x00_setup_chip() - Load and start RISC firmware.
1430 * @ha: HA context
1431 *
1432 * Returns 0 on success.
1433 */
1434static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001435qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001437 int rval;
1438 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001439 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001440 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1441 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001442 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001443
Giridhar Malavalia9083012010-04-12 17:59:55 -07001444 if (IS_QLA82XX(ha)) {
1445 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001446 if (rval == QLA_SUCCESS) {
1447 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001448 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001449 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001450 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001451 }
1452
Andrew Vasquez3db06522008-01-31 12:33:49 -08001453 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1454 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1455 spin_lock_irqsave(&ha->hardware_lock, flags);
1456 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1457 RD_REG_WORD(&reg->hccr);
1458 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1459 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
Andrew Vasquez18e75552009-06-03 09:55:30 -07001461 qla81xx_mpi_sync(vha);
1462
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001464 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001465 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001467 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001469 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 if (rval == QLA_SUCCESS) {
1471 /* Start firmware execution. */
1472 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001473 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001475 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001477 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001478enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001479 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001480 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 &ha->fw_major_version,
1482 &ha->fw_minor_version,
1483 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001484 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001485 ha->mpi_version, &ha->mpi_capabilities,
1486 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001487 if (rval != QLA_SUCCESS)
1488 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001489 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001490 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001491 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001492 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001493 if ((!ha->max_npiv_vports) ||
1494 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001495 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001496 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001497 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001498 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001499 qla2x00_get_resource_cnts(vha, NULL,
1500 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001501 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001502
Giridhar Malavalia9083012010-04-12 17:59:55 -07001503 if (!fw_major_version && ql2xallocfwdump) {
1504 if (!IS_QLA82XX(ha))
1505 qla2x00_alloc_fw_dump(vha);
1506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 }
1508 } else {
1509 DEBUG2(printk(KERN_INFO
1510 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001511 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 }
1513 }
1514
Andrew Vasquez3db06522008-01-31 12:33:49 -08001515 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1516 /* Enable proper parity. */
1517 spin_lock_irqsave(&ha->hardware_lock, flags);
1518 if (IS_QLA2300(ha))
1519 /* SRAM parity */
1520 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1521 else
1522 /* SRAM, Instruction RAM and GP RAM parity */
1523 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1524 RD_REG_WORD(&reg->hccr);
1525 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1526 }
1527
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001528 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1529 uint32_t size;
1530
1531 rval = qla81xx_fac_get_sector_size(vha, &size);
1532 if (rval == QLA_SUCCESS) {
1533 ha->flags.fac_supported = 1;
1534 ha->fdt_block_size = size << 2;
1535 } else {
1536 qla_printk(KERN_ERR, ha,
1537 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1538 ha->fw_major_version, ha->fw_minor_version,
1539 ha->fw_subminor_version);
1540 }
1541 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001542failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 if (rval) {
1544 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001545 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 }
1547
1548 return (rval);
1549}
1550
1551/**
1552 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1553 * @ha: HA context
1554 *
1555 * Beginning of request ring has initialization control block already built
1556 * by nvram config routine.
1557 *
1558 * Returns 0 on success.
1559 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001560void
1561qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562{
1563 uint16_t cnt;
1564 response_t *pkt;
1565
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001566 rsp->ring_ptr = rsp->ring;
1567 rsp->ring_index = 0;
1568 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001569 pkt = rsp->ring_ptr;
1570 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 pkt->signature = RESPONSE_PROCESSED;
1572 pkt++;
1573 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574}
1575
1576/**
1577 * qla2x00_update_fw_options() - Read and process firmware options.
1578 * @ha: HA context
1579 *
1580 * Returns 0 on success.
1581 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001582void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001583qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584{
1585 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001586 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
1588 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001589 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
1591 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1592 return;
1593
1594 /* Serial Link options. */
1595 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001596 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1598 sizeof(ha->fw_seriallink_options)));
1599
1600 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1601 if (ha->fw_seriallink_options[3] & BIT_2) {
1602 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1603
1604 /* 1G settings */
1605 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1606 emphasis = (ha->fw_seriallink_options[2] &
1607 (BIT_4 | BIT_3)) >> 3;
1608 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001609 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 rx_sens = (ha->fw_seriallink_options[0] &
1611 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1612 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1613 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1614 if (rx_sens == 0x0)
1615 rx_sens = 0x3;
1616 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1617 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1618 ha->fw_options[10] |= BIT_5 |
1619 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1620 (tx_sens & (BIT_1 | BIT_0));
1621
1622 /* 2G settings */
1623 swing = (ha->fw_seriallink_options[2] &
1624 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1625 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1626 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001627 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 rx_sens = (ha->fw_seriallink_options[1] &
1629 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1630 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1631 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1632 if (rx_sens == 0x0)
1633 rx_sens = 0x3;
1634 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1635 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1636 ha->fw_options[11] |= BIT_5 |
1637 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1638 (tx_sens & (BIT_1 | BIT_0));
1639 }
1640
1641 /* FCP2 options. */
1642 /* Return command IOCBs without waiting for an ABTS to complete. */
1643 ha->fw_options[3] |= BIT_13;
1644
1645 /* LED scheme. */
1646 if (ha->flags.enable_led_scheme)
1647 ha->fw_options[2] |= BIT_12;
1648
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001649 /* Detect ISP6312. */
1650 if (IS_QLA6312(ha))
1651 ha->fw_options[2] |= BIT_13;
1652
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001654 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655}
1656
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001657void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001658qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001659{
1660 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001661 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001662
Giridhar Malavalia9083012010-04-12 17:59:55 -07001663 if (IS_QLA82XX(ha))
1664 return;
1665
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001666 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001667 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001668 return;
1669
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001670 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001671 le16_to_cpu(ha->fw_seriallink_options24[1]),
1672 le16_to_cpu(ha->fw_seriallink_options24[2]),
1673 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001674 if (rval != QLA_SUCCESS) {
1675 qla_printk(KERN_WARNING, ha,
1676 "Unable to update Serial Link options (%x).\n", rval);
1677 }
1678}
1679
1680void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001681qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001682{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001683 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001684 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001685 struct req_que *req = ha->req_q_map[0];
1686 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001687
1688 /* Setup ring parameters in initialization control block. */
1689 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1690 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001691 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1692 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1693 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1694 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1695 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1696 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001697
1698 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1699 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1700 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1701 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1702 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1703}
1704
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001705void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001706qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001707{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001708 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001709 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1710 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1711 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001712 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001713 uint16_t rid = 0;
1714 struct req_que *req = ha->req_q_map[0];
1715 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001716
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001717/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001718 icb = (struct init_cb_24xx *)ha->init_cb;
1719 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1720 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001721 icb->request_q_length = cpu_to_le16(req->length);
1722 icb->response_q_length = cpu_to_le16(rsp->length);
1723 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1724 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1725 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1726 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001727
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001728 if (ha->mqenable) {
1729 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1730 icb->rid = __constant_cpu_to_le16(rid);
1731 if (ha->flags.msix_enabled) {
1732 msix = &ha->msix_entries[1];
1733 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001734 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001735 icb->msix = cpu_to_le16(msix->entry);
1736 }
1737 /* Use alternate PCI bus number */
1738 if (MSB(rid))
1739 icb->firmware_options_2 |=
1740 __constant_cpu_to_le32(BIT_19);
1741 /* Use alternate PCI devfn */
1742 if (LSB(rid))
1743 icb->firmware_options_2 |=
1744 __constant_cpu_to_le32(BIT_18);
1745
Anirban Chakraborty31557542009-12-02 10:36:55 -08001746 /* Use Disable MSIX Handshake mode for capable adapters */
1747 if (IS_MSIX_NACK_CAPABLE(ha)) {
1748 icb->firmware_options_2 &=
1749 __constant_cpu_to_le32(~BIT_22);
1750 ha->flags.disable_msix_handshake = 1;
1751 qla_printk(KERN_INFO, ha,
1752 "MSIX Handshake Disable Mode turned on\n");
1753 } else {
1754 icb->firmware_options_2 |=
1755 __constant_cpu_to_le32(BIT_22);
1756 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001757 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001758
1759 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1760 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1761 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1762 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1763 } else {
1764 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1765 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1766 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1767 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1768 }
1769 /* PCI posting */
1770 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001771}
1772
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773/**
1774 * qla2x00_init_rings() - Initializes firmware.
1775 * @ha: HA context
1776 *
1777 * Beginning of request ring has initialization control block already built
1778 * by nvram config routine.
1779 *
1780 * Returns 0 on success.
1781 */
1782static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001783qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784{
1785 int rval;
1786 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001787 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001788 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001789 struct req_que *req;
1790 struct rsp_que *rsp;
1791 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001792 struct mid_init_cb_24xx *mid_init_cb =
1793 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794
1795 spin_lock_irqsave(&ha->hardware_lock, flags);
1796
1797 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001798 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001799 req = ha->req_q_map[que];
1800 if (!req)
1801 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001802 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001803 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001805 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001806
1807 /* Initialize firmware. */
1808 req->ring_ptr = req->ring;
1809 req->ring_index = 0;
1810 req->cnt = req->length;
1811 }
1812
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001813 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001814 rsp = ha->rsp_q_map[que];
1815 if (!rsp)
1816 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001817 /* Initialize response queue entries */
1818 qla2x00_init_response_q_entries(rsp);
1819 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820
Dan Carpenter542bce12010-10-15 11:27:38 -07001821 spin_lock(&ha->vport_slock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001823 list_for_each_entry(vp, &ha->vp_list, list) {
1824 vp->rscn_in_ptr = 0;
1825 vp->rscn_out_ptr = 0;
1826 }
Arun Easifeafb7b2010-09-03 14:57:00 -07001827
Dan Carpenter542bce12010-10-15 11:27:38 -07001828 spin_unlock(&ha->vport_slock);
Arun Easifeafb7b2010-09-03 14:57:00 -07001829
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001830 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
1832 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1833
1834 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001835 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001837 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001838
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001839 if (ha->flags.npiv_supported) {
1840 if (ha->operating_mode == LOOP)
1841 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001842 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001843 }
1844
Andrew Vasquez24a08132009-03-24 09:08:16 -07001845 if (IS_FWI2_CAPABLE(ha)) {
1846 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1847 mid_init_cb->init_cb.execution_throttle =
1848 cpu_to_le16(ha->fw_xcb_count);
1849 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001850
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001851 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 if (rval) {
1853 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001854 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 } else {
1856 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001857 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 }
1859
1860 return (rval);
1861}
1862
1863/**
1864 * qla2x00_fw_ready() - Waits for firmware ready.
1865 * @ha: HA context
1866 *
1867 * Returns 0 on success.
1868 */
1869static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001870qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871{
1872 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001873 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 uint16_t min_wait; /* Minimum wait time if loop is down */
1875 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001876 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001877 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
1879 rval = QLA_SUCCESS;
1880
1881 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001882 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
1884 /*
1885 * Firmware should take at most one RATOV to login, plus 5 seconds for
1886 * our own processing.
1887 */
1888 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1889 wait_time = min_wait;
1890 }
1891
1892 /* Min wait time if loop down */
1893 mtime = jiffies + (min_wait * HZ);
1894
1895 /* wait time before firmware ready */
1896 wtime = jiffies + (wait_time * HZ);
1897
1898 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001899 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1901
1902 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001903 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904
1905 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001906 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001908 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001909 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001911 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1912 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001913 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001914 state[2]));
1915 if ((state[2] & FSTATE_LOGGED_IN) &&
1916 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1917 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001918 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001919
1920 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001921 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001922 if (rval != QLA_SUCCESS)
1923 break;
1924
1925 /* Add time taken to initialize. */
1926 cs84xx_time = jiffies - cs84xx_time;
1927 wtime += cs84xx_time;
1928 mtime += cs84xx_time;
1929 DEBUG16(printk("scsi(%ld): Increasing "
1930 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001931 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001932 }
1933 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001935 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001937 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 &ha->login_timeout, &ha->r_a_tov);
1939
1940 rval = QLA_SUCCESS;
1941 break;
1942 }
1943
1944 rval = QLA_FUNCTION_FAILED;
1945
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001946 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001947 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001949 * other than Wait for Login.
1950 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 if (time_after_eq(jiffies, mtime)) {
1952 qla_printk(KERN_INFO, ha,
1953 "Cable is unplugged...\n");
1954
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001955 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 break;
1957 }
1958 }
1959 } else {
1960 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07001961 if (time_after_eq(jiffies, mtime) ||
1962 (IS_QLA82XX(ha) && ha->flags.fw_hung))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 break;
1964 }
1965
1966 if (time_after_eq(jiffies, wtime))
1967 break;
1968
1969 /* Delay for a while */
1970 msleep(500);
1971
1972 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001973 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 } while (1);
1975
Andrew Vasquez656e8912009-06-03 09:55:29 -07001976 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1977 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1978 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
1980 if (rval) {
1981 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001982 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 }
1984
1985 return (rval);
1986}
1987
1988/*
1989* qla2x00_configure_hba
1990* Setup adapter context.
1991*
1992* Input:
1993* ha = adapter state pointer.
1994*
1995* Returns:
1996* 0 = success
1997*
1998* Context:
1999* Kernel context.
2000*/
2001static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002002qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003{
2004 int rval;
2005 uint16_t loop_id;
2006 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002007 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 uint8_t al_pa;
2009 uint8_t area;
2010 uint8_t domain;
2011 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002012 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
2014 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002015 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002016 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002018 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002019 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
2020 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002021 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08002022 } else {
2023 qla_printk(KERN_WARNING, ha,
2024 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002025 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002026 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 return (rval);
2028 }
2029
2030 if (topo == 4) {
2031 qla_printk(KERN_INFO, ha,
2032 "Cannot get topology - retrying.\n");
2033 return (QLA_FUNCTION_FAILED);
2034 }
2035
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002036 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037
2038 /* initialize */
2039 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2040 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002041 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042
2043 switch (topo) {
2044 case 0:
2045 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002046 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 ha->current_topology = ISP_CFG_NL;
2048 strcpy(connect_type, "(Loop)");
2049 break;
2050
2051 case 1:
2052 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002053 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002054 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 ha->current_topology = ISP_CFG_FL;
2056 strcpy(connect_type, "(FL_Port)");
2057 break;
2058
2059 case 2:
2060 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002061 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 ha->operating_mode = P2P;
2063 ha->current_topology = ISP_CFG_N;
2064 strcpy(connect_type, "(N_Port-to-N_Port)");
2065 break;
2066
2067 case 3:
2068 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002069 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002070 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 ha->operating_mode = P2P;
2072 ha->current_topology = ISP_CFG_F;
2073 strcpy(connect_type, "(F_Port)");
2074 break;
2075
2076 default:
2077 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
2078 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002079 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 ha->current_topology = ISP_CFG_NL;
2081 strcpy(connect_type, "(Loop)");
2082 break;
2083 }
2084
2085 /* Save Host port and loop ID. */
2086 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002087 vha->d_id.b.domain = domain;
2088 vha->d_id.b.area = area;
2089 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002091 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 qla_printk(KERN_INFO, ha,
2093 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002094 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095
2096 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002097 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002099 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 }
2101
2102 return(rval);
2103}
2104
Giridhar Malavalia9083012010-04-12 17:59:55 -07002105inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002106qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2107 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002108{
2109 char *st, *en;
2110 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002111 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002112 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavalia9083012010-04-12 17:59:55 -07002113 !IS_QLA8XXX_TYPE(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002114
2115 if (memcmp(model, BINZERO, len) != 0) {
2116 strncpy(ha->model_number, model, len);
2117 st = en = ha->model_number;
2118 en += len - 1;
2119 while (en > st) {
2120 if (*en != 0x20 && *en != 0x00)
2121 break;
2122 *en-- = '\0';
2123 }
2124
2125 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002126 if (use_tbl &&
2127 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002128 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002129 strncpy(ha->model_desc,
2130 qla2x00_model_name[index * 2 + 1],
2131 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002132 } else {
2133 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002134 if (use_tbl &&
2135 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002136 index < QLA_MODEL_NAMES) {
2137 strcpy(ha->model_number,
2138 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002139 strncpy(ha->model_desc,
2140 qla2x00_model_name[index * 2 + 1],
2141 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002142 } else {
2143 strcpy(ha->model_number, def);
2144 }
2145 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002146 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002147 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002148 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002149}
2150
David Miller4e08df32007-04-16 12:37:43 -07002151/* On sparc systems, obtain port and node WWN from firmware
2152 * properties.
2153 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002154static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002155{
2156#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002157 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002158 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002159 struct device_node *dp = pci_device_to_OF_node(pdev);
2160 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002161 int len;
2162
2163 val = of_get_property(dp, "port-wwn", &len);
2164 if (val && len >= WWN_SIZE)
2165 memcpy(nv->port_name, val, WWN_SIZE);
2166
2167 val = of_get_property(dp, "node-wwn", &len);
2168 if (val && len >= WWN_SIZE)
2169 memcpy(nv->node_name, val, WWN_SIZE);
2170#endif
2171}
2172
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173/*
2174* NVRAM configuration for ISP 2xxx
2175*
2176* Input:
2177* ha = adapter block pointer.
2178*
2179* Output:
2180* initialization control block in response_ring
2181* host adapters parameters in host adapter block
2182*
2183* Returns:
2184* 0 = success.
2185*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002186int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002187qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188{
David Miller4e08df32007-04-16 12:37:43 -07002189 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002190 uint8_t chksum = 0;
2191 uint16_t cnt;
2192 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002193 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002194 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002195 nvram_t *nv = ha->nvram;
2196 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002197 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198
David Miller4e08df32007-04-16 12:37:43 -07002199 rval = QLA_SUCCESS;
2200
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002202 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 ha->nvram_base = 0;
2204 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2205 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2206 ha->nvram_base = 0x80;
2207
2208 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002209 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002210 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2211 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002213 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07002214 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
2216 /* Bad NVRAM data, set defaults parameters. */
2217 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2218 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2219 /* Reset NVRAM data. */
2220 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
2221 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
2222 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07002223 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
2224 "invalid -- WWPN) defaults.\n");
2225
2226 /*
2227 * Set default initialization control block.
2228 */
2229 memset(nv, 0, ha->nvram_size);
2230 nv->parameter_block_version = ICB_VERSION;
2231
2232 if (IS_QLA23XX(ha)) {
2233 nv->firmware_options[0] = BIT_2 | BIT_1;
2234 nv->firmware_options[1] = BIT_7 | BIT_5;
2235 nv->add_firmware_options[0] = BIT_5;
2236 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2237 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2238 nv->special_options[1] = BIT_7;
2239 } else if (IS_QLA2200(ha)) {
2240 nv->firmware_options[0] = BIT_2 | BIT_1;
2241 nv->firmware_options[1] = BIT_7 | BIT_5;
2242 nv->add_firmware_options[0] = BIT_5;
2243 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2244 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2245 } else if (IS_QLA2100(ha)) {
2246 nv->firmware_options[0] = BIT_3 | BIT_1;
2247 nv->firmware_options[1] = BIT_5;
2248 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2249 }
2250
2251 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2252 nv->execution_throttle = __constant_cpu_to_le16(16);
2253 nv->retry_count = 8;
2254 nv->retry_delay = 1;
2255
2256 nv->port_name[0] = 33;
2257 nv->port_name[3] = 224;
2258 nv->port_name[4] = 139;
2259
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002260 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002261
2262 nv->login_timeout = 4;
2263
2264 /*
2265 * Set default host adapter parameters
2266 */
2267 nv->host_p[1] = BIT_2;
2268 nv->reset_delay = 5;
2269 nv->port_down_retry_count = 8;
2270 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2271 nv->link_down_timeout = 60;
2272
2273 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 }
2275
2276#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2277 /*
2278 * The SN2 does not provide BIOS emulation which means you can't change
2279 * potentially bogus BIOS settings. Force the use of default settings
2280 * for link rate and frame size. Hope that the rest of the settings
2281 * are valid.
2282 */
2283 if (ia64_platform_is("sn2")) {
2284 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2285 if (IS_QLA23XX(ha))
2286 nv->special_options[1] = BIT_7;
2287 }
2288#endif
2289
2290 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002291 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
2293 /*
2294 * Setup driver NVRAM options.
2295 */
2296 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2297 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2298 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2299 nv->firmware_options[1] &= ~BIT_4;
2300
2301 if (IS_QLA23XX(ha)) {
2302 nv->firmware_options[0] |= BIT_2;
2303 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002304 nv->firmware_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002305 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306
2307 if (IS_QLA2300(ha)) {
2308 if (ha->fb_rev == FPM_2310) {
2309 strcpy(ha->model_number, "QLA2310");
2310 } else {
2311 strcpy(ha->model_number, "QLA2300");
2312 }
2313 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002314 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002315 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 }
2317 } else if (IS_QLA2200(ha)) {
2318 nv->firmware_options[0] |= BIT_2;
2319 /*
2320 * 'Point-to-point preferred, else loop' is not a safe
2321 * connection mode setting.
2322 */
2323 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2324 (BIT_5 | BIT_4)) {
2325 /* Force 'loop preferred, else point-to-point'. */
2326 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2327 nv->add_firmware_options[0] |= BIT_5;
2328 }
2329 strcpy(ha->model_number, "QLA22xx");
2330 } else /*if (IS_QLA2100(ha))*/ {
2331 strcpy(ha->model_number, "QLA2100");
2332 }
2333
2334 /*
2335 * Copy over NVRAM RISC parameter block to initialization control block.
2336 */
2337 dptr1 = (uint8_t *)icb;
2338 dptr2 = (uint8_t *)&nv->parameter_block_version;
2339 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2340 while (cnt--)
2341 *dptr1++ = *dptr2++;
2342
2343 /* Copy 2nd half. */
2344 dptr1 = (uint8_t *)icb->add_firmware_options;
2345 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2346 while (cnt--)
2347 *dptr1++ = *dptr2++;
2348
Andrew Vasquez5341e862006-05-17 15:09:16 -07002349 /* Use alternate WWN? */
2350 if (nv->host_p[1] & BIT_7) {
2351 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2352 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2353 }
2354
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 /* Prepare nodename */
2356 if ((icb->firmware_options[1] & BIT_6) == 0) {
2357 /*
2358 * Firmware will apply the following mask if the nodename was
2359 * not provided.
2360 */
2361 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2362 icb->node_name[0] &= 0xF0;
2363 }
2364
2365 /*
2366 * Set host adapter parameters.
2367 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002368 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002369 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2371 /* Always load RISC code on non ISP2[12]00 chips. */
2372 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2373 ha->flags.disable_risc_code_load = 0;
2374 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2375 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2376 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002377 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002378 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379
2380 ha->operating_mode =
2381 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2382
2383 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2384 sizeof(ha->fw_seriallink_options));
2385
2386 /* save HBA serial number */
2387 ha->serial0 = icb->port_name[5];
2388 ha->serial1 = icb->port_name[6];
2389 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002390 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2391 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392
2393 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2394
2395 ha->retry_count = nv->retry_count;
2396
2397 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002398 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 nv->login_timeout = ql2xlogintimeout;
2400 if (nv->login_timeout < 4)
2401 nv->login_timeout = 4;
2402 ha->login_timeout = nv->login_timeout;
2403 icb->login_timeout = nv->login_timeout;
2404
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002405 /* Set minimum RATOV to 100 tenths of a second. */
2406 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 ha->loop_reset_delay = nv->reset_delay;
2409
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 /* Link Down Timeout = 0:
2411 *
2412 * When Port Down timer expires we will start returning
2413 * I/O's to OS with "DID_NO_CONNECT".
2414 *
2415 * Link Down Timeout != 0:
2416 *
2417 * The driver waits for the link to come up after link down
2418 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002419 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 if (nv->link_down_timeout == 0) {
2421 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002422 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 } else {
2424 ha->link_down_timeout = nv->link_down_timeout;
2425 ha->loop_down_abort_time =
2426 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002427 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 /*
2430 * Need enough time to try and get the port back.
2431 */
2432 ha->port_down_retry_count = nv->port_down_retry_count;
2433 if (qlport_down_retry)
2434 ha->port_down_retry_count = qlport_down_retry;
2435 /* Set login_retry_count */
2436 ha->login_retry_count = nv->retry_count;
2437 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2438 ha->port_down_retry_count > 3)
2439 ha->login_retry_count = ha->port_down_retry_count;
2440 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2441 ha->login_retry_count = ha->port_down_retry_count;
2442 if (ql2xloginretrycount)
2443 ha->login_retry_count = ql2xloginretrycount;
2444
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 icb->lun_enables = __constant_cpu_to_le16(0);
2446 icb->command_resource_count = 0;
2447 icb->immediate_notify_resource_count = 0;
2448 icb->timeout = __constant_cpu_to_le16(0);
2449
2450 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2451 /* Enable RIO */
2452 icb->firmware_options[0] &= ~BIT_3;
2453 icb->add_firmware_options[0] &=
2454 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2455 icb->add_firmware_options[0] |= BIT_2;
2456 icb->response_accumulation_timer = 3;
2457 icb->interrupt_delay_timer = 5;
2458
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002459 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002461 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002462 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002463 ha->zio_mode = icb->add_firmware_options[0] &
2464 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2465 ha->zio_timer = icb->interrupt_delay_timer ?
2466 icb->interrupt_delay_timer: 2;
2467 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 icb->add_firmware_options[0] &=
2469 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002470 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002471 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002472 ha->zio_mode = QLA_ZIO_MODE_6;
2473
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002474 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002475 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002476 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002478 "ZIO mode %d enabled; timer delay (%d us).\n",
2479 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002481 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2482 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002483 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 }
2485 }
2486
David Miller4e08df32007-04-16 12:37:43 -07002487 if (rval) {
2488 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002489 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07002490 }
2491 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492}
2493
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002494static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002495qla2x00_rport_del(void *data)
2496{
2497 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002498 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002499
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002500 spin_lock_irq(fcport->vha->host->host_lock);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002501 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002502 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002503 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002504 if (rport)
2505 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002506}
2507
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508/**
2509 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2510 * @ha: HA context
2511 * @flags: allocation flags
2512 *
2513 * Returns a pointer to the allocated fcport, or NULL, if none available.
2514 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002515fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002516qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517{
2518 fc_port_t *fcport;
2519
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002520 fcport = kzalloc(sizeof(fc_port_t), flags);
2521 if (!fcport)
2522 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523
2524 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002525 fcport->vha = vha;
2526 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 fcport->port_type = FCT_UNKNOWN;
2528 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002530 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002532 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533}
2534
2535/*
2536 * qla2x00_configure_loop
2537 * Updates Fibre Channel Device Database with what is actually on loop.
2538 *
2539 * Input:
2540 * ha = adapter block pointer.
2541 *
2542 * Returns:
2543 * 0 = success.
2544 * 1 = error.
2545 * 2 = database was full and device was not configured.
2546 */
2547static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002548qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549{
2550 int rval;
2551 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002552 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 rval = QLA_SUCCESS;
2554
2555 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002556 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2557 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 if (rval != QLA_SUCCESS) {
2559 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002560 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 return (rval);
2562 }
2563 }
2564
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002565 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002567 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568
2569 /*
2570 * If we have both an RSCN and PORT UPDATE pending then handle them
2571 * both at the same time.
2572 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002573 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2574 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575
Michael Hernandez3064ff32009-12-15 21:29:44 -08002576 qla2x00_get_data_rate(vha);
2577
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 /* Determine what we need to do */
2579 if (ha->current_topology == ISP_CFG_FL &&
2580 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2581
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002582 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 set_bit(RSCN_UPDATE, &flags);
2584
2585 } else if (ha->current_topology == ISP_CFG_F &&
2586 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2587
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002588 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 set_bit(RSCN_UPDATE, &flags);
2590 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2591
Andrew Vasquez21333b42006-05-17 15:09:56 -07002592 } else if (ha->current_topology == ISP_CFG_N) {
2593 clear_bit(RSCN_UPDATE, &flags);
2594
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002595 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2597
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002598 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 set_bit(RSCN_UPDATE, &flags);
2600 set_bit(LOCAL_LOOP_UPDATE, &flags);
2601 }
2602
2603 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002604 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002606 else
2607 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 }
2609
2610 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002611 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002613 else
2614 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 }
2616
2617 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002618 if (atomic_read(&vha->loop_down_timer) ||
2619 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 rval = QLA_FUNCTION_FAILED;
2621 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002622 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002624 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 }
2626 }
2627
2628 if (rval) {
2629 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002630 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 } else {
2632 DEBUG3(printk("%s: exiting normally\n", __func__));
2633 }
2634
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002635 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002636 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002638 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002639 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002640 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07002641 if (!IS_ALOGIO_CAPABLE(ha))
2642 vha->flags.rscn_queue_overflow = 1;
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 }
2645
2646 return (rval);
2647}
2648
2649
2650
2651/*
2652 * qla2x00_configure_local_loop
2653 * Updates Fibre Channel Device Database with local loop devices.
2654 *
2655 * Input:
2656 * ha = adapter block pointer.
2657 *
2658 * Returns:
2659 * 0 = success.
2660 */
2661static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002662qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663{
2664 int rval, rval2;
2665 int found_devs;
2666 int found;
2667 fc_port_t *fcport, *new_fcport;
2668
2669 uint16_t index;
2670 uint16_t entries;
2671 char *id_iter;
2672 uint16_t loop_id;
2673 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002674 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675
2676 found_devs = 0;
2677 new_fcport = NULL;
2678 entries = MAX_FIBRE_DEVICES;
2679
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002680 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2681 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682
2683 /* Get list of logged in devices. */
2684 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002685 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 &entries);
2687 if (rval != QLA_SUCCESS)
2688 goto cleanup_allocation;
2689
2690 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002691 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2693 entries * sizeof(struct gid_list_info)));
2694
2695 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002696 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 if (new_fcport == NULL) {
2698 rval = QLA_MEMORY_ALLOC_FAILED;
2699 goto cleanup_allocation;
2700 }
2701 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2702
2703 /*
2704 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2705 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002706 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2708 fcport->port_type != FCT_BROADCAST &&
2709 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2710
2711 DEBUG(printk("scsi(%ld): Marking port lost, "
2712 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002713 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714
2715 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 }
2717 }
2718
2719 /* Add devices to port list. */
2720 id_iter = (char *)ha->gid_list;
2721 for (index = 0; index < entries; index++) {
2722 domain = ((struct gid_list_info *)id_iter)->domain;
2723 area = ((struct gid_list_info *)id_iter)->area;
2724 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002725 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 loop_id = (uint16_t)
2727 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002728 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 loop_id = le16_to_cpu(
2730 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002731 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732
2733 /* Bypass reserved domain fields. */
2734 if ((domain & 0xf0) == 0xf0)
2735 continue;
2736
2737 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002738 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002739 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 continue;
2741
2742 /* Bypass invalid local loop ID. */
2743 if (loop_id > LAST_LOCAL_LOOP_ID)
2744 continue;
2745
2746 /* Fill in member data. */
2747 new_fcport->d_id.b.domain = domain;
2748 new_fcport->d_id.b.area = area;
2749 new_fcport->d_id.b.al_pa = al_pa;
2750 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002751 new_fcport->vp_idx = vha->vp_idx;
2752 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 if (rval2 != QLA_SUCCESS) {
2754 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2755 "information -- get_port_database=%x, "
2756 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002757 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002758 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002759 vha->host_no));
2760 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 continue;
2762 }
2763
2764 /* Check for matching device in port list. */
2765 found = 0;
2766 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002767 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 if (memcmp(new_fcport->port_name, fcport->port_name,
2769 WWN_SIZE))
2770 continue;
2771
Shyam Sundarddb9b122009-03-24 09:08:10 -07002772 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 fcport->loop_id = new_fcport->loop_id;
2774 fcport->port_type = new_fcport->port_type;
2775 fcport->d_id.b24 = new_fcport->d_id.b24;
2776 memcpy(fcport->node_name, new_fcport->node_name,
2777 WWN_SIZE);
2778
2779 found++;
2780 break;
2781 }
2782
2783 if (!found) {
2784 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002785 if (vha->vp_idx) {
2786 new_fcport->vha = vha;
2787 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002788 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002789 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790
2791 /* Allocate a new replacement fcport. */
2792 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002793 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 if (new_fcport == NULL) {
2795 rval = QLA_MEMORY_ALLOC_FAILED;
2796 goto cleanup_allocation;
2797 }
2798 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2799 }
2800
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002801 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002802 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002803
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002804 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
2806 found_devs++;
2807 }
2808
2809cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002810 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811
2812 if (rval != QLA_SUCCESS) {
2813 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002814 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 }
2816
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 return (rval);
2818}
2819
2820static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002821qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002822{
2823#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002824 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2825 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002826 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002827 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002828 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002829
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002830 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002831 return;
2832
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07002833 if (atomic_read(&fcport->state) != FCS_ONLINE)
2834 return;
2835
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002836 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2837 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002838 return;
2839
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002840 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002841 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002842 if (rval != QLA_SUCCESS) {
2843 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2844 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002845 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002846 fcport->port_name[2], fcport->port_name[3],
2847 fcport->port_name[4], fcport->port_name[5],
2848 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002849 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002850 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002851 link_speed = link_speeds[LS_UNKNOWN];
2852 if (fcport->fp_speed < 5)
2853 link_speed = link_speeds[fcport->fp_speed];
2854 else if (fcport->fp_speed == 0x13)
2855 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002856 DEBUG2(qla_printk(KERN_INFO, ha,
2857 "iIDMA adjusted to %s GB/s on "
2858 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002859 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002860 fcport->port_name[1], fcport->port_name[2],
2861 fcport->port_name[3], fcport->port_name[4],
2862 fcport->port_name[5], fcport->port_name[6],
2863 fcport->port_name[7]));
2864 }
2865}
2866
Adrian Bunk23be3312006-11-24 02:46:01 +01002867static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002868qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002869{
2870 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002871 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002872 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002873
Andrew Vasquezac280b62009-08-20 11:06:05 -07002874 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002875
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002876 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2877 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002878 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2879 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2880 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002881 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002882 if (!rport) {
2883 qla_printk(KERN_WARNING, ha,
2884 "Unable to allocate fc remote port!\n");
2885 return;
2886 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002887 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002888 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002889 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002890
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002891 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002892
2893 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002894 if (fcport->port_type == FCT_INITIATOR)
2895 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2896 if (fcport->port_type == FCT_TARGET)
2897 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002898 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002899}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900
2901/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002902 * qla2x00_update_fcport
2903 * Updates device on list.
2904 *
2905 * Input:
2906 * ha = adapter block pointer.
2907 * fcport = port structure pointer.
2908 *
2909 * Return:
2910 * 0 - Success
2911 * BIT_0 - error
2912 *
2913 * Context:
2914 * Kernel context.
2915 */
2916void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002917qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002918{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002919 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002920 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002921 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01002922
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002923 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002924 atomic_set(&fcport->state, FCS_ONLINE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002925 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002926}
2927
2928/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 * qla2x00_configure_fabric
2930 * Setup SNS devices with loop ID's.
2931 *
2932 * Input:
2933 * ha = adapter block pointer.
2934 *
2935 * Returns:
2936 * 0 = success.
2937 * BIT_0 = error
2938 */
2939static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002940qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941{
2942 int rval, rval2;
2943 fc_port_t *fcport, *fcptemp;
2944 uint16_t next_loopid;
2945 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002946 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002948 struct qla_hw_data *ha = vha->hw;
2949 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950
2951 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002952 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002953 loop_id = NPH_F_PORT;
2954 else
2955 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002956 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 if (rval != QLA_SUCCESS) {
2958 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002959 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002961 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 return (QLA_SUCCESS);
2963 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002964 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965
2966 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002967 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 if (rval2 == QLA_RSCNS_HANDLED) {
2969 /* No point doing the scan, just continue. */
2970 return (QLA_SUCCESS);
2971 }
2972 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002973 /* FDMI support. */
2974 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002975 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2976 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002977
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002979 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002980 loop_id = NPH_SNS;
2981 else
2982 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002983 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002984 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 if (mb[0] != MBS_COMMAND_COMPLETE) {
2986 DEBUG2(qla_printk(KERN_INFO, ha,
2987 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002988 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 mb[0], mb[1], mb[2], mb[6], mb[7]));
2990 return (QLA_SUCCESS);
2991 }
2992
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002993 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2994 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 /* EMPTY */
2996 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002997 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002999 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 /* EMPTY */
3001 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003002 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003004 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 /* EMPTY */
3006 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003007 "failed.\n", vha->host_no));
3008 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 /* EMPTY */
3010 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003011 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 }
3013 }
3014
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003015 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 if (rval != QLA_SUCCESS)
3017 break;
3018
3019 /*
3020 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003021 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003023 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3024 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 break;
3026
3027 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3028 continue;
3029
3030 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003031 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003032 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003034 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 fcport->port_type != FCT_INITIATOR &&
3036 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003037 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003038 fcport->loop_id,
3039 fcport->d_id.b.domain,
3040 fcport->d_id.b.area,
3041 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 fcport->loop_id = FC_NO_LOOP_ID;
3043 }
3044 }
3045 }
3046
3047 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003048 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049
3050 /*
3051 * Scan through our port list and login entries that need to be
3052 * logged in.
3053 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003054 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3055 if (atomic_read(&vha->loop_down_timer) ||
3056 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 break;
3058
3059 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3060 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3061 continue;
3062
3063 if (fcport->loop_id == FC_NO_LOOP_ID) {
3064 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07003065 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003066 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 if (rval != QLA_SUCCESS) {
3068 /* Ran out of IDs to use */
3069 break;
3070 }
3071 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003073 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 }
3075
3076 /* Exit if out of loop IDs. */
3077 if (rval != QLA_SUCCESS) {
3078 break;
3079 }
3080
3081 /*
3082 * Login and add the new devices to our port list.
3083 */
3084 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003085 if (atomic_read(&vha->loop_down_timer) ||
3086 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 break;
3088
3089 /* Find a new loop ID to use. */
3090 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003091 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 if (rval != QLA_SUCCESS) {
3093 /* Ran out of IDs to use */
3094 break;
3095 }
3096
bdf79622005-04-17 15:06:53 -05003097 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003098 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003099
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003100 if (vha->vp_idx) {
3101 fcport->vha = vha;
3102 fcport->vp_idx = vha->vp_idx;
3103 }
3104 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 }
3106 } while (0);
3107
3108 /* Free all new device structures not processed. */
3109 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3110 list_del(&fcport->list);
3111 kfree(fcport);
3112 }
3113
3114 if (rval) {
3115 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003116 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 }
3118
3119 return (rval);
3120}
3121
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122/*
3123 * qla2x00_find_all_fabric_devs
3124 *
3125 * Input:
3126 * ha = adapter block pointer.
3127 * dev = database device entry pointer.
3128 *
3129 * Returns:
3130 * 0 = success.
3131 *
3132 * Context:
3133 * Kernel context.
3134 */
3135static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003136qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3137 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138{
3139 int rval;
3140 uint16_t loop_id;
3141 fc_port_t *fcport, *new_fcport, *fcptemp;
3142 int found;
3143
3144 sw_info_t *swl;
3145 int swl_idx;
3146 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003147 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003148 struct qla_hw_data *ha = vha->hw;
3149 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003150 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151
3152 rval = QLA_SUCCESS;
3153
3154 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07003155 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003156 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 /*EMPTY*/
3158 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003159 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003161 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 kfree(swl);
3163 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003164 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 kfree(swl);
3166 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003167 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 kfree(swl);
3169 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003170 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003171 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3172 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003174
3175 /* If other queries succeeded probe for FC-4 type */
3176 if (swl)
3177 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 }
3179 swl_idx = 0;
3180
3181 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003182 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003184 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 return (QLA_MEMORY_ALLOC_FAILED);
3186 }
3187 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 /* Set start port ID scan at adapter ID. */
3189 first_dev = 1;
3190 last_dev = 0;
3191
3192 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003193 loop_id = ha->min_external_loopid;
3194 for (; loop_id <= ha->max_loop_id; loop_id++) {
3195 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 continue;
3197
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003198 if (ha->current_topology == ISP_CFG_FL &&
3199 (atomic_read(&vha->loop_down_timer) ||
3200 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003201 atomic_set(&vha->loop_down_timer, 0);
3202 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3203 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003205 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206
3207 if (swl != NULL) {
3208 if (last_dev) {
3209 wrap.b24 = new_fcport->d_id.b24;
3210 } else {
3211 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3212 memcpy(new_fcport->node_name,
3213 swl[swl_idx].node_name, WWN_SIZE);
3214 memcpy(new_fcport->port_name,
3215 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003216 memcpy(new_fcport->fabric_port_name,
3217 swl[swl_idx].fabric_port_name, WWN_SIZE);
3218 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003219 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220
3221 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3222 last_dev = 1;
3223 }
3224 swl_idx++;
3225 }
3226 } else {
3227 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003228 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 if (rval != QLA_SUCCESS) {
3230 qla_printk(KERN_WARNING, ha,
3231 "SNS scan failed -- assuming zero-entry "
3232 "result...\n");
3233 list_for_each_entry_safe(fcport, fcptemp,
3234 new_fcports, list) {
3235 list_del(&fcport->list);
3236 kfree(fcport);
3237 }
3238 rval = QLA_SUCCESS;
3239 break;
3240 }
3241 }
3242
3243 /* If wrap on switch device list, exit. */
3244 if (first_dev) {
3245 wrap.b24 = new_fcport->d_id.b24;
3246 first_dev = 0;
3247 } else if (new_fcport->d_id.b24 == wrap.b24) {
3248 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003249 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
3251 break;
3252 }
3253
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003254 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003255 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 continue;
3257
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003258 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003259 found = 0;
3260 if (ha->num_vhosts) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003261 unsigned long flags;
3262
3263 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003264 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003265 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3266 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003267 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003268 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003269 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003270 spin_unlock_irqrestore(&ha->vport_slock, flags);
3271
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003272 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003273 continue;
3274 }
3275
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003276 /* Bypass if same domain and area of adapter. */
3277 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003278 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003279 ISP_CFG_FL)
3280 continue;
3281
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 /* Bypass reserved domain fields. */
3283 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3284 continue;
3285
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003286 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003287 if (ql2xgffidenable &&
3288 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3289 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003290 continue;
3291
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 /* Locate matching device in database. */
3293 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003294 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295 if (memcmp(new_fcport->port_name, fcport->port_name,
3296 WWN_SIZE))
3297 continue;
3298
3299 found++;
3300
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003301 /* Update port state. */
3302 memcpy(fcport->fabric_port_name,
3303 new_fcport->fabric_port_name, WWN_SIZE);
3304 fcport->fp_speed = new_fcport->fp_speed;
3305
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 /*
3307 * If address the same and state FCS_ONLINE, nothing
3308 * changed.
3309 */
3310 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3311 atomic_read(&fcport->state) == FCS_ONLINE) {
3312 break;
3313 }
3314
3315 /*
3316 * If device was not a fabric device before.
3317 */
3318 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3319 fcport->d_id.b24 = new_fcport->d_id.b24;
3320 fcport->loop_id = FC_NO_LOOP_ID;
3321 fcport->flags |= (FCF_FABRIC_DEVICE |
3322 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 break;
3324 }
3325
3326 /*
3327 * Port ID changed or device was marked to be updated;
3328 * Log it out if still logged in and mark it for
3329 * relogin later.
3330 */
3331 fcport->d_id.b24 = new_fcport->d_id.b24;
3332 fcport->flags |= FCF_LOGIN_NEEDED;
3333 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003334 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 fcport->port_type != FCT_INITIATOR &&
3336 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003337 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003338 fcport->d_id.b.domain, fcport->d_id.b.area,
3339 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 fcport->loop_id = FC_NO_LOOP_ID;
3341 }
3342
3343 break;
3344 }
3345
3346 if (found)
3347 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 /* If device was not in our fcports list, then add it. */
3349 list_add_tail(&new_fcport->list, new_fcports);
3350
3351 /* Allocate a new replacement fcport. */
3352 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003353 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003355 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 return (QLA_MEMORY_ALLOC_FAILED);
3357 }
3358 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3359 new_fcport->d_id.b24 = nxt_d_id.b24;
3360 }
3361
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003362 kfree(swl);
3363 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 return (rval);
3366}
3367
3368/*
3369 * qla2x00_find_new_loop_id
3370 * Scan through our port list and find a new usable loop ID.
3371 *
3372 * Input:
3373 * ha: adapter state pointer.
3374 * dev: port structure pointer.
3375 *
3376 * Returns:
3377 * qla2x00 local function return status code.
3378 *
3379 * Context:
3380 * Kernel context.
3381 */
Adrian Bunk413975a2006-06-30 02:33:06 -07003382static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003383qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384{
3385 int rval;
3386 int found;
3387 fc_port_t *fcport;
3388 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003389 struct qla_hw_data *ha = vha->hw;
3390 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003391 struct scsi_qla_host *tvp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003392 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393
3394 rval = QLA_SUCCESS;
3395
3396 /* Save starting loop ID. */
3397 first_loop_id = dev->loop_id;
3398
3399 for (;;) {
3400 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003401 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403
3404 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003405 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407
3408 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003409 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 /* first loop ID. */
3411 dev->loop_id = ha->min_external_loopid;
3412 }
3413
3414 /* Check for loop ID being already in use. */
3415 found = 0;
3416 fcport = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003417
3418 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003419 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003420 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3421 if (fcport->loop_id == dev->loop_id &&
3422 fcport != dev) {
3423 /* ID possibly in use */
3424 found++;
3425 break;
3426 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003428 if (found)
3429 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003431 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432
3433 /* If not in use then it is free to use. */
3434 if (!found) {
3435 break;
3436 }
3437
3438 /* ID in use. Try next value. */
3439 dev->loop_id++;
3440
3441 /* If wrap around. No free ID to use. */
3442 if (dev->loop_id == first_loop_id) {
3443 dev->loop_id = FC_NO_LOOP_ID;
3444 rval = QLA_FUNCTION_FAILED;
3445 break;
3446 }
3447 }
3448
3449 return (rval);
3450}
3451
3452/*
3453 * qla2x00_device_resync
3454 * Marks devices in the database that needs resynchronization.
3455 *
3456 * Input:
3457 * ha = adapter block pointer.
3458 *
3459 * Context:
3460 * Kernel context.
3461 */
3462static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003463qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464{
3465 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466 uint32_t mask;
3467 fc_port_t *fcport;
3468 uint32_t rscn_entry;
3469 uint8_t rscn_out_iter;
3470 uint8_t format;
Mike Waychison1516ef42010-05-04 15:01:31 -07003471 port_id_t d_id = {};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472
3473 rval = QLA_RSCNS_HANDLED;
3474
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003475 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3476 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003478 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 format = MSB(MSW(rscn_entry));
3480 d_id.b.domain = LSB(MSW(rscn_entry));
3481 d_id.b.area = MSB(LSW(rscn_entry));
3482 d_id.b.al_pa = LSB(LSW(rscn_entry));
3483
3484 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3485 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003486 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487 d_id.b.area, d_id.b.al_pa));
3488
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003489 vha->rscn_out_ptr++;
3490 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3491 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492
3493 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003494 for (rscn_out_iter = vha->rscn_out_ptr;
3495 !vha->flags.rscn_queue_overflow &&
3496 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 rscn_out_iter = (rscn_out_iter ==
3498 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3499
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003500 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501 break;
3502
3503 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003504 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 rscn_out_iter));
3506
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003507 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508 }
3509
3510 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003511 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003513 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514
3515 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003516 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517 }
3518
3519 switch (format) {
3520 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 mask = 0xffffff;
3522 break;
3523 case 1:
3524 mask = 0xffff00;
3525 break;
3526 case 2:
3527 mask = 0xff0000;
3528 break;
3529 default:
3530 mask = 0x0;
3531 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003532 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 break;
3534 }
3535
3536 rval = QLA_SUCCESS;
3537
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003538 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3540 (fcport->d_id.b24 & mask) != d_id.b24 ||
3541 fcport->port_type == FCT_BROADCAST)
3542 continue;
3543
3544 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3545 if (format != 3 ||
3546 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003547 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003548 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 }
3550 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 }
3552 }
3553 return (rval);
3554}
3555
3556/*
3557 * qla2x00_fabric_dev_login
3558 * Login fabric target device and update FC port database.
3559 *
3560 * Input:
3561 * ha: adapter state pointer.
3562 * fcport: port structure list pointer.
3563 * next_loopid: contains value of a new loop ID that can be used
3564 * by the next login attempt.
3565 *
3566 * Returns:
3567 * qla2x00 local function return status code.
3568 *
3569 * Context:
3570 * Kernel context.
3571 */
3572static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003573qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 uint16_t *next_loopid)
3575{
3576 int rval;
3577 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003578 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003579 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580
3581 rval = QLA_SUCCESS;
3582 retry = 0;
3583
Andrew Vasquezac280b62009-08-20 11:06:05 -07003584 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003585 if (fcport->flags & FCF_ASYNC_SENT)
3586 return rval;
3587 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003588 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3589 if (!rval)
3590 return rval;
3591 }
3592
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003593 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003594 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003596 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003597 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003598 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003599 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003600 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003602 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003603 fcport->d_id.b.domain, fcport->d_id.b.area,
3604 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003605 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003607 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608 }
3609 }
3610
3611 return (rval);
3612}
3613
3614/*
3615 * qla2x00_fabric_login
3616 * Issue fabric login command.
3617 *
3618 * Input:
3619 * ha = adapter block pointer.
3620 * device = pointer to FC device type structure.
3621 *
3622 * Returns:
3623 * 0 - Login successfully
3624 * 1 - Login failed
3625 * 2 - Initiator device
3626 * 3 - Fatal error
3627 */
3628int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003629qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630 uint16_t *next_loopid)
3631{
3632 int rval;
3633 int retry;
3634 uint16_t tmp_loopid;
3635 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003636 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637
3638 retry = 0;
3639 tmp_loopid = 0;
3640
3641 for (;;) {
3642 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3643 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003644 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3646
3647 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003648 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649 fcport->d_id.b.domain, fcport->d_id.b.area,
3650 fcport->d_id.b.al_pa, mb, BIT_0);
3651 if (mb[0] == MBS_PORT_ID_USED) {
3652 /*
3653 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003654 * recommends the driver perform an implicit login with
3655 * the specified ID again. The ID we just used is save
3656 * here so we return with an ID that can be tried by
3657 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658 */
3659 retry++;
3660 tmp_loopid = fcport->loop_id;
3661 fcport->loop_id = mb[1];
3662
3663 DEBUG(printk("Fabric Login: port in use - next "
3664 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3665 fcport->loop_id, fcport->d_id.b.domain,
3666 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3667
3668 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3669 /*
3670 * Login succeeded.
3671 */
3672 if (retry) {
3673 /* A retry occurred before. */
3674 *next_loopid = tmp_loopid;
3675 } else {
3676 /*
3677 * No retry occurred before. Just increment the
3678 * ID value for next login.
3679 */
3680 *next_loopid = (fcport->loop_id + 1);
3681 }
3682
3683 if (mb[1] & BIT_0) {
3684 fcport->port_type = FCT_INITIATOR;
3685 } else {
3686 fcport->port_type = FCT_TARGET;
3687 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003688 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689 }
3690 }
3691
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003692 if (mb[10] & BIT_0)
3693 fcport->supported_classes |= FC_COS_CLASS2;
3694 if (mb[10] & BIT_1)
3695 fcport->supported_classes |= FC_COS_CLASS3;
3696
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697 rval = QLA_SUCCESS;
3698 break;
3699 } else if (mb[0] == MBS_LOOP_ID_USED) {
3700 /*
3701 * Loop ID already used, try next loop ID.
3702 */
3703 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003704 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 if (rval != QLA_SUCCESS) {
3706 /* Ran out of loop IDs to use */
3707 break;
3708 }
3709 } else if (mb[0] == MBS_COMMAND_ERROR) {
3710 /*
3711 * Firmware possibly timed out during login. If NO
3712 * retries are left to do then the device is declared
3713 * dead.
3714 */
3715 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003716 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003717 fcport->d_id.b.domain, fcport->d_id.b.area,
3718 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003719 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003720
3721 rval = 1;
3722 break;
3723 } else {
3724 /*
3725 * unrecoverable / not handled error
3726 */
3727 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003728 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003729 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 fcport->d_id.b.domain, fcport->d_id.b.area,
3731 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3732
3733 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003734 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003735 fcport->d_id.b.domain, fcport->d_id.b.area,
3736 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003738 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739
3740 rval = 3;
3741 break;
3742 }
3743 }
3744
3745 return (rval);
3746}
3747
3748/*
3749 * qla2x00_local_device_login
3750 * Issue local device login command.
3751 *
3752 * Input:
3753 * ha = adapter block pointer.
3754 * loop_id = loop id of device to login to.
3755 *
3756 * Returns (Where's the #define!!!!):
3757 * 0 - Login successfully
3758 * 1 - Login failed
3759 * 3 - Fatal error
3760 */
3761int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003762qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763{
3764 int rval;
3765 uint16_t mb[MAILBOX_REGISTER_COUNT];
3766
3767 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003768 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769 if (rval == QLA_SUCCESS) {
3770 /* Interrogate mailbox registers for any errors */
3771 if (mb[0] == MBS_COMMAND_ERROR)
3772 rval = 1;
3773 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3774 /* device not in PCB table */
3775 rval = 3;
3776 }
3777
3778 return (rval);
3779}
3780
3781/*
3782 * qla2x00_loop_resync
3783 * Resync with fibre channel devices.
3784 *
3785 * Input:
3786 * ha = adapter block pointer.
3787 *
3788 * Returns:
3789 * 0 = success
3790 */
3791int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003792qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003794 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003796 struct req_que *req;
3797 struct rsp_que *rsp;
3798
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003799 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003800 req = vha->hw->req_q_map[0];
3801 else
3802 req = vha->req;
3803 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003805 atomic_set(&vha->loop_state, LOOP_UPDATE);
3806 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3807 if (vha->flags.online) {
3808 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3810 wait_time = 256;
3811 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003812 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003814 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003815 qla2x00_marker(vha, req, rsp, 0, 0,
3816 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003817 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818
3819 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003820 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003822 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003824 } while (!atomic_read(&vha->loop_down_timer) &&
3825 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3826 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3827 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 }
3830
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003831 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003834 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836
3837 return (rval);
3838}
3839
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003841qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003842{
3843 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07003844 struct scsi_qla_host *vha;
3845 struct qla_hw_data *ha = base_vha->hw;
3846 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003847
Arun Easifeafb7b2010-09-03 14:57:00 -07003848 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003849 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07003850 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
3851 atomic_inc(&vha->vref_count);
3852 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Andrew Vasquez67becc02009-08-25 11:36:20 -07003853 if (fcport && fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07003854 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
3855 spin_unlock_irqrestore(&ha->vport_slock, flags);
3856
Andrew Vasquez67becc02009-08-25 11:36:20 -07003857 qla2x00_rport_del(fcport);
Arun Easifeafb7b2010-09-03 14:57:00 -07003858
3859 spin_lock_irqsave(&ha->vport_slock, flags);
3860 }
3861 }
3862 atomic_dec(&vha->vref_count);
3863 }
3864 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003865}
3866
Giridhar Malavalia9083012010-04-12 17:59:55 -07003867void
3868qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3869{
3870 struct qla_hw_data *ha = vha->hw;
3871 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Arun Easifeafb7b2010-09-03 14:57:00 -07003872 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003873
3874 vha->flags.online = 0;
3875 ha->flags.chip_reset_done = 0;
3876 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3877 ha->qla_stats.total_isp_aborts++;
3878
3879 qla_printk(KERN_INFO, ha,
3880 "Performing ISP error recovery - ha= %p.\n", ha);
3881
3882 /* Chip reset does not apply to 82XX */
3883 if (!IS_QLA82XX(ha))
3884 ha->isp_ops->reset_chip(vha);
3885
3886 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3887 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3888 atomic_set(&vha->loop_state, LOOP_DOWN);
3889 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07003890
3891 spin_lock_irqsave(&ha->vport_slock, flags);
3892 list_for_each_entry(vp, &base_vha->hw->vp_list, list) {
3893 atomic_inc(&vp->vref_count);
3894 spin_unlock_irqrestore(&ha->vport_slock, flags);
3895
Giridhar Malavalia9083012010-04-12 17:59:55 -07003896 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07003897
3898 spin_lock_irqsave(&ha->vport_slock, flags);
3899 atomic_dec(&vp->vref_count);
3900 }
3901 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003902 } else {
3903 if (!atomic_read(&vha->loop_down_timer))
3904 atomic_set(&vha->loop_down_timer,
3905 LOOP_DOWN_TIME);
3906 }
3907
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07003908 if (!ha->flags.eeh_busy) {
3909 /* Make sure for ISP 82XX IO DMA is complete */
3910 if (IS_QLA82XX(ha)) {
3911 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
3912 WAIT_HOST) == QLA_SUCCESS) {
3913 DEBUG2(qla_printk(KERN_INFO, ha,
3914 "Done wait for pending commands\n"));
3915 }
Giridhar Malavali4d78c972010-07-23 15:28:35 +05003916 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07003917
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07003918 /* Requeue all commands in outstanding command list. */
3919 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3920 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07003921}
3922
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923/*
3924* qla2x00_abort_isp
3925* Resets ISP and aborts all outstanding commands.
3926*
3927* Input:
3928* ha = adapter block pointer.
3929*
3930* Returns:
3931* 0 = success
3932*/
3933int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003934qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003936 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003938 struct qla_hw_data *ha = vha->hw;
3939 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003940 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07003941 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003943 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003944 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945
Andrew Vasquez85880802009-12-15 21:29:46 -08003946 if (unlikely(pci_channel_offline(ha->pdev) &&
3947 ha->flags.pci_channel_io_perm_failure)) {
3948 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3949 status = 0;
3950 return status;
3951 }
3952
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003953 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003954
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003955 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003957 if (!qla2x00_restart_isp(vha)) {
3958 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003960 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961 /*
3962 * Issue marker command only when we are going
3963 * to start the I/O .
3964 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003965 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 }
3967
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003968 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003970 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003972 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003973 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003974
Lalit Chandivade29c53972009-10-13 15:16:47 -07003975 if (IS_QLA81XX(ha))
3976 qla2x00_get_fw_version(vha,
3977 &ha->fw_major_version,
3978 &ha->fw_minor_version,
3979 &ha->fw_subminor_version,
3980 &ha->fw_attributes, &ha->fw_memory_size,
3981 ha->mpi_version, &ha->mpi_capabilities,
3982 ha->phy_version);
3983
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003984 if (ha->fce) {
3985 ha->flags.fce_enabled = 1;
3986 memset(ha->fce, 0,
3987 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003988 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003989 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3990 &ha->fce_bufs);
3991 if (rval) {
3992 qla_printk(KERN_WARNING, ha,
3993 "Unable to reinitialize FCE "
3994 "(%d).\n", rval);
3995 ha->flags.fce_enabled = 0;
3996 }
3997 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003998
3999 if (ha->eft) {
4000 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004001 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004002 ha->eft_dma, EFT_NUM_BUFFERS);
4003 if (rval) {
4004 qla_printk(KERN_WARNING, ha,
4005 "Unable to reinitialize EFT "
4006 "(%d).\n", rval);
4007 }
4008 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004010 vha->flags.online = 1;
4011 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 if (ha->isp_abort_cnt == 0) {
4013 qla_printk(KERN_WARNING, ha,
4014 "ISP error recovery failed - "
4015 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004016 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 * The next call disables the board
4018 * completely.
4019 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004020 ha->isp_ops->reset_adapter(vha);
4021 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004023 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 status = 0;
4025 } else { /* schedule another ISP abort */
4026 ha->isp_abort_cnt--;
4027 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004028 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004029 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030 status = 1;
4031 }
4032 } else {
4033 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
4034 DEBUG(printk("qla2x00(%ld): ISP error recovery "
4035 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004036 vha->host_no, ha->isp_abort_cnt));
4037 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 status = 1;
4039 }
4040 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004041
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 }
4043
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004044 if (!status) {
4045 DEBUG(printk(KERN_INFO
4046 "qla2x00_abort_isp(%ld): succeeded.\n",
4047 vha->host_no));
Arun Easifeafb7b2010-09-03 14:57:00 -07004048
4049 spin_lock_irqsave(&ha->vport_slock, flags);
4050 list_for_each_entry(vp, &ha->vp_list, list) {
4051 if (vp->vp_idx) {
4052 atomic_inc(&vp->vref_count);
4053 spin_unlock_irqrestore(&ha->vport_slock, flags);
4054
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004055 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004056
4057 spin_lock_irqsave(&ha->vport_slock, flags);
4058 atomic_dec(&vp->vref_count);
4059 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004060 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004061 spin_unlock_irqrestore(&ha->vport_slock, flags);
4062
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004063 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 qla_printk(KERN_INFO, ha,
4065 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 }
4067
4068 return(status);
4069}
4070
4071/*
4072* qla2x00_restart_isp
4073* restarts the ISP after a reset
4074*
4075* Input:
4076* ha = adapter block pointer.
4077*
4078* Returns:
4079* 0 = success
4080*/
4081static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004082qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004084 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004086 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004087 struct req_que *req = ha->req_q_map[0];
4088 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089
4090 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004091 if (qla2x00_isp_firmware(vha)) {
4092 vha->flags.online = 0;
4093 status = ha->isp_ops->chip_diag(vha);
4094 if (!status)
4095 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096 }
4097
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004098 if (!status && !(status = qla2x00_init_rings(vha))) {
4099 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004100 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004101 /* Initialize the queues in use */
4102 qla25xx_init_queues(ha);
4103
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004104 status = qla2x00_fw_ready(vha);
4105 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004107 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004108
4109 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004110 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004111
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004112 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004113 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4114 wait_time = 256;
4115 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004116 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4117 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004119 } while (!atomic_read(&vha->loop_down_timer) &&
4120 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4121 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4122 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123 }
4124
4125 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004126 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127 status = 0;
4128
4129 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4130 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004131 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132 }
4133 return (status);
4134}
4135
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004136static int
4137qla25xx_init_queues(struct qla_hw_data *ha)
4138{
4139 struct rsp_que *rsp = NULL;
4140 struct req_que *req = NULL;
4141 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4142 int ret = -1;
4143 int i;
4144
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004145 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004146 rsp = ha->rsp_q_map[i];
4147 if (rsp) {
4148 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004149 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004150 if (ret != QLA_SUCCESS)
4151 DEBUG2_17(printk(KERN_WARNING
4152 "%s Rsp que:%d init failed\n", __func__,
4153 rsp->id));
4154 else
4155 DEBUG2_17(printk(KERN_INFO
4156 "%s Rsp que:%d inited\n", __func__,
4157 rsp->id));
4158 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004159 }
4160 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004161 req = ha->req_q_map[i];
4162 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004163 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004164 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004165 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004166 if (ret != QLA_SUCCESS)
4167 DEBUG2_17(printk(KERN_WARNING
4168 "%s Req que:%d init failed\n", __func__,
4169 req->id));
4170 else
4171 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004172 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004173 req->id));
4174 }
4175 }
4176 return ret;
4177}
4178
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179/*
4180* qla2x00_reset_adapter
4181* Reset adapter.
4182*
4183* Input:
4184* ha = adapter block pointer.
4185*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004186void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004187qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188{
4189 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004190 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004191 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004192
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004193 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004194 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196 spin_lock_irqsave(&ha->hardware_lock, flags);
4197 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4198 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4199 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4200 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4201 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4202}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004203
4204void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004205qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004206{
4207 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004208 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004209 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4210
Giridhar Malavalia9083012010-04-12 17:59:55 -07004211 if (IS_QLA82XX(ha))
4212 return;
4213
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004214 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004215 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004216
4217 spin_lock_irqsave(&ha->hardware_lock, flags);
4218 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4219 RD_REG_DWORD(&reg->hccr);
4220 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4221 RD_REG_DWORD(&reg->hccr);
4222 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004223
4224 if (IS_NOPOLLING_TYPE(ha))
4225 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004226}
4227
David Miller4e08df32007-04-16 12:37:43 -07004228/* On sparc systems, obtain port and node WWN from firmware
4229 * properties.
4230 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004231static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4232 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004233{
4234#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004235 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004236 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004237 struct device_node *dp = pci_device_to_OF_node(pdev);
4238 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004239 int len;
4240
4241 val = of_get_property(dp, "port-wwn", &len);
4242 if (val && len >= WWN_SIZE)
4243 memcpy(nv->port_name, val, WWN_SIZE);
4244
4245 val = of_get_property(dp, "node-wwn", &len);
4246 if (val && len >= WWN_SIZE)
4247 memcpy(nv->node_name, val, WWN_SIZE);
4248#endif
4249}
4250
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004251int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004252qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004253{
David Miller4e08df32007-04-16 12:37:43 -07004254 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004255 struct init_cb_24xx *icb;
4256 struct nvram_24xx *nv;
4257 uint32_t *dptr;
4258 uint8_t *dptr1, *dptr2;
4259 uint32_t chksum;
4260 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004261 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004262
David Miller4e08df32007-04-16 12:37:43 -07004263 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004264 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004265 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004266
4267 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004268 if (ha->flags.port0) {
4269 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4270 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4271 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004272 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004273 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4274 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004275 ha->nvram_size = sizeof(struct nvram_24xx);
4276 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004277 if (IS_QLA82XX(ha))
4278 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004279
Seokmann Ju281afe12007-07-26 13:43:34 -07004280 /* Get VPD data into cache */
4281 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004282 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004283 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4284
4285 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004286 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004287 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004288 ha->nvram_size);
4289 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4290 chksum += le32_to_cpu(*dptr++);
4291
Andrew Vasquez76403352009-04-06 22:33:39 -07004292 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07004293 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004294
4295 /* Bad NVRAM data, set defaults parameters. */
4296 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4297 || nv->id[3] != ' ' ||
4298 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4299 /* Reset NVRAM data. */
4300 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4301 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4302 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07004303 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4304 "invalid -- WWPN) defaults.\n");
4305
4306 /*
4307 * Set default initialization control block.
4308 */
4309 memset(nv, 0, ha->nvram_size);
4310 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4311 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4312 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4313 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4314 nv->exchange_count = __constant_cpu_to_le16(0);
4315 nv->hard_address = __constant_cpu_to_le16(124);
4316 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004317 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004318 nv->port_name[2] = 0x00;
4319 nv->port_name[3] = 0xe0;
4320 nv->port_name[4] = 0x8b;
4321 nv->port_name[5] = 0x1c;
4322 nv->port_name[6] = 0x55;
4323 nv->port_name[7] = 0x86;
4324 nv->node_name[0] = 0x20;
4325 nv->node_name[1] = 0x00;
4326 nv->node_name[2] = 0x00;
4327 nv->node_name[3] = 0xe0;
4328 nv->node_name[4] = 0x8b;
4329 nv->node_name[5] = 0x1c;
4330 nv->node_name[6] = 0x55;
4331 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004332 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004333 nv->login_retry_count = __constant_cpu_to_le16(8);
4334 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4335 nv->login_timeout = __constant_cpu_to_le16(0);
4336 nv->firmware_options_1 =
4337 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4338 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4339 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4340 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4341 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4342 nv->efi_parameters = __constant_cpu_to_le32(0);
4343 nv->reset_delay = 5;
4344 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4345 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4346 nv->link_down_timeout = __constant_cpu_to_le16(30);
4347
4348 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004349 }
4350
4351 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004352 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004353
4354 /* Copy 1st segment. */
4355 dptr1 = (uint8_t *)icb;
4356 dptr2 = (uint8_t *)&nv->version;
4357 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4358 while (cnt--)
4359 *dptr1++ = *dptr2++;
4360
4361 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004362 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004363
4364 /* Copy 2nd segment. */
4365 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4366 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4367 cnt = (uint8_t *)&icb->reserved_3 -
4368 (uint8_t *)&icb->interrupt_delay_timer;
4369 while (cnt--)
4370 *dptr1++ = *dptr2++;
4371
4372 /*
4373 * Setup driver NVRAM options.
4374 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004375 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004376 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004377
Andrew Vasquez5341e862006-05-17 15:09:16 -07004378 /* Use alternate WWN? */
4379 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4380 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4381 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4382 }
4383
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004384 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004385 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004386 /*
4387 * Firmware will apply the following mask if the nodename was
4388 * not provided.
4389 */
4390 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4391 icb->node_name[0] &= 0xF0;
4392 }
4393
4394 /* Set host adapter parameters. */
4395 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004396 ha->flags.enable_lip_reset = 0;
4397 ha->flags.enable_lip_full_login =
4398 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4399 ha->flags.enable_target_reset =
4400 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004401 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004402 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004403
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004404 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4405 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004406
4407 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4408 sizeof(ha->fw_seriallink_options24));
4409
4410 /* save HBA serial number */
4411 ha->serial0 = icb->port_name[5];
4412 ha->serial1 = icb->port_name[6];
4413 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004414 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4415 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004416
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004417 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4418
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004419 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4420
4421 /* Set minimum login_timeout to 4 seconds. */
4422 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4423 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4424 if (le16_to_cpu(nv->login_timeout) < 4)
4425 nv->login_timeout = __constant_cpu_to_le16(4);
4426 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004427 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004428
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004429 /* Set minimum RATOV to 100 tenths of a second. */
4430 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004431
4432 ha->loop_reset_delay = nv->reset_delay;
4433
4434 /* Link Down Timeout = 0:
4435 *
4436 * When Port Down timer expires we will start returning
4437 * I/O's to OS with "DID_NO_CONNECT".
4438 *
4439 * Link Down Timeout != 0:
4440 *
4441 * The driver waits for the link to come up after link down
4442 * before returning I/Os to OS with "DID_NO_CONNECT".
4443 */
4444 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4445 ha->loop_down_abort_time =
4446 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4447 } else {
4448 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4449 ha->loop_down_abort_time =
4450 (LOOP_DOWN_TIME - ha->link_down_timeout);
4451 }
4452
4453 /* Need enough time to try and get the port back. */
4454 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4455 if (qlport_down_retry)
4456 ha->port_down_retry_count = qlport_down_retry;
4457
4458 /* Set login_retry_count */
4459 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4460 if (ha->port_down_retry_count ==
4461 le16_to_cpu(nv->port_down_retry_count) &&
4462 ha->port_down_retry_count > 3)
4463 ha->login_retry_count = ha->port_down_retry_count;
4464 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4465 ha->login_retry_count = ha->port_down_retry_count;
4466 if (ql2xloginretrycount)
4467 ha->login_retry_count = ql2xloginretrycount;
4468
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004469 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004470 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004471 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4472 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4473 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4474 le16_to_cpu(icb->interrupt_delay_timer): 2;
4475 }
4476 icb->firmware_options_2 &= __constant_cpu_to_le32(
4477 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004478 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004479 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004480 ha->zio_mode = QLA_ZIO_MODE_6;
4481
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004482 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004483 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004484 ha->zio_timer * 100));
4485 qla_printk(KERN_INFO, ha,
4486 "ZIO mode %d enabled; timer delay (%d us).\n",
4487 ha->zio_mode, ha->zio_timer * 100);
4488
4489 icb->firmware_options_2 |= cpu_to_le32(
4490 (uint32_t)ha->zio_mode);
4491 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004492 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004493 }
4494
David Miller4e08df32007-04-16 12:37:43 -07004495 if (rval) {
4496 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004497 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004498 }
4499 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004500}
4501
Adrian Bunk413975a2006-06-30 02:33:06 -07004502static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004503qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4504 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004505{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004506 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004507 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004508 uint32_t *dcode, dlen;
4509 uint32_t risc_addr;
4510 uint32_t risc_size;
4511 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004512 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004513 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004514
4515 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004516 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004517
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004518 rval = QLA_SUCCESS;
4519
4520 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004521 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004522 *srisc_addr = 0;
4523
4524 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004525 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004526 for (i = 0; i < 4; i++)
4527 dcode[i] = be32_to_cpu(dcode[i]);
4528 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4529 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4530 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4531 dcode[3] == 0)) {
4532 qla_printk(KERN_WARNING, ha,
4533 "Unable to verify integrity of flash firmware image!\n");
4534 qla_printk(KERN_WARNING, ha,
4535 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4536 dcode[1], dcode[2], dcode[3]);
4537
4538 return QLA_FUNCTION_FAILED;
4539 }
4540
4541 while (segments && rval == QLA_SUCCESS) {
4542 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004543 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004544
4545 risc_addr = be32_to_cpu(dcode[2]);
4546 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4547 risc_size = be32_to_cpu(dcode[3]);
4548
4549 fragment = 0;
4550 while (risc_size > 0 && rval == QLA_SUCCESS) {
4551 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4552 if (dlen > risc_size)
4553 dlen = risc_size;
4554
4555 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4556 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004557 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004558
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004559 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004560 for (i = 0; i < dlen; i++)
4561 dcode[i] = swab32(dcode[i]);
4562
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004563 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004564 dlen);
4565 if (rval) {
4566 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004567 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004568 fragment));
4569 qla_printk(KERN_WARNING, ha,
4570 "[ERROR] Failed to load segment %d of "
4571 "firmware\n", fragment);
4572 break;
4573 }
4574
4575 faddr += dlen;
4576 risc_addr += dlen;
4577 risc_size -= dlen;
4578 fragment++;
4579 }
4580
4581 /* Next segment. */
4582 segments--;
4583 }
4584
4585 return rval;
4586}
4587
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004588#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4589
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004590int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004591qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004592{
4593 int rval;
4594 int i, fragment;
4595 uint16_t *wcode, *fwcode;
4596 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4597 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004598 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004599 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004600
4601 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004602 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004603 if (!blob) {
4604 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004605 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4606 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004607 return QLA_FUNCTION_FAILED;
4608 }
4609
4610 rval = QLA_SUCCESS;
4611
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004612 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004613 *srisc_addr = 0;
4614 fwcode = (uint16_t *)blob->fw->data;
4615 fwclen = 0;
4616
4617 /* Validate firmware image by checking version. */
4618 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4619 qla_printk(KERN_WARNING, ha,
4620 "Unable to verify integrity of firmware image (%Zd)!\n",
4621 blob->fw->size);
4622 goto fail_fw_integrity;
4623 }
4624 for (i = 0; i < 4; i++)
4625 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4626 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4627 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4628 wcode[2] == 0 && wcode[3] == 0)) {
4629 qla_printk(KERN_WARNING, ha,
4630 "Unable to verify integrity of firmware image!\n");
4631 qla_printk(KERN_WARNING, ha,
4632 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4633 wcode[1], wcode[2], wcode[3]);
4634 goto fail_fw_integrity;
4635 }
4636
4637 seg = blob->segs;
4638 while (*seg && rval == QLA_SUCCESS) {
4639 risc_addr = *seg;
4640 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4641 risc_size = be16_to_cpu(fwcode[3]);
4642
4643 /* Validate firmware image size. */
4644 fwclen += risc_size * sizeof(uint16_t);
4645 if (blob->fw->size < fwclen) {
4646 qla_printk(KERN_WARNING, ha,
4647 "Unable to verify integrity of firmware image "
4648 "(%Zd)!\n", blob->fw->size);
4649 goto fail_fw_integrity;
4650 }
4651
4652 fragment = 0;
4653 while (risc_size > 0 && rval == QLA_SUCCESS) {
4654 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4655 if (wlen > risc_size)
4656 wlen = risc_size;
4657
4658 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004659 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004660 risc_addr, wlen));
4661
4662 for (i = 0; i < wlen; i++)
4663 wcode[i] = swab16(fwcode[i]);
4664
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004665 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004666 wlen);
4667 if (rval) {
4668 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004669 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004670 fragment));
4671 qla_printk(KERN_WARNING, ha,
4672 "[ERROR] Failed to load segment %d of "
4673 "firmware\n", fragment);
4674 break;
4675 }
4676
4677 fwcode += wlen;
4678 risc_addr += wlen;
4679 risc_size -= wlen;
4680 fragment++;
4681 }
4682
4683 /* Next segment. */
4684 seg++;
4685 }
4686 return rval;
4687
4688fail_fw_integrity:
4689 return QLA_FUNCTION_FAILED;
4690}
4691
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004692static int
4693qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004694{
4695 int rval;
4696 int segments, fragment;
4697 uint32_t *dcode, dlen;
4698 uint32_t risc_addr;
4699 uint32_t risc_size;
4700 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004701 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004702 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004703 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004704 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004705
Andrew Vasquez54333832005-11-09 15:49:04 -08004706 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004707 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004708 if (!blob) {
4709 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004710 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4711 "from: " QLA_FW_URL ".\n");
4712
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004713 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004714 }
4715
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004716 qla_printk(KERN_INFO, ha,
4717 "FW: Loading via request-firmware...\n");
4718
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004719 rval = QLA_SUCCESS;
4720
4721 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004722 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004723 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004724 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004725 fwclen = 0;
4726
4727 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004728 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004729 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004730 "Unable to verify integrity of firmware image (%Zd)!\n",
4731 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004732 goto fail_fw_integrity;
4733 }
4734 for (i = 0; i < 4; i++)
4735 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4736 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4737 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4738 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4739 dcode[3] == 0)) {
4740 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004741 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004742 qla_printk(KERN_WARNING, ha,
4743 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4744 dcode[1], dcode[2], dcode[3]);
4745 goto fail_fw_integrity;
4746 }
4747
4748 while (segments && rval == QLA_SUCCESS) {
4749 risc_addr = be32_to_cpu(fwcode[2]);
4750 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4751 risc_size = be32_to_cpu(fwcode[3]);
4752
4753 /* Validate firmware image size. */
4754 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004755 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004756 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004757 "Unable to verify integrity of firmware image "
4758 "(%Zd)!\n", blob->fw->size);
4759
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004760 goto fail_fw_integrity;
4761 }
4762
4763 fragment = 0;
4764 while (risc_size > 0 && rval == QLA_SUCCESS) {
4765 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4766 if (dlen > risc_size)
4767 dlen = risc_size;
4768
4769 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004770 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004771 risc_addr, dlen));
4772
4773 for (i = 0; i < dlen; i++)
4774 dcode[i] = swab32(fwcode[i]);
4775
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004776 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004777 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004778 if (rval) {
4779 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004780 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004781 fragment));
4782 qla_printk(KERN_WARNING, ha,
4783 "[ERROR] Failed to load segment %d of "
4784 "firmware\n", fragment);
4785 break;
4786 }
4787
4788 fwcode += dlen;
4789 risc_addr += dlen;
4790 risc_size -= dlen;
4791 fragment++;
4792 }
4793
4794 /* Next segment. */
4795 segments--;
4796 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004797 return rval;
4798
4799fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004800 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004801}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004802
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004803int
4804qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4805{
4806 int rval;
4807
Andrew Vasqueze337d902009-04-06 22:33:49 -07004808 if (ql2xfwloadbin == 1)
4809 return qla81xx_load_risc(vha, srisc_addr);
4810
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004811 /*
4812 * FW Load priority:
4813 * 1) Firmware via request-firmware interface (.bin file).
4814 * 2) Firmware residing in flash.
4815 */
4816 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4817 if (rval == QLA_SUCCESS)
4818 return rval;
4819
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004820 return qla24xx_load_risc_flash(vha, srisc_addr,
4821 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004822}
4823
4824int
4825qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4826{
4827 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004828 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004829
Andrew Vasqueze337d902009-04-06 22:33:49 -07004830 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004831 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004832
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004833 /*
4834 * FW Load priority:
4835 * 1) Firmware residing in flash.
4836 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004837 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004838 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004839 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004840 if (rval == QLA_SUCCESS)
4841 return rval;
4842
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004843try_blob_fw:
4844 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4845 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4846 return rval;
4847
4848 qla_printk(KERN_ERR, ha,
4849 "FW: Attempting to fallback to golden firmware...\n");
4850 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4851 if (rval != QLA_SUCCESS)
4852 return rval;
4853
4854 qla_printk(KERN_ERR, ha,
4855 "FW: Please update operational firmware...\n");
4856 ha->flags.running_gold_fw = 1;
4857
4858 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004859}
4860
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004861void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004862qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004863{
4864 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004865 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004866
Andrew Vasquez85880802009-12-15 21:29:46 -08004867 if (ha->flags.pci_channel_io_perm_failure)
4868 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004869 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004870 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004871 if (!ha->fw_major_version)
4872 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004873
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004874 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004875 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004876 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004877 ha->isp_ops->reset_chip(vha);
4878 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004879 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004880 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004881 continue;
4882 qla_printk(KERN_INFO, ha,
4883 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004884 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004885 }
4886}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004887
4888int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004889qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004890{
4891 int rval = QLA_SUCCESS;
4892 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004893 struct qla_hw_data *ha = vha->hw;
4894 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004895 struct req_que *req;
4896 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004897
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004898 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004899 return -EINVAL;
4900
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004901 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004902 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004903 req = ha->req_q_map[0];
4904 else
4905 req = vha->req;
4906 rsp = req->rsp;
4907
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004908 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004909 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004910 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004911 }
4912
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004913 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004914
4915 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004916 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004917 if (mb[0] != MBS_COMMAND_COMPLETE) {
4918 DEBUG15(qla_printk(KERN_INFO, ha,
4919 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4920 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4921 mb[0], mb[1], mb[2], mb[6], mb[7]));
4922 return (QLA_FUNCTION_FAILED);
4923 }
4924
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004925 atomic_set(&vha->loop_down_timer, 0);
4926 atomic_set(&vha->loop_state, LOOP_UP);
4927 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4928 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4929 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004930
4931 return rval;
4932}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004933
4934/* 84XX Support **************************************************************/
4935
4936static LIST_HEAD(qla_cs84xx_list);
4937static DEFINE_MUTEX(qla_cs84xx_mutex);
4938
4939static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004940qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004941{
4942 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004943 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004944
4945 mutex_lock(&qla_cs84xx_mutex);
4946
4947 /* Find any shared 84xx chip. */
4948 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4949 if (cs84xx->bus == ha->pdev->bus) {
4950 kref_get(&cs84xx->kref);
4951 goto done;
4952 }
4953 }
4954
4955 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4956 if (!cs84xx)
4957 goto done;
4958
4959 kref_init(&cs84xx->kref);
4960 spin_lock_init(&cs84xx->access_lock);
4961 mutex_init(&cs84xx->fw_update_mutex);
4962 cs84xx->bus = ha->pdev->bus;
4963
4964 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4965done:
4966 mutex_unlock(&qla_cs84xx_mutex);
4967 return cs84xx;
4968}
4969
4970static void
4971__qla84xx_chip_release(struct kref *kref)
4972{
4973 struct qla_chip_state_84xx *cs84xx =
4974 container_of(kref, struct qla_chip_state_84xx, kref);
4975
4976 mutex_lock(&qla_cs84xx_mutex);
4977 list_del(&cs84xx->list);
4978 mutex_unlock(&qla_cs84xx_mutex);
4979 kfree(cs84xx);
4980}
4981
4982void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004983qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004984{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004985 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004986 if (ha->cs84xx)
4987 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4988}
4989
4990static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004991qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004992{
4993 int rval;
4994 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004995 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004996
4997 mutex_lock(&ha->cs84xx->fw_update_mutex);
4998
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004999 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005000
5001 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5002
5003 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5004 QLA_SUCCESS;
5005}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005006
5007/* 81XX Support **************************************************************/
5008
5009int
5010qla81xx_nvram_config(scsi_qla_host_t *vha)
5011{
5012 int rval;
5013 struct init_cb_81xx *icb;
5014 struct nvram_81xx *nv;
5015 uint32_t *dptr;
5016 uint8_t *dptr1, *dptr2;
5017 uint32_t chksum;
5018 uint16_t cnt;
5019 struct qla_hw_data *ha = vha->hw;
5020
5021 rval = QLA_SUCCESS;
5022 icb = (struct init_cb_81xx *)ha->init_cb;
5023 nv = ha->nvram;
5024
5025 /* Determine NVRAM starting address. */
5026 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005027 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005028
5029 /* Get VPD data into cache */
5030 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005031 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5032 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005033
5034 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005035 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005036 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005037 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005038 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5039 chksum += le32_to_cpu(*dptr++);
5040
Andrew Vasquez76403352009-04-06 22:33:39 -07005041 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005042 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
5043
5044 /* Bad NVRAM data, set defaults parameters. */
5045 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5046 || nv->id[3] != ' ' ||
5047 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5048 /* Reset NVRAM data. */
5049 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
5050 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
5051 le16_to_cpu(nv->nvram_version));
5052 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
5053 "invalid -- WWPN) defaults.\n");
5054
5055 /*
5056 * Set default initialization control block.
5057 */
5058 memset(nv, 0, ha->nvram_size);
5059 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5060 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5061 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5062 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5063 nv->exchange_count = __constant_cpu_to_le16(0);
5064 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005065 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005066 nv->port_name[2] = 0x00;
5067 nv->port_name[3] = 0xe0;
5068 nv->port_name[4] = 0x8b;
5069 nv->port_name[5] = 0x1c;
5070 nv->port_name[6] = 0x55;
5071 nv->port_name[7] = 0x86;
5072 nv->node_name[0] = 0x20;
5073 nv->node_name[1] = 0x00;
5074 nv->node_name[2] = 0x00;
5075 nv->node_name[3] = 0xe0;
5076 nv->node_name[4] = 0x8b;
5077 nv->node_name[5] = 0x1c;
5078 nv->node_name[6] = 0x55;
5079 nv->node_name[7] = 0x86;
5080 nv->login_retry_count = __constant_cpu_to_le16(8);
5081 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5082 nv->login_timeout = __constant_cpu_to_le16(0);
5083 nv->firmware_options_1 =
5084 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5085 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5086 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5087 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5088 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5089 nv->efi_parameters = __constant_cpu_to_le32(0);
5090 nv->reset_delay = 5;
5091 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5092 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5093 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005094 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005095 nv->enode_mac[1] = 0x02;
5096 nv->enode_mac[2] = 0x03;
5097 nv->enode_mac[3] = 0x04;
5098 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005099 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005100
5101 rval = 1;
5102 }
5103
5104 /* Reset Initialization control block */
5105 memset(icb, 0, sizeof(struct init_cb_81xx));
5106
5107 /* Copy 1st segment. */
5108 dptr1 = (uint8_t *)icb;
5109 dptr2 = (uint8_t *)&nv->version;
5110 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5111 while (cnt--)
5112 *dptr1++ = *dptr2++;
5113
5114 icb->login_retry_count = nv->login_retry_count;
5115
5116 /* Copy 2nd segment. */
5117 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5118 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5119 cnt = (uint8_t *)&icb->reserved_5 -
5120 (uint8_t *)&icb->interrupt_delay_timer;
5121 while (cnt--)
5122 *dptr1++ = *dptr2++;
5123
5124 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5125 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5126 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
5127 icb->enode_mac[0] = 0x01;
5128 icb->enode_mac[1] = 0x02;
5129 icb->enode_mac[2] = 0x03;
5130 icb->enode_mac[3] = 0x04;
5131 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005132 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005133 }
5134
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005135 /* Use extended-initialization control block. */
5136 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5137
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005138 /*
5139 * Setup driver NVRAM options.
5140 */
5141 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005142 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005143
5144 /* Use alternate WWN? */
5145 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5146 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5147 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5148 }
5149
5150 /* Prepare nodename */
5151 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5152 /*
5153 * Firmware will apply the following mask if the nodename was
5154 * not provided.
5155 */
5156 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5157 icb->node_name[0] &= 0xF0;
5158 }
5159
5160 /* Set host adapter parameters. */
5161 ha->flags.disable_risc_code_load = 0;
5162 ha->flags.enable_lip_reset = 0;
5163 ha->flags.enable_lip_full_login =
5164 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5165 ha->flags.enable_target_reset =
5166 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5167 ha->flags.enable_led_scheme = 0;
5168 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5169
5170 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5171 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5172
5173 /* save HBA serial number */
5174 ha->serial0 = icb->port_name[5];
5175 ha->serial1 = icb->port_name[6];
5176 ha->serial2 = icb->port_name[7];
5177 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5178 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5179
5180 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5181
5182 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5183
5184 /* Set minimum login_timeout to 4 seconds. */
5185 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5186 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5187 if (le16_to_cpu(nv->login_timeout) < 4)
5188 nv->login_timeout = __constant_cpu_to_le16(4);
5189 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5190 icb->login_timeout = nv->login_timeout;
5191
5192 /* Set minimum RATOV to 100 tenths of a second. */
5193 ha->r_a_tov = 100;
5194
5195 ha->loop_reset_delay = nv->reset_delay;
5196
5197 /* Link Down Timeout = 0:
5198 *
5199 * When Port Down timer expires we will start returning
5200 * I/O's to OS with "DID_NO_CONNECT".
5201 *
5202 * Link Down Timeout != 0:
5203 *
5204 * The driver waits for the link to come up after link down
5205 * before returning I/Os to OS with "DID_NO_CONNECT".
5206 */
5207 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5208 ha->loop_down_abort_time =
5209 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5210 } else {
5211 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5212 ha->loop_down_abort_time =
5213 (LOOP_DOWN_TIME - ha->link_down_timeout);
5214 }
5215
5216 /* Need enough time to try and get the port back. */
5217 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5218 if (qlport_down_retry)
5219 ha->port_down_retry_count = qlport_down_retry;
5220
5221 /* Set login_retry_count */
5222 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5223 if (ha->port_down_retry_count ==
5224 le16_to_cpu(nv->port_down_retry_count) &&
5225 ha->port_down_retry_count > 3)
5226 ha->login_retry_count = ha->port_down_retry_count;
5227 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5228 ha->login_retry_count = ha->port_down_retry_count;
5229 if (ql2xloginretrycount)
5230 ha->login_retry_count = ql2xloginretrycount;
5231
5232 /* Enable ZIO. */
5233 if (!vha->flags.init_done) {
5234 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5235 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5236 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5237 le16_to_cpu(icb->interrupt_delay_timer): 2;
5238 }
5239 icb->firmware_options_2 &= __constant_cpu_to_le32(
5240 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5241 vha->flags.process_response_queue = 0;
5242 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5243 ha->zio_mode = QLA_ZIO_MODE_6;
5244
5245 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5246 "(%d us).\n", vha->host_no, ha->zio_mode,
5247 ha->zio_timer * 100));
5248 qla_printk(KERN_INFO, ha,
5249 "ZIO mode %d enabled; timer delay (%d us).\n",
5250 ha->zio_mode, ha->zio_timer * 100);
5251
5252 icb->firmware_options_2 |= cpu_to_le32(
5253 (uint32_t)ha->zio_mode);
5254 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5255 vha->flags.process_response_queue = 1;
5256 }
5257
5258 if (rval) {
5259 DEBUG2_3(printk(KERN_WARNING
5260 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
5261 }
5262 return (rval);
5263}
5264
Giridhar Malavalia9083012010-04-12 17:59:55 -07005265int
5266qla82xx_restart_isp(scsi_qla_host_t *vha)
5267{
5268 int status, rval;
5269 uint32_t wait_time;
5270 struct qla_hw_data *ha = vha->hw;
5271 struct req_que *req = ha->req_q_map[0];
5272 struct rsp_que *rsp = ha->rsp_q_map[0];
5273 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005274 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005275
5276 status = qla2x00_init_rings(vha);
5277 if (!status) {
5278 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5279 ha->flags.chip_reset_done = 1;
5280
5281 status = qla2x00_fw_ready(vha);
5282 if (!status) {
5283 qla_printk(KERN_INFO, ha,
5284 "%s(): Start configure loop, "
5285 "status = %d\n", __func__, status);
5286
5287 /* Issue a marker after FW becomes ready. */
5288 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5289
5290 vha->flags.online = 1;
5291 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5292 wait_time = 256;
5293 do {
5294 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5295 qla2x00_configure_loop(vha);
5296 wait_time--;
5297 } while (!atomic_read(&vha->loop_down_timer) &&
5298 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5299 wait_time &&
5300 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5301 }
5302
5303 /* if no cable then assume it's good */
5304 if ((vha->device_flags & DFLG_NO_CABLE))
5305 status = 0;
5306
5307 qla_printk(KERN_INFO, ha,
5308 "%s(): Configure loop done, status = 0x%x\n",
5309 __func__, status);
5310 }
5311
5312 if (!status) {
5313 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5314
5315 if (!atomic_read(&vha->loop_down_timer)) {
5316 /*
5317 * Issue marker command only when we are going
5318 * to start the I/O .
5319 */
5320 vha->marker_needed = 1;
5321 }
5322
5323 vha->flags.online = 1;
5324
5325 ha->isp_ops->enable_intrs(ha);
5326
5327 ha->isp_abort_cnt = 0;
5328 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5329
5330 if (ha->fce) {
5331 ha->flags.fce_enabled = 1;
5332 memset(ha->fce, 0,
5333 fce_calc_size(ha->fce_bufs));
5334 rval = qla2x00_enable_fce_trace(vha,
5335 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5336 &ha->fce_bufs);
5337 if (rval) {
5338 qla_printk(KERN_WARNING, ha,
5339 "Unable to reinitialize FCE "
5340 "(%d).\n", rval);
5341 ha->flags.fce_enabled = 0;
5342 }
5343 }
5344
5345 if (ha->eft) {
5346 memset(ha->eft, 0, EFT_SIZE);
5347 rval = qla2x00_enable_eft_trace(vha,
5348 ha->eft_dma, EFT_NUM_BUFFERS);
5349 if (rval) {
5350 qla_printk(KERN_WARNING, ha,
5351 "Unable to reinitialize EFT "
5352 "(%d).\n", rval);
5353 }
5354 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005355 }
5356
5357 if (!status) {
5358 DEBUG(printk(KERN_INFO
5359 "qla82xx_restart_isp(%ld): succeeded.\n",
5360 vha->host_no));
Arun Easifeafb7b2010-09-03 14:57:00 -07005361
5362 spin_lock_irqsave(&ha->vport_slock, flags);
5363 list_for_each_entry(vp, &ha->vp_list, list) {
5364 if (vp->vp_idx) {
5365 atomic_inc(&vp->vref_count);
5366 spin_unlock_irqrestore(&ha->vport_slock, flags);
5367
Giridhar Malavalia9083012010-04-12 17:59:55 -07005368 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07005369
5370 spin_lock_irqsave(&ha->vport_slock, flags);
5371 atomic_dec(&vp->vref_count);
5372 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005373 }
Arun Easifeafb7b2010-09-03 14:57:00 -07005374 spin_unlock_irqrestore(&ha->vport_slock, flags);
5375
Giridhar Malavalia9083012010-04-12 17:59:55 -07005376 } else {
5377 qla_printk(KERN_INFO, ha,
5378 "qla82xx_restart_isp: **** FAILED ****\n");
5379 }
5380
5381 return status;
5382}
5383
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005384void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005385qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005386{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005387 struct qla_hw_data *ha = vha->hw;
5388
5389 if (!ql2xetsenable)
5390 return;
5391
5392 /* Enable ETS Burst. */
5393 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5394 ha->fw_options[2] |= BIT_9;
5395 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005396}
Sarang Radke09ff7012010-03-19 17:03:59 -07005397
5398/*
5399 * qla24xx_get_fcp_prio
5400 * Gets the fcp cmd priority value for the logged in port.
5401 * Looks for a match of the port descriptors within
5402 * each of the fcp prio config entries. If a match is found,
5403 * the tag (priority) value is returned.
5404 *
5405 * Input:
5406 * ha = adapter block po
5407 * fcport = port structure pointer.
5408 *
5409 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005410 * non-zero (if found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005411 * 0 (if not found)
5412 *
5413 * Context:
5414 * Kernel context
5415 */
5416uint8_t
5417qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5418{
5419 int i, entries;
5420 uint8_t pid_match, wwn_match;
5421 uint8_t priority;
5422 uint32_t pid1, pid2;
5423 uint64_t wwn1, wwn2;
5424 struct qla_fcp_prio_entry *pri_entry;
5425 struct qla_hw_data *ha = vha->hw;
5426
5427 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
5428 return 0;
5429
5430 priority = 0;
5431 entries = ha->fcp_prio_cfg->num_entries;
5432 pri_entry = &ha->fcp_prio_cfg->entry[0];
5433
5434 for (i = 0; i < entries; i++) {
5435 pid_match = wwn_match = 0;
5436
5437 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5438 pri_entry++;
5439 continue;
5440 }
5441
5442 /* check source pid for a match */
5443 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5444 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5445 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5446 if (pid1 == INVALID_PORT_ID)
5447 pid_match++;
5448 else if (pid1 == pid2)
5449 pid_match++;
5450 }
5451
5452 /* check destination pid for a match */
5453 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5454 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5455 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5456 if (pid1 == INVALID_PORT_ID)
5457 pid_match++;
5458 else if (pid1 == pid2)
5459 pid_match++;
5460 }
5461
5462 /* check source WWN for a match */
5463 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5464 wwn1 = wwn_to_u64(vha->port_name);
5465 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5466 if (wwn2 == (uint64_t)-1)
5467 wwn_match++;
5468 else if (wwn1 == wwn2)
5469 wwn_match++;
5470 }
5471
5472 /* check destination WWN for a match */
5473 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5474 wwn1 = wwn_to_u64(fcport->port_name);
5475 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5476 if (wwn2 == (uint64_t)-1)
5477 wwn_match++;
5478 else if (wwn1 == wwn2)
5479 wwn_match++;
5480 }
5481
5482 if (pid_match == 2 || wwn_match == 2) {
5483 /* Found a matching entry */
5484 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5485 priority = pri_entry->tag;
5486 break;
5487 }
5488
5489 pri_entry++;
5490 }
5491
5492 return priority;
5493}
5494
5495/*
5496 * qla24xx_update_fcport_fcp_prio
5497 * Activates fcp priority for the logged in fc port
5498 *
5499 * Input:
5500 * ha = adapter block pointer.
5501 * fcp = port structure pointer.
5502 *
5503 * Return:
5504 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5505 *
5506 * Context:
5507 * Kernel context.
5508 */
5509int
5510qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *ha, fc_port_t *fcport)
5511{
5512 int ret;
5513 uint8_t priority;
5514 uint16_t mb[5];
5515
5516 if (atomic_read(&fcport->state) == FCS_UNCONFIGURED ||
5517 fcport->port_type != FCT_TARGET ||
5518 fcport->loop_id == FC_NO_LOOP_ID)
5519 return QLA_FUNCTION_FAILED;
5520
5521 priority = qla24xx_get_fcp_prio(ha, fcport);
5522 ret = qla24xx_set_fcp_prio(ha, fcport->loop_id, priority, mb);
5523 if (ret == QLA_SUCCESS)
5524 fcport->fcp_prio = priority;
5525 else
5526 DEBUG2(printk(KERN_WARNING
5527 "scsi(%ld): Unable to activate fcp priority, "
5528 " ret=0x%x\n", ha->host_no, ret));
5529
5530 return ret;
5531}
5532
5533/*
5534 * qla24xx_update_all_fcp_prio
5535 * Activates fcp priority for all the logged in ports
5536 *
5537 * Input:
5538 * ha = adapter block pointer.
5539 *
5540 * Return:
5541 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5542 *
5543 * Context:
5544 * Kernel context.
5545 */
5546int
5547qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5548{
5549 int ret;
5550 fc_port_t *fcport;
5551
5552 ret = QLA_FUNCTION_FAILED;
5553 /* We need to set priority for all logged in ports */
5554 list_for_each_entry(fcport, &vha->vp_fcports, list)
5555 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5556
5557 return ret;
5558}