blob: d0a0dc9d6d36fcb102adc46a2ce5eb3af71850a0 [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;
Andrew Vasquez794a5692010-12-21 16:00:21 -0800501 ha->flags.thermal_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800502 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
503 atomic_set(&vha->loop_state, LOOP_DOWN);
504 vha->device_flags = DFLG_NO_CABLE;
505 vha->dpc_flags = 0;
506 vha->flags.management_server_logged_in = 0;
507 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 ha->isp_abort_cnt = 0;
509 ha->beacon_blink_led = 0;
510
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800511 set_bit(0, ha->req_qid_map);
512 set_bit(0, ha->rsp_qid_map);
513
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700514 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800515 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -0800517 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800518 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 return (rval);
520 }
521
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800522 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800524 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700525 if (rval) {
526 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800527 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700528 return (rval);
529 }
530
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800531 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -0800532
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700534
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800535 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700537 if (ha->flags.disable_serdes) {
538 /* Mask HBA via NVRAM settings? */
539 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
540 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800541 vha->port_name[0], vha->port_name[1],
542 vha->port_name[2], vha->port_name[3],
543 vha->port_name[4], vha->port_name[5],
544 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700545 return QLA_FUNCTION_FAILED;
546 }
547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
549
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800550 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
551 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800552 if (rval)
553 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800554 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800555 if (rval)
556 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700558
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700559 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800560 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700561 if (!ha->cs84xx) {
562 qla_printk(KERN_ERR, ha,
563 "Unable to configure ISP84XX.\n");
564 return QLA_FUNCTION_FAILED;
565 }
566 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800567 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700568 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800570 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700571 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800572 rval = qla84xx_init_chip(vha);
573 if (rval != QLA_SUCCESS) {
574 qla_printk(KERN_ERR, ha,
575 "Unable to initialize ISP84XX.\n");
576 qla84xx_put_chip(vha);
577 }
578 }
579
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500580 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
581 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 return (rval);
584}
585
586/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700587 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 * @ha: HA context
589 *
590 * Returns 0 on success.
591 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700592int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800593qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700595 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700596 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800597 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700598 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700601 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700604 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
606
Andrew Vasquez737faec2008-10-24 15:13:45 -0700607 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700609 /* Get PCI bus information. */
610 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700611 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700612 spin_unlock_irqrestore(&ha->hardware_lock, flags);
613
614 return QLA_SUCCESS;
615}
616
617/**
618 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
619 * @ha: HA context
620 *
621 * Returns 0 on success.
622 */
623int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800624qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700625{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700626 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700627 unsigned long flags = 0;
628 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800629 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700630 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700631
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700632 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700633 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700634
635 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700636 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700637
638 if (IS_QLA2322(ha) || IS_QLA6322(ha))
639 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700640 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700641
642 /*
643 * If this is a 2300 card and not 2312, reset the
644 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
645 * the 2310 also reports itself as a 2300 so we need to get the
646 * fb revision level -- a 6 indicates it really is a 2300 and
647 * not a 2310.
648 */
649 if (IS_QLA2300(ha)) {
650 spin_lock_irqsave(&ha->hardware_lock, flags);
651
652 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700653 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700654 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700655 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700656 break;
657
658 udelay(10);
659 }
660
661 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700662 WRT_REG_WORD(&reg->ctrl_status, 0x20);
663 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700664
665 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700666 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700667
668 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700669 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700670
671 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700672 WRT_REG_WORD(&reg->ctrl_status, 0x0);
673 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700674
675 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700676 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700677 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700678 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700679 break;
680
681 udelay(10);
682 }
683
684 spin_unlock_irqrestore(&ha->hardware_lock, flags);
685 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700686
687 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
688
Andrew Vasquez737faec2008-10-24 15:13:45 -0700689 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700690
691 /* Get PCI bus information. */
692 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700693 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700694 spin_unlock_irqrestore(&ha->hardware_lock, flags);
695
696 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697}
698
699/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700700 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
701 * @ha: HA context
702 *
703 * Returns 0 on success.
704 */
705int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800706qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700707{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700708 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700709 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800710 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700711 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700712
713 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700714 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700715
716 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700717 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700718 w &= ~PCI_COMMAND_INTX_DISABLE;
719 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
720
721 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
722
723 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700724 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
725 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700726
727 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700728 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
729 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700730
Andrew Vasquez737faec2008-10-24 15:13:45 -0700731 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700732
Auke Kok44c10132007-06-08 15:46:36 -0700733 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800734
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700735 /* Get PCI bus information. */
736 spin_lock_irqsave(&ha->hardware_lock, flags);
737 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
738 spin_unlock_irqrestore(&ha->hardware_lock, flags);
739
740 return QLA_SUCCESS;
741}
742
743/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700744 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
745 * @ha: HA context
746 *
747 * Returns 0 on success.
748 */
749int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800750qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700751{
752 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800753 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700754
755 pci_set_master(ha->pdev);
756 pci_try_set_mwi(ha->pdev);
757
758 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
759 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
760 w &= ~PCI_COMMAND_INTX_DISABLE;
761 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
762
763 /* PCIe -- adjust Maximum Read Request Size (2048). */
764 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
765 pcie_set_readrq(ha->pdev, 2048);
766
Andrew Vasquez737faec2008-10-24 15:13:45 -0700767 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700768
769 ha->chip_revision = ha->pdev->revision;
770
771 return QLA_SUCCESS;
772}
773
774/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 * qla2x00_isp_firmware() - Choose firmware image.
776 * @ha: HA context
777 *
778 * Returns 0 on success.
779 */
780static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800781qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782{
783 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700784 uint16_t loop_id, topo, sw_cap;
785 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800786 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
788 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700789 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791 if (ha->flags.disable_risc_code_load) {
792 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800793 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
795
796 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800797 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700798 if (rval == QLA_SUCCESS) {
799 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800800 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700801 &area, &domain, &topo, &sw_cap);
802 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 }
804
805 if (rval) {
806 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800807 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 }
809
810 return (rval);
811}
812
813/**
814 * qla2x00_reset_chip() - Reset ISP chip.
815 * @ha: HA context
816 *
817 * Returns 0 on success.
818 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700819void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800820qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
822 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800823 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700824 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 uint16_t cmd;
827
Andrew Vasquez85880802009-12-15 21:29:46 -0800828 if (unlikely(pci_channel_offline(ha->pdev)))
829 return;
830
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700831 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
833 spin_lock_irqsave(&ha->hardware_lock, flags);
834
835 /* Turn off master enable */
836 cmd = 0;
837 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
838 cmd &= ~PCI_COMMAND_MASTER;
839 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
840
841 if (!IS_QLA2100(ha)) {
842 /* Pause RISC. */
843 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
844 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
845 for (cnt = 0; cnt < 30000; cnt++) {
846 if ((RD_REG_WORD(&reg->hccr) &
847 HCCR_RISC_PAUSE) != 0)
848 break;
849 udelay(100);
850 }
851 } else {
852 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
853 udelay(10);
854 }
855
856 /* Select FPM registers. */
857 WRT_REG_WORD(&reg->ctrl_status, 0x20);
858 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
859
860 /* FPM Soft Reset. */
861 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
862 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
863
864 /* Toggle Fpm Reset. */
865 if (!IS_QLA2200(ha)) {
866 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
867 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
868 }
869
870 /* Select frame buffer registers. */
871 WRT_REG_WORD(&reg->ctrl_status, 0x10);
872 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
873
874 /* Reset frame buffer FIFOs. */
875 if (IS_QLA2200(ha)) {
876 WRT_FB_CMD_REG(ha, reg, 0xa000);
877 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
878 } else {
879 WRT_FB_CMD_REG(ha, reg, 0x00fc);
880
881 /* Read back fb_cmd until zero or 3 seconds max */
882 for (cnt = 0; cnt < 3000; cnt++) {
883 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
884 break;
885 udelay(100);
886 }
887 }
888
889 /* Select RISC module registers. */
890 WRT_REG_WORD(&reg->ctrl_status, 0);
891 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
892
893 /* Reset RISC processor. */
894 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
895 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
896
897 /* Release RISC processor. */
898 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
899 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
900 }
901
902 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
903 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
904
905 /* Reset ISP chip. */
906 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
907
908 /* Wait for RISC to recover from reset. */
909 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
910 /*
911 * It is necessary to for a delay here since the card doesn't
912 * respond to PCI reads during a reset. On some architectures
913 * this will result in an MCA.
914 */
915 udelay(20);
916 for (cnt = 30000; cnt; cnt--) {
917 if ((RD_REG_WORD(&reg->ctrl_status) &
918 CSR_ISP_SOFT_RESET) == 0)
919 break;
920 udelay(100);
921 }
922 } else
923 udelay(10);
924
925 /* Reset RISC processor. */
926 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
927
928 WRT_REG_WORD(&reg->semaphore, 0);
929
930 /* Release RISC processor. */
931 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
932 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
933
934 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
935 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700936 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
939 udelay(100);
940 }
941 } else
942 udelay(100);
943
944 /* Turn on master enable */
945 cmd |= PCI_COMMAND_MASTER;
946 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
947
948 /* Disable RISC pause on FPM parity error. */
949 if (!IS_QLA2100(ha)) {
950 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
951 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
952 }
953
954 spin_unlock_irqrestore(&ha->hardware_lock, flags);
955}
956
957/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700958 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
959 *
960 * Returns 0 on success.
961 */
962int
963qla81xx_reset_mpi(scsi_qla_host_t *vha)
964{
965 uint16_t mb[4] = {0x1010, 0, 1, 0};
966
967 return qla81xx_write_mpi_register(vha, mb);
968}
969
970/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700971 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700972 * @ha: HA context
973 *
974 * Returns 0 on success.
975 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700976static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800977qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700978{
979 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800980 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700981 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
982 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800983 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700984 static int abts_cnt; /* ISP abort retry counts */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700985
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700986 spin_lock_irqsave(&ha->hardware_lock, flags);
987
988 /* Reset RISC. */
989 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
990 for (cnt = 0; cnt < 30000; cnt++) {
991 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
992 break;
993
994 udelay(10);
995 }
996
997 WRT_REG_DWORD(&reg->ctrl_status,
998 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800999 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001000
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001001 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001002 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001003 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1004 for (cnt = 10000 ; cnt && d2; cnt--) {
1005 udelay(5);
1006 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1007 barrier();
1008 }
1009
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001010 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001011 d2 = RD_REG_DWORD(&reg->ctrl_status);
1012 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1013 udelay(5);
1014 d2 = RD_REG_DWORD(&reg->ctrl_status);
1015 barrier();
1016 }
1017
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001018 /* If required, do an MPI FW reset now */
1019 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1020 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1021 if (++abts_cnt < 5) {
1022 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1023 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1024 } else {
1025 /*
1026 * We exhausted the ISP abort retries. We have to
1027 * set the board offline.
1028 */
1029 abts_cnt = 0;
1030 vha->flags.online = 0;
1031 }
1032 }
1033 }
1034
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001035 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1036 RD_REG_DWORD(&reg->hccr);
1037
1038 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1039 RD_REG_DWORD(&reg->hccr);
1040
1041 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1042 RD_REG_DWORD(&reg->hccr);
1043
1044 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1045 for (cnt = 6000000 ; cnt && d2; cnt--) {
1046 udelay(5);
1047 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1048 barrier();
1049 }
1050
1051 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001052
1053 if (IS_NOPOLLING_TYPE(ha))
1054 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001055}
1056
1057/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001058 * qla24xx_reset_chip() - Reset ISP24xx chip.
1059 * @ha: HA context
1060 *
1061 * Returns 0 on success.
1062 */
1063void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001064qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001065{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001066 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001067
1068 if (pci_channel_offline(ha->pdev) &&
1069 ha->flags.pci_channel_io_perm_failure) {
1070 return;
1071 }
1072
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001073 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001074
1075 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001076 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001077}
1078
1079/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 * qla2x00_chip_diag() - Test chip for proper operation.
1081 * @ha: HA context
1082 *
1083 * Returns 0 on success.
1084 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001085int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001086qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087{
1088 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001089 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001090 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 unsigned long flags = 0;
1092 uint16_t data;
1093 uint32_t cnt;
1094 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001095 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 /* Assume a failed state */
1098 rval = QLA_FUNCTION_FAILED;
1099
1100 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001101 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
1103 spin_lock_irqsave(&ha->hardware_lock, flags);
1104
1105 /* Reset ISP chip. */
1106 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1107
1108 /*
1109 * We need to have a delay here since the card will not respond while
1110 * in reset causing an MCA on some architectures.
1111 */
1112 udelay(20);
1113 data = qla2x00_debounce_register(&reg->ctrl_status);
1114 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1115 udelay(5);
1116 data = RD_REG_WORD(&reg->ctrl_status);
1117 barrier();
1118 }
1119
1120 if (!cnt)
1121 goto chip_diag_failed;
1122
1123 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07001124 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125
1126 /* Reset RISC processor. */
1127 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1128 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1129
1130 /* Workaround for QLA2312 PCI parity error */
1131 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1132 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1133 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1134 udelay(5);
1135 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001136 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 }
1138 } else
1139 udelay(10);
1140
1141 if (!cnt)
1142 goto chip_diag_failed;
1143
1144 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -07001145 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
1147 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1148 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1149 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1150 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1151 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1152 mb[3] != PROD_ID_3) {
1153 qla_printk(KERN_WARNING, ha,
1154 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
1155
1156 goto chip_diag_failed;
1157 }
1158 ha->product_id[0] = mb[1];
1159 ha->product_id[1] = mb[2];
1160 ha->product_id[2] = mb[3];
1161 ha->product_id[3] = mb[4];
1162
1163 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001164 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1166 else
1167 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001168 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
1170 if (IS_QLA2200(ha) &&
1171 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1172 /* Limit firmware transfer size with a 2200A */
1173 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001174 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001176 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 ha->fw_transfer_size = 128;
1178 }
1179
1180 /* Wrap Incoming Mailboxes Test. */
1181 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1182
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001183 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
1184 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 if (rval) {
1186 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001187 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 qla_printk(KERN_WARNING, ha,
1189 "Failed mailbox send register test\n");
1190 }
1191 else {
1192 /* Flag a successful rval */
1193 rval = QLA_SUCCESS;
1194 }
1195 spin_lock_irqsave(&ha->hardware_lock, flags);
1196
1197chip_diag_failed:
1198 if (rval)
1199 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001200 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
1202 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1203
1204 return (rval);
1205}
1206
1207/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001208 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1209 * @ha: HA context
1210 *
1211 * Returns 0 on success.
1212 */
1213int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001214qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001215{
1216 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001217 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001218 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001219
Giridhar Malavalia9083012010-04-12 17:59:55 -07001220 if (IS_QLA82XX(ha))
1221 return QLA_SUCCESS;
1222
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001223 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001224
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001225 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001226 if (rval) {
1227 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001228 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001229 qla_printk(KERN_WARNING, ha,
1230 "Failed mailbox send register test\n");
1231 } else {
1232 /* Flag a successful rval */
1233 rval = QLA_SUCCESS;
1234 }
1235
1236 return rval;
1237}
1238
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001239void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001240qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001241{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001242 int rval;
1243 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001244 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001245 dma_addr_t tc_dma;
1246 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001247 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001248 struct req_que *req = ha->req_q_map[0];
1249 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001250
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001251 if (ha->fw_dump) {
1252 qla_printk(KERN_WARNING, ha,
1253 "Firmware dump previously allocated.\n");
1254 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001255 }
1256
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001257 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001258 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001259 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1260 fixed_size = sizeof(struct qla2100_fw_dump);
1261 } else if (IS_QLA23XX(ha)) {
1262 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1263 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1264 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001265 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001266 if (IS_QLA81XX(ha))
1267 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1268 else if (IS_QLA25XX(ha))
1269 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1270 else
1271 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001272 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1273 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001274 if (ha->mqenable)
1275 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001276 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001277 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001278 goto try_eft;
1279
1280 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1281 GFP_KERNEL);
1282 if (!tc) {
1283 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1284 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001285 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001286 }
1287
1288 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001289 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001290 ha->fce_mb, &ha->fce_bufs);
1291 if (rval) {
1292 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1293 "FCE (%d).\n", rval);
1294 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1295 tc_dma);
1296 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001297 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001298 }
1299
1300 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1301 FCE_SIZE / 1024);
1302
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001303 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001304 ha->flags.fce_enabled = 1;
1305 ha->fce_dma = tc_dma;
1306 ha->fce = tc;
1307try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001308 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001309 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001310 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001311 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001312 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1313 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1314 goto cont_alloc;
1315 }
1316
Andrew Vasquezfc447652008-01-17 09:02:18 -08001317 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001318 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001319 if (rval) {
1320 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1321 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001322 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1323 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001324 goto cont_alloc;
1325 }
1326
1327 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1328 EFT_SIZE / 1024);
1329
1330 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001331 ha->eft_dma = tc_dma;
1332 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001333 }
1334cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001335 req_q_size = req->length * sizeof(request_t);
1336 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001337
1338 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001339 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001340 ha->chain_offset = dump_size;
1341 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001342
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001343 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001344 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001345 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001346 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001347
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001348 if (ha->fce) {
1349 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1350 ha->fce_dma);
1351 ha->fce = NULL;
1352 ha->fce_dma = 0;
1353 }
1354
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001355 if (ha->eft) {
1356 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1357 ha->eft_dma);
1358 ha->eft = NULL;
1359 ha->eft_dma = 0;
1360 }
1361 return;
1362 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001363 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1364 dump_size / 1024);
1365
1366 ha->fw_dump_len = dump_size;
1367 ha->fw_dump->signature[0] = 'Q';
1368 ha->fw_dump->signature[1] = 'L';
1369 ha->fw_dump->signature[2] = 'G';
1370 ha->fw_dump->signature[3] = 'C';
1371 ha->fw_dump->version = __constant_htonl(1);
1372
1373 ha->fw_dump->fixed_size = htonl(fixed_size);
1374 ha->fw_dump->mem_size = htonl(mem_size);
1375 ha->fw_dump->req_q_size = htonl(req_q_size);
1376 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1377
1378 ha->fw_dump->eft_size = htonl(eft_size);
1379 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1380 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1381
1382 ha->fw_dump->header_size =
1383 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001384}
1385
Andrew Vasquez18e75552009-06-03 09:55:30 -07001386static int
1387qla81xx_mpi_sync(scsi_qla_host_t *vha)
1388{
1389#define MPS_MASK 0xe0
1390 int rval;
1391 uint16_t dc;
1392 uint32_t dw;
1393 struct qla_hw_data *ha = vha->hw;
1394
1395 if (!IS_QLA81XX(vha->hw))
1396 return QLA_SUCCESS;
1397
1398 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1399 if (rval != QLA_SUCCESS) {
1400 DEBUG2(qla_printk(KERN_WARNING, ha,
1401 "Sync-MPI: Unable to acquire semaphore.\n"));
1402 goto done;
1403 }
1404
1405 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1406 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1407 if (rval != QLA_SUCCESS) {
1408 DEBUG2(qla_printk(KERN_WARNING, ha,
1409 "Sync-MPI: Unable to read sync.\n"));
1410 goto done_release;
1411 }
1412
1413 dc &= MPS_MASK;
1414 if (dc == (dw & MPS_MASK))
1415 goto done_release;
1416
1417 dw &= ~MPS_MASK;
1418 dw |= dc;
1419 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1420 if (rval != QLA_SUCCESS) {
1421 DEBUG2(qla_printk(KERN_WARNING, ha,
1422 "Sync-MPI: Unable to gain sync.\n"));
1423 }
1424
1425done_release:
1426 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1427 if (rval != QLA_SUCCESS) {
1428 DEBUG2(qla_printk(KERN_WARNING, ha,
1429 "Sync-MPI: Unable to release semaphore.\n"));
1430 }
1431
1432done:
1433 return rval;
1434}
1435
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001436/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 * qla2x00_setup_chip() - Load and start RISC firmware.
1438 * @ha: HA context
1439 *
1440 * Returns 0 on success.
1441 */
1442static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001443qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001445 int rval;
1446 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001447 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001448 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1449 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001450 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001451
Giridhar Malavalia9083012010-04-12 17:59:55 -07001452 if (IS_QLA82XX(ha)) {
1453 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001454 if (rval == QLA_SUCCESS) {
1455 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001456 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001457 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001458 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001459 }
1460
Andrew Vasquez3db06522008-01-31 12:33:49 -08001461 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1462 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1463 spin_lock_irqsave(&ha->hardware_lock, flags);
1464 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1465 RD_REG_WORD(&reg->hccr);
1466 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1467 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Andrew Vasquez18e75552009-06-03 09:55:30 -07001469 qla81xx_mpi_sync(vha);
1470
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001472 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001473 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001475 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001477 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 if (rval == QLA_SUCCESS) {
1479 /* Start firmware execution. */
1480 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001481 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001483 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001485 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001486enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001487 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001488 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 &ha->fw_major_version,
1490 &ha->fw_minor_version,
1491 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001492 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001493 ha->mpi_version, &ha->mpi_capabilities,
1494 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001495 if (rval != QLA_SUCCESS)
1496 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001497 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001498 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001499 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001500 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001501 if ((!ha->max_npiv_vports) ||
1502 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001503 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001504 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001505 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001506 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001507 qla2x00_get_resource_cnts(vha, NULL,
1508 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001509 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001510
Giridhar Malavalia9083012010-04-12 17:59:55 -07001511 if (!fw_major_version && ql2xallocfwdump) {
1512 if (!IS_QLA82XX(ha))
1513 qla2x00_alloc_fw_dump(vha);
1514 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 }
1516 } else {
1517 DEBUG2(printk(KERN_INFO
1518 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001519 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 }
1521 }
1522
Andrew Vasquez3db06522008-01-31 12:33:49 -08001523 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1524 /* Enable proper parity. */
1525 spin_lock_irqsave(&ha->hardware_lock, flags);
1526 if (IS_QLA2300(ha))
1527 /* SRAM parity */
1528 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1529 else
1530 /* SRAM, Instruction RAM and GP RAM parity */
1531 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1532 RD_REG_WORD(&reg->hccr);
1533 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1534 }
1535
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001536 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1537 uint32_t size;
1538
1539 rval = qla81xx_fac_get_sector_size(vha, &size);
1540 if (rval == QLA_SUCCESS) {
1541 ha->flags.fac_supported = 1;
1542 ha->fdt_block_size = size << 2;
1543 } else {
1544 qla_printk(KERN_ERR, ha,
1545 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1546 ha->fw_major_version, ha->fw_minor_version,
1547 ha->fw_subminor_version);
1548 }
1549 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001550failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 if (rval) {
1552 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001553 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 }
1555
1556 return (rval);
1557}
1558
1559/**
1560 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1561 * @ha: HA context
1562 *
1563 * Beginning of request ring has initialization control block already built
1564 * by nvram config routine.
1565 *
1566 * Returns 0 on success.
1567 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001568void
1569qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570{
1571 uint16_t cnt;
1572 response_t *pkt;
1573
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001574 rsp->ring_ptr = rsp->ring;
1575 rsp->ring_index = 0;
1576 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001577 pkt = rsp->ring_ptr;
1578 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 pkt->signature = RESPONSE_PROCESSED;
1580 pkt++;
1581 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582}
1583
1584/**
1585 * qla2x00_update_fw_options() - Read and process firmware options.
1586 * @ha: HA context
1587 *
1588 * Returns 0 on success.
1589 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001590void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001591qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592{
1593 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001594 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
1596 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001597 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598
1599 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1600 return;
1601
1602 /* Serial Link options. */
1603 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001604 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1606 sizeof(ha->fw_seriallink_options)));
1607
1608 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1609 if (ha->fw_seriallink_options[3] & BIT_2) {
1610 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1611
1612 /* 1G settings */
1613 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1614 emphasis = (ha->fw_seriallink_options[2] &
1615 (BIT_4 | BIT_3)) >> 3;
1616 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001617 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 rx_sens = (ha->fw_seriallink_options[0] &
1619 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1620 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1621 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1622 if (rx_sens == 0x0)
1623 rx_sens = 0x3;
1624 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1625 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1626 ha->fw_options[10] |= BIT_5 |
1627 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1628 (tx_sens & (BIT_1 | BIT_0));
1629
1630 /* 2G settings */
1631 swing = (ha->fw_seriallink_options[2] &
1632 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1633 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1634 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001635 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 rx_sens = (ha->fw_seriallink_options[1] &
1637 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1638 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1639 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1640 if (rx_sens == 0x0)
1641 rx_sens = 0x3;
1642 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1643 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1644 ha->fw_options[11] |= BIT_5 |
1645 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1646 (tx_sens & (BIT_1 | BIT_0));
1647 }
1648
1649 /* FCP2 options. */
1650 /* Return command IOCBs without waiting for an ABTS to complete. */
1651 ha->fw_options[3] |= BIT_13;
1652
1653 /* LED scheme. */
1654 if (ha->flags.enable_led_scheme)
1655 ha->fw_options[2] |= BIT_12;
1656
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001657 /* Detect ISP6312. */
1658 if (IS_QLA6312(ha))
1659 ha->fw_options[2] |= BIT_13;
1660
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001662 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663}
1664
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001665void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001666qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001667{
1668 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001669 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001670
Giridhar Malavalia9083012010-04-12 17:59:55 -07001671 if (IS_QLA82XX(ha))
1672 return;
1673
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001674 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001675 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001676 return;
1677
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001678 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001679 le16_to_cpu(ha->fw_seriallink_options24[1]),
1680 le16_to_cpu(ha->fw_seriallink_options24[2]),
1681 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001682 if (rval != QLA_SUCCESS) {
1683 qla_printk(KERN_WARNING, ha,
1684 "Unable to update Serial Link options (%x).\n", rval);
1685 }
1686}
1687
1688void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001689qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001690{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001691 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001692 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001693 struct req_que *req = ha->req_q_map[0];
1694 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001695
1696 /* Setup ring parameters in initialization control block. */
1697 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1698 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001699 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1700 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1701 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1702 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1703 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1704 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001705
1706 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1707 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1708 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1709 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1710 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1711}
1712
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001713void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001714qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001715{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001716 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001717 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1718 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1719 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001720 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001721 uint16_t rid = 0;
1722 struct req_que *req = ha->req_q_map[0];
1723 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001724
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001725/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001726 icb = (struct init_cb_24xx *)ha->init_cb;
1727 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1728 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001729 icb->request_q_length = cpu_to_le16(req->length);
1730 icb->response_q_length = cpu_to_le16(rsp->length);
1731 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1732 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1733 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1734 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001735
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001736 if (ha->mqenable) {
1737 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1738 icb->rid = __constant_cpu_to_le16(rid);
1739 if (ha->flags.msix_enabled) {
1740 msix = &ha->msix_entries[1];
1741 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001742 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001743 icb->msix = cpu_to_le16(msix->entry);
1744 }
1745 /* Use alternate PCI bus number */
1746 if (MSB(rid))
1747 icb->firmware_options_2 |=
1748 __constant_cpu_to_le32(BIT_19);
1749 /* Use alternate PCI devfn */
1750 if (LSB(rid))
1751 icb->firmware_options_2 |=
1752 __constant_cpu_to_le32(BIT_18);
1753
Anirban Chakraborty31557542009-12-02 10:36:55 -08001754 /* Use Disable MSIX Handshake mode for capable adapters */
1755 if (IS_MSIX_NACK_CAPABLE(ha)) {
1756 icb->firmware_options_2 &=
1757 __constant_cpu_to_le32(~BIT_22);
1758 ha->flags.disable_msix_handshake = 1;
1759 qla_printk(KERN_INFO, ha,
1760 "MSIX Handshake Disable Mode turned on\n");
1761 } else {
1762 icb->firmware_options_2 |=
1763 __constant_cpu_to_le32(BIT_22);
1764 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001765 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001766
1767 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1768 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1769 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1770 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1771 } else {
1772 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1773 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1774 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1775 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1776 }
1777 /* PCI posting */
1778 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001779}
1780
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781/**
1782 * qla2x00_init_rings() - Initializes firmware.
1783 * @ha: HA context
1784 *
1785 * Beginning of request ring has initialization control block already built
1786 * by nvram config routine.
1787 *
1788 * Returns 0 on success.
1789 */
1790static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001791qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792{
1793 int rval;
1794 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001795 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001796 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001797 struct req_que *req;
1798 struct rsp_que *rsp;
1799 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001800 struct mid_init_cb_24xx *mid_init_cb =
1801 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802
1803 spin_lock_irqsave(&ha->hardware_lock, flags);
1804
1805 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001806 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001807 req = ha->req_q_map[que];
1808 if (!req)
1809 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001810 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001811 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001813 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001814
1815 /* Initialize firmware. */
1816 req->ring_ptr = req->ring;
1817 req->ring_index = 0;
1818 req->cnt = req->length;
1819 }
1820
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001821 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001822 rsp = ha->rsp_q_map[que];
1823 if (!rsp)
1824 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001825 /* Initialize response queue entries */
1826 qla2x00_init_response_q_entries(rsp);
1827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
Dan Carpenter542bce12010-10-15 11:27:38 -07001829 spin_lock(&ha->vport_slock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001831 list_for_each_entry(vp, &ha->vp_list, list) {
1832 vp->rscn_in_ptr = 0;
1833 vp->rscn_out_ptr = 0;
1834 }
Arun Easifeafb7b2010-09-03 14:57:00 -07001835
Dan Carpenter542bce12010-10-15 11:27:38 -07001836 spin_unlock(&ha->vport_slock);
Arun Easifeafb7b2010-09-03 14:57:00 -07001837
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001838 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839
1840 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1841
1842 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001843 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001845 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001846
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001847 if (ha->flags.npiv_supported) {
1848 if (ha->operating_mode == LOOP)
1849 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001850 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001851 }
1852
Andrew Vasquez24a08132009-03-24 09:08:16 -07001853 if (IS_FWI2_CAPABLE(ha)) {
1854 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1855 mid_init_cb->init_cb.execution_throttle =
1856 cpu_to_le16(ha->fw_xcb_count);
1857 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001858
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001859 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 if (rval) {
1861 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001862 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 } else {
1864 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001865 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 }
1867
1868 return (rval);
1869}
1870
1871/**
1872 * qla2x00_fw_ready() - Waits for firmware ready.
1873 * @ha: HA context
1874 *
1875 * Returns 0 on success.
1876 */
1877static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001878qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879{
1880 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001881 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 uint16_t min_wait; /* Minimum wait time if loop is down */
1883 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001884 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001885 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
1887 rval = QLA_SUCCESS;
1888
1889 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001890 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891
1892 /*
1893 * Firmware should take at most one RATOV to login, plus 5 seconds for
1894 * our own processing.
1895 */
1896 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1897 wait_time = min_wait;
1898 }
1899
1900 /* Min wait time if loop down */
1901 mtime = jiffies + (min_wait * HZ);
1902
1903 /* wait time before firmware ready */
1904 wtime = jiffies + (wait_time * HZ);
1905
1906 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001907 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1909
1910 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001911 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
1913 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001914 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001916 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001917 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001919 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1920 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001921 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001922 state[2]));
1923 if ((state[2] & FSTATE_LOGGED_IN) &&
1924 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1925 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001926 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001927
1928 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001929 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001930 if (rval != QLA_SUCCESS)
1931 break;
1932
1933 /* Add time taken to initialize. */
1934 cs84xx_time = jiffies - cs84xx_time;
1935 wtime += cs84xx_time;
1936 mtime += cs84xx_time;
1937 DEBUG16(printk("scsi(%ld): Increasing "
1938 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001939 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001940 }
1941 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001943 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001945 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 &ha->login_timeout, &ha->r_a_tov);
1947
1948 rval = QLA_SUCCESS;
1949 break;
1950 }
1951
1952 rval = QLA_FUNCTION_FAILED;
1953
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001954 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001955 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001957 * other than Wait for Login.
1958 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 if (time_after_eq(jiffies, mtime)) {
1960 qla_printk(KERN_INFO, ha,
1961 "Cable is unplugged...\n");
1962
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001963 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 break;
1965 }
1966 }
1967 } else {
1968 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07001969 if (time_after_eq(jiffies, mtime) ||
1970 (IS_QLA82XX(ha) && ha->flags.fw_hung))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 break;
1972 }
1973
1974 if (time_after_eq(jiffies, wtime))
1975 break;
1976
1977 /* Delay for a while */
1978 msleep(500);
1979
1980 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001981 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 } while (1);
1983
Andrew Vasquez656e8912009-06-03 09:55:29 -07001984 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1985 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1986 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987
1988 if (rval) {
1989 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001990 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 }
1992
1993 return (rval);
1994}
1995
1996/*
1997* qla2x00_configure_hba
1998* Setup adapter context.
1999*
2000* Input:
2001* ha = adapter state pointer.
2002*
2003* Returns:
2004* 0 = success
2005*
2006* Context:
2007* Kernel context.
2008*/
2009static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002010qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011{
2012 int rval;
2013 uint16_t loop_id;
2014 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002015 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 uint8_t al_pa;
2017 uint8_t area;
2018 uint8_t domain;
2019 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002020 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021
2022 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002023 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002024 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002026 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002027 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
2028 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002029 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08002030 } else {
2031 qla_printk(KERN_WARNING, ha,
2032 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002033 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002034 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 return (rval);
2036 }
2037
2038 if (topo == 4) {
2039 qla_printk(KERN_INFO, ha,
2040 "Cannot get topology - retrying.\n");
2041 return (QLA_FUNCTION_FAILED);
2042 }
2043
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002044 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
2046 /* initialize */
2047 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2048 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002049 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
2051 switch (topo) {
2052 case 0:
2053 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002054 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 ha->current_topology = ISP_CFG_NL;
2056 strcpy(connect_type, "(Loop)");
2057 break;
2058
2059 case 1:
2060 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002061 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002062 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 ha->current_topology = ISP_CFG_FL;
2064 strcpy(connect_type, "(FL_Port)");
2065 break;
2066
2067 case 2:
2068 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002069 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 ha->operating_mode = P2P;
2071 ha->current_topology = ISP_CFG_N;
2072 strcpy(connect_type, "(N_Port-to-N_Port)");
2073 break;
2074
2075 case 3:
2076 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002077 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002078 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 ha->operating_mode = P2P;
2080 ha->current_topology = ISP_CFG_F;
2081 strcpy(connect_type, "(F_Port)");
2082 break;
2083
2084 default:
2085 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
2086 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002087 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 ha->current_topology = ISP_CFG_NL;
2089 strcpy(connect_type, "(Loop)");
2090 break;
2091 }
2092
2093 /* Save Host port and loop ID. */
2094 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002095 vha->d_id.b.domain = domain;
2096 vha->d_id.b.area = area;
2097 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002099 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 qla_printk(KERN_INFO, ha,
2101 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002102 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103
2104 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002105 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002107 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 }
2109
2110 return(rval);
2111}
2112
Giridhar Malavalia9083012010-04-12 17:59:55 -07002113inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002114qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2115 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002116{
2117 char *st, *en;
2118 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002119 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002120 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavalia9083012010-04-12 17:59:55 -07002121 !IS_QLA8XXX_TYPE(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002122
2123 if (memcmp(model, BINZERO, len) != 0) {
2124 strncpy(ha->model_number, model, len);
2125 st = en = ha->model_number;
2126 en += len - 1;
2127 while (en > st) {
2128 if (*en != 0x20 && *en != 0x00)
2129 break;
2130 *en-- = '\0';
2131 }
2132
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)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002137 strncpy(ha->model_desc,
2138 qla2x00_model_name[index * 2 + 1],
2139 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002140 } else {
2141 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002142 if (use_tbl &&
2143 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002144 index < QLA_MODEL_NAMES) {
2145 strcpy(ha->model_number,
2146 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002147 strncpy(ha->model_desc,
2148 qla2x00_model_name[index * 2 + 1],
2149 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002150 } else {
2151 strcpy(ha->model_number, def);
2152 }
2153 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002154 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002155 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002156 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002157}
2158
David Miller4e08df32007-04-16 12:37:43 -07002159/* On sparc systems, obtain port and node WWN from firmware
2160 * properties.
2161 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002162static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002163{
2164#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002165 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002166 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002167 struct device_node *dp = pci_device_to_OF_node(pdev);
2168 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002169 int len;
2170
2171 val = of_get_property(dp, "port-wwn", &len);
2172 if (val && len >= WWN_SIZE)
2173 memcpy(nv->port_name, val, WWN_SIZE);
2174
2175 val = of_get_property(dp, "node-wwn", &len);
2176 if (val && len >= WWN_SIZE)
2177 memcpy(nv->node_name, val, WWN_SIZE);
2178#endif
2179}
2180
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181/*
2182* NVRAM configuration for ISP 2xxx
2183*
2184* Input:
2185* ha = adapter block pointer.
2186*
2187* Output:
2188* initialization control block in response_ring
2189* host adapters parameters in host adapter block
2190*
2191* Returns:
2192* 0 = success.
2193*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002194int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002195qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196{
David Miller4e08df32007-04-16 12:37:43 -07002197 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002198 uint8_t chksum = 0;
2199 uint16_t cnt;
2200 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002201 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002202 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002203 nvram_t *nv = ha->nvram;
2204 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002205 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206
David Miller4e08df32007-04-16 12:37:43 -07002207 rval = QLA_SUCCESS;
2208
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002210 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 ha->nvram_base = 0;
2212 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2213 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2214 ha->nvram_base = 0x80;
2215
2216 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002217 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002218 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2219 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002221 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07002222 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223
2224 /* Bad NVRAM data, set defaults parameters. */
2225 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2226 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2227 /* Reset NVRAM data. */
2228 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
2229 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
2230 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07002231 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
2232 "invalid -- WWPN) defaults.\n");
2233
2234 /*
2235 * Set default initialization control block.
2236 */
2237 memset(nv, 0, ha->nvram_size);
2238 nv->parameter_block_version = ICB_VERSION;
2239
2240 if (IS_QLA23XX(ha)) {
2241 nv->firmware_options[0] = BIT_2 | BIT_1;
2242 nv->firmware_options[1] = BIT_7 | BIT_5;
2243 nv->add_firmware_options[0] = BIT_5;
2244 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2245 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2246 nv->special_options[1] = BIT_7;
2247 } else if (IS_QLA2200(ha)) {
2248 nv->firmware_options[0] = BIT_2 | BIT_1;
2249 nv->firmware_options[1] = BIT_7 | BIT_5;
2250 nv->add_firmware_options[0] = BIT_5;
2251 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2252 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2253 } else if (IS_QLA2100(ha)) {
2254 nv->firmware_options[0] = BIT_3 | BIT_1;
2255 nv->firmware_options[1] = BIT_5;
2256 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2257 }
2258
2259 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2260 nv->execution_throttle = __constant_cpu_to_le16(16);
2261 nv->retry_count = 8;
2262 nv->retry_delay = 1;
2263
2264 nv->port_name[0] = 33;
2265 nv->port_name[3] = 224;
2266 nv->port_name[4] = 139;
2267
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002268 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002269
2270 nv->login_timeout = 4;
2271
2272 /*
2273 * Set default host adapter parameters
2274 */
2275 nv->host_p[1] = BIT_2;
2276 nv->reset_delay = 5;
2277 nv->port_down_retry_count = 8;
2278 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2279 nv->link_down_timeout = 60;
2280
2281 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 }
2283
2284#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2285 /*
2286 * The SN2 does not provide BIOS emulation which means you can't change
2287 * potentially bogus BIOS settings. Force the use of default settings
2288 * for link rate and frame size. Hope that the rest of the settings
2289 * are valid.
2290 */
2291 if (ia64_platform_is("sn2")) {
2292 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2293 if (IS_QLA23XX(ha))
2294 nv->special_options[1] = BIT_7;
2295 }
2296#endif
2297
2298 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002299 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300
2301 /*
2302 * Setup driver NVRAM options.
2303 */
2304 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2305 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2306 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2307 nv->firmware_options[1] &= ~BIT_4;
2308
2309 if (IS_QLA23XX(ha)) {
2310 nv->firmware_options[0] |= BIT_2;
2311 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002312 nv->firmware_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002313 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314
2315 if (IS_QLA2300(ha)) {
2316 if (ha->fb_rev == FPM_2310) {
2317 strcpy(ha->model_number, "QLA2310");
2318 } else {
2319 strcpy(ha->model_number, "QLA2300");
2320 }
2321 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002322 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002323 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 }
2325 } else if (IS_QLA2200(ha)) {
2326 nv->firmware_options[0] |= BIT_2;
2327 /*
2328 * 'Point-to-point preferred, else loop' is not a safe
2329 * connection mode setting.
2330 */
2331 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2332 (BIT_5 | BIT_4)) {
2333 /* Force 'loop preferred, else point-to-point'. */
2334 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2335 nv->add_firmware_options[0] |= BIT_5;
2336 }
2337 strcpy(ha->model_number, "QLA22xx");
2338 } else /*if (IS_QLA2100(ha))*/ {
2339 strcpy(ha->model_number, "QLA2100");
2340 }
2341
2342 /*
2343 * Copy over NVRAM RISC parameter block to initialization control block.
2344 */
2345 dptr1 = (uint8_t *)icb;
2346 dptr2 = (uint8_t *)&nv->parameter_block_version;
2347 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2348 while (cnt--)
2349 *dptr1++ = *dptr2++;
2350
2351 /* Copy 2nd half. */
2352 dptr1 = (uint8_t *)icb->add_firmware_options;
2353 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2354 while (cnt--)
2355 *dptr1++ = *dptr2++;
2356
Andrew Vasquez5341e862006-05-17 15:09:16 -07002357 /* Use alternate WWN? */
2358 if (nv->host_p[1] & BIT_7) {
2359 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2360 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2361 }
2362
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 /* Prepare nodename */
2364 if ((icb->firmware_options[1] & BIT_6) == 0) {
2365 /*
2366 * Firmware will apply the following mask if the nodename was
2367 * not provided.
2368 */
2369 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2370 icb->node_name[0] &= 0xF0;
2371 }
2372
2373 /*
2374 * Set host adapter parameters.
2375 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002376 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002377 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2379 /* Always load RISC code on non ISP2[12]00 chips. */
2380 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2381 ha->flags.disable_risc_code_load = 0;
2382 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2383 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2384 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002385 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002386 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387
2388 ha->operating_mode =
2389 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2390
2391 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2392 sizeof(ha->fw_seriallink_options));
2393
2394 /* save HBA serial number */
2395 ha->serial0 = icb->port_name[5];
2396 ha->serial1 = icb->port_name[6];
2397 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002398 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2399 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400
2401 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2402
2403 ha->retry_count = nv->retry_count;
2404
2405 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002406 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 nv->login_timeout = ql2xlogintimeout;
2408 if (nv->login_timeout < 4)
2409 nv->login_timeout = 4;
2410 ha->login_timeout = nv->login_timeout;
2411 icb->login_timeout = nv->login_timeout;
2412
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002413 /* Set minimum RATOV to 100 tenths of a second. */
2414 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 ha->loop_reset_delay = nv->reset_delay;
2417
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 /* Link Down Timeout = 0:
2419 *
2420 * When Port Down timer expires we will start returning
2421 * I/O's to OS with "DID_NO_CONNECT".
2422 *
2423 * Link Down Timeout != 0:
2424 *
2425 * The driver waits for the link to come up after link down
2426 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002427 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 if (nv->link_down_timeout == 0) {
2429 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002430 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 } else {
2432 ha->link_down_timeout = nv->link_down_timeout;
2433 ha->loop_down_abort_time =
2434 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 /*
2438 * Need enough time to try and get the port back.
2439 */
2440 ha->port_down_retry_count = nv->port_down_retry_count;
2441 if (qlport_down_retry)
2442 ha->port_down_retry_count = qlport_down_retry;
2443 /* Set login_retry_count */
2444 ha->login_retry_count = nv->retry_count;
2445 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2446 ha->port_down_retry_count > 3)
2447 ha->login_retry_count = ha->port_down_retry_count;
2448 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2449 ha->login_retry_count = ha->port_down_retry_count;
2450 if (ql2xloginretrycount)
2451 ha->login_retry_count = ql2xloginretrycount;
2452
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 icb->lun_enables = __constant_cpu_to_le16(0);
2454 icb->command_resource_count = 0;
2455 icb->immediate_notify_resource_count = 0;
2456 icb->timeout = __constant_cpu_to_le16(0);
2457
2458 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2459 /* Enable RIO */
2460 icb->firmware_options[0] &= ~BIT_3;
2461 icb->add_firmware_options[0] &=
2462 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2463 icb->add_firmware_options[0] |= BIT_2;
2464 icb->response_accumulation_timer = 3;
2465 icb->interrupt_delay_timer = 5;
2466
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002467 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002469 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002470 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002471 ha->zio_mode = icb->add_firmware_options[0] &
2472 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2473 ha->zio_timer = icb->interrupt_delay_timer ?
2474 icb->interrupt_delay_timer: 2;
2475 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 icb->add_firmware_options[0] &=
2477 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002478 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002479 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002480 ha->zio_mode = QLA_ZIO_MODE_6;
2481
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002482 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002483 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002484 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002486 "ZIO mode %d enabled; timer delay (%d us).\n",
2487 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002489 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2490 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002491 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 }
2493 }
2494
David Miller4e08df32007-04-16 12:37:43 -07002495 if (rval) {
2496 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002497 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07002498 }
2499 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500}
2501
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002502static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002503qla2x00_rport_del(void *data)
2504{
2505 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002506 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002507
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002508 spin_lock_irq(fcport->vha->host->host_lock);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002509 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002510 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002511 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002512 if (rport)
2513 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002514}
2515
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516/**
2517 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2518 * @ha: HA context
2519 * @flags: allocation flags
2520 *
2521 * Returns a pointer to the allocated fcport, or NULL, if none available.
2522 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002523fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002524qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525{
2526 fc_port_t *fcport;
2527
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002528 fcport = kzalloc(sizeof(fc_port_t), flags);
2529 if (!fcport)
2530 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531
2532 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002533 fcport->vha = vha;
2534 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 fcport->port_type = FCT_UNKNOWN;
2536 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002538 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002540 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541}
2542
2543/*
2544 * qla2x00_configure_loop
2545 * Updates Fibre Channel Device Database with what is actually on loop.
2546 *
2547 * Input:
2548 * ha = adapter block pointer.
2549 *
2550 * Returns:
2551 * 0 = success.
2552 * 1 = error.
2553 * 2 = database was full and device was not configured.
2554 */
2555static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002556qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557{
2558 int rval;
2559 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002560 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 rval = QLA_SUCCESS;
2562
2563 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002564 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2565 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 if (rval != QLA_SUCCESS) {
2567 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002568 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 return (rval);
2570 }
2571 }
2572
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002573 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002575 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576
2577 /*
2578 * If we have both an RSCN and PORT UPDATE pending then handle them
2579 * both at the same time.
2580 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002581 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2582 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583
Michael Hernandez3064ff32009-12-15 21:29:44 -08002584 qla2x00_get_data_rate(vha);
2585
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 /* Determine what we need to do */
2587 if (ha->current_topology == ISP_CFG_FL &&
2588 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2589
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002590 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 set_bit(RSCN_UPDATE, &flags);
2592
2593 } else if (ha->current_topology == ISP_CFG_F &&
2594 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2595
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002596 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 set_bit(RSCN_UPDATE, &flags);
2598 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2599
Andrew Vasquez21333b42006-05-17 15:09:56 -07002600 } else if (ha->current_topology == ISP_CFG_N) {
2601 clear_bit(RSCN_UPDATE, &flags);
2602
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002603 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2605
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002606 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 set_bit(RSCN_UPDATE, &flags);
2608 set_bit(LOCAL_LOOP_UPDATE, &flags);
2609 }
2610
2611 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002612 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002614 else
2615 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 }
2617
2618 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002619 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002621 else
2622 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 }
2624
2625 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002626 if (atomic_read(&vha->loop_down_timer) ||
2627 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 rval = QLA_FUNCTION_FAILED;
2629 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002630 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002632 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 }
2634 }
2635
2636 if (rval) {
2637 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002638 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 } else {
2640 DEBUG3(printk("%s: exiting normally\n", __func__));
2641 }
2642
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002643 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002644 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002646 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002647 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002648 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07002649 if (!IS_ALOGIO_CAPABLE(ha))
2650 vha->flags.rscn_queue_overflow = 1;
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002651 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 }
2653
2654 return (rval);
2655}
2656
2657
2658
2659/*
2660 * qla2x00_configure_local_loop
2661 * Updates Fibre Channel Device Database with local loop devices.
2662 *
2663 * Input:
2664 * ha = adapter block pointer.
2665 *
2666 * Returns:
2667 * 0 = success.
2668 */
2669static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002670qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671{
2672 int rval, rval2;
2673 int found_devs;
2674 int found;
2675 fc_port_t *fcport, *new_fcport;
2676
2677 uint16_t index;
2678 uint16_t entries;
2679 char *id_iter;
2680 uint16_t loop_id;
2681 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002682 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683
2684 found_devs = 0;
2685 new_fcport = NULL;
2686 entries = MAX_FIBRE_DEVICES;
2687
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002688 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2689 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690
2691 /* Get list of logged in devices. */
2692 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002693 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 &entries);
2695 if (rval != QLA_SUCCESS)
2696 goto cleanup_allocation;
2697
2698 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002699 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2701 entries * sizeof(struct gid_list_info)));
2702
2703 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002704 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 if (new_fcport == NULL) {
2706 rval = QLA_MEMORY_ALLOC_FAILED;
2707 goto cleanup_allocation;
2708 }
2709 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2710
2711 /*
2712 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2713 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002714 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2716 fcport->port_type != FCT_BROADCAST &&
2717 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2718
2719 DEBUG(printk("scsi(%ld): Marking port lost, "
2720 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002721 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
2723 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 }
2725 }
2726
2727 /* Add devices to port list. */
2728 id_iter = (char *)ha->gid_list;
2729 for (index = 0; index < entries; index++) {
2730 domain = ((struct gid_list_info *)id_iter)->domain;
2731 area = ((struct gid_list_info *)id_iter)->area;
2732 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002733 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 loop_id = (uint16_t)
2735 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002736 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 loop_id = le16_to_cpu(
2738 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002739 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740
2741 /* Bypass reserved domain fields. */
2742 if ((domain & 0xf0) == 0xf0)
2743 continue;
2744
2745 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002746 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002747 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 continue;
2749
2750 /* Bypass invalid local loop ID. */
2751 if (loop_id > LAST_LOCAL_LOOP_ID)
2752 continue;
2753
2754 /* Fill in member data. */
2755 new_fcport->d_id.b.domain = domain;
2756 new_fcport->d_id.b.area = area;
2757 new_fcport->d_id.b.al_pa = al_pa;
2758 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002759 new_fcport->vp_idx = vha->vp_idx;
2760 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 if (rval2 != QLA_SUCCESS) {
2762 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2763 "information -- get_port_database=%x, "
2764 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002765 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002766 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002767 vha->host_no));
2768 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 continue;
2770 }
2771
2772 /* Check for matching device in port list. */
2773 found = 0;
2774 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002775 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 if (memcmp(new_fcport->port_name, fcport->port_name,
2777 WWN_SIZE))
2778 continue;
2779
Shyam Sundarddb9b122009-03-24 09:08:10 -07002780 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 fcport->loop_id = new_fcport->loop_id;
2782 fcport->port_type = new_fcport->port_type;
2783 fcport->d_id.b24 = new_fcport->d_id.b24;
2784 memcpy(fcport->node_name, new_fcport->node_name,
2785 WWN_SIZE);
2786
2787 found++;
2788 break;
2789 }
2790
2791 if (!found) {
2792 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002793 if (vha->vp_idx) {
2794 new_fcport->vha = vha;
2795 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002796 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002797 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798
2799 /* Allocate a new replacement fcport. */
2800 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002801 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 if (new_fcport == NULL) {
2803 rval = QLA_MEMORY_ALLOC_FAILED;
2804 goto cleanup_allocation;
2805 }
2806 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2807 }
2808
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002809 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002810 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002811
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002812 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813
2814 found_devs++;
2815 }
2816
2817cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002818 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819
2820 if (rval != QLA_SUCCESS) {
2821 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002822 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 }
2824
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 return (rval);
2826}
2827
2828static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002829qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002830{
2831#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002832 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2833 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002834 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002835 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002836 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002837
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002838 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002839 return;
2840
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07002841 if (atomic_read(&fcport->state) != FCS_ONLINE)
2842 return;
2843
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002844 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2845 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002846 return;
2847
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002848 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002849 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002850 if (rval != QLA_SUCCESS) {
2851 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2852 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002853 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002854 fcport->port_name[2], fcport->port_name[3],
2855 fcport->port_name[4], fcport->port_name[5],
2856 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002857 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002858 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002859 link_speed = link_speeds[LS_UNKNOWN];
2860 if (fcport->fp_speed < 5)
2861 link_speed = link_speeds[fcport->fp_speed];
2862 else if (fcport->fp_speed == 0x13)
2863 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002864 DEBUG2(qla_printk(KERN_INFO, ha,
2865 "iIDMA adjusted to %s GB/s on "
2866 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002867 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002868 fcport->port_name[1], fcport->port_name[2],
2869 fcport->port_name[3], fcport->port_name[4],
2870 fcport->port_name[5], fcport->port_name[6],
2871 fcport->port_name[7]));
2872 }
2873}
2874
Adrian Bunk23be3312006-11-24 02:46:01 +01002875static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002876qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002877{
2878 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002879 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002880 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002881
Andrew Vasquezac280b62009-08-20 11:06:05 -07002882 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002883
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002884 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2885 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002886 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2887 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2888 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002889 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002890 if (!rport) {
2891 qla_printk(KERN_WARNING, ha,
2892 "Unable to allocate fc remote port!\n");
2893 return;
2894 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002895 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002896 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002897 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002898
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002899 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002900
2901 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002902 if (fcport->port_type == FCT_INITIATOR)
2903 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2904 if (fcport->port_type == FCT_TARGET)
2905 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002906 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002907}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908
2909/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002910 * qla2x00_update_fcport
2911 * Updates device on list.
2912 *
2913 * Input:
2914 * ha = adapter block pointer.
2915 * fcport = port structure pointer.
2916 *
2917 * Return:
2918 * 0 - Success
2919 * BIT_0 - error
2920 *
2921 * Context:
2922 * Kernel context.
2923 */
2924void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002925qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002926{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002927 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002928 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002929 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01002930
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002931 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08002932 qla24xx_update_fcport_fcp_prio(vha, fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002933 qla2x00_reg_remote_port(vha, fcport);
Giridhar Malavali38170fa2010-10-15 11:27:49 -07002934 atomic_set(&fcport->state, FCS_ONLINE);
Adrian Bunk23be3312006-11-24 02:46:01 +01002935}
2936
2937/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 * qla2x00_configure_fabric
2939 * Setup SNS devices with loop ID's.
2940 *
2941 * Input:
2942 * ha = adapter block pointer.
2943 *
2944 * Returns:
2945 * 0 = success.
2946 * BIT_0 = error
2947 */
2948static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002949qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950{
2951 int rval, rval2;
2952 fc_port_t *fcport, *fcptemp;
2953 uint16_t next_loopid;
2954 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002955 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002957 struct qla_hw_data *ha = vha->hw;
2958 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959
2960 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002961 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002962 loop_id = NPH_F_PORT;
2963 else
2964 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002965 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 if (rval != QLA_SUCCESS) {
2967 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002968 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002970 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 return (QLA_SUCCESS);
2972 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002973 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974
2975 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002976 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 if (rval2 == QLA_RSCNS_HANDLED) {
2978 /* No point doing the scan, just continue. */
2979 return (QLA_SUCCESS);
2980 }
2981 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002982 /* FDMI support. */
2983 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002984 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2985 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002986
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002988 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002989 loop_id = NPH_SNS;
2990 else
2991 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002992 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002993 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 if (mb[0] != MBS_COMMAND_COMPLETE) {
2995 DEBUG2(qla_printk(KERN_INFO, ha,
2996 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002997 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 mb[0], mb[1], mb[2], mb[6], mb[7]));
2999 return (QLA_SUCCESS);
3000 }
3001
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003002 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3003 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 /* EMPTY */
3005 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003006 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003008 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 /* EMPTY */
3010 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003011 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003013 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 /* EMPTY */
3015 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003016 "failed.\n", vha->host_no));
3017 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 /* EMPTY */
3019 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003020 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 }
3022 }
3023
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003024 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 if (rval != QLA_SUCCESS)
3026 break;
3027
3028 /*
3029 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003030 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003032 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3033 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 break;
3035
3036 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3037 continue;
3038
3039 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003040 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003041 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003043 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 fcport->port_type != FCT_INITIATOR &&
3045 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003046 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003047 fcport->loop_id,
3048 fcport->d_id.b.domain,
3049 fcport->d_id.b.area,
3050 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 fcport->loop_id = FC_NO_LOOP_ID;
3052 }
3053 }
3054 }
3055
3056 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003057 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058
3059 /*
3060 * Scan through our port list and login entries that need to be
3061 * logged in.
3062 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003063 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3064 if (atomic_read(&vha->loop_down_timer) ||
3065 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 break;
3067
3068 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3069 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3070 continue;
3071
3072 if (fcport->loop_id == FC_NO_LOOP_ID) {
3073 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07003074 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003075 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 if (rval != QLA_SUCCESS) {
3077 /* Ran out of IDs to use */
3078 break;
3079 }
3080 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003082 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 }
3084
3085 /* Exit if out of loop IDs. */
3086 if (rval != QLA_SUCCESS) {
3087 break;
3088 }
3089
3090 /*
3091 * Login and add the new devices to our port list.
3092 */
3093 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003094 if (atomic_read(&vha->loop_down_timer) ||
3095 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 break;
3097
3098 /* Find a new loop ID to use. */
3099 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003100 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 if (rval != QLA_SUCCESS) {
3102 /* Ran out of IDs to use */
3103 break;
3104 }
3105
bdf79622005-04-17 15:06:53 -05003106 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003107 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003108
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003109 if (vha->vp_idx) {
3110 fcport->vha = vha;
3111 fcport->vp_idx = vha->vp_idx;
3112 }
3113 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 }
3115 } while (0);
3116
3117 /* Free all new device structures not processed. */
3118 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3119 list_del(&fcport->list);
3120 kfree(fcport);
3121 }
3122
3123 if (rval) {
3124 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003125 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 }
3127
3128 return (rval);
3129}
3130
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131/*
3132 * qla2x00_find_all_fabric_devs
3133 *
3134 * Input:
3135 * ha = adapter block pointer.
3136 * dev = database device entry pointer.
3137 *
3138 * Returns:
3139 * 0 = success.
3140 *
3141 * Context:
3142 * Kernel context.
3143 */
3144static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003145qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3146 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147{
3148 int rval;
3149 uint16_t loop_id;
3150 fc_port_t *fcport, *new_fcport, *fcptemp;
3151 int found;
3152
3153 sw_info_t *swl;
3154 int swl_idx;
3155 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003156 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003157 struct qla_hw_data *ha = vha->hw;
3158 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003159 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160
3161 rval = QLA_SUCCESS;
3162
3163 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07003164 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003165 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 /*EMPTY*/
3167 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003168 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003170 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 kfree(swl);
3172 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003173 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 kfree(swl);
3175 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003176 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 kfree(swl);
3178 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003179 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003180 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3181 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003183
3184 /* If other queries succeeded probe for FC-4 type */
3185 if (swl)
3186 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 }
3188 swl_idx = 0;
3189
3190 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003191 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003193 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 return (QLA_MEMORY_ALLOC_FAILED);
3195 }
3196 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 /* Set start port ID scan at adapter ID. */
3198 first_dev = 1;
3199 last_dev = 0;
3200
3201 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003202 loop_id = ha->min_external_loopid;
3203 for (; loop_id <= ha->max_loop_id; loop_id++) {
3204 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 continue;
3206
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003207 if (ha->current_topology == ISP_CFG_FL &&
3208 (atomic_read(&vha->loop_down_timer) ||
3209 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003210 atomic_set(&vha->loop_down_timer, 0);
3211 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3212 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215
3216 if (swl != NULL) {
3217 if (last_dev) {
3218 wrap.b24 = new_fcport->d_id.b24;
3219 } else {
3220 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3221 memcpy(new_fcport->node_name,
3222 swl[swl_idx].node_name, WWN_SIZE);
3223 memcpy(new_fcport->port_name,
3224 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003225 memcpy(new_fcport->fabric_port_name,
3226 swl[swl_idx].fabric_port_name, WWN_SIZE);
3227 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003228 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229
3230 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3231 last_dev = 1;
3232 }
3233 swl_idx++;
3234 }
3235 } else {
3236 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003237 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 if (rval != QLA_SUCCESS) {
3239 qla_printk(KERN_WARNING, ha,
3240 "SNS scan failed -- assuming zero-entry "
3241 "result...\n");
3242 list_for_each_entry_safe(fcport, fcptemp,
3243 new_fcports, list) {
3244 list_del(&fcport->list);
3245 kfree(fcport);
3246 }
3247 rval = QLA_SUCCESS;
3248 break;
3249 }
3250 }
3251
3252 /* If wrap on switch device list, exit. */
3253 if (first_dev) {
3254 wrap.b24 = new_fcport->d_id.b24;
3255 first_dev = 0;
3256 } else if (new_fcport->d_id.b24 == wrap.b24) {
3257 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003258 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
3260 break;
3261 }
3262
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003263 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003264 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 continue;
3266
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003267 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003268 found = 0;
3269 if (ha->num_vhosts) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003270 unsigned long flags;
3271
3272 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003273 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003274 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3275 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003276 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003277 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003278 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003279 spin_unlock_irqrestore(&ha->vport_slock, flags);
3280
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003281 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003282 continue;
3283 }
3284
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003285 /* Bypass if same domain and area of adapter. */
3286 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003287 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003288 ISP_CFG_FL)
3289 continue;
3290
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 /* Bypass reserved domain fields. */
3292 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3293 continue;
3294
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003295 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003296 if (ql2xgffidenable &&
3297 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3298 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003299 continue;
3300
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 /* Locate matching device in database. */
3302 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003303 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 if (memcmp(new_fcport->port_name, fcport->port_name,
3305 WWN_SIZE))
3306 continue;
3307
3308 found++;
3309
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003310 /* Update port state. */
3311 memcpy(fcport->fabric_port_name,
3312 new_fcport->fabric_port_name, WWN_SIZE);
3313 fcport->fp_speed = new_fcport->fp_speed;
3314
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 /*
3316 * If address the same and state FCS_ONLINE, nothing
3317 * changed.
3318 */
3319 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3320 atomic_read(&fcport->state) == FCS_ONLINE) {
3321 break;
3322 }
3323
3324 /*
3325 * If device was not a fabric device before.
3326 */
3327 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3328 fcport->d_id.b24 = new_fcport->d_id.b24;
3329 fcport->loop_id = FC_NO_LOOP_ID;
3330 fcport->flags |= (FCF_FABRIC_DEVICE |
3331 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 break;
3333 }
3334
3335 /*
3336 * Port ID changed or device was marked to be updated;
3337 * Log it out if still logged in and mark it for
3338 * relogin later.
3339 */
3340 fcport->d_id.b24 = new_fcport->d_id.b24;
3341 fcport->flags |= FCF_LOGIN_NEEDED;
3342 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003343 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 fcport->port_type != FCT_INITIATOR &&
3345 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003346 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003347 fcport->d_id.b.domain, fcport->d_id.b.area,
3348 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 fcport->loop_id = FC_NO_LOOP_ID;
3350 }
3351
3352 break;
3353 }
3354
3355 if (found)
3356 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 /* If device was not in our fcports list, then add it. */
3358 list_add_tail(&new_fcport->list, new_fcports);
3359
3360 /* Allocate a new replacement fcport. */
3361 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003362 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003364 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 return (QLA_MEMORY_ALLOC_FAILED);
3366 }
3367 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3368 new_fcport->d_id.b24 = nxt_d_id.b24;
3369 }
3370
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003371 kfree(swl);
3372 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 return (rval);
3375}
3376
3377/*
3378 * qla2x00_find_new_loop_id
3379 * Scan through our port list and find a new usable loop ID.
3380 *
3381 * Input:
3382 * ha: adapter state pointer.
3383 * dev: port structure pointer.
3384 *
3385 * Returns:
3386 * qla2x00 local function return status code.
3387 *
3388 * Context:
3389 * Kernel context.
3390 */
Adrian Bunk413975a2006-06-30 02:33:06 -07003391static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003392qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393{
3394 int rval;
3395 int found;
3396 fc_port_t *fcport;
3397 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003398 struct qla_hw_data *ha = vha->hw;
3399 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003400 struct scsi_qla_host *tvp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003401 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402
3403 rval = QLA_SUCCESS;
3404
3405 /* Save starting loop ID. */
3406 first_loop_id = dev->loop_id;
3407
3408 for (;;) {
3409 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003410 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412
3413 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003414 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416
3417 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419 /* first loop ID. */
3420 dev->loop_id = ha->min_external_loopid;
3421 }
3422
3423 /* Check for loop ID being already in use. */
3424 found = 0;
3425 fcport = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003426
3427 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003428 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003429 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3430 if (fcport->loop_id == dev->loop_id &&
3431 fcport != dev) {
3432 /* ID possibly in use */
3433 found++;
3434 break;
3435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003437 if (found)
3438 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003440 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441
3442 /* If not in use then it is free to use. */
3443 if (!found) {
3444 break;
3445 }
3446
3447 /* ID in use. Try next value. */
3448 dev->loop_id++;
3449
3450 /* If wrap around. No free ID to use. */
3451 if (dev->loop_id == first_loop_id) {
3452 dev->loop_id = FC_NO_LOOP_ID;
3453 rval = QLA_FUNCTION_FAILED;
3454 break;
3455 }
3456 }
3457
3458 return (rval);
3459}
3460
3461/*
3462 * qla2x00_device_resync
3463 * Marks devices in the database that needs resynchronization.
3464 *
3465 * Input:
3466 * ha = adapter block pointer.
3467 *
3468 * Context:
3469 * Kernel context.
3470 */
3471static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003472qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473{
3474 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 uint32_t mask;
3476 fc_port_t *fcport;
3477 uint32_t rscn_entry;
3478 uint8_t rscn_out_iter;
3479 uint8_t format;
Mike Waychison1516ef42010-05-04 15:01:31 -07003480 port_id_t d_id = {};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481
3482 rval = QLA_RSCNS_HANDLED;
3483
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003484 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3485 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003487 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 format = MSB(MSW(rscn_entry));
3489 d_id.b.domain = LSB(MSW(rscn_entry));
3490 d_id.b.area = MSB(LSW(rscn_entry));
3491 d_id.b.al_pa = LSB(LSW(rscn_entry));
3492
3493 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3494 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003495 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496 d_id.b.area, d_id.b.al_pa));
3497
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003498 vha->rscn_out_ptr++;
3499 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3500 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501
3502 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003503 for (rscn_out_iter = vha->rscn_out_ptr;
3504 !vha->flags.rscn_queue_overflow &&
3505 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 rscn_out_iter = (rscn_out_iter ==
3507 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3508
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003509 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 break;
3511
3512 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003513 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 rscn_out_iter));
3515
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003516 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517 }
3518
3519 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003520 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003522 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523
3524 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003525 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 }
3527
3528 switch (format) {
3529 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 mask = 0xffffff;
3531 break;
3532 case 1:
3533 mask = 0xffff00;
3534 break;
3535 case 2:
3536 mask = 0xff0000;
3537 break;
3538 default:
3539 mask = 0x0;
3540 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003541 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 break;
3543 }
3544
3545 rval = QLA_SUCCESS;
3546
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003547 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3549 (fcport->d_id.b24 & mask) != d_id.b24 ||
3550 fcport->port_type == FCT_BROADCAST)
3551 continue;
3552
3553 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3554 if (format != 3 ||
3555 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003556 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003557 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558 }
3559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560 }
3561 }
3562 return (rval);
3563}
3564
3565/*
3566 * qla2x00_fabric_dev_login
3567 * Login fabric target device and update FC port database.
3568 *
3569 * Input:
3570 * ha: adapter state pointer.
3571 * fcport: port structure list pointer.
3572 * next_loopid: contains value of a new loop ID that can be used
3573 * by the next login attempt.
3574 *
3575 * Returns:
3576 * qla2x00 local function return status code.
3577 *
3578 * Context:
3579 * Kernel context.
3580 */
3581static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003582qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583 uint16_t *next_loopid)
3584{
3585 int rval;
3586 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003587 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003588 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589
3590 rval = QLA_SUCCESS;
3591 retry = 0;
3592
Andrew Vasquezac280b62009-08-20 11:06:05 -07003593 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003594 if (fcport->flags & FCF_ASYNC_SENT)
3595 return rval;
3596 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003597 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3598 if (!rval)
3599 return rval;
3600 }
3601
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003602 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003603 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003605 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003606 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003607 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003608 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003609 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003611 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003612 fcport->d_id.b.domain, fcport->d_id.b.area,
3613 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003614 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003616 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 }
3618 }
3619
3620 return (rval);
3621}
3622
3623/*
3624 * qla2x00_fabric_login
3625 * Issue fabric login command.
3626 *
3627 * Input:
3628 * ha = adapter block pointer.
3629 * device = pointer to FC device type structure.
3630 *
3631 * Returns:
3632 * 0 - Login successfully
3633 * 1 - Login failed
3634 * 2 - Initiator device
3635 * 3 - Fatal error
3636 */
3637int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003638qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639 uint16_t *next_loopid)
3640{
3641 int rval;
3642 int retry;
3643 uint16_t tmp_loopid;
3644 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003645 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646
3647 retry = 0;
3648 tmp_loopid = 0;
3649
3650 for (;;) {
3651 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3652 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003653 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3655
3656 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003657 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658 fcport->d_id.b.domain, fcport->d_id.b.area,
3659 fcport->d_id.b.al_pa, mb, BIT_0);
3660 if (mb[0] == MBS_PORT_ID_USED) {
3661 /*
3662 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003663 * recommends the driver perform an implicit login with
3664 * the specified ID again. The ID we just used is save
3665 * here so we return with an ID that can be tried by
3666 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667 */
3668 retry++;
3669 tmp_loopid = fcport->loop_id;
3670 fcport->loop_id = mb[1];
3671
3672 DEBUG(printk("Fabric Login: port in use - next "
3673 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3674 fcport->loop_id, fcport->d_id.b.domain,
3675 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3676
3677 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3678 /*
3679 * Login succeeded.
3680 */
3681 if (retry) {
3682 /* A retry occurred before. */
3683 *next_loopid = tmp_loopid;
3684 } else {
3685 /*
3686 * No retry occurred before. Just increment the
3687 * ID value for next login.
3688 */
3689 *next_loopid = (fcport->loop_id + 1);
3690 }
3691
3692 if (mb[1] & BIT_0) {
3693 fcport->port_type = FCT_INITIATOR;
3694 } else {
3695 fcport->port_type = FCT_TARGET;
3696 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003697 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 }
3699 }
3700
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003701 if (mb[10] & BIT_0)
3702 fcport->supported_classes |= FC_COS_CLASS2;
3703 if (mb[10] & BIT_1)
3704 fcport->supported_classes |= FC_COS_CLASS3;
3705
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706 rval = QLA_SUCCESS;
3707 break;
3708 } else if (mb[0] == MBS_LOOP_ID_USED) {
3709 /*
3710 * Loop ID already used, try next loop ID.
3711 */
3712 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003713 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 if (rval != QLA_SUCCESS) {
3715 /* Ran out of loop IDs to use */
3716 break;
3717 }
3718 } else if (mb[0] == MBS_COMMAND_ERROR) {
3719 /*
3720 * Firmware possibly timed out during login. If NO
3721 * retries are left to do then the device is declared
3722 * dead.
3723 */
3724 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003725 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003726 fcport->d_id.b.domain, fcport->d_id.b.area,
3727 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003728 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729
3730 rval = 1;
3731 break;
3732 } else {
3733 /*
3734 * unrecoverable / not handled error
3735 */
3736 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003737 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003738 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 fcport->d_id.b.domain, fcport->d_id.b.area,
3740 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3741
3742 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003743 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003744 fcport->d_id.b.domain, fcport->d_id.b.area,
3745 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003747 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748
3749 rval = 3;
3750 break;
3751 }
3752 }
3753
3754 return (rval);
3755}
3756
3757/*
3758 * qla2x00_local_device_login
3759 * Issue local device login command.
3760 *
3761 * Input:
3762 * ha = adapter block pointer.
3763 * loop_id = loop id of device to login to.
3764 *
3765 * Returns (Where's the #define!!!!):
3766 * 0 - Login successfully
3767 * 1 - Login failed
3768 * 3 - Fatal error
3769 */
3770int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003771qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772{
3773 int rval;
3774 uint16_t mb[MAILBOX_REGISTER_COUNT];
3775
3776 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003777 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778 if (rval == QLA_SUCCESS) {
3779 /* Interrogate mailbox registers for any errors */
3780 if (mb[0] == MBS_COMMAND_ERROR)
3781 rval = 1;
3782 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3783 /* device not in PCB table */
3784 rval = 3;
3785 }
3786
3787 return (rval);
3788}
3789
3790/*
3791 * qla2x00_loop_resync
3792 * Resync with fibre channel devices.
3793 *
3794 * Input:
3795 * ha = adapter block pointer.
3796 *
3797 * Returns:
3798 * 0 = success
3799 */
3800int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003801qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003803 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003805 struct req_que *req;
3806 struct rsp_que *rsp;
3807
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003808 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003809 req = vha->hw->req_q_map[0];
3810 else
3811 req = vha->req;
3812 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003814 atomic_set(&vha->loop_state, LOOP_UPDATE);
3815 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3816 if (vha->flags.online) {
3817 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3819 wait_time = 256;
3820 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003821 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003823 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003824 qla2x00_marker(vha, req, rsp, 0, 0,
3825 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003826 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827
3828 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003829 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003831 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003833 } while (!atomic_read(&vha->loop_down_timer) &&
3834 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3835 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3836 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 }
3839
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003840 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003843 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845
3846 return (rval);
3847}
3848
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003849/*
3850* qla2x00_perform_loop_resync
3851* Description: This function will set the appropriate flags and call
3852* qla2x00_loop_resync. If successful loop will be resynced
3853* Arguments : scsi_qla_host_t pointer
3854* returm : Success or Failure
3855*/
3856
3857int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
3858{
3859 int32_t rval = 0;
3860
3861 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
3862 /*Configure the flags so that resync happens properly*/
3863 atomic_set(&ha->loop_down_timer, 0);
3864 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3865 atomic_set(&ha->loop_state, LOOP_UP);
3866 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
3867 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
3868 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3869
3870 rval = qla2x00_loop_resync(ha);
3871 } else
3872 atomic_set(&ha->loop_state, LOOP_DEAD);
3873
3874 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3875 }
3876
3877 return rval;
3878}
3879
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003881qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003882{
3883 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07003884 struct scsi_qla_host *vha;
3885 struct qla_hw_data *ha = base_vha->hw;
3886 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003887
Arun Easifeafb7b2010-09-03 14:57:00 -07003888 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003889 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07003890 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
3891 atomic_inc(&vha->vref_count);
3892 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08003893 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07003894 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
3895 spin_unlock_irqrestore(&ha->vport_slock, flags);
3896
Andrew Vasquez67becc02009-08-25 11:36:20 -07003897 qla2x00_rport_del(fcport);
Arun Easifeafb7b2010-09-03 14:57:00 -07003898
3899 spin_lock_irqsave(&ha->vport_slock, flags);
3900 }
3901 }
3902 atomic_dec(&vha->vref_count);
3903 }
3904 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003905}
3906
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003907/*
3908* qla82xx_quiescent_state_cleanup
3909* Description: This function will block the new I/Os
3910* Its not aborting any I/Os as context
3911* is not destroyed during quiescence
3912* Arguments: scsi_qla_host_t
3913* return : void
3914*/
3915void
3916qla82xx_quiescent_state_cleanup(scsi_qla_host_t *vha)
3917{
3918 struct qla_hw_data *ha = vha->hw;
3919 struct scsi_qla_host *vp;
3920
3921 qla_printk(KERN_INFO, ha,
3922 "Performing ISP error recovery - ha= %p.\n", ha);
3923
3924 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3925 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3926 atomic_set(&vha->loop_state, LOOP_DOWN);
3927 qla2x00_mark_all_devices_lost(vha, 0);
3928 list_for_each_entry(vp, &ha->vp_list, list)
3929 qla2x00_mark_all_devices_lost(vha, 0);
3930 } else {
3931 if (!atomic_read(&vha->loop_down_timer))
3932 atomic_set(&vha->loop_down_timer,
3933 LOOP_DOWN_TIME);
3934 }
3935 /* Wait for pending cmds to complete */
3936 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
3937}
3938
Giridhar Malavalia9083012010-04-12 17:59:55 -07003939void
3940qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3941{
3942 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003943 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003944 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003945
3946 vha->flags.online = 0;
3947 ha->flags.chip_reset_done = 0;
3948 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3949 ha->qla_stats.total_isp_aborts++;
3950
3951 qla_printk(KERN_INFO, ha,
3952 "Performing ISP error recovery - ha= %p.\n", ha);
3953
3954 /* Chip reset does not apply to 82XX */
3955 if (!IS_QLA82XX(ha))
3956 ha->isp_ops->reset_chip(vha);
3957
3958 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3959 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3960 atomic_set(&vha->loop_state, LOOP_DOWN);
3961 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07003962
3963 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003964 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003965 atomic_inc(&vp->vref_count);
3966 spin_unlock_irqrestore(&ha->vport_slock, flags);
3967
Giridhar Malavalia9083012010-04-12 17:59:55 -07003968 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07003969
3970 spin_lock_irqsave(&ha->vport_slock, flags);
3971 atomic_dec(&vp->vref_count);
3972 }
3973 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003974 } else {
3975 if (!atomic_read(&vha->loop_down_timer))
3976 atomic_set(&vha->loop_down_timer,
3977 LOOP_DOWN_TIME);
3978 }
3979
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07003980 if (!ha->flags.eeh_busy) {
3981 /* Make sure for ISP 82XX IO DMA is complete */
3982 if (IS_QLA82XX(ha)) {
3983 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0,
3984 WAIT_HOST) == QLA_SUCCESS) {
3985 DEBUG2(qla_printk(KERN_INFO, ha,
3986 "Done wait for pending commands\n"));
3987 }
Giridhar Malavali4d78c972010-07-23 15:28:35 +05003988 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07003989
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07003990 /* Requeue all commands in outstanding command list. */
3991 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3992 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07003993}
3994
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995/*
3996* qla2x00_abort_isp
3997* Resets ISP and aborts all outstanding commands.
3998*
3999* Input:
4000* ha = adapter block pointer.
4001*
4002* Returns:
4003* 0 = success
4004*/
4005int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004006qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007{
Andrew Vasquez476e8972006-08-23 14:54:55 -07004008 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004010 struct qla_hw_data *ha = vha->hw;
4011 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004012 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07004013 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004015 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004016 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017
Andrew Vasquez85880802009-12-15 21:29:46 -08004018 if (unlikely(pci_channel_offline(ha->pdev) &&
4019 ha->flags.pci_channel_io_perm_failure)) {
4020 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4021 status = 0;
4022 return status;
4023 }
4024
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004025 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08004026
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004027 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004028
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004029 if (!qla2x00_restart_isp(vha)) {
4030 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004032 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 /*
4034 * Issue marker command only when we are going
4035 * to start the I/O .
4036 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004037 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 }
4039
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004040 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004042 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004044 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004045 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07004046
Lalit Chandivade29c53972009-10-13 15:16:47 -07004047 if (IS_QLA81XX(ha))
4048 qla2x00_get_fw_version(vha,
4049 &ha->fw_major_version,
4050 &ha->fw_minor_version,
4051 &ha->fw_subminor_version,
4052 &ha->fw_attributes, &ha->fw_memory_size,
4053 ha->mpi_version, &ha->mpi_capabilities,
4054 ha->phy_version);
4055
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004056 if (ha->fce) {
4057 ha->flags.fce_enabled = 1;
4058 memset(ha->fce, 0,
4059 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004060 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004061 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4062 &ha->fce_bufs);
4063 if (rval) {
4064 qla_printk(KERN_WARNING, ha,
4065 "Unable to reinitialize FCE "
4066 "(%d).\n", rval);
4067 ha->flags.fce_enabled = 0;
4068 }
4069 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004070
4071 if (ha->eft) {
4072 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004073 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004074 ha->eft_dma, EFT_NUM_BUFFERS);
4075 if (rval) {
4076 qla_printk(KERN_WARNING, ha,
4077 "Unable to reinitialize EFT "
4078 "(%d).\n", rval);
4079 }
4080 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004082 vha->flags.online = 1;
4083 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084 if (ha->isp_abort_cnt == 0) {
4085 qla_printk(KERN_WARNING, ha,
4086 "ISP error recovery failed - "
4087 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004088 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 * The next call disables the board
4090 * completely.
4091 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004092 ha->isp_ops->reset_adapter(vha);
4093 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004095 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004096 status = 0;
4097 } else { /* schedule another ISP abort */
4098 ha->isp_abort_cnt--;
4099 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004100 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004101 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102 status = 1;
4103 }
4104 } else {
4105 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
4106 DEBUG(printk("qla2x00(%ld): ISP error recovery "
4107 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004108 vha->host_no, ha->isp_abort_cnt));
4109 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110 status = 1;
4111 }
4112 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004113
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114 }
4115
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004116 if (!status) {
4117 DEBUG(printk(KERN_INFO
4118 "qla2x00_abort_isp(%ld): succeeded.\n",
4119 vha->host_no));
Arun Easifeafb7b2010-09-03 14:57:00 -07004120
4121 spin_lock_irqsave(&ha->vport_slock, flags);
4122 list_for_each_entry(vp, &ha->vp_list, list) {
4123 if (vp->vp_idx) {
4124 atomic_inc(&vp->vref_count);
4125 spin_unlock_irqrestore(&ha->vport_slock, flags);
4126
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004127 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004128
4129 spin_lock_irqsave(&ha->vport_slock, flags);
4130 atomic_dec(&vp->vref_count);
4131 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004132 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004133 spin_unlock_irqrestore(&ha->vport_slock, flags);
4134
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004135 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 qla_printk(KERN_INFO, ha,
4137 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 }
4139
4140 return(status);
4141}
4142
4143/*
4144* qla2x00_restart_isp
4145* restarts the ISP after a reset
4146*
4147* Input:
4148* ha = adapter block pointer.
4149*
4150* Returns:
4151* 0 = success
4152*/
4153static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004154qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004156 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004158 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004159 struct req_que *req = ha->req_q_map[0];
4160 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161
4162 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004163 if (qla2x00_isp_firmware(vha)) {
4164 vha->flags.online = 0;
4165 status = ha->isp_ops->chip_diag(vha);
4166 if (!status)
4167 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168 }
4169
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004170 if (!status && !(status = qla2x00_init_rings(vha))) {
4171 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004172 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004173 /* Initialize the queues in use */
4174 qla25xx_init_queues(ha);
4175
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004176 status = qla2x00_fw_ready(vha);
4177 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004179 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004180
4181 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004182 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004183
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004184 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4186 wait_time = 256;
4187 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004188 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4189 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004191 } while (!atomic_read(&vha->loop_down_timer) &&
4192 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4193 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4194 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195 }
4196
4197 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004198 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199 status = 0;
4200
4201 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4202 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004203 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004204 }
4205 return (status);
4206}
4207
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004208static int
4209qla25xx_init_queues(struct qla_hw_data *ha)
4210{
4211 struct rsp_que *rsp = NULL;
4212 struct req_que *req = NULL;
4213 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4214 int ret = -1;
4215 int i;
4216
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004217 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004218 rsp = ha->rsp_q_map[i];
4219 if (rsp) {
4220 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004221 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004222 if (ret != QLA_SUCCESS)
4223 DEBUG2_17(printk(KERN_WARNING
4224 "%s Rsp que:%d init failed\n", __func__,
4225 rsp->id));
4226 else
4227 DEBUG2_17(printk(KERN_INFO
4228 "%s Rsp que:%d inited\n", __func__,
4229 rsp->id));
4230 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004231 }
4232 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004233 req = ha->req_q_map[i];
4234 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004235 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004236 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004237 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004238 if (ret != QLA_SUCCESS)
4239 DEBUG2_17(printk(KERN_WARNING
4240 "%s Req que:%d init failed\n", __func__,
4241 req->id));
4242 else
4243 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004244 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004245 req->id));
4246 }
4247 }
4248 return ret;
4249}
4250
Linus Torvalds1da177e2005-04-16 15:20:36 -07004251/*
4252* qla2x00_reset_adapter
4253* Reset adapter.
4254*
4255* Input:
4256* ha = adapter block pointer.
4257*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004258void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004259qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260{
4261 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004262 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004263 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004265 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004266 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268 spin_lock_irqsave(&ha->hardware_lock, flags);
4269 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4270 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4271 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4272 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4273 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4274}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004275
4276void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004277qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004278{
4279 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004280 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004281 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4282
Giridhar Malavalia9083012010-04-12 17:59:55 -07004283 if (IS_QLA82XX(ha))
4284 return;
4285
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004286 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004287 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004288
4289 spin_lock_irqsave(&ha->hardware_lock, flags);
4290 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4291 RD_REG_DWORD(&reg->hccr);
4292 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4293 RD_REG_DWORD(&reg->hccr);
4294 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004295
4296 if (IS_NOPOLLING_TYPE(ha))
4297 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004298}
4299
David Miller4e08df32007-04-16 12:37:43 -07004300/* On sparc systems, obtain port and node WWN from firmware
4301 * properties.
4302 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004303static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4304 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004305{
4306#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004307 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004308 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004309 struct device_node *dp = pci_device_to_OF_node(pdev);
4310 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004311 int len;
4312
4313 val = of_get_property(dp, "port-wwn", &len);
4314 if (val && len >= WWN_SIZE)
4315 memcpy(nv->port_name, val, WWN_SIZE);
4316
4317 val = of_get_property(dp, "node-wwn", &len);
4318 if (val && len >= WWN_SIZE)
4319 memcpy(nv->node_name, val, WWN_SIZE);
4320#endif
4321}
4322
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004323int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004324qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004325{
David Miller4e08df32007-04-16 12:37:43 -07004326 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004327 struct init_cb_24xx *icb;
4328 struct nvram_24xx *nv;
4329 uint32_t *dptr;
4330 uint8_t *dptr1, *dptr2;
4331 uint32_t chksum;
4332 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004333 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004334
David Miller4e08df32007-04-16 12:37:43 -07004335 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004336 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004337 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004338
4339 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004340 if (ha->flags.port0) {
4341 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4342 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4343 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004344 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004345 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4346 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004347 ha->nvram_size = sizeof(struct nvram_24xx);
4348 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004349 if (IS_QLA82XX(ha))
4350 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004351
Seokmann Ju281afe12007-07-26 13:43:34 -07004352 /* Get VPD data into cache */
4353 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004354 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004355 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4356
4357 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004358 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004359 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004360 ha->nvram_size);
4361 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4362 chksum += le32_to_cpu(*dptr++);
4363
Andrew Vasquez76403352009-04-06 22:33:39 -07004364 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07004365 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004366
4367 /* Bad NVRAM data, set defaults parameters. */
4368 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4369 || nv->id[3] != ' ' ||
4370 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4371 /* Reset NVRAM data. */
4372 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4373 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4374 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07004375 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4376 "invalid -- WWPN) defaults.\n");
4377
4378 /*
4379 * Set default initialization control block.
4380 */
4381 memset(nv, 0, ha->nvram_size);
4382 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4383 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4384 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4385 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4386 nv->exchange_count = __constant_cpu_to_le16(0);
4387 nv->hard_address = __constant_cpu_to_le16(124);
4388 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004389 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004390 nv->port_name[2] = 0x00;
4391 nv->port_name[3] = 0xe0;
4392 nv->port_name[4] = 0x8b;
4393 nv->port_name[5] = 0x1c;
4394 nv->port_name[6] = 0x55;
4395 nv->port_name[7] = 0x86;
4396 nv->node_name[0] = 0x20;
4397 nv->node_name[1] = 0x00;
4398 nv->node_name[2] = 0x00;
4399 nv->node_name[3] = 0xe0;
4400 nv->node_name[4] = 0x8b;
4401 nv->node_name[5] = 0x1c;
4402 nv->node_name[6] = 0x55;
4403 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004404 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004405 nv->login_retry_count = __constant_cpu_to_le16(8);
4406 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4407 nv->login_timeout = __constant_cpu_to_le16(0);
4408 nv->firmware_options_1 =
4409 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4410 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4411 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4412 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4413 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4414 nv->efi_parameters = __constant_cpu_to_le32(0);
4415 nv->reset_delay = 5;
4416 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4417 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4418 nv->link_down_timeout = __constant_cpu_to_le16(30);
4419
4420 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004421 }
4422
4423 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004424 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004425
4426 /* Copy 1st segment. */
4427 dptr1 = (uint8_t *)icb;
4428 dptr2 = (uint8_t *)&nv->version;
4429 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4430 while (cnt--)
4431 *dptr1++ = *dptr2++;
4432
4433 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004434 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004435
4436 /* Copy 2nd segment. */
4437 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4438 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4439 cnt = (uint8_t *)&icb->reserved_3 -
4440 (uint8_t *)&icb->interrupt_delay_timer;
4441 while (cnt--)
4442 *dptr1++ = *dptr2++;
4443
4444 /*
4445 * Setup driver NVRAM options.
4446 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004447 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004448 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004449
Andrew Vasquez5341e862006-05-17 15:09:16 -07004450 /* Use alternate WWN? */
4451 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4452 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4453 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4454 }
4455
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004456 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004457 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004458 /*
4459 * Firmware will apply the following mask if the nodename was
4460 * not provided.
4461 */
4462 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4463 icb->node_name[0] &= 0xF0;
4464 }
4465
4466 /* Set host adapter parameters. */
4467 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004468 ha->flags.enable_lip_reset = 0;
4469 ha->flags.enable_lip_full_login =
4470 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4471 ha->flags.enable_target_reset =
4472 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004473 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004474 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004475
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004476 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4477 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004478
4479 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4480 sizeof(ha->fw_seriallink_options24));
4481
4482 /* save HBA serial number */
4483 ha->serial0 = icb->port_name[5];
4484 ha->serial1 = icb->port_name[6];
4485 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004486 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4487 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004488
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004489 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4490
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004491 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4492
4493 /* Set minimum login_timeout to 4 seconds. */
4494 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4495 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4496 if (le16_to_cpu(nv->login_timeout) < 4)
4497 nv->login_timeout = __constant_cpu_to_le16(4);
4498 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004499 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004500
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004501 /* Set minimum RATOV to 100 tenths of a second. */
4502 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004503
4504 ha->loop_reset_delay = nv->reset_delay;
4505
4506 /* Link Down Timeout = 0:
4507 *
4508 * When Port Down timer expires we will start returning
4509 * I/O's to OS with "DID_NO_CONNECT".
4510 *
4511 * Link Down Timeout != 0:
4512 *
4513 * The driver waits for the link to come up after link down
4514 * before returning I/Os to OS with "DID_NO_CONNECT".
4515 */
4516 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4517 ha->loop_down_abort_time =
4518 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4519 } else {
4520 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4521 ha->loop_down_abort_time =
4522 (LOOP_DOWN_TIME - ha->link_down_timeout);
4523 }
4524
4525 /* Need enough time to try and get the port back. */
4526 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4527 if (qlport_down_retry)
4528 ha->port_down_retry_count = qlport_down_retry;
4529
4530 /* Set login_retry_count */
4531 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4532 if (ha->port_down_retry_count ==
4533 le16_to_cpu(nv->port_down_retry_count) &&
4534 ha->port_down_retry_count > 3)
4535 ha->login_retry_count = ha->port_down_retry_count;
4536 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4537 ha->login_retry_count = ha->port_down_retry_count;
4538 if (ql2xloginretrycount)
4539 ha->login_retry_count = ql2xloginretrycount;
4540
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004541 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004542 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004543 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4544 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4545 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4546 le16_to_cpu(icb->interrupt_delay_timer): 2;
4547 }
4548 icb->firmware_options_2 &= __constant_cpu_to_le32(
4549 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004550 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004551 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004552 ha->zio_mode = QLA_ZIO_MODE_6;
4553
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004554 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004555 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004556 ha->zio_timer * 100));
4557 qla_printk(KERN_INFO, ha,
4558 "ZIO mode %d enabled; timer delay (%d us).\n",
4559 ha->zio_mode, ha->zio_timer * 100);
4560
4561 icb->firmware_options_2 |= cpu_to_le32(
4562 (uint32_t)ha->zio_mode);
4563 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004564 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004565 }
4566
David Miller4e08df32007-04-16 12:37:43 -07004567 if (rval) {
4568 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004569 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004570 }
4571 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004572}
4573
Adrian Bunk413975a2006-06-30 02:33:06 -07004574static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004575qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4576 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004577{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004578 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004579 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004580 uint32_t *dcode, dlen;
4581 uint32_t risc_addr;
4582 uint32_t risc_size;
4583 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004584 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004585 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004586
4587 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004588 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004589
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004590 rval = QLA_SUCCESS;
4591
4592 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004593 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004594 *srisc_addr = 0;
4595
4596 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004597 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004598 for (i = 0; i < 4; i++)
4599 dcode[i] = be32_to_cpu(dcode[i]);
4600 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4601 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4602 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4603 dcode[3] == 0)) {
4604 qla_printk(KERN_WARNING, ha,
4605 "Unable to verify integrity of flash firmware image!\n");
4606 qla_printk(KERN_WARNING, ha,
4607 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4608 dcode[1], dcode[2], dcode[3]);
4609
4610 return QLA_FUNCTION_FAILED;
4611 }
4612
4613 while (segments && rval == QLA_SUCCESS) {
4614 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004615 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004616
4617 risc_addr = be32_to_cpu(dcode[2]);
4618 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4619 risc_size = be32_to_cpu(dcode[3]);
4620
4621 fragment = 0;
4622 while (risc_size > 0 && rval == QLA_SUCCESS) {
4623 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4624 if (dlen > risc_size)
4625 dlen = risc_size;
4626
4627 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4628 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004629 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004630
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004631 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004632 for (i = 0; i < dlen; i++)
4633 dcode[i] = swab32(dcode[i]);
4634
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004635 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004636 dlen);
4637 if (rval) {
4638 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004639 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004640 fragment));
4641 qla_printk(KERN_WARNING, ha,
4642 "[ERROR] Failed to load segment %d of "
4643 "firmware\n", fragment);
4644 break;
4645 }
4646
4647 faddr += dlen;
4648 risc_addr += dlen;
4649 risc_size -= dlen;
4650 fragment++;
4651 }
4652
4653 /* Next segment. */
4654 segments--;
4655 }
4656
4657 return rval;
4658}
4659
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004660#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4661
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004662int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004663qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004664{
4665 int rval;
4666 int i, fragment;
4667 uint16_t *wcode, *fwcode;
4668 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4669 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004670 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004671 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004672
4673 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004674 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004675 if (!blob) {
4676 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004677 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4678 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004679 return QLA_FUNCTION_FAILED;
4680 }
4681
4682 rval = QLA_SUCCESS;
4683
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004684 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004685 *srisc_addr = 0;
4686 fwcode = (uint16_t *)blob->fw->data;
4687 fwclen = 0;
4688
4689 /* Validate firmware image by checking version. */
4690 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4691 qla_printk(KERN_WARNING, ha,
4692 "Unable to verify integrity of firmware image (%Zd)!\n",
4693 blob->fw->size);
4694 goto fail_fw_integrity;
4695 }
4696 for (i = 0; i < 4; i++)
4697 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4698 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4699 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4700 wcode[2] == 0 && wcode[3] == 0)) {
4701 qla_printk(KERN_WARNING, ha,
4702 "Unable to verify integrity of firmware image!\n");
4703 qla_printk(KERN_WARNING, ha,
4704 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4705 wcode[1], wcode[2], wcode[3]);
4706 goto fail_fw_integrity;
4707 }
4708
4709 seg = blob->segs;
4710 while (*seg && rval == QLA_SUCCESS) {
4711 risc_addr = *seg;
4712 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4713 risc_size = be16_to_cpu(fwcode[3]);
4714
4715 /* Validate firmware image size. */
4716 fwclen += risc_size * sizeof(uint16_t);
4717 if (blob->fw->size < fwclen) {
4718 qla_printk(KERN_WARNING, ha,
4719 "Unable to verify integrity of firmware image "
4720 "(%Zd)!\n", blob->fw->size);
4721 goto fail_fw_integrity;
4722 }
4723
4724 fragment = 0;
4725 while (risc_size > 0 && rval == QLA_SUCCESS) {
4726 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4727 if (wlen > risc_size)
4728 wlen = risc_size;
4729
4730 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004731 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004732 risc_addr, wlen));
4733
4734 for (i = 0; i < wlen; i++)
4735 wcode[i] = swab16(fwcode[i]);
4736
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004737 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004738 wlen);
4739 if (rval) {
4740 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004741 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004742 fragment));
4743 qla_printk(KERN_WARNING, ha,
4744 "[ERROR] Failed to load segment %d of "
4745 "firmware\n", fragment);
4746 break;
4747 }
4748
4749 fwcode += wlen;
4750 risc_addr += wlen;
4751 risc_size -= wlen;
4752 fragment++;
4753 }
4754
4755 /* Next segment. */
4756 seg++;
4757 }
4758 return rval;
4759
4760fail_fw_integrity:
4761 return QLA_FUNCTION_FAILED;
4762}
4763
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004764static int
4765qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004766{
4767 int rval;
4768 int segments, fragment;
4769 uint32_t *dcode, dlen;
4770 uint32_t risc_addr;
4771 uint32_t risc_size;
4772 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004773 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004774 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004775 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004776 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004777
Andrew Vasquez54333832005-11-09 15:49:04 -08004778 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004779 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004780 if (!blob) {
4781 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004782 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4783 "from: " QLA_FW_URL ".\n");
4784
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004785 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004786 }
4787
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004788 qla_printk(KERN_INFO, ha,
4789 "FW: Loading via request-firmware...\n");
4790
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004791 rval = QLA_SUCCESS;
4792
4793 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004794 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004795 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004796 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004797 fwclen = 0;
4798
4799 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004800 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004801 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004802 "Unable to verify integrity of firmware image (%Zd)!\n",
4803 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004804 goto fail_fw_integrity;
4805 }
4806 for (i = 0; i < 4; i++)
4807 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4808 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4809 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4810 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4811 dcode[3] == 0)) {
4812 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004813 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004814 qla_printk(KERN_WARNING, ha,
4815 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4816 dcode[1], dcode[2], dcode[3]);
4817 goto fail_fw_integrity;
4818 }
4819
4820 while (segments && rval == QLA_SUCCESS) {
4821 risc_addr = be32_to_cpu(fwcode[2]);
4822 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4823 risc_size = be32_to_cpu(fwcode[3]);
4824
4825 /* Validate firmware image size. */
4826 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004827 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004828 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004829 "Unable to verify integrity of firmware image "
4830 "(%Zd)!\n", blob->fw->size);
4831
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004832 goto fail_fw_integrity;
4833 }
4834
4835 fragment = 0;
4836 while (risc_size > 0 && rval == QLA_SUCCESS) {
4837 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4838 if (dlen > risc_size)
4839 dlen = risc_size;
4840
4841 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004842 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004843 risc_addr, dlen));
4844
4845 for (i = 0; i < dlen; i++)
4846 dcode[i] = swab32(fwcode[i]);
4847
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004848 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004849 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004850 if (rval) {
4851 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004852 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004853 fragment));
4854 qla_printk(KERN_WARNING, ha,
4855 "[ERROR] Failed to load segment %d of "
4856 "firmware\n", fragment);
4857 break;
4858 }
4859
4860 fwcode += dlen;
4861 risc_addr += dlen;
4862 risc_size -= dlen;
4863 fragment++;
4864 }
4865
4866 /* Next segment. */
4867 segments--;
4868 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004869 return rval;
4870
4871fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004872 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004873}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004874
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004875int
4876qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4877{
4878 int rval;
4879
Andrew Vasqueze337d902009-04-06 22:33:49 -07004880 if (ql2xfwloadbin == 1)
4881 return qla81xx_load_risc(vha, srisc_addr);
4882
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004883 /*
4884 * FW Load priority:
4885 * 1) Firmware via request-firmware interface (.bin file).
4886 * 2) Firmware residing in flash.
4887 */
4888 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4889 if (rval == QLA_SUCCESS)
4890 return rval;
4891
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004892 return qla24xx_load_risc_flash(vha, srisc_addr,
4893 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004894}
4895
4896int
4897qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4898{
4899 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004900 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004901
Andrew Vasqueze337d902009-04-06 22:33:49 -07004902 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004903 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004904
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004905 /*
4906 * FW Load priority:
4907 * 1) Firmware residing in flash.
4908 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004909 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004910 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004911 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004912 if (rval == QLA_SUCCESS)
4913 return rval;
4914
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004915try_blob_fw:
4916 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4917 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4918 return rval;
4919
4920 qla_printk(KERN_ERR, ha,
4921 "FW: Attempting to fallback to golden firmware...\n");
4922 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4923 if (rval != QLA_SUCCESS)
4924 return rval;
4925
4926 qla_printk(KERN_ERR, ha,
4927 "FW: Please update operational firmware...\n");
4928 ha->flags.running_gold_fw = 1;
4929
4930 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004931}
4932
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004933void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004934qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004935{
4936 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004937 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004938
Andrew Vasquez85880802009-12-15 21:29:46 -08004939 if (ha->flags.pci_channel_io_perm_failure)
4940 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004941 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004942 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004943 if (!ha->fw_major_version)
4944 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004945
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004946 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004947 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004948 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004949 ha->isp_ops->reset_chip(vha);
4950 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004951 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004952 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004953 continue;
4954 qla_printk(KERN_INFO, ha,
4955 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004956 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004957 }
4958}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004959
4960int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004961qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004962{
4963 int rval = QLA_SUCCESS;
4964 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004965 struct qla_hw_data *ha = vha->hw;
4966 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004967 struct req_que *req;
4968 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004969
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004970 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004971 return -EINVAL;
4972
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004973 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004974 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004975 req = ha->req_q_map[0];
4976 else
4977 req = vha->req;
4978 rsp = req->rsp;
4979
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004980 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004981 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004982 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004983 }
4984
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004985 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004986
4987 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004988 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004989 if (mb[0] != MBS_COMMAND_COMPLETE) {
4990 DEBUG15(qla_printk(KERN_INFO, ha,
4991 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4992 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4993 mb[0], mb[1], mb[2], mb[6], mb[7]));
4994 return (QLA_FUNCTION_FAILED);
4995 }
4996
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004997 atomic_set(&vha->loop_down_timer, 0);
4998 atomic_set(&vha->loop_state, LOOP_UP);
4999 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5000 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5001 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005002
5003 return rval;
5004}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005005
5006/* 84XX Support **************************************************************/
5007
5008static LIST_HEAD(qla_cs84xx_list);
5009static DEFINE_MUTEX(qla_cs84xx_mutex);
5010
5011static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005012qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005013{
5014 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005015 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005016
5017 mutex_lock(&qla_cs84xx_mutex);
5018
5019 /* Find any shared 84xx chip. */
5020 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5021 if (cs84xx->bus == ha->pdev->bus) {
5022 kref_get(&cs84xx->kref);
5023 goto done;
5024 }
5025 }
5026
5027 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5028 if (!cs84xx)
5029 goto done;
5030
5031 kref_init(&cs84xx->kref);
5032 spin_lock_init(&cs84xx->access_lock);
5033 mutex_init(&cs84xx->fw_update_mutex);
5034 cs84xx->bus = ha->pdev->bus;
5035
5036 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5037done:
5038 mutex_unlock(&qla_cs84xx_mutex);
5039 return cs84xx;
5040}
5041
5042static void
5043__qla84xx_chip_release(struct kref *kref)
5044{
5045 struct qla_chip_state_84xx *cs84xx =
5046 container_of(kref, struct qla_chip_state_84xx, kref);
5047
5048 mutex_lock(&qla_cs84xx_mutex);
5049 list_del(&cs84xx->list);
5050 mutex_unlock(&qla_cs84xx_mutex);
5051 kfree(cs84xx);
5052}
5053
5054void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005055qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005056{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005057 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005058 if (ha->cs84xx)
5059 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
5060}
5061
5062static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005063qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005064{
5065 int rval;
5066 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005067 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005068
5069 mutex_lock(&ha->cs84xx->fw_update_mutex);
5070
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005071 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005072
5073 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5074
5075 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5076 QLA_SUCCESS;
5077}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005078
5079/* 81XX Support **************************************************************/
5080
5081int
5082qla81xx_nvram_config(scsi_qla_host_t *vha)
5083{
5084 int rval;
5085 struct init_cb_81xx *icb;
5086 struct nvram_81xx *nv;
5087 uint32_t *dptr;
5088 uint8_t *dptr1, *dptr2;
5089 uint32_t chksum;
5090 uint16_t cnt;
5091 struct qla_hw_data *ha = vha->hw;
5092
5093 rval = QLA_SUCCESS;
5094 icb = (struct init_cb_81xx *)ha->init_cb;
5095 nv = ha->nvram;
5096
5097 /* Determine NVRAM starting address. */
5098 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005099 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005100
5101 /* Get VPD data into cache */
5102 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005103 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5104 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005105
5106 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005107 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005108 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005109 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005110 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5111 chksum += le32_to_cpu(*dptr++);
5112
Andrew Vasquez76403352009-04-06 22:33:39 -07005113 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005114 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
5115
5116 /* Bad NVRAM data, set defaults parameters. */
5117 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5118 || nv->id[3] != ' ' ||
5119 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5120 /* Reset NVRAM data. */
5121 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
5122 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
5123 le16_to_cpu(nv->nvram_version));
5124 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
5125 "invalid -- WWPN) defaults.\n");
5126
5127 /*
5128 * Set default initialization control block.
5129 */
5130 memset(nv, 0, ha->nvram_size);
5131 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5132 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5133 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5134 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5135 nv->exchange_count = __constant_cpu_to_le16(0);
5136 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005137 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005138 nv->port_name[2] = 0x00;
5139 nv->port_name[3] = 0xe0;
5140 nv->port_name[4] = 0x8b;
5141 nv->port_name[5] = 0x1c;
5142 nv->port_name[6] = 0x55;
5143 nv->port_name[7] = 0x86;
5144 nv->node_name[0] = 0x20;
5145 nv->node_name[1] = 0x00;
5146 nv->node_name[2] = 0x00;
5147 nv->node_name[3] = 0xe0;
5148 nv->node_name[4] = 0x8b;
5149 nv->node_name[5] = 0x1c;
5150 nv->node_name[6] = 0x55;
5151 nv->node_name[7] = 0x86;
5152 nv->login_retry_count = __constant_cpu_to_le16(8);
5153 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5154 nv->login_timeout = __constant_cpu_to_le16(0);
5155 nv->firmware_options_1 =
5156 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5157 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5158 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5159 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5160 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5161 nv->efi_parameters = __constant_cpu_to_le32(0);
5162 nv->reset_delay = 5;
5163 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5164 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5165 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005166 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005167 nv->enode_mac[1] = 0x02;
5168 nv->enode_mac[2] = 0x03;
5169 nv->enode_mac[3] = 0x04;
5170 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005171 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005172
5173 rval = 1;
5174 }
5175
5176 /* Reset Initialization control block */
5177 memset(icb, 0, sizeof(struct init_cb_81xx));
5178
5179 /* Copy 1st segment. */
5180 dptr1 = (uint8_t *)icb;
5181 dptr2 = (uint8_t *)&nv->version;
5182 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5183 while (cnt--)
5184 *dptr1++ = *dptr2++;
5185
5186 icb->login_retry_count = nv->login_retry_count;
5187
5188 /* Copy 2nd segment. */
5189 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5190 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5191 cnt = (uint8_t *)&icb->reserved_5 -
5192 (uint8_t *)&icb->interrupt_delay_timer;
5193 while (cnt--)
5194 *dptr1++ = *dptr2++;
5195
5196 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5197 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5198 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
5199 icb->enode_mac[0] = 0x01;
5200 icb->enode_mac[1] = 0x02;
5201 icb->enode_mac[2] = 0x03;
5202 icb->enode_mac[3] = 0x04;
5203 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005204 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005205 }
5206
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005207 /* Use extended-initialization control block. */
5208 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5209
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005210 /*
5211 * Setup driver NVRAM options.
5212 */
5213 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005214 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005215
5216 /* Use alternate WWN? */
5217 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5218 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5219 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5220 }
5221
5222 /* Prepare nodename */
5223 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5224 /*
5225 * Firmware will apply the following mask if the nodename was
5226 * not provided.
5227 */
5228 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5229 icb->node_name[0] &= 0xF0;
5230 }
5231
5232 /* Set host adapter parameters. */
5233 ha->flags.disable_risc_code_load = 0;
5234 ha->flags.enable_lip_reset = 0;
5235 ha->flags.enable_lip_full_login =
5236 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5237 ha->flags.enable_target_reset =
5238 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5239 ha->flags.enable_led_scheme = 0;
5240 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5241
5242 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5243 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5244
5245 /* save HBA serial number */
5246 ha->serial0 = icb->port_name[5];
5247 ha->serial1 = icb->port_name[6];
5248 ha->serial2 = icb->port_name[7];
5249 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5250 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5251
5252 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5253
5254 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5255
5256 /* Set minimum login_timeout to 4 seconds. */
5257 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5258 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5259 if (le16_to_cpu(nv->login_timeout) < 4)
5260 nv->login_timeout = __constant_cpu_to_le16(4);
5261 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5262 icb->login_timeout = nv->login_timeout;
5263
5264 /* Set minimum RATOV to 100 tenths of a second. */
5265 ha->r_a_tov = 100;
5266
5267 ha->loop_reset_delay = nv->reset_delay;
5268
5269 /* Link Down Timeout = 0:
5270 *
5271 * When Port Down timer expires we will start returning
5272 * I/O's to OS with "DID_NO_CONNECT".
5273 *
5274 * Link Down Timeout != 0:
5275 *
5276 * The driver waits for the link to come up after link down
5277 * before returning I/Os to OS with "DID_NO_CONNECT".
5278 */
5279 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5280 ha->loop_down_abort_time =
5281 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5282 } else {
5283 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5284 ha->loop_down_abort_time =
5285 (LOOP_DOWN_TIME - ha->link_down_timeout);
5286 }
5287
5288 /* Need enough time to try and get the port back. */
5289 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5290 if (qlport_down_retry)
5291 ha->port_down_retry_count = qlport_down_retry;
5292
5293 /* Set login_retry_count */
5294 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5295 if (ha->port_down_retry_count ==
5296 le16_to_cpu(nv->port_down_retry_count) &&
5297 ha->port_down_retry_count > 3)
5298 ha->login_retry_count = ha->port_down_retry_count;
5299 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5300 ha->login_retry_count = ha->port_down_retry_count;
5301 if (ql2xloginretrycount)
5302 ha->login_retry_count = ql2xloginretrycount;
5303
5304 /* Enable ZIO. */
5305 if (!vha->flags.init_done) {
5306 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5307 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5308 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5309 le16_to_cpu(icb->interrupt_delay_timer): 2;
5310 }
5311 icb->firmware_options_2 &= __constant_cpu_to_le32(
5312 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5313 vha->flags.process_response_queue = 0;
5314 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5315 ha->zio_mode = QLA_ZIO_MODE_6;
5316
5317 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5318 "(%d us).\n", vha->host_no, ha->zio_mode,
5319 ha->zio_timer * 100));
5320 qla_printk(KERN_INFO, ha,
5321 "ZIO mode %d enabled; timer delay (%d us).\n",
5322 ha->zio_mode, ha->zio_timer * 100);
5323
5324 icb->firmware_options_2 |= cpu_to_le32(
5325 (uint32_t)ha->zio_mode);
5326 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5327 vha->flags.process_response_queue = 1;
5328 }
5329
5330 if (rval) {
5331 DEBUG2_3(printk(KERN_WARNING
5332 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
5333 }
5334 return (rval);
5335}
5336
Giridhar Malavalia9083012010-04-12 17:59:55 -07005337int
5338qla82xx_restart_isp(scsi_qla_host_t *vha)
5339{
5340 int status, rval;
5341 uint32_t wait_time;
5342 struct qla_hw_data *ha = vha->hw;
5343 struct req_que *req = ha->req_q_map[0];
5344 struct rsp_que *rsp = ha->rsp_q_map[0];
5345 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005346 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005347
5348 status = qla2x00_init_rings(vha);
5349 if (!status) {
5350 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5351 ha->flags.chip_reset_done = 1;
5352
5353 status = qla2x00_fw_ready(vha);
5354 if (!status) {
5355 qla_printk(KERN_INFO, ha,
5356 "%s(): Start configure loop, "
5357 "status = %d\n", __func__, status);
5358
5359 /* Issue a marker after FW becomes ready. */
5360 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5361
5362 vha->flags.online = 1;
5363 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5364 wait_time = 256;
5365 do {
5366 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5367 qla2x00_configure_loop(vha);
5368 wait_time--;
5369 } while (!atomic_read(&vha->loop_down_timer) &&
5370 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5371 wait_time &&
5372 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5373 }
5374
5375 /* if no cable then assume it's good */
5376 if ((vha->device_flags & DFLG_NO_CABLE))
5377 status = 0;
5378
5379 qla_printk(KERN_INFO, ha,
5380 "%s(): Configure loop done, status = 0x%x\n",
5381 __func__, status);
5382 }
5383
5384 if (!status) {
5385 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5386
5387 if (!atomic_read(&vha->loop_down_timer)) {
5388 /*
5389 * Issue marker command only when we are going
5390 * to start the I/O .
5391 */
5392 vha->marker_needed = 1;
5393 }
5394
5395 vha->flags.online = 1;
5396
5397 ha->isp_ops->enable_intrs(ha);
5398
5399 ha->isp_abort_cnt = 0;
5400 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5401
5402 if (ha->fce) {
5403 ha->flags.fce_enabled = 1;
5404 memset(ha->fce, 0,
5405 fce_calc_size(ha->fce_bufs));
5406 rval = qla2x00_enable_fce_trace(vha,
5407 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5408 &ha->fce_bufs);
5409 if (rval) {
5410 qla_printk(KERN_WARNING, ha,
5411 "Unable to reinitialize FCE "
5412 "(%d).\n", rval);
5413 ha->flags.fce_enabled = 0;
5414 }
5415 }
5416
5417 if (ha->eft) {
5418 memset(ha->eft, 0, EFT_SIZE);
5419 rval = qla2x00_enable_eft_trace(vha,
5420 ha->eft_dma, EFT_NUM_BUFFERS);
5421 if (rval) {
5422 qla_printk(KERN_WARNING, ha,
5423 "Unable to reinitialize EFT "
5424 "(%d).\n", rval);
5425 }
5426 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005427 }
5428
5429 if (!status) {
5430 DEBUG(printk(KERN_INFO
5431 "qla82xx_restart_isp(%ld): succeeded.\n",
5432 vha->host_no));
Arun Easifeafb7b2010-09-03 14:57:00 -07005433
5434 spin_lock_irqsave(&ha->vport_slock, flags);
5435 list_for_each_entry(vp, &ha->vp_list, list) {
5436 if (vp->vp_idx) {
5437 atomic_inc(&vp->vref_count);
5438 spin_unlock_irqrestore(&ha->vport_slock, flags);
5439
Giridhar Malavalia9083012010-04-12 17:59:55 -07005440 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07005441
5442 spin_lock_irqsave(&ha->vport_slock, flags);
5443 atomic_dec(&vp->vref_count);
5444 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005445 }
Arun Easifeafb7b2010-09-03 14:57:00 -07005446 spin_unlock_irqrestore(&ha->vport_slock, flags);
5447
Giridhar Malavalia9083012010-04-12 17:59:55 -07005448 } else {
5449 qla_printk(KERN_INFO, ha,
5450 "qla82xx_restart_isp: **** FAILED ****\n");
5451 }
5452
5453 return status;
5454}
5455
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005456void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005457qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005458{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005459 struct qla_hw_data *ha = vha->hw;
5460
5461 if (!ql2xetsenable)
5462 return;
5463
5464 /* Enable ETS Burst. */
5465 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5466 ha->fw_options[2] |= BIT_9;
5467 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005468}
Sarang Radke09ff7012010-03-19 17:03:59 -07005469
5470/*
5471 * qla24xx_get_fcp_prio
5472 * Gets the fcp cmd priority value for the logged in port.
5473 * Looks for a match of the port descriptors within
5474 * each of the fcp prio config entries. If a match is found,
5475 * the tag (priority) value is returned.
5476 *
5477 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005478 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005479 * fcport = port structure pointer.
5480 *
5481 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005482 * non-zero (if found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005483 * 0 (if not found)
5484 *
5485 * Context:
5486 * Kernel context
5487 */
5488uint8_t
5489qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5490{
5491 int i, entries;
5492 uint8_t pid_match, wwn_match;
5493 uint8_t priority;
5494 uint32_t pid1, pid2;
5495 uint64_t wwn1, wwn2;
5496 struct qla_fcp_prio_entry *pri_entry;
5497 struct qla_hw_data *ha = vha->hw;
5498
5499 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
5500 return 0;
5501
5502 priority = 0;
5503 entries = ha->fcp_prio_cfg->num_entries;
5504 pri_entry = &ha->fcp_prio_cfg->entry[0];
5505
5506 for (i = 0; i < entries; i++) {
5507 pid_match = wwn_match = 0;
5508
5509 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5510 pri_entry++;
5511 continue;
5512 }
5513
5514 /* check source pid for a match */
5515 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5516 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5517 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5518 if (pid1 == INVALID_PORT_ID)
5519 pid_match++;
5520 else if (pid1 == pid2)
5521 pid_match++;
5522 }
5523
5524 /* check destination pid for a match */
5525 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5526 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5527 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5528 if (pid1 == INVALID_PORT_ID)
5529 pid_match++;
5530 else if (pid1 == pid2)
5531 pid_match++;
5532 }
5533
5534 /* check source WWN for a match */
5535 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5536 wwn1 = wwn_to_u64(vha->port_name);
5537 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5538 if (wwn2 == (uint64_t)-1)
5539 wwn_match++;
5540 else if (wwn1 == wwn2)
5541 wwn_match++;
5542 }
5543
5544 /* check destination WWN for a match */
5545 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5546 wwn1 = wwn_to_u64(fcport->port_name);
5547 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5548 if (wwn2 == (uint64_t)-1)
5549 wwn_match++;
5550 else if (wwn1 == wwn2)
5551 wwn_match++;
5552 }
5553
5554 if (pid_match == 2 || wwn_match == 2) {
5555 /* Found a matching entry */
5556 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5557 priority = pri_entry->tag;
5558 break;
5559 }
5560
5561 pri_entry++;
5562 }
5563
5564 return priority;
5565}
5566
5567/*
5568 * qla24xx_update_fcport_fcp_prio
5569 * Activates fcp priority for the logged in fc port
5570 *
5571 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005572 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005573 * fcp = port structure pointer.
5574 *
5575 * Return:
5576 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5577 *
5578 * Context:
5579 * Kernel context.
5580 */
5581int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005582qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07005583{
5584 int ret;
5585 uint8_t priority;
5586 uint16_t mb[5];
5587
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005588 if (fcport->port_type != FCT_TARGET ||
5589 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07005590 return QLA_FUNCTION_FAILED;
5591
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005592 priority = qla24xx_get_fcp_prio(vha, fcport);
5593 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Sarang Radke09ff7012010-03-19 17:03:59 -07005594 if (ret == QLA_SUCCESS)
5595 fcport->fcp_prio = priority;
5596 else
5597 DEBUG2(printk(KERN_WARNING
5598 "scsi(%ld): Unable to activate fcp priority, "
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005599 " ret=0x%x\n", vha->host_no, ret));
Sarang Radke09ff7012010-03-19 17:03:59 -07005600
5601 return ret;
5602}
5603
5604/*
5605 * qla24xx_update_all_fcp_prio
5606 * Activates fcp priority for all the logged in ports
5607 *
5608 * Input:
5609 * ha = adapter block pointer.
5610 *
5611 * Return:
5612 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5613 *
5614 * Context:
5615 * Kernel context.
5616 */
5617int
5618qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5619{
5620 int ret;
5621 fc_port_t *fcport;
5622
5623 ret = QLA_FUNCTION_FAILED;
5624 /* We need to set priority for all logged in ports */
5625 list_for_each_entry(fcport, &vha->vp_fcports, list)
5626 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5627
5628 return ret;
5629}