blob: 2c9f47aef229b1f62899683fd0a29ecc4a37321c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez07e264b2011-03-30 11:46:23 -07003 * Copyright (c) 2003-2011 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
Anirban Chakraborty73208df2008-12-09 16:45:39 -08008#include "qla_gbl.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Andrew Vasquez0107109e2005-07-06 10:31:37 -070012#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#include "qla_devtbl.h"
15
David Miller4e08df32007-04-16 12:37:43 -070016#ifdef CONFIG_SPARC
17#include <asm/prom.h>
David Miller4e08df32007-04-16 12:37:43 -070018#endif
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020/*
21* QLogic ISP2x00 Hardware Support Function Prototypes.
22*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070023static int qla2x00_isp_firmware(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static int qla2x00_setup_chip(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static int qla2x00_init_rings(scsi_qla_host_t *);
26static int qla2x00_fw_ready(scsi_qla_host_t *);
27static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028static int qla2x00_configure_loop(scsi_qla_host_t *);
29static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static int qla2x00_configure_fabric(scsi_qla_host_t *);
31static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
32static int qla2x00_device_resync(scsi_qla_host_t *);
33static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
34 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
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 qla2x00_post_async_adisc_work(vha, fcport, data);
390 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700391 }
392 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700393 break;
394 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700395 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700396 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
397 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
398 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700399 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700400 break;
401 case MBS_PORT_ID_USED:
402 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700403 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700404 qla2x00_post_async_login_work(vha, fcport, NULL);
405 break;
406 case MBS_LOOP_ID_USED:
407 fcport->loop_id++;
408 rval = qla2x00_find_new_loop_id(vha, fcport);
409 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700410 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez80d79442011-03-30 11:46:17 -0700411 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700412 break;
413 }
414 qla2x00_post_async_login_work(vha, fcport, NULL);
415 break;
416 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700417 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700418}
419
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700420void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700421qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
422 uint16_t *data)
423{
424 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700425 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700426}
427
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700428void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700429qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
430 uint16_t *data)
431{
432 if (data[0] == MBS_COMMAND_COMPLETE) {
433 qla2x00_update_fcport(vha, fcport);
434
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700435 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700436 }
437
438 /* Retry login. */
439 fcport->flags &= ~FCF_ASYNC_SENT;
440 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
441 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
442 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700443 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700444
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700445 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700446}
447
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700448void
449qla2x00_async_tm_cmd_done(struct scsi_qla_host *vha, fc_port_t *fcport,
450 struct srb_iocb *iocb)
451{
452 int rval;
453 uint32_t flags;
454 uint16_t lun;
455
456 flags = iocb->u.tmf.flags;
457 lun = (uint16_t)iocb->u.tmf.lun;
458
459 /* Issue Marker IOCB */
Giridhar Malavalid94d10e2010-07-23 15:28:23 +0500460 rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
461 vha->hw->rsp_q_map[0], fcport->loop_id, lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700462 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
463
464 if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
465 DEBUG2_3_11(printk(KERN_WARNING
466 "%s(%ld): TM IOCB failed (%x).\n",
467 __func__, vha->host_no, rval));
468 }
469
470 return;
471}
472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473/****************************************************************************/
474/* QLogic ISP2x00 Hardware Support Functions. */
475/****************************************************************************/
476
477/*
478* qla2x00_initialize_adapter
479* Initialize board.
480*
481* Input:
482* ha = adapter block pointer.
483*
484* Returns:
485* 0 = success
486*/
487int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800488qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489{
490 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800491 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800492 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700493
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800495 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700496 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800497 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800498 ha->flags.pci_channel_io_perm_failure = 0;
499 ha->flags.eeh_busy = 0;
Andrew Vasquez794a5692010-12-21 16:00:21 -0800500 ha->flags.thermal_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800501 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
502 atomic_set(&vha->loop_state, LOOP_DOWN);
503 vha->device_flags = DFLG_NO_CABLE;
504 vha->dpc_flags = 0;
505 vha->flags.management_server_logged_in = 0;
506 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 ha->isp_abort_cnt = 0;
508 ha->beacon_blink_led = 0;
509
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800510 set_bit(0, ha->req_qid_map);
511 set_bit(0, ha->rsp_qid_map);
512
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700513 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800514 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -0800516 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800517 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 return (rval);
519 }
520
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800521 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800523 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700524 if (rval) {
525 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800526 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700527 return (rval);
528 }
529
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800530 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -0800531
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700533
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800534 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700536 if (ha->flags.disable_serdes) {
537 /* Mask HBA via NVRAM settings? */
538 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
539 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800540 vha->port_name[0], vha->port_name[1],
541 vha->port_name[2], vha->port_name[3],
542 vha->port_name[4], vha->port_name[5],
543 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700544 return QLA_FUNCTION_FAILED;
545 }
546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
548
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800549 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
550 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800551 if (rval)
552 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800553 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800554 if (rval)
555 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700557
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700558 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800559 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700560 if (!ha->cs84xx) {
561 qla_printk(KERN_ERR, ha,
562 "Unable to configure ISP84XX.\n");
563 return QLA_FUNCTION_FAILED;
564 }
565 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800566 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700567 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800569 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700570 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800571 rval = qla84xx_init_chip(vha);
572 if (rval != QLA_SUCCESS) {
573 qla_printk(KERN_ERR, ha,
574 "Unable to initialize ISP84XX.\n");
575 qla84xx_put_chip(vha);
576 }
577 }
578
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500579 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
580 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 return (rval);
583}
584
585/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700586 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 * @ha: HA context
588 *
589 * Returns 0 on success.
590 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700591int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800592qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700594 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700595 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800596 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700597 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700600 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700603 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
605
Andrew Vasquez737faec2008-10-24 15:13:45 -0700606 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700608 /* Get PCI bus information. */
609 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700610 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700611 spin_unlock_irqrestore(&ha->hardware_lock, flags);
612
613 return QLA_SUCCESS;
614}
615
616/**
617 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
618 * @ha: HA context
619 *
620 * Returns 0 on success.
621 */
622int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800623qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700624{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700625 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700626 unsigned long flags = 0;
627 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800628 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700629 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700630
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700631 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700632 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700633
634 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700635 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700636
637 if (IS_QLA2322(ha) || IS_QLA6322(ha))
638 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700639 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700640
641 /*
642 * If this is a 2300 card and not 2312, reset the
643 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
644 * the 2310 also reports itself as a 2300 so we need to get the
645 * fb revision level -- a 6 indicates it really is a 2300 and
646 * not a 2310.
647 */
648 if (IS_QLA2300(ha)) {
649 spin_lock_irqsave(&ha->hardware_lock, flags);
650
651 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700652 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700653 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700654 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700655 break;
656
657 udelay(10);
658 }
659
660 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700661 WRT_REG_WORD(&reg->ctrl_status, 0x20);
662 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700663
664 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700665 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700666
667 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700668 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700669
670 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700671 WRT_REG_WORD(&reg->ctrl_status, 0x0);
672 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700673
674 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700675 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700676 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700677 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700678 break;
679
680 udelay(10);
681 }
682
683 spin_unlock_irqrestore(&ha->hardware_lock, flags);
684 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700685
686 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
687
Andrew Vasquez737faec2008-10-24 15:13:45 -0700688 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700689
690 /* Get PCI bus information. */
691 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700692 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700693 spin_unlock_irqrestore(&ha->hardware_lock, flags);
694
695 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696}
697
698/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700699 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
700 * @ha: HA context
701 *
702 * Returns 0 on success.
703 */
704int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800705qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700706{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700707 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700708 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800709 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700710 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700711
712 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700713 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700714
715 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700716 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700717 w &= ~PCI_COMMAND_INTX_DISABLE;
718 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
719
720 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
721
722 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700723 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
724 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700725
726 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700727 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
728 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700729
Andrew Vasquez737faec2008-10-24 15:13:45 -0700730 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700731
Auke Kok44c10132007-06-08 15:46:36 -0700732 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800733
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700734 /* Get PCI bus information. */
735 spin_lock_irqsave(&ha->hardware_lock, flags);
736 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
737 spin_unlock_irqrestore(&ha->hardware_lock, flags);
738
739 return QLA_SUCCESS;
740}
741
742/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700743 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
744 * @ha: HA context
745 *
746 * Returns 0 on success.
747 */
748int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800749qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700750{
751 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800752 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700753
754 pci_set_master(ha->pdev);
755 pci_try_set_mwi(ha->pdev);
756
757 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
758 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
759 w &= ~PCI_COMMAND_INTX_DISABLE;
760 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
761
762 /* PCIe -- adjust Maximum Read Request Size (2048). */
763 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
764 pcie_set_readrq(ha->pdev, 2048);
765
Andrew Vasquez737faec2008-10-24 15:13:45 -0700766 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700767
768 ha->chip_revision = ha->pdev->revision;
769
770 return QLA_SUCCESS;
771}
772
773/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 * qla2x00_isp_firmware() - Choose firmware image.
775 * @ha: HA context
776 *
777 * Returns 0 on success.
778 */
779static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800780qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781{
782 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700783 uint16_t loop_id, topo, sw_cap;
784 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800785 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700788 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
790 if (ha->flags.disable_risc_code_load) {
791 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800792 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
794
795 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800796 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700797 if (rval == QLA_SUCCESS) {
798 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800799 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700800 &area, &domain, &topo, &sw_cap);
801 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 }
803
804 if (rval) {
805 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800806 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 }
808
809 return (rval);
810}
811
812/**
813 * qla2x00_reset_chip() - Reset ISP chip.
814 * @ha: HA context
815 *
816 * Returns 0 on success.
817 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700818void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800819qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
821 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800822 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700823 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 uint16_t cmd;
826
Andrew Vasquez85880802009-12-15 21:29:46 -0800827 if (unlikely(pci_channel_offline(ha->pdev)))
828 return;
829
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700830 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
832 spin_lock_irqsave(&ha->hardware_lock, flags);
833
834 /* Turn off master enable */
835 cmd = 0;
836 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
837 cmd &= ~PCI_COMMAND_MASTER;
838 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
839
840 if (!IS_QLA2100(ha)) {
841 /* Pause RISC. */
842 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
843 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
844 for (cnt = 0; cnt < 30000; cnt++) {
845 if ((RD_REG_WORD(&reg->hccr) &
846 HCCR_RISC_PAUSE) != 0)
847 break;
848 udelay(100);
849 }
850 } else {
851 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
852 udelay(10);
853 }
854
855 /* Select FPM registers. */
856 WRT_REG_WORD(&reg->ctrl_status, 0x20);
857 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
858
859 /* FPM Soft Reset. */
860 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
861 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
862
863 /* Toggle Fpm Reset. */
864 if (!IS_QLA2200(ha)) {
865 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
866 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
867 }
868
869 /* Select frame buffer registers. */
870 WRT_REG_WORD(&reg->ctrl_status, 0x10);
871 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
872
873 /* Reset frame buffer FIFOs. */
874 if (IS_QLA2200(ha)) {
875 WRT_FB_CMD_REG(ha, reg, 0xa000);
876 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
877 } else {
878 WRT_FB_CMD_REG(ha, reg, 0x00fc);
879
880 /* Read back fb_cmd until zero or 3 seconds max */
881 for (cnt = 0; cnt < 3000; cnt++) {
882 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
883 break;
884 udelay(100);
885 }
886 }
887
888 /* Select RISC module registers. */
889 WRT_REG_WORD(&reg->ctrl_status, 0);
890 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
891
892 /* Reset RISC processor. */
893 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
894 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
895
896 /* Release RISC processor. */
897 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
898 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
899 }
900
901 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
902 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
903
904 /* Reset ISP chip. */
905 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
906
907 /* Wait for RISC to recover from reset. */
908 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
909 /*
910 * It is necessary to for a delay here since the card doesn't
911 * respond to PCI reads during a reset. On some architectures
912 * this will result in an MCA.
913 */
914 udelay(20);
915 for (cnt = 30000; cnt; cnt--) {
916 if ((RD_REG_WORD(&reg->ctrl_status) &
917 CSR_ISP_SOFT_RESET) == 0)
918 break;
919 udelay(100);
920 }
921 } else
922 udelay(10);
923
924 /* Reset RISC processor. */
925 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
926
927 WRT_REG_WORD(&reg->semaphore, 0);
928
929 /* Release RISC processor. */
930 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
931 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
932
933 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
934 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700935 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
938 udelay(100);
939 }
940 } else
941 udelay(100);
942
943 /* Turn on master enable */
944 cmd |= PCI_COMMAND_MASTER;
945 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
946
947 /* Disable RISC pause on FPM parity error. */
948 if (!IS_QLA2100(ha)) {
949 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
950 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
951 }
952
953 spin_unlock_irqrestore(&ha->hardware_lock, flags);
954}
955
956/**
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700957 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
958 *
959 * Returns 0 on success.
960 */
961int
962qla81xx_reset_mpi(scsi_qla_host_t *vha)
963{
964 uint16_t mb[4] = {0x1010, 0, 1, 0};
965
966 return qla81xx_write_mpi_register(vha, mb);
967}
968
969/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700970 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700971 * @ha: HA context
972 *
973 * Returns 0 on success.
974 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700975static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800976qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700977{
978 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800979 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700980 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
981 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800982 uint16_t wd;
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700983 static int abts_cnt; /* ISP abort retry counts */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700984
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700985 spin_lock_irqsave(&ha->hardware_lock, flags);
986
987 /* Reset RISC. */
988 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
989 for (cnt = 0; cnt < 30000; cnt++) {
990 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
991 break;
992
993 udelay(10);
994 }
995
996 WRT_REG_DWORD(&reg->ctrl_status,
997 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800998 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700999
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001000 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001001 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001002 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1003 for (cnt = 10000 ; cnt && d2; cnt--) {
1004 udelay(5);
1005 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1006 barrier();
1007 }
1008
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001009 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001010 d2 = RD_REG_DWORD(&reg->ctrl_status);
1011 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1012 udelay(5);
1013 d2 = RD_REG_DWORD(&reg->ctrl_status);
1014 barrier();
1015 }
1016
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001017 /* If required, do an MPI FW reset now */
1018 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1019 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1020 if (++abts_cnt < 5) {
1021 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1022 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1023 } else {
1024 /*
1025 * We exhausted the ISP abort retries. We have to
1026 * set the board offline.
1027 */
1028 abts_cnt = 0;
1029 vha->flags.online = 0;
1030 }
1031 }
1032 }
1033
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001034 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1035 RD_REG_DWORD(&reg->hccr);
1036
1037 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1038 RD_REG_DWORD(&reg->hccr);
1039
1040 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1041 RD_REG_DWORD(&reg->hccr);
1042
1043 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1044 for (cnt = 6000000 ; cnt && d2; cnt--) {
1045 udelay(5);
1046 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1047 barrier();
1048 }
1049
1050 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001051
1052 if (IS_NOPOLLING_TYPE(ha))
1053 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001054}
1055
1056/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001057 * qla24xx_reset_chip() - Reset ISP24xx chip.
1058 * @ha: HA context
1059 *
1060 * Returns 0 on success.
1061 */
1062void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001063qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001064{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001065 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001066
1067 if (pci_channel_offline(ha->pdev) &&
1068 ha->flags.pci_channel_io_perm_failure) {
1069 return;
1070 }
1071
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001072 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001073
1074 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001075 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001076}
1077
1078/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 * qla2x00_chip_diag() - Test chip for proper operation.
1080 * @ha: HA context
1081 *
1082 * Returns 0 on success.
1083 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001084int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001085qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086{
1087 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001088 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001089 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 unsigned long flags = 0;
1091 uint16_t data;
1092 uint32_t cnt;
1093 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001094 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
1096 /* Assume a failed state */
1097 rval = QLA_FUNCTION_FAILED;
1098
1099 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001100 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
1102 spin_lock_irqsave(&ha->hardware_lock, flags);
1103
1104 /* Reset ISP chip. */
1105 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1106
1107 /*
1108 * We need to have a delay here since the card will not respond while
1109 * in reset causing an MCA on some architectures.
1110 */
1111 udelay(20);
1112 data = qla2x00_debounce_register(&reg->ctrl_status);
1113 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1114 udelay(5);
1115 data = RD_REG_WORD(&reg->ctrl_status);
1116 barrier();
1117 }
1118
1119 if (!cnt)
1120 goto chip_diag_failed;
1121
1122 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07001123 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
1125 /* Reset RISC processor. */
1126 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1127 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1128
1129 /* Workaround for QLA2312 PCI parity error */
1130 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1131 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1132 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1133 udelay(5);
1134 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001135 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 }
1137 } else
1138 udelay(10);
1139
1140 if (!cnt)
1141 goto chip_diag_failed;
1142
1143 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -07001144 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1147 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1148 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1149 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1150 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1151 mb[3] != PROD_ID_3) {
1152 qla_printk(KERN_WARNING, ha,
1153 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
1154
1155 goto chip_diag_failed;
1156 }
1157 ha->product_id[0] = mb[1];
1158 ha->product_id[1] = mb[2];
1159 ha->product_id[2] = mb[3];
1160 ha->product_id[3] = mb[4];
1161
1162 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001163 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1165 else
1166 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001167 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
1169 if (IS_QLA2200(ha) &&
1170 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1171 /* Limit firmware transfer size with a 2200A */
1172 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001173 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001175 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 ha->fw_transfer_size = 128;
1177 }
1178
1179 /* Wrap Incoming Mailboxes Test. */
1180 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1181
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001182 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
1183 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 if (rval) {
1185 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001186 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 qla_printk(KERN_WARNING, ha,
1188 "Failed mailbox send register test\n");
1189 }
1190 else {
1191 /* Flag a successful rval */
1192 rval = QLA_SUCCESS;
1193 }
1194 spin_lock_irqsave(&ha->hardware_lock, flags);
1195
1196chip_diag_failed:
1197 if (rval)
1198 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001199 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
1201 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1202
1203 return (rval);
1204}
1205
1206/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001207 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1208 * @ha: HA context
1209 *
1210 * Returns 0 on success.
1211 */
1212int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001213qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001214{
1215 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001216 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001217 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001218
Giridhar Malavalia9083012010-04-12 17:59:55 -07001219 if (IS_QLA82XX(ha))
1220 return QLA_SUCCESS;
1221
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001222 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001223
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001224 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001225 if (rval) {
1226 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001227 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001228 qla_printk(KERN_WARNING, ha,
1229 "Failed mailbox send register test\n");
1230 } else {
1231 /* Flag a successful rval */
1232 rval = QLA_SUCCESS;
1233 }
1234
1235 return rval;
1236}
1237
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001238void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001239qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001240{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001241 int rval;
1242 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001243 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001244 dma_addr_t tc_dma;
1245 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001246 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001247 struct req_que *req = ha->req_q_map[0];
1248 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001249
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001250 if (ha->fw_dump) {
1251 qla_printk(KERN_WARNING, ha,
1252 "Firmware dump previously allocated.\n");
1253 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001254 }
1255
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001256 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001257 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001258 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1259 fixed_size = sizeof(struct qla2100_fw_dump);
1260 } else if (IS_QLA23XX(ha)) {
1261 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1262 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1263 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001264 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001265 if (IS_QLA81XX(ha))
1266 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1267 else if (IS_QLA25XX(ha))
1268 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1269 else
1270 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001271 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1272 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001273 if (ha->mqenable)
1274 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001275 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001276 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001277 goto try_eft;
1278
1279 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1280 GFP_KERNEL);
1281 if (!tc) {
1282 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1283 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001284 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001285 }
1286
1287 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001288 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001289 ha->fce_mb, &ha->fce_bufs);
1290 if (rval) {
1291 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1292 "FCE (%d).\n", rval);
1293 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1294 tc_dma);
1295 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001296 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001297 }
1298
1299 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1300 FCE_SIZE / 1024);
1301
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001302 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001303 ha->flags.fce_enabled = 1;
1304 ha->fce_dma = tc_dma;
1305 ha->fce = tc;
1306try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001307 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001308 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001309 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001310 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001311 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1312 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1313 goto cont_alloc;
1314 }
1315
Andrew Vasquezfc447652008-01-17 09:02:18 -08001316 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001317 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001318 if (rval) {
1319 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1320 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001321 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1322 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001323 goto cont_alloc;
1324 }
1325
1326 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1327 EFT_SIZE / 1024);
1328
1329 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001330 ha->eft_dma = tc_dma;
1331 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001332 }
1333cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001334 req_q_size = req->length * sizeof(request_t);
1335 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001336
1337 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001338 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001339 ha->chain_offset = dump_size;
1340 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001341
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001342 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001343 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001344 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001345 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001346
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001347 if (ha->fce) {
1348 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1349 ha->fce_dma);
1350 ha->fce = NULL;
1351 ha->fce_dma = 0;
1352 }
1353
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001354 if (ha->eft) {
1355 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1356 ha->eft_dma);
1357 ha->eft = NULL;
1358 ha->eft_dma = 0;
1359 }
1360 return;
1361 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001362 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1363 dump_size / 1024);
1364
1365 ha->fw_dump_len = dump_size;
1366 ha->fw_dump->signature[0] = 'Q';
1367 ha->fw_dump->signature[1] = 'L';
1368 ha->fw_dump->signature[2] = 'G';
1369 ha->fw_dump->signature[3] = 'C';
1370 ha->fw_dump->version = __constant_htonl(1);
1371
1372 ha->fw_dump->fixed_size = htonl(fixed_size);
1373 ha->fw_dump->mem_size = htonl(mem_size);
1374 ha->fw_dump->req_q_size = htonl(req_q_size);
1375 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1376
1377 ha->fw_dump->eft_size = htonl(eft_size);
1378 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1379 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1380
1381 ha->fw_dump->header_size =
1382 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001383}
1384
Andrew Vasquez18e75552009-06-03 09:55:30 -07001385static int
1386qla81xx_mpi_sync(scsi_qla_host_t *vha)
1387{
1388#define MPS_MASK 0xe0
1389 int rval;
1390 uint16_t dc;
1391 uint32_t dw;
1392 struct qla_hw_data *ha = vha->hw;
1393
1394 if (!IS_QLA81XX(vha->hw))
1395 return QLA_SUCCESS;
1396
1397 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1398 if (rval != QLA_SUCCESS) {
1399 DEBUG2(qla_printk(KERN_WARNING, ha,
1400 "Sync-MPI: Unable to acquire semaphore.\n"));
1401 goto done;
1402 }
1403
1404 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1405 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1406 if (rval != QLA_SUCCESS) {
1407 DEBUG2(qla_printk(KERN_WARNING, ha,
1408 "Sync-MPI: Unable to read sync.\n"));
1409 goto done_release;
1410 }
1411
1412 dc &= MPS_MASK;
1413 if (dc == (dw & MPS_MASK))
1414 goto done_release;
1415
1416 dw &= ~MPS_MASK;
1417 dw |= dc;
1418 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1419 if (rval != QLA_SUCCESS) {
1420 DEBUG2(qla_printk(KERN_WARNING, ha,
1421 "Sync-MPI: Unable to gain sync.\n"));
1422 }
1423
1424done_release:
1425 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1426 if (rval != QLA_SUCCESS) {
1427 DEBUG2(qla_printk(KERN_WARNING, ha,
1428 "Sync-MPI: Unable to release semaphore.\n"));
1429 }
1430
1431done:
1432 return rval;
1433}
1434
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001435/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 * qla2x00_setup_chip() - Load and start RISC firmware.
1437 * @ha: HA context
1438 *
1439 * Returns 0 on success.
1440 */
1441static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001442qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001444 int rval;
1445 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001446 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001447 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1448 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001449 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001450
Giridhar Malavalia9083012010-04-12 17:59:55 -07001451 if (IS_QLA82XX(ha)) {
1452 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001453 if (rval == QLA_SUCCESS) {
1454 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001455 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001456 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001457 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001458 }
1459
Andrew Vasquez3db06522008-01-31 12:33:49 -08001460 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1461 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1462 spin_lock_irqsave(&ha->hardware_lock, flags);
1463 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1464 RD_REG_WORD(&reg->hccr);
1465 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Andrew Vasquez18e75552009-06-03 09:55:30 -07001468 qla81xx_mpi_sync(vha);
1469
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001471 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001472 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001474 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001476 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 if (rval == QLA_SUCCESS) {
1478 /* Start firmware execution. */
1479 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001480 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001482 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001484 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001485enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001486 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001487 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 &ha->fw_major_version,
1489 &ha->fw_minor_version,
1490 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001491 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001492 ha->mpi_version, &ha->mpi_capabilities,
1493 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001494 if (rval != QLA_SUCCESS)
1495 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001496 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001497 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001498 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001499 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001500 if ((!ha->max_npiv_vports) ||
1501 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001502 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001503 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001504 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001505 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001506 qla2x00_get_resource_cnts(vha, NULL,
1507 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001508 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001509
Giridhar Malavalia9083012010-04-12 17:59:55 -07001510 if (!fw_major_version && ql2xallocfwdump) {
1511 if (!IS_QLA82XX(ha))
1512 qla2x00_alloc_fw_dump(vha);
1513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 }
1515 } else {
1516 DEBUG2(printk(KERN_INFO
1517 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001518 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 }
1520 }
1521
Andrew Vasquez3db06522008-01-31 12:33:49 -08001522 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1523 /* Enable proper parity. */
1524 spin_lock_irqsave(&ha->hardware_lock, flags);
1525 if (IS_QLA2300(ha))
1526 /* SRAM parity */
1527 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1528 else
1529 /* SRAM, Instruction RAM and GP RAM parity */
1530 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1531 RD_REG_WORD(&reg->hccr);
1532 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1533 }
1534
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001535 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1536 uint32_t size;
1537
1538 rval = qla81xx_fac_get_sector_size(vha, &size);
1539 if (rval == QLA_SUCCESS) {
1540 ha->flags.fac_supported = 1;
1541 ha->fdt_block_size = size << 2;
1542 } else {
1543 qla_printk(KERN_ERR, ha,
1544 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1545 ha->fw_major_version, ha->fw_minor_version,
1546 ha->fw_subminor_version);
1547 }
1548 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001549failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 if (rval) {
1551 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001552 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 }
1554
1555 return (rval);
1556}
1557
1558/**
1559 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1560 * @ha: HA context
1561 *
1562 * Beginning of request ring has initialization control block already built
1563 * by nvram config routine.
1564 *
1565 * Returns 0 on success.
1566 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001567void
1568qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569{
1570 uint16_t cnt;
1571 response_t *pkt;
1572
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001573 rsp->ring_ptr = rsp->ring;
1574 rsp->ring_index = 0;
1575 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001576 pkt = rsp->ring_ptr;
1577 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 pkt->signature = RESPONSE_PROCESSED;
1579 pkt++;
1580 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581}
1582
1583/**
1584 * qla2x00_update_fw_options() - Read and process firmware options.
1585 * @ha: HA context
1586 *
1587 * Returns 0 on success.
1588 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001589void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001590qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591{
1592 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001593 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594
1595 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001596 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
1598 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1599 return;
1600
1601 /* Serial Link options. */
1602 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001603 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1605 sizeof(ha->fw_seriallink_options)));
1606
1607 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1608 if (ha->fw_seriallink_options[3] & BIT_2) {
1609 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1610
1611 /* 1G settings */
1612 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1613 emphasis = (ha->fw_seriallink_options[2] &
1614 (BIT_4 | BIT_3)) >> 3;
1615 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001616 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 rx_sens = (ha->fw_seriallink_options[0] &
1618 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1619 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1620 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1621 if (rx_sens == 0x0)
1622 rx_sens = 0x3;
1623 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1624 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1625 ha->fw_options[10] |= BIT_5 |
1626 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1627 (tx_sens & (BIT_1 | BIT_0));
1628
1629 /* 2G settings */
1630 swing = (ha->fw_seriallink_options[2] &
1631 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1632 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1633 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001634 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 rx_sens = (ha->fw_seriallink_options[1] &
1636 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1637 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1638 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1639 if (rx_sens == 0x0)
1640 rx_sens = 0x3;
1641 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1642 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1643 ha->fw_options[11] |= BIT_5 |
1644 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1645 (tx_sens & (BIT_1 | BIT_0));
1646 }
1647
1648 /* FCP2 options. */
1649 /* Return command IOCBs without waiting for an ABTS to complete. */
1650 ha->fw_options[3] |= BIT_13;
1651
1652 /* LED scheme. */
1653 if (ha->flags.enable_led_scheme)
1654 ha->fw_options[2] |= BIT_12;
1655
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001656 /* Detect ISP6312. */
1657 if (IS_QLA6312(ha))
1658 ha->fw_options[2] |= BIT_13;
1659
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001661 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662}
1663
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001664void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001665qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001666{
1667 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001668 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001669
Giridhar Malavalia9083012010-04-12 17:59:55 -07001670 if (IS_QLA82XX(ha))
1671 return;
1672
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001673 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001674 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001675 return;
1676
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001677 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001678 le16_to_cpu(ha->fw_seriallink_options24[1]),
1679 le16_to_cpu(ha->fw_seriallink_options24[2]),
1680 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001681 if (rval != QLA_SUCCESS) {
1682 qla_printk(KERN_WARNING, ha,
1683 "Unable to update Serial Link options (%x).\n", rval);
1684 }
1685}
1686
1687void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001688qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001689{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001690 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001691 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001692 struct req_que *req = ha->req_q_map[0];
1693 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001694
1695 /* Setup ring parameters in initialization control block. */
1696 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1697 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001698 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1699 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1700 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1701 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1702 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1703 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001704
1705 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1706 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1707 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1708 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1709 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1710}
1711
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001712void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001713qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001714{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001715 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001716 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1717 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1718 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001719 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001720 uint16_t rid = 0;
1721 struct req_que *req = ha->req_q_map[0];
1722 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001723
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001724/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001725 icb = (struct init_cb_24xx *)ha->init_cb;
1726 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1727 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001728 icb->request_q_length = cpu_to_le16(req->length);
1729 icb->response_q_length = cpu_to_le16(rsp->length);
1730 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1731 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1732 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1733 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001734
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001735 if (ha->mqenable) {
1736 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1737 icb->rid = __constant_cpu_to_le16(rid);
1738 if (ha->flags.msix_enabled) {
1739 msix = &ha->msix_entries[1];
1740 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001741 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001742 icb->msix = cpu_to_le16(msix->entry);
1743 }
1744 /* Use alternate PCI bus number */
1745 if (MSB(rid))
1746 icb->firmware_options_2 |=
1747 __constant_cpu_to_le32(BIT_19);
1748 /* Use alternate PCI devfn */
1749 if (LSB(rid))
1750 icb->firmware_options_2 |=
1751 __constant_cpu_to_le32(BIT_18);
1752
Anirban Chakraborty31557542009-12-02 10:36:55 -08001753 /* Use Disable MSIX Handshake mode for capable adapters */
1754 if (IS_MSIX_NACK_CAPABLE(ha)) {
1755 icb->firmware_options_2 &=
1756 __constant_cpu_to_le32(~BIT_22);
1757 ha->flags.disable_msix_handshake = 1;
1758 qla_printk(KERN_INFO, ha,
1759 "MSIX Handshake Disable Mode turned on\n");
1760 } else {
1761 icb->firmware_options_2 |=
1762 __constant_cpu_to_le32(BIT_22);
1763 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001764 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001765
1766 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1767 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1768 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1769 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1770 } else {
1771 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1772 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1773 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1774 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1775 }
1776 /* PCI posting */
1777 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001778}
1779
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780/**
1781 * qla2x00_init_rings() - Initializes firmware.
1782 * @ha: HA context
1783 *
1784 * Beginning of request ring has initialization control block already built
1785 * by nvram config routine.
1786 *
1787 * Returns 0 on success.
1788 */
1789static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001790qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791{
1792 int rval;
1793 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001794 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001795 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001796 struct req_que *req;
1797 struct rsp_que *rsp;
1798 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001799 struct mid_init_cb_24xx *mid_init_cb =
1800 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
1802 spin_lock_irqsave(&ha->hardware_lock, flags);
1803
1804 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001805 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001806 req = ha->req_q_map[que];
1807 if (!req)
1808 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001809 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001810 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001812 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001813
1814 /* Initialize firmware. */
1815 req->ring_ptr = req->ring;
1816 req->ring_index = 0;
1817 req->cnt = req->length;
1818 }
1819
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001820 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001821 rsp = ha->rsp_q_map[que];
1822 if (!rsp)
1823 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001824 /* Initialize response queue entries */
1825 qla2x00_init_response_q_entries(rsp);
1826 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
Dan Carpenter542bce12010-10-15 11:27:38 -07001828 spin_lock(&ha->vport_slock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001830 list_for_each_entry(vp, &ha->vp_list, list) {
1831 vp->rscn_in_ptr = 0;
1832 vp->rscn_out_ptr = 0;
1833 }
Arun Easifeafb7b2010-09-03 14:57:00 -07001834
Dan Carpenter542bce12010-10-15 11:27:38 -07001835 spin_unlock(&ha->vport_slock);
Arun Easifeafb7b2010-09-03 14:57:00 -07001836
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001837 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838
1839 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1840
1841 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001842 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001844 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001845
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001846 if (ha->flags.npiv_supported) {
1847 if (ha->operating_mode == LOOP)
1848 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001849 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001850 }
1851
Andrew Vasquez24a08132009-03-24 09:08:16 -07001852 if (IS_FWI2_CAPABLE(ha)) {
1853 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1854 mid_init_cb->init_cb.execution_throttle =
1855 cpu_to_le16(ha->fw_xcb_count);
1856 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001857
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001858 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 if (rval) {
1860 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001861 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 } else {
1863 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001864 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 }
1866
1867 return (rval);
1868}
1869
1870/**
1871 * qla2x00_fw_ready() - Waits for firmware ready.
1872 * @ha: HA context
1873 *
1874 * Returns 0 on success.
1875 */
1876static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001877qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878{
1879 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001880 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 uint16_t min_wait; /* Minimum wait time if loop is down */
1882 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001883 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001884 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
1886 rval = QLA_SUCCESS;
1887
1888 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001889 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890
1891 /*
1892 * Firmware should take at most one RATOV to login, plus 5 seconds for
1893 * our own processing.
1894 */
1895 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1896 wait_time = min_wait;
1897 }
1898
1899 /* Min wait time if loop down */
1900 mtime = jiffies + (min_wait * HZ);
1901
1902 /* wait time before firmware ready */
1903 wtime = jiffies + (wait_time * HZ);
1904
1905 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001906 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1908
1909 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001910 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911
1912 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001913 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001915 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001916 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001918 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1919 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001920 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001921 state[2]));
1922 if ((state[2] & FSTATE_LOGGED_IN) &&
1923 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1924 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001925 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001926
1927 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001928 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001929 if (rval != QLA_SUCCESS)
1930 break;
1931
1932 /* Add time taken to initialize. */
1933 cs84xx_time = jiffies - cs84xx_time;
1934 wtime += cs84xx_time;
1935 mtime += cs84xx_time;
1936 DEBUG16(printk("scsi(%ld): Increasing "
1937 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001938 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001939 }
1940 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001942 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001944 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 &ha->login_timeout, &ha->r_a_tov);
1946
1947 rval = QLA_SUCCESS;
1948 break;
1949 }
1950
1951 rval = QLA_FUNCTION_FAILED;
1952
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001953 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001954 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001956 * other than Wait for Login.
1957 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 if (time_after_eq(jiffies, mtime)) {
1959 qla_printk(KERN_INFO, ha,
1960 "Cable is unplugged...\n");
1961
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001962 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 break;
1964 }
1965 }
1966 } else {
1967 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07001968 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08001969 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 break;
1971 }
1972
1973 if (time_after_eq(jiffies, wtime))
1974 break;
1975
1976 /* Delay for a while */
1977 msleep(500);
1978
1979 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001980 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 } while (1);
1982
Andrew Vasquez656e8912009-06-03 09:55:29 -07001983 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1984 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1985 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
1987 if (rval) {
1988 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001989 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 }
1991
1992 return (rval);
1993}
1994
1995/*
1996* qla2x00_configure_hba
1997* Setup adapter context.
1998*
1999* Input:
2000* ha = adapter state pointer.
2001*
2002* Returns:
2003* 0 = success
2004*
2005* Context:
2006* Kernel context.
2007*/
2008static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002009qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010{
2011 int rval;
2012 uint16_t loop_id;
2013 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002014 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 uint8_t al_pa;
2016 uint8_t area;
2017 uint8_t domain;
2018 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002019 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020
2021 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002022 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002023 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002025 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Andrew Vasquez7a44b862010-12-21 16:00:23 -08002026 IS_QLA8XXX_TYPE(ha) ||
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;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002507 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002508
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002509 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002510 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002511 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002512 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002513 if (rport)
2514 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002515}
2516
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517/**
2518 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2519 * @ha: HA context
2520 * @flags: allocation flags
2521 *
2522 * Returns a pointer to the allocated fcport, or NULL, if none available.
2523 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002524fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002525qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526{
2527 fc_port_t *fcport;
2528
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002529 fcport = kzalloc(sizeof(fc_port_t), flags);
2530 if (!fcport)
2531 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
2533 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002534 fcport->vha = vha;
2535 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 fcport->port_type = FCT_UNKNOWN;
2537 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002539 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002541 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542}
2543
2544/*
2545 * qla2x00_configure_loop
2546 * Updates Fibre Channel Device Database with what is actually on loop.
2547 *
2548 * Input:
2549 * ha = adapter block pointer.
2550 *
2551 * Returns:
2552 * 0 = success.
2553 * 1 = error.
2554 * 2 = database was full and device was not configured.
2555 */
2556static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002557qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558{
2559 int rval;
2560 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002561 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 rval = QLA_SUCCESS;
2563
2564 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002565 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2566 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 if (rval != QLA_SUCCESS) {
2568 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002569 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 return (rval);
2571 }
2572 }
2573
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002574 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002576 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577
2578 /*
2579 * If we have both an RSCN and PORT UPDATE pending then handle them
2580 * both at the same time.
2581 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002582 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2583 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584
Michael Hernandez3064ff32009-12-15 21:29:44 -08002585 qla2x00_get_data_rate(vha);
2586
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 /* Determine what we need to do */
2588 if (ha->current_topology == ISP_CFG_FL &&
2589 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2590
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002591 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 set_bit(RSCN_UPDATE, &flags);
2593
2594 } else if (ha->current_topology == ISP_CFG_F &&
2595 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2596
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002597 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 set_bit(RSCN_UPDATE, &flags);
2599 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2600
Andrew Vasquez21333b42006-05-17 15:09:56 -07002601 } else if (ha->current_topology == ISP_CFG_N) {
2602 clear_bit(RSCN_UPDATE, &flags);
2603
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002604 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2606
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002607 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 set_bit(RSCN_UPDATE, &flags);
2609 set_bit(LOCAL_LOOP_UPDATE, &flags);
2610 }
2611
2612 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002613 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002615 else
2616 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 }
2618
2619 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002620 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002622 else
2623 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 }
2625
2626 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002627 if (atomic_read(&vha->loop_down_timer) ||
2628 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 rval = QLA_FUNCTION_FAILED;
2630 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002631 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002633 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 }
2635 }
2636
2637 if (rval) {
2638 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002639 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 } else {
2641 DEBUG3(printk("%s: exiting normally\n", __func__));
2642 }
2643
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002644 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002645 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002647 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002648 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002649 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07002650 if (!IS_ALOGIO_CAPABLE(ha))
2651 vha->flags.rscn_queue_overflow = 1;
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002652 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 }
2654
2655 return (rval);
2656}
2657
2658
2659
2660/*
2661 * qla2x00_configure_local_loop
2662 * Updates Fibre Channel Device Database with local loop devices.
2663 *
2664 * Input:
2665 * ha = adapter block pointer.
2666 *
2667 * Returns:
2668 * 0 = success.
2669 */
2670static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002671qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672{
2673 int rval, rval2;
2674 int found_devs;
2675 int found;
2676 fc_port_t *fcport, *new_fcport;
2677
2678 uint16_t index;
2679 uint16_t entries;
2680 char *id_iter;
2681 uint16_t loop_id;
2682 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002683 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
2685 found_devs = 0;
2686 new_fcport = NULL;
2687 entries = MAX_FIBRE_DEVICES;
2688
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002689 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2690 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691
2692 /* Get list of logged in devices. */
2693 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002694 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 &entries);
2696 if (rval != QLA_SUCCESS)
2697 goto cleanup_allocation;
2698
2699 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002700 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2702 entries * sizeof(struct gid_list_info)));
2703
2704 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002705 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 if (new_fcport == NULL) {
2707 rval = QLA_MEMORY_ALLOC_FAILED;
2708 goto cleanup_allocation;
2709 }
2710 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2711
2712 /*
2713 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2714 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002715 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2717 fcport->port_type != FCT_BROADCAST &&
2718 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2719
2720 DEBUG(printk("scsi(%ld): Marking port lost, "
2721 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002722 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723
2724 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 }
2726 }
2727
2728 /* Add devices to port list. */
2729 id_iter = (char *)ha->gid_list;
2730 for (index = 0; index < entries; index++) {
2731 domain = ((struct gid_list_info *)id_iter)->domain;
2732 area = ((struct gid_list_info *)id_iter)->area;
2733 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002734 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 loop_id = (uint16_t)
2736 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002737 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 loop_id = le16_to_cpu(
2739 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002740 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741
2742 /* Bypass reserved domain fields. */
2743 if ((domain & 0xf0) == 0xf0)
2744 continue;
2745
2746 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002747 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002748 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 continue;
2750
2751 /* Bypass invalid local loop ID. */
2752 if (loop_id > LAST_LOCAL_LOOP_ID)
2753 continue;
2754
2755 /* Fill in member data. */
2756 new_fcport->d_id.b.domain = domain;
2757 new_fcport->d_id.b.area = area;
2758 new_fcport->d_id.b.al_pa = al_pa;
2759 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002760 new_fcport->vp_idx = vha->vp_idx;
2761 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 if (rval2 != QLA_SUCCESS) {
2763 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2764 "information -- get_port_database=%x, "
2765 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002766 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002767 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002768 vha->host_no));
2769 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 continue;
2771 }
2772
2773 /* Check for matching device in port list. */
2774 found = 0;
2775 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002776 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 if (memcmp(new_fcport->port_name, fcport->port_name,
2778 WWN_SIZE))
2779 continue;
2780
Shyam Sundarddb9b122009-03-24 09:08:10 -07002781 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 fcport->loop_id = new_fcport->loop_id;
2783 fcport->port_type = new_fcport->port_type;
2784 fcport->d_id.b24 = new_fcport->d_id.b24;
2785 memcpy(fcport->node_name, new_fcport->node_name,
2786 WWN_SIZE);
2787
2788 found++;
2789 break;
2790 }
2791
2792 if (!found) {
2793 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002794 if (vha->vp_idx) {
2795 new_fcport->vha = vha;
2796 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002797 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002798 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799
2800 /* Allocate a new replacement fcport. */
2801 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002802 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 if (new_fcport == NULL) {
2804 rval = QLA_MEMORY_ALLOC_FAILED;
2805 goto cleanup_allocation;
2806 }
2807 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2808 }
2809
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002810 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002811 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002812
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002813 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814
2815 found_devs++;
2816 }
2817
2818cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002819 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820
2821 if (rval != QLA_SUCCESS) {
2822 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002823 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 }
2825
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 return (rval);
2827}
2828
2829static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002830qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002831{
2832#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002833 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2834 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002835 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002836 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002837 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002838
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002839 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002840 return;
2841
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07002842 if (atomic_read(&fcport->state) != FCS_ONLINE)
2843 return;
2844
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002845 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2846 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002847 return;
2848
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002849 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002850 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002851 if (rval != QLA_SUCCESS) {
2852 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2853 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002854 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002855 fcport->port_name[2], fcport->port_name[3],
2856 fcport->port_name[4], fcport->port_name[5],
2857 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002858 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002859 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002860 link_speed = link_speeds[LS_UNKNOWN];
2861 if (fcport->fp_speed < 5)
2862 link_speed = link_speeds[fcport->fp_speed];
2863 else if (fcport->fp_speed == 0x13)
2864 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002865 DEBUG2(qla_printk(KERN_INFO, ha,
2866 "iIDMA adjusted to %s GB/s on "
2867 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002868 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002869 fcport->port_name[1], fcport->port_name[2],
2870 fcport->port_name[3], fcport->port_name[4],
2871 fcport->port_name[5], fcport->port_name[6],
2872 fcport->port_name[7]));
2873 }
2874}
2875
Adrian Bunk23be3312006-11-24 02:46:01 +01002876static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002877qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002878{
2879 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002880 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002881 struct qla_hw_data *ha = vha->hw;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002882 unsigned long flags;
8482e1182005-04-17 15:04:54 -05002883
Andrew Vasquezac280b62009-08-20 11:06:05 -07002884 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002885
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002886 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2887 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002888 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2889 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2890 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002891 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002892 if (!rport) {
2893 qla_printk(KERN_WARNING, ha,
2894 "Unable to allocate fc remote port!\n");
2895 return;
2896 }
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002897 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002898 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002899 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002900
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002901 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002902
2903 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002904 if (fcport->port_type == FCT_INITIATOR)
2905 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2906 if (fcport->port_type == FCT_TARGET)
2907 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002908 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002909}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910
2911/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002912 * qla2x00_update_fcport
2913 * Updates device on list.
2914 *
2915 * Input:
2916 * ha = adapter block pointer.
2917 * fcport = port structure pointer.
2918 *
2919 * Return:
2920 * 0 - Success
2921 * BIT_0 - error
2922 *
2923 * Context:
2924 * Kernel context.
2925 */
2926void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002927qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002928{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002929 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002930 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002931 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01002932
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002933 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08002934 qla24xx_update_fcport_fcp_prio(vha, fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002935 qla2x00_reg_remote_port(vha, fcport);
Giridhar Malavali38170fa2010-10-15 11:27:49 -07002936 atomic_set(&fcport->state, FCS_ONLINE);
Adrian Bunk23be3312006-11-24 02:46:01 +01002937}
2938
2939/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 * qla2x00_configure_fabric
2941 * Setup SNS devices with loop ID's.
2942 *
2943 * Input:
2944 * ha = adapter block pointer.
2945 *
2946 * Returns:
2947 * 0 = success.
2948 * BIT_0 = error
2949 */
2950static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002951qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952{
2953 int rval, rval2;
2954 fc_port_t *fcport, *fcptemp;
2955 uint16_t next_loopid;
2956 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002957 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002959 struct qla_hw_data *ha = vha->hw;
2960 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961
2962 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002963 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002964 loop_id = NPH_F_PORT;
2965 else
2966 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002967 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 if (rval != QLA_SUCCESS) {
2969 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002970 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002972 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 return (QLA_SUCCESS);
2974 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002975 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976
2977 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002978 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 if (rval2 == QLA_RSCNS_HANDLED) {
2980 /* No point doing the scan, just continue. */
2981 return (QLA_SUCCESS);
2982 }
2983 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002984 /* FDMI support. */
2985 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002986 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2987 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002988
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002990 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002991 loop_id = NPH_SNS;
2992 else
2993 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002994 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002995 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 if (mb[0] != MBS_COMMAND_COMPLETE) {
2997 DEBUG2(qla_printk(KERN_INFO, ha,
2998 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002999 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 mb[0], mb[1], mb[2], mb[6], mb[7]));
3001 return (QLA_SUCCESS);
3002 }
3003
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003004 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3005 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 /* EMPTY */
3007 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003008 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003010 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 /* EMPTY */
3012 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003013 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003015 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 /* EMPTY */
3017 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003018 "failed.\n", vha->host_no));
3019 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 /* EMPTY */
3021 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003022 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 }
3024 }
3025
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003026 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 if (rval != QLA_SUCCESS)
3028 break;
3029
3030 /*
3031 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003032 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003034 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3035 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 break;
3037
3038 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3039 continue;
3040
3041 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003042 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003043 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003045 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 fcport->port_type != FCT_INITIATOR &&
3047 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003048 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003049 fcport->loop_id,
3050 fcport->d_id.b.domain,
3051 fcport->d_id.b.area,
3052 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 fcport->loop_id = FC_NO_LOOP_ID;
3054 }
3055 }
3056 }
3057
3058 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003059 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060
3061 /*
3062 * Scan through our port list and login entries that need to be
3063 * logged in.
3064 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003065 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3066 if (atomic_read(&vha->loop_down_timer) ||
3067 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 break;
3069
3070 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3071 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3072 continue;
3073
3074 if (fcport->loop_id == FC_NO_LOOP_ID) {
3075 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07003076 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003077 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078 if (rval != QLA_SUCCESS) {
3079 /* Ran out of IDs to use */
3080 break;
3081 }
3082 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003084 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 }
3086
3087 /* Exit if out of loop IDs. */
3088 if (rval != QLA_SUCCESS) {
3089 break;
3090 }
3091
3092 /*
3093 * Login and add the new devices to our port list.
3094 */
3095 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003096 if (atomic_read(&vha->loop_down_timer) ||
3097 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 break;
3099
3100 /* Find a new loop ID to use. */
3101 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003102 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 if (rval != QLA_SUCCESS) {
3104 /* Ran out of IDs to use */
3105 break;
3106 }
3107
bdf79622005-04-17 15:06:53 -05003108 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003109 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003110
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003111 if (vha->vp_idx) {
3112 fcport->vha = vha;
3113 fcport->vp_idx = vha->vp_idx;
3114 }
3115 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 }
3117 } while (0);
3118
3119 /* Free all new device structures not processed. */
3120 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3121 list_del(&fcport->list);
3122 kfree(fcport);
3123 }
3124
3125 if (rval) {
3126 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003127 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 }
3129
3130 return (rval);
3131}
3132
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133/*
3134 * qla2x00_find_all_fabric_devs
3135 *
3136 * Input:
3137 * ha = adapter block pointer.
3138 * dev = database device entry pointer.
3139 *
3140 * Returns:
3141 * 0 = success.
3142 *
3143 * Context:
3144 * Kernel context.
3145 */
3146static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003147qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3148 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149{
3150 int rval;
3151 uint16_t loop_id;
3152 fc_port_t *fcport, *new_fcport, *fcptemp;
3153 int found;
3154
3155 sw_info_t *swl;
3156 int swl_idx;
3157 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003158 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003159 struct qla_hw_data *ha = vha->hw;
3160 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003161 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162
3163 rval = QLA_SUCCESS;
3164
3165 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07003166 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003167 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 /*EMPTY*/
3169 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003170 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003172 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 kfree(swl);
3174 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003175 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 kfree(swl);
3177 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003178 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 kfree(swl);
3180 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003181 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003182 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3183 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003185
3186 /* If other queries succeeded probe for FC-4 type */
3187 if (swl)
3188 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 }
3190 swl_idx = 0;
3191
3192 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003193 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003195 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 return (QLA_MEMORY_ALLOC_FAILED);
3197 }
3198 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 /* Set start port ID scan at adapter ID. */
3200 first_dev = 1;
3201 last_dev = 0;
3202
3203 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003204 loop_id = ha->min_external_loopid;
3205 for (; loop_id <= ha->max_loop_id; loop_id++) {
3206 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 continue;
3208
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003209 if (ha->current_topology == ISP_CFG_FL &&
3210 (atomic_read(&vha->loop_down_timer) ||
3211 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003212 atomic_set(&vha->loop_down_timer, 0);
3213 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3214 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003216 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217
3218 if (swl != NULL) {
3219 if (last_dev) {
3220 wrap.b24 = new_fcport->d_id.b24;
3221 } else {
3222 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3223 memcpy(new_fcport->node_name,
3224 swl[swl_idx].node_name, WWN_SIZE);
3225 memcpy(new_fcport->port_name,
3226 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003227 memcpy(new_fcport->fabric_port_name,
3228 swl[swl_idx].fabric_port_name, WWN_SIZE);
3229 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003230 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231
3232 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3233 last_dev = 1;
3234 }
3235 swl_idx++;
3236 }
3237 } else {
3238 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003239 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240 if (rval != QLA_SUCCESS) {
3241 qla_printk(KERN_WARNING, ha,
3242 "SNS scan failed -- assuming zero-entry "
3243 "result...\n");
3244 list_for_each_entry_safe(fcport, fcptemp,
3245 new_fcports, list) {
3246 list_del(&fcport->list);
3247 kfree(fcport);
3248 }
3249 rval = QLA_SUCCESS;
3250 break;
3251 }
3252 }
3253
3254 /* If wrap on switch device list, exit. */
3255 if (first_dev) {
3256 wrap.b24 = new_fcport->d_id.b24;
3257 first_dev = 0;
3258 } else if (new_fcport->d_id.b24 == wrap.b24) {
3259 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003260 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
3262 break;
3263 }
3264
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003265 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003266 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 continue;
3268
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003269 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003270 found = 0;
3271 if (ha->num_vhosts) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003272 unsigned long flags;
3273
3274 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003275 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003276 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3277 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003278 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003279 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003280 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003281 spin_unlock_irqrestore(&ha->vport_slock, flags);
3282
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003283 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003284 continue;
3285 }
3286
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003287 /* Bypass if same domain and area of adapter. */
3288 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003289 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003290 ISP_CFG_FL)
3291 continue;
3292
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 /* Bypass reserved domain fields. */
3294 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3295 continue;
3296
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003297 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003298 if (ql2xgffidenable &&
3299 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3300 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003301 continue;
3302
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 /* Locate matching device in database. */
3304 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003305 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 if (memcmp(new_fcport->port_name, fcport->port_name,
3307 WWN_SIZE))
3308 continue;
3309
3310 found++;
3311
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003312 /* Update port state. */
3313 memcpy(fcport->fabric_port_name,
3314 new_fcport->fabric_port_name, WWN_SIZE);
3315 fcport->fp_speed = new_fcport->fp_speed;
3316
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 /*
3318 * If address the same and state FCS_ONLINE, nothing
3319 * changed.
3320 */
3321 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3322 atomic_read(&fcport->state) == FCS_ONLINE) {
3323 break;
3324 }
3325
3326 /*
3327 * If device was not a fabric device before.
3328 */
3329 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3330 fcport->d_id.b24 = new_fcport->d_id.b24;
3331 fcport->loop_id = FC_NO_LOOP_ID;
3332 fcport->flags |= (FCF_FABRIC_DEVICE |
3333 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 break;
3335 }
3336
3337 /*
3338 * Port ID changed or device was marked to be updated;
3339 * Log it out if still logged in and mark it for
3340 * relogin later.
3341 */
3342 fcport->d_id.b24 = new_fcport->d_id.b24;
3343 fcport->flags |= FCF_LOGIN_NEEDED;
3344 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003345 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 fcport->port_type != FCT_INITIATOR &&
3347 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003348 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003349 fcport->d_id.b.domain, fcport->d_id.b.area,
3350 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 fcport->loop_id = FC_NO_LOOP_ID;
3352 }
3353
3354 break;
3355 }
3356
3357 if (found)
3358 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 /* If device was not in our fcports list, then add it. */
3360 list_add_tail(&new_fcport->list, new_fcports);
3361
3362 /* Allocate a new replacement fcport. */
3363 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003364 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003366 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 return (QLA_MEMORY_ALLOC_FAILED);
3368 }
3369 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3370 new_fcport->d_id.b24 = nxt_d_id.b24;
3371 }
3372
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003373 kfree(swl);
3374 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 return (rval);
3377}
3378
3379/*
3380 * qla2x00_find_new_loop_id
3381 * Scan through our port list and find a new usable loop ID.
3382 *
3383 * Input:
3384 * ha: adapter state pointer.
3385 * dev: port structure pointer.
3386 *
3387 * Returns:
3388 * qla2x00 local function return status code.
3389 *
3390 * Context:
3391 * Kernel context.
3392 */
Adrian Bunk413975a2006-06-30 02:33:06 -07003393static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003394qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395{
3396 int rval;
3397 int found;
3398 fc_port_t *fcport;
3399 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003400 struct qla_hw_data *ha = vha->hw;
3401 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003402 struct scsi_qla_host *tvp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003403 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404
3405 rval = QLA_SUCCESS;
3406
3407 /* Save starting loop ID. */
3408 first_loop_id = dev->loop_id;
3409
3410 for (;;) {
3411 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003412 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414
3415 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003416 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418
3419 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003420 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421 /* first loop ID. */
3422 dev->loop_id = ha->min_external_loopid;
3423 }
3424
3425 /* Check for loop ID being already in use. */
3426 found = 0;
3427 fcport = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003428
3429 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003430 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003431 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3432 if (fcport->loop_id == dev->loop_id &&
3433 fcport != dev) {
3434 /* ID possibly in use */
3435 found++;
3436 break;
3437 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003439 if (found)
3440 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003442 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443
3444 /* If not in use then it is free to use. */
3445 if (!found) {
3446 break;
3447 }
3448
3449 /* ID in use. Try next value. */
3450 dev->loop_id++;
3451
3452 /* If wrap around. No free ID to use. */
3453 if (dev->loop_id == first_loop_id) {
3454 dev->loop_id = FC_NO_LOOP_ID;
3455 rval = QLA_FUNCTION_FAILED;
3456 break;
3457 }
3458 }
3459
3460 return (rval);
3461}
3462
3463/*
3464 * qla2x00_device_resync
3465 * Marks devices in the database that needs resynchronization.
3466 *
3467 * Input:
3468 * ha = adapter block pointer.
3469 *
3470 * Context:
3471 * Kernel context.
3472 */
3473static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003474qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475{
3476 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 uint32_t mask;
3478 fc_port_t *fcport;
3479 uint32_t rscn_entry;
3480 uint8_t rscn_out_iter;
3481 uint8_t format;
Mike Waychison1516ef42010-05-04 15:01:31 -07003482 port_id_t d_id = {};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483
3484 rval = QLA_RSCNS_HANDLED;
3485
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003486 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3487 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003489 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490 format = MSB(MSW(rscn_entry));
3491 d_id.b.domain = LSB(MSW(rscn_entry));
3492 d_id.b.area = MSB(LSW(rscn_entry));
3493 d_id.b.al_pa = LSB(LSW(rscn_entry));
3494
3495 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3496 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003497 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 d_id.b.area, d_id.b.al_pa));
3499
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003500 vha->rscn_out_ptr++;
3501 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3502 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503
3504 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003505 for (rscn_out_iter = vha->rscn_out_ptr;
3506 !vha->flags.rscn_queue_overflow &&
3507 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508 rscn_out_iter = (rscn_out_iter ==
3509 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3510
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003511 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512 break;
3513
3514 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003515 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 rscn_out_iter));
3517
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003518 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519 }
3520
3521 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003522 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003524 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525
3526 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003527 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 }
3529
3530 switch (format) {
3531 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 mask = 0xffffff;
3533 break;
3534 case 1:
3535 mask = 0xffff00;
3536 break;
3537 case 2:
3538 mask = 0xff0000;
3539 break;
3540 default:
3541 mask = 0x0;
3542 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003543 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 break;
3545 }
3546
3547 rval = QLA_SUCCESS;
3548
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003549 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3551 (fcport->d_id.b24 & mask) != d_id.b24 ||
3552 fcport->port_type == FCT_BROADCAST)
3553 continue;
3554
3555 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3556 if (format != 3 ||
3557 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003558 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003559 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560 }
3561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 }
3563 }
3564 return (rval);
3565}
3566
3567/*
3568 * qla2x00_fabric_dev_login
3569 * Login fabric target device and update FC port database.
3570 *
3571 * Input:
3572 * ha: adapter state pointer.
3573 * fcport: port structure list pointer.
3574 * next_loopid: contains value of a new loop ID that can be used
3575 * by the next login attempt.
3576 *
3577 * Returns:
3578 * qla2x00 local function return status code.
3579 *
3580 * Context:
3581 * Kernel context.
3582 */
3583static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003584qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585 uint16_t *next_loopid)
3586{
3587 int rval;
3588 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003589 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003590 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591
3592 rval = QLA_SUCCESS;
3593 retry = 0;
3594
Andrew Vasquezac280b62009-08-20 11:06:05 -07003595 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003596 if (fcport->flags & FCF_ASYNC_SENT)
3597 return rval;
3598 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003599 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3600 if (!rval)
3601 return rval;
3602 }
3603
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003604 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003605 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003607 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003608 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003609 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003610 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003611 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003613 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003614 fcport->d_id.b.domain, fcport->d_id.b.area,
3615 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003616 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003618 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619 }
3620 }
3621
3622 return (rval);
3623}
3624
3625/*
3626 * qla2x00_fabric_login
3627 * Issue fabric login command.
3628 *
3629 * Input:
3630 * ha = adapter block pointer.
3631 * device = pointer to FC device type structure.
3632 *
3633 * Returns:
3634 * 0 - Login successfully
3635 * 1 - Login failed
3636 * 2 - Initiator device
3637 * 3 - Fatal error
3638 */
3639int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003640qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641 uint16_t *next_loopid)
3642{
3643 int rval;
3644 int retry;
3645 uint16_t tmp_loopid;
3646 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003647 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648
3649 retry = 0;
3650 tmp_loopid = 0;
3651
3652 for (;;) {
3653 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3654 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003655 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3657
3658 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003659 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660 fcport->d_id.b.domain, fcport->d_id.b.area,
3661 fcport->d_id.b.al_pa, mb, BIT_0);
3662 if (mb[0] == MBS_PORT_ID_USED) {
3663 /*
3664 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003665 * recommends the driver perform an implicit login with
3666 * the specified ID again. The ID we just used is save
3667 * here so we return with an ID that can be tried by
3668 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 */
3670 retry++;
3671 tmp_loopid = fcport->loop_id;
3672 fcport->loop_id = mb[1];
3673
3674 DEBUG(printk("Fabric Login: port in use - next "
3675 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3676 fcport->loop_id, fcport->d_id.b.domain,
3677 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3678
3679 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3680 /*
3681 * Login succeeded.
3682 */
3683 if (retry) {
3684 /* A retry occurred before. */
3685 *next_loopid = tmp_loopid;
3686 } else {
3687 /*
3688 * No retry occurred before. Just increment the
3689 * ID value for next login.
3690 */
3691 *next_loopid = (fcport->loop_id + 1);
3692 }
3693
3694 if (mb[1] & BIT_0) {
3695 fcport->port_type = FCT_INITIATOR;
3696 } else {
3697 fcport->port_type = FCT_TARGET;
3698 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003699 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003700 }
3701 }
3702
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003703 if (mb[10] & BIT_0)
3704 fcport->supported_classes |= FC_COS_CLASS2;
3705 if (mb[10] & BIT_1)
3706 fcport->supported_classes |= FC_COS_CLASS3;
3707
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 rval = QLA_SUCCESS;
3709 break;
3710 } else if (mb[0] == MBS_LOOP_ID_USED) {
3711 /*
3712 * Loop ID already used, try next loop ID.
3713 */
3714 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003715 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 if (rval != QLA_SUCCESS) {
3717 /* Ran out of loop IDs to use */
3718 break;
3719 }
3720 } else if (mb[0] == MBS_COMMAND_ERROR) {
3721 /*
3722 * Firmware possibly timed out during login. If NO
3723 * retries are left to do then the device is declared
3724 * dead.
3725 */
3726 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003727 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003728 fcport->d_id.b.domain, fcport->d_id.b.area,
3729 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003730 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731
3732 rval = 1;
3733 break;
3734 } else {
3735 /*
3736 * unrecoverable / not handled error
3737 */
3738 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003739 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003740 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741 fcport->d_id.b.domain, fcport->d_id.b.area,
3742 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3743
3744 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003745 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003746 fcport->d_id.b.domain, fcport->d_id.b.area,
3747 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003749 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750
3751 rval = 3;
3752 break;
3753 }
3754 }
3755
3756 return (rval);
3757}
3758
3759/*
3760 * qla2x00_local_device_login
3761 * Issue local device login command.
3762 *
3763 * Input:
3764 * ha = adapter block pointer.
3765 * loop_id = loop id of device to login to.
3766 *
3767 * Returns (Where's the #define!!!!):
3768 * 0 - Login successfully
3769 * 1 - Login failed
3770 * 3 - Fatal error
3771 */
3772int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003773qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774{
3775 int rval;
3776 uint16_t mb[MAILBOX_REGISTER_COUNT];
3777
3778 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003779 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780 if (rval == QLA_SUCCESS) {
3781 /* Interrogate mailbox registers for any errors */
3782 if (mb[0] == MBS_COMMAND_ERROR)
3783 rval = 1;
3784 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3785 /* device not in PCB table */
3786 rval = 3;
3787 }
3788
3789 return (rval);
3790}
3791
3792/*
3793 * qla2x00_loop_resync
3794 * Resync with fibre channel devices.
3795 *
3796 * Input:
3797 * ha = adapter block pointer.
3798 *
3799 * Returns:
3800 * 0 = success
3801 */
3802int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003803qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003805 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003807 struct req_que *req;
3808 struct rsp_que *rsp;
3809
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003810 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003811 req = vha->hw->req_q_map[0];
3812 else
3813 req = vha->req;
3814 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003816 atomic_set(&vha->loop_state, LOOP_UPDATE);
3817 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3818 if (vha->flags.online) {
3819 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3821 wait_time = 256;
3822 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003823 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003825 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003826 qla2x00_marker(vha, req, rsp, 0, 0,
3827 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003828 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829
3830 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003831 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003833 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003835 } while (!atomic_read(&vha->loop_down_timer) &&
3836 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3837 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3838 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 }
3841
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003842 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003845 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847
3848 return (rval);
3849}
3850
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003851/*
3852* qla2x00_perform_loop_resync
3853* Description: This function will set the appropriate flags and call
3854* qla2x00_loop_resync. If successful loop will be resynced
3855* Arguments : scsi_qla_host_t pointer
3856* returm : Success or Failure
3857*/
3858
3859int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
3860{
3861 int32_t rval = 0;
3862
3863 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
3864 /*Configure the flags so that resync happens properly*/
3865 atomic_set(&ha->loop_down_timer, 0);
3866 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3867 atomic_set(&ha->loop_state, LOOP_UP);
3868 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
3869 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
3870 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3871
3872 rval = qla2x00_loop_resync(ha);
3873 } else
3874 atomic_set(&ha->loop_state, LOOP_DEAD);
3875
3876 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3877 }
3878
3879 return rval;
3880}
3881
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003883qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003884{
3885 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07003886 struct scsi_qla_host *vha;
3887 struct qla_hw_data *ha = base_vha->hw;
3888 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003889
Arun Easifeafb7b2010-09-03 14:57:00 -07003890 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003891 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07003892 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
3893 atomic_inc(&vha->vref_count);
3894 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08003895 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07003896 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
3897 spin_unlock_irqrestore(&ha->vport_slock, flags);
3898
Andrew Vasquez67becc02009-08-25 11:36:20 -07003899 qla2x00_rport_del(fcport);
Arun Easifeafb7b2010-09-03 14:57:00 -07003900
3901 spin_lock_irqsave(&ha->vport_slock, flags);
3902 }
3903 }
3904 atomic_dec(&vha->vref_count);
3905 }
3906 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003907}
3908
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003909/*
3910* qla82xx_quiescent_state_cleanup
3911* Description: This function will block the new I/Os
3912* Its not aborting any I/Os as context
3913* is not destroyed during quiescence
3914* Arguments: scsi_qla_host_t
3915* return : void
3916*/
3917void
3918qla82xx_quiescent_state_cleanup(scsi_qla_host_t *vha)
3919{
3920 struct qla_hw_data *ha = vha->hw;
3921 struct scsi_qla_host *vp;
3922
3923 qla_printk(KERN_INFO, ha,
3924 "Performing ISP error recovery - ha= %p.\n", ha);
3925
3926 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3927 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3928 atomic_set(&vha->loop_state, LOOP_DOWN);
3929 qla2x00_mark_all_devices_lost(vha, 0);
3930 list_for_each_entry(vp, &ha->vp_list, list)
3931 qla2x00_mark_all_devices_lost(vha, 0);
3932 } else {
3933 if (!atomic_read(&vha->loop_down_timer))
3934 atomic_set(&vha->loop_down_timer,
3935 LOOP_DOWN_TIME);
3936 }
3937 /* Wait for pending cmds to complete */
3938 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
3939}
3940
Giridhar Malavalia9083012010-04-12 17:59:55 -07003941void
3942qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3943{
3944 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003945 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003946 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08003947 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003948
Saurav Kashyape46ef002011-02-23 15:27:16 -08003949 /* For ISP82XX, driver waits for completion of the commands.
3950 * online flag should be set.
3951 */
3952 if (!IS_QLA82XX(ha))
3953 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003954 ha->flags.chip_reset_done = 0;
3955 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3956 ha->qla_stats.total_isp_aborts++;
3957
3958 qla_printk(KERN_INFO, ha,
3959 "Performing ISP error recovery - ha= %p.\n", ha);
3960
Saurav Kashyape46ef002011-02-23 15:27:16 -08003961 /* For ISP82XX, reset_chip is just disabling interrupts.
3962 * Driver waits for the completion of the commands.
3963 * the interrupts need to be enabled.
3964 */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003965 if (!IS_QLA82XX(ha))
3966 ha->isp_ops->reset_chip(vha);
3967
3968 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3969 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3970 atomic_set(&vha->loop_state, LOOP_DOWN);
3971 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07003972
3973 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003974 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003975 atomic_inc(&vp->vref_count);
3976 spin_unlock_irqrestore(&ha->vport_slock, flags);
3977
Giridhar Malavalia9083012010-04-12 17:59:55 -07003978 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07003979
3980 spin_lock_irqsave(&ha->vport_slock, flags);
3981 atomic_dec(&vp->vref_count);
3982 }
3983 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003984 } else {
3985 if (!atomic_read(&vha->loop_down_timer))
3986 atomic_set(&vha->loop_down_timer,
3987 LOOP_DOWN_TIME);
3988 }
3989
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08003990 /* Clear all async request states across all VPs. */
3991 list_for_each_entry(fcport, &vha->vp_fcports, list)
3992 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
3993 spin_lock_irqsave(&ha->vport_slock, flags);
3994 list_for_each_entry(vp, &ha->vp_list, list) {
3995 atomic_inc(&vp->vref_count);
3996 spin_unlock_irqrestore(&ha->vport_slock, flags);
3997
3998 list_for_each_entry(fcport, &vp->vp_fcports, list)
3999 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4000
4001 spin_lock_irqsave(&ha->vport_slock, flags);
4002 atomic_dec(&vp->vref_count);
4003 }
4004 spin_unlock_irqrestore(&ha->vport_slock, flags);
4005
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004006 if (!ha->flags.eeh_busy) {
4007 /* Make sure for ISP 82XX IO DMA is complete */
4008 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004009 qla82xx_chip_reset_cleanup(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004010
Saurav Kashyape46ef002011-02-23 15:27:16 -08004011 /* Done waiting for pending commands.
4012 * Reset the online flag.
4013 */
4014 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004015 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004016
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004017 /* Requeue all commands in outstanding command list. */
4018 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4019 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020}
4021
4022/*
4023* qla2x00_abort_isp
4024* Resets ISP and aborts all outstanding commands.
4025*
4026* Input:
4027* ha = adapter block pointer.
4028*
4029* Returns:
4030* 0 = success
4031*/
4032int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004033qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034{
Andrew Vasquez476e8972006-08-23 14:54:55 -07004035 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004037 struct qla_hw_data *ha = vha->hw;
4038 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004039 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07004040 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004042 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004043 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044
Andrew Vasquez85880802009-12-15 21:29:46 -08004045 if (unlikely(pci_channel_offline(ha->pdev) &&
4046 ha->flags.pci_channel_io_perm_failure)) {
4047 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4048 status = 0;
4049 return status;
4050 }
4051
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004052 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08004053
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004054 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004056 if (!qla2x00_restart_isp(vha)) {
4057 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004059 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004060 /*
4061 * Issue marker command only when we are going
4062 * to start the I/O .
4063 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004064 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065 }
4066
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004067 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004069 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004071 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004072 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07004073
Lalit Chandivade29c53972009-10-13 15:16:47 -07004074 if (IS_QLA81XX(ha))
4075 qla2x00_get_fw_version(vha,
4076 &ha->fw_major_version,
4077 &ha->fw_minor_version,
4078 &ha->fw_subminor_version,
4079 &ha->fw_attributes, &ha->fw_memory_size,
4080 ha->mpi_version, &ha->mpi_capabilities,
4081 ha->phy_version);
4082
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004083 if (ha->fce) {
4084 ha->flags.fce_enabled = 1;
4085 memset(ha->fce, 0,
4086 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004087 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004088 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4089 &ha->fce_bufs);
4090 if (rval) {
4091 qla_printk(KERN_WARNING, ha,
4092 "Unable to reinitialize FCE "
4093 "(%d).\n", rval);
4094 ha->flags.fce_enabled = 0;
4095 }
4096 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004097
4098 if (ha->eft) {
4099 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004100 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004101 ha->eft_dma, EFT_NUM_BUFFERS);
4102 if (rval) {
4103 qla_printk(KERN_WARNING, ha,
4104 "Unable to reinitialize EFT "
4105 "(%d).\n", rval);
4106 }
4107 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004108 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004109 vha->flags.online = 1;
4110 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111 if (ha->isp_abort_cnt == 0) {
4112 qla_printk(KERN_WARNING, ha,
4113 "ISP error recovery failed - "
4114 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004115 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116 * The next call disables the board
4117 * completely.
4118 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004119 ha->isp_ops->reset_adapter(vha);
4120 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004122 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123 status = 0;
4124 } else { /* schedule another ISP abort */
4125 ha->isp_abort_cnt--;
4126 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004127 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004128 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 status = 1;
4130 }
4131 } else {
4132 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
4133 DEBUG(printk("qla2x00(%ld): ISP error recovery "
4134 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004135 vha->host_no, ha->isp_abort_cnt));
4136 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 status = 1;
4138 }
4139 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004140
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141 }
4142
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004143 if (!status) {
4144 DEBUG(printk(KERN_INFO
4145 "qla2x00_abort_isp(%ld): succeeded.\n",
4146 vha->host_no));
Arun Easifeafb7b2010-09-03 14:57:00 -07004147
4148 spin_lock_irqsave(&ha->vport_slock, flags);
4149 list_for_each_entry(vp, &ha->vp_list, list) {
4150 if (vp->vp_idx) {
4151 atomic_inc(&vp->vref_count);
4152 spin_unlock_irqrestore(&ha->vport_slock, flags);
4153
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004154 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004155
4156 spin_lock_irqsave(&ha->vport_slock, flags);
4157 atomic_dec(&vp->vref_count);
4158 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004159 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004160 spin_unlock_irqrestore(&ha->vport_slock, flags);
4161
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004162 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163 qla_printk(KERN_INFO, ha,
4164 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004165 }
4166
4167 return(status);
4168}
4169
4170/*
4171* qla2x00_restart_isp
4172* restarts the ISP after a reset
4173*
4174* Input:
4175* ha = adapter block pointer.
4176*
4177* Returns:
4178* 0 = success
4179*/
4180static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004181qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004183 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004185 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004186 struct req_que *req = ha->req_q_map[0];
4187 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004188
4189 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004190 if (qla2x00_isp_firmware(vha)) {
4191 vha->flags.online = 0;
4192 status = ha->isp_ops->chip_diag(vha);
4193 if (!status)
4194 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195 }
4196
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004197 if (!status && !(status = qla2x00_init_rings(vha))) {
4198 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004199 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004200 /* Initialize the queues in use */
4201 qla25xx_init_queues(ha);
4202
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004203 status = qla2x00_fw_ready(vha);
4204 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004206 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004207
4208 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004209 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004210
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004211 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4213 wait_time = 256;
4214 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004215 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4216 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004218 } while (!atomic_read(&vha->loop_down_timer) &&
4219 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4220 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4221 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222 }
4223
4224 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004225 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226 status = 0;
4227
4228 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4229 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004230 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231 }
4232 return (status);
4233}
4234
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004235static int
4236qla25xx_init_queues(struct qla_hw_data *ha)
4237{
4238 struct rsp_que *rsp = NULL;
4239 struct req_que *req = NULL;
4240 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4241 int ret = -1;
4242 int i;
4243
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004244 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004245 rsp = ha->rsp_q_map[i];
4246 if (rsp) {
4247 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004248 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004249 if (ret != QLA_SUCCESS)
4250 DEBUG2_17(printk(KERN_WARNING
4251 "%s Rsp que:%d init failed\n", __func__,
4252 rsp->id));
4253 else
4254 DEBUG2_17(printk(KERN_INFO
4255 "%s Rsp que:%d inited\n", __func__,
4256 rsp->id));
4257 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004258 }
4259 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004260 req = ha->req_q_map[i];
4261 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004262 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004263 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004264 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004265 if (ret != QLA_SUCCESS)
4266 DEBUG2_17(printk(KERN_WARNING
4267 "%s Req que:%d init failed\n", __func__,
4268 req->id));
4269 else
4270 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004271 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004272 req->id));
4273 }
4274 }
4275 return ret;
4276}
4277
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278/*
4279* qla2x00_reset_adapter
4280* Reset adapter.
4281*
4282* Input:
4283* ha = adapter block pointer.
4284*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004285void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004286qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287{
4288 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004289 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004290 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004292 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004293 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295 spin_lock_irqsave(&ha->hardware_lock, flags);
4296 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4297 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4298 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4299 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4300 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4301}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004302
4303void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004304qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004305{
4306 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004307 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004308 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4309
Giridhar Malavalia9083012010-04-12 17:59:55 -07004310 if (IS_QLA82XX(ha))
4311 return;
4312
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004313 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004314 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004315
4316 spin_lock_irqsave(&ha->hardware_lock, flags);
4317 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4318 RD_REG_DWORD(&reg->hccr);
4319 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4320 RD_REG_DWORD(&reg->hccr);
4321 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004322
4323 if (IS_NOPOLLING_TYPE(ha))
4324 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004325}
4326
David Miller4e08df32007-04-16 12:37:43 -07004327/* On sparc systems, obtain port and node WWN from firmware
4328 * properties.
4329 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004330static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4331 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004332{
4333#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004334 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004335 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004336 struct device_node *dp = pci_device_to_OF_node(pdev);
4337 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004338 int len;
4339
4340 val = of_get_property(dp, "port-wwn", &len);
4341 if (val && len >= WWN_SIZE)
4342 memcpy(nv->port_name, val, WWN_SIZE);
4343
4344 val = of_get_property(dp, "node-wwn", &len);
4345 if (val && len >= WWN_SIZE)
4346 memcpy(nv->node_name, val, WWN_SIZE);
4347#endif
4348}
4349
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004350int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004351qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004352{
David Miller4e08df32007-04-16 12:37:43 -07004353 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004354 struct init_cb_24xx *icb;
4355 struct nvram_24xx *nv;
4356 uint32_t *dptr;
4357 uint8_t *dptr1, *dptr2;
4358 uint32_t chksum;
4359 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004360 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004361
David Miller4e08df32007-04-16 12:37:43 -07004362 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004363 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004364 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004365
4366 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004367 if (ha->flags.port0) {
4368 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4369 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4370 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004371 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004372 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4373 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004374 ha->nvram_size = sizeof(struct nvram_24xx);
4375 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004376 if (IS_QLA82XX(ha))
4377 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004378
Seokmann Ju281afe12007-07-26 13:43:34 -07004379 /* Get VPD data into cache */
4380 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004381 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004382 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4383
4384 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004385 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004386 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004387 ha->nvram_size);
4388 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4389 chksum += le32_to_cpu(*dptr++);
4390
Andrew Vasquez76403352009-04-06 22:33:39 -07004391 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07004392 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004393
4394 /* Bad NVRAM data, set defaults parameters. */
4395 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4396 || nv->id[3] != ' ' ||
4397 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4398 /* Reset NVRAM data. */
4399 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4400 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4401 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07004402 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4403 "invalid -- WWPN) defaults.\n");
4404
4405 /*
4406 * Set default initialization control block.
4407 */
4408 memset(nv, 0, ha->nvram_size);
4409 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4410 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4411 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4412 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4413 nv->exchange_count = __constant_cpu_to_le16(0);
4414 nv->hard_address = __constant_cpu_to_le16(124);
4415 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004416 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004417 nv->port_name[2] = 0x00;
4418 nv->port_name[3] = 0xe0;
4419 nv->port_name[4] = 0x8b;
4420 nv->port_name[5] = 0x1c;
4421 nv->port_name[6] = 0x55;
4422 nv->port_name[7] = 0x86;
4423 nv->node_name[0] = 0x20;
4424 nv->node_name[1] = 0x00;
4425 nv->node_name[2] = 0x00;
4426 nv->node_name[3] = 0xe0;
4427 nv->node_name[4] = 0x8b;
4428 nv->node_name[5] = 0x1c;
4429 nv->node_name[6] = 0x55;
4430 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004431 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004432 nv->login_retry_count = __constant_cpu_to_le16(8);
4433 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4434 nv->login_timeout = __constant_cpu_to_le16(0);
4435 nv->firmware_options_1 =
4436 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4437 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4438 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4439 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4440 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4441 nv->efi_parameters = __constant_cpu_to_le32(0);
4442 nv->reset_delay = 5;
4443 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4444 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4445 nv->link_down_timeout = __constant_cpu_to_le16(30);
4446
4447 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004448 }
4449
4450 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004451 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004452
4453 /* Copy 1st segment. */
4454 dptr1 = (uint8_t *)icb;
4455 dptr2 = (uint8_t *)&nv->version;
4456 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4457 while (cnt--)
4458 *dptr1++ = *dptr2++;
4459
4460 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004461 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004462
4463 /* Copy 2nd segment. */
4464 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4465 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4466 cnt = (uint8_t *)&icb->reserved_3 -
4467 (uint8_t *)&icb->interrupt_delay_timer;
4468 while (cnt--)
4469 *dptr1++ = *dptr2++;
4470
4471 /*
4472 * Setup driver NVRAM options.
4473 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004474 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004475 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004476
Andrew Vasquez5341e862006-05-17 15:09:16 -07004477 /* Use alternate WWN? */
4478 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4479 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4480 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4481 }
4482
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004483 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004484 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004485 /*
4486 * Firmware will apply the following mask if the nodename was
4487 * not provided.
4488 */
4489 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4490 icb->node_name[0] &= 0xF0;
4491 }
4492
4493 /* Set host adapter parameters. */
4494 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004495 ha->flags.enable_lip_reset = 0;
4496 ha->flags.enable_lip_full_login =
4497 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4498 ha->flags.enable_target_reset =
4499 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004500 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004501 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004502
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004503 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4504 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004505
4506 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4507 sizeof(ha->fw_seriallink_options24));
4508
4509 /* save HBA serial number */
4510 ha->serial0 = icb->port_name[5];
4511 ha->serial1 = icb->port_name[6];
4512 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004513 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4514 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004515
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004516 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4517
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004518 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4519
4520 /* Set minimum login_timeout to 4 seconds. */
4521 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4522 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4523 if (le16_to_cpu(nv->login_timeout) < 4)
4524 nv->login_timeout = __constant_cpu_to_le16(4);
4525 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004526 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004527
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004528 /* Set minimum RATOV to 100 tenths of a second. */
4529 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004530
4531 ha->loop_reset_delay = nv->reset_delay;
4532
4533 /* Link Down Timeout = 0:
4534 *
4535 * When Port Down timer expires we will start returning
4536 * I/O's to OS with "DID_NO_CONNECT".
4537 *
4538 * Link Down Timeout != 0:
4539 *
4540 * The driver waits for the link to come up after link down
4541 * before returning I/Os to OS with "DID_NO_CONNECT".
4542 */
4543 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4544 ha->loop_down_abort_time =
4545 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4546 } else {
4547 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4548 ha->loop_down_abort_time =
4549 (LOOP_DOWN_TIME - ha->link_down_timeout);
4550 }
4551
4552 /* Need enough time to try and get the port back. */
4553 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4554 if (qlport_down_retry)
4555 ha->port_down_retry_count = qlport_down_retry;
4556
4557 /* Set login_retry_count */
4558 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4559 if (ha->port_down_retry_count ==
4560 le16_to_cpu(nv->port_down_retry_count) &&
4561 ha->port_down_retry_count > 3)
4562 ha->login_retry_count = ha->port_down_retry_count;
4563 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4564 ha->login_retry_count = ha->port_down_retry_count;
4565 if (ql2xloginretrycount)
4566 ha->login_retry_count = ql2xloginretrycount;
4567
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004568 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004569 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004570 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4571 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4572 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4573 le16_to_cpu(icb->interrupt_delay_timer): 2;
4574 }
4575 icb->firmware_options_2 &= __constant_cpu_to_le32(
4576 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004577 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004578 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004579 ha->zio_mode = QLA_ZIO_MODE_6;
4580
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004581 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004582 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004583 ha->zio_timer * 100));
4584 qla_printk(KERN_INFO, ha,
4585 "ZIO mode %d enabled; timer delay (%d us).\n",
4586 ha->zio_mode, ha->zio_timer * 100);
4587
4588 icb->firmware_options_2 |= cpu_to_le32(
4589 (uint32_t)ha->zio_mode);
4590 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004591 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004592 }
4593
David Miller4e08df32007-04-16 12:37:43 -07004594 if (rval) {
4595 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004596 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004597 }
4598 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004599}
4600
Adrian Bunk413975a2006-06-30 02:33:06 -07004601static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004602qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4603 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004604{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004605 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004606 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004607 uint32_t *dcode, dlen;
4608 uint32_t risc_addr;
4609 uint32_t risc_size;
4610 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004611 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004612 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004613
4614 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004615 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004616
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004617 rval = QLA_SUCCESS;
4618
4619 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004620 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004621 *srisc_addr = 0;
4622
4623 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004624 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004625 for (i = 0; i < 4; i++)
4626 dcode[i] = be32_to_cpu(dcode[i]);
4627 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4628 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4629 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4630 dcode[3] == 0)) {
4631 qla_printk(KERN_WARNING, ha,
4632 "Unable to verify integrity of flash firmware image!\n");
4633 qla_printk(KERN_WARNING, ha,
4634 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4635 dcode[1], dcode[2], dcode[3]);
4636
4637 return QLA_FUNCTION_FAILED;
4638 }
4639
4640 while (segments && rval == QLA_SUCCESS) {
4641 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004642 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004643
4644 risc_addr = be32_to_cpu(dcode[2]);
4645 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4646 risc_size = be32_to_cpu(dcode[3]);
4647
4648 fragment = 0;
4649 while (risc_size > 0 && rval == QLA_SUCCESS) {
4650 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4651 if (dlen > risc_size)
4652 dlen = risc_size;
4653
4654 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4655 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004656 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004657
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004658 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004659 for (i = 0; i < dlen; i++)
4660 dcode[i] = swab32(dcode[i]);
4661
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004662 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004663 dlen);
4664 if (rval) {
4665 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004666 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004667 fragment));
4668 qla_printk(KERN_WARNING, ha,
4669 "[ERROR] Failed to load segment %d of "
4670 "firmware\n", fragment);
4671 break;
4672 }
4673
4674 faddr += dlen;
4675 risc_addr += dlen;
4676 risc_size -= dlen;
4677 fragment++;
4678 }
4679
4680 /* Next segment. */
4681 segments--;
4682 }
4683
4684 return rval;
4685}
4686
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004687#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4688
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004689int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004690qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004691{
4692 int rval;
4693 int i, fragment;
4694 uint16_t *wcode, *fwcode;
4695 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4696 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004697 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004698 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004699
4700 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004701 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004702 if (!blob) {
4703 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004704 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4705 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004706 return QLA_FUNCTION_FAILED;
4707 }
4708
4709 rval = QLA_SUCCESS;
4710
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004711 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004712 *srisc_addr = 0;
4713 fwcode = (uint16_t *)blob->fw->data;
4714 fwclen = 0;
4715
4716 /* Validate firmware image by checking version. */
4717 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4718 qla_printk(KERN_WARNING, ha,
4719 "Unable to verify integrity of firmware image (%Zd)!\n",
4720 blob->fw->size);
4721 goto fail_fw_integrity;
4722 }
4723 for (i = 0; i < 4; i++)
4724 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4725 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4726 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4727 wcode[2] == 0 && wcode[3] == 0)) {
4728 qla_printk(KERN_WARNING, ha,
4729 "Unable to verify integrity of firmware image!\n");
4730 qla_printk(KERN_WARNING, ha,
4731 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4732 wcode[1], wcode[2], wcode[3]);
4733 goto fail_fw_integrity;
4734 }
4735
4736 seg = blob->segs;
4737 while (*seg && rval == QLA_SUCCESS) {
4738 risc_addr = *seg;
4739 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4740 risc_size = be16_to_cpu(fwcode[3]);
4741
4742 /* Validate firmware image size. */
4743 fwclen += risc_size * sizeof(uint16_t);
4744 if (blob->fw->size < fwclen) {
4745 qla_printk(KERN_WARNING, ha,
4746 "Unable to verify integrity of firmware image "
4747 "(%Zd)!\n", blob->fw->size);
4748 goto fail_fw_integrity;
4749 }
4750
4751 fragment = 0;
4752 while (risc_size > 0 && rval == QLA_SUCCESS) {
4753 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4754 if (wlen > risc_size)
4755 wlen = risc_size;
4756
4757 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004758 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004759 risc_addr, wlen));
4760
4761 for (i = 0; i < wlen; i++)
4762 wcode[i] = swab16(fwcode[i]);
4763
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004764 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004765 wlen);
4766 if (rval) {
4767 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004768 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004769 fragment));
4770 qla_printk(KERN_WARNING, ha,
4771 "[ERROR] Failed to load segment %d of "
4772 "firmware\n", fragment);
4773 break;
4774 }
4775
4776 fwcode += wlen;
4777 risc_addr += wlen;
4778 risc_size -= wlen;
4779 fragment++;
4780 }
4781
4782 /* Next segment. */
4783 seg++;
4784 }
4785 return rval;
4786
4787fail_fw_integrity:
4788 return QLA_FUNCTION_FAILED;
4789}
4790
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004791static int
4792qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004793{
4794 int rval;
4795 int segments, fragment;
4796 uint32_t *dcode, dlen;
4797 uint32_t risc_addr;
4798 uint32_t risc_size;
4799 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004800 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004801 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004802 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004803 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004804
Andrew Vasquez54333832005-11-09 15:49:04 -08004805 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004806 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004807 if (!blob) {
4808 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004809 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4810 "from: " QLA_FW_URL ".\n");
4811
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004812 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004813 }
4814
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004815 qla_printk(KERN_INFO, ha,
4816 "FW: Loading via request-firmware...\n");
4817
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004818 rval = QLA_SUCCESS;
4819
4820 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004821 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004822 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004823 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004824 fwclen = 0;
4825
4826 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004827 if (blob->fw->size < 8 * sizeof(uint32_t)) {
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 (%Zd)!\n",
4830 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004831 goto fail_fw_integrity;
4832 }
4833 for (i = 0; i < 4; i++)
4834 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4835 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4836 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4837 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4838 dcode[3] == 0)) {
4839 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004840 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004841 qla_printk(KERN_WARNING, ha,
4842 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4843 dcode[1], dcode[2], dcode[3]);
4844 goto fail_fw_integrity;
4845 }
4846
4847 while (segments && rval == QLA_SUCCESS) {
4848 risc_addr = be32_to_cpu(fwcode[2]);
4849 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4850 risc_size = be32_to_cpu(fwcode[3]);
4851
4852 /* Validate firmware image size. */
4853 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004854 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004855 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004856 "Unable to verify integrity of firmware image "
4857 "(%Zd)!\n", blob->fw->size);
4858
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004859 goto fail_fw_integrity;
4860 }
4861
4862 fragment = 0;
4863 while (risc_size > 0 && rval == QLA_SUCCESS) {
4864 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4865 if (dlen > risc_size)
4866 dlen = risc_size;
4867
4868 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004869 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004870 risc_addr, dlen));
4871
4872 for (i = 0; i < dlen; i++)
4873 dcode[i] = swab32(fwcode[i]);
4874
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004875 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004876 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004877 if (rval) {
4878 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004879 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004880 fragment));
4881 qla_printk(KERN_WARNING, ha,
4882 "[ERROR] Failed to load segment %d of "
4883 "firmware\n", fragment);
4884 break;
4885 }
4886
4887 fwcode += dlen;
4888 risc_addr += dlen;
4889 risc_size -= dlen;
4890 fragment++;
4891 }
4892
4893 /* Next segment. */
4894 segments--;
4895 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004896 return rval;
4897
4898fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004899 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004900}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004901
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004902int
4903qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4904{
4905 int rval;
4906
Andrew Vasqueze337d902009-04-06 22:33:49 -07004907 if (ql2xfwloadbin == 1)
4908 return qla81xx_load_risc(vha, srisc_addr);
4909
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004910 /*
4911 * FW Load priority:
4912 * 1) Firmware via request-firmware interface (.bin file).
4913 * 2) Firmware residing in flash.
4914 */
4915 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4916 if (rval == QLA_SUCCESS)
4917 return rval;
4918
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004919 return qla24xx_load_risc_flash(vha, srisc_addr,
4920 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004921}
4922
4923int
4924qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4925{
4926 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004927 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004928
Andrew Vasqueze337d902009-04-06 22:33:49 -07004929 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004930 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004931
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004932 /*
4933 * FW Load priority:
4934 * 1) Firmware residing in flash.
4935 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004936 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004937 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004938 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004939 if (rval == QLA_SUCCESS)
4940 return rval;
4941
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004942try_blob_fw:
4943 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4944 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4945 return rval;
4946
4947 qla_printk(KERN_ERR, ha,
4948 "FW: Attempting to fallback to golden firmware...\n");
4949 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4950 if (rval != QLA_SUCCESS)
4951 return rval;
4952
4953 qla_printk(KERN_ERR, ha,
4954 "FW: Please update operational firmware...\n");
4955 ha->flags.running_gold_fw = 1;
4956
4957 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004958}
4959
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004960void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004961qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004962{
4963 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004964 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004965
Andrew Vasquez85880802009-12-15 21:29:46 -08004966 if (ha->flags.pci_channel_io_perm_failure)
4967 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004968 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004969 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004970 if (!ha->fw_major_version)
4971 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004972
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004973 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004974 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004975 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004976 ha->isp_ops->reset_chip(vha);
4977 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004978 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004979 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004980 continue;
4981 qla_printk(KERN_INFO, ha,
4982 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004983 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004984 }
4985}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004986
4987int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004988qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004989{
4990 int rval = QLA_SUCCESS;
4991 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004992 struct qla_hw_data *ha = vha->hw;
4993 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004994 struct req_que *req;
4995 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004996
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004997 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004998 return -EINVAL;
4999
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005000 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07005001 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005002 req = ha->req_q_map[0];
5003 else
5004 req = vha->req;
5005 rsp = req->rsp;
5006
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005007 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005008 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005009 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005010 }
5011
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005012 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005013
5014 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005015 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005016 if (mb[0] != MBS_COMMAND_COMPLETE) {
5017 DEBUG15(qla_printk(KERN_INFO, ha,
5018 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5019 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
5020 mb[0], mb[1], mb[2], mb[6], mb[7]));
5021 return (QLA_FUNCTION_FAILED);
5022 }
5023
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005024 atomic_set(&vha->loop_down_timer, 0);
5025 atomic_set(&vha->loop_state, LOOP_UP);
5026 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5027 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5028 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005029
5030 return rval;
5031}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005032
5033/* 84XX Support **************************************************************/
5034
5035static LIST_HEAD(qla_cs84xx_list);
5036static DEFINE_MUTEX(qla_cs84xx_mutex);
5037
5038static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005039qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005040{
5041 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005042 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005043
5044 mutex_lock(&qla_cs84xx_mutex);
5045
5046 /* Find any shared 84xx chip. */
5047 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5048 if (cs84xx->bus == ha->pdev->bus) {
5049 kref_get(&cs84xx->kref);
5050 goto done;
5051 }
5052 }
5053
5054 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5055 if (!cs84xx)
5056 goto done;
5057
5058 kref_init(&cs84xx->kref);
5059 spin_lock_init(&cs84xx->access_lock);
5060 mutex_init(&cs84xx->fw_update_mutex);
5061 cs84xx->bus = ha->pdev->bus;
5062
5063 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5064done:
5065 mutex_unlock(&qla_cs84xx_mutex);
5066 return cs84xx;
5067}
5068
5069static void
5070__qla84xx_chip_release(struct kref *kref)
5071{
5072 struct qla_chip_state_84xx *cs84xx =
5073 container_of(kref, struct qla_chip_state_84xx, kref);
5074
5075 mutex_lock(&qla_cs84xx_mutex);
5076 list_del(&cs84xx->list);
5077 mutex_unlock(&qla_cs84xx_mutex);
5078 kfree(cs84xx);
5079}
5080
5081void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005082qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005083{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005084 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005085 if (ha->cs84xx)
5086 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
5087}
5088
5089static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005090qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005091{
5092 int rval;
5093 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005094 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005095
5096 mutex_lock(&ha->cs84xx->fw_update_mutex);
5097
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005098 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005099
5100 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5101
5102 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5103 QLA_SUCCESS;
5104}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005105
5106/* 81XX Support **************************************************************/
5107
5108int
5109qla81xx_nvram_config(scsi_qla_host_t *vha)
5110{
5111 int rval;
5112 struct init_cb_81xx *icb;
5113 struct nvram_81xx *nv;
5114 uint32_t *dptr;
5115 uint8_t *dptr1, *dptr2;
5116 uint32_t chksum;
5117 uint16_t cnt;
5118 struct qla_hw_data *ha = vha->hw;
5119
5120 rval = QLA_SUCCESS;
5121 icb = (struct init_cb_81xx *)ha->init_cb;
5122 nv = ha->nvram;
5123
5124 /* Determine NVRAM starting address. */
5125 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005126 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005127
5128 /* Get VPD data into cache */
5129 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005130 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5131 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005132
5133 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005134 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005135 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005136 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005137 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5138 chksum += le32_to_cpu(*dptr++);
5139
Andrew Vasquez76403352009-04-06 22:33:39 -07005140 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005141 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
5142
5143 /* Bad NVRAM data, set defaults parameters. */
5144 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5145 || nv->id[3] != ' ' ||
5146 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5147 /* Reset NVRAM data. */
5148 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
5149 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
5150 le16_to_cpu(nv->nvram_version));
5151 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
5152 "invalid -- WWPN) defaults.\n");
5153
5154 /*
5155 * Set default initialization control block.
5156 */
5157 memset(nv, 0, ha->nvram_size);
5158 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5159 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5160 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5161 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5162 nv->exchange_count = __constant_cpu_to_le16(0);
5163 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005164 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005165 nv->port_name[2] = 0x00;
5166 nv->port_name[3] = 0xe0;
5167 nv->port_name[4] = 0x8b;
5168 nv->port_name[5] = 0x1c;
5169 nv->port_name[6] = 0x55;
5170 nv->port_name[7] = 0x86;
5171 nv->node_name[0] = 0x20;
5172 nv->node_name[1] = 0x00;
5173 nv->node_name[2] = 0x00;
5174 nv->node_name[3] = 0xe0;
5175 nv->node_name[4] = 0x8b;
5176 nv->node_name[5] = 0x1c;
5177 nv->node_name[6] = 0x55;
5178 nv->node_name[7] = 0x86;
5179 nv->login_retry_count = __constant_cpu_to_le16(8);
5180 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5181 nv->login_timeout = __constant_cpu_to_le16(0);
5182 nv->firmware_options_1 =
5183 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5184 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5185 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5186 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5187 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5188 nv->efi_parameters = __constant_cpu_to_le32(0);
5189 nv->reset_delay = 5;
5190 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5191 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5192 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005193 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005194 nv->enode_mac[1] = 0x02;
5195 nv->enode_mac[2] = 0x03;
5196 nv->enode_mac[3] = 0x04;
5197 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005198 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005199
5200 rval = 1;
5201 }
5202
5203 /* Reset Initialization control block */
5204 memset(icb, 0, sizeof(struct init_cb_81xx));
5205
5206 /* Copy 1st segment. */
5207 dptr1 = (uint8_t *)icb;
5208 dptr2 = (uint8_t *)&nv->version;
5209 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5210 while (cnt--)
5211 *dptr1++ = *dptr2++;
5212
5213 icb->login_retry_count = nv->login_retry_count;
5214
5215 /* Copy 2nd segment. */
5216 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5217 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5218 cnt = (uint8_t *)&icb->reserved_5 -
5219 (uint8_t *)&icb->interrupt_delay_timer;
5220 while (cnt--)
5221 *dptr1++ = *dptr2++;
5222
5223 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5224 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5225 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
5226 icb->enode_mac[0] = 0x01;
5227 icb->enode_mac[1] = 0x02;
5228 icb->enode_mac[2] = 0x03;
5229 icb->enode_mac[3] = 0x04;
5230 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005231 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005232 }
5233
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005234 /* Use extended-initialization control block. */
5235 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5236
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005237 /*
5238 * Setup driver NVRAM options.
5239 */
5240 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005241 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005242
5243 /* Use alternate WWN? */
5244 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5245 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5246 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5247 }
5248
5249 /* Prepare nodename */
5250 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5251 /*
5252 * Firmware will apply the following mask if the nodename was
5253 * not provided.
5254 */
5255 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5256 icb->node_name[0] &= 0xF0;
5257 }
5258
5259 /* Set host adapter parameters. */
5260 ha->flags.disable_risc_code_load = 0;
5261 ha->flags.enable_lip_reset = 0;
5262 ha->flags.enable_lip_full_login =
5263 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5264 ha->flags.enable_target_reset =
5265 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5266 ha->flags.enable_led_scheme = 0;
5267 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5268
5269 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5270 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5271
5272 /* save HBA serial number */
5273 ha->serial0 = icb->port_name[5];
5274 ha->serial1 = icb->port_name[6];
5275 ha->serial2 = icb->port_name[7];
5276 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5277 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5278
5279 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5280
5281 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5282
5283 /* Set minimum login_timeout to 4 seconds. */
5284 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5285 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5286 if (le16_to_cpu(nv->login_timeout) < 4)
5287 nv->login_timeout = __constant_cpu_to_le16(4);
5288 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5289 icb->login_timeout = nv->login_timeout;
5290
5291 /* Set minimum RATOV to 100 tenths of a second. */
5292 ha->r_a_tov = 100;
5293
5294 ha->loop_reset_delay = nv->reset_delay;
5295
5296 /* Link Down Timeout = 0:
5297 *
5298 * When Port Down timer expires we will start returning
5299 * I/O's to OS with "DID_NO_CONNECT".
5300 *
5301 * Link Down Timeout != 0:
5302 *
5303 * The driver waits for the link to come up after link down
5304 * before returning I/Os to OS with "DID_NO_CONNECT".
5305 */
5306 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5307 ha->loop_down_abort_time =
5308 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5309 } else {
5310 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5311 ha->loop_down_abort_time =
5312 (LOOP_DOWN_TIME - ha->link_down_timeout);
5313 }
5314
5315 /* Need enough time to try and get the port back. */
5316 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5317 if (qlport_down_retry)
5318 ha->port_down_retry_count = qlport_down_retry;
5319
5320 /* Set login_retry_count */
5321 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5322 if (ha->port_down_retry_count ==
5323 le16_to_cpu(nv->port_down_retry_count) &&
5324 ha->port_down_retry_count > 3)
5325 ha->login_retry_count = ha->port_down_retry_count;
5326 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5327 ha->login_retry_count = ha->port_down_retry_count;
5328 if (ql2xloginretrycount)
5329 ha->login_retry_count = ql2xloginretrycount;
5330
5331 /* Enable ZIO. */
5332 if (!vha->flags.init_done) {
5333 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5334 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5335 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5336 le16_to_cpu(icb->interrupt_delay_timer): 2;
5337 }
5338 icb->firmware_options_2 &= __constant_cpu_to_le32(
5339 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5340 vha->flags.process_response_queue = 0;
5341 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5342 ha->zio_mode = QLA_ZIO_MODE_6;
5343
5344 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5345 "(%d us).\n", vha->host_no, ha->zio_mode,
5346 ha->zio_timer * 100));
5347 qla_printk(KERN_INFO, ha,
5348 "ZIO mode %d enabled; timer delay (%d us).\n",
5349 ha->zio_mode, ha->zio_timer * 100);
5350
5351 icb->firmware_options_2 |= cpu_to_le32(
5352 (uint32_t)ha->zio_mode);
5353 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5354 vha->flags.process_response_queue = 1;
5355 }
5356
5357 if (rval) {
5358 DEBUG2_3(printk(KERN_WARNING
5359 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
5360 }
5361 return (rval);
5362}
5363
Giridhar Malavalia9083012010-04-12 17:59:55 -07005364int
5365qla82xx_restart_isp(scsi_qla_host_t *vha)
5366{
5367 int status, rval;
5368 uint32_t wait_time;
5369 struct qla_hw_data *ha = vha->hw;
5370 struct req_que *req = ha->req_q_map[0];
5371 struct rsp_que *rsp = ha->rsp_q_map[0];
5372 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005373 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005374
5375 status = qla2x00_init_rings(vha);
5376 if (!status) {
5377 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5378 ha->flags.chip_reset_done = 1;
5379
5380 status = qla2x00_fw_ready(vha);
5381 if (!status) {
5382 qla_printk(KERN_INFO, ha,
5383 "%s(): Start configure loop, "
5384 "status = %d\n", __func__, status);
5385
5386 /* Issue a marker after FW becomes ready. */
5387 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5388
5389 vha->flags.online = 1;
5390 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5391 wait_time = 256;
5392 do {
5393 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5394 qla2x00_configure_loop(vha);
5395 wait_time--;
5396 } while (!atomic_read(&vha->loop_down_timer) &&
5397 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5398 wait_time &&
5399 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5400 }
5401
5402 /* if no cable then assume it's good */
5403 if ((vha->device_flags & DFLG_NO_CABLE))
5404 status = 0;
5405
5406 qla_printk(KERN_INFO, ha,
5407 "%s(): Configure loop done, status = 0x%x\n",
5408 __func__, status);
5409 }
5410
5411 if (!status) {
5412 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5413
5414 if (!atomic_read(&vha->loop_down_timer)) {
5415 /*
5416 * Issue marker command only when we are going
5417 * to start the I/O .
5418 */
5419 vha->marker_needed = 1;
5420 }
5421
5422 vha->flags.online = 1;
5423
5424 ha->isp_ops->enable_intrs(ha);
5425
5426 ha->isp_abort_cnt = 0;
5427 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5428
5429 if (ha->fce) {
5430 ha->flags.fce_enabled = 1;
5431 memset(ha->fce, 0,
5432 fce_calc_size(ha->fce_bufs));
5433 rval = qla2x00_enable_fce_trace(vha,
5434 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5435 &ha->fce_bufs);
5436 if (rval) {
5437 qla_printk(KERN_WARNING, ha,
5438 "Unable to reinitialize FCE "
5439 "(%d).\n", rval);
5440 ha->flags.fce_enabled = 0;
5441 }
5442 }
5443
5444 if (ha->eft) {
5445 memset(ha->eft, 0, EFT_SIZE);
5446 rval = qla2x00_enable_eft_trace(vha,
5447 ha->eft_dma, EFT_NUM_BUFFERS);
5448 if (rval) {
5449 qla_printk(KERN_WARNING, ha,
5450 "Unable to reinitialize EFT "
5451 "(%d).\n", rval);
5452 }
5453 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005454 }
5455
5456 if (!status) {
5457 DEBUG(printk(KERN_INFO
5458 "qla82xx_restart_isp(%ld): succeeded.\n",
5459 vha->host_no));
Arun Easifeafb7b2010-09-03 14:57:00 -07005460
5461 spin_lock_irqsave(&ha->vport_slock, flags);
5462 list_for_each_entry(vp, &ha->vp_list, list) {
5463 if (vp->vp_idx) {
5464 atomic_inc(&vp->vref_count);
5465 spin_unlock_irqrestore(&ha->vport_slock, flags);
5466
Giridhar Malavalia9083012010-04-12 17:59:55 -07005467 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07005468
5469 spin_lock_irqsave(&ha->vport_slock, flags);
5470 atomic_dec(&vp->vref_count);
5471 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005472 }
Arun Easifeafb7b2010-09-03 14:57:00 -07005473 spin_unlock_irqrestore(&ha->vport_slock, flags);
5474
Giridhar Malavalia9083012010-04-12 17:59:55 -07005475 } else {
5476 qla_printk(KERN_INFO, ha,
5477 "qla82xx_restart_isp: **** FAILED ****\n");
5478 }
5479
5480 return status;
5481}
5482
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005483void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005484qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005485{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005486 struct qla_hw_data *ha = vha->hw;
5487
5488 if (!ql2xetsenable)
5489 return;
5490
5491 /* Enable ETS Burst. */
5492 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5493 ha->fw_options[2] |= BIT_9;
5494 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005495}
Sarang Radke09ff7012010-03-19 17:03:59 -07005496
5497/*
5498 * qla24xx_get_fcp_prio
5499 * Gets the fcp cmd priority value for the logged in port.
5500 * Looks for a match of the port descriptors within
5501 * each of the fcp prio config entries. If a match is found,
5502 * the tag (priority) value is returned.
5503 *
5504 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005505 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005506 * fcport = port structure pointer.
5507 *
5508 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005509 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005510 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005511 *
5512 * Context:
5513 * Kernel context
5514 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005515static int
Sarang Radke09ff7012010-03-19 17:03:59 -07005516qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5517{
5518 int i, entries;
5519 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005520 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005521 uint32_t pid1, pid2;
5522 uint64_t wwn1, wwn2;
5523 struct qla_fcp_prio_entry *pri_entry;
5524 struct qla_hw_data *ha = vha->hw;
5525
5526 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005527 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005528
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005529 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005530 entries = ha->fcp_prio_cfg->num_entries;
5531 pri_entry = &ha->fcp_prio_cfg->entry[0];
5532
5533 for (i = 0; i < entries; i++) {
5534 pid_match = wwn_match = 0;
5535
5536 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5537 pri_entry++;
5538 continue;
5539 }
5540
5541 /* check source pid for a match */
5542 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5543 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5544 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5545 if (pid1 == INVALID_PORT_ID)
5546 pid_match++;
5547 else if (pid1 == pid2)
5548 pid_match++;
5549 }
5550
5551 /* check destination pid for a match */
5552 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5553 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5554 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5555 if (pid1 == INVALID_PORT_ID)
5556 pid_match++;
5557 else if (pid1 == pid2)
5558 pid_match++;
5559 }
5560
5561 /* check source WWN for a match */
5562 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5563 wwn1 = wwn_to_u64(vha->port_name);
5564 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5565 if (wwn2 == (uint64_t)-1)
5566 wwn_match++;
5567 else if (wwn1 == wwn2)
5568 wwn_match++;
5569 }
5570
5571 /* check destination WWN for a match */
5572 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5573 wwn1 = wwn_to_u64(fcport->port_name);
5574 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5575 if (wwn2 == (uint64_t)-1)
5576 wwn_match++;
5577 else if (wwn1 == wwn2)
5578 wwn_match++;
5579 }
5580
5581 if (pid_match == 2 || wwn_match == 2) {
5582 /* Found a matching entry */
5583 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5584 priority = pri_entry->tag;
5585 break;
5586 }
5587
5588 pri_entry++;
5589 }
5590
5591 return priority;
5592}
5593
5594/*
5595 * qla24xx_update_fcport_fcp_prio
5596 * Activates fcp priority for the logged in fc port
5597 *
5598 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005599 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005600 * fcp = port structure pointer.
5601 *
5602 * Return:
5603 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5604 *
5605 * Context:
5606 * Kernel context.
5607 */
5608int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005609qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07005610{
5611 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005612 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005613 uint16_t mb[5];
5614
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005615 if (fcport->port_type != FCT_TARGET ||
5616 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07005617 return QLA_FUNCTION_FAILED;
5618
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005619 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005620 if (priority < 0)
5621 return QLA_FUNCTION_FAILED;
5622
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005623 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Sarang Radke09ff7012010-03-19 17:03:59 -07005624 if (ret == QLA_SUCCESS)
5625 fcport->fcp_prio = priority;
5626 else
5627 DEBUG2(printk(KERN_WARNING
5628 "scsi(%ld): Unable to activate fcp priority, "
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005629 " ret=0x%x\n", vha->host_no, ret));
Sarang Radke09ff7012010-03-19 17:03:59 -07005630
5631 return ret;
5632}
5633
5634/*
5635 * qla24xx_update_all_fcp_prio
5636 * Activates fcp priority for all the logged in ports
5637 *
5638 * Input:
5639 * ha = adapter block pointer.
5640 *
5641 * Return:
5642 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5643 *
5644 * Context:
5645 * Kernel context.
5646 */
5647int
5648qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5649{
5650 int ret;
5651 fc_port_t *fcport;
5652
5653 ret = QLA_FUNCTION_FAILED;
5654 /* We need to set priority for all logged in ports */
5655 list_for_each_entry(fcport, &vha->vp_fcports, list)
5656 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5657
5658 return ret;
5659}